Passed
Push — master ( ae5aa5...55fff1 )
by Brian
05:20
created
includes/wpinv-item-functions.php 2 patches
Indentation   +20 added lines, -20 removed lines patch added patch discarded remove patch
@@ -57,21 +57,21 @@  discard block
 block discarded – undo
57 57
     $args = wp_parse_args(
58 58
         $args,
59 59
         array(
60
-			'status'     => array( 'publish' ),
61
-			'limit'      => get_option( 'posts_per_page' ),
62
-			'page'       => 1,
63
-			'exclude'    => array(),
64
-			'orderby'    => 'date',
65
-			'order'      => 'DESC',
66
-			'type'       => wpinv_item_types(),
67
-			'meta_query' => array(
60
+            'status'     => array( 'publish' ),
61
+            'limit'      => get_option( 'posts_per_page' ),
62
+            'page'       => 1,
63
+            'exclude'    => array(),
64
+            'orderby'    => 'date',
65
+            'order'      => 'DESC',
66
+            'type'       => wpinv_item_types(),
67
+            'meta_query' => array(
68 68
                 array(
69 69
                     'key'     => '_wpinv_one_time',
70 70
                     'compare' => 'NOT EXISTS',
71 71
                 ),
72 72
             ),
73
-			'return'     => 'objects',
74
-			'paginate'   => false,
73
+            'return'     => 'objects',
74
+            'paginate'   => false,
75 75
         )
76 76
     );
77 77
 
@@ -211,9 +211,9 @@  discard block
 block discarded – undo
211 211
 
212 212
 function wpinv_get_item_types() {
213 213
     $item_types = array(
214
-		'custom' => __( 'Standard', 'invoicing' ),
215
-		'fee'    => __( 'Fee', 'invoicing' ),
216
-	);
214
+        'custom' => __( 'Standard', 'invoicing' ),
215
+        'fee'    => __( 'Fee', 'invoicing' ),
216
+    );
217 217
     return apply_filters( 'wpinv_get_item_types', $item_types );
218 218
 }
219 219
 
@@ -255,16 +255,16 @@  discard block
 block discarded – undo
255 255
     $args = array();
256 256
     if ( $post_ids ) {
257 257
         $args = array(
258
-			'fields' => 'ids',
259
-		);
258
+            'fields' => 'ids',
259
+        );
260 260
     }
261 261
 
262 262
     $args = array_merge(
263 263
         $args,
264 264
         array(
265 265
             'post_type'  => 'wpi_item',
266
-			'orderby'    => 'rand',
267
-			'post_count' => $num,
266
+            'orderby'    => 'rand',
267
+            'post_count' => $num,
268 268
             'meta_query' => array(
269 269
                 array(
270 270
                     'key'     => '_wpinv_one_time',
@@ -439,10 +439,10 @@  discard block
 block discarded – undo
439 439
     $bill_times_less = $bill_times - 1;
440 440
 
441 441
     if ( ! empty( $bill_times ) ) {
442
-		$bill_times = $item->get_recurring_interval() * $bill_times;
442
+        $bill_times = $item->get_recurring_interval() * $bill_times;
443 443
         $bill_times_less = getpaid_get_subscription_period_label( $item->get_recurring_period(), $bill_times - $item->get_recurring_interval() );
444
-		$bill_times = getpaid_get_subscription_period_label( $item->get_recurring_period(), $bill_times );
445
-	}
444
+        $bill_times = getpaid_get_subscription_period_label( $item->get_recurring_period(), $bill_times );
445
+    }
446 446
 
447 447
     if ( $item instanceof GetPaid_Form_Item && false === $_initial_price ) {
448 448
         $initial_price   = wpinv_price( $item->get_sub_total(), $currency );
Please login to merge, or discard this patch.
Spacing   +131 added lines, -131 removed lines patch added patch discarded remove patch
@@ -6,7 +6,7 @@  discard block
 block discarded – undo
6 6
  * @package Invoicing
7 7
  */
8 8
 
9
-defined( 'ABSPATH' ) || exit;
9
+defined('ABSPATH') || exit;
10 10
 
11 11
 /**
12 12
  * Retrieves an item by it's ID.
@@ -14,9 +14,9 @@  discard block
 block discarded – undo
14 14
  * @param int the item ID to retrieve.
15 15
  * @return WPInv_Item|false
16 16
  */
17
-function wpinv_get_item_by_id( $id ) {
18
-    $item = wpinv_get_item( $id );
19
-    return empty( $item ) || $id != $item->get_id() ? false : $item;
17
+function wpinv_get_item_by_id($id) {
18
+    $item = wpinv_get_item($id);
19
+    return empty($item) || $id != $item->get_id() ? false : $item;
20 20
 }
21 21
 
22 22
 /**
@@ -24,14 +24,14 @@  discard block
 block discarded – undo
24 24
  *
25 25
  * @return WPInv_Item|false
26 26
  */
27
-function wpinv_get_item_by( $field = '', $value = '', $type = '' ) {
27
+function wpinv_get_item_by($field = '', $value = '', $type = '') {
28 28
 
29
-    if ( 'id' === strtolower( $field ) ) {
30
-        return wpinv_get_item_by_id( $value );
29
+    if ('id' === strtolower($field)) {
30
+        return wpinv_get_item_by_id($value);
31 31
     }
32 32
 
33
-    $id = WPInv_Item::get_item_id_by_field( $value, strtolower( $field ), $type );
34
-    return empty( $id ) ? false : wpinv_get_item( $id );
33
+    $id = WPInv_Item::get_item_id_by_field($value, strtolower($field), $type);
34
+    return empty($id) ? false : wpinv_get_item($id);
35 35
 
36 36
 }
37 37
 
@@ -41,24 +41,24 @@  discard block
 block discarded – undo
41 41
  * @param int|WPInv_Item the item to retrieve.
42 42
  * @return WPInv_Item|false
43 43
  */
44
-function wpinv_get_item( $item = 0 ) {
44
+function wpinv_get_item($item = 0) {
45 45
 
46
-    if ( empty( $item ) ) {
46
+    if (empty($item)) {
47 47
         return false;
48 48
     }
49 49
 
50
-    $item = new WPInv_Item( $item );
50
+    $item = new WPInv_Item($item);
51 51
     return $item->exists() ? $item : false;
52 52
 
53 53
 }
54 54
 
55
-function wpinv_get_all_items( $args = array() ) {
55
+function wpinv_get_all_items($args = array()) {
56 56
 
57 57
     $args = wp_parse_args(
58 58
         $args,
59 59
         array(
60
-			'status'     => array( 'publish' ),
61
-			'limit'      => get_option( 'posts_per_page' ),
60
+			'status'     => array('publish'),
61
+			'limit'      => get_option('posts_per_page'),
62 62
 			'page'       => 1,
63 63
 			'exclude'    => array(),
64 64
 			'orderby'    => 'date',
@@ -83,44 +83,44 @@  discard block
 block discarded – undo
83 83
         'fields'         => 'ids',
84 84
         'orderby'        => $args['orderby'],
85 85
         'order'          => $args['order'],
86
-        'paged'          => absint( $args['page'] ),
86
+        'paged'          => absint($args['page']),
87 87
     );
88 88
 
89
-    if ( ! empty( $args['exclude'] ) ) {
90
-        $wp_query_args['post__not_in'] = array_map( 'absint', $args['exclude'] );
89
+    if (!empty($args['exclude'])) {
90
+        $wp_query_args['post__not_in'] = array_map('absint', $args['exclude']);
91 91
     }
92 92
 
93
-    if ( ! $args['paginate'] ) {
93
+    if (!$args['paginate']) {
94 94
         $wp_query_args['no_found_rows'] = true;
95 95
     }
96 96
 
97
-    if ( ! empty( $args['search'] ) ) {
97
+    if (!empty($args['search'])) {
98 98
         $wp_query_args['s'] = $args['search'];
99 99
     }
100 100
 
101
-    if ( ! empty( $args['type'] ) && $args['type'] !== wpinv_item_types() ) {
102
-        $types = wpinv_parse_list( $args['type'] );
101
+    if (!empty($args['type']) && $args['type'] !== wpinv_item_types()) {
102
+        $types = wpinv_parse_list($args['type']);
103 103
         $wp_query_args['meta_query'][] = array(
104 104
             'key'     => '_wpinv_type',
105
-            'value'   => implode( ',', $types ),
105
+            'value'   => implode(',', $types),
106 106
             'compare' => 'IN',
107 107
         );
108 108
     }
109 109
 
110
-    $wp_query_args = apply_filters( 'wpinv_get_items_args', $wp_query_args, $args );
110
+    $wp_query_args = apply_filters('wpinv_get_items_args', $wp_query_args, $args);
111 111
 
112 112
     // Get results.
113
-    $items = new WP_Query( $wp_query_args );
113
+    $items = new WP_Query($wp_query_args);
114 114
 
115
-    if ( 'objects' === $args['return'] ) {
116
-        $return = array_map( 'wpinv_get_item_by_id', $items->posts );
117
-    } elseif ( 'self' === $args['return'] ) {
115
+    if ('objects' === $args['return']) {
116
+        $return = array_map('wpinv_get_item_by_id', $items->posts);
117
+    } elseif ('self' === $args['return']) {
118 118
         return $items;
119 119
     } else {
120 120
         $return = $items->posts;
121 121
     }
122 122
 
123
-    if ( $args['paginate'] ) {
123
+    if ($args['paginate']) {
124 124
         return (object) array(
125 125
             'items'         => $return,
126 126
             'total'         => $items->found_posts,
@@ -132,12 +132,12 @@  discard block
 block discarded – undo
132 132
 
133 133
 }
134 134
 
135
-function wpinv_is_free_item( $item_id = 0 ) {
136
-    if ( empty( $item_id ) ) {
135
+function wpinv_is_free_item($item_id = 0) {
136
+    if (empty($item_id)) {
137 137
         return false;
138 138
     }
139 139
 
140
-    $item = new WPInv_Item( $item_id );
140
+    $item = new WPInv_Item($item_id);
141 141
 
142 142
     return $item->is_free();
143 143
 }
@@ -147,21 +147,21 @@  discard block
 block discarded – undo
147 147
  *
148 148
  * @param WP_Post|WPInv_Item|Int $item The item to check for.
149 149
  */
150
-function wpinv_item_is_editable( $item = 0 ) {
150
+function wpinv_item_is_editable($item = 0) {
151 151
 
152 152
     // Fetch the item.
153
-    $item = new WPInv_Item( $item );
153
+    $item = new WPInv_Item($item);
154 154
 
155 155
     // Check if it is editable.
156 156
     return $item->is_editable();
157 157
 }
158 158
 
159
-function wpinv_get_item_price( $item_id = 0 ) {
160
-    if ( empty( $item_id ) ) {
159
+function wpinv_get_item_price($item_id = 0) {
160
+    if (empty($item_id)) {
161 161
         return false;
162 162
     }
163 163
 
164
-    $item = new WPInv_Item( $item_id );
164
+    $item = new WPInv_Item($item_id);
165 165
 
166 166
     return $item->get_price();
167 167
 }
@@ -171,89 +171,89 @@  discard block
 block discarded – undo
171 171
  *
172 172
  * @param WPInv_Item|int $item
173 173
  */
174
-function wpinv_is_recurring_item( $item = 0 ) {
175
-    $item = new WPInv_Item( $item );
174
+function wpinv_is_recurring_item($item = 0) {
175
+    $item = new WPInv_Item($item);
176 176
     return $item->is_recurring();
177 177
 }
178 178
 
179
-function wpinv_item_price( $item_id = 0 ) {
180
-    if ( empty( $item_id ) ) {
179
+function wpinv_item_price($item_id = 0) {
180
+    if (empty($item_id)) {
181 181
         return false;
182 182
     }
183 183
 
184
-    $price = wpinv_get_item_price( $item_id );
185
-    $price = wpinv_price( $price );
184
+    $price = wpinv_get_item_price($item_id);
185
+    $price = wpinv_price($price);
186 186
 
187
-    return apply_filters( 'wpinv_item_price', $price, $item_id );
187
+    return apply_filters('wpinv_item_price', $price, $item_id);
188 188
 }
189 189
 
190
-function wpinv_get_item_final_price( $item_id = 0, $amount_override = null ) {
191
-    if ( is_null( $amount_override ) ) {
192
-        $original_price = get_post_meta( $item_id, '_wpinv_price', true );
190
+function wpinv_get_item_final_price($item_id = 0, $amount_override = null) {
191
+    if (is_null($amount_override)) {
192
+        $original_price = get_post_meta($item_id, '_wpinv_price', true);
193 193
     } else {
194 194
         $original_price = $amount_override;
195 195
     }
196 196
 
197 197
     $price = $original_price;
198 198
 
199
-    return apply_filters( 'wpinv_get_item_final_price', $price, $item_id );
199
+    return apply_filters('wpinv_get_item_final_price', $price, $item_id);
200 200
 }
201 201
 
202
-function wpinv_item_custom_singular_name( $item_id ) {
203
-    if ( empty( $item_id ) ) {
202
+function wpinv_item_custom_singular_name($item_id) {
203
+    if (empty($item_id)) {
204 204
         return false;
205 205
     }
206 206
 
207
-    $item = new WPInv_Item( $item_id );
207
+    $item = new WPInv_Item($item_id);
208 208
 
209 209
     return $item->get_custom_singular_name();
210 210
 }
211 211
 
212 212
 function wpinv_get_item_types() {
213 213
     $item_types = array(
214
-		'custom' => __( 'Standard', 'invoicing' ),
215
-		'fee'    => __( 'Fee', 'invoicing' ),
214
+		'custom' => __('Standard', 'invoicing'),
215
+		'fee'    => __('Fee', 'invoicing'),
216 216
 	);
217
-    return apply_filters( 'wpinv_get_item_types', $item_types );
217
+    return apply_filters('wpinv_get_item_types', $item_types);
218 218
 }
219 219
 
220 220
 function wpinv_item_types() {
221 221
     $item_types = wpinv_get_item_types();
222 222
 
223
-    return ( ! empty( $item_types ) ? array_keys( $item_types ) : array() );
223
+    return (!empty($item_types) ? array_keys($item_types) : array());
224 224
 }
225 225
 
226
-function wpinv_get_item_type( $item_id ) {
227
-    if ( empty( $item_id ) ) {
226
+function wpinv_get_item_type($item_id) {
227
+    if (empty($item_id)) {
228 228
         return false;
229 229
     }
230 230
 
231
-    $item = new WPInv_Item( $item_id );
231
+    $item = new WPInv_Item($item_id);
232 232
 
233 233
     return $item->get_type();
234 234
 }
235 235
 
236
-function wpinv_item_type( $item_id ) {
236
+function wpinv_item_type($item_id) {
237 237
     $item_types = wpinv_get_item_types();
238 238
 
239
-    $item_type = wpinv_get_item_type( $item_id );
239
+    $item_type = wpinv_get_item_type($item_id);
240 240
 
241
-    if ( empty( $item_type ) ) {
241
+    if (empty($item_type)) {
242 242
         $item_type = '-';
243 243
     }
244 244
 
245
-    $item_type = isset( $item_types[ $item_type ] ) ? $item_types[ $item_type ] : __( $item_type, 'invoicing' );
245
+    $item_type = isset($item_types[$item_type]) ? $item_types[$item_type] : __($item_type, 'invoicing');
246 246
 
247
-    return apply_filters( 'wpinv_item_type', $item_type, $item_id );
247
+    return apply_filters('wpinv_item_type', $item_type, $item_id);
248 248
 }
249 249
 
250
-function wpinv_get_random_item( $post_ids = true ) {
251
-    wpinv_get_random_items( 1, $post_ids );
250
+function wpinv_get_random_item($post_ids = true) {
251
+    wpinv_get_random_items(1, $post_ids);
252 252
 }
253 253
 
254
-function wpinv_get_random_items( $num = 3, $post_ids = true ) {
254
+function wpinv_get_random_items($num = 3, $post_ids = true) {
255 255
     $args = array();
256
-    if ( $post_ids ) {
256
+    if ($post_ids) {
257 257
         $args = array(
258 258
 			'fields' => 'ids',
259 259
 		);
@@ -274,9 +274,9 @@  discard block
 block discarded – undo
274 274
         )
275 275
     );
276 276
 
277
-    $args  = apply_filters( 'wpinv_get_random_items', $args );
277
+    $args = apply_filters('wpinv_get_random_items', $args);
278 278
 
279
-    return get_posts( $args );
279
+    return get_posts($args);
280 280
 }
281 281
 
282 282
 /**
@@ -285,13 +285,13 @@  discard block
 block discarded – undo
285 285
  * @param WPInv_Item|int $item
286 286
  * @param bool $html
287 287
  */
288
-function wpinv_get_item_suffix( $item, $html = true ) {
288
+function wpinv_get_item_suffix($item, $html = true) {
289 289
 
290
-    $item   = new WPInv_Item( $item );
291
-    $suffix = $item->is_recurring() ? ' ' . __( '(r)', 'invoicing' ) : '';
292
-    $suffix = $html ? $suffix : wp_strip_all_tags( $suffix );
290
+    $item   = new WPInv_Item($item);
291
+    $suffix = $item->is_recurring() ? ' ' . __('(r)', 'invoicing') : '';
292
+    $suffix = $html ? $suffix : wp_strip_all_tags($suffix);
293 293
 
294
-    return apply_filters( 'wpinv_get_item_suffix', $suffix, $item, $html );
294
+    return apply_filters('wpinv_get_item_suffix', $suffix, $item, $html);
295 295
 }
296 296
 
297 297
 /**
@@ -300,9 +300,9 @@  discard block
 block discarded – undo
300 300
  * @param WPInv_Item|int $item
301 301
  * @param bool $force_delete
302 302
  */
303
-function wpinv_remove_item( $item = 0, $force_delete = false ) {
304
-    $item = new WPInv_Item( $item );
305
-    $item->delete( $force_delete );
303
+function wpinv_remove_item($item = 0, $force_delete = false) {
304
+    $item = new WPInv_Item($item);
305
+    $item->delete($force_delete);
306 306
 }
307 307
 
308 308
 /**
@@ -341,44 +341,44 @@  discard block
 block discarded – undo
341 341
  * @param bool $wp_error whether or not to return a WP_Error on failure.
342 342
  * @return bool|WP_Error|WPInv_Item
343 343
  */
344
-function wpinv_create_item( $args = array(), $wp_error = false ) {
344
+function wpinv_create_item($args = array(), $wp_error = false) {
345 345
 
346 346
     // Prepare the item.
347
-    if ( ! empty( $args['custom_id'] ) && empty( $args['ID'] ) ) {
348
-        $type = empty( $args['type'] ) ? 'custom' : $args['type'];
349
-        $item = wpinv_get_item_by( 'custom_id', $args['custom_id'], $type );
347
+    if (!empty($args['custom_id']) && empty($args['ID'])) {
348
+        $type = empty($args['type']) ? 'custom' : $args['type'];
349
+        $item = wpinv_get_item_by('custom_id', $args['custom_id'], $type);
350 350
 
351
-        if ( ! empty( $item ) ) {
351
+        if (!empty($item)) {
352 352
             $args['ID'] = $item->get_id();
353 353
         }
354 354
     }
355 355
 
356 356
     // Do we have an item?
357
-    if ( ! empty( $args['ID'] ) ) {
358
-        $item = new WPInv_Item( $args['ID'] );
357
+    if (!empty($args['ID'])) {
358
+        $item = new WPInv_Item($args['ID']);
359 359
     } else {
360 360
         $item = new WPInv_Item();
361 361
     }
362 362
 
363 363
     // Do we have an error?
364
-    if ( ! empty( $item->last_error ) ) {
365
-        return $wp_error ? new WP_Error( 'invalid_item', $item->last_error ) : false;
364
+    if (!empty($item->last_error)) {
365
+        return $wp_error ? new WP_Error('invalid_item', $item->last_error) : false;
366 366
     }
367 367
 
368 368
     // Update item props.
369
-    $item->set_props( $args );
369
+    $item->set_props($args);
370 370
 
371 371
     // Save the item.
372 372
     $item->save();
373 373
 
374 374
     // Do we have an error?
375
-    if ( ! empty( $item->last_error ) ) {
376
-        return $wp_error ? new WP_Error( 'not_saved', $item->last_error ) : false;
375
+    if (!empty($item->last_error)) {
376
+        return $wp_error ? new WP_Error('not_saved', $item->last_error) : false;
377 377
     }
378 378
 
379 379
     // Was the item saved?
380
-    if ( ! $item->get_id() ) {
381
-        return $wp_error ? new WP_Error( 'not_saved', __( 'An error occured while saving the item', 'invoicing' ) ) : false;
380
+    if (!$item->get_id()) {
381
+        return $wp_error ? new WP_Error('not_saved', __('An error occured while saving the item', 'invoicing')) : false;
382 382
     }
383 383
 
384 384
     return $item;
@@ -390,14 +390,14 @@  discard block
 block discarded – undo
390 390
  *
391 391
  * @see wpinv_create_item()
392 392
  */
393
-function wpinv_update_item( $args = array(), $wp_error = false ) {
394
-    return wpinv_create_item( $args, $wp_error );
393
+function wpinv_update_item($args = array(), $wp_error = false) {
394
+    return wpinv_create_item($args, $wp_error);
395 395
 }
396 396
 
397 397
 /**
398 398
  * Sanitizes a recurring period
399 399
  */
400
-function getpaid_sanitize_recurring_period( $period, $full = false ) {
400
+function getpaid_sanitize_recurring_period($period, $full = false) {
401 401
 
402 402
     $periods = array(
403 403
         'D' => 'day',
@@ -406,16 +406,16 @@  discard block
 block discarded – undo
406 406
         'Y' => 'year',
407 407
     );
408 408
 
409
-    if ( ! isset( $periods[ $period ] ) ) {
409
+    if (!isset($periods[$period])) {
410 410
         $period = 'D';
411 411
     }
412 412
 
413
-    return $full ? $periods[ $period ] : $period;
413
+    return $full ? $periods[$period] : $period;
414 414
 
415 415
 }
416 416
 
417
-function wpinv_item_max_buyable_quantity( $item_id ) {
418
-    return apply_filters( 'wpinv_item_max_buyable_quantity', 5, $item_id );
417
+function wpinv_item_max_buyable_quantity($item_id) {
418
+    return apply_filters('wpinv_item_max_buyable_quantity', 5, $item_id);
419 419
 }
420 420
 
421 421
 /**
@@ -423,47 +423,47 @@  discard block
 block discarded – undo
423 423
  *
424 424
  * @param WPInv_Item|GetPaid_Form_Item $item
425 425
  */
426
-function getpaid_item_recurring_price_help_text( $item, $currency = '', $_initial_price = false, $_recurring_price = false ) {
426
+function getpaid_item_recurring_price_help_text($item, $currency = '', $_initial_price = false, $_recurring_price = false) {
427 427
 
428 428
     // Abort if it is not recurring.
429
-    if ( ! $item->is_recurring() ) {
429
+    if (!$item->is_recurring()) {
430 430
         return '';
431 431
     }
432 432
 
433
-    $initial_price   = false === $_initial_price ? wpinv_price( $item->get_initial_price(), $currency ) : $_initial_price;
434
-    $recurring_price = false === $_recurring_price ? wpinv_price( $item->get_recurring_price(), $currency ) : $_recurring_price;
435
-    $period          = getpaid_get_subscription_period_label( $item->get_recurring_period(), $item->get_recurring_interval(), '' );
433
+    $initial_price   = false === $_initial_price ? wpinv_price($item->get_initial_price(), $currency) : $_initial_price;
434
+    $recurring_price = false === $_recurring_price ? wpinv_price($item->get_recurring_price(), $currency) : $_recurring_price;
435
+    $period          = getpaid_get_subscription_period_label($item->get_recurring_period(), $item->get_recurring_interval(), '');
436 436
     $initial_class   = 'getpaid-item-initial-price';
437 437
     $recurring_class = 'getpaid-item-recurring-price';
438 438
     $bill_times      = $item->get_recurring_limit();
439 439
     $bill_times_less = $bill_times - 1;
440 440
 
441
-    if ( ! empty( $bill_times ) ) {
441
+    if (!empty($bill_times)) {
442 442
 		$bill_times = $item->get_recurring_interval() * $bill_times;
443
-        $bill_times_less = getpaid_get_subscription_period_label( $item->get_recurring_period(), $bill_times - $item->get_recurring_interval() );
444
-		$bill_times = getpaid_get_subscription_period_label( $item->get_recurring_period(), $bill_times );
443
+        $bill_times_less = getpaid_get_subscription_period_label($item->get_recurring_period(), $bill_times - $item->get_recurring_interval());
444
+		$bill_times = getpaid_get_subscription_period_label($item->get_recurring_period(), $bill_times);
445 445
 	}
446 446
 
447
-    if ( $item instanceof GetPaid_Form_Item && false === $_initial_price ) {
448
-        $initial_price   = wpinv_price( $item->get_sub_total(), $currency );
449
-        $recurring_price = wpinv_price( $item->get_recurring_sub_total(), $currency );
447
+    if ($item instanceof GetPaid_Form_Item && false === $_initial_price) {
448
+        $initial_price   = wpinv_price($item->get_sub_total(), $currency);
449
+        $recurring_price = wpinv_price($item->get_recurring_sub_total(), $currency);
450 450
     }
451 451
 
452
-    if ( wpinv_price( 0, $currency ) == $initial_price && wpinv_price( 0, $currency ) == $recurring_price ) {
453
-        return __( 'Free forever', 'invoicing' );
452
+    if (wpinv_price(0, $currency) == $initial_price && wpinv_price(0, $currency) == $recurring_price) {
453
+        return __('Free forever', 'invoicing');
454 454
     }
455 455
 
456 456
     // For free trial items.
457
-    if ( $item->has_free_trial() ) {
458
-        $trial_period = getpaid_get_subscription_period_label( $item->get_trial_period(), $item->get_trial_interval() );
457
+    if ($item->has_free_trial()) {
458
+        $trial_period = getpaid_get_subscription_period_label($item->get_trial_period(), $item->get_trial_interval());
459 459
 
460
-        if ( wpinv_price( 0, $currency ) == $initial_price ) {
460
+        if (wpinv_price(0, $currency) == $initial_price) {
461 461
 
462
-            if ( empty( $bill_times ) ) {
462
+            if (empty($bill_times)) {
463 463
 
464 464
                 return sprintf(
465 465
                     // translators: $1: is the trial period, $2: is the recurring price, $3: is the susbcription period
466
-                    _x( 'Free for %1$s then %2$s / %3$s', 'Item subscription amount. (e.g.: Free for 1 month then $120 / year)', 'invoicing' ),
466
+                    _x('Free for %1$s then %2$s / %3$s', 'Item subscription amount. (e.g.: Free for 1 month then $120 / year)', 'invoicing'),
467 467
                     "<span class='getpaid-item-trial-period'>$trial_period</span>",
468 468
                     "<span class='$recurring_class'>$recurring_price</span>",
469 469
                     "<span class='getpaid-item-recurring-period'>$period</span>"
@@ -473,7 +473,7 @@  discard block
 block discarded – undo
473 473
 
474 474
             return sprintf(
475 475
                 // translators: $1: is the trial period, $2: is the recurring price, $3: is the susbcription period, $4: is the bill times
476
-                _x( 'Free for %1$s then %2$s / %3$s for %4$s', 'Item subscription amount. (e.g.: Free for 1 month then $120 / year for 4 years)', 'invoicing' ),
476
+                _x('Free for %1$s then %2$s / %3$s for %4$s', 'Item subscription amount. (e.g.: Free for 1 month then $120 / year for 4 years)', 'invoicing'),
477 477
                 "<span class='getpaid-item-trial-period'>$trial_period</span>",
478 478
                 "<span class='$recurring_class'>$recurring_price</span>",
479 479
                 "<span class='getpaid-item-recurring-period'>$period</span>",
@@ -482,11 +482,11 @@  discard block
 block discarded – undo
482 482
 
483 483
         }
484 484
 
485
-        if ( empty( $bill_times ) ) {
485
+        if (empty($bill_times)) {
486 486
 
487 487
             return sprintf(
488 488
                 // translators: $1: is the initial price, $2: is the trial period, $3: is the recurring price, $4: is the susbcription period
489
-                _x( '%1$s for %2$s then %3$s / %4$s', 'Item subscription amount. (e.g.: $7 for 1 month then $120 / year)', 'invoicing' ),
489
+                _x('%1$s for %2$s then %3$s / %4$s', 'Item subscription amount. (e.g.: $7 for 1 month then $120 / year)', 'invoicing'),
490 490
                 "<span class='$initial_class'>$initial_price</span>",
491 491
                 "<span class='getpaid-item-trial-period'>$trial_period</span>",
492 492
                 "<span class='$recurring_class'>$recurring_price</span>",
@@ -497,7 +497,7 @@  discard block
 block discarded – undo
497 497
 
498 498
         return sprintf(
499 499
             // translators: $1: is the initial price, $2: is the trial period, $3: is the recurring price, $4: is the susbcription period, $4: is the susbcription bill times
500
-            _x( '%1$s for %2$s then %3$s / %4$s for %5$s', 'Item subscription amount. (e.g.: $7 for 1 month then $120 / year for 5 years)', 'invoicing' ),
500
+            _x('%1$s for %2$s then %3$s / %4$s for %5$s', 'Item subscription amount. (e.g.: $7 for 1 month then $120 / year for 5 years)', 'invoicing'),
501 501
             "<span class='$initial_class'>$initial_price</span>",
502 502
             "<span class='getpaid-item-trial-period'>$trial_period</span>",
503 503
             "<span class='$recurring_class'>$recurring_price</span>",
@@ -507,13 +507,13 @@  discard block
 block discarded – undo
507 507
 
508 508
     }
509 509
 
510
-    if ( $initial_price == $recurring_price ) {
510
+    if ($initial_price == $recurring_price) {
511 511
 
512
-        if ( empty( $bill_times ) ) {
512
+        if (empty($bill_times)) {
513 513
 
514 514
             return sprintf(
515 515
                 // translators: $1: is the recurring price, $2: is the susbcription period
516
-                _x( '%1$s / %2$s', 'Item subscription amount. (e.g.: $120 / year)', 'invoicing' ),
516
+                _x('%1$s / %2$s', 'Item subscription amount. (e.g.: $120 / year)', 'invoicing'),
517 517
                 "<span class='$recurring_class'>$recurring_price</span>",
518 518
                 "<span class='getpaid-item-recurring-period'>$period</span>"
519 519
             );
@@ -522,7 +522,7 @@  discard block
 block discarded – undo
522 522
 
523 523
         return sprintf(
524 524
             // translators: $1: is the recurring price, $2: is the susbcription period, $3: is the susbcription bill times
525
-            _x( '%1$s / %2$s for %3$s', 'Item subscription amount. (e.g.: $120 / year for 5 years)', 'invoicing' ),
525
+            _x('%1$s / %2$s for %3$s', 'Item subscription amount. (e.g.: $120 / year for 5 years)', 'invoicing'),
526 526
             "<span class='$recurring_class'>$recurring_price</span>",
527 527
             "<span class='getpaid-item-recurring-period'>$period</span>",
528 528
             "<span class='getpaid-item-recurring-bill-times'>$bill_times</span>"
@@ -530,13 +530,13 @@  discard block
 block discarded – undo
530 530
 
531 531
     }
532 532
 
533
-    if ( $initial_price == wpinv_price( 0, $currency ) ) {
533
+    if ($initial_price == wpinv_price(0, $currency)) {
534 534
 
535
-        if ( empty( $bill_times ) ) {
535
+        if (empty($bill_times)) {
536 536
 
537 537
             return sprintf(
538 538
                 // translators: $1: is the recurring period, $2: is the recurring price
539
-                _x( 'Free for %1$s then %2$s / %1$s', 'Item subscription amount. (e.g.: Free for 3 months then $7 / 3 months)', 'invoicing' ),
539
+                _x('Free for %1$s then %2$s / %1$s', 'Item subscription amount. (e.g.: Free for 3 months then $7 / 3 months)', 'invoicing'),
540 540
                 "<span class='getpaid-item-recurring-period'>$period</span>",
541 541
                 "<span class='$recurring_class'>$recurring_price</span>"
542 542
             );
@@ -545,7 +545,7 @@  discard block
 block discarded – undo
545 545
 
546 546
         return sprintf(
547 547
             // translators: $1: is the recurring period, $2: is the recurring price, $3: is the bill times
548
-            _x( 'Free for %1$s then %2$s / %1$s for %3$s', 'Item subscription amount. (e.g.: Free for 3 months then $7 / 3 months for 12 months)', 'invoicing' ),
548
+            _x('Free for %1$s then %2$s / %1$s for %3$s', 'Item subscription amount. (e.g.: Free for 3 months then $7 / 3 months for 12 months)', 'invoicing'),
549 549
             "<span class='getpaid-item-recurring-period'>$period</span>",
550 550
             "<span class='$recurring_class'>$recurring_price</span>",
551 551
             "<span class='getpaid-item-recurring-bill-times'>$bill_times_less</span>"
@@ -553,11 +553,11 @@  discard block
 block discarded – undo
553 553
 
554 554
     }
555 555
 
556
-    if ( empty( $bill_times ) ) {
556
+    if (empty($bill_times)) {
557 557
 
558 558
         return sprintf(
559 559
             // translators: $1: is the initial price, $2: is the recurring price, $3: is the susbcription period
560
-            _x( 'Initial payment of %1$s then %2$s / %3$s', 'Item subscription amount. (e.g.: Initial payment of $7 then $120 / year)', 'invoicing' ),
560
+            _x('Initial payment of %1$s then %2$s / %3$s', 'Item subscription amount. (e.g.: Initial payment of $7 then $120 / year)', 'invoicing'),
561 561
             "<span class='$initial_class'>$initial_price</span>",
562 562
             "<span class='$recurring_class'>$recurring_price</span>",
563 563
             "<span class='getpaid-item-recurring-period'>$period</span>"
@@ -567,7 +567,7 @@  discard block
 block discarded – undo
567 567
 
568 568
     return sprintf(
569 569
         // translators: $1: is the initial price, $2: is the recurring price, $3: is the susbcription period, $4: is the susbcription bill times
570
-        _x( 'Initial payment of %1$s then %2$s / %3$s for %4$s', 'Item subscription amount. (e.g.: Initial payment of $7 then $120 / year for 4 years)', 'invoicing' ),
570
+        _x('Initial payment of %1$s then %2$s / %3$s for %4$s', 'Item subscription amount. (e.g.: Initial payment of $7 then $120 / year for 4 years)', 'invoicing'),
571 571
         "<span class='$initial_class'>$initial_price</span>",
572 572
         "<span class='$recurring_class'>$recurring_price</span>",
573 573
         "<span class='getpaid-item-recurring-period'>$period</span>",
Please login to merge, or discard this patch.
includes/gateways/class-getpaid-authorize-net-gateway.php 2 patches
Indentation   +232 added lines, -232 removed lines patch added patch discarded remove patch
@@ -13,17 +13,17 @@  discard block
 block discarded – undo
13 13
 class GetPaid_Authorize_Net_Gateway extends GetPaid_Authorize_Net_Legacy_Gateway {
14 14
 
15 15
     /**
16
-	 * Payment method id.
17
-	 *
18
-	 * @var string
19
-	 */
16
+     * Payment method id.
17
+     *
18
+     * @var string
19
+     */
20 20
     public $id = 'authorizenet';
21 21
 
22 22
     /**
23
-	 * An array of features that this gateway supports.
24
-	 *
25
-	 * @var array
26
-	 */
23
+     * An array of features that this gateway supports.
24
+     *
25
+     * @var array
26
+     */
27 27
     protected $supports = array(
28 28
         'subscription',
29 29
         'sandbox',
@@ -36,44 +36,44 @@  discard block
 block discarded – undo
36 36
     );
37 37
 
38 38
     /**
39
-	 * Payment method order.
40
-	 *
41
-	 * @var int
42
-	 */
39
+     * Payment method order.
40
+     *
41
+     * @var int
42
+     */
43 43
     public $order = 4;
44 44
 
45 45
     /**
46
-	 * Endpoint for requests from Authorize.net.
47
-	 *
48
-	 * @var string
49
-	 */
50
-	protected $notify_url;
51
-
52
-	/**
53
-	 * Endpoint for requests to Authorize.net.
54
-	 *
55
-	 * @var string
56
-	 */
46
+     * Endpoint for requests from Authorize.net.
47
+     *
48
+     * @var string
49
+     */
50
+    protected $notify_url;
51
+
52
+    /**
53
+     * Endpoint for requests to Authorize.net.
54
+     *
55
+     * @var string
56
+     */
57 57
     protected $endpoint;
58 58
 
59 59
     /**
60
-	 * Currencies this gateway is allowed for.
61
-	 *
62
-	 * @var array
63
-	 */
64
-	public $currencies = array( 'USD', 'CAD', 'GBP', 'DKK', 'NOK', 'PLN', 'SEK', 'AUD', 'EUR', 'NZD' );
60
+     * Currencies this gateway is allowed for.
61
+     *
62
+     * @var array
63
+     */
64
+    public $currencies = array( 'USD', 'CAD', 'GBP', 'DKK', 'NOK', 'PLN', 'SEK', 'AUD', 'EUR', 'NZD' );
65 65
 
66 66
     /**
67
-	 * URL to view a transaction.
68
-	 *
69
-	 * @var string
70
-	 */
67
+     * URL to view a transaction.
68
+     *
69
+     * @var string
70
+     */
71 71
     public $view_transaction_url = 'https://{sandbox}authorize.net/ui/themes/sandbox/Transaction/TransactionReceipt.aspx?transid=%s';
72 72
 
73 73
     /**
74
-	 * Class constructor.
75
-	 */
76
-	public function __construct() {
74
+     * Class constructor.
75
+     */
76
+    public function __construct() {
77 77
 
78 78
         $this->title                = __( 'Credit Card / Debit Card', 'invoicing' );
79 79
         $this->method_title         = __( 'Authorize.Net', 'invoicing' );
@@ -85,11 +85,11 @@  discard block
 block discarded – undo
85 85
     }
86 86
 
87 87
     /**
88
-	 * Displays the payment method select field.
89
-	 *
90
-	 * @param int $invoice_id 0 or invoice id.
91
-	 * @param GetPaid_Payment_Form $form Current payment form.
92
-	 */
88
+     * Displays the payment method select field.
89
+     *
90
+     * @param int $invoice_id 0 or invoice id.
91
+     * @param GetPaid_Payment_Form $form Current payment form.
92
+     */
93 93
     public function payment_fields( $invoice_id, $form ) {
94 94
 
95 95
         // Let the user select a payment method.
@@ -100,16 +100,16 @@  discard block
 block discarded – undo
100 100
     }
101 101
 
102 102
     /**
103
-	 * Creates a customer profile.
104
-	 *
105
-	 *
106
-	 * @param WPInv_Invoice $invoice Invoice.
103
+     * Creates a customer profile.
104
+     *
105
+     *
106
+     * @param WPInv_Invoice $invoice Invoice.
107 107
      * @param array $submission_data Posted checkout fields.
108 108
      * @param bool $save Whether or not to save the payment as a token.
109 109
      * @link https://developer.authorize.net/api/reference/index.html#customer-profiles-create-customer-profile
110
-	 * @return string|WP_Error Payment profile id.
111
-	 */
112
-	public function create_customer_profile( $invoice, $submission_data, $save = true ) {
110
+     * @return string|WP_Error Payment profile id.
111
+     */
112
+    public function create_customer_profile( $invoice, $submission_data, $save = true ) {
113 113
 
114 114
         // Remove non-digits from the number
115 115
         $submission_data['authorizenet']['cc_number'] = preg_replace( '/\D/', '', $submission_data['authorizenet']['cc_number'] );
@@ -191,14 +191,14 @@  discard block
 block discarded – undo
191 191
     }
192 192
 
193 193
     /**
194
-	 * Retrieves a customer profile.
195
-	 *
196
-	 *
197
-	 * @param string $profile_id profile id.
198
-	 * @return string|WP_Error Profile id.
194
+     * Retrieves a customer profile.
195
+     *
196
+     *
197
+     * @param string $profile_id profile id.
198
+     * @return string|WP_Error Profile id.
199 199
      * @link https://developer.authorize.net/api/reference/index.html#customer-profiles-get-customer-profile
200
-	 */
201
-	public function get_customer_profile( $profile_id ) {
200
+     */
201
+    public function get_customer_profile( $profile_id ) {
202 202
 
203 203
         // Generate args.
204 204
         $args = array(
@@ -213,17 +213,17 @@  discard block
 block discarded – undo
213 213
     }
214 214
 
215 215
     /**
216
-	 * Creates a customer profile.
217
-	 *
218
-	 *
216
+     * Creates a customer profile.
217
+     *
218
+     *
219 219
      * @param string $profile_id profile id.
220
-	 * @param WPInv_Invoice $invoice Invoice.
220
+     * @param WPInv_Invoice $invoice Invoice.
221 221
      * @param array $submission_data Posted checkout fields.
222 222
      * @param bool $save Whether or not to save the payment as a token.
223 223
      * @link https://developer.authorize.net/api/reference/index.html#customer-profiles-create-customer-profile
224
-	 * @return string|WP_Error Profile id.
225
-	 */
226
-	public function create_customer_payment_profile( $customer_profile, $invoice, $submission_data, $save ) {
224
+     * @return string|WP_Error Profile id.
225
+     */
226
+    public function create_customer_payment_profile( $customer_profile, $invoice, $submission_data, $save ) {
227 227
 
228 228
         // Remove non-digits from the number
229 229
         $submission_data['authorizenet']['cc_number'] = preg_replace( '/\D/', '', $submission_data['authorizenet']['cc_number'] );
@@ -311,13 +311,13 @@  discard block
 block discarded – undo
311 311
     }
312 312
 
313 313
     /**
314
-	 * Retrieves payment details from cache.
315
-	 *
316
-	 *
314
+     * Retrieves payment details from cache.
315
+     *
316
+     *
317 317
      * @param array $payment_details.
318
-	 * @return array|false Profile id.
319
-	 */
320
-	public function retrieve_payment_profile_from_cache( $payment_details, $customer_profile, $invoice ) {
318
+     * @return array|false Profile id.
319
+     */
320
+    public function retrieve_payment_profile_from_cache( $payment_details, $customer_profile, $invoice ) {
321 321
 
322 322
         $cached_information = get_option( 'getpaid_authorize_net_cached_profiles', array() );
323 323
         $payment_details    = hash_hmac( 'sha256', json_encode( $payment_details ), SECURE_AUTH_KEY );
@@ -342,13 +342,13 @@  discard block
 block discarded – undo
342 342
     }
343 343
 
344 344
     /**
345
-	 * Securely adds payment details to cache.
346
-	 *
347
-	 *
345
+     * Securely adds payment details to cache.
346
+     *
347
+     *
348 348
      * @param array $payment_details.
349 349
      * @param string $payment_profile_id.
350
-	 */
351
-	public function add_payment_profile_to_cache( $payment_details, $payment_profile_id ) {
350
+     */
351
+    public function add_payment_profile_to_cache( $payment_details, $payment_profile_id ) {
352 352
 
353 353
         $cached_information = get_option( 'getpaid_authorize_net_cached_profiles', array() );
354 354
         $cached_information = is_array( $cached_information ) ? $cached_information : array();
@@ -360,15 +360,15 @@  discard block
 block discarded – undo
360 360
     }
361 361
 
362 362
     /**
363
-	 * Retrieves a customer payment profile.
364
-	 *
365
-	 *
366
-	 * @param string $customer_profile_id customer profile id.
363
+     * Retrieves a customer payment profile.
364
+     *
365
+     *
366
+     * @param string $customer_profile_id customer profile id.
367 367
      * @param string $payment_profile_id payment profile id.
368
-	 * @return string|WP_Error Profile id.
368
+     * @return string|WP_Error Profile id.
369 369
      * @link https://developer.authorize.net/api/reference/index.html#customer-profiles-get-customer-payment-profile
370
-	 */
371
-	public function get_customer_payment_profile( $customer_profile_id, $payment_profile_id ) {
370
+     */
371
+    public function get_customer_payment_profile( $customer_profile_id, $payment_profile_id ) {
372 372
 
373 373
         // Generate args.
374 374
         $args = array(
@@ -384,15 +384,15 @@  discard block
 block discarded – undo
384 384
     }
385 385
 
386 386
     /**
387
-	 * Charges a customer payment profile.
388
-	 *
387
+     * Charges a customer payment profile.
388
+     *
389 389
      * @param string $customer_profile_id customer profile id.
390 390
      * @param string $payment_profile_id payment profile id.
391
-	 * @param WPInv_Invoice $invoice Invoice.
391
+     * @param WPInv_Invoice $invoice Invoice.
392 392
      * @link https://developer.authorize.net/api/reference/index.html#payment-transactions-charge-a-customer-profile
393
-	 * @return WP_Error|object
394
-	 */
395
-	public function charge_customer_payment_profile( $customer_profile_id, $payment_profile_id, $invoice ) {
393
+     * @return WP_Error|object
394
+     */
395
+    public function charge_customer_payment_profile( $customer_profile_id, $payment_profile_id, $invoice ) {
396 396
 
397 397
         // Generate args.
398 398
         $args = array(
@@ -438,43 +438,43 @@  discard block
 block discarded – undo
438 438
     }
439 439
 
440 440
     /**
441
-	 * Processes a customer charge.
442
-	 *
441
+     * Processes a customer charge.
442
+     *
443 443
      * @param stdClass $result Api response.
444
-	 * @param WPInv_Invoice $invoice Invoice.
445
-	 */
446
-	public function process_charge_response( $result, $invoice ) {
444
+     * @param WPInv_Invoice $invoice Invoice.
445
+     */
446
+    public function process_charge_response( $result, $invoice ) {
447 447
 
448 448
         wpinv_clear_errors();
449
-		$response_code = (int) $result->transactionResponse->responseCode;
449
+        $response_code = (int) $result->transactionResponse->responseCode;
450 450
 
451 451
         $invoice->add_note( 'Transaction Response: ' . print_r( $result->transactionResponse, true ), false, false, true );
452 452
 
453
-		// Succeeded.
454
-		if ( 1 == $response_code || 4 == $response_code ) {
453
+        // Succeeded.
454
+        if ( 1 == $response_code || 4 == $response_code ) {
455 455
 
456
-			// Maybe set a transaction id.
457
-			if ( ! empty( $result->transactionResponse->transId ) ) {
458
-				$invoice->set_transaction_id( $result->transactionResponse->transId );
459
-			}
456
+            // Maybe set a transaction id.
457
+            if ( ! empty( $result->transactionResponse->transId ) ) {
458
+                $invoice->set_transaction_id( $result->transactionResponse->transId );
459
+            }
460 460
 
461
-			$invoice->add_note( sprintf( __( 'Authentication code: %1$s (%2$s).', 'invoicing' ), $result->transactionResponse->authCode, $result->transactionResponse->accountNumber ), false, false, true );
461
+            $invoice->add_note( sprintf( __( 'Authentication code: %1$s (%2$s).', 'invoicing' ), $result->transactionResponse->authCode, $result->transactionResponse->accountNumber ), false, false, true );
462 462
 
463
-			if ( 1 == $response_code ) {
464
-				return $invoice->mark_paid();
465
-			}
463
+            if ( 1 == $response_code ) {
464
+                return $invoice->mark_paid();
465
+            }
466 466
 
467
-			$invoice->set_status( 'wpi-onhold' );
468
-        	$invoice->add_note(
467
+            $invoice->set_status( 'wpi-onhold' );
468
+            $invoice->add_note(
469 469
                 sprintf(
470 470
                     __( 'Held for review: %s', 'invoicing' ),
471 471
                     $result->transactionResponse->messages->message[0]->description
472 472
                 )
473
-			);
473
+            );
474 474
 
475
-			return $invoice->save();
475
+            return $invoice->save();
476 476
 
477
-		}
477
+        }
478 478
 
479 479
         wpinv_set_error( 'card_declined' );
480 480
 
@@ -486,13 +486,13 @@  discard block
 block discarded – undo
486 486
     }
487 487
 
488 488
     /**
489
-	 * Returns payment information.
490
-	 *
491
-	 *
492
-	 * @param array $card Card details.
493
-	 * @return array
494
-	 */
495
-	public function get_payment_information( $card ) {
489
+     * Returns payment information.
490
+     *
491
+     *
492
+     * @param array $card Card details.
493
+     * @return array
494
+     */
495
+    public function get_payment_information( $card ) {
496 496
         return array(
497 497
 
498 498
             'creditCard' => array(
@@ -505,25 +505,25 @@  discard block
 block discarded – undo
505 505
     }
506 506
 
507 507
     /**
508
-	 * Returns the customer profile meta name.
509
-	 *
510
-	 *
511
-	 * @param WPInv_Invoice $invoice Invoice.
512
-	 * @return string
513
-	 */
514
-	public function get_customer_profile_meta_name( $invoice ) {
508
+     * Returns the customer profile meta name.
509
+     *
510
+     *
511
+     * @param WPInv_Invoice $invoice Invoice.
512
+     * @return string
513
+     */
514
+    public function get_customer_profile_meta_name( $invoice ) {
515 515
         return $this->is_sandbox( $invoice ) ? 'getpaid_authorizenet_sandbox_customer_profile_id' : 'getpaid_authorizenet_customer_profile_id';
516 516
     }
517 517
 
518 518
     /**
519
-	 * Validates the submitted data.
520
-	 *
521
-	 *
522
-	 * @param array $submission_data Posted checkout fields.
519
+     * Validates the submitted data.
520
+     *
521
+     *
522
+     * @param array $submission_data Posted checkout fields.
523 523
      * @param WPInv_Invoice $invoice
524
-	 * @return WP_Error|string The payment profile id
525
-	 */
526
-	public function validate_submission_data( $submission_data, $invoice ) {
524
+     * @return WP_Error|string The payment profile id
525
+     */
526
+    public function validate_submission_data( $submission_data, $invoice ) {
527 527
 
528 528
         // Validate authentication details.
529 529
         $auth = $this->get_auth_params();
@@ -555,13 +555,13 @@  discard block
 block discarded – undo
555 555
     }
556 556
 
557 557
     /**
558
-	 * Returns invoice line items.
559
-	 *
560
-	 *
561
-	 * @param WPInv_Invoice $invoice Invoice.
562
-	 * @return array
563
-	 */
564
-	public function get_line_items( $invoice ) {
558
+     * Returns invoice line items.
559
+     *
560
+     *
561
+     * @param WPInv_Invoice $invoice Invoice.
562
+     * @return array
563
+     */
564
+    public function get_line_items( $invoice ) {
565 565
         $items = array();
566 566
 
567 567
         foreach ( $invoice->get_items() as $item ) {
@@ -598,15 +598,15 @@  discard block
 block discarded – undo
598 598
     }
599 599
 
600 600
     /**
601
-	 * Process Payment.
602
-	 *
603
-	 *
604
-	 * @param WPInv_Invoice $invoice Invoice.
605
-	 * @param array $submission_data Posted checkout fields.
606
-	 * @param GetPaid_Payment_Form_Submission $submission Checkout submission.
607
-	 * @return array
608
-	 */
609
-	public function process_payment( $invoice, $submission_data, $submission ) {
601
+     * Process Payment.
602
+     *
603
+     *
604
+     * @param WPInv_Invoice $invoice Invoice.
605
+     * @param array $submission_data Posted checkout fields.
606
+     * @param GetPaid_Payment_Form_Submission $submission Checkout submission.
607
+     * @return array
608
+     */
609
+    public function process_payment( $invoice, $submission_data, $submission ) {
610 610
 
611 611
         // Validate the submitted data.
612 612
         $payment_profile_id = $this->validate_submission_data( $submission_data, $invoice );
@@ -639,45 +639,45 @@  discard block
 block discarded – undo
639 639
 
640 640
         exit;
641 641
 
642
-	}
642
+    }
643 643
 
644
-	/**
645
-	 * Processes the initial payment.
646
-	 *
644
+    /**
645
+     * Processes the initial payment.
646
+     *
647 647
      * @param WPInv_Invoice $invoice Invoice.
648
-	 */
649
-	protected function process_initial_payment( $invoice ) {
648
+     */
649
+    protected function process_initial_payment( $invoice ) {
650 650
 
651
-		$payment_profile_id = get_post_meta( $invoice->get_id(), 'getpaid_authorizenet_profile_id', true );
651
+        $payment_profile_id = get_post_meta( $invoice->get_id(), 'getpaid_authorizenet_profile_id', true );
652 652
         $customer_profile   = get_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), true );
653
-		$result             = $this->charge_customer_payment_profile( $customer_profile, $payment_profile_id, $invoice );
653
+        $result             = $this->charge_customer_payment_profile( $customer_profile, $payment_profile_id, $invoice );
654 654
 
655
-		// Do we have an error?
656
-		if ( is_wp_error( $result ) ) {
657
-			wpinv_set_error( $result->get_error_code(), $result->get_error_message() );
658
-			wpinv_send_back_to_checkout( $invoice );
659
-		}
655
+        // Do we have an error?
656
+        if ( is_wp_error( $result ) ) {
657
+            wpinv_set_error( $result->get_error_code(), $result->get_error_message() );
658
+            wpinv_send_back_to_checkout( $invoice );
659
+        }
660 660
 
661
-		// Process the response.
662
-		$this->process_charge_response( $result, $invoice );
661
+        // Process the response.
662
+        $this->process_charge_response( $result, $invoice );
663 663
 
664
-		if ( wpinv_get_errors() ) {
665
-			wpinv_send_back_to_checkout( $invoice );
666
-		}
664
+        if ( wpinv_get_errors() ) {
665
+            wpinv_send_back_to_checkout( $invoice );
666
+        }
667 667
 
668
-	}
668
+    }
669 669
 
670 670
     /**
671
-	 * Processes recurring payments.
672
-	 *
671
+     * Processes recurring payments.
672
+     *
673 673
      * @param WPInv_Invoice $invoice Invoice.
674 674
      * @param WPInv_Subscription[]|WPInv_Subscription $subscriptions Subscriptions.
675
-	 */
676
-	public function process_subscription( $invoice, $subscriptions ) {
675
+     */
676
+    public function process_subscription( $invoice, $subscriptions ) {
677 677
 
678 678
         // Check if there is an initial amount to charge.
679 679
         if ( (float) $invoice->get_total() > 0 ) {
680
-			$this->process_initial_payment( $invoice );
680
+            $this->process_initial_payment( $invoice );
681 681
         }
682 682
 
683 683
         // Activate the subscriptions.
@@ -695,36 +695,36 @@  discard block
 block discarded – undo
695 695
             }
696 696
         }
697 697
 
698
-		// Redirect to the success page.
698
+        // Redirect to the success page.
699 699
         wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) );
700 700
 
701 701
     }
702 702
 
703
-	/**
704
-	 * (Maybe) renews an authorize.net subscription profile.
705
-	 *
706
-	 *
703
+    /**
704
+     * (Maybe) renews an authorize.net subscription profile.
705
+     *
706
+     *
707 707
      * @param WPInv_Subscription $subscription
708
-	 */
709
-	public function maybe_renew_subscription( $subscription ) {
708
+     */
709
+    public function maybe_renew_subscription( $subscription ) {
710 710
 
711 711
         // Ensure its our subscription && it's active.
712 712
         if ( $this->id === $subscription->get_gateway() && $subscription->has_status( 'active trialling' ) ) {
713 713
             $this->renew_subscription( $subscription );
714 714
         }
715 715
 
716
-	}
716
+    }
717 717
 
718 718
     /**
719
-	 * Renews a subscription.
720
-	 *
719
+     * Renews a subscription.
720
+     *
721 721
      * @param WPInv_Subscription $subscription
722
-	 */
723
-	public function renew_subscription( $subscription ) {
722
+     */
723
+    public function renew_subscription( $subscription ) {
724 724
 
725
-		// Generate the renewal invoice.
726
-		$new_invoice = $subscription->create_payment();
727
-		$old_invoice = $subscription->get_parent_payment();
725
+        // Generate the renewal invoice.
726
+        $new_invoice = $subscription->create_payment();
727
+        $old_invoice = $subscription->get_parent_payment();
728 728
 
729 729
         if ( empty( $new_invoice ) ) {
730 730
             $old_invoice->add_note( __( 'Error generating a renewal invoice.', 'invoicing' ), false, false, false );
@@ -733,37 +733,37 @@  discard block
 block discarded – undo
733 733
         }
734 734
 
735 735
         // Charge the payment method.
736
-		$payment_profile_id = get_post_meta( $old_invoice->get_id(), 'getpaid_authorizenet_profile_id', true );
737
-		$customer_profile   = get_user_meta( $old_invoice->get_user_id(), $this->get_customer_profile_meta_name( $old_invoice ), true );
738
-		$result             = $this->charge_customer_payment_profile( $customer_profile, $payment_profile_id, $new_invoice );
739
-
740
-		// Do we have an error?
741
-		if ( is_wp_error( $result ) ) {
742
-
743
-			$old_invoice->add_note(
744
-				sprintf( __( 'Error renewing subscription : ( %s ).', 'invoicing' ), $result->get_error_message() ),
745
-				true,
746
-				false,
747
-				true
748
-			);
749
-			$subscription->failing();
750
-			return;
751
-
752
-		}
753
-
754
-		// Process the response.
755
-		$this->process_charge_response( $result, $new_invoice );
756
-
757
-		if ( wpinv_get_errors() ) {
758
-
759
-			$old_invoice->add_note(
760
-				sprintf( __( 'Error renewing subscription : ( %s ).', 'invoicing' ), getpaid_get_errors_html() ),
761
-				true,
762
-				false,
763
-				true
764
-			);
765
-			$subscription->failing();
766
-			return;
736
+        $payment_profile_id = get_post_meta( $old_invoice->get_id(), 'getpaid_authorizenet_profile_id', true );
737
+        $customer_profile   = get_user_meta( $old_invoice->get_user_id(), $this->get_customer_profile_meta_name( $old_invoice ), true );
738
+        $result             = $this->charge_customer_payment_profile( $customer_profile, $payment_profile_id, $new_invoice );
739
+
740
+        // Do we have an error?
741
+        if ( is_wp_error( $result ) ) {
742
+
743
+            $old_invoice->add_note(
744
+                sprintf( __( 'Error renewing subscription : ( %s ).', 'invoicing' ), $result->get_error_message() ),
745
+                true,
746
+                false,
747
+                true
748
+            );
749
+            $subscription->failing();
750
+            return;
751
+
752
+        }
753
+
754
+        // Process the response.
755
+        $this->process_charge_response( $result, $new_invoice );
756
+
757
+        if ( wpinv_get_errors() ) {
758
+
759
+            $old_invoice->add_note(
760
+                sprintf( __( 'Error renewing subscription : ( %s ).', 'invoicing' ), getpaid_get_errors_html() ),
761
+                true,
762
+                false,
763
+                true
764
+            );
765
+            $subscription->failing();
766
+            return;
767 767
 
768 768
         }
769 769
 
@@ -776,13 +776,13 @@  discard block
 block discarded – undo
776 776
     }
777 777
 
778 778
     /**
779
-	 * Processes invoice addons.
780
-	 *
781
-	 * @param WPInv_Invoice $invoice
782
-	 * @param GetPaid_Form_Item[] $items
783
-	 * @return WPInv_Invoice
784
-	 */
785
-	public function process_addons( $invoice, $items ) {
779
+     * Processes invoice addons.
780
+     *
781
+     * @param WPInv_Invoice $invoice
782
+     * @param GetPaid_Form_Item[] $items
783
+     * @return WPInv_Invoice
784
+     */
785
+    public function process_addons( $invoice, $items ) {
786 786
 
787 787
         global $getpaid_authorize_addons;
788 788
 
@@ -801,7 +801,7 @@  discard block
 block discarded – undo
801 801
         $invoice->recalculate_total();
802 802
 
803 803
         $payment_profile_id = get_post_meta( $invoice->get_id(), 'getpaid_authorizenet_profile_id', true );
804
-		$customer_profile   = get_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), true );
804
+        $customer_profile   = get_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), true );
805 805
 
806 806
         add_filter( 'getpaid_authorizenet_charge_customer_payment_profile_args', array( $this, 'filter_addons_request' ), 10, 2 );
807 807
         $result = $this->charge_customer_payment_profile( $customer_profile, $payment_profile_id, $invoice );
@@ -816,11 +816,11 @@  discard block
 block discarded – undo
816 816
     }
817 817
 
818 818
     /**
819
-	 * Processes invoice addons.
820
-	 *
819
+     * Processes invoice addons.
820
+     *
821 821
      * @param array $args
822
-	 * @return array
823
-	 */
822
+     * @return array
823
+     */
824 824
     public function filter_addons_request( $args ) {
825 825
 
826 826
         global $getpaid_authorize_addons;
@@ -854,11 +854,11 @@  discard block
 block discarded – undo
854 854
     }
855 855
 
856 856
     /**
857
-	 * Filters the gateway settings.
858
-	 *
859
-	 * @param array $admin_settings
860
-	 */
861
-	public function admin_settings( $admin_settings ) {
857
+     * Filters the gateway settings.
858
+     *
859
+     * @param array $admin_settings
860
+     */
861
+    public function admin_settings( $admin_settings ) {
862 862
 
863 863
         $currencies = sprintf(
864 864
             __( 'Supported Currencies: %s', 'invoicing' ),
@@ -898,7 +898,7 @@  discard block
 block discarded – undo
898 898
             'readonly' => true,
899 899
         );
900 900
 
901
-		return $admin_settings;
902
-	}
901
+        return $admin_settings;
902
+    }
903 903
 
904 904
 }
Please login to merge, or discard this patch.
Spacing   +206 added lines, -206 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
4 4
  *
5 5
  */
6 6
 
7
-defined( 'ABSPATH' ) || exit;
7
+defined('ABSPATH') || exit;
8 8
 
9 9
 /**
10 10
  * Authorize.net Payment Gateway class.
@@ -61,7 +61,7 @@  discard block
 block discarded – undo
61 61
 	 *
62 62
 	 * @var array
63 63
 	 */
64
-	public $currencies = array( 'USD', 'CAD', 'GBP', 'DKK', 'NOK', 'PLN', 'SEK', 'AUD', 'EUR', 'NZD' );
64
+	public $currencies = array('USD', 'CAD', 'GBP', 'DKK', 'NOK', 'PLN', 'SEK', 'AUD', 'EUR', 'NZD');
65 65
 
66 66
     /**
67 67
 	 * URL to view a transaction.
@@ -75,12 +75,12 @@  discard block
 block discarded – undo
75 75
 	 */
76 76
 	public function __construct() {
77 77
 
78
-        $this->title                = __( 'Credit Card / Debit Card', 'invoicing' );
79
-        $this->method_title         = __( 'Authorize.Net', 'invoicing' );
80
-        $this->notify_url           = getpaid_get_non_query_string_ipn_url( $this->id );
78
+        $this->title                = __('Credit Card / Debit Card', 'invoicing');
79
+        $this->method_title         = __('Authorize.Net', 'invoicing');
80
+        $this->notify_url           = getpaid_get_non_query_string_ipn_url($this->id);
81 81
 
82
-        add_action( 'getpaid_should_renew_subscription', array( $this, 'maybe_renew_subscription' ) );
83
-        add_filter( 'getpaid_authorizenet_sandbox_notice', array( $this, 'sandbox_notice' ) );
82
+        add_action('getpaid_should_renew_subscription', array($this, 'maybe_renew_subscription'));
83
+        add_filter('getpaid_authorizenet_sandbox_notice', array($this, 'sandbox_notice'));
84 84
         parent::__construct();
85 85
     }
86 86
 
@@ -90,13 +90,13 @@  discard block
 block discarded – undo
90 90
 	 * @param int $invoice_id 0 or invoice id.
91 91
 	 * @param GetPaid_Payment_Form $form Current payment form.
92 92
 	 */
93
-    public function payment_fields( $invoice_id, $form ) {
93
+    public function payment_fields($invoice_id, $form) {
94 94
 
95 95
         // Let the user select a payment method.
96 96
         $this->saved_payment_methods();
97 97
 
98 98
         // Show the credit card entry form.
99
-        $this->new_payment_method_entry( $this->get_cc_form( true ) );
99
+        $this->new_payment_method_entry($this->get_cc_form(true));
100 100
     }
101 101
 
102 102
     /**
@@ -109,79 +109,79 @@  discard block
 block discarded – undo
109 109
      * @link https://developer.authorize.net/api/reference/index.html#customer-profiles-create-customer-profile
110 110
 	 * @return string|WP_Error Payment profile id.
111 111
 	 */
112
-	public function create_customer_profile( $invoice, $submission_data, $save = true ) {
112
+	public function create_customer_profile($invoice, $submission_data, $save = true) {
113 113
 
114 114
         // Remove non-digits from the number
115
-        $submission_data['authorizenet']['cc_number'] = preg_replace( '/\D/', '', $submission_data['authorizenet']['cc_number'] );
115
+        $submission_data['authorizenet']['cc_number'] = preg_replace('/\D/', '', $submission_data['authorizenet']['cc_number']);
116 116
 
117 117
         // Generate args.
118 118
         $args = array(
119 119
             'createCustomerProfileRequest' => array(
120 120
                 'merchantAuthentication' => $this->get_auth_params(),
121 121
                 'profile'                => array(
122
-                    'merchantCustomerId' => getpaid_limit_length( $invoice->get_user_id(), 20 ),
123
-                    'description'        => getpaid_limit_length( $invoice->get_full_name(), 255 ),
124
-                    'email'              => getpaid_limit_length( $invoice->get_email(), 255 ),
122
+                    'merchantCustomerId' => getpaid_limit_length($invoice->get_user_id(), 20),
123
+                    'description'        => getpaid_limit_length($invoice->get_full_name(), 255),
124
+                    'email'              => getpaid_limit_length($invoice->get_email(), 255),
125 125
                     'paymentProfiles'    => array(
126 126
                         'customerType' => 'individual',
127 127
 
128 128
                         // Billing information.
129 129
                         'billTo'       => array(
130
-                            'firstName' => getpaid_limit_length( $invoice->get_first_name(), 50 ),
131
-                            'lastName'  => getpaid_limit_length( $invoice->get_last_name(), 50 ),
132
-                            'address'   => getpaid_limit_length( $invoice->get_address(), 60 ),
133
-                            'city'      => getpaid_limit_length( $invoice->get_city(), 40 ),
134
-                            'state'     => getpaid_limit_length( $invoice->get_state(), 40 ),
135
-                            'zip'       => getpaid_limit_length( $invoice->get_zip(), 20 ),
136
-                            'country'   => getpaid_limit_length( $invoice->get_country(), 60 ),
130
+                            'firstName' => getpaid_limit_length($invoice->get_first_name(), 50),
131
+                            'lastName'  => getpaid_limit_length($invoice->get_last_name(), 50),
132
+                            'address'   => getpaid_limit_length($invoice->get_address(), 60),
133
+                            'city'      => getpaid_limit_length($invoice->get_city(), 40),
134
+                            'state'     => getpaid_limit_length($invoice->get_state(), 40),
135
+                            'zip'       => getpaid_limit_length($invoice->get_zip(), 20),
136
+                            'country'   => getpaid_limit_length($invoice->get_country(), 60),
137 137
                         ),
138 138
 
139 139
                         // Payment information.
140
-                        'payment'      => $this->get_payment_information( $submission_data['authorizenet'] ),
140
+                        'payment'      => $this->get_payment_information($submission_data['authorizenet']),
141 141
                     ),
142 142
                 ),
143
-                'validationMode'         => $this->is_sandbox( $invoice ) ? 'testMode' : 'liveMode',
143
+                'validationMode'         => $this->is_sandbox($invoice) ? 'testMode' : 'liveMode',
144 144
             ),
145 145
         );
146 146
 
147
-        $response = $this->post( apply_filters( 'getpaid_authorizenet_customer_profile_args', $args, $invoice ), $invoice );
147
+        $response = $this->post(apply_filters('getpaid_authorizenet_customer_profile_args', $args, $invoice), $invoice);
148 148
 
149
-        if ( is_wp_error( $response ) ) {
149
+        if (is_wp_error($response)) {
150 150
 
151 151
             // In case the payment profile already exists remotely.
152
-            if ( 'dup_payment_profile' === $response->get_error_code() ) {
153
-                $customer_profile_id = strtok( $response->get_error_message(), '.' );
154
-                update_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), $customer_profile_id );
155
-                return strtok( '.' );
152
+            if ('dup_payment_profile' === $response->get_error_code()) {
153
+                $customer_profile_id = strtok($response->get_error_message(), '.');
154
+                update_user_meta($invoice->get_user_id(), $this->get_customer_profile_meta_name($invoice), $customer_profile_id);
155
+                return strtok('.');
156 156
             }
157 157
 
158 158
             // In case the customer profile already exists remotely.
159
-            if ( 'E00039' === $response->get_error_code() ) {
160
-                $customer_profile_id = str_replace( 'A duplicate record with ID ', '', $response->get_error_message() );
161
-                $customer_profile_id = str_replace( ' already exists.', '', $customer_profile_id );
162
-                return $this->create_customer_payment_profile( trim( $customer_profile_id ), $invoice, $submission_data, $save );
159
+            if ('E00039' === $response->get_error_code()) {
160
+                $customer_profile_id = str_replace('A duplicate record with ID ', '', $response->get_error_message());
161
+                $customer_profile_id = str_replace(' already exists.', '', $customer_profile_id);
162
+                return $this->create_customer_payment_profile(trim($customer_profile_id), $invoice, $submission_data, $save);
163 163
             }
164 164
 
165 165
             return $response;
166 166
         }
167 167
 
168
-        update_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), $response->customerProfileId );
168
+        update_user_meta($invoice->get_user_id(), $this->get_customer_profile_meta_name($invoice), $response->customerProfileId);
169 169
 
170 170
         // Save the payment token.
171
-        if ( $save ) {
171
+        if ($save) {
172 172
             $this->save_token(
173 173
                 array(
174 174
                     'id'      => $response->customerPaymentProfileIdList[0],
175
-                    'name'    => getpaid_get_card_name( $submission_data['authorizenet']['cc_number'] ) . '&middot;&middot;&middot;&middot;' . substr( $submission_data['authorizenet']['cc_number'], -4 ),
175
+                    'name'    => getpaid_get_card_name($submission_data['authorizenet']['cc_number']) . '&middot;&middot;&middot;&middot;' . substr($submission_data['authorizenet']['cc_number'], -4),
176 176
                     'default' => true,
177
-                    'type'    => $this->is_sandbox( $invoice ) ? 'sandbox' : 'live',
177
+                    'type'    => $this->is_sandbox($invoice) ? 'sandbox' : 'live',
178 178
                 )
179 179
             );
180 180
         }
181 181
 
182 182
         // Add a note about the validation response.
183 183
         $invoice->add_note(
184
-            sprintf( __( 'Created Authorize.NET customer profile: %s', 'invoicing' ), $response->validationDirectResponseList[0] ),
184
+            sprintf(__('Created Authorize.NET customer profile: %s', 'invoicing'), $response->validationDirectResponseList[0]),
185 185
             false,
186 186
             false,
187 187
             true
@@ -198,7 +198,7 @@  discard block
 block discarded – undo
198 198
 	 * @return string|WP_Error Profile id.
199 199
      * @link https://developer.authorize.net/api/reference/index.html#customer-profiles-get-customer-profile
200 200
 	 */
201
-	public function get_customer_profile( $profile_id ) {
201
+	public function get_customer_profile($profile_id) {
202 202
 
203 203
         // Generate args.
204 204
         $args = array(
@@ -208,7 +208,7 @@  discard block
 block discarded – undo
208 208
             ),
209 209
         );
210 210
 
211
-        return $this->post( $args, false );
211
+        return $this->post($args, false);
212 212
 
213 213
     }
214 214
 
@@ -223,18 +223,18 @@  discard block
 block discarded – undo
223 223
      * @link https://developer.authorize.net/api/reference/index.html#customer-profiles-create-customer-profile
224 224
 	 * @return string|WP_Error Profile id.
225 225
 	 */
226
-	public function create_customer_payment_profile( $customer_profile, $invoice, $submission_data, $save ) {
226
+	public function create_customer_payment_profile($customer_profile, $invoice, $submission_data, $save) {
227 227
 
228 228
         // Remove non-digits from the number
229
-        $submission_data['authorizenet']['cc_number'] = preg_replace( '/\D/', '', $submission_data['authorizenet']['cc_number'] );
229
+        $submission_data['authorizenet']['cc_number'] = preg_replace('/\D/', '', $submission_data['authorizenet']['cc_number']);
230 230
 
231 231
         // Prepare card details.
232
-        $payment_information                          = $this->get_payment_information( $submission_data['authorizenet'] );
232
+        $payment_information                          = $this->get_payment_information($submission_data['authorizenet']);
233 233
 
234 234
         // Authorize.NET does not support saving the same card twice.
235
-        $cached_information                           = $this->retrieve_payment_profile_from_cache( $payment_information, $customer_profile, $invoice );
235
+        $cached_information                           = $this->retrieve_payment_profile_from_cache($payment_information, $customer_profile, $invoice);
236 236
 
237
-        if ( $cached_information ) {
237
+        if ($cached_information) {
238 238
             return $cached_information;
239 239
         }
240 240
 
@@ -247,34 +247,34 @@  discard block
 block discarded – undo
247 247
 
248 248
                     // Billing information.
249 249
                     'billTo'  => array(
250
-                        'firstName' => getpaid_limit_length( $invoice->get_first_name(), 50 ),
251
-                        'lastName'  => getpaid_limit_length( $invoice->get_last_name(), 50 ),
252
-                        'address'   => getpaid_limit_length( $invoice->get_address(), 60 ),
253
-                        'city'      => getpaid_limit_length( $invoice->get_city(), 40 ),
254
-                        'state'     => getpaid_limit_length( $invoice->get_state(), 40 ),
255
-                        'zip'       => getpaid_limit_length( $invoice->get_zip(), 20 ),
256
-                        'country'   => getpaid_limit_length( $invoice->get_country(), 60 ),
250
+                        'firstName' => getpaid_limit_length($invoice->get_first_name(), 50),
251
+                        'lastName'  => getpaid_limit_length($invoice->get_last_name(), 50),
252
+                        'address'   => getpaid_limit_length($invoice->get_address(), 60),
253
+                        'city'      => getpaid_limit_length($invoice->get_city(), 40),
254
+                        'state'     => getpaid_limit_length($invoice->get_state(), 40),
255
+                        'zip'       => getpaid_limit_length($invoice->get_zip(), 20),
256
+                        'country'   => getpaid_limit_length($invoice->get_country(), 60),
257 257
                     ),
258 258
 
259 259
                     // Payment information.
260 260
                     'payment' => $payment_information,
261 261
                 ),
262
-                'validationMode'         => $this->is_sandbox( $invoice ) ? 'testMode' : 'liveMode',
262
+                'validationMode'         => $this->is_sandbox($invoice) ? 'testMode' : 'liveMode',
263 263
             ),
264 264
         );
265 265
 
266
-        $response = $this->post( apply_filters( 'getpaid_authorizenet_create_customer_payment_profile_args', $args, $invoice ), $invoice );
266
+        $response = $this->post(apply_filters('getpaid_authorizenet_create_customer_payment_profile_args', $args, $invoice), $invoice);
267 267
 
268
-        if ( is_wp_error( $response ) ) {
268
+        if (is_wp_error($response)) {
269 269
 
270 270
             // In case the payment profile already exists remotely.
271
-            if ( 'dup_payment_profile' == $response->get_error_code() ) {
272
-                $customer_profile_id = strtok( $response->get_error_message(), '.' );
273
-                $payment_profile_id  = strtok( '.' );
274
-                update_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), $customer_profile_id );
271
+            if ('dup_payment_profile' == $response->get_error_code()) {
272
+                $customer_profile_id = strtok($response->get_error_message(), '.');
273
+                $payment_profile_id  = strtok('.');
274
+                update_user_meta($invoice->get_user_id(), $this->get_customer_profile_meta_name($invoice), $customer_profile_id);
275 275
 
276 276
                 // Cache payment profile id.
277
-                $this->add_payment_profile_to_cache( $payment_information, $payment_profile_id );
277
+                $this->add_payment_profile_to_cache($payment_information, $payment_profile_id);
278 278
 
279 279
                 return $payment_profile_id;
280 280
             }
@@ -283,29 +283,29 @@  discard block
 block discarded – undo
283 283
         }
284 284
 
285 285
         // Save the payment token.
286
-        if ( $save ) {
286
+        if ($save) {
287 287
             $this->save_token(
288 288
                 array(
289 289
                     'id'      => $response->customerPaymentProfileId,
290
-                    'name'    => getpaid_get_card_name( $submission_data['authorizenet']['cc_number'] ) . ' &middot;&middot;&middot;&middot; ' . substr( $submission_data['authorizenet']['cc_number'], -4 ),
290
+                    'name'    => getpaid_get_card_name($submission_data['authorizenet']['cc_number']) . ' &middot;&middot;&middot;&middot; ' . substr($submission_data['authorizenet']['cc_number'], -4),
291 291
                     'default' => true,
292
-                    'type'    => $this->is_sandbox( $invoice ) ? 'sandbox' : 'live',
292
+                    'type'    => $this->is_sandbox($invoice) ? 'sandbox' : 'live',
293 293
                 )
294 294
             );
295 295
         }
296 296
 
297 297
         // Cache payment profile id.
298
-        $this->add_payment_profile_to_cache( $payment_information, $response->customerPaymentProfileId );
298
+        $this->add_payment_profile_to_cache($payment_information, $response->customerPaymentProfileId);
299 299
 
300 300
         // Add a note about the validation response.
301 301
         $invoice->add_note(
302
-            sprintf( __( 'Saved Authorize.NET payment profile: %s', 'invoicing' ), $response->validationDirectResponse ),
302
+            sprintf(__('Saved Authorize.NET payment profile: %s', 'invoicing'), $response->validationDirectResponse),
303 303
             false,
304 304
             false,
305 305
             true
306 306
         );
307 307
 
308
-        update_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), $customer_profile );
308
+        update_user_meta($invoice->get_user_id(), $this->get_customer_profile_meta_name($invoice), $customer_profile);
309 309
 
310 310
         return $response->customerPaymentProfileId;
311 311
     }
@@ -317,12 +317,12 @@  discard block
 block discarded – undo
317 317
      * @param array $payment_details.
318 318
 	 * @return array|false Profile id.
319 319
 	 */
320
-	public function retrieve_payment_profile_from_cache( $payment_details, $customer_profile, $invoice ) {
320
+	public function retrieve_payment_profile_from_cache($payment_details, $customer_profile, $invoice) {
321 321
 
322
-        $cached_information = get_option( 'getpaid_authorize_net_cached_profiles', array() );
323
-        $payment_details    = hash_hmac( 'sha256', json_encode( $payment_details ), SECURE_AUTH_KEY );
322
+        $cached_information = get_option('getpaid_authorize_net_cached_profiles', array());
323
+        $payment_details    = hash_hmac('sha256', json_encode($payment_details), SECURE_AUTH_KEY);
324 324
 
325
-        if ( ! is_array( $cached_information ) || ! array_key_exists( $payment_details, $cached_information ) ) {
325
+        if (!is_array($cached_information) || !array_key_exists($payment_details, $cached_information)) {
326 326
             return false;
327 327
         }
328 328
 
@@ -331,13 +331,13 @@  discard block
 block discarded – undo
331 331
             'getCustomerPaymentProfileRequest' => array(
332 332
                 'merchantAuthentication'   => $this->get_auth_params(),
333 333
                 'customerProfileId'        => $customer_profile,
334
-                'customerPaymentProfileId' => $cached_information[ $payment_details ],
334
+                'customerPaymentProfileId' => $cached_information[$payment_details],
335 335
             ),
336 336
         );
337 337
 
338
-        $response = $this->post( $args, $invoice );
338
+        $response = $this->post($args, $invoice);
339 339
 
340
-        return is_wp_error( $response ) ? false : $cached_information[ $payment_details ];
340
+        return is_wp_error($response) ? false : $cached_information[$payment_details];
341 341
 
342 342
     }
343 343
 
@@ -348,14 +348,14 @@  discard block
 block discarded – undo
348 348
      * @param array $payment_details.
349 349
      * @param string $payment_profile_id.
350 350
 	 */
351
-	public function add_payment_profile_to_cache( $payment_details, $payment_profile_id ) {
351
+	public function add_payment_profile_to_cache($payment_details, $payment_profile_id) {
352 352
 
353
-        $cached_information = get_option( 'getpaid_authorize_net_cached_profiles', array() );
354
-        $cached_information = is_array( $cached_information ) ? $cached_information : array();
355
-        $payment_details    = hash_hmac( 'sha256', json_encode( $payment_details ), SECURE_AUTH_KEY );
353
+        $cached_information = get_option('getpaid_authorize_net_cached_profiles', array());
354
+        $cached_information = is_array($cached_information) ? $cached_information : array();
355
+        $payment_details    = hash_hmac('sha256', json_encode($payment_details), SECURE_AUTH_KEY);
356 356
 
357
-        $cached_information[ $payment_details ] = $payment_profile_id;
358
-        update_option( 'getpaid_authorize_net_cached_profiles', $cached_information );
357
+        $cached_information[$payment_details] = $payment_profile_id;
358
+        update_option('getpaid_authorize_net_cached_profiles', $cached_information);
359 359
 
360 360
     }
361 361
 
@@ -368,7 +368,7 @@  discard block
 block discarded – undo
368 368
 	 * @return string|WP_Error Profile id.
369 369
      * @link https://developer.authorize.net/api/reference/index.html#customer-profiles-get-customer-payment-profile
370 370
 	 */
371
-	public function get_customer_payment_profile( $customer_profile_id, $payment_profile_id ) {
371
+	public function get_customer_payment_profile($customer_profile_id, $payment_profile_id) {
372 372
 
373 373
         // Generate args.
374 374
         $args = array(
@@ -379,7 +379,7 @@  discard block
 block discarded – undo
379 379
             ),
380 380
         );
381 381
 
382
-        return $this->post( $args, false );
382
+        return $this->post($args, false);
383 383
 
384 384
     }
385 385
 
@@ -392,7 +392,7 @@  discard block
 block discarded – undo
392 392
      * @link https://developer.authorize.net/api/reference/index.html#payment-transactions-charge-a-customer-profile
393 393
 	 * @return WP_Error|object
394 394
 	 */
395
-	public function charge_customer_payment_profile( $customer_profile_id, $payment_profile_id, $invoice ) {
395
+	public function charge_customer_payment_profile($customer_profile_id, $payment_profile_id, $invoice) {
396 396
 
397 397
         // Generate args.
398 398
         $args = array(
@@ -412,28 +412,28 @@  discard block
 block discarded – undo
412 412
                         ),
413 413
                     ),
414 414
                     'order'           => array(
415
-                        'invoiceNumber' => getpaid_limit_length( $invoice->get_number(), 20 ),
415
+                        'invoiceNumber' => getpaid_limit_length($invoice->get_number(), 20),
416 416
                     ),
417
-                    'lineItems'       => array( 'lineItem' => $this->get_line_items( $invoice ) ),
417
+                    'lineItems'       => array('lineItem' => $this->get_line_items($invoice)),
418 418
                     'tax'             => array(
419 419
                         'amount' => $invoice->get_total_tax(),
420
-                        'name'   => __( 'TAX', 'invoicing' ),
420
+                        'name'   => __('TAX', 'invoicing'),
421 421
                     ),
422
-                    'poNumber'        => getpaid_limit_length( $invoice->get_number(), 25 ),
422
+                    'poNumber'        => getpaid_limit_length($invoice->get_number(), 25),
423 423
                     'customer'        => array(
424
-                        'id'    => getpaid_limit_length( $invoice->get_user_id(), 25 ),
425
-                        'email' => getpaid_limit_length( $invoice->get_email(), 25 ),
424
+                        'id'    => getpaid_limit_length($invoice->get_user_id(), 25),
425
+                        'email' => getpaid_limit_length($invoice->get_email(), 25),
426 426
                     ),
427 427
                     'customerIP'      => $invoice->get_ip(),
428 428
                 ),
429 429
             ),
430 430
         );
431 431
 
432
-        if ( 0 == $invoice->get_total_tax() ) {
433
-            unset( $args['createTransactionRequest']['transactionRequest']['tax'] );
432
+        if (0 == $invoice->get_total_tax()) {
433
+            unset($args['createTransactionRequest']['transactionRequest']['tax']);
434 434
         }
435 435
 
436
-        return $this->post( apply_filters( 'getpaid_authorizenet_charge_customer_payment_profile_args', $args, $invoice ), $invoice );
436
+        return $this->post(apply_filters('getpaid_authorizenet_charge_customer_payment_profile_args', $args, $invoice), $invoice);
437 437
 
438 438
     }
439 439
 
@@ -443,31 +443,31 @@  discard block
 block discarded – undo
443 443
      * @param stdClass $result Api response.
444 444
 	 * @param WPInv_Invoice $invoice Invoice.
445 445
 	 */
446
-	public function process_charge_response( $result, $invoice ) {
446
+	public function process_charge_response($result, $invoice) {
447 447
 
448 448
         wpinv_clear_errors();
449 449
 		$response_code = (int) $result->transactionResponse->responseCode;
450 450
 
451
-        $invoice->add_note( 'Transaction Response: ' . print_r( $result->transactionResponse, true ), false, false, true );
451
+        $invoice->add_note('Transaction Response: ' . print_r($result->transactionResponse, true), false, false, true);
452 452
 
453 453
 		// Succeeded.
454
-		if ( 1 == $response_code || 4 == $response_code ) {
454
+		if (1 == $response_code || 4 == $response_code) {
455 455
 
456 456
 			// Maybe set a transaction id.
457
-			if ( ! empty( $result->transactionResponse->transId ) ) {
458
-				$invoice->set_transaction_id( $result->transactionResponse->transId );
457
+			if (!empty($result->transactionResponse->transId)) {
458
+				$invoice->set_transaction_id($result->transactionResponse->transId);
459 459
 			}
460 460
 
461
-			$invoice->add_note( sprintf( __( 'Authentication code: %1$s (%2$s).', 'invoicing' ), $result->transactionResponse->authCode, $result->transactionResponse->accountNumber ), false, false, true );
461
+			$invoice->add_note(sprintf(__('Authentication code: %1$s (%2$s).', 'invoicing'), $result->transactionResponse->authCode, $result->transactionResponse->accountNumber), false, false, true);
462 462
 
463
-			if ( 1 == $response_code ) {
463
+			if (1 == $response_code) {
464 464
 				return $invoice->mark_paid();
465 465
 			}
466 466
 
467
-			$invoice->set_status( 'wpi-onhold' );
467
+			$invoice->set_status('wpi-onhold');
468 468
         	$invoice->add_note(
469 469
                 sprintf(
470
-                    __( 'Held for review: %s', 'invoicing' ),
470
+                    __('Held for review: %s', 'invoicing'),
471 471
                     $result->transactionResponse->messages->message[0]->description
472 472
                 )
473 473
 			);
@@ -476,11 +476,11 @@  discard block
 block discarded – undo
476 476
 
477 477
 		}
478 478
 
479
-        wpinv_set_error( 'card_declined' );
479
+        wpinv_set_error('card_declined');
480 480
 
481
-        if ( ! empty( $result->transactionResponse->errors ) ) {
481
+        if (!empty($result->transactionResponse->errors)) {
482 482
             $errors = (object) $result->transactionResponse->errors;
483
-            wpinv_set_error( $errors->error[0]->errorCode, esc_html( $errors->error[0]->errorText ) );
483
+            wpinv_set_error($errors->error[0]->errorCode, esc_html($errors->error[0]->errorText));
484 484
         }
485 485
 
486 486
     }
@@ -492,7 +492,7 @@  discard block
 block discarded – undo
492 492
 	 * @param array $card Card details.
493 493
 	 * @return array
494 494
 	 */
495
-	public function get_payment_information( $card ) {
495
+	public function get_payment_information($card) {
496 496
         return array(
497 497
 
498 498
             'creditCard' => array(
@@ -511,8 +511,8 @@  discard block
 block discarded – undo
511 511
 	 * @param WPInv_Invoice $invoice Invoice.
512 512
 	 * @return string
513 513
 	 */
514
-	public function get_customer_profile_meta_name( $invoice ) {
515
-        return $this->is_sandbox( $invoice ) ? 'getpaid_authorizenet_sandbox_customer_profile_id' : 'getpaid_authorizenet_customer_profile_id';
514
+	public function get_customer_profile_meta_name($invoice) {
515
+        return $this->is_sandbox($invoice) ? 'getpaid_authorizenet_sandbox_customer_profile_id' : 'getpaid_authorizenet_customer_profile_id';
516 516
     }
517 517
 
518 518
     /**
@@ -523,34 +523,34 @@  discard block
 block discarded – undo
523 523
      * @param WPInv_Invoice $invoice
524 524
 	 * @return WP_Error|string The payment profile id
525 525
 	 */
526
-	public function validate_submission_data( $submission_data, $invoice ) {
526
+	public function validate_submission_data($submission_data, $invoice) {
527 527
 
528 528
         // Validate authentication details.
529 529
         $auth = $this->get_auth_params();
530 530
 
531
-        if ( empty( $auth['name'] ) || empty( $auth['transactionKey'] ) ) {
532
-            return new WP_Error( 'invalid_settings', __( 'Please set-up your login id and transaction key before using this gateway.', 'invoicing' ) );
531
+        if (empty($auth['name']) || empty($auth['transactionKey'])) {
532
+            return new WP_Error('invalid_settings', __('Please set-up your login id and transaction key before using this gateway.', 'invoicing'));
533 533
         }
534 534
 
535 535
         // Validate the payment method.
536
-        if ( empty( $submission_data['getpaid-authorizenet-payment-method'] ) ) {
537
-            return new WP_Error( 'invalid_payment_method', __( 'Please select a different payment method or add a new card.', 'invoicing' ) );
536
+        if (empty($submission_data['getpaid-authorizenet-payment-method'])) {
537
+            return new WP_Error('invalid_payment_method', __('Please select a different payment method or add a new card.', 'invoicing'));
538 538
         }
539 539
 
540 540
         // Are we adding a new payment method?
541
-        if ( 'new' != $submission_data['getpaid-authorizenet-payment-method'] ) {
541
+        if ('new' != $submission_data['getpaid-authorizenet-payment-method']) {
542 542
             return $submission_data['getpaid-authorizenet-payment-method'];
543 543
         }
544 544
 
545 545
         // Retrieve the customer profile id.
546
-        $profile_id = get_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), true );
546
+        $profile_id = get_user_meta($invoice->get_user_id(), $this->get_customer_profile_meta_name($invoice), true);
547 547
 
548 548
         // Create payment method.
549
-        if ( empty( $profile_id ) ) {
550
-            return $this->create_customer_profile( $invoice, $submission_data, ! empty( $submission_data['getpaid-authorizenet-new-payment-method'] ) );
549
+        if (empty($profile_id)) {
550
+            return $this->create_customer_profile($invoice, $submission_data, !empty($submission_data['getpaid-authorizenet-new-payment-method']));
551 551
         }
552 552
 
553
-        return $this->create_customer_payment_profile( $profile_id, $invoice, $submission_data, ! empty( $submission_data['getpaid-authorizenet-new-payment-method'] ) );
553
+        return $this->create_customer_payment_profile($profile_id, $invoice, $submission_data, !empty($submission_data['getpaid-authorizenet-new-payment-method']));
554 554
 
555 555
     }
556 556
 
@@ -561,32 +561,32 @@  discard block
 block discarded – undo
561 561
 	 * @param WPInv_Invoice $invoice Invoice.
562 562
 	 * @return array
563 563
 	 */
564
-	public function get_line_items( $invoice ) {
564
+	public function get_line_items($invoice) {
565 565
         $items = array();
566 566
 
567
-        foreach ( $invoice->get_items() as $item ) {
567
+        foreach ($invoice->get_items() as $item) {
568 568
 
569 569
             $amount  = $invoice->is_renewal() ? $item->get_price() : $item->get_initial_price();
570 570
             $items[] = array(
571
-                'itemId'      => getpaid_limit_length( $item->get_id(), 31 ),
572
-                'name'        => getpaid_limit_length( $item->get_raw_name(), 31 ),
573
-                'description' => getpaid_limit_length( $item->get_description(), 255 ),
574
-                'quantity'    => (string) ( $invoice->get_template() == 'amount' ? 1 : $item->get_quantity() ),
571
+                'itemId'      => getpaid_limit_length($item->get_id(), 31),
572
+                'name'        => getpaid_limit_length($item->get_raw_name(), 31),
573
+                'description' => getpaid_limit_length($item->get_description(), 255),
574
+                'quantity'    => (string) ($invoice->get_template() == 'amount' ? 1 : $item->get_quantity()),
575 575
                 'unitPrice'   => (float) $amount,
576 576
                 'taxable'     => wpinv_use_taxes() && $invoice->is_taxable() && 'tax-exempt' != $item->get_vat_rule(),
577 577
             );
578 578
 
579 579
         }
580 580
 
581
-        foreach ( $invoice->get_fees() as $fee_name => $fee ) {
581
+        foreach ($invoice->get_fees() as $fee_name => $fee) {
582 582
 
583
-            $amount  = $invoice->is_renewal() ? $fee['recurring_fee'] : $fee['initial_fee'];
583
+            $amount = $invoice->is_renewal() ? $fee['recurring_fee'] : $fee['initial_fee'];
584 584
 
585
-            if ( $amount > 0 ) {
585
+            if ($amount > 0) {
586 586
                 $items[] = array(
587
-                    'itemId'      => getpaid_limit_length( $fee_name, 31 ),
588
-                    'name'        => getpaid_limit_length( $fee_name, 31 ),
589
-                    'description' => getpaid_limit_length( $fee_name, 255 ),
587
+                    'itemId'      => getpaid_limit_length($fee_name, 31),
588
+                    'name'        => getpaid_limit_length($fee_name, 31),
589
+                    'description' => getpaid_limit_length($fee_name, 255),
590 590
                     'quantity'    => '1',
591 591
                     'unitPrice'   => (float) $amount,
592 592
                     'taxable'     => false,
@@ -606,36 +606,36 @@  discard block
 block discarded – undo
606 606
 	 * @param GetPaid_Payment_Form_Submission $submission Checkout submission.
607 607
 	 * @return array
608 608
 	 */
609
-	public function process_payment( $invoice, $submission_data, $submission ) {
609
+	public function process_payment($invoice, $submission_data, $submission) {
610 610
 
611 611
         // Validate the submitted data.
612
-        $payment_profile_id = $this->validate_submission_data( $submission_data, $invoice );
612
+        $payment_profile_id = $this->validate_submission_data($submission_data, $invoice);
613 613
 
614 614
         // Do we have an error?
615
-        if ( is_wp_error( $payment_profile_id ) ) {
616
-            wpinv_set_error( $payment_profile_id->get_error_code(), $payment_profile_id->get_error_message() );
617
-            wpinv_send_back_to_checkout( $invoice );
615
+        if (is_wp_error($payment_profile_id)) {
616
+            wpinv_set_error($payment_profile_id->get_error_code(), $payment_profile_id->get_error_message());
617
+            wpinv_send_back_to_checkout($invoice);
618 618
         }
619 619
 
620 620
         // Save the payment method to the order.
621
-        update_post_meta( $invoice->get_id(), 'getpaid_authorizenet_profile_id', $payment_profile_id );
621
+        update_post_meta($invoice->get_id(), 'getpaid_authorizenet_profile_id', $payment_profile_id);
622 622
 
623 623
         // Check if this is a subscription or not.
624
-        $subscriptions = getpaid_get_invoice_subscriptions( $invoice );
625
-        if ( ! empty( $subscriptions ) ) {
626
-            $this->process_subscription( $invoice, $subscriptions );
624
+        $subscriptions = getpaid_get_invoice_subscriptions($invoice);
625
+        if (!empty($subscriptions)) {
626
+            $this->process_subscription($invoice, $subscriptions);
627 627
         }
628 628
 
629 629
         // If it is free, send to the success page.
630
-        if ( ! $invoice->needs_payment() ) {
630
+        if (!$invoice->needs_payment()) {
631 631
             $invoice->mark_paid();
632
-            wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) );
632
+            wpinv_send_to_success_page(array('invoice_key' => $invoice->get_key()));
633 633
         }
634 634
 
635 635
         // Charge the payment profile.
636
-        $this->process_initial_payment( $invoice );
636
+        $this->process_initial_payment($invoice);
637 637
 
638
-        wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) );
638
+        wpinv_send_to_success_page(array('invoice_key' => $invoice->get_key()));
639 639
 
640 640
         exit;
641 641
 
@@ -646,23 +646,23 @@  discard block
 block discarded – undo
646 646
 	 *
647 647
      * @param WPInv_Invoice $invoice Invoice.
648 648
 	 */
649
-	protected function process_initial_payment( $invoice ) {
649
+	protected function process_initial_payment($invoice) {
650 650
 
651
-		$payment_profile_id = get_post_meta( $invoice->get_id(), 'getpaid_authorizenet_profile_id', true );
652
-        $customer_profile   = get_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), true );
653
-		$result             = $this->charge_customer_payment_profile( $customer_profile, $payment_profile_id, $invoice );
651
+		$payment_profile_id = get_post_meta($invoice->get_id(), 'getpaid_authorizenet_profile_id', true);
652
+        $customer_profile = get_user_meta($invoice->get_user_id(), $this->get_customer_profile_meta_name($invoice), true);
653
+		$result             = $this->charge_customer_payment_profile($customer_profile, $payment_profile_id, $invoice);
654 654
 
655 655
 		// Do we have an error?
656
-		if ( is_wp_error( $result ) ) {
657
-			wpinv_set_error( $result->get_error_code(), $result->get_error_message() );
658
-			wpinv_send_back_to_checkout( $invoice );
656
+		if (is_wp_error($result)) {
657
+			wpinv_set_error($result->get_error_code(), $result->get_error_message());
658
+			wpinv_send_back_to_checkout($invoice);
659 659
 		}
660 660
 
661 661
 		// Process the response.
662
-		$this->process_charge_response( $result, $invoice );
662
+		$this->process_charge_response($result, $invoice);
663 663
 
664
-		if ( wpinv_get_errors() ) {
665
-			wpinv_send_back_to_checkout( $invoice );
664
+		if (wpinv_get_errors()) {
665
+			wpinv_send_back_to_checkout($invoice);
666 666
 		}
667 667
 
668 668
 	}
@@ -673,30 +673,30 @@  discard block
 block discarded – undo
673 673
      * @param WPInv_Invoice $invoice Invoice.
674 674
      * @param WPInv_Subscription[]|WPInv_Subscription $subscriptions Subscriptions.
675 675
 	 */
676
-	public function process_subscription( $invoice, $subscriptions ) {
676
+	public function process_subscription($invoice, $subscriptions) {
677 677
 
678 678
         // Check if there is an initial amount to charge.
679
-        if ( (float) $invoice->get_total() > 0 ) {
680
-			$this->process_initial_payment( $invoice );
679
+        if ((float) $invoice->get_total() > 0) {
680
+			$this->process_initial_payment($invoice);
681 681
         }
682 682
 
683 683
         // Activate the subscriptions.
684
-        $subscriptions = is_array( $subscriptions ) ? $subscriptions : array( $subscriptions );
684
+        $subscriptions = is_array($subscriptions) ? $subscriptions : array($subscriptions);
685 685
 
686
-        foreach ( $subscriptions as $subscription ) {
687
-            if ( $subscription->exists() ) {
688
-                $duration = strtotime( $subscription->get_expiration() ) - strtotime( $subscription->get_date_created() );
689
-                $expiry   = date( 'Y-m-d H:i:s', ( current_time( 'timestamp' ) + $duration ) );
686
+        foreach ($subscriptions as $subscription) {
687
+            if ($subscription->exists()) {
688
+                $duration = strtotime($subscription->get_expiration()) - strtotime($subscription->get_date_created());
689
+                $expiry   = date('Y-m-d H:i:s', (current_time('timestamp') + $duration));
690 690
 
691
-                $subscription->set_next_renewal_date( $expiry );
692
-                $subscription->set_date_created( current_time( 'mysql' ) );
693
-                $subscription->set_profile_id( $invoice->generate_key( 'authnet_sub_' . $invoice->get_id() . '_' . $subscription->get_id() ) );
691
+                $subscription->set_next_renewal_date($expiry);
692
+                $subscription->set_date_created(current_time('mysql'));
693
+                $subscription->set_profile_id($invoice->generate_key('authnet_sub_' . $invoice->get_id() . '_' . $subscription->get_id()));
694 694
                 $subscription->activate();
695 695
             }
696 696
         }
697 697
 
698 698
 		// Redirect to the success page.
699
-        wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) );
699
+        wpinv_send_to_success_page(array('invoice_key' => $invoice->get_key()));
700 700
 
701 701
     }
702 702
 
@@ -706,11 +706,11 @@  discard block
 block discarded – undo
706 706
 	 *
707 707
      * @param WPInv_Subscription $subscription
708 708
 	 */
709
-	public function maybe_renew_subscription( $subscription ) {
709
+	public function maybe_renew_subscription($subscription) {
710 710
 
711 711
         // Ensure its our subscription && it's active.
712
-        if ( $this->id === $subscription->get_gateway() && $subscription->has_status( 'active trialling' ) ) {
713
-            $this->renew_subscription( $subscription );
712
+        if ($this->id === $subscription->get_gateway() && $subscription->has_status('active trialling')) {
713
+            $this->renew_subscription($subscription);
714 714
         }
715 715
 
716 716
 	}
@@ -720,28 +720,28 @@  discard block
 block discarded – undo
720 720
 	 *
721 721
      * @param WPInv_Subscription $subscription
722 722
 	 */
723
-	public function renew_subscription( $subscription ) {
723
+	public function renew_subscription($subscription) {
724 724
 
725 725
 		// Generate the renewal invoice.
726 726
 		$new_invoice = $subscription->create_payment();
727 727
 		$old_invoice = $subscription->get_parent_payment();
728 728
 
729
-        if ( empty( $new_invoice ) ) {
730
-            $old_invoice->add_note( __( 'Error generating a renewal invoice.', 'invoicing' ), false, false, false );
729
+        if (empty($new_invoice)) {
730
+            $old_invoice->add_note(__('Error generating a renewal invoice.', 'invoicing'), false, false, false);
731 731
             $subscription->failing();
732 732
             return;
733 733
         }
734 734
 
735 735
         // Charge the payment method.
736
-		$payment_profile_id = get_post_meta( $old_invoice->get_id(), 'getpaid_authorizenet_profile_id', true );
737
-		$customer_profile   = get_user_meta( $old_invoice->get_user_id(), $this->get_customer_profile_meta_name( $old_invoice ), true );
738
-		$result             = $this->charge_customer_payment_profile( $customer_profile, $payment_profile_id, $new_invoice );
736
+		$payment_profile_id = get_post_meta($old_invoice->get_id(), 'getpaid_authorizenet_profile_id', true);
737
+		$customer_profile   = get_user_meta($old_invoice->get_user_id(), $this->get_customer_profile_meta_name($old_invoice), true);
738
+		$result             = $this->charge_customer_payment_profile($customer_profile, $payment_profile_id, $new_invoice);
739 739
 
740 740
 		// Do we have an error?
741
-		if ( is_wp_error( $result ) ) {
741
+		if (is_wp_error($result)) {
742 742
 
743 743
 			$old_invoice->add_note(
744
-				sprintf( __( 'Error renewing subscription : ( %s ).', 'invoicing' ), $result->get_error_message() ),
744
+				sprintf(__('Error renewing subscription : ( %s ).', 'invoicing'), $result->get_error_message()),
745 745
 				true,
746 746
 				false,
747 747
 				true
@@ -752,12 +752,12 @@  discard block
 block discarded – undo
752 752
 		}
753 753
 
754 754
 		// Process the response.
755
-		$this->process_charge_response( $result, $new_invoice );
755
+		$this->process_charge_response($result, $new_invoice);
756 756
 
757
-		if ( wpinv_get_errors() ) {
757
+		if (wpinv_get_errors()) {
758 758
 
759 759
 			$old_invoice->add_note(
760
-				sprintf( __( 'Error renewing subscription : ( %s ).', 'invoicing' ), getpaid_get_errors_html() ),
760
+				sprintf(__('Error renewing subscription : ( %s ).', 'invoicing'), getpaid_get_errors_html()),
761 761
 				true,
762 762
 				false,
763 763
 				true
@@ -767,9 +767,9 @@  discard block
 block discarded – undo
767 767
 
768 768
         }
769 769
 
770
-        if ( ! $new_invoice->needs_payment() ) {
770
+        if (!$new_invoice->needs_payment()) {
771 771
             $subscription->renew();
772
-            $subscription->after_add_payment( $new_invoice );
772
+            $subscription->after_add_payment($new_invoice);
773 773
         } else {
774 774
             $subscription->failing();
775 775
         }
@@ -782,33 +782,33 @@  discard block
 block discarded – undo
782 782
 	 * @param GetPaid_Form_Item[] $items
783 783
 	 * @return WPInv_Invoice
784 784
 	 */
785
-	public function process_addons( $invoice, $items ) {
785
+	public function process_addons($invoice, $items) {
786 786
 
787 787
         global $getpaid_authorize_addons;
788 788
 
789 789
         $getpaid_authorize_addons = array();
790
-        foreach ( $items as $item ) {
790
+        foreach ($items as $item) {
791 791
 
792
-            if ( is_null( $invoice->get_item( $item->get_id() ) ) && ! is_wp_error( $invoice->add_item( $item ) ) ) {
792
+            if (is_null($invoice->get_item($item->get_id())) && !is_wp_error($invoice->add_item($item))) {
793 793
                 $getpaid_authorize_addons[] = $item;
794 794
             }
795 795
 }
796 796
 
797
-        if ( empty( $getpaid_authorize_addons ) ) {
797
+        if (empty($getpaid_authorize_addons)) {
798 798
             return;
799 799
         }
800 800
 
801 801
         $invoice->recalculate_total();
802 802
 
803
-        $payment_profile_id = get_post_meta( $invoice->get_id(), 'getpaid_authorizenet_profile_id', true );
804
-		$customer_profile   = get_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), true );
803
+        $payment_profile_id = get_post_meta($invoice->get_id(), 'getpaid_authorizenet_profile_id', true);
804
+		$customer_profile = get_user_meta($invoice->get_user_id(), $this->get_customer_profile_meta_name($invoice), true);
805 805
 
806
-        add_filter( 'getpaid_authorizenet_charge_customer_payment_profile_args', array( $this, 'filter_addons_request' ), 10, 2 );
807
-        $result = $this->charge_customer_payment_profile( $customer_profile, $payment_profile_id, $invoice );
808
-        remove_filter( 'getpaid_authorizenet_charge_customer_payment_profile_args', array( $this, 'filter_addons_request' ) );
806
+        add_filter('getpaid_authorizenet_charge_customer_payment_profile_args', array($this, 'filter_addons_request'), 10, 2);
807
+        $result = $this->charge_customer_payment_profile($customer_profile, $payment_profile_id, $invoice);
808
+        remove_filter('getpaid_authorizenet_charge_customer_payment_profile_args', array($this, 'filter_addons_request'));
809 809
 
810
-        if ( is_wp_error( $result ) ) {
811
-            wpinv_set_error( $result->get_error_code(), $result->get_error_message() );
810
+        if (is_wp_error($result)) {
811
+            wpinv_set_error($result->get_error_code(), $result->get_error_message());
812 812
             return;
813 813
         }
814 814
 
@@ -821,19 +821,19 @@  discard block
 block discarded – undo
821 821
      * @param array $args
822 822
 	 * @return array
823 823
 	 */
824
-    public function filter_addons_request( $args ) {
824
+    public function filter_addons_request($args) {
825 825
 
826 826
         global $getpaid_authorize_addons;
827 827
         $total = 0;
828 828
 
829
-        foreach ( $getpaid_authorize_addons as $addon ) {
829
+        foreach ($getpaid_authorize_addons as $addon) {
830 830
             $total += $addon->get_sub_total();
831 831
         }
832 832
 
833 833
         $args['createTransactionRequest']['transactionRequest']['amount'] = $total;
834 834
 
835
-        if ( isset( $args['createTransactionRequest']['transactionRequest']['tax'] ) ) {
836
-            unset( $args['createTransactionRequest']['transactionRequest']['tax'] );
835
+        if (isset($args['createTransactionRequest']['transactionRequest']['tax'])) {
836
+            unset($args['createTransactionRequest']['transactionRequest']['tax']);
837 837
         }
838 838
 
839 839
         return $args;
@@ -846,7 +846,7 @@  discard block
 block discarded – undo
846 846
     public function sandbox_notice() {
847 847
 
848 848
         return sprintf(
849
-            __( 'SANDBOX ENABLED. You can use sandbox testing details only. See the %1$sAuthorize.NET Sandbox Testing Guide%2$s for more details.', 'invoicing' ),
849
+            __('SANDBOX ENABLED. You can use sandbox testing details only. See the %1$sAuthorize.NET Sandbox Testing Guide%2$s for more details.', 'invoicing'),
850 850
             '<a href="https://developer.authorize.net/hello_world/testing_guide.html">',
851 851
             '</a>'
852 852
         );
@@ -858,42 +858,42 @@  discard block
 block discarded – undo
858 858
 	 *
859 859
 	 * @param array $admin_settings
860 860
 	 */
861
-	public function admin_settings( $admin_settings ) {
861
+	public function admin_settings($admin_settings) {
862 862
 
863 863
         $currencies = sprintf(
864
-            __( 'Supported Currencies: %s', 'invoicing' ),
865
-            implode( ', ', $this->currencies )
864
+            __('Supported Currencies: %s', 'invoicing'),
865
+            implode(', ', $this->currencies)
866 866
         );
867 867
 
868 868
         $admin_settings['authorizenet_active']['desc'] .= " ($currencies)";
869
-        $admin_settings['authorizenet_desc']['std']     = __( 'Pay securely using your credit or debit card.', 'invoicing' );
869
+        $admin_settings['authorizenet_desc']['std']     = __('Pay securely using your credit or debit card.', 'invoicing');
870 870
 
871 871
         $admin_settings['authorizenet_login_id'] = array(
872 872
             'type' => 'text',
873 873
             'id'   => 'authorizenet_login_id',
874
-            'name' => __( 'API Login ID', 'invoicing' ),
875
-            'desc' => '<a href="https://support.authorize.net/s/article/How-do-I-obtain-my-API-Login-ID-and-Transaction-Key"><em>' . __( 'How do I obtain my API Login ID and Transaction Key?', 'invoicing' ) . '</em></a>',
874
+            'name' => __('API Login ID', 'invoicing'),
875
+            'desc' => '<a href="https://support.authorize.net/s/article/How-do-I-obtain-my-API-Login-ID-and-Transaction-Key"><em>' . __('How do I obtain my API Login ID and Transaction Key?', 'invoicing') . '</em></a>',
876 876
         );
877 877
 
878 878
         $admin_settings['authorizenet_transaction_key'] = array(
879 879
             'type' => 'text',
880 880
             'id'   => 'authorizenet_transaction_key',
881
-            'name' => __( 'Transaction Key', 'invoicing' ),
881
+            'name' => __('Transaction Key', 'invoicing'),
882 882
         );
883 883
 
884 884
         $admin_settings['authorizenet_signature_key'] = array(
885 885
             'type' => 'text',
886 886
             'id'   => 'authorizenet_signature_key',
887
-            'name' => __( 'Signature Key', 'invoicing' ),
888
-            'desc' => '<a href="https://support.authorize.net/s/article/What-is-a-Signature-Key"><em>' . __( 'Learn more.', 'invoicing' ) . '</em></a>',
887
+            'name' => __('Signature Key', 'invoicing'),
888
+            'desc' => '<a href="https://support.authorize.net/s/article/What-is-a-Signature-Key"><em>' . __('Learn more.', 'invoicing') . '</em></a>',
889 889
         );
890 890
 
891 891
         $admin_settings['authorizenet_ipn_url'] = array(
892 892
             'type'     => 'ipn_url',
893 893
             'id'       => 'authorizenet_ipn_url',
894
-            'name'     => __( 'Webhook URL', 'invoicing' ),
894
+            'name'     => __('Webhook URL', 'invoicing'),
895 895
             'std'      => $this->notify_url,
896
-            'desc'     => __( 'Create a new webhook using this URL as the endpoint URL and set it to receive all payment events.', 'invoicing' ) . ' <a href="https://support.authorize.net/s/article/How-do-I-add-edit-Webhook-notification-end-points"><em>' . __( 'Learn more.', 'invoicing' ) . '</em></a>',
896
+            'desc'     => __('Create a new webhook using this URL as the endpoint URL and set it to receive all payment events.', 'invoicing') . ' <a href="https://support.authorize.net/s/article/How-do-I-add-edit-Webhook-notification-end-points"><em>' . __('Learn more.', 'invoicing') . '</em></a>',
897 897
             'custom'   => 'authorizenet',
898 898
             'readonly' => true,
899 899
         );
Please login to merge, or discard this patch.
includes/wpinv-subscription.php 2 patches
Indentation   +1051 added lines, -1051 removed lines patch added patch discarded remove patch
@@ -15,125 +15,125 @@  discard block
 block discarded – undo
15 15
  */
16 16
 class WPInv_Subscription extends GetPaid_Data {
17 17
 
18
-	/**
19
-	 * Which data store to load.
20
-	 *
21
-	 * @var string
22
-	 */
23
-	protected $data_store_name = 'subscription';
24
-
25
-	/**
26
-	 * This is the name of this object type.
27
-	 *
28
-	 * @var string
29
-	 */
30
-	protected $object_type = 'subscription';
31
-
32
-	/**
33
-	 * Item Data array. This is the core item data exposed in APIs.
34
-	 *
35
-	 * @since 1.0.19
36
-	 * @var array
37
-	 */
38
-	protected $data = array(
39
-		'customer_id'       => 0,
40
-		'frequency'         => 1,
41
-		'period'            => 'D',
42
-		'initial_amount'    => null,
43
-		'recurring_amount'  => null,
44
-		'bill_times'        => 0,
45
-		'transaction_id'    => '',
46
-		'parent_payment_id' => null,
47
-		'product_id'        => 0,
48
-		'created'           => '0000-00-00 00:00:00',
49
-		'expiration'        => '0000-00-00 00:00:00',
50
-		'trial_period'      => '',
51
-		'status'            => 'pending',
52
-		'profile_id'        => '',
53
-		'gateway'           => '',
54
-		'customer'          => '',
55
-	);
56
-
57
-	/**
58
-	 * Stores the status transition information.
59
-	 *
60
-	 * @since 1.0.19
61
-	 * @var bool
62
-	 */
63
-	protected $status_transition = false;
64
-
65
-	/**
66
-	 * Get the subscription if ID is passed, otherwise the subscription is new and empty.
67
-	 *
68
-	 * @param  int|string|object|WPInv_Subscription $subscription Subscription id, profile_id, or object to read.
69
-	 * @param  bool $deprecated
70
-	 */
71
-	function __construct( $subscription = 0, $deprecated = false ) {
72
-
73
-		parent::__construct( $subscription );
74
-
75
-		if ( ! $deprecated && ! empty( $subscription ) && is_numeric( $subscription ) ) {
76
-			$this->set_id( $subscription );
77
-		} elseif ( $subscription instanceof self ) {
78
-			$this->set_id( $subscription->get_id() );
79
-		} elseif ( $deprecated && $subscription_id = self::get_subscription_id_by_field( $subscription, 'profile_id' ) ) {
80
-			$this->set_id( $subscription_id );
81
-		} elseif ( ! empty( $subscription->id ) ) {
82
-			$this->set_id( $subscription->id );
83
-		} else {
84
-			$this->set_object_read( true );
85
-		}
86
-
87
-		// Load the datastore.
88
-		$this->data_store = GetPaid_Data_Store::load( $this->data_store_name );
89
-
90
-		if ( $this->get_id() > 0 ) {
91
-			$this->data_store->read( $this );
92
-		}
93
-
94
-	}
95
-
96
-	/**
97
-	 * Given an invoice id, profile id, transaction id, it returns the subscription's id.
98
-	 *
99
-	 *
100
-	 * @static
101
-	 * @param string $value
102
-	 * @param string $field Either invoice_id, transaction_id or profile_id.
103
-	 * @since 1.0.19
104
-	 * @return int
105
-	 */
106
-	public static function get_subscription_id_by_field( $value, $field = 'profile_id' ) {
18
+    /**
19
+     * Which data store to load.
20
+     *
21
+     * @var string
22
+     */
23
+    protected $data_store_name = 'subscription';
24
+
25
+    /**
26
+     * This is the name of this object type.
27
+     *
28
+     * @var string
29
+     */
30
+    protected $object_type = 'subscription';
31
+
32
+    /**
33
+     * Item Data array. This is the core item data exposed in APIs.
34
+     *
35
+     * @since 1.0.19
36
+     * @var array
37
+     */
38
+    protected $data = array(
39
+        'customer_id'       => 0,
40
+        'frequency'         => 1,
41
+        'period'            => 'D',
42
+        'initial_amount'    => null,
43
+        'recurring_amount'  => null,
44
+        'bill_times'        => 0,
45
+        'transaction_id'    => '',
46
+        'parent_payment_id' => null,
47
+        'product_id'        => 0,
48
+        'created'           => '0000-00-00 00:00:00',
49
+        'expiration'        => '0000-00-00 00:00:00',
50
+        'trial_period'      => '',
51
+        'status'            => 'pending',
52
+        'profile_id'        => '',
53
+        'gateway'           => '',
54
+        'customer'          => '',
55
+    );
56
+
57
+    /**
58
+     * Stores the status transition information.
59
+     *
60
+     * @since 1.0.19
61
+     * @var bool
62
+     */
63
+    protected $status_transition = false;
64
+
65
+    /**
66
+     * Get the subscription if ID is passed, otherwise the subscription is new and empty.
67
+     *
68
+     * @param  int|string|object|WPInv_Subscription $subscription Subscription id, profile_id, or object to read.
69
+     * @param  bool $deprecated
70
+     */
71
+    function __construct( $subscription = 0, $deprecated = false ) {
72
+
73
+        parent::__construct( $subscription );
74
+
75
+        if ( ! $deprecated && ! empty( $subscription ) && is_numeric( $subscription ) ) {
76
+            $this->set_id( $subscription );
77
+        } elseif ( $subscription instanceof self ) {
78
+            $this->set_id( $subscription->get_id() );
79
+        } elseif ( $deprecated && $subscription_id = self::get_subscription_id_by_field( $subscription, 'profile_id' ) ) {
80
+            $this->set_id( $subscription_id );
81
+        } elseif ( ! empty( $subscription->id ) ) {
82
+            $this->set_id( $subscription->id );
83
+        } else {
84
+            $this->set_object_read( true );
85
+        }
86
+
87
+        // Load the datastore.
88
+        $this->data_store = GetPaid_Data_Store::load( $this->data_store_name );
89
+
90
+        if ( $this->get_id() > 0 ) {
91
+            $this->data_store->read( $this );
92
+        }
93
+
94
+    }
95
+
96
+    /**
97
+     * Given an invoice id, profile id, transaction id, it returns the subscription's id.
98
+     *
99
+     *
100
+     * @static
101
+     * @param string $value
102
+     * @param string $field Either invoice_id, transaction_id or profile_id.
103
+     * @since 1.0.19
104
+     * @return int
105
+     */
106
+    public static function get_subscription_id_by_field( $value, $field = 'profile_id' ) {
107 107
         global $wpdb;
108 108
 
109
-		// Trim the value.
110
-		$value = trim( $value );
109
+        // Trim the value.
110
+        $value = trim( $value );
111 111
 
112
-		if ( empty( $value ) ) {
113
-			return 0;
114
-		}
112
+        if ( empty( $value ) ) {
113
+            return 0;
114
+        }
115 115
 
116
-		if ( 'invoice_id' == $field ) {
117
-			$field = 'parent_payment_id';
118
-		}
116
+        if ( 'invoice_id' == $field ) {
117
+            $field = 'parent_payment_id';
118
+        }
119 119
 
120 120
         // Valid fields.
121 121
         $fields = array(
122
-			'parent_payment_id',
123
-			'transaction_id',
124
-			'profile_id',
125
-		);
126
-
127
-		// Ensure a field has been passed.
128
-		if ( empty( $field ) || ! in_array( $field, $fields ) ) {
129
-			return 0;
130
-		}
131
-
132
-		// Maybe retrieve from the cache.
133
-		$subscription_id   = wp_cache_get( $value, "getpaid_subscription_{$field}s_to_subscription_ids" );
134
-		if ( ! empty( $subscription_id ) ) {
135
-			return $subscription_id;
136
-		}
122
+            'parent_payment_id',
123
+            'transaction_id',
124
+            'profile_id',
125
+        );
126
+
127
+        // Ensure a field has been passed.
128
+        if ( empty( $field ) || ! in_array( $field, $fields ) ) {
129
+            return 0;
130
+        }
131
+
132
+        // Maybe retrieve from the cache.
133
+        $subscription_id   = wp_cache_get( $value, "getpaid_subscription_{$field}s_to_subscription_ids" );
134
+        if ( ! empty( $subscription_id ) ) {
135
+            return $subscription_id;
136
+        }
137 137
 
138 138
         // Fetch from the db.
139 139
         $table            = $wpdb->prefix . 'wpinv_subscriptions';
@@ -141,42 +141,42 @@  discard block
 block discarded – undo
141 141
             $wpdb->prepare( "SELECT `id` FROM $table WHERE `$field`=%s LIMIT 1", $value )
142 142
         );
143 143
 
144
-		if ( empty( $subscription_id ) ) {
145
-			return 0;
146
-		}
144
+        if ( empty( $subscription_id ) ) {
145
+            return 0;
146
+        }
147 147
 
148
-		// Update the cache with our data.
149
-		wp_cache_set( $value, $subscription_id, "getpaid_subscription_{$field}s_to_subscription_ids" );
148
+        // Update the cache with our data.
149
+        wp_cache_set( $value, $subscription_id, "getpaid_subscription_{$field}s_to_subscription_ids" );
150 150
 
151
-		return $subscription_id;
152
-	}
151
+        return $subscription_id;
152
+    }
153 153
 
154
-	/**
154
+    /**
155 155
      * Clears the subscription's cache.
156 156
      */
157 157
     public function clear_cache() {
158
-		$caches = array(
159
-			'getpaid_subscription_parent_payment_ids_to_subscription_ids' => $this->get_parent_payment_id(),
160
-			'getpaid_subscription_transaction_ids_to_subscription_ids'    => $this->get_transaction_id(),
161
-			'getpaid_subscription_profile_ids_to_subscription_ids'        => $this->get_profile_id(),
162
-			'getpaid_subscriptions'                                       => $this->get_id(),
163
-		);
164
-
165
-		foreach ( $caches as $cache => $value ) {
166
-			if ( '' !== $value && false !== $value ) {
167
-				wp_cache_delete( $value, $cache );
168
-			}
169
-		}
170
-	}
171
-
172
-	/**
158
+        $caches = array(
159
+            'getpaid_subscription_parent_payment_ids_to_subscription_ids' => $this->get_parent_payment_id(),
160
+            'getpaid_subscription_transaction_ids_to_subscription_ids'    => $this->get_transaction_id(),
161
+            'getpaid_subscription_profile_ids_to_subscription_ids'        => $this->get_profile_id(),
162
+            'getpaid_subscriptions'                                       => $this->get_id(),
163
+        );
164
+
165
+        foreach ( $caches as $cache => $value ) {
166
+            if ( '' !== $value && false !== $value ) {
167
+                wp_cache_delete( $value, $cache );
168
+            }
169
+        }
170
+    }
171
+
172
+    /**
173 173
      * Checks if a subscription key is set.
174 174
      */
175 175
     public function _isset( $key ) {
176 176
         return isset( $this->data[ $key ] ) || method_exists( $this, "get_$key" );
177
-	}
177
+    }
178 178
 
179
-	/*
179
+    /*
180 180
 	|--------------------------------------------------------------------------
181 181
 	| CRUD methods
182 182
 	|--------------------------------------------------------------------------
@@ -185,544 +185,544 @@  discard block
 block discarded – undo
185 185
 	|
186 186
     */
187 187
 
188
-	/*
188
+    /*
189 189
 	|--------------------------------------------------------------------------
190 190
 	| Getters
191 191
 	|--------------------------------------------------------------------------
192 192
 	*/
193 193
 
194
-	/**
195
-	 * Get customer id.
196
-	 *
197
-	 * @since 1.0.19
198
-	 * @param  string $context View or edit context.
199
-	 * @return int
200
-	 */
201
-	public function get_customer_id( $context = 'view' ) {
202
-		return (int) $this->get_prop( 'customer_id', $context );
203
-	}
204
-
205
-	/**
206
-	 * Get customer information.
207
-	 *
208
-	 * @since 1.0.19
209
-	 * @param  string $context View or edit context.
210
-	 * @return WP_User|false WP_User object on success, false on failure.
211
-	 */
212
-	public function get_customer( $context = 'view' ) {
213
-		return get_userdata( $this->get_customer_id( $context ) );
214
-	}
215
-
216
-	/**
217
-	 * Get parent invoice id.
218
-	 *
219
-	 * @since 1.0.19
220
-	 * @param  string $context View or edit context.
221
-	 * @return int
222
-	 */
223
-	public function get_parent_invoice_id( $context = 'view' ) {
224
-		return (int) $this->get_prop( 'parent_payment_id', $context );
225
-	}
226
-
227
-	/**
228
-	 * Alias for self::get_parent_invoice_id().
229
-	 *
230
-	 * @since 1.0.19
231
-	 * @param  string $context View or edit context.
232
-	 * @return int
233
-	 */
194
+    /**
195
+     * Get customer id.
196
+     *
197
+     * @since 1.0.19
198
+     * @param  string $context View or edit context.
199
+     * @return int
200
+     */
201
+    public function get_customer_id( $context = 'view' ) {
202
+        return (int) $this->get_prop( 'customer_id', $context );
203
+    }
204
+
205
+    /**
206
+     * Get customer information.
207
+     *
208
+     * @since 1.0.19
209
+     * @param  string $context View or edit context.
210
+     * @return WP_User|false WP_User object on success, false on failure.
211
+     */
212
+    public function get_customer( $context = 'view' ) {
213
+        return get_userdata( $this->get_customer_id( $context ) );
214
+    }
215
+
216
+    /**
217
+     * Get parent invoice id.
218
+     *
219
+     * @since 1.0.19
220
+     * @param  string $context View or edit context.
221
+     * @return int
222
+     */
223
+    public function get_parent_invoice_id( $context = 'view' ) {
224
+        return (int) $this->get_prop( 'parent_payment_id', $context );
225
+    }
226
+
227
+    /**
228
+     * Alias for self::get_parent_invoice_id().
229
+     *
230
+     * @since 1.0.19
231
+     * @param  string $context View or edit context.
232
+     * @return int
233
+     */
234 234
     public function get_parent_payment_id( $context = 'view' ) {
235 235
         return $this->get_parent_invoice_id( $context );
236
-	}
236
+    }
237
+
238
+    /**
239
+     * Alias for self::get_parent_invoice_id().
240
+     *
241
+     * @since  1.0.0
242
+     * @return int
243
+     */
244
+    public function get_original_payment_id( $context = 'view' ) {
245
+        return $this->get_parent_invoice_id( $context );
246
+    }
247
+
248
+    /**
249
+     * Get parent invoice.
250
+     *
251
+     * @since 1.0.19
252
+     * @param  string $context View or edit context.
253
+     * @return WPInv_Invoice
254
+     */
255
+    public function get_parent_invoice( $context = 'view' ) {
256
+        return new WPInv_Invoice( $this->get_parent_invoice_id( $context ) );
257
+    }
258
+
259
+    /**
260
+     * Alias for self::get_parent_invoice().
261
+     *
262
+     * @since 1.0.19
263
+     * @param  string $context View or edit context.
264
+     * @return WPInv_Invoice
265
+     */
266
+    public function get_parent_payment( $context = 'view' ) {
267
+        return $this->get_parent_invoice( $context );
268
+    }
269
+
270
+    /**
271
+     * Get subscription's product id.
272
+     *
273
+     * @since 1.0.19
274
+     * @param  string $context View or edit context.
275
+     * @return int
276
+     */
277
+    public function get_product_id( $context = 'view' ) {
278
+        return (int) $this->get_prop( 'product_id', $context );
279
+    }
280
+
281
+    /**
282
+     * Get the subscription product.
283
+     *
284
+     * @since 1.0.19
285
+     * @param  string $context View or edit context.
286
+     * @return WPInv_Item
287
+     */
288
+    public function get_product( $context = 'view' ) {
289
+        return new WPInv_Item( $this->get_product_id( $context ) );
290
+    }
291
+
292
+    /**
293
+     * Get parent invoice's gateway.
294
+     *
295
+     * Here for backwards compatibility.
296
+     *
297
+     * @since 1.0.19
298
+     * @param  string $context View or edit context.
299
+     * @return string
300
+     */
301
+    public function get_gateway( $context = 'view' ) {
302
+        return $this->get_parent_invoice( $context )->get_gateway();
303
+    }
304
+
305
+    /**
306
+     * Get the period of a renewal.
307
+     *
308
+     * @since 1.0.19
309
+     * @param  string $context View or edit context.
310
+     * @return string
311
+     */
312
+    public function get_period( $context = 'view' ) {
313
+        return $this->get_prop( 'period', $context );
314
+    }
315
+
316
+    /**
317
+     * Get number of periods each renewal is valid for.
318
+     *
319
+     * @since 1.0.19
320
+     * @param  string $context View or edit context.
321
+     * @return int
322
+     */
323
+    public function get_frequency( $context = 'view' ) {
324
+        return (int) $this->get_prop( 'frequency', $context );
325
+    }
326
+
327
+    /**
328
+     * Get the initial amount for the subscription.
329
+     *
330
+     * @since 1.0.19
331
+     * @param  string $context View or edit context.
332
+     * @return float
333
+     */
334
+    public function get_initial_amount( $context = 'view' ) {
335
+        return (float) wpinv_sanitize_amount( $this->get_prop( 'initial_amount', $context ) );
336
+    }
337
+
338
+    /**
339
+     * Get the recurring amount for the subscription.
340
+     *
341
+     * @since 1.0.19
342
+     * @param  string $context View or edit context.
343
+     * @return float
344
+     */
345
+    public function get_recurring_amount( $context = 'view' ) {
346
+        return (float) wpinv_sanitize_amount( $this->get_prop( 'recurring_amount', $context ) );
347
+    }
348
+
349
+    /**
350
+     * Get number of times that this subscription can be renewed.
351
+     *
352
+     * @since 1.0.19
353
+     * @param  string $context View or edit context.
354
+     * @return int
355
+     */
356
+    public function get_bill_times( $context = 'view' ) {
357
+        return (int) $this->get_prop( 'bill_times', $context );
358
+    }
359
+
360
+    /**
361
+     * Get transaction id of this subscription's parent invoice.
362
+     *
363
+     * @since 1.0.19
364
+     * @param  string $context View or edit context.
365
+     * @return string
366
+     */
367
+    public function get_transaction_id( $context = 'view' ) {
368
+        return $this->get_prop( 'transaction_id', $context );
369
+    }
370
+
371
+    /**
372
+     * Get the date that the subscription was created.
373
+     *
374
+     * @since 1.0.19
375
+     * @param  string $context View or edit context.
376
+     * @return string
377
+     */
378
+    public function get_created( $context = 'view' ) {
379
+        return $this->get_prop( 'created', $context );
380
+    }
381
+
382
+    /**
383
+     * Alias for self::get_created().
384
+     *
385
+     * @since 1.0.19
386
+     * @param  string $context View or edit context.
387
+     * @return string
388
+     */
389
+    public function get_date_created( $context = 'view' ) {
390
+        return $this->get_created( $context );
391
+    }
392
+
393
+    /**
394
+     * Retrieves the creation date in a timestamp
395
+     *
396
+     * @since  1.0.0
397
+     * @return int
398
+     */
399
+    public function get_time_created() {
400
+        $created = $this->get_date_created();
401
+        return empty( $created ) ? current_time( 'timestamp' ) : strtotime( $created, current_time( 'timestamp' ) );
402
+    }
403
+
404
+    /**
405
+     * Get GMT date when the subscription was created.
406
+     *
407
+     * @since 1.0.19
408
+     * @param  string $context View or edit context.
409
+     * @return string
410
+     */
411
+    public function get_date_created_gmt( $context = 'view' ) {
412
+        $date = $this->get_date_created( $context );
413
+
414
+        if ( $date ) {
415
+            $date = get_gmt_from_date( $date );
416
+        }
417
+        return $date;
418
+    }
419
+
420
+    /**
421
+     * Get the date that the subscription will renew.
422
+     *
423
+     * @since 1.0.19
424
+     * @param  string $context View or edit context.
425
+     * @return string
426
+     */
427
+    public function get_next_renewal_date( $context = 'view' ) {
428
+        return $this->get_prop( 'expiration', $context );
429
+    }
430
+
431
+    /**
432
+     * Alias for self::get_next_renewal_date().
433
+     *
434
+     * @since 1.0.19
435
+     * @param  string $context View or edit context.
436
+     * @return string
437
+     */
438
+    public function get_expiration( $context = 'view' ) {
439
+        return $this->get_next_renewal_date( $context );
440
+    }
441
+
442
+    /**
443
+     * Retrieves the expiration date in a timestamp
444
+     *
445
+     * @since  1.0.0
446
+     * @return int
447
+     */
448
+    public function get_expiration_time() {
449
+        $expiration = $this->get_expiration();
450
+
451
+        if ( empty( $expiration ) || '0000-00-00 00:00:00' == $expiration ) {
452
+            return current_time( 'timestamp' );
453
+        }
454
+
455
+        $expiration = strtotime( $expiration, current_time( 'timestamp' ) );
456
+        return $expiration < current_time( 'timestamp' ) ? current_time( 'timestamp' ) : $expiration;
457
+    }
458
+
459
+    /**
460
+     * Get GMT date when the subscription will renew.
461
+     *
462
+     * @since 1.0.19
463
+     * @param  string $context View or edit context.
464
+     * @return string
465
+     */
466
+    public function get_next_renewal_date_gmt( $context = 'view' ) {
467
+        $date = $this->get_next_renewal_date( $context );
468
+
469
+        if ( $date ) {
470
+            $date = get_gmt_from_date( $date );
471
+        }
472
+        return $date;
473
+    }
474
+
475
+    /**
476
+     * Get the subscription's trial period.
477
+     *
478
+     * @since 1.0.19
479
+     * @param  string $context View or edit context.
480
+     * @return string
481
+     */
482
+    public function get_trial_period( $context = 'view' ) {
483
+        return $this->get_prop( 'trial_period', $context );
484
+    }
485
+
486
+    /**
487
+     * Get the subscription's status.
488
+     *
489
+     * @since 1.0.19
490
+     * @param  string $context View or edit context.
491
+     * @return string
492
+     */
493
+    public function get_status( $context = 'view' ) {
494
+        return $this->get_prop( 'status', $context );
495
+    }
496
+
497
+    /**
498
+     * Get the subscription's profile id.
499
+     *
500
+     * @since 1.0.19
501
+     * @param  string $context View or edit context.
502
+     * @return string
503
+     */
504
+    public function get_profile_id( $context = 'view' ) {
505
+        return $this->get_prop( 'profile_id', $context );
506
+    }
507
+
508
+    /*
509
+	|--------------------------------------------------------------------------
510
+	| Setters
511
+	|--------------------------------------------------------------------------
512
+	*/
513
+
514
+    /**
515
+     * Set customer id.
516
+     *
517
+     * @since 1.0.19
518
+     * @param  int $value The customer's id.
519
+     */
520
+    public function set_customer_id( $value ) {
521
+        $this->set_prop( 'customer_id', (int) $value );
522
+    }
523
+
524
+    /**
525
+     * Set parent invoice id.
526
+     *
527
+     * @since 1.0.19
528
+     * @param  int $value The parent invoice id.
529
+     */
530
+    public function set_parent_invoice_id( $value ) {
531
+        $this->set_prop( 'parent_payment_id', (int) $value );
532
+    }
533
+
534
+    /**
535
+     * Alias for self::set_parent_invoice_id().
536
+     *
537
+     * @since 1.0.19
538
+     * @param  int $value The parent invoice id.
539
+     */
540
+    public function set_parent_payment_id( $value ) {
541
+        $this->set_parent_invoice_id( $value );
542
+    }
543
+
544
+    /**
545
+     * Alias for self::set_parent_invoice_id().
546
+     *
547
+     * @since 1.0.19
548
+     * @param  int $value The parent invoice id.
549
+     */
550
+    public function set_original_payment_id( $value ) {
551
+        $this->set_parent_invoice_id( $value );
552
+    }
553
+
554
+    /**
555
+     * Set subscription's product id.
556
+     *
557
+     * @since 1.0.19
558
+     * @param  int $value The subscription product id.
559
+     */
560
+    public function set_product_id( $value ) {
561
+        $this->set_prop( 'product_id', (int) $value );
562
+    }
563
+
564
+    /**
565
+     * Set the period of a renewal.
566
+     *
567
+     * @since 1.0.19
568
+     * @param  string $value The renewal period.
569
+     */
570
+    public function set_period( $value ) {
571
+        $this->set_prop( 'period', $value );
572
+    }
573
+
574
+    /**
575
+     * Set number of periods each renewal is valid for.
576
+     *
577
+     * @since 1.0.19
578
+     * @param  int $value The subscription frequency.
579
+     */
580
+    public function set_frequency( $value ) {
581
+        $value = empty( $value ) ? 1 : (int) $value;
582
+        $this->set_prop( 'frequency', absint( $value ) );
583
+    }
584
+
585
+    /**
586
+     * Set the initial amount for the subscription.
587
+     *
588
+     * @since 1.0.19
589
+     * @param  float $value The initial subcription amount.
590
+     */
591
+    public function set_initial_amount( $value ) {
592
+        $this->set_prop( 'initial_amount', wpinv_sanitize_amount( $value ) );
593
+    }
594
+
595
+    /**
596
+     * Set the recurring amount for the subscription.
597
+     *
598
+     * @since 1.0.19
599
+     * @param  float $value The recurring subcription amount.
600
+     */
601
+    public function set_recurring_amount( $value ) {
602
+        $this->set_prop( 'recurring_amount', wpinv_sanitize_amount( $value ) );
603
+    }
604
+
605
+    /**
606
+     * Set number of times that this subscription can be renewed.
607
+     *
608
+     * @since 1.0.19
609
+     * @param  int $value Bill times.
610
+     */
611
+    public function set_bill_times( $value ) {
612
+        $this->set_prop( 'bill_times', (int) $value );
613
+    }
614
+
615
+    /**
616
+     * Get transaction id of this subscription's parent invoice.
617
+     *
618
+     * @since 1.0.19
619
+     * @param string $value Bill times.
620
+     */
621
+    public function set_transaction_id( $value ) {
622
+        $this->set_prop( 'transaction_id', sanitize_text_field( $value ) );
623
+    }
624
+
625
+    /**
626
+     * Set date when this subscription started.
627
+     *
628
+     * @since 1.0.19
629
+     * @param string $value strtotime compliant date.
630
+     */
631
+    public function set_created( $value ) {
632
+        $date = strtotime( $value );
633
+
634
+        if ( $date && $value !== '0000-00-00 00:00:00' ) {
635
+            $this->set_prop( 'created', gmdate( 'Y-m-d H:i:s', $date ) );
636
+            return;
637
+        }
638
+
639
+        $this->set_prop( 'created', '' );
640
+
641
+    }
237 642
 
238
-	/**
239
-     * Alias for self::get_parent_invoice_id().
643
+    /**
644
+     * Alias for self::set_created().
240 645
      *
241
-     * @since  1.0.0
242
-     * @return int
646
+     * @since 1.0.19
647
+     * @param string $value strtotime compliant date.
243 648
      */
244
-    public function get_original_payment_id( $context = 'view' ) {
245
-        return $this->get_parent_invoice_id( $context );
649
+    public function set_date_created( $value ) {
650
+        $this->set_created( $value );
246 651
     }
247 652
 
248
-	/**
249
-	 * Get parent invoice.
250
-	 *
251
-	 * @since 1.0.19
252
-	 * @param  string $context View or edit context.
253
-	 * @return WPInv_Invoice
254
-	 */
255
-	public function get_parent_invoice( $context = 'view' ) {
256
-		return new WPInv_Invoice( $this->get_parent_invoice_id( $context ) );
257
-	}
258
-
259
-	/**
260
-	 * Alias for self::get_parent_invoice().
261
-	 *
262
-	 * @since 1.0.19
263
-	 * @param  string $context View or edit context.
264
-	 * @return WPInv_Invoice
265
-	 */
266
-    public function get_parent_payment( $context = 'view' ) {
267
-        return $this->get_parent_invoice( $context );
268
-	}
269
-
270
-	/**
271
-	 * Get subscription's product id.
272
-	 *
273
-	 * @since 1.0.19
274
-	 * @param  string $context View or edit context.
275
-	 * @return int
276
-	 */
277
-	public function get_product_id( $context = 'view' ) {
278
-		return (int) $this->get_prop( 'product_id', $context );
279
-	}
280
-
281
-	/**
282
-	 * Get the subscription product.
283
-	 *
284
-	 * @since 1.0.19
285
-	 * @param  string $context View or edit context.
286
-	 * @return WPInv_Item
287
-	 */
288
-	public function get_product( $context = 'view' ) {
289
-		return new WPInv_Item( $this->get_product_id( $context ) );
290
-	}
291
-
292
-	/**
293
-	 * Get parent invoice's gateway.
294
-	 *
295
-	 * Here for backwards compatibility.
296
-	 *
297
-	 * @since 1.0.19
298
-	 * @param  string $context View or edit context.
299
-	 * @return string
300
-	 */
301
-	public function get_gateway( $context = 'view' ) {
302
-		return $this->get_parent_invoice( $context )->get_gateway();
303
-	}
304
-
305
-	/**
306
-	 * Get the period of a renewal.
307
-	 *
308
-	 * @since 1.0.19
309
-	 * @param  string $context View or edit context.
310
-	 * @return string
311
-	 */
312
-	public function get_period( $context = 'view' ) {
313
-		return $this->get_prop( 'period', $context );
314
-	}
315
-
316
-	/**
317
-	 * Get number of periods each renewal is valid for.
318
-	 *
319
-	 * @since 1.0.19
320
-	 * @param  string $context View or edit context.
321
-	 * @return int
322
-	 */
323
-	public function get_frequency( $context = 'view' ) {
324
-		return (int) $this->get_prop( 'frequency', $context );
325
-	}
326
-
327
-	/**
328
-	 * Get the initial amount for the subscription.
329
-	 *
330
-	 * @since 1.0.19
331
-	 * @param  string $context View or edit context.
332
-	 * @return float
333
-	 */
334
-	public function get_initial_amount( $context = 'view' ) {
335
-		return (float) wpinv_sanitize_amount( $this->get_prop( 'initial_amount', $context ) );
336
-	}
337
-
338
-	/**
339
-	 * Get the recurring amount for the subscription.
340
-	 *
341
-	 * @since 1.0.19
342
-	 * @param  string $context View or edit context.
343
-	 * @return float
344
-	 */
345
-	public function get_recurring_amount( $context = 'view' ) {
346
-		return (float) wpinv_sanitize_amount( $this->get_prop( 'recurring_amount', $context ) );
347
-	}
348
-
349
-	/**
350
-	 * Get number of times that this subscription can be renewed.
351
-	 *
352
-	 * @since 1.0.19
353
-	 * @param  string $context View or edit context.
354
-	 * @return int
355
-	 */
356
-	public function get_bill_times( $context = 'view' ) {
357
-		return (int) $this->get_prop( 'bill_times', $context );
358
-	}
359
-
360
-	/**
361
-	 * Get transaction id of this subscription's parent invoice.
362
-	 *
363
-	 * @since 1.0.19
364
-	 * @param  string $context View or edit context.
365
-	 * @return string
366
-	 */
367
-	public function get_transaction_id( $context = 'view' ) {
368
-		return $this->get_prop( 'transaction_id', $context );
369
-	}
370
-
371
-	/**
372
-	 * Get the date that the subscription was created.
373
-	 *
374
-	 * @since 1.0.19
375
-	 * @param  string $context View or edit context.
376
-	 * @return string
377
-	 */
378
-	public function get_created( $context = 'view' ) {
379
-		return $this->get_prop( 'created', $context );
380
-	}
381
-
382
-	/**
383
-	 * Alias for self::get_created().
384
-	 *
385
-	 * @since 1.0.19
386
-	 * @param  string $context View or edit context.
387
-	 * @return string
388
-	 */
389
-	public function get_date_created( $context = 'view' ) {
390
-		return $this->get_created( $context );
391
-	}
392
-
393
-	/**
394
-	 * Retrieves the creation date in a timestamp
395
-	 *
396
-	 * @since  1.0.0
397
-	 * @return int
398
-	 */
399
-	public function get_time_created() {
400
-		$created = $this->get_date_created();
401
-		return empty( $created ) ? current_time( 'timestamp' ) : strtotime( $created, current_time( 'timestamp' ) );
402
-	}
403
-
404
-	/**
405
-	 * Get GMT date when the subscription was created.
406
-	 *
407
-	 * @since 1.0.19
408
-	 * @param  string $context View or edit context.
409
-	 * @return string
410
-	 */
411
-	public function get_date_created_gmt( $context = 'view' ) {
412
-        $date = $this->get_date_created( $context );
653
+    /**
654
+     * Set the date that the subscription will renew.
655
+     *
656
+     * @since 1.0.19
657
+     * @param string $value strtotime compliant date.
658
+     */
659
+    public function set_next_renewal_date( $value ) {
660
+        $date = strtotime( $value );
413 661
 
414
-        if ( $date ) {
415
-            $date = get_gmt_from_date( $date );
662
+        if ( $date && $value !== '0000-00-00 00:00:00' ) {
663
+            $this->set_prop( 'expiration', gmdate( 'Y-m-d H:i:s', $date ) );
664
+            return;
416 665
         }
417
-		return $date;
418
-	}
419
-
420
-	/**
421
-	 * Get the date that the subscription will renew.
422
-	 *
423
-	 * @since 1.0.19
424
-	 * @param  string $context View or edit context.
425
-	 * @return string
426
-	 */
427
-	public function get_next_renewal_date( $context = 'view' ) {
428
-		return $this->get_prop( 'expiration', $context );
429
-	}
430
-
431
-	/**
432
-	 * Alias for self::get_next_renewal_date().
433
-	 *
434
-	 * @since 1.0.19
435
-	 * @param  string $context View or edit context.
436
-	 * @return string
437
-	 */
438
-	public function get_expiration( $context = 'view' ) {
439
-		return $this->get_next_renewal_date( $context );
440
-	}
441
-
442
-	/**
443
-	 * Retrieves the expiration date in a timestamp
444
-	 *
445
-	 * @since  1.0.0
446
-	 * @return int
447
-	 */
448
-	public function get_expiration_time() {
449
-		$expiration = $this->get_expiration();
450
-
451
-		if ( empty( $expiration ) || '0000-00-00 00:00:00' == $expiration ) {
452
-			return current_time( 'timestamp' );
453
-		}
454
-
455
-		$expiration = strtotime( $expiration, current_time( 'timestamp' ) );
456
-		return $expiration < current_time( 'timestamp' ) ? current_time( 'timestamp' ) : $expiration;
457
-	}
458
-
459
-	/**
460
-	 * Get GMT date when the subscription will renew.
461
-	 *
462
-	 * @since 1.0.19
463
-	 * @param  string $context View or edit context.
464
-	 * @return string
465
-	 */
466
-	public function get_next_renewal_date_gmt( $context = 'view' ) {
467
-        $date = $this->get_next_renewal_date( $context );
468 666
 
469
-        if ( $date ) {
470
-            $date = get_gmt_from_date( $date );
471
-        }
472
-		return $date;
473
-	}
474
-
475
-	/**
476
-	 * Get the subscription's trial period.
477
-	 *
478
-	 * @since 1.0.19
479
-	 * @param  string $context View or edit context.
480
-	 * @return string
481
-	 */
482
-	public function get_trial_period( $context = 'view' ) {
483
-		return $this->get_prop( 'trial_period', $context );
484
-	}
485
-
486
-	/**
487
-	 * Get the subscription's status.
488
-	 *
489
-	 * @since 1.0.19
490
-	 * @param  string $context View or edit context.
491
-	 * @return string
492
-	 */
493
-	public function get_status( $context = 'view' ) {
494
-		return $this->get_prop( 'status', $context );
495
-	}
496
-
497
-	/**
498
-	 * Get the subscription's profile id.
499
-	 *
500
-	 * @since 1.0.19
501
-	 * @param  string $context View or edit context.
502
-	 * @return string
503
-	 */
504
-	public function get_profile_id( $context = 'view' ) {
505
-		return $this->get_prop( 'profile_id', $context );
506
-	}
507
-
508
-	/*
509
-	|--------------------------------------------------------------------------
510
-	| Setters
511
-	|--------------------------------------------------------------------------
512
-	*/
667
+        $this->set_prop( 'expiration', '' );
513 668
 
514
-	/**
515
-	 * Set customer id.
516
-	 *
517
-	 * @since 1.0.19
518
-	 * @param  int $value The customer's id.
519
-	 */
520
-	public function set_customer_id( $value ) {
521
-		$this->set_prop( 'customer_id', (int) $value );
522
-	}
523
-
524
-	/**
525
-	 * Set parent invoice id.
526
-	 *
527
-	 * @since 1.0.19
528
-	 * @param  int $value The parent invoice id.
529
-	 */
530
-	public function set_parent_invoice_id( $value ) {
531
-		$this->set_prop( 'parent_payment_id', (int) $value );
532
-	}
533
-
534
-	/**
535
-	 * Alias for self::set_parent_invoice_id().
536
-	 *
537
-	 * @since 1.0.19
538
-	 * @param  int $value The parent invoice id.
539
-	 */
540
-    public function set_parent_payment_id( $value ) {
541
-        $this->set_parent_invoice_id( $value );
542
-	}
669
+    }
543 670
 
544
-	/**
545
-     * Alias for self::set_parent_invoice_id().
671
+    /**
672
+     * Alias for self::set_next_renewal_date().
546 673
      *
547 674
      * @since 1.0.19
548
-	 * @param  int $value The parent invoice id.
675
+     * @param string $value strtotime compliant date.
549 676
      */
550
-    public function set_original_payment_id( $value ) {
551
-        $this->set_parent_invoice_id( $value );
552
-	}
553
-
554
-	/**
555
-	 * Set subscription's product id.
556
-	 *
557
-	 * @since 1.0.19
558
-	 * @param  int $value The subscription product id.
559
-	 */
560
-	public function set_product_id( $value ) {
561
-		$this->set_prop( 'product_id', (int) $value );
562
-	}
563
-
564
-	/**
565
-	 * Set the period of a renewal.
566
-	 *
567
-	 * @since 1.0.19
568
-	 * @param  string $value The renewal period.
569
-	 */
570
-	public function set_period( $value ) {
571
-		$this->set_prop( 'period', $value );
572
-	}
573
-
574
-	/**
575
-	 * Set number of periods each renewal is valid for.
576
-	 *
577
-	 * @since 1.0.19
578
-	 * @param  int $value The subscription frequency.
579
-	 */
580
-	public function set_frequency( $value ) {
581
-		$value = empty( $value ) ? 1 : (int) $value;
582
-		$this->set_prop( 'frequency', absint( $value ) );
583
-	}
584
-
585
-	/**
586
-	 * Set the initial amount for the subscription.
587
-	 *
588
-	 * @since 1.0.19
589
-	 * @param  float $value The initial subcription amount.
590
-	 */
591
-	public function set_initial_amount( $value ) {
592
-		$this->set_prop( 'initial_amount', wpinv_sanitize_amount( $value ) );
593
-	}
594
-
595
-	/**
596
-	 * Set the recurring amount for the subscription.
597
-	 *
598
-	 * @since 1.0.19
599
-	 * @param  float $value The recurring subcription amount.
600
-	 */
601
-	public function set_recurring_amount( $value ) {
602
-		$this->set_prop( 'recurring_amount', wpinv_sanitize_amount( $value ) );
603
-	}
604
-
605
-	/**
606
-	 * Set number of times that this subscription can be renewed.
607
-	 *
608
-	 * @since 1.0.19
609
-	 * @param  int $value Bill times.
610
-	 */
611
-	public function set_bill_times( $value ) {
612
-		$this->set_prop( 'bill_times', (int) $value );
613
-	}
614
-
615
-	/**
616
-	 * Get transaction id of this subscription's parent invoice.
617
-	 *
618
-	 * @since 1.0.19
619
-	 * @param string $value Bill times.
620
-	 */
621
-	public function set_transaction_id( $value ) {
622
-		$this->set_prop( 'transaction_id', sanitize_text_field( $value ) );
623
-	}
624
-
625
-	/**
626
-	 * Set date when this subscription started.
627
-	 *
628
-	 * @since 1.0.19
629
-	 * @param string $value strtotime compliant date.
630
-	 */
631
-	public function set_created( $value ) {
632
-        $date = strtotime( $value );
677
+    public function set_expiration( $value ) {
678
+        $this->set_next_renewal_date( $value );
679
+    }
633 680
 
634
-        if ( $date && $value !== '0000-00-00 00:00:00' ) {
635
-            $this->set_prop( 'created', gmdate( 'Y-m-d H:i:s', $date ) );
681
+    /**
682
+     * Set the subscription's trial period.
683
+     *
684
+     * @since 1.0.19
685
+     * @param string $value trial period e.g 1 year.
686
+     */
687
+    public function set_trial_period( $value ) {
688
+        $this->set_prop( 'trial_period', $value );
689
+    }
690
+
691
+    /**
692
+     * Set the subscription's status.
693
+     *
694
+     * @since 1.0.19
695
+     * @param string $new_status    New subscription status.
696
+     */
697
+    public function set_status( $new_status ) {
698
+
699
+        // Abort if this is not a valid status;
700
+        if ( ! array_key_exists( $new_status, getpaid_get_subscription_statuses() ) ) {
636 701
             return;
637 702
         }
638 703
 
639
-		$this->set_prop( 'created', '' );
640
-
641
-	}
704
+        $old_status = ! empty( $this->status_transition['from'] ) ? $this->status_transition['from'] : $this->get_status();
705
+        if ( true === $this->object_read && $old_status !== $new_status ) {
706
+            $this->status_transition = array(
707
+                'from' => $old_status,
708
+                'to'   => $new_status,
709
+            );
710
+        }
642 711
 
643
-	/**
644
-	 * Alias for self::set_created().
645
-	 *
646
-	 * @since 1.0.19
647
-	 * @param string $value strtotime compliant date.
648
-	 */
649
-	public function set_date_created( $value ) {
650
-		$this->set_created( $value );
712
+        $this->set_prop( 'status', $new_status );
651 713
     }
652 714
 
653
-	/**
654
-	 * Set the date that the subscription will renew.
655
-	 *
656
-	 * @since 1.0.19
657
-	 * @param string $value strtotime compliant date.
658
-	 */
659
-	public function set_next_renewal_date( $value ) {
660
-		$date = strtotime( $value );
715
+    /**
716
+     * Set the subscription's (remote) profile id.
717
+     *
718
+     * @since 1.0.19
719
+     * @param  string $value the remote profile id.
720
+     */
721
+    public function set_profile_id( $value ) {
722
+        $this->set_prop( 'profile_id', sanitize_text_field( $value ) );
723
+    }
661 724
 
662
-        if ( $date && $value !== '0000-00-00 00:00:00' ) {
663
-            $this->set_prop( 'expiration', gmdate( 'Y-m-d H:i:s', $date ) );
664
-            return;
665
-		}
666
-
667
-		$this->set_prop( 'expiration', '' );
668
-
669
-	}
670
-
671
-	/**
672
-	 * Alias for self::set_next_renewal_date().
673
-	 *
674
-	 * @since 1.0.19
675
-	 * @param string $value strtotime compliant date.
676
-	 */
677
-	public function set_expiration( $value ) {
678
-		$this->set_next_renewal_date( $value );
679
-    }
680
-
681
-	/**
682
-	 * Set the subscription's trial period.
683
-	 *
684
-	 * @since 1.0.19
685
-	 * @param string $value trial period e.g 1 year.
686
-	 */
687
-	public function set_trial_period( $value ) {
688
-		$this->set_prop( 'trial_period', $value );
689
-	}
690
-
691
-	/**
692
-	 * Set the subscription's status.
693
-	 *
694
-	 * @since 1.0.19
695
-	 * @param string $new_status    New subscription status.
696
-	 */
697
-	public function set_status( $new_status ) {
698
-
699
-		// Abort if this is not a valid status;
700
-		if ( ! array_key_exists( $new_status, getpaid_get_subscription_statuses() ) ) {
701
-			return;
702
-		}
703
-
704
-		$old_status = ! empty( $this->status_transition['from'] ) ? $this->status_transition['from'] : $this->get_status();
705
-		if ( true === $this->object_read && $old_status !== $new_status ) {
706
-			$this->status_transition = array(
707
-				'from' => $old_status,
708
-				'to'   => $new_status,
709
-			);
710
-		}
711
-
712
-		$this->set_prop( 'status', $new_status );
713
-	}
714
-
715
-	/**
716
-	 * Set the subscription's (remote) profile id.
717
-	 *
718
-	 * @since 1.0.19
719
-	 * @param  string $value the remote profile id.
720
-	 */
721
-	public function set_profile_id( $value ) {
722
-		$this->set_prop( 'profile_id', sanitize_text_field( $value ) );
723
-	}
724
-
725
-	/*
725
+    /*
726 726
 	|--------------------------------------------------------------------------
727 727
 	| Boolean methods
728 728
 	|--------------------------------------------------------------------------
@@ -731,55 +731,55 @@  discard block
 block discarded – undo
731 731
 	|
732 732
 	*/
733 733
 
734
-	/**
734
+    /**
735 735
      * Checks if the subscription has a given status.
736
-	 *
737
-	 * @param string|array String or array of strings to check for.
738
-	 * @return bool
736
+     *
737
+     * @param string|array String or array of strings to check for.
738
+     * @return bool
739 739
      */
740 740
     public function has_status( $status ) {
741 741
         return in_array( $this->get_status(), wpinv_clean( wpinv_parse_list( $status ) ) );
742
-	}
742
+    }
743 743
 
744
-	/**
744
+    /**
745 745
      * Checks if the subscription has a trial period.
746
-	 *
747
-	 * @return bool
746
+     *
747
+     * @return bool
748 748
      */
749 749
     public function has_trial_period() {
750
-		$period = $this->get_trial_period();
750
+        $period = $this->get_trial_period();
751 751
         return ! empty( $period );
752
-	}
753
-
754
-	/**
755
-	 * Is the subscription active?
756
-	 *
757
-	 * @return bool
758
-	 */
759
-	public function is_active() {
760
-		return $this->has_status( 'active trialling' ) && ! $this->is_expired();
761
-	}
762
-
763
-	/**
764
-	 * Is the subscription expired?
765
-	 *
766
-	 * @return bool
767
-	 */
768
-	public function is_expired() {
769
-		return $this->has_status( 'expired' ) || ( $this->has_status( 'active cancelled trialling' ) && $this->get_expiration_time() < current_time( 'timestamp' ) );
770
-	}
771
-
772
-	/**
773
-	 * Is this the last renewals?
774
-	 *
775
-	 * @return bool
776
-	 */
777
-	public function is_last_renewal() {
778
-		$max_bills = $this->get_bill_times();
779
-		return ! empty( $max_bills ) && $max_bills <= $this->get_times_billed();
780
-	}
781
-
782
-	/*
752
+    }
753
+
754
+    /**
755
+     * Is the subscription active?
756
+     *
757
+     * @return bool
758
+     */
759
+    public function is_active() {
760
+        return $this->has_status( 'active trialling' ) && ! $this->is_expired();
761
+    }
762
+
763
+    /**
764
+     * Is the subscription expired?
765
+     *
766
+     * @return bool
767
+     */
768
+    public function is_expired() {
769
+        return $this->has_status( 'expired' ) || ( $this->has_status( 'active cancelled trialling' ) && $this->get_expiration_time() < current_time( 'timestamp' ) );
770
+    }
771
+
772
+    /**
773
+     * Is this the last renewals?
774
+     *
775
+     * @return bool
776
+     */
777
+    public function is_last_renewal() {
778
+        $max_bills = $this->get_bill_times();
779
+        return ! empty( $max_bills ) && $max_bills <= $this->get_times_billed();
780
+    }
781
+
782
+    /*
783 783
 	|--------------------------------------------------------------------------
784 784
 	| Additional methods
785 785
 	|--------------------------------------------------------------------------
@@ -788,27 +788,27 @@  discard block
 block discarded – undo
788 788
 	|
789 789
 	*/
790 790
 
791
-	/**
792
-	 * Backwards compatibilty.
793
-	 */
794
-	public function create( $data = array() ) {
791
+    /**
792
+     * Backwards compatibilty.
793
+     */
794
+    public function create( $data = array() ) {
795 795
 
796
-		// Set the properties.
797
-		if ( is_array( $data ) ) {
798
-			$this->set_props( $data );
799
-		}
796
+        // Set the properties.
797
+        if ( is_array( $data ) ) {
798
+            $this->set_props( $data );
799
+        }
800 800
 
801
-		// Save the item.
802
-		return $this->save();
801
+        // Save the item.
802
+        return $this->save();
803 803
 
804
-	}
804
+    }
805 805
 
806
-	/**
807
-	 * Backwards compatibilty.
808
-	 */
809
-	public function update( $args = array() ) {
810
-		return $this->create( $args );
811
-	}
806
+    /**
807
+     * Backwards compatibilty.
808
+     */
809
+    public function update( $args = array() ) {
810
+        return $this->create( $args );
811
+    }
812 812
 
813 813
     /**
814 814
      * Retrieve renewal payments for a subscription
@@ -818,22 +818,22 @@  discard block
 block discarded – undo
818 818
      */
819 819
     public function get_child_payments( $hide_pending = true ) {
820 820
 
821
-		$statuses = array( 'publish', 'wpi-processing', 'wpi-renewal' );
821
+        $statuses = array( 'publish', 'wpi-processing', 'wpi-renewal' );
822 822
 
823
-		if ( ! $hide_pending ) {
824
-			$statuses = array_keys( wpinv_get_invoice_statuses() );
825
-		}
823
+        if ( ! $hide_pending ) {
824
+            $statuses = array_keys( wpinv_get_invoice_statuses() );
825
+        }
826 826
 
827 827
         return get_posts(
828
-			array(
829
-            	'post_parent' => $this->get_parent_payment_id(),
830
-            	'numberposts' => -1,
831
-            	'post_status' => $statuses,
832
-            	'orderby'     => 'ID',
833
-            	'order'       => 'ASC',
834
-            	'post_type'   => 'wpi_invoice',
835
-			)
836
-		);
828
+            array(
829
+                'post_parent' => $this->get_parent_payment_id(),
830
+                'numberposts' => -1,
831
+                'post_status' => $statuses,
832
+                'orderby'     => 'ID',
833
+                'order'       => 'ASC',
834
+                'post_type'   => 'wpi_invoice',
835
+            )
836
+        );
837 837
     }
838 838
 
839 839
     /**
@@ -843,7 +843,7 @@  discard block
 block discarded – undo
843 843
      * @return int
844 844
      */
845 845
     public function get_total_payments() {
846
-		return getpaid_count_subscription_invoices( $this->get_parent_invoice_id(), $this->get_id() );
846
+        return getpaid_count_subscription_invoices( $this->get_parent_invoice_id(), $this->get_id() );
847 847
     }
848 848
 
849 849
     /**
@@ -867,192 +867,192 @@  discard block
 block discarded – undo
867 867
      *
868 868
      * @since  2.4
869 869
      * @param  array $args Array of values for the payment, including amount and transaction ID
870
-	 * @param  WPInv_Invoice $invoice If adding an existing invoice.
870
+     * @param  WPInv_Invoice $invoice If adding an existing invoice.
871 871
      * @return bool
872 872
      */
873 873
     public function add_payment( $args = array(), $invoice = false ) {
874 874
 
875
-		// Process each payment once.
875
+        // Process each payment once.
876 876
         if ( ! empty( $args['transaction_id'] ) && $this->payment_exists( $args['transaction_id'] ) ) {
877 877
             return false;
878 878
         }
879 879
 
880
-		// Are we creating a new invoice?
881
-		if ( empty( $invoice ) ) {
882
-			$invoice = $this->create_payment( false );
880
+        // Are we creating a new invoice?
881
+        if ( empty( $invoice ) ) {
882
+            $invoice = $this->create_payment( false );
883 883
 
884
-			if ( empty( $invoice ) ) {
885
-				return false;
886
-			}
887
-		}
884
+            if ( empty( $invoice ) ) {
885
+                return false;
886
+            }
887
+        }
888 888
 
889
-		// Maybe set a transaction id.
890
-		if ( ! empty( $args['transaction_id'] ) ) {
891
-			$invoice->set_transaction_id( $args['transaction_id'] );
892
-		}
889
+        // Maybe set a transaction id.
890
+        if ( ! empty( $args['transaction_id'] ) ) {
891
+            $invoice->set_transaction_id( $args['transaction_id'] );
892
+        }
893 893
 
894
-		// Set the completed date.
895
-		$invoice->set_completed_date( current_time( 'mysql' ) );
894
+        // Set the completed date.
895
+        $invoice->set_completed_date( current_time( 'mysql' ) );
896 896
 
897
-		// And the gateway.
898
-		if ( ! empty( $args['gateway'] ) ) {
899
-			$invoice->set_gateway( $args['gateway'] );
900
-		}
897
+        // And the gateway.
898
+        if ( ! empty( $args['gateway'] ) ) {
899
+            $invoice->set_gateway( $args['gateway'] );
900
+        }
901 901
 
902
-		$invoice->set_status( 'wpi-renewal' );
903
-		$invoice->save();
902
+        $invoice->set_status( 'wpi-renewal' );
903
+        $invoice->save();
904 904
 
905
-		if ( ! $invoice->exists() ) {
906
-			return false;
907
-		}
905
+        if ( ! $invoice->exists() ) {
906
+            return false;
907
+        }
908 908
 
909
-		return $this->after_add_payment( $invoice );
910
-	}
909
+        return $this->after_add_payment( $invoice );
910
+    }
911 911
 
912 912
     public function after_add_payment( $invoice ) {
913 913
 
914
-		do_action( 'getpaid_after_create_subscription_renewal_invoice', $invoice, $this );
915
-		do_action( 'wpinv_recurring_add_subscription_payment', $invoice, $this );
914
+        do_action( 'getpaid_after_create_subscription_renewal_invoice', $invoice, $this );
915
+        do_action( 'wpinv_recurring_add_subscription_payment', $invoice, $this );
916 916
         do_action( 'wpinv_recurring_record_payment', $invoice->get_id(), $this->get_parent_invoice_id(), $invoice->get_recurring_total(), $invoice->get_transaction_id() );
917 917
 
918 918
         update_post_meta( $invoice->get_id(), '_wpinv_subscription_id', $this->id );
919 919
 
920 920
         return $invoice->get_id();
921
-	}
921
+    }
922 922
 
923
-	/**
923
+    /**
924 924
      * Creates a new invoice and returns it.
925 925
      *
926 926
      * @since  1.0.19
927
-	 * @param bool $save Whether we should save the invoice.
927
+     * @param bool $save Whether we should save the invoice.
928 928
      * @return WPInv_Invoice|bool
929 929
      */
930 930
     public function create_payment( $save = true ) {
931 931
 
932
-		$parent_invoice = $this->get_parent_payment();
933
-
934
-		if ( ! $parent_invoice->exists() ) {
935
-			return false;
936
-		}
937
-
938
-		// Duplicate the parent invoice.
939
-		$invoice = getpaid_duplicate_invoice( $parent_invoice );
940
-		$invoice->set_parent_id( $parent_invoice->get_id() );
941
-		$invoice->set_subscription_id( $this->get_id() );
942
-		$invoice->set_remote_subscription_id( $this->get_profile_id() );
943
-
944
-		// Set invoice items.
945
-		$subscription_group = getpaid_get_invoice_subscription_group( $parent_invoice->get_id(), $this->get_id() );
946
-		$allowed_items      = empty( $subscription_group ) ? array( $this->get_product_id() ) : array_keys( $subscription_group['items'] );
947
-		$invoice_items      = array();
948
-
949
-		foreach ( $invoice->get_items() as $item ) {
950
-			if ( in_array( $item->get_id(), $allowed_items ) ) {
951
-				$invoice_items[] = $item;
952
-			}
953
-		}
954
-
955
-		$invoice->set_items( $invoice_items );
956
-
957
-		if ( ! empty( $subscription_group['fees'] ) ) {
958
-			$invoice->set_fees( $subscription_group['fees'] );
959
-		}
960
-
961
-		// Maybe recalculate discount (Pre-GetPaid Fix).
962
-		$discount = new WPInv_Discount( $invoice->get_discount_code() );
963
-		if ( $discount->exists() && $discount->is_recurring() && 0 == $invoice->get_total_discount() ) {
964
-			$invoice->add_discount( getpaid_calculate_invoice_discount( $invoice, $discount ) );
965
-		}
966
-
967
-		$invoice->recalculate_total();
968
-		$invoice->set_status( 'wpi-pending' );
969
-
970
-		if ( ! $save ) {
971
-			return $invoice;
972
-		}
973
-
974
-		$invoice->save();
975
-
976
-		return $invoice->exists() ? $invoice : false;
977
-    }
978
-
979
-	/**
980
-	 * Renews or completes a subscription
981
-	 *
982
-	 * @since  1.0.0
983
-	 * @return int The subscription's id
984
-	 */
985
-	public function renew( $calculate_from = null ) {
986
-
987
-		// Complete subscription if applicable
988
-		if ( $this->is_last_renewal() ) {
989
-			return $this->complete();
990
-		}
991
-
992
-		// Calculate new expiration
993
-		$frequency      = $this->get_frequency();
994
-		$period         = $this->get_period();
995
-		$calculate_from = empty( $calculate_from ) ? $this->get_expiration_time() : $calculate_from;
996
-		$new_expiration = strtotime( "+ $frequency $period", $calculate_from );
997
-
998
-		$this->set_expiration( date( 'Y-m-d H:i:s', $new_expiration ) );
999
-		$this->set_status( 'active' );
1000
-		$this->save();
1001
-
1002
-		do_action( 'getpaid_subscription_renewed', $this );
1003
-
1004
-		return $this->get_id();
1005
-	}
1006
-
1007
-	/**
1008
-	 * Marks a subscription as completed
1009
-	 *
1010
-	 * Subscription is completed when the number of payments matches the billing_times field
1011
-	 *
1012
-	 * @since  1.0.0
1013
-	 * @return int|bool Subscription id or false if the subscription is cancelled.
1014
-	 */
1015
-	public function complete() {
1016
-
1017
-		// Only mark a subscription as complete if it's not already cancelled.
1018
-		if ( $this->has_status( 'cancelled' ) ) {
1019
-			return false;
1020
-		}
1021
-
1022
-		$this->set_status( 'completed' );
1023
-		return $this->save();
1024
-
1025
-	}
1026
-
1027
-	/**
1028
-	 * Marks a subscription as expired
1029
-	 *
1030
-	 * @since  1.0.0
1031
-	 * @param  bool $check_expiration
1032
-	 * @return int|bool Subscription id or false if $check_expiration is true and expiration date is in the future.
1033
-	 */
1034
-	public function expire( $check_expiration = false ) {
1035
-
1036
-		if ( $check_expiration && $this->get_expiration_time() > current_time( 'timestamp' ) ) {
1037
-			// Do not mark as expired since real expiration date is in the future
1038
-			return false;
1039
-		}
1040
-
1041
-		$this->set_status( 'expired' );
1042
-		return $this->save();
1043
-
1044
-	}
1045
-
1046
-	/**
1047
-	 * Marks a subscription as failing
1048
-	 *
1049
-	 * @since  2.4.2
1050
-	 * @return int Subscription id.
1051
-	 */
1052
-	public function failing() {
1053
-		$this->set_status( 'failing' );
1054
-		return $this->save();
1055
-	}
932
+        $parent_invoice = $this->get_parent_payment();
933
+
934
+        if ( ! $parent_invoice->exists() ) {
935
+            return false;
936
+        }
937
+
938
+        // Duplicate the parent invoice.
939
+        $invoice = getpaid_duplicate_invoice( $parent_invoice );
940
+        $invoice->set_parent_id( $parent_invoice->get_id() );
941
+        $invoice->set_subscription_id( $this->get_id() );
942
+        $invoice->set_remote_subscription_id( $this->get_profile_id() );
943
+
944
+        // Set invoice items.
945
+        $subscription_group = getpaid_get_invoice_subscription_group( $parent_invoice->get_id(), $this->get_id() );
946
+        $allowed_items      = empty( $subscription_group ) ? array( $this->get_product_id() ) : array_keys( $subscription_group['items'] );
947
+        $invoice_items      = array();
948
+
949
+        foreach ( $invoice->get_items() as $item ) {
950
+            if ( in_array( $item->get_id(), $allowed_items ) ) {
951
+                $invoice_items[] = $item;
952
+            }
953
+        }
954
+
955
+        $invoice->set_items( $invoice_items );
956
+
957
+        if ( ! empty( $subscription_group['fees'] ) ) {
958
+            $invoice->set_fees( $subscription_group['fees'] );
959
+        }
960
+
961
+        // Maybe recalculate discount (Pre-GetPaid Fix).
962
+        $discount = new WPInv_Discount( $invoice->get_discount_code() );
963
+        if ( $discount->exists() && $discount->is_recurring() && 0 == $invoice->get_total_discount() ) {
964
+            $invoice->add_discount( getpaid_calculate_invoice_discount( $invoice, $discount ) );
965
+        }
966
+
967
+        $invoice->recalculate_total();
968
+        $invoice->set_status( 'wpi-pending' );
969
+
970
+        if ( ! $save ) {
971
+            return $invoice;
972
+        }
973
+
974
+        $invoice->save();
975
+
976
+        return $invoice->exists() ? $invoice : false;
977
+    }
978
+
979
+    /**
980
+     * Renews or completes a subscription
981
+     *
982
+     * @since  1.0.0
983
+     * @return int The subscription's id
984
+     */
985
+    public function renew( $calculate_from = null ) {
986
+
987
+        // Complete subscription if applicable
988
+        if ( $this->is_last_renewal() ) {
989
+            return $this->complete();
990
+        }
991
+
992
+        // Calculate new expiration
993
+        $frequency      = $this->get_frequency();
994
+        $period         = $this->get_period();
995
+        $calculate_from = empty( $calculate_from ) ? $this->get_expiration_time() : $calculate_from;
996
+        $new_expiration = strtotime( "+ $frequency $period", $calculate_from );
997
+
998
+        $this->set_expiration( date( 'Y-m-d H:i:s', $new_expiration ) );
999
+        $this->set_status( 'active' );
1000
+        $this->save();
1001
+
1002
+        do_action( 'getpaid_subscription_renewed', $this );
1003
+
1004
+        return $this->get_id();
1005
+    }
1006
+
1007
+    /**
1008
+     * Marks a subscription as completed
1009
+     *
1010
+     * Subscription is completed when the number of payments matches the billing_times field
1011
+     *
1012
+     * @since  1.0.0
1013
+     * @return int|bool Subscription id or false if the subscription is cancelled.
1014
+     */
1015
+    public function complete() {
1016
+
1017
+        // Only mark a subscription as complete if it's not already cancelled.
1018
+        if ( $this->has_status( 'cancelled' ) ) {
1019
+            return false;
1020
+        }
1021
+
1022
+        $this->set_status( 'completed' );
1023
+        return $this->save();
1024
+
1025
+    }
1026
+
1027
+    /**
1028
+     * Marks a subscription as expired
1029
+     *
1030
+     * @since  1.0.0
1031
+     * @param  bool $check_expiration
1032
+     * @return int|bool Subscription id or false if $check_expiration is true and expiration date is in the future.
1033
+     */
1034
+    public function expire( $check_expiration = false ) {
1035
+
1036
+        if ( $check_expiration && $this->get_expiration_time() > current_time( 'timestamp' ) ) {
1037
+            // Do not mark as expired since real expiration date is in the future
1038
+            return false;
1039
+        }
1040
+
1041
+        $this->set_status( 'expired' );
1042
+        return $this->save();
1043
+
1044
+    }
1045
+
1046
+    /**
1047
+     * Marks a subscription as failing
1048
+     *
1049
+     * @since  2.4.2
1050
+     * @return int Subscription id.
1051
+     */
1052
+    public function failing() {
1053
+        $this->set_status( 'failing' );
1054
+        return $this->save();
1055
+    }
1056 1056
 
1057 1057
     /**
1058 1058
      * Marks a subscription as cancelled
@@ -1061,19 +1061,19 @@  discard block
 block discarded – undo
1061 1061
      * @return int Subscription id.
1062 1062
      */
1063 1063
     public function cancel() {
1064
-		$this->set_status( 'cancelled' );
1065
-		return $this->save();
1064
+        $this->set_status( 'cancelled' );
1065
+        return $this->save();
1066 1066
     }
1067 1067
 
1068
-	/**
1069
-	 * Determines if a subscription can be cancelled both locally and with a payment processor.
1070
-	 *
1071
-	 * @since  1.0.0
1072
-	 * @return bool
1073
-	 */
1074
-	public function can_cancel() {
1075
-		return apply_filters( 'wpinv_subscription_can_cancel', $this->has_status( $this->get_cancellable_statuses() ), $this );
1076
-	}
1068
+    /**
1069
+     * Determines if a subscription can be cancelled both locally and with a payment processor.
1070
+     *
1071
+     * @since  1.0.0
1072
+     * @return bool
1073
+     */
1074
+    public function can_cancel() {
1075
+        return apply_filters( 'wpinv_subscription_can_cancel', $this->has_status( $this->get_cancellable_statuses() ), $this );
1076
+    }
1077 1077
 
1078 1078
     /**
1079 1079
      * Returns an array of subscription statuses that can be cancelled
@@ -1086,109 +1086,109 @@  discard block
 block discarded – undo
1086 1086
         return apply_filters( 'wpinv_recurring_cancellable_statuses', array( 'active', 'trialling', 'failing' ) );
1087 1087
     }
1088 1088
 
1089
-	/**
1090
-	 * Retrieves the URL to cancel subscription
1091
-	 *
1092
-	 * @since  1.0.0
1093
-	 * @return string
1094
-	 */
1095
-	public function get_cancel_url() {
1096
-		$url = getpaid_get_authenticated_action_url( 'subscription_cancel', $this->get_view_url() );
1097
-		return apply_filters( 'wpinv_subscription_cancel_url', $url, $this );
1098
-	}
1099
-
1100
-	/**
1101
-	 * Retrieves the URL to view a subscription
1102
-	 *
1103
-	 * @since  1.0.19
1104
-	 * @return string
1105
-	 */
1106
-	public function get_view_url() {
1107
-
1108
-		$url = getpaid_get_tab_url( 'gp-subscriptions', get_permalink( (int) wpinv_get_option( 'invoice_subscription_page' ) ) );
1109
-		$url = add_query_arg( 'subscription', $this->get_id(), $url );
1110
-
1111
-		return apply_filters( 'getpaid_get_subscription_view_url', $url, $this );
1112
-	}
1113
-
1114
-	/**
1115
-	 * Determines if subscription can be manually renewed
1116
-	 *
1117
-	 * This method is filtered by payment gateways in order to return true on subscriptions
1118
-	 * that can be renewed manually
1119
-	 *
1120
-	 * @since  2.5
1121
-	 * @return bool
1122
-	 */
1123
-	public function can_renew() {
1124
-		return apply_filters( 'wpinv_subscription_can_renew', true, $this );
1125
-	}
1126
-
1127
-	/**
1128
-	 * Retrieves the URL to renew a subscription
1129
-	 *
1130
-	 * @since  2.5
1131
-	 * @return string
1132
-	 */
1133
-	public function get_renew_url() {
1134
-		$url = wp_nonce_url(
1089
+    /**
1090
+     * Retrieves the URL to cancel subscription
1091
+     *
1092
+     * @since  1.0.0
1093
+     * @return string
1094
+     */
1095
+    public function get_cancel_url() {
1096
+        $url = getpaid_get_authenticated_action_url( 'subscription_cancel', $this->get_view_url() );
1097
+        return apply_filters( 'wpinv_subscription_cancel_url', $url, $this );
1098
+    }
1099
+
1100
+    /**
1101
+     * Retrieves the URL to view a subscription
1102
+     *
1103
+     * @since  1.0.19
1104
+     * @return string
1105
+     */
1106
+    public function get_view_url() {
1107
+
1108
+        $url = getpaid_get_tab_url( 'gp-subscriptions', get_permalink( (int) wpinv_get_option( 'invoice_subscription_page' ) ) );
1109
+        $url = add_query_arg( 'subscription', $this->get_id(), $url );
1110
+
1111
+        return apply_filters( 'getpaid_get_subscription_view_url', $url, $this );
1112
+    }
1113
+
1114
+    /**
1115
+     * Determines if subscription can be manually renewed
1116
+     *
1117
+     * This method is filtered by payment gateways in order to return true on subscriptions
1118
+     * that can be renewed manually
1119
+     *
1120
+     * @since  2.5
1121
+     * @return bool
1122
+     */
1123
+    public function can_renew() {
1124
+        return apply_filters( 'wpinv_subscription_can_renew', true, $this );
1125
+    }
1126
+
1127
+    /**
1128
+     * Retrieves the URL to renew a subscription
1129
+     *
1130
+     * @since  2.5
1131
+     * @return string
1132
+     */
1133
+    public function get_renew_url() {
1134
+        $url = wp_nonce_url(
1135 1135
             add_query_arg(
1136 1136
                 array(
1137
-					'getpaid-action' => 'renew_subscription',
1138
-					'sub_id'         => $this->get_id,
1137
+                    'getpaid-action' => 'renew_subscription',
1138
+                    'sub_id'         => $this->get_id,
1139 1139
                 )
1140 1140
             ),
1141 1141
             'getpaid-nonce'
1142 1142
         );
1143
-		return apply_filters( 'wpinv_subscription_renew_url', $url, $this );
1144
-	}
1145
-
1146
-	/**
1147
-	 * Determines if subscription can have their payment method updated
1148
-	 *
1149
-	 * @since  1.0.0
1150
-	 * @return bool
1151
-	 */
1152
-	public function can_update() {
1153
-		return apply_filters( 'wpinv_subscription_can_update', false, $this );
1154
-	}
1155
-
1156
-	/**
1157
-	 * Retrieves the URL to update subscription
1158
-	 *
1159
-	 * @since  1.0.0
1160
-	 * @return string
1161
-	 */
1162
-	public function get_update_url() {
1163
-		$url = add_query_arg(
1143
+        return apply_filters( 'wpinv_subscription_renew_url', $url, $this );
1144
+    }
1145
+
1146
+    /**
1147
+     * Determines if subscription can have their payment method updated
1148
+     *
1149
+     * @since  1.0.0
1150
+     * @return bool
1151
+     */
1152
+    public function can_update() {
1153
+        return apply_filters( 'wpinv_subscription_can_update', false, $this );
1154
+    }
1155
+
1156
+    /**
1157
+     * Retrieves the URL to update subscription
1158
+     *
1159
+     * @since  1.0.0
1160
+     * @return string
1161
+     */
1162
+    public function get_update_url() {
1163
+        $url = add_query_arg(
1164 1164
             array(
1165
-				'action'          => 'update',
1166
-				'subscription_id' => $this->get_id(),
1165
+                'action'          => 'update',
1166
+                'subscription_id' => $this->get_id(),
1167 1167
             )
1168 1168
         );
1169
-		return apply_filters( 'wpinv_subscription_update_url', $url, $this );
1170
-	}
1171
-
1172
-	/**
1173
-	 * Retrieves the subscription status label
1174
-	 *
1175
-	 * @since  1.0.0
1176
-	 * @return string
1177
-	 */
1178
-	public function get_status_label() {
1179
-		return getpaid_get_subscription_status_label( $this->get_status() );
1180
-	}
1181
-
1182
-	/**
1183
-	 * Retrieves the subscription status class
1184
-	 *
1185
-	 * @since  1.0.19
1186
-	 * @return string
1187
-	 */
1188
-	public function get_status_class() {
1189
-		$statuses = getpaid_get_subscription_status_classes();
1190
-		return isset( $statuses[ $this->get_status() ] ) ? $statuses[ $this->get_status() ] : 'bg-dark';
1191
-	}
1169
+        return apply_filters( 'wpinv_subscription_update_url', $url, $this );
1170
+    }
1171
+
1172
+    /**
1173
+     * Retrieves the subscription status label
1174
+     *
1175
+     * @since  1.0.0
1176
+     * @return string
1177
+     */
1178
+    public function get_status_label() {
1179
+        return getpaid_get_subscription_status_label( $this->get_status() );
1180
+    }
1181
+
1182
+    /**
1183
+     * Retrieves the subscription status class
1184
+     *
1185
+     * @since  1.0.19
1186
+     * @return string
1187
+     */
1188
+    public function get_status_class() {
1189
+        $statuses = getpaid_get_subscription_status_classes();
1190
+        return isset( $statuses[ $this->get_status() ] ) ? $statuses[ $this->get_status() ] : 'bg-dark';
1191
+    }
1192 1192
 
1193 1193
     /**
1194 1194
      * Retrieves the subscription status label
@@ -1198,11 +1198,11 @@  discard block
 block discarded – undo
1198 1198
      */
1199 1199
     public function get_status_label_html() {
1200 1200
 
1201
-		$status_label = sanitize_text_field( $this->get_status_label() );
1202
-		$class        = esc_attr( $this->get_status_class() );
1203
-		$status       = sanitize_html_class( $this->get_status() );
1201
+        $status_label = sanitize_text_field( $this->get_status_label() );
1202
+        $class        = esc_attr( $this->get_status_class() );
1203
+        $status       = sanitize_html_class( $this->get_status() );
1204 1204
 
1205
-		return "<span class='bsui'><span class='badge $class $status'>$status_label</span></span>";
1205
+        return "<span class='bsui'><span class='badge $class $status'>$status_label</span></span>";
1206 1206
     }
1207 1207
 
1208 1208
     /**
@@ -1213,75 +1213,75 @@  discard block
 block discarded – undo
1213 1213
      * @return bool
1214 1214
      */
1215 1215
     public function payment_exists( $txn_id = '' ) {
1216
-		$invoice_id = WPInv_Invoice::get_invoice_id_by_field( $txn_id, 'transaction_id' );
1216
+        $invoice_id = WPInv_Invoice::get_invoice_id_by_field( $txn_id, 'transaction_id' );
1217 1217
         return ! empty( $invoice_id );
1218
-	}
1219
-
1220
-	/**
1221
-	 * Handle the status transition.
1222
-	 */
1223
-	protected function status_transition() {
1224
-		$status_transition = $this->status_transition;
1225
-
1226
-		// Reset status transition variable.
1227
-		$this->status_transition = false;
1228
-
1229
-		if ( $status_transition ) {
1230
-			try {
1231
-
1232
-				// Fire a hook for the status change.
1233
-				do_action( 'wpinv_subscription_' . $status_transition['to'], $this->get_id(), $this, $status_transition );
1234
-				do_action( 'getpaid_subscription_' . $status_transition['to'], $this, $status_transition );
1235
-
1236
-				if ( ! empty( $status_transition['from'] ) ) {
1237
-
1238
-					/* translators: 1: old subscription status 2: new subscription status */
1239
-					$transition_note = sprintf( __( 'Subscription status changed from %1$s to %2$s.', 'invoicing' ), getpaid_get_subscription_status_label( $status_transition['from'] ), getpaid_get_subscription_status_label( $status_transition['to'] ) );
1240
-
1241
-					// Note the transition occurred.
1242
-					$this->get_parent_payment()->add_note( $transition_note, false, false, true );
1243
-
1244
-					// Fire another hook.
1245
-					do_action( 'getpaid_subscription_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this->get_id(), $this );
1246
-					do_action( 'getpaid_subscription_status_changed', $this, $status_transition['from'], $status_transition['to'] );
1247
-
1248
-				} else {
1249
-					/* translators: %s: new invoice status */
1250
-					$transition_note = sprintf( __( 'Subscription status set to %s.', 'invoicing' ), getpaid_get_subscription_status_label( $status_transition['to'] ) );
1251
-
1252
-					// Note the transition occurred.
1253
-					$this->get_parent_payment()->add_note( $transition_note, false, false, true );
1254
-
1255
-				}
1256
-			} catch ( Exception $e ) {
1257
-				$this->get_parent_payment()->add_note( __( 'Error during subscription status transition.', 'invoicing' ) . ' ' . $e->getMessage() );
1258
-			}
1259
-		}
1260
-
1261
-	}
1262
-
1263
-	/**
1264
-	 * Save data to the database.
1265
-	 *
1266
-	 * @since 1.0.19
1267
-	 * @return int subscription ID
1268
-	 */
1269
-	public function save() {
1270
-		parent::save();
1271
-		$this->status_transition();
1272
-		return $this->get_id();
1273
-	}
1274
-
1275
-	/**
1276
-	 * Activates a subscription.
1277
-	 *
1278
-	 * @since 1.0.19
1279
-	 * @return int subscription ID
1280
-	 */
1281
-	public function activate() {
1282
-		$status = $this->has_trial_period() && 'trialling' === $this->get_status() ? 'trialling' : 'active';
1283
-		$this->set_status( $status );
1284
-		return $this->save();
1285
-	}
1218
+    }
1219
+
1220
+    /**
1221
+     * Handle the status transition.
1222
+     */
1223
+    protected function status_transition() {
1224
+        $status_transition = $this->status_transition;
1225
+
1226
+        // Reset status transition variable.
1227
+        $this->status_transition = false;
1228
+
1229
+        if ( $status_transition ) {
1230
+            try {
1231
+
1232
+                // Fire a hook for the status change.
1233
+                do_action( 'wpinv_subscription_' . $status_transition['to'], $this->get_id(), $this, $status_transition );
1234
+                do_action( 'getpaid_subscription_' . $status_transition['to'], $this, $status_transition );
1235
+
1236
+                if ( ! empty( $status_transition['from'] ) ) {
1237
+
1238
+                    /* translators: 1: old subscription status 2: new subscription status */
1239
+                    $transition_note = sprintf( __( 'Subscription status changed from %1$s to %2$s.', 'invoicing' ), getpaid_get_subscription_status_label( $status_transition['from'] ), getpaid_get_subscription_status_label( $status_transition['to'] ) );
1240
+
1241
+                    // Note the transition occurred.
1242
+                    $this->get_parent_payment()->add_note( $transition_note, false, false, true );
1243
+
1244
+                    // Fire another hook.
1245
+                    do_action( 'getpaid_subscription_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this->get_id(), $this );
1246
+                    do_action( 'getpaid_subscription_status_changed', $this, $status_transition['from'], $status_transition['to'] );
1247
+
1248
+                } else {
1249
+                    /* translators: %s: new invoice status */
1250
+                    $transition_note = sprintf( __( 'Subscription status set to %s.', 'invoicing' ), getpaid_get_subscription_status_label( $status_transition['to'] ) );
1251
+
1252
+                    // Note the transition occurred.
1253
+                    $this->get_parent_payment()->add_note( $transition_note, false, false, true );
1254
+
1255
+                }
1256
+            } catch ( Exception $e ) {
1257
+                $this->get_parent_payment()->add_note( __( 'Error during subscription status transition.', 'invoicing' ) . ' ' . $e->getMessage() );
1258
+            }
1259
+        }
1260
+
1261
+    }
1262
+
1263
+    /**
1264
+     * Save data to the database.
1265
+     *
1266
+     * @since 1.0.19
1267
+     * @return int subscription ID
1268
+     */
1269
+    public function save() {
1270
+        parent::save();
1271
+        $this->status_transition();
1272
+        return $this->get_id();
1273
+    }
1274
+
1275
+    /**
1276
+     * Activates a subscription.
1277
+     *
1278
+     * @since 1.0.19
1279
+     * @return int subscription ID
1280
+     */
1281
+    public function activate() {
1282
+        $status = $this->has_trial_period() && 'trialling' === $this->get_status() ? 'trialling' : 'active';
1283
+        $this->set_status( $status );
1284
+        return $this->save();
1285
+    }
1286 1286
 
1287 1287
 }
Please login to merge, or discard this patch.
Spacing   +234 added lines, -234 removed lines patch added patch discarded remove patch
@@ -6,7 +6,7 @@  discard block
 block discarded – undo
6 6
  * @package Invoicing
7 7
  */
8 8
 
9
-defined( 'ABSPATH' ) || exit;
9
+defined('ABSPATH') || exit;
10 10
 
11 11
 /**
12 12
  * The Subscription Class
@@ -68,27 +68,27 @@  discard block
 block discarded – undo
68 68
 	 * @param  int|string|object|WPInv_Subscription $subscription Subscription id, profile_id, or object to read.
69 69
 	 * @param  bool $deprecated
70 70
 	 */
71
-	function __construct( $subscription = 0, $deprecated = false ) {
71
+	function __construct($subscription = 0, $deprecated = false) {
72 72
 
73
-		parent::__construct( $subscription );
73
+		parent::__construct($subscription);
74 74
 
75
-		if ( ! $deprecated && ! empty( $subscription ) && is_numeric( $subscription ) ) {
76
-			$this->set_id( $subscription );
77
-		} elseif ( $subscription instanceof self ) {
78
-			$this->set_id( $subscription->get_id() );
79
-		} elseif ( $deprecated && $subscription_id = self::get_subscription_id_by_field( $subscription, 'profile_id' ) ) {
80
-			$this->set_id( $subscription_id );
81
-		} elseif ( ! empty( $subscription->id ) ) {
82
-			$this->set_id( $subscription->id );
75
+		if (!$deprecated && !empty($subscription) && is_numeric($subscription)) {
76
+			$this->set_id($subscription);
77
+		} elseif ($subscription instanceof self) {
78
+			$this->set_id($subscription->get_id());
79
+		} elseif ($deprecated && $subscription_id = self::get_subscription_id_by_field($subscription, 'profile_id')) {
80
+			$this->set_id($subscription_id);
81
+		} elseif (!empty($subscription->id)) {
82
+			$this->set_id($subscription->id);
83 83
 		} else {
84
-			$this->set_object_read( true );
84
+			$this->set_object_read(true);
85 85
 		}
86 86
 
87 87
 		// Load the datastore.
88
-		$this->data_store = GetPaid_Data_Store::load( $this->data_store_name );
88
+		$this->data_store = GetPaid_Data_Store::load($this->data_store_name);
89 89
 
90
-		if ( $this->get_id() > 0 ) {
91
-			$this->data_store->read( $this );
90
+		if ($this->get_id() > 0) {
91
+			$this->data_store->read($this);
92 92
 		}
93 93
 
94 94
 	}
@@ -103,17 +103,17 @@  discard block
 block discarded – undo
103 103
 	 * @since 1.0.19
104 104
 	 * @return int
105 105
 	 */
106
-	public static function get_subscription_id_by_field( $value, $field = 'profile_id' ) {
106
+	public static function get_subscription_id_by_field($value, $field = 'profile_id') {
107 107
         global $wpdb;
108 108
 
109 109
 		// Trim the value.
110
-		$value = trim( $value );
110
+		$value = trim($value);
111 111
 
112
-		if ( empty( $value ) ) {
112
+		if (empty($value)) {
113 113
 			return 0;
114 114
 		}
115 115
 
116
-		if ( 'invoice_id' == $field ) {
116
+		if ('invoice_id' == $field) {
117 117
 			$field = 'parent_payment_id';
118 118
 		}
119 119
 
@@ -125,28 +125,28 @@  discard block
 block discarded – undo
125 125
 		);
126 126
 
127 127
 		// Ensure a field has been passed.
128
-		if ( empty( $field ) || ! in_array( $field, $fields ) ) {
128
+		if (empty($field) || !in_array($field, $fields)) {
129 129
 			return 0;
130 130
 		}
131 131
 
132 132
 		// Maybe retrieve from the cache.
133
-		$subscription_id   = wp_cache_get( $value, "getpaid_subscription_{$field}s_to_subscription_ids" );
134
-		if ( ! empty( $subscription_id ) ) {
133
+		$subscription_id = wp_cache_get($value, "getpaid_subscription_{$field}s_to_subscription_ids");
134
+		if (!empty($subscription_id)) {
135 135
 			return $subscription_id;
136 136
 		}
137 137
 
138 138
         // Fetch from the db.
139 139
         $table            = $wpdb->prefix . 'wpinv_subscriptions';
140 140
         $subscription_id  = (int) $wpdb->get_var(
141
-            $wpdb->prepare( "SELECT `id` FROM $table WHERE `$field`=%s LIMIT 1", $value )
141
+            $wpdb->prepare("SELECT `id` FROM $table WHERE `$field`=%s LIMIT 1", $value)
142 142
         );
143 143
 
144
-		if ( empty( $subscription_id ) ) {
144
+		if (empty($subscription_id)) {
145 145
 			return 0;
146 146
 		}
147 147
 
148 148
 		// Update the cache with our data.
149
-		wp_cache_set( $value, $subscription_id, "getpaid_subscription_{$field}s_to_subscription_ids" );
149
+		wp_cache_set($value, $subscription_id, "getpaid_subscription_{$field}s_to_subscription_ids");
150 150
 
151 151
 		return $subscription_id;
152 152
 	}
@@ -162,9 +162,9 @@  discard block
 block discarded – undo
162 162
 			'getpaid_subscriptions'                                       => $this->get_id(),
163 163
 		);
164 164
 
165
-		foreach ( $caches as $cache => $value ) {
166
-			if ( '' !== $value && false !== $value ) {
167
-				wp_cache_delete( $value, $cache );
165
+		foreach ($caches as $cache => $value) {
166
+			if ('' !== $value && false !== $value) {
167
+				wp_cache_delete($value, $cache);
168 168
 			}
169 169
 		}
170 170
 	}
@@ -172,8 +172,8 @@  discard block
 block discarded – undo
172 172
 	/**
173 173
      * Checks if a subscription key is set.
174 174
      */
175
-    public function _isset( $key ) {
176
-        return isset( $this->data[ $key ] ) || method_exists( $this, "get_$key" );
175
+    public function _isset($key) {
176
+        return isset($this->data[$key]) || method_exists($this, "get_$key");
177 177
 	}
178 178
 
179 179
 	/*
@@ -198,8 +198,8 @@  discard block
 block discarded – undo
198 198
 	 * @param  string $context View or edit context.
199 199
 	 * @return int
200 200
 	 */
201
-	public function get_customer_id( $context = 'view' ) {
202
-		return (int) $this->get_prop( 'customer_id', $context );
201
+	public function get_customer_id($context = 'view') {
202
+		return (int) $this->get_prop('customer_id', $context);
203 203
 	}
204 204
 
205 205
 	/**
@@ -209,8 +209,8 @@  discard block
 block discarded – undo
209 209
 	 * @param  string $context View or edit context.
210 210
 	 * @return WP_User|false WP_User object on success, false on failure.
211 211
 	 */
212
-	public function get_customer( $context = 'view' ) {
213
-		return get_userdata( $this->get_customer_id( $context ) );
212
+	public function get_customer($context = 'view') {
213
+		return get_userdata($this->get_customer_id($context));
214 214
 	}
215 215
 
216 216
 	/**
@@ -220,8 +220,8 @@  discard block
 block discarded – undo
220 220
 	 * @param  string $context View or edit context.
221 221
 	 * @return int
222 222
 	 */
223
-	public function get_parent_invoice_id( $context = 'view' ) {
224
-		return (int) $this->get_prop( 'parent_payment_id', $context );
223
+	public function get_parent_invoice_id($context = 'view') {
224
+		return (int) $this->get_prop('parent_payment_id', $context);
225 225
 	}
226 226
 
227 227
 	/**
@@ -231,8 +231,8 @@  discard block
 block discarded – undo
231 231
 	 * @param  string $context View or edit context.
232 232
 	 * @return int
233 233
 	 */
234
-    public function get_parent_payment_id( $context = 'view' ) {
235
-        return $this->get_parent_invoice_id( $context );
234
+    public function get_parent_payment_id($context = 'view') {
235
+        return $this->get_parent_invoice_id($context);
236 236
 	}
237 237
 
238 238
 	/**
@@ -241,8 +241,8 @@  discard block
 block discarded – undo
241 241
      * @since  1.0.0
242 242
      * @return int
243 243
      */
244
-    public function get_original_payment_id( $context = 'view' ) {
245
-        return $this->get_parent_invoice_id( $context );
244
+    public function get_original_payment_id($context = 'view') {
245
+        return $this->get_parent_invoice_id($context);
246 246
     }
247 247
 
248 248
 	/**
@@ -252,8 +252,8 @@  discard block
 block discarded – undo
252 252
 	 * @param  string $context View or edit context.
253 253
 	 * @return WPInv_Invoice
254 254
 	 */
255
-	public function get_parent_invoice( $context = 'view' ) {
256
-		return new WPInv_Invoice( $this->get_parent_invoice_id( $context ) );
255
+	public function get_parent_invoice($context = 'view') {
256
+		return new WPInv_Invoice($this->get_parent_invoice_id($context));
257 257
 	}
258 258
 
259 259
 	/**
@@ -263,8 +263,8 @@  discard block
 block discarded – undo
263 263
 	 * @param  string $context View or edit context.
264 264
 	 * @return WPInv_Invoice
265 265
 	 */
266
-    public function get_parent_payment( $context = 'view' ) {
267
-        return $this->get_parent_invoice( $context );
266
+    public function get_parent_payment($context = 'view') {
267
+        return $this->get_parent_invoice($context);
268 268
 	}
269 269
 
270 270
 	/**
@@ -274,8 +274,8 @@  discard block
 block discarded – undo
274 274
 	 * @param  string $context View or edit context.
275 275
 	 * @return int
276 276
 	 */
277
-	public function get_product_id( $context = 'view' ) {
278
-		return (int) $this->get_prop( 'product_id', $context );
277
+	public function get_product_id($context = 'view') {
278
+		return (int) $this->get_prop('product_id', $context);
279 279
 	}
280 280
 
281 281
 	/**
@@ -285,8 +285,8 @@  discard block
 block discarded – undo
285 285
 	 * @param  string $context View or edit context.
286 286
 	 * @return WPInv_Item
287 287
 	 */
288
-	public function get_product( $context = 'view' ) {
289
-		return new WPInv_Item( $this->get_product_id( $context ) );
288
+	public function get_product($context = 'view') {
289
+		return new WPInv_Item($this->get_product_id($context));
290 290
 	}
291 291
 
292 292
 	/**
@@ -298,8 +298,8 @@  discard block
 block discarded – undo
298 298
 	 * @param  string $context View or edit context.
299 299
 	 * @return string
300 300
 	 */
301
-	public function get_gateway( $context = 'view' ) {
302
-		return $this->get_parent_invoice( $context )->get_gateway();
301
+	public function get_gateway($context = 'view') {
302
+		return $this->get_parent_invoice($context)->get_gateway();
303 303
 	}
304 304
 
305 305
 	/**
@@ -309,8 +309,8 @@  discard block
 block discarded – undo
309 309
 	 * @param  string $context View or edit context.
310 310
 	 * @return string
311 311
 	 */
312
-	public function get_period( $context = 'view' ) {
313
-		return $this->get_prop( 'period', $context );
312
+	public function get_period($context = 'view') {
313
+		return $this->get_prop('period', $context);
314 314
 	}
315 315
 
316 316
 	/**
@@ -320,8 +320,8 @@  discard block
 block discarded – undo
320 320
 	 * @param  string $context View or edit context.
321 321
 	 * @return int
322 322
 	 */
323
-	public function get_frequency( $context = 'view' ) {
324
-		return (int) $this->get_prop( 'frequency', $context );
323
+	public function get_frequency($context = 'view') {
324
+		return (int) $this->get_prop('frequency', $context);
325 325
 	}
326 326
 
327 327
 	/**
@@ -331,8 +331,8 @@  discard block
 block discarded – undo
331 331
 	 * @param  string $context View or edit context.
332 332
 	 * @return float
333 333
 	 */
334
-	public function get_initial_amount( $context = 'view' ) {
335
-		return (float) wpinv_sanitize_amount( $this->get_prop( 'initial_amount', $context ) );
334
+	public function get_initial_amount($context = 'view') {
335
+		return (float) wpinv_sanitize_amount($this->get_prop('initial_amount', $context));
336 336
 	}
337 337
 
338 338
 	/**
@@ -342,8 +342,8 @@  discard block
 block discarded – undo
342 342
 	 * @param  string $context View or edit context.
343 343
 	 * @return float
344 344
 	 */
345
-	public function get_recurring_amount( $context = 'view' ) {
346
-		return (float) wpinv_sanitize_amount( $this->get_prop( 'recurring_amount', $context ) );
345
+	public function get_recurring_amount($context = 'view') {
346
+		return (float) wpinv_sanitize_amount($this->get_prop('recurring_amount', $context));
347 347
 	}
348 348
 
349 349
 	/**
@@ -353,8 +353,8 @@  discard block
 block discarded – undo
353 353
 	 * @param  string $context View or edit context.
354 354
 	 * @return int
355 355
 	 */
356
-	public function get_bill_times( $context = 'view' ) {
357
-		return (int) $this->get_prop( 'bill_times', $context );
356
+	public function get_bill_times($context = 'view') {
357
+		return (int) $this->get_prop('bill_times', $context);
358 358
 	}
359 359
 
360 360
 	/**
@@ -364,8 +364,8 @@  discard block
 block discarded – undo
364 364
 	 * @param  string $context View or edit context.
365 365
 	 * @return string
366 366
 	 */
367
-	public function get_transaction_id( $context = 'view' ) {
368
-		return $this->get_prop( 'transaction_id', $context );
367
+	public function get_transaction_id($context = 'view') {
368
+		return $this->get_prop('transaction_id', $context);
369 369
 	}
370 370
 
371 371
 	/**
@@ -375,8 +375,8 @@  discard block
 block discarded – undo
375 375
 	 * @param  string $context View or edit context.
376 376
 	 * @return string
377 377
 	 */
378
-	public function get_created( $context = 'view' ) {
379
-		return $this->get_prop( 'created', $context );
378
+	public function get_created($context = 'view') {
379
+		return $this->get_prop('created', $context);
380 380
 	}
381 381
 
382 382
 	/**
@@ -386,8 +386,8 @@  discard block
 block discarded – undo
386 386
 	 * @param  string $context View or edit context.
387 387
 	 * @return string
388 388
 	 */
389
-	public function get_date_created( $context = 'view' ) {
390
-		return $this->get_created( $context );
389
+	public function get_date_created($context = 'view') {
390
+		return $this->get_created($context);
391 391
 	}
392 392
 
393 393
 	/**
@@ -398,7 +398,7 @@  discard block
 block discarded – undo
398 398
 	 */
399 399
 	public function get_time_created() {
400 400
 		$created = $this->get_date_created();
401
-		return empty( $created ) ? current_time( 'timestamp' ) : strtotime( $created, current_time( 'timestamp' ) );
401
+		return empty($created) ? current_time('timestamp') : strtotime($created, current_time('timestamp'));
402 402
 	}
403 403
 
404 404
 	/**
@@ -408,11 +408,11 @@  discard block
 block discarded – undo
408 408
 	 * @param  string $context View or edit context.
409 409
 	 * @return string
410 410
 	 */
411
-	public function get_date_created_gmt( $context = 'view' ) {
412
-        $date = $this->get_date_created( $context );
411
+	public function get_date_created_gmt($context = 'view') {
412
+        $date = $this->get_date_created($context);
413 413
 
414
-        if ( $date ) {
415
-            $date = get_gmt_from_date( $date );
414
+        if ($date) {
415
+            $date = get_gmt_from_date($date);
416 416
         }
417 417
 		return $date;
418 418
 	}
@@ -424,8 +424,8 @@  discard block
 block discarded – undo
424 424
 	 * @param  string $context View or edit context.
425 425
 	 * @return string
426 426
 	 */
427
-	public function get_next_renewal_date( $context = 'view' ) {
428
-		return $this->get_prop( 'expiration', $context );
427
+	public function get_next_renewal_date($context = 'view') {
428
+		return $this->get_prop('expiration', $context);
429 429
 	}
430 430
 
431 431
 	/**
@@ -435,8 +435,8 @@  discard block
 block discarded – undo
435 435
 	 * @param  string $context View or edit context.
436 436
 	 * @return string
437 437
 	 */
438
-	public function get_expiration( $context = 'view' ) {
439
-		return $this->get_next_renewal_date( $context );
438
+	public function get_expiration($context = 'view') {
439
+		return $this->get_next_renewal_date($context);
440 440
 	}
441 441
 
442 442
 	/**
@@ -448,12 +448,12 @@  discard block
 block discarded – undo
448 448
 	public function get_expiration_time() {
449 449
 		$expiration = $this->get_expiration();
450 450
 
451
-		if ( empty( $expiration ) || '0000-00-00 00:00:00' == $expiration ) {
452
-			return current_time( 'timestamp' );
451
+		if (empty($expiration) || '0000-00-00 00:00:00' == $expiration) {
452
+			return current_time('timestamp');
453 453
 		}
454 454
 
455
-		$expiration = strtotime( $expiration, current_time( 'timestamp' ) );
456
-		return $expiration < current_time( 'timestamp' ) ? current_time( 'timestamp' ) : $expiration;
455
+		$expiration = strtotime($expiration, current_time('timestamp'));
456
+		return $expiration < current_time('timestamp') ? current_time('timestamp') : $expiration;
457 457
 	}
458 458
 
459 459
 	/**
@@ -463,11 +463,11 @@  discard block
 block discarded – undo
463 463
 	 * @param  string $context View or edit context.
464 464
 	 * @return string
465 465
 	 */
466
-	public function get_next_renewal_date_gmt( $context = 'view' ) {
467
-        $date = $this->get_next_renewal_date( $context );
466
+	public function get_next_renewal_date_gmt($context = 'view') {
467
+        $date = $this->get_next_renewal_date($context);
468 468
 
469
-        if ( $date ) {
470
-            $date = get_gmt_from_date( $date );
469
+        if ($date) {
470
+            $date = get_gmt_from_date($date);
471 471
         }
472 472
 		return $date;
473 473
 	}
@@ -479,8 +479,8 @@  discard block
 block discarded – undo
479 479
 	 * @param  string $context View or edit context.
480 480
 	 * @return string
481 481
 	 */
482
-	public function get_trial_period( $context = 'view' ) {
483
-		return $this->get_prop( 'trial_period', $context );
482
+	public function get_trial_period($context = 'view') {
483
+		return $this->get_prop('trial_period', $context);
484 484
 	}
485 485
 
486 486
 	/**
@@ -490,8 +490,8 @@  discard block
 block discarded – undo
490 490
 	 * @param  string $context View or edit context.
491 491
 	 * @return string
492 492
 	 */
493
-	public function get_status( $context = 'view' ) {
494
-		return $this->get_prop( 'status', $context );
493
+	public function get_status($context = 'view') {
494
+		return $this->get_prop('status', $context);
495 495
 	}
496 496
 
497 497
 	/**
@@ -501,8 +501,8 @@  discard block
 block discarded – undo
501 501
 	 * @param  string $context View or edit context.
502 502
 	 * @return string
503 503
 	 */
504
-	public function get_profile_id( $context = 'view' ) {
505
-		return $this->get_prop( 'profile_id', $context );
504
+	public function get_profile_id($context = 'view') {
505
+		return $this->get_prop('profile_id', $context);
506 506
 	}
507 507
 
508 508
 	/*
@@ -517,8 +517,8 @@  discard block
 block discarded – undo
517 517
 	 * @since 1.0.19
518 518
 	 * @param  int $value The customer's id.
519 519
 	 */
520
-	public function set_customer_id( $value ) {
521
-		$this->set_prop( 'customer_id', (int) $value );
520
+	public function set_customer_id($value) {
521
+		$this->set_prop('customer_id', (int) $value);
522 522
 	}
523 523
 
524 524
 	/**
@@ -527,8 +527,8 @@  discard block
 block discarded – undo
527 527
 	 * @since 1.0.19
528 528
 	 * @param  int $value The parent invoice id.
529 529
 	 */
530
-	public function set_parent_invoice_id( $value ) {
531
-		$this->set_prop( 'parent_payment_id', (int) $value );
530
+	public function set_parent_invoice_id($value) {
531
+		$this->set_prop('parent_payment_id', (int) $value);
532 532
 	}
533 533
 
534 534
 	/**
@@ -537,8 +537,8 @@  discard block
 block discarded – undo
537 537
 	 * @since 1.0.19
538 538
 	 * @param  int $value The parent invoice id.
539 539
 	 */
540
-    public function set_parent_payment_id( $value ) {
541
-        $this->set_parent_invoice_id( $value );
540
+    public function set_parent_payment_id($value) {
541
+        $this->set_parent_invoice_id($value);
542 542
 	}
543 543
 
544 544
 	/**
@@ -547,8 +547,8 @@  discard block
 block discarded – undo
547 547
      * @since 1.0.19
548 548
 	 * @param  int $value The parent invoice id.
549 549
      */
550
-    public function set_original_payment_id( $value ) {
551
-        $this->set_parent_invoice_id( $value );
550
+    public function set_original_payment_id($value) {
551
+        $this->set_parent_invoice_id($value);
552 552
 	}
553 553
 
554 554
 	/**
@@ -557,8 +557,8 @@  discard block
 block discarded – undo
557 557
 	 * @since 1.0.19
558 558
 	 * @param  int $value The subscription product id.
559 559
 	 */
560
-	public function set_product_id( $value ) {
561
-		$this->set_prop( 'product_id', (int) $value );
560
+	public function set_product_id($value) {
561
+		$this->set_prop('product_id', (int) $value);
562 562
 	}
563 563
 
564 564
 	/**
@@ -567,8 +567,8 @@  discard block
 block discarded – undo
567 567
 	 * @since 1.0.19
568 568
 	 * @param  string $value The renewal period.
569 569
 	 */
570
-	public function set_period( $value ) {
571
-		$this->set_prop( 'period', $value );
570
+	public function set_period($value) {
571
+		$this->set_prop('period', $value);
572 572
 	}
573 573
 
574 574
 	/**
@@ -577,9 +577,9 @@  discard block
 block discarded – undo
577 577
 	 * @since 1.0.19
578 578
 	 * @param  int $value The subscription frequency.
579 579
 	 */
580
-	public function set_frequency( $value ) {
581
-		$value = empty( $value ) ? 1 : (int) $value;
582
-		$this->set_prop( 'frequency', absint( $value ) );
580
+	public function set_frequency($value) {
581
+		$value = empty($value) ? 1 : (int) $value;
582
+		$this->set_prop('frequency', absint($value));
583 583
 	}
584 584
 
585 585
 	/**
@@ -588,8 +588,8 @@  discard block
 block discarded – undo
588 588
 	 * @since 1.0.19
589 589
 	 * @param  float $value The initial subcription amount.
590 590
 	 */
591
-	public function set_initial_amount( $value ) {
592
-		$this->set_prop( 'initial_amount', wpinv_sanitize_amount( $value ) );
591
+	public function set_initial_amount($value) {
592
+		$this->set_prop('initial_amount', wpinv_sanitize_amount($value));
593 593
 	}
594 594
 
595 595
 	/**
@@ -598,8 +598,8 @@  discard block
 block discarded – undo
598 598
 	 * @since 1.0.19
599 599
 	 * @param  float $value The recurring subcription amount.
600 600
 	 */
601
-	public function set_recurring_amount( $value ) {
602
-		$this->set_prop( 'recurring_amount', wpinv_sanitize_amount( $value ) );
601
+	public function set_recurring_amount($value) {
602
+		$this->set_prop('recurring_amount', wpinv_sanitize_amount($value));
603 603
 	}
604 604
 
605 605
 	/**
@@ -608,8 +608,8 @@  discard block
 block discarded – undo
608 608
 	 * @since 1.0.19
609 609
 	 * @param  int $value Bill times.
610 610
 	 */
611
-	public function set_bill_times( $value ) {
612
-		$this->set_prop( 'bill_times', (int) $value );
611
+	public function set_bill_times($value) {
612
+		$this->set_prop('bill_times', (int) $value);
613 613
 	}
614 614
 
615 615
 	/**
@@ -618,8 +618,8 @@  discard block
 block discarded – undo
618 618
 	 * @since 1.0.19
619 619
 	 * @param string $value Bill times.
620 620
 	 */
621
-	public function set_transaction_id( $value ) {
622
-		$this->set_prop( 'transaction_id', sanitize_text_field( $value ) );
621
+	public function set_transaction_id($value) {
622
+		$this->set_prop('transaction_id', sanitize_text_field($value));
623 623
 	}
624 624
 
625 625
 	/**
@@ -628,15 +628,15 @@  discard block
 block discarded – undo
628 628
 	 * @since 1.0.19
629 629
 	 * @param string $value strtotime compliant date.
630 630
 	 */
631
-	public function set_created( $value ) {
632
-        $date = strtotime( $value );
631
+	public function set_created($value) {
632
+        $date = strtotime($value);
633 633
 
634
-        if ( $date && $value !== '0000-00-00 00:00:00' ) {
635
-            $this->set_prop( 'created', gmdate( 'Y-m-d H:i:s', $date ) );
634
+        if ($date && $value !== '0000-00-00 00:00:00') {
635
+            $this->set_prop('created', gmdate('Y-m-d H:i:s', $date));
636 636
             return;
637 637
         }
638 638
 
639
-		$this->set_prop( 'created', '' );
639
+		$this->set_prop('created', '');
640 640
 
641 641
 	}
642 642
 
@@ -646,8 +646,8 @@  discard block
 block discarded – undo
646 646
 	 * @since 1.0.19
647 647
 	 * @param string $value strtotime compliant date.
648 648
 	 */
649
-	public function set_date_created( $value ) {
650
-		$this->set_created( $value );
649
+	public function set_date_created($value) {
650
+		$this->set_created($value);
651 651
     }
652 652
 
653 653
 	/**
@@ -656,15 +656,15 @@  discard block
 block discarded – undo
656 656
 	 * @since 1.0.19
657 657
 	 * @param string $value strtotime compliant date.
658 658
 	 */
659
-	public function set_next_renewal_date( $value ) {
660
-		$date = strtotime( $value );
659
+	public function set_next_renewal_date($value) {
660
+		$date = strtotime($value);
661 661
 
662
-        if ( $date && $value !== '0000-00-00 00:00:00' ) {
663
-            $this->set_prop( 'expiration', gmdate( 'Y-m-d H:i:s', $date ) );
662
+        if ($date && $value !== '0000-00-00 00:00:00') {
663
+            $this->set_prop('expiration', gmdate('Y-m-d H:i:s', $date));
664 664
             return;
665 665
 		}
666 666
 
667
-		$this->set_prop( 'expiration', '' );
667
+		$this->set_prop('expiration', '');
668 668
 
669 669
 	}
670 670
 
@@ -674,8 +674,8 @@  discard block
 block discarded – undo
674 674
 	 * @since 1.0.19
675 675
 	 * @param string $value strtotime compliant date.
676 676
 	 */
677
-	public function set_expiration( $value ) {
678
-		$this->set_next_renewal_date( $value );
677
+	public function set_expiration($value) {
678
+		$this->set_next_renewal_date($value);
679 679
     }
680 680
 
681 681
 	/**
@@ -684,8 +684,8 @@  discard block
 block discarded – undo
684 684
 	 * @since 1.0.19
685 685
 	 * @param string $value trial period e.g 1 year.
686 686
 	 */
687
-	public function set_trial_period( $value ) {
688
-		$this->set_prop( 'trial_period', $value );
687
+	public function set_trial_period($value) {
688
+		$this->set_prop('trial_period', $value);
689 689
 	}
690 690
 
691 691
 	/**
@@ -694,22 +694,22 @@  discard block
 block discarded – undo
694 694
 	 * @since 1.0.19
695 695
 	 * @param string $new_status    New subscription status.
696 696
 	 */
697
-	public function set_status( $new_status ) {
697
+	public function set_status($new_status) {
698 698
 
699 699
 		// Abort if this is not a valid status;
700
-		if ( ! array_key_exists( $new_status, getpaid_get_subscription_statuses() ) ) {
700
+		if (!array_key_exists($new_status, getpaid_get_subscription_statuses())) {
701 701
 			return;
702 702
 		}
703 703
 
704
-		$old_status = ! empty( $this->status_transition['from'] ) ? $this->status_transition['from'] : $this->get_status();
705
-		if ( true === $this->object_read && $old_status !== $new_status ) {
704
+		$old_status = !empty($this->status_transition['from']) ? $this->status_transition['from'] : $this->get_status();
705
+		if (true === $this->object_read && $old_status !== $new_status) {
706 706
 			$this->status_transition = array(
707 707
 				'from' => $old_status,
708 708
 				'to'   => $new_status,
709 709
 			);
710 710
 		}
711 711
 
712
-		$this->set_prop( 'status', $new_status );
712
+		$this->set_prop('status', $new_status);
713 713
 	}
714 714
 
715 715
 	/**
@@ -718,8 +718,8 @@  discard block
 block discarded – undo
718 718
 	 * @since 1.0.19
719 719
 	 * @param  string $value the remote profile id.
720 720
 	 */
721
-	public function set_profile_id( $value ) {
722
-		$this->set_prop( 'profile_id', sanitize_text_field( $value ) );
721
+	public function set_profile_id($value) {
722
+		$this->set_prop('profile_id', sanitize_text_field($value));
723 723
 	}
724 724
 
725 725
 	/*
@@ -737,8 +737,8 @@  discard block
 block discarded – undo
737 737
 	 * @param string|array String or array of strings to check for.
738 738
 	 * @return bool
739 739
      */
740
-    public function has_status( $status ) {
741
-        return in_array( $this->get_status(), wpinv_clean( wpinv_parse_list( $status ) ) );
740
+    public function has_status($status) {
741
+        return in_array($this->get_status(), wpinv_clean(wpinv_parse_list($status)));
742 742
 	}
743 743
 
744 744
 	/**
@@ -748,7 +748,7 @@  discard block
 block discarded – undo
748 748
      */
749 749
     public function has_trial_period() {
750 750
 		$period = $this->get_trial_period();
751
-        return ! empty( $period );
751
+        return !empty($period);
752 752
 	}
753 753
 
754 754
 	/**
@@ -757,7 +757,7 @@  discard block
 block discarded – undo
757 757
 	 * @return bool
758 758
 	 */
759 759
 	public function is_active() {
760
-		return $this->has_status( 'active trialling' ) && ! $this->is_expired();
760
+		return $this->has_status('active trialling') && !$this->is_expired();
761 761
 	}
762 762
 
763 763
 	/**
@@ -766,7 +766,7 @@  discard block
 block discarded – undo
766 766
 	 * @return bool
767 767
 	 */
768 768
 	public function is_expired() {
769
-		return $this->has_status( 'expired' ) || ( $this->has_status( 'active cancelled trialling' ) && $this->get_expiration_time() < current_time( 'timestamp' ) );
769
+		return $this->has_status('expired') || ($this->has_status('active cancelled trialling') && $this->get_expiration_time() < current_time('timestamp'));
770 770
 	}
771 771
 
772 772
 	/**
@@ -776,7 +776,7 @@  discard block
 block discarded – undo
776 776
 	 */
777 777
 	public function is_last_renewal() {
778 778
 		$max_bills = $this->get_bill_times();
779
-		return ! empty( $max_bills ) && $max_bills <= $this->get_times_billed();
779
+		return !empty($max_bills) && $max_bills <= $this->get_times_billed();
780 780
 	}
781 781
 
782 782
 	/*
@@ -791,11 +791,11 @@  discard block
 block discarded – undo
791 791
 	/**
792 792
 	 * Backwards compatibilty.
793 793
 	 */
794
-	public function create( $data = array() ) {
794
+	public function create($data = array()) {
795 795
 
796 796
 		// Set the properties.
797
-		if ( is_array( $data ) ) {
798
-			$this->set_props( $data );
797
+		if (is_array($data)) {
798
+			$this->set_props($data);
799 799
 		}
800 800
 
801 801
 		// Save the item.
@@ -806,8 +806,8 @@  discard block
 block discarded – undo
806 806
 	/**
807 807
 	 * Backwards compatibilty.
808 808
 	 */
809
-	public function update( $args = array() ) {
810
-		return $this->create( $args );
809
+	public function update($args = array()) {
810
+		return $this->create($args);
811 811
 	}
812 812
 
813 813
     /**
@@ -816,12 +816,12 @@  discard block
 block discarded – undo
816 816
      * @since  1.0.0
817 817
      * @return WP_Post[]
818 818
      */
819
-    public function get_child_payments( $hide_pending = true ) {
819
+    public function get_child_payments($hide_pending = true) {
820 820
 
821
-		$statuses = array( 'publish', 'wpi-processing', 'wpi-renewal' );
821
+		$statuses = array('publish', 'wpi-processing', 'wpi-renewal');
822 822
 
823
-		if ( ! $hide_pending ) {
824
-			$statuses = array_keys( wpinv_get_invoice_statuses() );
823
+		if (!$hide_pending) {
824
+			$statuses = array_keys(wpinv_get_invoice_statuses());
825 825
 		}
826 826
 
827 827
         return get_posts(
@@ -843,7 +843,7 @@  discard block
 block discarded – undo
843 843
      * @return int
844 844
      */
845 845
     public function get_total_payments() {
846
-		return getpaid_count_subscription_invoices( $this->get_parent_invoice_id(), $this->get_id() );
846
+		return getpaid_count_subscription_invoices($this->get_parent_invoice_id(), $this->get_id());
847 847
     }
848 848
 
849 849
     /**
@@ -855,7 +855,7 @@  discard block
 block discarded – undo
855 855
     public function get_times_billed() {
856 856
         $times_billed = $this->get_total_payments();
857 857
 
858
-        if ( (float) $this->get_initial_amount() == 0 && $times_billed > 0 ) {
858
+        if ((float) $this->get_initial_amount() == 0 && $times_billed > 0) {
859 859
             $times_billed--;
860 860
         }
861 861
 
@@ -870,52 +870,52 @@  discard block
 block discarded – undo
870 870
 	 * @param  WPInv_Invoice $invoice If adding an existing invoice.
871 871
      * @return bool
872 872
      */
873
-    public function add_payment( $args = array(), $invoice = false ) {
873
+    public function add_payment($args = array(), $invoice = false) {
874 874
 
875 875
 		// Process each payment once.
876
-        if ( ! empty( $args['transaction_id'] ) && $this->payment_exists( $args['transaction_id'] ) ) {
876
+        if (!empty($args['transaction_id']) && $this->payment_exists($args['transaction_id'])) {
877 877
             return false;
878 878
         }
879 879
 
880 880
 		// Are we creating a new invoice?
881
-		if ( empty( $invoice ) ) {
882
-			$invoice = $this->create_payment( false );
881
+		if (empty($invoice)) {
882
+			$invoice = $this->create_payment(false);
883 883
 
884
-			if ( empty( $invoice ) ) {
884
+			if (empty($invoice)) {
885 885
 				return false;
886 886
 			}
887 887
 		}
888 888
 
889 889
 		// Maybe set a transaction id.
890
-		if ( ! empty( $args['transaction_id'] ) ) {
891
-			$invoice->set_transaction_id( $args['transaction_id'] );
890
+		if (!empty($args['transaction_id'])) {
891
+			$invoice->set_transaction_id($args['transaction_id']);
892 892
 		}
893 893
 
894 894
 		// Set the completed date.
895
-		$invoice->set_completed_date( current_time( 'mysql' ) );
895
+		$invoice->set_completed_date(current_time('mysql'));
896 896
 
897 897
 		// And the gateway.
898
-		if ( ! empty( $args['gateway'] ) ) {
899
-			$invoice->set_gateway( $args['gateway'] );
898
+		if (!empty($args['gateway'])) {
899
+			$invoice->set_gateway($args['gateway']);
900 900
 		}
901 901
 
902
-		$invoice->set_status( 'wpi-renewal' );
902
+		$invoice->set_status('wpi-renewal');
903 903
 		$invoice->save();
904 904
 
905
-		if ( ! $invoice->exists() ) {
905
+		if (!$invoice->exists()) {
906 906
 			return false;
907 907
 		}
908 908
 
909
-		return $this->after_add_payment( $invoice );
909
+		return $this->after_add_payment($invoice);
910 910
 	}
911 911
 
912
-    public function after_add_payment( $invoice ) {
912
+    public function after_add_payment($invoice) {
913 913
 
914
-		do_action( 'getpaid_after_create_subscription_renewal_invoice', $invoice, $this );
915
-		do_action( 'wpinv_recurring_add_subscription_payment', $invoice, $this );
916
-        do_action( 'wpinv_recurring_record_payment', $invoice->get_id(), $this->get_parent_invoice_id(), $invoice->get_recurring_total(), $invoice->get_transaction_id() );
914
+		do_action('getpaid_after_create_subscription_renewal_invoice', $invoice, $this);
915
+		do_action('wpinv_recurring_add_subscription_payment', $invoice, $this);
916
+        do_action('wpinv_recurring_record_payment', $invoice->get_id(), $this->get_parent_invoice_id(), $invoice->get_recurring_total(), $invoice->get_transaction_id());
917 917
 
918
-        update_post_meta( $invoice->get_id(), '_wpinv_subscription_id', $this->id );
918
+        update_post_meta($invoice->get_id(), '_wpinv_subscription_id', $this->id);
919 919
 
920 920
         return $invoice->get_id();
921 921
 	}
@@ -927,47 +927,47 @@  discard block
 block discarded – undo
927 927
 	 * @param bool $save Whether we should save the invoice.
928 928
      * @return WPInv_Invoice|bool
929 929
      */
930
-    public function create_payment( $save = true ) {
930
+    public function create_payment($save = true) {
931 931
 
932 932
 		$parent_invoice = $this->get_parent_payment();
933 933
 
934
-		if ( ! $parent_invoice->exists() ) {
934
+		if (!$parent_invoice->exists()) {
935 935
 			return false;
936 936
 		}
937 937
 
938 938
 		// Duplicate the parent invoice.
939
-		$invoice = getpaid_duplicate_invoice( $parent_invoice );
940
-		$invoice->set_parent_id( $parent_invoice->get_id() );
941
-		$invoice->set_subscription_id( $this->get_id() );
942
-		$invoice->set_remote_subscription_id( $this->get_profile_id() );
939
+		$invoice = getpaid_duplicate_invoice($parent_invoice);
940
+		$invoice->set_parent_id($parent_invoice->get_id());
941
+		$invoice->set_subscription_id($this->get_id());
942
+		$invoice->set_remote_subscription_id($this->get_profile_id());
943 943
 
944 944
 		// Set invoice items.
945
-		$subscription_group = getpaid_get_invoice_subscription_group( $parent_invoice->get_id(), $this->get_id() );
946
-		$allowed_items      = empty( $subscription_group ) ? array( $this->get_product_id() ) : array_keys( $subscription_group['items'] );
945
+		$subscription_group = getpaid_get_invoice_subscription_group($parent_invoice->get_id(), $this->get_id());
946
+		$allowed_items      = empty($subscription_group) ? array($this->get_product_id()) : array_keys($subscription_group['items']);
947 947
 		$invoice_items      = array();
948 948
 
949
-		foreach ( $invoice->get_items() as $item ) {
950
-			if ( in_array( $item->get_id(), $allowed_items ) ) {
949
+		foreach ($invoice->get_items() as $item) {
950
+			if (in_array($item->get_id(), $allowed_items)) {
951 951
 				$invoice_items[] = $item;
952 952
 			}
953 953
 		}
954 954
 
955
-		$invoice->set_items( $invoice_items );
955
+		$invoice->set_items($invoice_items);
956 956
 
957
-		if ( ! empty( $subscription_group['fees'] ) ) {
958
-			$invoice->set_fees( $subscription_group['fees'] );
957
+		if (!empty($subscription_group['fees'])) {
958
+			$invoice->set_fees($subscription_group['fees']);
959 959
 		}
960 960
 
961 961
 		// Maybe recalculate discount (Pre-GetPaid Fix).
962
-		$discount = new WPInv_Discount( $invoice->get_discount_code() );
963
-		if ( $discount->exists() && $discount->is_recurring() && 0 == $invoice->get_total_discount() ) {
964
-			$invoice->add_discount( getpaid_calculate_invoice_discount( $invoice, $discount ) );
962
+		$discount = new WPInv_Discount($invoice->get_discount_code());
963
+		if ($discount->exists() && $discount->is_recurring() && 0 == $invoice->get_total_discount()) {
964
+			$invoice->add_discount(getpaid_calculate_invoice_discount($invoice, $discount));
965 965
 		}
966 966
 
967 967
 		$invoice->recalculate_total();
968
-		$invoice->set_status( 'wpi-pending' );
968
+		$invoice->set_status('wpi-pending');
969 969
 
970
-		if ( ! $save ) {
970
+		if (!$save) {
971 971
 			return $invoice;
972 972
 		}
973 973
 
@@ -982,24 +982,24 @@  discard block
 block discarded – undo
982 982
 	 * @since  1.0.0
983 983
 	 * @return int The subscription's id
984 984
 	 */
985
-	public function renew( $calculate_from = null ) {
985
+	public function renew($calculate_from = null) {
986 986
 
987 987
 		// Complete subscription if applicable
988
-		if ( $this->is_last_renewal() ) {
988
+		if ($this->is_last_renewal()) {
989 989
 			return $this->complete();
990 990
 		}
991 991
 
992 992
 		// Calculate new expiration
993 993
 		$frequency      = $this->get_frequency();
994 994
 		$period         = $this->get_period();
995
-		$calculate_from = empty( $calculate_from ) ? $this->get_expiration_time() : $calculate_from;
996
-		$new_expiration = strtotime( "+ $frequency $period", $calculate_from );
995
+		$calculate_from = empty($calculate_from) ? $this->get_expiration_time() : $calculate_from;
996
+		$new_expiration = strtotime("+ $frequency $period", $calculate_from);
997 997
 
998
-		$this->set_expiration( date( 'Y-m-d H:i:s', $new_expiration ) );
999
-		$this->set_status( 'active' );
998
+		$this->set_expiration(date('Y-m-d H:i:s', $new_expiration));
999
+		$this->set_status('active');
1000 1000
 		$this->save();
1001 1001
 
1002
-		do_action( 'getpaid_subscription_renewed', $this );
1002
+		do_action('getpaid_subscription_renewed', $this);
1003 1003
 
1004 1004
 		return $this->get_id();
1005 1005
 	}
@@ -1015,11 +1015,11 @@  discard block
 block discarded – undo
1015 1015
 	public function complete() {
1016 1016
 
1017 1017
 		// Only mark a subscription as complete if it's not already cancelled.
1018
-		if ( $this->has_status( 'cancelled' ) ) {
1018
+		if ($this->has_status('cancelled')) {
1019 1019
 			return false;
1020 1020
 		}
1021 1021
 
1022
-		$this->set_status( 'completed' );
1022
+		$this->set_status('completed');
1023 1023
 		return $this->save();
1024 1024
 
1025 1025
 	}
@@ -1031,14 +1031,14 @@  discard block
 block discarded – undo
1031 1031
 	 * @param  bool $check_expiration
1032 1032
 	 * @return int|bool Subscription id or false if $check_expiration is true and expiration date is in the future.
1033 1033
 	 */
1034
-	public function expire( $check_expiration = false ) {
1034
+	public function expire($check_expiration = false) {
1035 1035
 
1036
-		if ( $check_expiration && $this->get_expiration_time() > current_time( 'timestamp' ) ) {
1036
+		if ($check_expiration && $this->get_expiration_time() > current_time('timestamp')) {
1037 1037
 			// Do not mark as expired since real expiration date is in the future
1038 1038
 			return false;
1039 1039
 		}
1040 1040
 
1041
-		$this->set_status( 'expired' );
1041
+		$this->set_status('expired');
1042 1042
 		return $this->save();
1043 1043
 
1044 1044
 	}
@@ -1050,7 +1050,7 @@  discard block
 block discarded – undo
1050 1050
 	 * @return int Subscription id.
1051 1051
 	 */
1052 1052
 	public function failing() {
1053
-		$this->set_status( 'failing' );
1053
+		$this->set_status('failing');
1054 1054
 		return $this->save();
1055 1055
 	}
1056 1056
 
@@ -1061,7 +1061,7 @@  discard block
 block discarded – undo
1061 1061
      * @return int Subscription id.
1062 1062
      */
1063 1063
     public function cancel() {
1064
-		$this->set_status( 'cancelled' );
1064
+		$this->set_status('cancelled');
1065 1065
 		return $this->save();
1066 1066
     }
1067 1067
 
@@ -1072,7 +1072,7 @@  discard block
 block discarded – undo
1072 1072
 	 * @return bool
1073 1073
 	 */
1074 1074
 	public function can_cancel() {
1075
-		return apply_filters( 'wpinv_subscription_can_cancel', $this->has_status( $this->get_cancellable_statuses() ), $this );
1075
+		return apply_filters('wpinv_subscription_can_cancel', $this->has_status($this->get_cancellable_statuses()), $this);
1076 1076
 	}
1077 1077
 
1078 1078
     /**
@@ -1083,7 +1083,7 @@  discard block
 block discarded – undo
1083 1083
      * @return      array
1084 1084
      */
1085 1085
     public function get_cancellable_statuses() {
1086
-        return apply_filters( 'wpinv_recurring_cancellable_statuses', array( 'active', 'trialling', 'failing' ) );
1086
+        return apply_filters('wpinv_recurring_cancellable_statuses', array('active', 'trialling', 'failing'));
1087 1087
     }
1088 1088
 
1089 1089
 	/**
@@ -1093,8 +1093,8 @@  discard block
 block discarded – undo
1093 1093
 	 * @return string
1094 1094
 	 */
1095 1095
 	public function get_cancel_url() {
1096
-		$url = getpaid_get_authenticated_action_url( 'subscription_cancel', $this->get_view_url() );
1097
-		return apply_filters( 'wpinv_subscription_cancel_url', $url, $this );
1096
+		$url = getpaid_get_authenticated_action_url('subscription_cancel', $this->get_view_url());
1097
+		return apply_filters('wpinv_subscription_cancel_url', $url, $this);
1098 1098
 	}
1099 1099
 
1100 1100
 	/**
@@ -1105,10 +1105,10 @@  discard block
 block discarded – undo
1105 1105
 	 */
1106 1106
 	public function get_view_url() {
1107 1107
 
1108
-		$url = getpaid_get_tab_url( 'gp-subscriptions', get_permalink( (int) wpinv_get_option( 'invoice_subscription_page' ) ) );
1109
-		$url = add_query_arg( 'subscription', $this->get_id(), $url );
1108
+		$url = getpaid_get_tab_url('gp-subscriptions', get_permalink((int) wpinv_get_option('invoice_subscription_page')));
1109
+		$url = add_query_arg('subscription', $this->get_id(), $url);
1110 1110
 
1111
-		return apply_filters( 'getpaid_get_subscription_view_url', $url, $this );
1111
+		return apply_filters('getpaid_get_subscription_view_url', $url, $this);
1112 1112
 	}
1113 1113
 
1114 1114
 	/**
@@ -1121,7 +1121,7 @@  discard block
 block discarded – undo
1121 1121
 	 * @return bool
1122 1122
 	 */
1123 1123
 	public function can_renew() {
1124
-		return apply_filters( 'wpinv_subscription_can_renew', true, $this );
1124
+		return apply_filters('wpinv_subscription_can_renew', true, $this);
1125 1125
 	}
1126 1126
 
1127 1127
 	/**
@@ -1140,7 +1140,7 @@  discard block
 block discarded – undo
1140 1140
             ),
1141 1141
             'getpaid-nonce'
1142 1142
         );
1143
-		return apply_filters( 'wpinv_subscription_renew_url', $url, $this );
1143
+		return apply_filters('wpinv_subscription_renew_url', $url, $this);
1144 1144
 	}
1145 1145
 
1146 1146
 	/**
@@ -1150,7 +1150,7 @@  discard block
 block discarded – undo
1150 1150
 	 * @return bool
1151 1151
 	 */
1152 1152
 	public function can_update() {
1153
-		return apply_filters( 'wpinv_subscription_can_update', false, $this );
1153
+		return apply_filters('wpinv_subscription_can_update', false, $this);
1154 1154
 	}
1155 1155
 
1156 1156
 	/**
@@ -1166,7 +1166,7 @@  discard block
 block discarded – undo
1166 1166
 				'subscription_id' => $this->get_id(),
1167 1167
             )
1168 1168
         );
1169
-		return apply_filters( 'wpinv_subscription_update_url', $url, $this );
1169
+		return apply_filters('wpinv_subscription_update_url', $url, $this);
1170 1170
 	}
1171 1171
 
1172 1172
 	/**
@@ -1176,7 +1176,7 @@  discard block
 block discarded – undo
1176 1176
 	 * @return string
1177 1177
 	 */
1178 1178
 	public function get_status_label() {
1179
-		return getpaid_get_subscription_status_label( $this->get_status() );
1179
+		return getpaid_get_subscription_status_label($this->get_status());
1180 1180
 	}
1181 1181
 
1182 1182
 	/**
@@ -1187,7 +1187,7 @@  discard block
 block discarded – undo
1187 1187
 	 */
1188 1188
 	public function get_status_class() {
1189 1189
 		$statuses = getpaid_get_subscription_status_classes();
1190
-		return isset( $statuses[ $this->get_status() ] ) ? $statuses[ $this->get_status() ] : 'bg-dark';
1190
+		return isset($statuses[$this->get_status()]) ? $statuses[$this->get_status()] : 'bg-dark';
1191 1191
 	}
1192 1192
 
1193 1193
     /**
@@ -1198,9 +1198,9 @@  discard block
 block discarded – undo
1198 1198
      */
1199 1199
     public function get_status_label_html() {
1200 1200
 
1201
-		$status_label = sanitize_text_field( $this->get_status_label() );
1202
-		$class        = esc_attr( $this->get_status_class() );
1203
-		$status       = sanitize_html_class( $this->get_status() );
1201
+		$status_label = sanitize_text_field($this->get_status_label());
1202
+		$class        = esc_attr($this->get_status_class());
1203
+		$status       = sanitize_html_class($this->get_status());
1204 1204
 
1205 1205
 		return "<span class='bsui'><span class='badge $class $status'>$status_label</span></span>";
1206 1206
     }
@@ -1212,9 +1212,9 @@  discard block
 block discarded – undo
1212 1212
      * @param  string $txn_id The transaction ID from the merchant processor
1213 1213
      * @return bool
1214 1214
      */
1215
-    public function payment_exists( $txn_id = '' ) {
1216
-		$invoice_id = WPInv_Invoice::get_invoice_id_by_field( $txn_id, 'transaction_id' );
1217
-        return ! empty( $invoice_id );
1215
+    public function payment_exists($txn_id = '') {
1216
+		$invoice_id = WPInv_Invoice::get_invoice_id_by_field($txn_id, 'transaction_id');
1217
+        return !empty($invoice_id);
1218 1218
 	}
1219 1219
 
1220 1220
 	/**
@@ -1226,35 +1226,35 @@  discard block
 block discarded – undo
1226 1226
 		// Reset status transition variable.
1227 1227
 		$this->status_transition = false;
1228 1228
 
1229
-		if ( $status_transition ) {
1229
+		if ($status_transition) {
1230 1230
 			try {
1231 1231
 
1232 1232
 				// Fire a hook for the status change.
1233
-				do_action( 'wpinv_subscription_' . $status_transition['to'], $this->get_id(), $this, $status_transition );
1234
-				do_action( 'getpaid_subscription_' . $status_transition['to'], $this, $status_transition );
1233
+				do_action('wpinv_subscription_' . $status_transition['to'], $this->get_id(), $this, $status_transition);
1234
+				do_action('getpaid_subscription_' . $status_transition['to'], $this, $status_transition);
1235 1235
 
1236
-				if ( ! empty( $status_transition['from'] ) ) {
1236
+				if (!empty($status_transition['from'])) {
1237 1237
 
1238 1238
 					/* translators: 1: old subscription status 2: new subscription status */
1239
-					$transition_note = sprintf( __( 'Subscription status changed from %1$s to %2$s.', 'invoicing' ), getpaid_get_subscription_status_label( $status_transition['from'] ), getpaid_get_subscription_status_label( $status_transition['to'] ) );
1239
+					$transition_note = sprintf(__('Subscription status changed from %1$s to %2$s.', 'invoicing'), getpaid_get_subscription_status_label($status_transition['from']), getpaid_get_subscription_status_label($status_transition['to']));
1240 1240
 
1241 1241
 					// Note the transition occurred.
1242
-					$this->get_parent_payment()->add_note( $transition_note, false, false, true );
1242
+					$this->get_parent_payment()->add_note($transition_note, false, false, true);
1243 1243
 
1244 1244
 					// Fire another hook.
1245
-					do_action( 'getpaid_subscription_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this->get_id(), $this );
1246
-					do_action( 'getpaid_subscription_status_changed', $this, $status_transition['from'], $status_transition['to'] );
1245
+					do_action('getpaid_subscription_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this->get_id(), $this);
1246
+					do_action('getpaid_subscription_status_changed', $this, $status_transition['from'], $status_transition['to']);
1247 1247
 
1248 1248
 				} else {
1249 1249
 					/* translators: %s: new invoice status */
1250
-					$transition_note = sprintf( __( 'Subscription status set to %s.', 'invoicing' ), getpaid_get_subscription_status_label( $status_transition['to'] ) );
1250
+					$transition_note = sprintf(__('Subscription status set to %s.', 'invoicing'), getpaid_get_subscription_status_label($status_transition['to']));
1251 1251
 
1252 1252
 					// Note the transition occurred.
1253
-					$this->get_parent_payment()->add_note( $transition_note, false, false, true );
1253
+					$this->get_parent_payment()->add_note($transition_note, false, false, true);
1254 1254
 
1255 1255
 				}
1256
-			} catch ( Exception $e ) {
1257
-				$this->get_parent_payment()->add_note( __( 'Error during subscription status transition.', 'invoicing' ) . ' ' . $e->getMessage() );
1256
+			} catch (Exception $e) {
1257
+				$this->get_parent_payment()->add_note(__('Error during subscription status transition.', 'invoicing') . ' ' . $e->getMessage());
1258 1258
 			}
1259 1259
 		}
1260 1260
 
@@ -1280,7 +1280,7 @@  discard block
 block discarded – undo
1280 1280
 	 */
1281 1281
 	public function activate() {
1282 1282
 		$status = $this->has_trial_period() && 'trialling' === $this->get_status() ? 'trialling' : 'active';
1283
-		$this->set_status( $status );
1283
+		$this->set_status($status);
1284 1284
 		return $this->save();
1285 1285
 	}
1286 1286
 
Please login to merge, or discard this patch.
includes/data-stores/class-getpaid-customer-data-store.php 2 patches
Indentation   +184 added lines, -184 removed lines patch added patch discarded remove patch
@@ -5,7 +5,7 @@  discard block
 block discarded – undo
5 5
  *
6 6
  */
7 7
 if ( ! defined( 'ABSPATH' ) ) {
8
-	exit;
8
+    exit;
9 9
 }
10 10
 
11 11
 /**
@@ -15,196 +15,196 @@  discard block
 block discarded – undo
15 15
  */
16 16
 class GetPaid_Customer_Data_Store {
17 17
 
18
-	/*
18
+    /*
19 19
 	|--------------------------------------------------------------------------
20 20
 	| CRUD Methods
21 21
 	|--------------------------------------------------------------------------
22 22
 	*/
23 23
 
24
-	/**
25
-	 * Method to create a new customer in the database.
26
-	 *
27
-	 * @param GetPaid_Customer $customer customer object.
28
-	 */
29
-	public function create( &$customer ) {
30
-		global $wpdb;
31
-
32
-		$values  = array();
33
-		$formats = array();
34
-
35
-		$fields = self::get_database_fields();
36
-		unset( $fields['id'] );
37
-
38
-		foreach ( $fields as $key => $format ) {
39
-			$values[ $key ] = $customer->get( $key, 'edit' );
40
-			$formats[]      = $format;
41
-		}
42
-
43
-		$result = $wpdb->insert( $wpdb->prefix . 'getpaid_customers', $values, $formats );
44
-
45
-		if ( $result ) {
46
-			$customer->set_id( $wpdb->insert_id );
47
-			$customer->apply_changes();
48
-			$customer->clear_cache();
49
-			do_action( 'getpaid_new_customer', $customer );
50
-			return true;
51
-		}
52
-
53
-		return false;
54
-	}
55
-
56
-	/**
57
-	 * Method to read a customer from the database.
58
-	 *
59
-	 * @param GetPaid_Customer $customer customer object.
60
-	 *
61
-	 */
62
-	public function read( &$customer ) {
63
-		global $wpdb;
64
-
65
-		$customer->set_defaults();
66
-
67
-		if ( ! $customer->get_id() ) {
68
-			$customer->last_error = 'Invalid customer.';
69
-			$customer->set_id( 0 );
70
-			return false;
71
-		}
72
-
73
-		// Maybe retrieve from the cache.
74
-		$raw_customer = wp_cache_get( $customer->get_id(), 'getpaid_customers' );
75
-
76
-		// If not found, retrieve from the db.
77
-		if ( false === $raw_customer ) {
78
-
79
-			$raw_customer = $wpdb->get_row(
80
-				$wpdb->prepare(
81
-					"SELECT * FROM {$wpdb->prefix}getpaid_customers WHERE id = %d",
82
-					$customer->get_id()
83
-				)
84
-			);
85
-
86
-			// Update the cache with our data
87
-			wp_cache_set( $customer->get_id(), $raw_customer, 'getpaid_customers' );
88
-
89
-		}
90
-
91
-		if ( ! $raw_customer ) {
92
-			$raw_customer->last_error = 'Invalid customer.';
93
-			return false;
94
-		}
95
-
96
-		// Loop through raw customer fields.
97
-		foreach ( (array) $raw_customer as $key => $value ) {
98
-			$customer->set( $key, $value );
99
-		}
100
-
101
-		$customer->set_object_read( true );
102
-		do_action( 'getpaid_read_customer', $customer );
103
-
104
-	}
105
-
106
-	/**
107
-	 * Method to update a customer in the database.
108
-	 *
109
-	 * @param GetPaid_Customer $customer Customer object.
110
-	 */
111
-	public function update( &$customer ) {
112
-		global $wpdb;
113
-
114
-		do_action( 'getpaid_before_update_customer', $customer, $customer->get_changes() );
115
-
116
-		$changes = $customer->get_changes();
117
-		$values  = array();
118
-		$format  = array();
119
-
120
-		foreach ( self::get_database_fields() as $key => $format ) {
121
-			if ( array_key_exists( $key, $changes ) ) {
122
-				$values[ $key ] = $customer->get( $key, 'edit' );
123
-				$formats[]      = $format;
124
-			}
125
-		}
126
-
127
-		if ( empty( $values ) ) {
128
-			return;
129
-		}
130
-
131
-		$wpdb->update(
132
-			$wpdb->prefix . 'getpaid_customers',
133
-			$values,
134
-			array(
135
-				'id' => $customer->get_id(),
136
-			),
137
-			$formats,
138
-			'%d'
139
-		);
140
-
141
-		// Apply the changes.
142
-		$customer->apply_changes();
143
-
144
-		// Delete cache.
145
-		$customer->clear_cache();
146
-
147
-		// Fire a hook.
148
-		do_action( 'getpaid_update_customer', $customer );
149
-
150
-	}
151
-
152
-	/**
153
-	 * Method to delete a customer from the database.
154
-	 *
155
-	 * @param GetPaid_Customer $customer
156
-	 */
157
-	public function delete( &$customer ) {
158
-		global $wpdb;
159
-
160
-		do_action( 'getpaid_before_delete_customer', $customer );
161
-
162
-		$wpdb->delete(
163
-			$wpdb->prefix . 'getpaid_customers',
164
-			array(
165
-				'id' => $customer->get_id(),
166
-			),
167
-			'%d'
168
-		);
169
-
170
-		// Delete cache.
171
-		$customer->clear_cache();
172
-
173
-		// Fire a hook.
174
-		do_action( 'getpaid_delete_customer', $customer );
175
-
176
-		$customer->set_id( 0 );
177
-	}
178
-
179
-	/*
24
+    /**
25
+     * Method to create a new customer in the database.
26
+     *
27
+     * @param GetPaid_Customer $customer customer object.
28
+     */
29
+    public function create( &$customer ) {
30
+        global $wpdb;
31
+
32
+        $values  = array();
33
+        $formats = array();
34
+
35
+        $fields = self::get_database_fields();
36
+        unset( $fields['id'] );
37
+
38
+        foreach ( $fields as $key => $format ) {
39
+            $values[ $key ] = $customer->get( $key, 'edit' );
40
+            $formats[]      = $format;
41
+        }
42
+
43
+        $result = $wpdb->insert( $wpdb->prefix . 'getpaid_customers', $values, $formats );
44
+
45
+        if ( $result ) {
46
+            $customer->set_id( $wpdb->insert_id );
47
+            $customer->apply_changes();
48
+            $customer->clear_cache();
49
+            do_action( 'getpaid_new_customer', $customer );
50
+            return true;
51
+        }
52
+
53
+        return false;
54
+    }
55
+
56
+    /**
57
+     * Method to read a customer from the database.
58
+     *
59
+     * @param GetPaid_Customer $customer customer object.
60
+     *
61
+     */
62
+    public function read( &$customer ) {
63
+        global $wpdb;
64
+
65
+        $customer->set_defaults();
66
+
67
+        if ( ! $customer->get_id() ) {
68
+            $customer->last_error = 'Invalid customer.';
69
+            $customer->set_id( 0 );
70
+            return false;
71
+        }
72
+
73
+        // Maybe retrieve from the cache.
74
+        $raw_customer = wp_cache_get( $customer->get_id(), 'getpaid_customers' );
75
+
76
+        // If not found, retrieve from the db.
77
+        if ( false === $raw_customer ) {
78
+
79
+            $raw_customer = $wpdb->get_row(
80
+                $wpdb->prepare(
81
+                    "SELECT * FROM {$wpdb->prefix}getpaid_customers WHERE id = %d",
82
+                    $customer->get_id()
83
+                )
84
+            );
85
+
86
+            // Update the cache with our data
87
+            wp_cache_set( $customer->get_id(), $raw_customer, 'getpaid_customers' );
88
+
89
+        }
90
+
91
+        if ( ! $raw_customer ) {
92
+            $raw_customer->last_error = 'Invalid customer.';
93
+            return false;
94
+        }
95
+
96
+        // Loop through raw customer fields.
97
+        foreach ( (array) $raw_customer as $key => $value ) {
98
+            $customer->set( $key, $value );
99
+        }
100
+
101
+        $customer->set_object_read( true );
102
+        do_action( 'getpaid_read_customer', $customer );
103
+
104
+    }
105
+
106
+    /**
107
+     * Method to update a customer in the database.
108
+     *
109
+     * @param GetPaid_Customer $customer Customer object.
110
+     */
111
+    public function update( &$customer ) {
112
+        global $wpdb;
113
+
114
+        do_action( 'getpaid_before_update_customer', $customer, $customer->get_changes() );
115
+
116
+        $changes = $customer->get_changes();
117
+        $values  = array();
118
+        $format  = array();
119
+
120
+        foreach ( self::get_database_fields() as $key => $format ) {
121
+            if ( array_key_exists( $key, $changes ) ) {
122
+                $values[ $key ] = $customer->get( $key, 'edit' );
123
+                $formats[]      = $format;
124
+            }
125
+        }
126
+
127
+        if ( empty( $values ) ) {
128
+            return;
129
+        }
130
+
131
+        $wpdb->update(
132
+            $wpdb->prefix . 'getpaid_customers',
133
+            $values,
134
+            array(
135
+                'id' => $customer->get_id(),
136
+            ),
137
+            $formats,
138
+            '%d'
139
+        );
140
+
141
+        // Apply the changes.
142
+        $customer->apply_changes();
143
+
144
+        // Delete cache.
145
+        $customer->clear_cache();
146
+
147
+        // Fire a hook.
148
+        do_action( 'getpaid_update_customer', $customer );
149
+
150
+    }
151
+
152
+    /**
153
+     * Method to delete a customer from the database.
154
+     *
155
+     * @param GetPaid_Customer $customer
156
+     */
157
+    public function delete( &$customer ) {
158
+        global $wpdb;
159
+
160
+        do_action( 'getpaid_before_delete_customer', $customer );
161
+
162
+        $wpdb->delete(
163
+            $wpdb->prefix . 'getpaid_customers',
164
+            array(
165
+                'id' => $customer->get_id(),
166
+            ),
167
+            '%d'
168
+        );
169
+
170
+        // Delete cache.
171
+        $customer->clear_cache();
172
+
173
+        // Fire a hook.
174
+        do_action( 'getpaid_delete_customer', $customer );
175
+
176
+        $customer->set_id( 0 );
177
+    }
178
+
179
+    /*
180 180
 	|--------------------------------------------------------------------------
181 181
 	| Additional Methods
182 182
 	|--------------------------------------------------------------------------
183 183
 	*/
184
-	public static function get_database_fields() {
185
-
186
-		$fields = array(
187
-			'id'             => '%d',
188
-			'user_id'        => '%d',
189
-			'email'          => '%s',
190
-			'email_cc'       => '%s',
191
-			'status'         => '%s',
192
-			'purchase_value' => '%f',
193
-			'purchase_count' => '%d',
194
-			'date_created'   => '%s',
195
-			'date_modified'  => '%s',
196
-			'uuid'           => '%s',
197
-		);
198
-
199
-		// Add address fields.
200
-		foreach ( array_keys( getpaid_user_address_fields() ) as $field ) {
201
-
202
-			// Skip id, user_id and email.
203
-			if ( ! in_array( $field, array( 'id', 'user_id', 'email', 'purchase_value', 'purchase_count', 'date_created', 'date_modified', 'uuid' ), true ) ) {
204
-				$fields[ $field ] = '%s';
205
-			}
206
-		}
207
-
208
-		return $fields;
209
-	}
184
+    public static function get_database_fields() {
185
+
186
+        $fields = array(
187
+            'id'             => '%d',
188
+            'user_id'        => '%d',
189
+            'email'          => '%s',
190
+            'email_cc'       => '%s',
191
+            'status'         => '%s',
192
+            'purchase_value' => '%f',
193
+            'purchase_count' => '%d',
194
+            'date_created'   => '%s',
195
+            'date_modified'  => '%s',
196
+            'uuid'           => '%s',
197
+        );
198
+
199
+        // Add address fields.
200
+        foreach ( array_keys( getpaid_user_address_fields() ) as $field ) {
201
+
202
+            // Skip id, user_id and email.
203
+            if ( ! in_array( $field, array( 'id', 'user_id', 'email', 'purchase_value', 'purchase_count', 'date_created', 'date_modified', 'uuid' ), true ) ) {
204
+                $fields[ $field ] = '%s';
205
+            }
206
+        }
207
+
208
+        return $fields;
209
+    }
210 210
 }
Please login to merge, or discard this patch.
Spacing   +34 added lines, -34 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
4 4
  * GetPaid_Customer_Data_Store class file.
5 5
  *
6 6
  */
7
-if ( ! defined( 'ABSPATH' ) ) {
7
+if (!defined('ABSPATH')) {
8 8
 	exit;
9 9
 }
10 10
 
@@ -26,27 +26,27 @@  discard block
 block discarded – undo
26 26
 	 *
27 27
 	 * @param GetPaid_Customer $customer customer object.
28 28
 	 */
29
-	public function create( &$customer ) {
29
+	public function create(&$customer) {
30 30
 		global $wpdb;
31 31
 
32 32
 		$values  = array();
33 33
 		$formats = array();
34 34
 
35 35
 		$fields = self::get_database_fields();
36
-		unset( $fields['id'] );
36
+		unset($fields['id']);
37 37
 
38
-		foreach ( $fields as $key => $format ) {
39
-			$values[ $key ] = $customer->get( $key, 'edit' );
38
+		foreach ($fields as $key => $format) {
39
+			$values[$key] = $customer->get($key, 'edit');
40 40
 			$formats[]      = $format;
41 41
 		}
42 42
 
43
-		$result = $wpdb->insert( $wpdb->prefix . 'getpaid_customers', $values, $formats );
43
+		$result = $wpdb->insert($wpdb->prefix . 'getpaid_customers', $values, $formats);
44 44
 
45
-		if ( $result ) {
46
-			$customer->set_id( $wpdb->insert_id );
45
+		if ($result) {
46
+			$customer->set_id($wpdb->insert_id);
47 47
 			$customer->apply_changes();
48 48
 			$customer->clear_cache();
49
-			do_action( 'getpaid_new_customer', $customer );
49
+			do_action('getpaid_new_customer', $customer);
50 50
 			return true;
51 51
 		}
52 52
 
@@ -59,22 +59,22 @@  discard block
 block discarded – undo
59 59
 	 * @param GetPaid_Customer $customer customer object.
60 60
 	 *
61 61
 	 */
62
-	public function read( &$customer ) {
62
+	public function read(&$customer) {
63 63
 		global $wpdb;
64 64
 
65 65
 		$customer->set_defaults();
66 66
 
67
-		if ( ! $customer->get_id() ) {
67
+		if (!$customer->get_id()) {
68 68
 			$customer->last_error = 'Invalid customer.';
69
-			$customer->set_id( 0 );
69
+			$customer->set_id(0);
70 70
 			return false;
71 71
 		}
72 72
 
73 73
 		// Maybe retrieve from the cache.
74
-		$raw_customer = wp_cache_get( $customer->get_id(), 'getpaid_customers' );
74
+		$raw_customer = wp_cache_get($customer->get_id(), 'getpaid_customers');
75 75
 
76 76
 		// If not found, retrieve from the db.
77
-		if ( false === $raw_customer ) {
77
+		if (false === $raw_customer) {
78 78
 
79 79
 			$raw_customer = $wpdb->get_row(
80 80
 				$wpdb->prepare(
@@ -84,22 +84,22 @@  discard block
 block discarded – undo
84 84
 			);
85 85
 
86 86
 			// Update the cache with our data
87
-			wp_cache_set( $customer->get_id(), $raw_customer, 'getpaid_customers' );
87
+			wp_cache_set($customer->get_id(), $raw_customer, 'getpaid_customers');
88 88
 
89 89
 		}
90 90
 
91
-		if ( ! $raw_customer ) {
91
+		if (!$raw_customer) {
92 92
 			$raw_customer->last_error = 'Invalid customer.';
93 93
 			return false;
94 94
 		}
95 95
 
96 96
 		// Loop through raw customer fields.
97
-		foreach ( (array) $raw_customer as $key => $value ) {
98
-			$customer->set( $key, $value );
97
+		foreach ((array) $raw_customer as $key => $value) {
98
+			$customer->set($key, $value);
99 99
 		}
100 100
 
101
-		$customer->set_object_read( true );
102
-		do_action( 'getpaid_read_customer', $customer );
101
+		$customer->set_object_read(true);
102
+		do_action('getpaid_read_customer', $customer);
103 103
 
104 104
 	}
105 105
 
@@ -108,23 +108,23 @@  discard block
 block discarded – undo
108 108
 	 *
109 109
 	 * @param GetPaid_Customer $customer Customer object.
110 110
 	 */
111
-	public function update( &$customer ) {
111
+	public function update(&$customer) {
112 112
 		global $wpdb;
113 113
 
114
-		do_action( 'getpaid_before_update_customer', $customer, $customer->get_changes() );
114
+		do_action('getpaid_before_update_customer', $customer, $customer->get_changes());
115 115
 
116 116
 		$changes = $customer->get_changes();
117 117
 		$values  = array();
118 118
 		$format  = array();
119 119
 
120
-		foreach ( self::get_database_fields() as $key => $format ) {
121
-			if ( array_key_exists( $key, $changes ) ) {
122
-				$values[ $key ] = $customer->get( $key, 'edit' );
120
+		foreach (self::get_database_fields() as $key => $format) {
121
+			if (array_key_exists($key, $changes)) {
122
+				$values[$key] = $customer->get($key, 'edit');
123 123
 				$formats[]      = $format;
124 124
 			}
125 125
 		}
126 126
 
127
-		if ( empty( $values ) ) {
127
+		if (empty($values)) {
128 128
 			return;
129 129
 		}
130 130
 
@@ -145,7 +145,7 @@  discard block
 block discarded – undo
145 145
 		$customer->clear_cache();
146 146
 
147 147
 		// Fire a hook.
148
-		do_action( 'getpaid_update_customer', $customer );
148
+		do_action('getpaid_update_customer', $customer);
149 149
 
150 150
 	}
151 151
 
@@ -154,10 +154,10 @@  discard block
 block discarded – undo
154 154
 	 *
155 155
 	 * @param GetPaid_Customer $customer
156 156
 	 */
157
-	public function delete( &$customer ) {
157
+	public function delete(&$customer) {
158 158
 		global $wpdb;
159 159
 
160
-		do_action( 'getpaid_before_delete_customer', $customer );
160
+		do_action('getpaid_before_delete_customer', $customer);
161 161
 
162 162
 		$wpdb->delete(
163 163
 			$wpdb->prefix . 'getpaid_customers',
@@ -171,9 +171,9 @@  discard block
 block discarded – undo
171 171
 		$customer->clear_cache();
172 172
 
173 173
 		// Fire a hook.
174
-		do_action( 'getpaid_delete_customer', $customer );
174
+		do_action('getpaid_delete_customer', $customer);
175 175
 
176
-		$customer->set_id( 0 );
176
+		$customer->set_id(0);
177 177
 	}
178 178
 
179 179
 	/*
@@ -197,11 +197,11 @@  discard block
 block discarded – undo
197 197
 		);
198 198
 
199 199
 		// Add address fields.
200
-		foreach ( array_keys( getpaid_user_address_fields() ) as $field ) {
200
+		foreach (array_keys(getpaid_user_address_fields()) as $field) {
201 201
 
202 202
 			// Skip id, user_id and email.
203
-			if ( ! in_array( $field, array( 'id', 'user_id', 'email', 'purchase_value', 'purchase_count', 'date_created', 'date_modified', 'uuid' ), true ) ) {
204
-				$fields[ $field ] = '%s';
203
+			if (!in_array($field, array('id', 'user_id', 'email', 'purchase_value', 'purchase_count', 'date_created', 'date_modified', 'uuid'), true)) {
204
+				$fields[$field] = '%s';
205 205
 			}
206 206
 		}
207 207
 
Please login to merge, or discard this patch.
includes/class-wpinv.php 2 patches
Indentation   +606 added lines, -606 removed lines patch added patch discarded remove patch
@@ -14,652 +14,652 @@
 block discarded – undo
14 14
  */
15 15
 class WPInv_Plugin {
16 16
 
17
-	/**
18
-	 * GetPaid version.
19
-	 *
20
-	 * @var string
21
-	 */
22
-	public $version;
23
-
24
-	/**
25
-	 * Data container.
26
-	 *
27
-	 * @var array
28
-	 */
29
-	protected $data = array();
30
-
31
-	/**
32
-	 * Form elements instance.
33
-	 *
34
-	 * @var WPInv_Payment_Form_Elements
35
-	 */
36
-	public $form_elements;
37
-
38
-	/**
39
-	 * @var array An array of payment gateways.
40
-	 */
41
-	public $gateways;
42
-
43
-	/**
44
-	 * Class constructor.
45
-	 */
46
-	public function __construct() {
47
-		$this->define_constants();
48
-		$this->includes();
49
-		$this->init_hooks();
50
-		$this->set_properties();
51
-	}
52
-
53
-	/**
54
-	 * Sets a custom data property.
55
-	 *
56
-	 * @param string $prop The prop to set.
57
-	 * @param mixed $value The value to retrieve.
58
-	 */
59
-	public function set( $prop, $value ) {
60
-		$this->data[ $prop ] = $value;
61
-	}
62
-
63
-	/**
64
-	 * Gets a custom data property.
65
-	 *
66
-	 * @param string $prop The prop to set.
67
-	 * @return mixed The value.
68
-	 */
69
-	public function get( $prop ) {
70
-
71
-		if ( isset( $this->data[ $prop ] ) ) {
72
-			return $this->data[ $prop ];
73
-		}
74
-
75
-		return null;
76
-	}
77
-
78
-	/**
79
-	 * Define class properties.
80
-	 */
81
-	public function set_properties() {
82
-
83
-		// Sessions.
84
-		$this->set( 'session', new WPInv_Session_Handler() );
85
-		$GLOBALS['wpi_session'] = $this->get( 'session' ); // Backwards compatibility.
86
-		$GLOBALS['wpinv_euvat'] = new WPInv_EUVat(); // Backwards compatibility.
87
-
88
-		// Init other objects.
89
-		$this->set( 'notes', new WPInv_Notes() );
90
-		$this->set( 'api', new WPInv_API() );
91
-		$this->set( 'post_types', new GetPaid_Post_Types() );
92
-		$this->set( 'template', new GetPaid_Template() );
93
-		$this->set( 'admin', new GetPaid_Admin() );
94
-		$this->set( 'subscriptions', new WPInv_Subscriptions() );
95
-		$this->set( 'invoice_emails', new GetPaid_Invoice_Notification_Emails() );
96
-		$this->set( 'subscription_emails', new GetPaid_Subscription_Notification_Emails() );
97
-		$this->set( 'daily_maintenace', new GetPaid_Daily_Maintenance() );
98
-		$this->set( 'payment_forms', new GetPaid_Payment_Forms() );
99
-		$this->set( 'maxmind', new GetPaid_MaxMind_Geolocation() );
100
-
101
-	}
102
-
103
-	 /**
104
-	 * Define plugin constants.
105
-	 */
106
-	public function define_constants() {
107
-		define( 'WPINV_PLUGIN_DIR', plugin_dir_path( WPINV_PLUGIN_FILE ) );
108
-		define( 'WPINV_PLUGIN_URL', plugin_dir_url( WPINV_PLUGIN_FILE ) );
109
-		$this->version = WPINV_VERSION;
110
-	}
111
-
112
-	/**
113
-	 * Hook into actions and filters.
114
-	 *
115
-	 * @since 1.0.19
116
-	 */
117
-	protected function init_hooks() {
118
-		/* Internationalize the text strings used. */
119
-		add_action( 'plugins_loaded', array( &$this, 'plugins_loaded' ) );
120
-
121
-		// Init the plugin after WordPress inits.
122
-		add_action( 'init', array( $this, 'init' ), 1 );
123
-		add_action( 'init', array( $this, 'maybe_process_ipn' ), 10 );
124
-		add_action( 'init', array( $this, 'wpinv_actions' ) );
125
-		add_action( 'init', array( $this, 'maybe_do_authenticated_action' ), 100 );
126
-		add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), 11 );
127
-		add_action( 'wp_footer', array( $this, 'wp_footer' ) );
128
-		add_action( 'wp_head', array( $this, 'wp_head' ) );
129
-		add_action( 'widgets_init', array( $this, 'register_widgets' ) );
130
-		add_filter( 'wpseo_exclude_from_sitemap_by_post_ids', array( $this, 'wpseo_exclude_from_sitemap_by_post_ids' ) );
131
-		add_filter( 'the_seo_framework_sitemap_supported_post_types', array( $this, 'exclude_invoicing_post_types' ) );
132
-		add_filter( 'pre_get_posts', array( &$this, 'pre_get_posts' ) );
133
-
134
-		add_filter( 'query_vars', array( $this, 'custom_query_vars' ) );
17
+    /**
18
+     * GetPaid version.
19
+     *
20
+     * @var string
21
+     */
22
+    public $version;
23
+
24
+    /**
25
+     * Data container.
26
+     *
27
+     * @var array
28
+     */
29
+    protected $data = array();
30
+
31
+    /**
32
+     * Form elements instance.
33
+     *
34
+     * @var WPInv_Payment_Form_Elements
35
+     */
36
+    public $form_elements;
37
+
38
+    /**
39
+     * @var array An array of payment gateways.
40
+     */
41
+    public $gateways;
42
+
43
+    /**
44
+     * Class constructor.
45
+     */
46
+    public function __construct() {
47
+        $this->define_constants();
48
+        $this->includes();
49
+        $this->init_hooks();
50
+        $this->set_properties();
51
+    }
52
+
53
+    /**
54
+     * Sets a custom data property.
55
+     *
56
+     * @param string $prop The prop to set.
57
+     * @param mixed $value The value to retrieve.
58
+     */
59
+    public function set( $prop, $value ) {
60
+        $this->data[ $prop ] = $value;
61
+    }
62
+
63
+    /**
64
+     * Gets a custom data property.
65
+     *
66
+     * @param string $prop The prop to set.
67
+     * @return mixed The value.
68
+     */
69
+    public function get( $prop ) {
70
+
71
+        if ( isset( $this->data[ $prop ] ) ) {
72
+            return $this->data[ $prop ];
73
+        }
74
+
75
+        return null;
76
+    }
77
+
78
+    /**
79
+     * Define class properties.
80
+     */
81
+    public function set_properties() {
82
+
83
+        // Sessions.
84
+        $this->set( 'session', new WPInv_Session_Handler() );
85
+        $GLOBALS['wpi_session'] = $this->get( 'session' ); // Backwards compatibility.
86
+        $GLOBALS['wpinv_euvat'] = new WPInv_EUVat(); // Backwards compatibility.
87
+
88
+        // Init other objects.
89
+        $this->set( 'notes', new WPInv_Notes() );
90
+        $this->set( 'api', new WPInv_API() );
91
+        $this->set( 'post_types', new GetPaid_Post_Types() );
92
+        $this->set( 'template', new GetPaid_Template() );
93
+        $this->set( 'admin', new GetPaid_Admin() );
94
+        $this->set( 'subscriptions', new WPInv_Subscriptions() );
95
+        $this->set( 'invoice_emails', new GetPaid_Invoice_Notification_Emails() );
96
+        $this->set( 'subscription_emails', new GetPaid_Subscription_Notification_Emails() );
97
+        $this->set( 'daily_maintenace', new GetPaid_Daily_Maintenance() );
98
+        $this->set( 'payment_forms', new GetPaid_Payment_Forms() );
99
+        $this->set( 'maxmind', new GetPaid_MaxMind_Geolocation() );
100
+
101
+    }
102
+
103
+        /**
104
+         * Define plugin constants.
105
+         */
106
+    public function define_constants() {
107
+        define( 'WPINV_PLUGIN_DIR', plugin_dir_path( WPINV_PLUGIN_FILE ) );
108
+        define( 'WPINV_PLUGIN_URL', plugin_dir_url( WPINV_PLUGIN_FILE ) );
109
+        $this->version = WPINV_VERSION;
110
+    }
111
+
112
+    /**
113
+     * Hook into actions and filters.
114
+     *
115
+     * @since 1.0.19
116
+     */
117
+    protected function init_hooks() {
118
+        /* Internationalize the text strings used. */
119
+        add_action( 'plugins_loaded', array( &$this, 'plugins_loaded' ) );
120
+
121
+        // Init the plugin after WordPress inits.
122
+        add_action( 'init', array( $this, 'init' ), 1 );
123
+        add_action( 'init', array( $this, 'maybe_process_ipn' ), 10 );
124
+        add_action( 'init', array( $this, 'wpinv_actions' ) );
125
+        add_action( 'init', array( $this, 'maybe_do_authenticated_action' ), 100 );
126
+        add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), 11 );
127
+        add_action( 'wp_footer', array( $this, 'wp_footer' ) );
128
+        add_action( 'wp_head', array( $this, 'wp_head' ) );
129
+        add_action( 'widgets_init', array( $this, 'register_widgets' ) );
130
+        add_filter( 'wpseo_exclude_from_sitemap_by_post_ids', array( $this, 'wpseo_exclude_from_sitemap_by_post_ids' ) );
131
+        add_filter( 'the_seo_framework_sitemap_supported_post_types', array( $this, 'exclude_invoicing_post_types' ) );
132
+        add_filter( 'pre_get_posts', array( &$this, 'pre_get_posts' ) );
133
+
134
+        add_filter( 'query_vars', array( $this, 'custom_query_vars' ) );
135 135
         add_action( 'init', array( $this, 'add_rewrite_rule' ), 10, 0 );
136
-		add_action( 'pre_get_posts', array( $this, 'maybe_process_new_ipn' ), 1 );
137
-
138
-		// Fires after registering actions.
139
-		do_action( 'wpinv_actions', $this );
140
-		do_action( 'getpaid_actions', $this );
141
-
142
-	}
143
-
144
-	public function plugins_loaded() {
145
-		/* Internationalize the text strings used. */
146
-		$this->load_textdomain();
147
-
148
-		do_action( 'wpinv_loaded' );
149
-
150
-		// Fix oxygen page builder conflict
151
-		if ( function_exists( 'ct_css_output' ) ) {
152
-			wpinv_oxygen_fix_conflict();
153
-		}
154
-	}
155
-
156
-	/**
157
-	 * Load Localisation files.
158
-	 *
159
-	 * Note: the first-loaded translation file overrides any following ones if the same translation is present.
160
-	 *
161
-	 * Locales found in:
162
-	 *      - WP_LANG_DIR/plugins/invoicing-LOCALE.mo
163
-	 *      - WP_PLUGIN_DIR/invoicing/languages/invoicing-LOCALE.mo
164
-	 *
165
-	 * @since 1.0.0
166
-	 */
167
-	public function load_textdomain() {
168
-
169
-		load_plugin_textdomain(
170
-			'invoicing',
171
-			false,
172
-			plugin_basename( dirname( WPINV_PLUGIN_FILE ) ) . '/languages/'
173
-		);
174
-
175
-	}
176
-
177
-	/**
178
-	 * Include required core files used in admin and on the frontend.
179
-	 */
180
-	public function includes() {
181
-
182
-		// Start with the settings.
183
-		require_once WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php';
184
-
185
-		// Packages/libraries.
186
-		require_once WPINV_PLUGIN_DIR . 'vendor/autoload.php';
187
-		require_once WPINV_PLUGIN_DIR . 'vendor/ayecode/wp-ayecode-ui/ayecode-ui-loader.php';
188
-
189
-		// Load functions.
190
-		require_once WPINV_PLUGIN_DIR . 'includes/deprecated-functions.php';
191
-		require_once WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php';
192
-		require_once WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php';
193
-		require_once WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php';
194
-		require_once WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php';
195
-		require_once WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php';
196
-		require_once WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php';
197
-		require_once WPINV_PLUGIN_DIR . 'includes/invoice-functions.php';
198
-		require_once WPINV_PLUGIN_DIR . 'includes/subscription-functions.php';
199
-		require_once WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php';
200
-		require_once WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php';
201
-		require_once WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php';
202
-		require_once WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php';
203
-		require_once WPINV_PLUGIN_DIR . 'includes/user-functions.php';
204
-		require_once WPINV_PLUGIN_DIR . 'includes/error-functions.php';
205
-
206
-		// Register autoloader.
207
-		try {
208
-			spl_autoload_register( array( $this, 'autoload' ), true );
209
-		} catch ( Exception $e ) {
210
-			wpinv_error_log( $e->getMessage(), '', __FILE__, 149, true );
211
-		}
212
-
213
-		require_once WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-session.php';
214
-		require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-session-handler.php';
215
-		require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php';
216
-		require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php';
217
-		require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-cache-helper.php';
218
-		require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-db.php';
219
-		require_once WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php';
220
-		require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions-db.php';
221
-		require_once WPINV_PLUGIN_DIR . 'includes/wpinv-subscription.php';
222
-		require_once WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-privacy.php';
223
-		require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-privacy.php';
224
-		require_once WPINV_PLUGIN_DIR . 'includes/libraries/class-ayecode-addons.php';
225
-		require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-addons.php';
226
-		require_once WPINV_PLUGIN_DIR . 'widgets/checkout.php';
227
-		require_once WPINV_PLUGIN_DIR . 'widgets/invoice-history.php';
228
-		require_once WPINV_PLUGIN_DIR . 'widgets/invoice-receipt.php';
229
-		require_once WPINV_PLUGIN_DIR . 'widgets/invoice-messages.php';
230
-		require_once WPINV_PLUGIN_DIR . 'widgets/subscriptions.php';
231
-		require_once WPINV_PLUGIN_DIR . 'widgets/buy-item.php';
232
-		require_once WPINV_PLUGIN_DIR . 'widgets/getpaid.php';
233
-		require_once WPINV_PLUGIN_DIR . 'widgets/invoice.php';
234
-		require_once WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php';
235
-
236
-		if ( is_admin() || ( defined( 'WP_CLI' ) && WP_CLI ) ) {
237
-			GetPaid_Post_Types_Admin::init();
238
-
239
-			require_once WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php';
240
-			require_once WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-payment-form.php';
241
-			require_once WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php';
242
-			require_once WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-admin-menus.php';
243
-			require_once WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-users.php';
244
-			require_once WPINV_PLUGIN_DIR . 'includes/admin/class-getpaid-admin-profile.php';
245
-			// load the user class only on the users.php page
246
-			global $pagenow;
247
-			if ( $pagenow == 'users.php' ) {
248
-				new WPInv_Admin_Users();
249
-			}
250
-		}
251
-
252
-		// Register cli commands
253
-		if ( defined( 'WP_CLI' ) && WP_CLI ) {
254
-			require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-cli.php';
255
-			WP_CLI::add_command( 'invoicing', 'WPInv_CLI' );
256
-		}
257
-
258
-	}
259
-
260
-	/**
261
-	 * Class autoloader
262
-	 *
263
-	 * @param       string $class_name The name of the class to load.
264
-	 * @access      public
265
-	 * @since       1.0.19
266
-	 * @return      void
267
-	 */
268
-	public function autoload( $class_name ) {
269
-
270
-		// Normalize the class name...
271
-		$class_name  = strtolower( $class_name );
272
-
273
-		// ... and make sure it is our class.
274
-		if ( false === strpos( $class_name, 'getpaid_' ) && false === strpos( $class_name, 'wpinv_' ) ) {
275
-			return;
276
-		}
277
-
278
-		// Next, prepare the file name from the class.
279
-		$file_name = 'class-' . str_replace( '_', '-', $class_name ) . '.php';
280
-
281
-		// Base path of the classes.
282
-		$plugin_path = untrailingslashit( WPINV_PLUGIN_DIR );
283
-
284
-		// And an array of possible locations in order of importance.
285
-		$locations = array(
286
-			"$plugin_path/includes",
287
-			"$plugin_path/includes/data-stores",
288
-			"$plugin_path/includes/gateways",
289
-			"$plugin_path/includes/payments",
290
-			"$plugin_path/includes/geolocation",
291
-			"$plugin_path/includes/reports",
292
-			"$plugin_path/includes/api",
293
-			"$plugin_path/includes/admin",
294
-			"$plugin_path/includes/admin/meta-boxes",
295
-		);
296
-
297
-		foreach ( apply_filters( 'getpaid_autoload_locations', $locations ) as $location ) {
298
-
299
-			if ( file_exists( trailingslashit( $location ) . $file_name ) ) {
300
-				include trailingslashit( $location ) . $file_name;
301
-				break;
302
-			}
136
+        add_action( 'pre_get_posts', array( $this, 'maybe_process_new_ipn' ), 1 );
137
+
138
+        // Fires after registering actions.
139
+        do_action( 'wpinv_actions', $this );
140
+        do_action( 'getpaid_actions', $this );
141
+
142
+    }
143
+
144
+    public function plugins_loaded() {
145
+        /* Internationalize the text strings used. */
146
+        $this->load_textdomain();
147
+
148
+        do_action( 'wpinv_loaded' );
149
+
150
+        // Fix oxygen page builder conflict
151
+        if ( function_exists( 'ct_css_output' ) ) {
152
+            wpinv_oxygen_fix_conflict();
153
+        }
154
+    }
155
+
156
+    /**
157
+     * Load Localisation files.
158
+     *
159
+     * Note: the first-loaded translation file overrides any following ones if the same translation is present.
160
+     *
161
+     * Locales found in:
162
+     *      - WP_LANG_DIR/plugins/invoicing-LOCALE.mo
163
+     *      - WP_PLUGIN_DIR/invoicing/languages/invoicing-LOCALE.mo
164
+     *
165
+     * @since 1.0.0
166
+     */
167
+    public function load_textdomain() {
168
+
169
+        load_plugin_textdomain(
170
+            'invoicing',
171
+            false,
172
+            plugin_basename( dirname( WPINV_PLUGIN_FILE ) ) . '/languages/'
173
+        );
174
+
175
+    }
176
+
177
+    /**
178
+     * Include required core files used in admin and on the frontend.
179
+     */
180
+    public function includes() {
181
+
182
+        // Start with the settings.
183
+        require_once WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php';
184
+
185
+        // Packages/libraries.
186
+        require_once WPINV_PLUGIN_DIR . 'vendor/autoload.php';
187
+        require_once WPINV_PLUGIN_DIR . 'vendor/ayecode/wp-ayecode-ui/ayecode-ui-loader.php';
188
+
189
+        // Load functions.
190
+        require_once WPINV_PLUGIN_DIR . 'includes/deprecated-functions.php';
191
+        require_once WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php';
192
+        require_once WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php';
193
+        require_once WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php';
194
+        require_once WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php';
195
+        require_once WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php';
196
+        require_once WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php';
197
+        require_once WPINV_PLUGIN_DIR . 'includes/invoice-functions.php';
198
+        require_once WPINV_PLUGIN_DIR . 'includes/subscription-functions.php';
199
+        require_once WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php';
200
+        require_once WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php';
201
+        require_once WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php';
202
+        require_once WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php';
203
+        require_once WPINV_PLUGIN_DIR . 'includes/user-functions.php';
204
+        require_once WPINV_PLUGIN_DIR . 'includes/error-functions.php';
205
+
206
+        // Register autoloader.
207
+        try {
208
+            spl_autoload_register( array( $this, 'autoload' ), true );
209
+        } catch ( Exception $e ) {
210
+            wpinv_error_log( $e->getMessage(), '', __FILE__, 149, true );
211
+        }
212
+
213
+        require_once WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-session.php';
214
+        require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-session-handler.php';
215
+        require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php';
216
+        require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php';
217
+        require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-cache-helper.php';
218
+        require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-db.php';
219
+        require_once WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php';
220
+        require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions-db.php';
221
+        require_once WPINV_PLUGIN_DIR . 'includes/wpinv-subscription.php';
222
+        require_once WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-privacy.php';
223
+        require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-privacy.php';
224
+        require_once WPINV_PLUGIN_DIR . 'includes/libraries/class-ayecode-addons.php';
225
+        require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-addons.php';
226
+        require_once WPINV_PLUGIN_DIR . 'widgets/checkout.php';
227
+        require_once WPINV_PLUGIN_DIR . 'widgets/invoice-history.php';
228
+        require_once WPINV_PLUGIN_DIR . 'widgets/invoice-receipt.php';
229
+        require_once WPINV_PLUGIN_DIR . 'widgets/invoice-messages.php';
230
+        require_once WPINV_PLUGIN_DIR . 'widgets/subscriptions.php';
231
+        require_once WPINV_PLUGIN_DIR . 'widgets/buy-item.php';
232
+        require_once WPINV_PLUGIN_DIR . 'widgets/getpaid.php';
233
+        require_once WPINV_PLUGIN_DIR . 'widgets/invoice.php';
234
+        require_once WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php';
235
+
236
+        if ( is_admin() || ( defined( 'WP_CLI' ) && WP_CLI ) ) {
237
+            GetPaid_Post_Types_Admin::init();
238
+
239
+            require_once WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php';
240
+            require_once WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-payment-form.php';
241
+            require_once WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php';
242
+            require_once WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-admin-menus.php';
243
+            require_once WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-users.php';
244
+            require_once WPINV_PLUGIN_DIR . 'includes/admin/class-getpaid-admin-profile.php';
245
+            // load the user class only on the users.php page
246
+            global $pagenow;
247
+            if ( $pagenow == 'users.php' ) {
248
+                new WPInv_Admin_Users();
249
+            }
250
+        }
251
+
252
+        // Register cli commands
253
+        if ( defined( 'WP_CLI' ) && WP_CLI ) {
254
+            require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-cli.php';
255
+            WP_CLI::add_command( 'invoicing', 'WPInv_CLI' );
256
+        }
257
+
258
+    }
259
+
260
+    /**
261
+     * Class autoloader
262
+     *
263
+     * @param       string $class_name The name of the class to load.
264
+     * @access      public
265
+     * @since       1.0.19
266
+     * @return      void
267
+     */
268
+    public function autoload( $class_name ) {
269
+
270
+        // Normalize the class name...
271
+        $class_name  = strtolower( $class_name );
272
+
273
+        // ... and make sure it is our class.
274
+        if ( false === strpos( $class_name, 'getpaid_' ) && false === strpos( $class_name, 'wpinv_' ) ) {
275
+            return;
276
+        }
277
+
278
+        // Next, prepare the file name from the class.
279
+        $file_name = 'class-' . str_replace( '_', '-', $class_name ) . '.php';
280
+
281
+        // Base path of the classes.
282
+        $plugin_path = untrailingslashit( WPINV_PLUGIN_DIR );
283
+
284
+        // And an array of possible locations in order of importance.
285
+        $locations = array(
286
+            "$plugin_path/includes",
287
+            "$plugin_path/includes/data-stores",
288
+            "$plugin_path/includes/gateways",
289
+            "$plugin_path/includes/payments",
290
+            "$plugin_path/includes/geolocation",
291
+            "$plugin_path/includes/reports",
292
+            "$plugin_path/includes/api",
293
+            "$plugin_path/includes/admin",
294
+            "$plugin_path/includes/admin/meta-boxes",
295
+        );
296
+
297
+        foreach ( apply_filters( 'getpaid_autoload_locations', $locations ) as $location ) {
298
+
299
+            if ( file_exists( trailingslashit( $location ) . $file_name ) ) {
300
+                include trailingslashit( $location ) . $file_name;
301
+                break;
302
+            }
303 303
 }
304 304
 
305
-	}
306
-
307
-	/**
308
-	 * Inits hooks etc.
309
-	 */
310
-	public function init() {
311
-
312
-		// Fires before getpaid inits.
313
-		do_action( 'before_getpaid_init', $this );
314
-
315
-		// Maybe upgrade.
316
-		$this->maybe_upgrade_database();
317
-
318
-		// Load default gateways.
319
-		$gateways = apply_filters(
320
-			'getpaid_default_gateways',
321
-			array(
322
-				'manual'        => 'GetPaid_Manual_Gateway',
323
-				'paypal'        => 'GetPaid_Paypal_Gateway',
324
-				'worldpay'      => 'GetPaid_Worldpay_Gateway',
325
-				'bank_transfer' => 'GetPaid_Bank_Transfer_Gateway',
326
-				'authorizenet'  => 'GetPaid_Authorize_Net_Gateway',
327
-			)
328
-		);
329
-
330
-		foreach ( $gateways as $id => $class ) {
331
-			$this->gateways[ $id ] = new $class();
332
-		}
333
-
334
-		if ( 'yes' != get_option( 'wpinv_renamed_gateways' ) ) {
335
-			GetPaid_Installer::rename_gateways_label();
336
-			update_option( 'wpinv_renamed_gateways', 'yes' );
337
-		}
338
-
339
-		// Fires after getpaid inits.
340
-		do_action( 'getpaid_init', $this );
341
-
342
-	}
343
-
344
-	/**
345
-	 * Checks if this is an IPN request and processes it.
346
-	 */
347
-	public function maybe_process_ipn() {
348
-
349
-		// Ensure that this is an IPN request.
350
-		if ( empty( $_GET['wpi-listener'] ) || 'IPN' !== $_GET['wpi-listener'] || empty( $_GET['wpi-gateway'] ) ) {
351
-			return;
352
-		}
353
-
354
-		$gateway = sanitize_text_field( $_GET['wpi-gateway'] );
355
-
356
-		do_action( 'wpinv_verify_payment_ipn', $gateway );
357
-		do_action( "wpinv_verify_{$gateway}_ipn" );
358
-		exit;
359
-
360
-	}
361
-
362
-	public function enqueue_scripts() {
363
-
364
-		// Fires before adding scripts.
365
-		do_action( 'getpaid_enqueue_scripts' );
366
-
367
-		$localize                         = array();
368
-		$localize['ajax_url']             = admin_url( 'admin-ajax.php' );
369
-		$localize['thousands']            = wpinv_thousands_separator();
370
-		$localize['decimals']             = wpinv_decimal_separator();
371
-		$localize['nonce']                = wp_create_nonce( 'wpinv-nonce' );
372
-		$localize['txtComplete']          = __( 'Continue', 'invoicing' );
373
-		$localize['UseTaxes']             = wpinv_use_taxes();
374
-		$localize['formNonce']            = wp_create_nonce( 'getpaid_form_nonce' );
375
-		$localize['loading']              = __( 'Loading...', 'invoicing' );
376
-		$localize['connectionError']      = __( 'Could not establish a connection to the server.', 'invoicing' );
377
-		$localize['recaptchaSettings']    = getpaid_get_recaptcha_settings();
378
-
379
-		$localize = apply_filters( 'wpinv_front_js_localize', $localize );
380
-
381
-		// reCaptcha.
382
-		if ( getpaid_is_recaptcha_enabled() ) {
383
-			$url = apply_filters(
384
-				'getpaid_recaptcha_api_url',
385
-				add_query_arg(
386
-					array(
387
-						'render' => 'v2' === getpaid_get_recaptcha_version() ? 'explicit' : getpaid_get_recaptcha_site_key(),
388
-					),
389
-					'https://www.google.com/recaptcha/api.js'
390
-				)
391
-			);
392
-			wp_enqueue_script( 'recaptcha', $url, array(), null, true ); // phpcs:ignore WordPress.WP.EnqueuedResourceParameters.MissingVersion
393
-		}
394
-
395
-		$version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/payment-forms.js' );
396
-		wp_enqueue_script( 'wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/payment-forms.js', array( 'jquery' ), $version, true );
397
-		wp_localize_script( 'wpinv-front-script', 'WPInv', $localize );
398
-	}
399
-
400
-	public function wpinv_actions() {
401
-		if ( isset( $_REQUEST['wpi_action'] ) ) {
402
-			do_action( 'wpinv_' . wpinv_sanitize_key( $_REQUEST['wpi_action'] ), $_REQUEST );
403
-		}
404
-
405
-		if ( defined( 'WP_ALL_IMPORT_ROOT_DIR' ) ) {
406
-			include plugin_dir_path( __FILE__ ) . 'libraries/wp-all-import/class-getpaid-wp-all-import.php';
407
-		}
408
-	}
409
-
410
-	/**
305
+    }
306
+
307
+    /**
308
+     * Inits hooks etc.
309
+     */
310
+    public function init() {
311
+
312
+        // Fires before getpaid inits.
313
+        do_action( 'before_getpaid_init', $this );
314
+
315
+        // Maybe upgrade.
316
+        $this->maybe_upgrade_database();
317
+
318
+        // Load default gateways.
319
+        $gateways = apply_filters(
320
+            'getpaid_default_gateways',
321
+            array(
322
+                'manual'        => 'GetPaid_Manual_Gateway',
323
+                'paypal'        => 'GetPaid_Paypal_Gateway',
324
+                'worldpay'      => 'GetPaid_Worldpay_Gateway',
325
+                'bank_transfer' => 'GetPaid_Bank_Transfer_Gateway',
326
+                'authorizenet'  => 'GetPaid_Authorize_Net_Gateway',
327
+            )
328
+        );
329
+
330
+        foreach ( $gateways as $id => $class ) {
331
+            $this->gateways[ $id ] = new $class();
332
+        }
333
+
334
+        if ( 'yes' != get_option( 'wpinv_renamed_gateways' ) ) {
335
+            GetPaid_Installer::rename_gateways_label();
336
+            update_option( 'wpinv_renamed_gateways', 'yes' );
337
+        }
338
+
339
+        // Fires after getpaid inits.
340
+        do_action( 'getpaid_init', $this );
341
+
342
+    }
343
+
344
+    /**
345
+     * Checks if this is an IPN request and processes it.
346
+     */
347
+    public function maybe_process_ipn() {
348
+
349
+        // Ensure that this is an IPN request.
350
+        if ( empty( $_GET['wpi-listener'] ) || 'IPN' !== $_GET['wpi-listener'] || empty( $_GET['wpi-gateway'] ) ) {
351
+            return;
352
+        }
353
+
354
+        $gateway = sanitize_text_field( $_GET['wpi-gateway'] );
355
+
356
+        do_action( 'wpinv_verify_payment_ipn', $gateway );
357
+        do_action( "wpinv_verify_{$gateway}_ipn" );
358
+        exit;
359
+
360
+    }
361
+
362
+    public function enqueue_scripts() {
363
+
364
+        // Fires before adding scripts.
365
+        do_action( 'getpaid_enqueue_scripts' );
366
+
367
+        $localize                         = array();
368
+        $localize['ajax_url']             = admin_url( 'admin-ajax.php' );
369
+        $localize['thousands']            = wpinv_thousands_separator();
370
+        $localize['decimals']             = wpinv_decimal_separator();
371
+        $localize['nonce']                = wp_create_nonce( 'wpinv-nonce' );
372
+        $localize['txtComplete']          = __( 'Continue', 'invoicing' );
373
+        $localize['UseTaxes']             = wpinv_use_taxes();
374
+        $localize['formNonce']            = wp_create_nonce( 'getpaid_form_nonce' );
375
+        $localize['loading']              = __( 'Loading...', 'invoicing' );
376
+        $localize['connectionError']      = __( 'Could not establish a connection to the server.', 'invoicing' );
377
+        $localize['recaptchaSettings']    = getpaid_get_recaptcha_settings();
378
+
379
+        $localize = apply_filters( 'wpinv_front_js_localize', $localize );
380
+
381
+        // reCaptcha.
382
+        if ( getpaid_is_recaptcha_enabled() ) {
383
+            $url = apply_filters(
384
+                'getpaid_recaptcha_api_url',
385
+                add_query_arg(
386
+                    array(
387
+                        'render' => 'v2' === getpaid_get_recaptcha_version() ? 'explicit' : getpaid_get_recaptcha_site_key(),
388
+                    ),
389
+                    'https://www.google.com/recaptcha/api.js'
390
+                )
391
+            );
392
+            wp_enqueue_script( 'recaptcha', $url, array(), null, true ); // phpcs:ignore WordPress.WP.EnqueuedResourceParameters.MissingVersion
393
+        }
394
+
395
+        $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/payment-forms.js' );
396
+        wp_enqueue_script( 'wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/payment-forms.js', array( 'jquery' ), $version, true );
397
+        wp_localize_script( 'wpinv-front-script', 'WPInv', $localize );
398
+    }
399
+
400
+    public function wpinv_actions() {
401
+        if ( isset( $_REQUEST['wpi_action'] ) ) {
402
+            do_action( 'wpinv_' . wpinv_sanitize_key( $_REQUEST['wpi_action'] ), $_REQUEST );
403
+        }
404
+
405
+        if ( defined( 'WP_ALL_IMPORT_ROOT_DIR' ) ) {
406
+            include plugin_dir_path( __FILE__ ) . 'libraries/wp-all-import/class-getpaid-wp-all-import.php';
407
+        }
408
+    }
409
+
410
+    /**
411 411
      * Fires an action after verifying that a user can fire them.
412
-	 *
413
-	 * Note: If the action is on an invoice, subscription etc, esure that the
414
-	 * current user owns the invoice/subscription.
412
+     *
413
+     * Note: If the action is on an invoice, subscription etc, esure that the
414
+     * current user owns the invoice/subscription.
415 415
      */
416 416
     public function maybe_do_authenticated_action() {
417 417
 
418
-		if ( isset( $_REQUEST['getpaid-action'] ) && isset( $_REQUEST['getpaid-nonce'] ) && wp_verify_nonce( $_REQUEST['getpaid-nonce'], 'getpaid-nonce' ) ) {
418
+        if ( isset( $_REQUEST['getpaid-action'] ) && isset( $_REQUEST['getpaid-nonce'] ) && wp_verify_nonce( $_REQUEST['getpaid-nonce'], 'getpaid-nonce' ) ) {
419 419
 
420
-			$key  = sanitize_key( $_REQUEST['getpaid-action'] );
421
-			$data = wp_unslash( $_REQUEST );
422
-			if ( is_user_logged_in() ) {
423
-				do_action( "getpaid_authenticated_action_$key", $data );
424
-			}
420
+            $key  = sanitize_key( $_REQUEST['getpaid-action'] );
421
+            $data = wp_unslash( $_REQUEST );
422
+            if ( is_user_logged_in() ) {
423
+                do_action( "getpaid_authenticated_action_$key", $data );
424
+            }
425 425
 
426
-			do_action( "getpaid_unauthenticated_action_$key", $data );
426
+            do_action( "getpaid_unauthenticated_action_$key", $data );
427 427
 
428
-		}
428
+        }
429 429
 
430 430
     }
431 431
 
432
-	public function pre_get_posts( $wp_query ) {
433
-
434
-		if ( ! is_admin() && ! empty( $wp_query->query_vars['post_type'] ) && getpaid_is_invoice_post_type( $wp_query->query_vars['post_type'] ) && is_user_logged_in() && is_single() && $wp_query->is_main_query() ) {
435
-			$wp_query->query_vars['post_status'] = array_keys( wpinv_get_invoice_statuses( false, false, $wp_query->query_vars['post_type'] ) );
436
-		}
437
-
438
-		return $wp_query;
439
-	}
440
-
441
-	/**
442
-	 * Register widgets
443
-	 *
444
-	 */
445
-	public function register_widgets() {
446
-		global $pagenow;
447
-
448
-		// Currently, UX Builder does not work particulaly well with SuperDuper.
449
-		// So we disable our widgets when editing a page with UX Builder.
450
-		if ( function_exists( 'ux_builder_is_active' ) && ux_builder_is_active() ) {
451
-			return;
452
-		}
453
-
454
-		$block_widget_init_screens = function_exists( 'sd_pagenow_exclude' ) ? sd_pagenow_exclude() : array();
455
-
456
-		if ( is_admin() && $pagenow && in_array( $pagenow, $block_widget_init_screens ) ) {
457
-			// don't initiate in these conditions.
458
-		} else {
459
-
460
-			// Only load allowed widgets.
461
-			$exclude = function_exists( 'sd_widget_exclude' ) ? sd_widget_exclude() : array();
462
-			$widgets = apply_filters(
463
-				'getpaid_widget_classes',
464
-				array(
465
-					'WPInv_Checkout_Widget',
466
-					'WPInv_History_Widget',
467
-					'WPInv_Receipt_Widget',
468
-					'WPInv_Subscriptions_Widget',
469
-					'WPInv_Buy_Item_Widget',
470
-					'WPInv_Messages_Widget',
471
-					'WPInv_GetPaid_Widget',
472
-					'WPInv_Invoice_Widget',
473
-				)
474
-			);
475
-
476
-			// For each widget...
477
-			foreach ( $widgets as $widget ) {
478
-
479
-				// Abort early if it is excluded for this page.
480
-				if ( in_array( $widget, $exclude ) ) {
481
-					continue;
482
-				}
483
-
484
-				// SD V1 used to extend the widget class. V2 does not, so we cannot call register widget on it.
485
-				if ( is_subclass_of( $widget, 'WP_Widget' ) ) {
486
-					register_widget( $widget );
487
-				} else {
488
-					new $widget();
489
-				}
432
+    public function pre_get_posts( $wp_query ) {
433
+
434
+        if ( ! is_admin() && ! empty( $wp_query->query_vars['post_type'] ) && getpaid_is_invoice_post_type( $wp_query->query_vars['post_type'] ) && is_user_logged_in() && is_single() && $wp_query->is_main_query() ) {
435
+            $wp_query->query_vars['post_status'] = array_keys( wpinv_get_invoice_statuses( false, false, $wp_query->query_vars['post_type'] ) );
436
+        }
437
+
438
+        return $wp_query;
439
+    }
440
+
441
+    /**
442
+     * Register widgets
443
+     *
444
+     */
445
+    public function register_widgets() {
446
+        global $pagenow;
447
+
448
+        // Currently, UX Builder does not work particulaly well with SuperDuper.
449
+        // So we disable our widgets when editing a page with UX Builder.
450
+        if ( function_exists( 'ux_builder_is_active' ) && ux_builder_is_active() ) {
451
+            return;
452
+        }
453
+
454
+        $block_widget_init_screens = function_exists( 'sd_pagenow_exclude' ) ? sd_pagenow_exclude() : array();
455
+
456
+        if ( is_admin() && $pagenow && in_array( $pagenow, $block_widget_init_screens ) ) {
457
+            // don't initiate in these conditions.
458
+        } else {
459
+
460
+            // Only load allowed widgets.
461
+            $exclude = function_exists( 'sd_widget_exclude' ) ? sd_widget_exclude() : array();
462
+            $widgets = apply_filters(
463
+                'getpaid_widget_classes',
464
+                array(
465
+                    'WPInv_Checkout_Widget',
466
+                    'WPInv_History_Widget',
467
+                    'WPInv_Receipt_Widget',
468
+                    'WPInv_Subscriptions_Widget',
469
+                    'WPInv_Buy_Item_Widget',
470
+                    'WPInv_Messages_Widget',
471
+                    'WPInv_GetPaid_Widget',
472
+                    'WPInv_Invoice_Widget',
473
+                )
474
+            );
475
+
476
+            // For each widget...
477
+            foreach ( $widgets as $widget ) {
478
+
479
+                // Abort early if it is excluded for this page.
480
+                if ( in_array( $widget, $exclude ) ) {
481
+                    continue;
482
+                }
483
+
484
+                // SD V1 used to extend the widget class. V2 does not, so we cannot call register widget on it.
485
+                if ( is_subclass_of( $widget, 'WP_Widget' ) ) {
486
+                    register_widget( $widget );
487
+                } else {
488
+                    new $widget();
489
+                }
490 490
 }
491 491
 }
492 492
 
493
-	}
493
+    }
494
+
495
+    /**
496
+     * Upgrades the database.
497
+     *
498
+     * @since 2.0.2
499
+     */
500
+    public function maybe_upgrade_database() {
501
+
502
+        // Ensure the database tables are up to date.
503
+        GetPaid_Installer::maybe_create_db_tables();
504
+
505
+        $wpi_version = get_option( 'wpinv_version', 0 );
506
+
507
+        if ( $wpi_version == WPINV_VERSION ) {
508
+            return;
509
+        }
510
+
511
+        $installer = new GetPaid_Installer();
512
+
513
+        if ( empty( $wpi_version ) ) {
514
+            return $installer->upgrade_db( 0 );
515
+        }
516
+
517
+        $upgrades  = array(
518
+            '0.0.5' => '004',
519
+            '1.0.3' => '102',
520
+            '2.0.0' => '118',
521
+            '2.8.0' => '279',
522
+        );
523
+
524
+        foreach ( $upgrades as $key => $method ) {
525
+
526
+            if ( version_compare( $wpi_version, $key, '<' ) ) {
527
+                return $installer->upgrade_db( $method );
528
+            }
529
+        }
530
+
531
+    }
532
+
533
+    /**
534
+     * Flushes the permalinks if needed.
535
+     *
536
+     * @since 2.0.8
537
+     */
538
+    public function maybe_flush_permalinks() {
539
+
540
+        $flush = get_option( 'wpinv_flush_permalinks', 0 );
541
+
542
+        if ( ! empty( $flush ) ) {
543
+            flush_rewrite_rules();
544
+            delete_option( 'wpinv_flush_permalinks' );
545
+        }
546
+
547
+    }
548
+
549
+    /**
550
+     * Remove our pages from yoast sitemaps.
551
+     *
552
+     * @since 1.0.19
553
+     * @param int[] $excluded_posts_ids
554
+     */
555
+    public function wpseo_exclude_from_sitemap_by_post_ids( $excluded_posts_ids ) {
556
+
557
+        // Ensure that we have an array.
558
+        if ( ! is_array( $excluded_posts_ids ) ) {
559
+            $excluded_posts_ids = array();
560
+        }
561
+
562
+        // Prepare our pages.
563
+        $our_pages = array();
564
+
565
+        // Checkout page.
566
+        $our_pages[] = wpinv_get_option( 'checkout_page', false );
567
+
568
+        // Success page.
569
+        $our_pages[] = wpinv_get_option( 'success_page', false );
570
+
571
+        // Failure page.
572
+        $our_pages[] = wpinv_get_option( 'failure_page', false );
494 573
 
495
-	/**
496
-	 * Upgrades the database.
497
-	 *
498
-	 * @since 2.0.2
499
-	 */
500
-	public function maybe_upgrade_database() {
574
+        // History page.
575
+        $our_pages[] = wpinv_get_option( 'invoice_history_page', false );
501 576
 
502
-		// Ensure the database tables are up to date.
503
-		GetPaid_Installer::maybe_create_db_tables();
577
+        // Subscriptions page.
578
+        $our_pages[] = wpinv_get_option( 'invoice_subscription_page', false );
504 579
 
505
-		$wpi_version = get_option( 'wpinv_version', 0 );
580
+        $our_pages   = array_map( 'intval', array_filter( $our_pages ) );
506 581
 
507
-		if ( $wpi_version == WPINV_VERSION ) {
508
-			return;
509
-		}
582
+        $excluded_posts_ids = $excluded_posts_ids + $our_pages;
583
+        return array_unique( $excluded_posts_ids );
510 584
 
511
-		$installer = new GetPaid_Installer();
585
+    }
586
+
587
+    /**
588
+     * Remove our pages from yoast sitemaps.
589
+     *
590
+     * @since 1.0.19
591
+     * @param string[] $post_types
592
+     */
593
+    public function exclude_invoicing_post_types( $post_types ) {
594
+
595
+        // Ensure that we have an array.
596
+        if ( ! is_array( $post_types ) ) {
597
+            $post_types = array();
598
+        }
599
+
600
+        // Remove our post types.
601
+        return array_diff( $post_types, array_keys( getpaid_get_invoice_post_types() ) );
602
+    }
603
+
604
+    /**
605
+     * Displays additional footer code.
606
+     *
607
+     * @since 2.0.0
608
+     */
609
+    public function wp_footer() {
610
+        wpinv_get_template( 'frontend-footer.php' );
611
+    }
512 612
 
513
-		if ( empty( $wpi_version ) ) {
514
-			return $installer->upgrade_db( 0 );
515
-		}
613
+    /**
614
+     * Displays additional header code.
615
+     *
616
+     * @since 2.0.0
617
+     */
618
+    public function wp_head() {
619
+        wpinv_get_template( 'frontend-head.php' );
620
+    }
516 621
 
517
-		$upgrades  = array(
518
-			'0.0.5' => '004',
519
-			'1.0.3' => '102',
520
-			'2.0.0' => '118',
521
-			'2.8.0' => '279',
522
-		);
523
-
524
-		foreach ( $upgrades as $key => $method ) {
525
-
526
-			if ( version_compare( $wpi_version, $key, '<' ) ) {
527
-				return $installer->upgrade_db( $method );
528
-			}
529
-		}
530
-
531
-	}
532
-
533
-	/**
534
-	 * Flushes the permalinks if needed.
535
-	 *
536
-	 * @since 2.0.8
537
-	 */
538
-	public function maybe_flush_permalinks() {
539
-
540
-		$flush = get_option( 'wpinv_flush_permalinks', 0 );
541
-
542
-		if ( ! empty( $flush ) ) {
543
-			flush_rewrite_rules();
544
-			delete_option( 'wpinv_flush_permalinks' );
545
-		}
546
-
547
-	}
548
-
549
-	/**
550
-	 * Remove our pages from yoast sitemaps.
551
-	 *
552
-	 * @since 1.0.19
553
-	 * @param int[] $excluded_posts_ids
554
-	 */
555
-	public function wpseo_exclude_from_sitemap_by_post_ids( $excluded_posts_ids ) {
556
-
557
-		// Ensure that we have an array.
558
-		if ( ! is_array( $excluded_posts_ids ) ) {
559
-			$excluded_posts_ids = array();
560
-		}
561
-
562
-		// Prepare our pages.
563
-		$our_pages = array();
564
-
565
-		// Checkout page.
566
-		$our_pages[] = wpinv_get_option( 'checkout_page', false );
567
-
568
-		// Success page.
569
-		$our_pages[] = wpinv_get_option( 'success_page', false );
570
-
571
-		// Failure page.
572
-		$our_pages[] = wpinv_get_option( 'failure_page', false );
573
-
574
-		// History page.
575
-		$our_pages[] = wpinv_get_option( 'invoice_history_page', false );
576
-
577
-		// Subscriptions page.
578
-		$our_pages[] = wpinv_get_option( 'invoice_subscription_page', false );
579
-
580
-		$our_pages   = array_map( 'intval', array_filter( $our_pages ) );
581
-
582
-		$excluded_posts_ids = $excluded_posts_ids + $our_pages;
583
-		return array_unique( $excluded_posts_ids );
584
-
585
-	}
586
-
587
-	/**
588
-	 * Remove our pages from yoast sitemaps.
589
-	 *
590
-	 * @since 1.0.19
591
-	 * @param string[] $post_types
592
-	 */
593
-	public function exclude_invoicing_post_types( $post_types ) {
594
-
595
-		// Ensure that we have an array.
596
-		if ( ! is_array( $post_types ) ) {
597
-			$post_types = array();
598
-		}
599
-
600
-		// Remove our post types.
601
-		return array_diff( $post_types, array_keys( getpaid_get_invoice_post_types() ) );
602
-	}
603
-
604
-	/**
605
-	 * Displays additional footer code.
606
-	 *
607
-	 * @since 2.0.0
608
-	 */
609
-	public function wp_footer() {
610
-		wpinv_get_template( 'frontend-footer.php' );
611
-	}
612
-
613
-	/**
614
-	 * Displays additional header code.
615
-	 *
616
-	 * @since 2.0.0
617
-	 */
618
-	public function wp_head() {
619
-		wpinv_get_template( 'frontend-head.php' );
620
-	}
621
-
622
-	/**
623
-	 * Custom query vars.
624
-	 *
625
-	 */
626
-	public function custom_query_vars( $vars ) {
622
+    /**
623
+     * Custom query vars.
624
+     *
625
+     */
626
+    public function custom_query_vars( $vars ) {
627 627
         $vars[] = 'getpaid-ipn';
628 628
         return $vars;
629
-	}
629
+    }
630 630
 
631
-	/**
632
-	 * Add rewrite tags and rules.
633
-	 *
634
-	 */
635
-	public function add_rewrite_rule() {
631
+    /**
632
+     * Add rewrite tags and rules.
633
+     *
634
+     */
635
+    public function add_rewrite_rule() {
636 636
         $tag = 'getpaid-ipn';
637 637
         add_rewrite_tag( "%$tag%", '([^&]+)' );
638 638
         add_rewrite_rule( "^$tag/([^/]*)/?", "index.php?$tag=\$matches[1]", 'top' );
639
-	}
639
+    }
640 640
 
641
-	/**
642
-	 * Processes non-query string ipns.
643
-	 *
644
-	 */
645
-	public function maybe_process_new_ipn( $query ) {
641
+    /**
642
+     * Processes non-query string ipns.
643
+     *
644
+     */
645
+    public function maybe_process_new_ipn( $query ) {
646 646
 
647 647
         if ( is_admin() || ! $query->is_main_query() ) {
648 648
             return;
649 649
         }
650 650
 
651
-		$gateway = get_query_var( 'getpaid-ipn' );
651
+        $gateway = get_query_var( 'getpaid-ipn' );
652 652
 
653 653
         if ( ! empty( $gateway ) ) {
654 654
 
655
-			$gateway = sanitize_text_field( $gateway );
656
-			nocache_headers();
657
-			do_action( 'wpinv_verify_payment_ipn', $gateway );
658
-			do_action( "wpinv_verify_{$gateway}_ipn" );
659
-			exit;
655
+            $gateway = sanitize_text_field( $gateway );
656
+            nocache_headers();
657
+            do_action( 'wpinv_verify_payment_ipn', $gateway );
658
+            do_action( "wpinv_verify_{$gateway}_ipn" );
659
+            exit;
660 660
 
661 661
         }
662 662
 
663
-	}
663
+    }
664 664
 
665 665
 }
Please login to merge, or discard this patch.
Spacing   +136 added lines, -136 removed lines patch added patch discarded remove patch
@@ -6,7 +6,7 @@  discard block
 block discarded – undo
6 6
  * @since   1.0.0
7 7
  */
8 8
 
9
-defined( 'ABSPATH' ) || exit;
9
+defined('ABSPATH') || exit;
10 10
 
11 11
 /**
12 12
  * Main Invoicing class.
@@ -56,8 +56,8 @@  discard block
 block discarded – undo
56 56
 	 * @param string $prop The prop to set.
57 57
 	 * @param mixed $value The value to retrieve.
58 58
 	 */
59
-	public function set( $prop, $value ) {
60
-		$this->data[ $prop ] = $value;
59
+	public function set($prop, $value) {
60
+		$this->data[$prop] = $value;
61 61
 	}
62 62
 
63 63
 	/**
@@ -66,10 +66,10 @@  discard block
 block discarded – undo
66 66
 	 * @param string $prop The prop to set.
67 67
 	 * @return mixed The value.
68 68
 	 */
69
-	public function get( $prop ) {
69
+	public function get($prop) {
70 70
 
71
-		if ( isset( $this->data[ $prop ] ) ) {
72
-			return $this->data[ $prop ];
71
+		if (isset($this->data[$prop])) {
72
+			return $this->data[$prop];
73 73
 		}
74 74
 
75 75
 		return null;
@@ -81,22 +81,22 @@  discard block
 block discarded – undo
81 81
 	public function set_properties() {
82 82
 
83 83
 		// Sessions.
84
-		$this->set( 'session', new WPInv_Session_Handler() );
85
-		$GLOBALS['wpi_session'] = $this->get( 'session' ); // Backwards compatibility.
84
+		$this->set('session', new WPInv_Session_Handler());
85
+		$GLOBALS['wpi_session'] = $this->get('session'); // Backwards compatibility.
86 86
 		$GLOBALS['wpinv_euvat'] = new WPInv_EUVat(); // Backwards compatibility.
87 87
 
88 88
 		// Init other objects.
89
-		$this->set( 'notes', new WPInv_Notes() );
90
-		$this->set( 'api', new WPInv_API() );
91
-		$this->set( 'post_types', new GetPaid_Post_Types() );
92
-		$this->set( 'template', new GetPaid_Template() );
93
-		$this->set( 'admin', new GetPaid_Admin() );
94
-		$this->set( 'subscriptions', new WPInv_Subscriptions() );
95
-		$this->set( 'invoice_emails', new GetPaid_Invoice_Notification_Emails() );
96
-		$this->set( 'subscription_emails', new GetPaid_Subscription_Notification_Emails() );
97
-		$this->set( 'daily_maintenace', new GetPaid_Daily_Maintenance() );
98
-		$this->set( 'payment_forms', new GetPaid_Payment_Forms() );
99
-		$this->set( 'maxmind', new GetPaid_MaxMind_Geolocation() );
89
+		$this->set('notes', new WPInv_Notes());
90
+		$this->set('api', new WPInv_API());
91
+		$this->set('post_types', new GetPaid_Post_Types());
92
+		$this->set('template', new GetPaid_Template());
93
+		$this->set('admin', new GetPaid_Admin());
94
+		$this->set('subscriptions', new WPInv_Subscriptions());
95
+		$this->set('invoice_emails', new GetPaid_Invoice_Notification_Emails());
96
+		$this->set('subscription_emails', new GetPaid_Subscription_Notification_Emails());
97
+		$this->set('daily_maintenace', new GetPaid_Daily_Maintenance());
98
+		$this->set('payment_forms', new GetPaid_Payment_Forms());
99
+		$this->set('maxmind', new GetPaid_MaxMind_Geolocation());
100 100
 
101 101
 	}
102 102
 
@@ -104,8 +104,8 @@  discard block
 block discarded – undo
104 104
 	 * Define plugin constants.
105 105
 	 */
106 106
 	public function define_constants() {
107
-		define( 'WPINV_PLUGIN_DIR', plugin_dir_path( WPINV_PLUGIN_FILE ) );
108
-		define( 'WPINV_PLUGIN_URL', plugin_dir_url( WPINV_PLUGIN_FILE ) );
107
+		define('WPINV_PLUGIN_DIR', plugin_dir_path(WPINV_PLUGIN_FILE));
108
+		define('WPINV_PLUGIN_URL', plugin_dir_url(WPINV_PLUGIN_FILE));
109 109
 		$this->version = WPINV_VERSION;
110 110
 	}
111 111
 
@@ -116,28 +116,28 @@  discard block
 block discarded – undo
116 116
 	 */
117 117
 	protected function init_hooks() {
118 118
 		/* Internationalize the text strings used. */
119
-		add_action( 'plugins_loaded', array( &$this, 'plugins_loaded' ) );
119
+		add_action('plugins_loaded', array(&$this, 'plugins_loaded'));
120 120
 
121 121
 		// Init the plugin after WordPress inits.
122
-		add_action( 'init', array( $this, 'init' ), 1 );
123
-		add_action( 'init', array( $this, 'maybe_process_ipn' ), 10 );
124
-		add_action( 'init', array( $this, 'wpinv_actions' ) );
125
-		add_action( 'init', array( $this, 'maybe_do_authenticated_action' ), 100 );
126
-		add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), 11 );
127
-		add_action( 'wp_footer', array( $this, 'wp_footer' ) );
128
-		add_action( 'wp_head', array( $this, 'wp_head' ) );
129
-		add_action( 'widgets_init', array( $this, 'register_widgets' ) );
130
-		add_filter( 'wpseo_exclude_from_sitemap_by_post_ids', array( $this, 'wpseo_exclude_from_sitemap_by_post_ids' ) );
131
-		add_filter( 'the_seo_framework_sitemap_supported_post_types', array( $this, 'exclude_invoicing_post_types' ) );
132
-		add_filter( 'pre_get_posts', array( &$this, 'pre_get_posts' ) );
133
-
134
-		add_filter( 'query_vars', array( $this, 'custom_query_vars' ) );
135
-        add_action( 'init', array( $this, 'add_rewrite_rule' ), 10, 0 );
136
-		add_action( 'pre_get_posts', array( $this, 'maybe_process_new_ipn' ), 1 );
122
+		add_action('init', array($this, 'init'), 1);
123
+		add_action('init', array($this, 'maybe_process_ipn'), 10);
124
+		add_action('init', array($this, 'wpinv_actions'));
125
+		add_action('init', array($this, 'maybe_do_authenticated_action'), 100);
126
+		add_action('wp_enqueue_scripts', array($this, 'enqueue_scripts'), 11);
127
+		add_action('wp_footer', array($this, 'wp_footer'));
128
+		add_action('wp_head', array($this, 'wp_head'));
129
+		add_action('widgets_init', array($this, 'register_widgets'));
130
+		add_filter('wpseo_exclude_from_sitemap_by_post_ids', array($this, 'wpseo_exclude_from_sitemap_by_post_ids'));
131
+		add_filter('the_seo_framework_sitemap_supported_post_types', array($this, 'exclude_invoicing_post_types'));
132
+		add_filter('pre_get_posts', array(&$this, 'pre_get_posts'));
133
+
134
+		add_filter('query_vars', array($this, 'custom_query_vars'));
135
+        add_action('init', array($this, 'add_rewrite_rule'), 10, 0);
136
+		add_action('pre_get_posts', array($this, 'maybe_process_new_ipn'), 1);
137 137
 
138 138
 		// Fires after registering actions.
139
-		do_action( 'wpinv_actions', $this );
140
-		do_action( 'getpaid_actions', $this );
139
+		do_action('wpinv_actions', $this);
140
+		do_action('getpaid_actions', $this);
141 141
 
142 142
 	}
143 143
 
@@ -145,10 +145,10 @@  discard block
 block discarded – undo
145 145
 		/* Internationalize the text strings used. */
146 146
 		$this->load_textdomain();
147 147
 
148
-		do_action( 'wpinv_loaded' );
148
+		do_action('wpinv_loaded');
149 149
 
150 150
 		// Fix oxygen page builder conflict
151
-		if ( function_exists( 'ct_css_output' ) ) {
151
+		if (function_exists('ct_css_output')) {
152 152
 			wpinv_oxygen_fix_conflict();
153 153
 		}
154 154
 	}
@@ -169,7 +169,7 @@  discard block
 block discarded – undo
169 169
 		load_plugin_textdomain(
170 170
 			'invoicing',
171 171
 			false,
172
-			plugin_basename( dirname( WPINV_PLUGIN_FILE ) ) . '/languages/'
172
+			plugin_basename(dirname(WPINV_PLUGIN_FILE)) . '/languages/'
173 173
 		);
174 174
 
175 175
 	}
@@ -205,9 +205,9 @@  discard block
 block discarded – undo
205 205
 
206 206
 		// Register autoloader.
207 207
 		try {
208
-			spl_autoload_register( array( $this, 'autoload' ), true );
209
-		} catch ( Exception $e ) {
210
-			wpinv_error_log( $e->getMessage(), '', __FILE__, 149, true );
208
+			spl_autoload_register(array($this, 'autoload'), true);
209
+		} catch (Exception $e) {
210
+			wpinv_error_log($e->getMessage(), '', __FILE__, 149, true);
211 211
 		}
212 212
 
213 213
 		require_once WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-session.php';
@@ -233,7 +233,7 @@  discard block
 block discarded – undo
233 233
 		require_once WPINV_PLUGIN_DIR . 'widgets/invoice.php';
234 234
 		require_once WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php';
235 235
 
236
-		if ( is_admin() || ( defined( 'WP_CLI' ) && WP_CLI ) ) {
236
+		if (is_admin() || (defined('WP_CLI') && WP_CLI)) {
237 237
 			GetPaid_Post_Types_Admin::init();
238 238
 
239 239
 			require_once WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php';
@@ -244,15 +244,15 @@  discard block
 block discarded – undo
244 244
 			require_once WPINV_PLUGIN_DIR . 'includes/admin/class-getpaid-admin-profile.php';
245 245
 			// load the user class only on the users.php page
246 246
 			global $pagenow;
247
-			if ( $pagenow == 'users.php' ) {
247
+			if ($pagenow == 'users.php') {
248 248
 				new WPInv_Admin_Users();
249 249
 			}
250 250
 		}
251 251
 
252 252
 		// Register cli commands
253
-		if ( defined( 'WP_CLI' ) && WP_CLI ) {
253
+		if (defined('WP_CLI') && WP_CLI) {
254 254
 			require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-cli.php';
255
-			WP_CLI::add_command( 'invoicing', 'WPInv_CLI' );
255
+			WP_CLI::add_command('invoicing', 'WPInv_CLI');
256 256
 		}
257 257
 
258 258
 	}
@@ -265,21 +265,21 @@  discard block
 block discarded – undo
265 265
 	 * @since       1.0.19
266 266
 	 * @return      void
267 267
 	 */
268
-	public function autoload( $class_name ) {
268
+	public function autoload($class_name) {
269 269
 
270 270
 		// Normalize the class name...
271
-		$class_name  = strtolower( $class_name );
271
+		$class_name = strtolower($class_name);
272 272
 
273 273
 		// ... and make sure it is our class.
274
-		if ( false === strpos( $class_name, 'getpaid_' ) && false === strpos( $class_name, 'wpinv_' ) ) {
274
+		if (false === strpos($class_name, 'getpaid_') && false === strpos($class_name, 'wpinv_')) {
275 275
 			return;
276 276
 		}
277 277
 
278 278
 		// Next, prepare the file name from the class.
279
-		$file_name = 'class-' . str_replace( '_', '-', $class_name ) . '.php';
279
+		$file_name = 'class-' . str_replace('_', '-', $class_name) . '.php';
280 280
 
281 281
 		// Base path of the classes.
282
-		$plugin_path = untrailingslashit( WPINV_PLUGIN_DIR );
282
+		$plugin_path = untrailingslashit(WPINV_PLUGIN_DIR);
283 283
 
284 284
 		// And an array of possible locations in order of importance.
285 285
 		$locations = array(
@@ -294,10 +294,10 @@  discard block
 block discarded – undo
294 294
 			"$plugin_path/includes/admin/meta-boxes",
295 295
 		);
296 296
 
297
-		foreach ( apply_filters( 'getpaid_autoload_locations', $locations ) as $location ) {
297
+		foreach (apply_filters('getpaid_autoload_locations', $locations) as $location) {
298 298
 
299
-			if ( file_exists( trailingslashit( $location ) . $file_name ) ) {
300
-				include trailingslashit( $location ) . $file_name;
299
+			if (file_exists(trailingslashit($location) . $file_name)) {
300
+				include trailingslashit($location) . $file_name;
301 301
 				break;
302 302
 			}
303 303
 }
@@ -310,7 +310,7 @@  discard block
 block discarded – undo
310 310
 	public function init() {
311 311
 
312 312
 		// Fires before getpaid inits.
313
-		do_action( 'before_getpaid_init', $this );
313
+		do_action('before_getpaid_init', $this);
314 314
 
315 315
 		// Maybe upgrade.
316 316
 		$this->maybe_upgrade_database();
@@ -327,17 +327,17 @@  discard block
 block discarded – undo
327 327
 			)
328 328
 		);
329 329
 
330
-		foreach ( $gateways as $id => $class ) {
331
-			$this->gateways[ $id ] = new $class();
330
+		foreach ($gateways as $id => $class) {
331
+			$this->gateways[$id] = new $class();
332 332
 		}
333 333
 
334
-		if ( 'yes' != get_option( 'wpinv_renamed_gateways' ) ) {
334
+		if ('yes' != get_option('wpinv_renamed_gateways')) {
335 335
 			GetPaid_Installer::rename_gateways_label();
336
-			update_option( 'wpinv_renamed_gateways', 'yes' );
336
+			update_option('wpinv_renamed_gateways', 'yes');
337 337
 		}
338 338
 
339 339
 		// Fires after getpaid inits.
340
-		do_action( 'getpaid_init', $this );
340
+		do_action('getpaid_init', $this);
341 341
 
342 342
 	}
343 343
 
@@ -347,14 +347,14 @@  discard block
 block discarded – undo
347 347
 	public function maybe_process_ipn() {
348 348
 
349 349
 		// Ensure that this is an IPN request.
350
-		if ( empty( $_GET['wpi-listener'] ) || 'IPN' !== $_GET['wpi-listener'] || empty( $_GET['wpi-gateway'] ) ) {
350
+		if (empty($_GET['wpi-listener']) || 'IPN' !== $_GET['wpi-listener'] || empty($_GET['wpi-gateway'])) {
351 351
 			return;
352 352
 		}
353 353
 
354
-		$gateway = sanitize_text_field( $_GET['wpi-gateway'] );
354
+		$gateway = sanitize_text_field($_GET['wpi-gateway']);
355 355
 
356
-		do_action( 'wpinv_verify_payment_ipn', $gateway );
357
-		do_action( "wpinv_verify_{$gateway}_ipn" );
356
+		do_action('wpinv_verify_payment_ipn', $gateway);
357
+		do_action("wpinv_verify_{$gateway}_ipn");
358 358
 		exit;
359 359
 
360 360
 	}
@@ -362,24 +362,24 @@  discard block
 block discarded – undo
362 362
 	public function enqueue_scripts() {
363 363
 
364 364
 		// Fires before adding scripts.
365
-		do_action( 'getpaid_enqueue_scripts' );
365
+		do_action('getpaid_enqueue_scripts');
366 366
 
367 367
 		$localize                         = array();
368
-		$localize['ajax_url']             = admin_url( 'admin-ajax.php' );
368
+		$localize['ajax_url']             = admin_url('admin-ajax.php');
369 369
 		$localize['thousands']            = wpinv_thousands_separator();
370 370
 		$localize['decimals']             = wpinv_decimal_separator();
371
-		$localize['nonce']                = wp_create_nonce( 'wpinv-nonce' );
372
-		$localize['txtComplete']          = __( 'Continue', 'invoicing' );
371
+		$localize['nonce']                = wp_create_nonce('wpinv-nonce');
372
+		$localize['txtComplete']          = __('Continue', 'invoicing');
373 373
 		$localize['UseTaxes']             = wpinv_use_taxes();
374
-		$localize['formNonce']            = wp_create_nonce( 'getpaid_form_nonce' );
375
-		$localize['loading']              = __( 'Loading...', 'invoicing' );
376
-		$localize['connectionError']      = __( 'Could not establish a connection to the server.', 'invoicing' );
374
+		$localize['formNonce']            = wp_create_nonce('getpaid_form_nonce');
375
+		$localize['loading']              = __('Loading...', 'invoicing');
376
+		$localize['connectionError']      = __('Could not establish a connection to the server.', 'invoicing');
377 377
 		$localize['recaptchaSettings']    = getpaid_get_recaptcha_settings();
378 378
 
379
-		$localize = apply_filters( 'wpinv_front_js_localize', $localize );
379
+		$localize = apply_filters('wpinv_front_js_localize', $localize);
380 380
 
381 381
 		// reCaptcha.
382
-		if ( getpaid_is_recaptcha_enabled() ) {
382
+		if (getpaid_is_recaptcha_enabled()) {
383 383
 			$url = apply_filters(
384 384
 				'getpaid_recaptcha_api_url',
385 385
 				add_query_arg(
@@ -389,21 +389,21 @@  discard block
 block discarded – undo
389 389
 					'https://www.google.com/recaptcha/api.js'
390 390
 				)
391 391
 			);
392
-			wp_enqueue_script( 'recaptcha', $url, array(), null, true ); // phpcs:ignore WordPress.WP.EnqueuedResourceParameters.MissingVersion
392
+			wp_enqueue_script('recaptcha', $url, array(), null, true); // phpcs:ignore WordPress.WP.EnqueuedResourceParameters.MissingVersion
393 393
 		}
394 394
 
395
-		$version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/payment-forms.js' );
396
-		wp_enqueue_script( 'wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/payment-forms.js', array( 'jquery' ), $version, true );
397
-		wp_localize_script( 'wpinv-front-script', 'WPInv', $localize );
395
+		$version = filemtime(WPINV_PLUGIN_DIR . 'assets/js/payment-forms.js');
396
+		wp_enqueue_script('wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/payment-forms.js', array('jquery'), $version, true);
397
+		wp_localize_script('wpinv-front-script', 'WPInv', $localize);
398 398
 	}
399 399
 
400 400
 	public function wpinv_actions() {
401
-		if ( isset( $_REQUEST['wpi_action'] ) ) {
402
-			do_action( 'wpinv_' . wpinv_sanitize_key( $_REQUEST['wpi_action'] ), $_REQUEST );
401
+		if (isset($_REQUEST['wpi_action'])) {
402
+			do_action('wpinv_' . wpinv_sanitize_key($_REQUEST['wpi_action']), $_REQUEST);
403 403
 		}
404 404
 
405
-		if ( defined( 'WP_ALL_IMPORT_ROOT_DIR' ) ) {
406
-			include plugin_dir_path( __FILE__ ) . 'libraries/wp-all-import/class-getpaid-wp-all-import.php';
405
+		if (defined('WP_ALL_IMPORT_ROOT_DIR')) {
406
+			include plugin_dir_path(__FILE__) . 'libraries/wp-all-import/class-getpaid-wp-all-import.php';
407 407
 		}
408 408
 	}
409 409
 
@@ -415,24 +415,24 @@  discard block
 block discarded – undo
415 415
      */
416 416
     public function maybe_do_authenticated_action() {
417 417
 
418
-		if ( isset( $_REQUEST['getpaid-action'] ) && isset( $_REQUEST['getpaid-nonce'] ) && wp_verify_nonce( $_REQUEST['getpaid-nonce'], 'getpaid-nonce' ) ) {
418
+		if (isset($_REQUEST['getpaid-action']) && isset($_REQUEST['getpaid-nonce']) && wp_verify_nonce($_REQUEST['getpaid-nonce'], 'getpaid-nonce')) {
419 419
 
420
-			$key  = sanitize_key( $_REQUEST['getpaid-action'] );
421
-			$data = wp_unslash( $_REQUEST );
422
-			if ( is_user_logged_in() ) {
423
-				do_action( "getpaid_authenticated_action_$key", $data );
420
+			$key  = sanitize_key($_REQUEST['getpaid-action']);
421
+			$data = wp_unslash($_REQUEST);
422
+			if (is_user_logged_in()) {
423
+				do_action("getpaid_authenticated_action_$key", $data);
424 424
 			}
425 425
 
426
-			do_action( "getpaid_unauthenticated_action_$key", $data );
426
+			do_action("getpaid_unauthenticated_action_$key", $data);
427 427
 
428 428
 		}
429 429
 
430 430
     }
431 431
 
432
-	public function pre_get_posts( $wp_query ) {
432
+	public function pre_get_posts($wp_query) {
433 433
 
434
-		if ( ! is_admin() && ! empty( $wp_query->query_vars['post_type'] ) && getpaid_is_invoice_post_type( $wp_query->query_vars['post_type'] ) && is_user_logged_in() && is_single() && $wp_query->is_main_query() ) {
435
-			$wp_query->query_vars['post_status'] = array_keys( wpinv_get_invoice_statuses( false, false, $wp_query->query_vars['post_type'] ) );
434
+		if (!is_admin() && !empty($wp_query->query_vars['post_type']) && getpaid_is_invoice_post_type($wp_query->query_vars['post_type']) && is_user_logged_in() && is_single() && $wp_query->is_main_query()) {
435
+			$wp_query->query_vars['post_status'] = array_keys(wpinv_get_invoice_statuses(false, false, $wp_query->query_vars['post_type']));
436 436
 		}
437 437
 
438 438
 		return $wp_query;
@@ -447,18 +447,18 @@  discard block
 block discarded – undo
447 447
 
448 448
 		// Currently, UX Builder does not work particulaly well with SuperDuper.
449 449
 		// So we disable our widgets when editing a page with UX Builder.
450
-		if ( function_exists( 'ux_builder_is_active' ) && ux_builder_is_active() ) {
450
+		if (function_exists('ux_builder_is_active') && ux_builder_is_active()) {
451 451
 			return;
452 452
 		}
453 453
 
454
-		$block_widget_init_screens = function_exists( 'sd_pagenow_exclude' ) ? sd_pagenow_exclude() : array();
454
+		$block_widget_init_screens = function_exists('sd_pagenow_exclude') ? sd_pagenow_exclude() : array();
455 455
 
456
-		if ( is_admin() && $pagenow && in_array( $pagenow, $block_widget_init_screens ) ) {
456
+		if (is_admin() && $pagenow && in_array($pagenow, $block_widget_init_screens)) {
457 457
 			// don't initiate in these conditions.
458 458
 		} else {
459 459
 
460 460
 			// Only load allowed widgets.
461
-			$exclude = function_exists( 'sd_widget_exclude' ) ? sd_widget_exclude() : array();
461
+			$exclude = function_exists('sd_widget_exclude') ? sd_widget_exclude() : array();
462 462
 			$widgets = apply_filters(
463 463
 				'getpaid_widget_classes',
464 464
 				array(
@@ -474,16 +474,16 @@  discard block
 block discarded – undo
474 474
 			);
475 475
 
476 476
 			// For each widget...
477
-			foreach ( $widgets as $widget ) {
477
+			foreach ($widgets as $widget) {
478 478
 
479 479
 				// Abort early if it is excluded for this page.
480
-				if ( in_array( $widget, $exclude ) ) {
480
+				if (in_array($widget, $exclude)) {
481 481
 					continue;
482 482
 				}
483 483
 
484 484
 				// SD V1 used to extend the widget class. V2 does not, so we cannot call register widget on it.
485
-				if ( is_subclass_of( $widget, 'WP_Widget' ) ) {
486
-					register_widget( $widget );
485
+				if (is_subclass_of($widget, 'WP_Widget')) {
486
+					register_widget($widget);
487 487
 				} else {
488 488
 					new $widget();
489 489
 				}
@@ -502,29 +502,29 @@  discard block
 block discarded – undo
502 502
 		// Ensure the database tables are up to date.
503 503
 		GetPaid_Installer::maybe_create_db_tables();
504 504
 
505
-		$wpi_version = get_option( 'wpinv_version', 0 );
505
+		$wpi_version = get_option('wpinv_version', 0);
506 506
 
507
-		if ( $wpi_version == WPINV_VERSION ) {
507
+		if ($wpi_version == WPINV_VERSION) {
508 508
 			return;
509 509
 		}
510 510
 
511 511
 		$installer = new GetPaid_Installer();
512 512
 
513
-		if ( empty( $wpi_version ) ) {
514
-			return $installer->upgrade_db( 0 );
513
+		if (empty($wpi_version)) {
514
+			return $installer->upgrade_db(0);
515 515
 		}
516 516
 
517
-		$upgrades  = array(
517
+		$upgrades = array(
518 518
 			'0.0.5' => '004',
519 519
 			'1.0.3' => '102',
520 520
 			'2.0.0' => '118',
521 521
 			'2.8.0' => '279',
522 522
 		);
523 523
 
524
-		foreach ( $upgrades as $key => $method ) {
524
+		foreach ($upgrades as $key => $method) {
525 525
 
526
-			if ( version_compare( $wpi_version, $key, '<' ) ) {
527
-				return $installer->upgrade_db( $method );
526
+			if (version_compare($wpi_version, $key, '<')) {
527
+				return $installer->upgrade_db($method);
528 528
 			}
529 529
 		}
530 530
 
@@ -537,11 +537,11 @@  discard block
 block discarded – undo
537 537
 	 */
538 538
 	public function maybe_flush_permalinks() {
539 539
 
540
-		$flush = get_option( 'wpinv_flush_permalinks', 0 );
540
+		$flush = get_option('wpinv_flush_permalinks', 0);
541 541
 
542
-		if ( ! empty( $flush ) ) {
542
+		if (!empty($flush)) {
543 543
 			flush_rewrite_rules();
544
-			delete_option( 'wpinv_flush_permalinks' );
544
+			delete_option('wpinv_flush_permalinks');
545 545
 		}
546 546
 
547 547
 	}
@@ -552,10 +552,10 @@  discard block
 block discarded – undo
552 552
 	 * @since 1.0.19
553 553
 	 * @param int[] $excluded_posts_ids
554 554
 	 */
555
-	public function wpseo_exclude_from_sitemap_by_post_ids( $excluded_posts_ids ) {
555
+	public function wpseo_exclude_from_sitemap_by_post_ids($excluded_posts_ids) {
556 556
 
557 557
 		// Ensure that we have an array.
558
-		if ( ! is_array( $excluded_posts_ids ) ) {
558
+		if (!is_array($excluded_posts_ids)) {
559 559
 			$excluded_posts_ids = array();
560 560
 		}
561 561
 
@@ -563,24 +563,24 @@  discard block
 block discarded – undo
563 563
 		$our_pages = array();
564 564
 
565 565
 		// Checkout page.
566
-		$our_pages[] = wpinv_get_option( 'checkout_page', false );
566
+		$our_pages[] = wpinv_get_option('checkout_page', false);
567 567
 
568 568
 		// Success page.
569
-		$our_pages[] = wpinv_get_option( 'success_page', false );
569
+		$our_pages[] = wpinv_get_option('success_page', false);
570 570
 
571 571
 		// Failure page.
572
-		$our_pages[] = wpinv_get_option( 'failure_page', false );
572
+		$our_pages[] = wpinv_get_option('failure_page', false);
573 573
 
574 574
 		// History page.
575
-		$our_pages[] = wpinv_get_option( 'invoice_history_page', false );
575
+		$our_pages[] = wpinv_get_option('invoice_history_page', false);
576 576
 
577 577
 		// Subscriptions page.
578
-		$our_pages[] = wpinv_get_option( 'invoice_subscription_page', false );
578
+		$our_pages[] = wpinv_get_option('invoice_subscription_page', false);
579 579
 
580
-		$our_pages   = array_map( 'intval', array_filter( $our_pages ) );
580
+		$our_pages   = array_map('intval', array_filter($our_pages));
581 581
 
582 582
 		$excluded_posts_ids = $excluded_posts_ids + $our_pages;
583
-		return array_unique( $excluded_posts_ids );
583
+		return array_unique($excluded_posts_ids);
584 584
 
585 585
 	}
586 586
 
@@ -590,15 +590,15 @@  discard block
 block discarded – undo
590 590
 	 * @since 1.0.19
591 591
 	 * @param string[] $post_types
592 592
 	 */
593
-	public function exclude_invoicing_post_types( $post_types ) {
593
+	public function exclude_invoicing_post_types($post_types) {
594 594
 
595 595
 		// Ensure that we have an array.
596
-		if ( ! is_array( $post_types ) ) {
596
+		if (!is_array($post_types)) {
597 597
 			$post_types = array();
598 598
 		}
599 599
 
600 600
 		// Remove our post types.
601
-		return array_diff( $post_types, array_keys( getpaid_get_invoice_post_types() ) );
601
+		return array_diff($post_types, array_keys(getpaid_get_invoice_post_types()));
602 602
 	}
603 603
 
604 604
 	/**
@@ -607,7 +607,7 @@  discard block
 block discarded – undo
607 607
 	 * @since 2.0.0
608 608
 	 */
609 609
 	public function wp_footer() {
610
-		wpinv_get_template( 'frontend-footer.php' );
610
+		wpinv_get_template('frontend-footer.php');
611 611
 	}
612 612
 
613 613
 	/**
@@ -616,14 +616,14 @@  discard block
 block discarded – undo
616 616
 	 * @since 2.0.0
617 617
 	 */
618 618
 	public function wp_head() {
619
-		wpinv_get_template( 'frontend-head.php' );
619
+		wpinv_get_template('frontend-head.php');
620 620
 	}
621 621
 
622 622
 	/**
623 623
 	 * Custom query vars.
624 624
 	 *
625 625
 	 */
626
-	public function custom_query_vars( $vars ) {
626
+	public function custom_query_vars($vars) {
627 627
         $vars[] = 'getpaid-ipn';
628 628
         return $vars;
629 629
 	}
@@ -634,28 +634,28 @@  discard block
 block discarded – undo
634 634
 	 */
635 635
 	public function add_rewrite_rule() {
636 636
         $tag = 'getpaid-ipn';
637
-        add_rewrite_tag( "%$tag%", '([^&]+)' );
638
-        add_rewrite_rule( "^$tag/([^/]*)/?", "index.php?$tag=\$matches[1]", 'top' );
637
+        add_rewrite_tag("%$tag%", '([^&]+)');
638
+        add_rewrite_rule("^$tag/([^/]*)/?", "index.php?$tag=\$matches[1]", 'top');
639 639
 	}
640 640
 
641 641
 	/**
642 642
 	 * Processes non-query string ipns.
643 643
 	 *
644 644
 	 */
645
-	public function maybe_process_new_ipn( $query ) {
645
+	public function maybe_process_new_ipn($query) {
646 646
 
647
-        if ( is_admin() || ! $query->is_main_query() ) {
647
+        if (is_admin() || !$query->is_main_query()) {
648 648
             return;
649 649
         }
650 650
 
651
-		$gateway = get_query_var( 'getpaid-ipn' );
651
+		$gateway = get_query_var('getpaid-ipn');
652 652
 
653
-        if ( ! empty( $gateway ) ) {
653
+        if (!empty($gateway)) {
654 654
 
655
-			$gateway = sanitize_text_field( $gateway );
655
+			$gateway = sanitize_text_field($gateway);
656 656
 			nocache_headers();
657
-			do_action( 'wpinv_verify_payment_ipn', $gateway );
658
-			do_action( "wpinv_verify_{$gateway}_ipn" );
657
+			do_action('wpinv_verify_payment_ipn', $gateway);
658
+			do_action("wpinv_verify_{$gateway}_ipn");
659 659
 			exit;
660 660
 
661 661
         }
Please login to merge, or discard this patch.
includes/user-functions.php 2 patches
Indentation   +88 added lines, -88 removed lines patch added patch discarded remove patch
@@ -19,28 +19,28 @@  discard block
 block discarded – undo
19 19
  */
20 20
 function getpaid_get_customers( $args = array(), $return = 'results' ) {
21 21
 
22
-	// Do not retrieve all fields if we just want the count.
23
-	if ( 'count' === $return ) {
24
-		$args['fields'] = 'id';
25
-		$args['number'] = 1;
26
-	}
22
+    // Do not retrieve all fields if we just want the count.
23
+    if ( 'count' === $return ) {
24
+        $args['fields'] = 'id';
25
+        $args['number'] = 1;
26
+    }
27 27
 
28
-	// Do not count all matches if we just want the results.
29
-	if ( 'results' === $return ) {
30
-		$args['count_total'] = false;
31
-	}
28
+    // Do not count all matches if we just want the results.
29
+    if ( 'results' === $return ) {
30
+        $args['count_total'] = false;
31
+    }
32 32
 
33
-	$query = new GetPaid_Customers_Query( $args );
33
+    $query = new GetPaid_Customers_Query( $args );
34 34
 
35
-	if ( 'results' === $return ) {
36
-		return $query->get_results();
37
-	}
35
+    if ( 'results' === $return ) {
36
+        return $query->get_results();
37
+    }
38 38
 
39
-	if ( 'count' === $return ) {
40
-		return $query->get_total();
41
-	}
39
+    if ( 'count' === $return ) {
40
+        return $query->get_total();
41
+    }
42 42
 
43
-	return $query;
43
+    return $query;
44 44
 }
45 45
 
46 46
 /**
@@ -106,11 +106,11 @@  discard block
 block discarded – undo
106 106
  */
107 107
 function wpinv_get_capability( $capalibilty = 'manage_invoicing' ) {
108 108
 
109
-	if ( current_user_can( 'manage_options' ) ) {
110
-		return 'manage_options';
111
-	};
109
+    if ( current_user_can( 'manage_options' ) ) {
110
+        return 'manage_options';
111
+    };
112 112
 
113
-	return $capalibilty;
113
+    return $capalibilty;
114 114
 }
115 115
 
116 116
 /**
@@ -133,9 +133,9 @@  discard block
 block discarded – undo
133 133
  * @return bool Whether the current user has the given capability.
134 134
  */
135 135
 function wpinv_current_user_can( $capability, $args = array() ) {
136
-	$can = wpinv_current_user_can_manage_invoicing();
136
+    $can = wpinv_current_user_can_manage_invoicing();
137 137
 
138
-	return apply_filters( 'getpaid_current_user_can', $can, $capability, $args );
138
+    return apply_filters( 'getpaid_current_user_can', $can, $capability, $args );
139 139
 }
140 140
 
141 141
 /**
@@ -149,10 +149,10 @@  discard block
 block discarded – undo
149 149
     // Prepare user values.
150 150
     $prefix = preg_replace( '/\s+/', '', $prefix );
151 151
     $prefix = empty( $prefix ) ? $email : $prefix;
152
-	$args   = array(
153
-		'user_login' => wpinv_generate_user_name( $prefix ),
154
-		'user_pass'  => wp_generate_password(),
155
-		'user_email' => $email,
152
+    $args   = array(
153
+        'user_login' => wpinv_generate_user_name( $prefix ),
154
+        'user_pass'  => wp_generate_password(),
155
+        'user_email' => $email,
156 156
         'role'       => 'subscriber',
157 157
     );
158 158
 
@@ -169,16 +169,16 @@  discard block
 block discarded – undo
169 169
 function wpinv_generate_user_name( $prefix = '' ) {
170 170
 
171 171
     // If prefix is an email, retrieve the part before the email.
172
-	$prefix = strtok( $prefix, '@' );
172
+    $prefix = strtok( $prefix, '@' );
173 173
     $prefix = trim( $prefix, '.' );
174 174
 
175
-	// Sanitize the username.
176
-	$prefix = sanitize_user( $prefix, true );
175
+    // Sanitize the username.
176
+    $prefix = sanitize_user( $prefix, true );
177 177
 
178
-	$illegal_logins = (array) apply_filters( 'illegal_user_logins', array() );
179
-	if ( empty( $prefix ) || in_array( strtolower( $prefix ), array_map( 'strtolower', $illegal_logins ), true ) ) {
180
-		$prefix = 'gtp_' . zeroise( wp_rand( 0, 9999 ), 4 );
181
-	}
178
+    $illegal_logins = (array) apply_filters( 'illegal_user_logins', array() );
179
+    if ( empty( $prefix ) || in_array( strtolower( $prefix ), array_map( 'strtolower', $illegal_logins ), true ) ) {
180
+        $prefix = 'gtp_' . zeroise( wp_rand( 0, 9999 ), 4 );
181
+    }
182 182
 
183 183
     $username = $prefix;
184 184
     $postfix  = 2;
@@ -317,43 +317,43 @@  discard block
 block discarded – undo
317 317
 
318 318
                         $value = $customer->get( $key );
319 319
 
320
-					// Display the country.
321
-					if ( 'country' == $key ) {
322
-
323
-						aui()->select(
324
-							array(
325
-								'options'     => wpinv_get_country_list(),
326
-								'name'        => 'getpaid_address[' . esc_attr( $key ) . ']',
327
-								'id'          => 'wpinv-' . sanitize_html_class( $key ),
328
-								'value'       => sanitize_text_field( $value ),
329
-								'placeholder' => $label,
330
-								'label'       => wp_kses_post( $label ),
331
-								'label_type'  => 'vertical',
332
-								'class'       => 'getpaid-address-field',
320
+                    // Display the country.
321
+                    if ( 'country' == $key ) {
322
+
323
+                        aui()->select(
324
+                            array(
325
+                                'options'     => wpinv_get_country_list(),
326
+                                'name'        => 'getpaid_address[' . esc_attr( $key ) . ']',
327
+                                'id'          => 'wpinv-' . sanitize_html_class( $key ),
328
+                                'value'       => sanitize_text_field( $value ),
329
+                                'placeholder' => $label,
330
+                                'label'       => wp_kses_post( $label ),
331
+                                'label_type'  => 'vertical',
332
+                                'class'       => 'getpaid-address-field',
333 333
                             ),
334 334
                             true
335
-						);
335
+                        );
336 336
 
337
-					}
337
+                    }
338 338
 
339
-					// Display the state.
340
-					elseif ( 'state' == $key ) {
339
+                    // Display the state.
340
+                    elseif ( 'state' == $key ) {
341 341
 
342
-						getpaid_get_states_select_markup(
342
+                        getpaid_get_states_select_markup(
343 343
                             $customer->get( 'country' ),
344
-							$value,
345
-							$label,
346
-							$label,
347
-							'',
348
-							false,
349
-							'',
350
-							'getpaid_address[' . esc_attr( $key ) . ']',
344
+                            $value,
345
+                            $label,
346
+                            $label,
347
+                            '',
348
+                            false,
349
+                            '',
350
+                            'getpaid_address[' . esc_attr( $key ) . ']',
351 351
                             true
352
-						);
352
+                        );
353 353
 
354 354
                         } else {
355 355
 
356
-						aui()->input(
356
+                        aui()->input(
357 357
                             array(
358 358
                                 'name'        => 'getpaid_address[' . esc_attr( $key ) . ']',
359 359
                                 'id'          => 'wpinv-' . sanitize_html_class( $key ),
@@ -365,7 +365,7 @@  discard block
 block discarded – undo
365 365
                                 'class'       => 'getpaid-address-field',
366 366
                             ),
367 367
                             true
368
-						);
368
+                        );
369 369
 
370 370
                         }
371 371
                     }
@@ -509,7 +509,7 @@  discard block
 block discarded – undo
509 509
 function getpaid_allowed_html() {
510 510
     $allowed_html = wp_kses_allowed_html( 'post' );
511 511
 
512
-	// form fields
512
+    // form fields
513 513
     $allowed_html['form'] = array(
514 514
         'action'         => true,
515 515
         'accept'         => true,
@@ -521,12 +521,12 @@  discard block
 block discarded – undo
521 521
     );
522 522
 
523 523
     // - input
524
-	$allowed_html['input'] = array(
525
-		'class'        => array(),
526
-		'id'           => array(),
527
-		'name'         => array(),
528
-		'value'        => array(),
529
-		'type'         => array(),
524
+    $allowed_html['input'] = array(
525
+        'class'        => array(),
526
+        'id'           => array(),
527
+        'name'         => array(),
528
+        'value'        => array(),
529
+        'type'         => array(),
530 530
         'placeholder'  => array(),
531 531
         'autocomplete' => array(),
532 532
         'autofocus'    => array(),
@@ -540,33 +540,33 @@  discard block
 block discarded – undo
540 540
         'max'          => array(),
541 541
         'step'         => array(),
542 542
         'size'         => array(),
543
-	);
543
+    );
544 544
 
545 545
     // - input
546
-	$allowed_html['textarea'] = array(
547
-		'class' => array(),
548
-		'id'    => array(),
549
-		'name'  => array(),
550
-		'value' => array(),
551
-	);
552
-
553
-	// select
554
-	$allowed_html['select'] = array(
555
-		'class'        => array(),
556
-		'id'           => array(),
557
-		'name'         => array(),
546
+    $allowed_html['textarea'] = array(
547
+        'class' => array(),
548
+        'id'    => array(),
549
+        'name'  => array(),
550
+        'value' => array(),
551
+    );
552
+
553
+    // select
554
+    $allowed_html['select'] = array(
555
+        'class'        => array(),
556
+        'id'           => array(),
557
+        'name'         => array(),
558 558
         'autocomplete' => array(),
559 559
         'multiple'     => array(),
560
-	);
560
+    );
561 561
 
562
-	// select options
563
-	$allowed_html['option'] = array(
564
-		'selected' => array(),
562
+    // select options
563
+    $allowed_html['option'] = array(
564
+        'selected' => array(),
565 565
         'disabled' => array(),
566 566
         'value'    => array(),
567
-	);
567
+    );
568 568
 
569
-	return $allowed_html;
569
+    return $allowed_html;
570 570
 
571 571
 }
572 572
 
Please login to merge, or discard this patch.
Spacing   +150 added lines, -150 removed lines patch added patch discarded remove patch
@@ -6,7 +6,7 @@  discard block
 block discarded – undo
6 6
  * @package GetPaid
7 7
  */
8 8
 
9
-defined( 'ABSPATH' ) || exit;
9
+defined('ABSPATH') || exit;
10 10
 
11 11
 /**
12 12
  * Queries the customers database.
@@ -17,26 +17,26 @@  discard block
 block discarded – undo
17 17
  *
18 18
  * @return int|array|GetPaid_Customer[]|GetPaid_Customers_Query
19 19
  */
20
-function getpaid_get_customers( $args = array(), $return = 'results' ) {
20
+function getpaid_get_customers($args = array(), $return = 'results') {
21 21
 
22 22
 	// Do not retrieve all fields if we just want the count.
23
-	if ( 'count' === $return ) {
23
+	if ('count' === $return) {
24 24
 		$args['fields'] = 'id';
25 25
 		$args['number'] = 1;
26 26
 	}
27 27
 
28 28
 	// Do not count all matches if we just want the results.
29
-	if ( 'results' === $return ) {
29
+	if ('results' === $return) {
30 30
 		$args['count_total'] = false;
31 31
 	}
32 32
 
33
-	$query = new GetPaid_Customers_Query( $args );
33
+	$query = new GetPaid_Customers_Query($args);
34 34
 
35
-	if ( 'results' === $return ) {
35
+	if ('results' === $return) {
36 36
 		return $query->get_results();
37 37
 	}
38 38
 
39
-	if ( 'count' === $return ) {
39
+	if ('count' === $return) {
40 40
 		return $query->get_total();
41 41
 	}
42 42
 
@@ -49,19 +49,19 @@  discard block
 block discarded – undo
49 49
  * @param int|string|object|GetPaid_Customer $customer customer id, email or object.
50 50
  * @return GetPaid_Customer|null
51 51
  */
52
-function getpaid_get_customer( $customer ) {
52
+function getpaid_get_customer($customer) {
53 53
 
54
-    if ( empty( $customer ) ) {
54
+    if (empty($customer)) {
55 55
         return null;
56 56
     }
57 57
 
58 58
     // Retrieve the customer.
59
-    if ( ! is_a( $customer, 'GetPaid_Customer' ) ) {
60
-        $customer = new GetPaid_Customer( $customer );
59
+    if (!is_a($customer, 'GetPaid_Customer')) {
60
+        $customer = new GetPaid_Customer($customer);
61 61
     }
62 62
 
63 63
     // Check if it exists.
64
-    if ( $customer->exists() ) {
64
+    if ($customer->exists()) {
65 65
         return $customer;
66 66
     }
67 67
 
@@ -74,9 +74,9 @@  discard block
 block discarded – undo
74 74
  * @return GetPaid_Customer|null
75 75
  * @since 1.0.0
76 76
  */
77
-function getpaid_get_customer_by_user_id( $user_id ) {
77
+function getpaid_get_customer_by_user_id($user_id) {
78 78
     return getpaid_get_customer(
79
-        GetPaid_Customer::get_customer_id_by( $user_id, 'user_id' )
79
+        GetPaid_Customer::get_customer_id_by($user_id, 'user_id')
80 80
     );
81 81
 }
82 82
 
@@ -88,13 +88,13 @@  discard block
 block discarded – undo
88 88
  * @param array $args
89 89
  * @see wp_dropdown_users
90 90
  */
91
-function wpinv_dropdown_users( $args = '' ) {
91
+function wpinv_dropdown_users($args = '') {
92 92
 
93
-    if ( is_array( $args ) && ! empty( $args['show'] ) && 'display_name_with_email' == $args['show'] ) {
93
+    if (is_array($args) && !empty($args['show']) && 'display_name_with_email' == $args['show']) {
94 94
         $args['show'] = 'display_name_with_login';
95 95
     }
96 96
 
97
-    return wp_dropdown_users( $args );
97
+    return wp_dropdown_users($args);
98 98
 }
99 99
 
100 100
 /**
@@ -104,9 +104,9 @@  discard block
 block discarded – undo
104 104
  * @return string capability to check against
105 105
  * @param string $capalibilty Optional. The alternative capability to check against.
106 106
  */
107
-function wpinv_get_capability( $capalibilty = 'manage_invoicing' ) {
107
+function wpinv_get_capability($capalibilty = 'manage_invoicing') {
108 108
 
109
-	if ( current_user_can( 'manage_options' ) ) {
109
+	if (current_user_can('manage_options')) {
110 110
 		return 'manage_options';
111 111
 	};
112 112
 
@@ -120,7 +120,7 @@  discard block
 block discarded – undo
120 120
  * @return bool
121 121
  */
122 122
 function wpinv_current_user_can_manage_invoicing() {
123
-    return current_user_can( wpinv_get_capability() );
123
+    return current_user_can(wpinv_get_capability());
124 124
 }
125 125
 
126 126
 /**
@@ -132,10 +132,10 @@  discard block
 block discarded – undo
132 132
  * @param mixed  $args    Optional further parameters, typically starting with an object.
133 133
  * @return bool Whether the current user has the given capability.
134 134
  */
135
-function wpinv_current_user_can( $capability, $args = array() ) {
135
+function wpinv_current_user_can($capability, $args = array()) {
136 136
 	$can = wpinv_current_user_can_manage_invoicing();
137 137
 
138
-	return apply_filters( 'getpaid_current_user_can', $can, $capability, $args );
138
+	return apply_filters('getpaid_current_user_can', $can, $capability, $args);
139 139
 }
140 140
 
141 141
 /**
@@ -144,19 +144,19 @@  discard block
 block discarded – undo
144 144
  * @since 1.0.19
145 145
  * @return int|WP_Error
146 146
  */
147
-function wpinv_create_user( $email, $prefix = '' ) {
147
+function wpinv_create_user($email, $prefix = '') {
148 148
 
149 149
     // Prepare user values.
150
-    $prefix = preg_replace( '/\s+/', '', $prefix );
151
-    $prefix = empty( $prefix ) ? $email : $prefix;
152
-	$args   = array(
153
-		'user_login' => wpinv_generate_user_name( $prefix ),
150
+    $prefix = preg_replace('/\s+/', '', $prefix);
151
+    $prefix = empty($prefix) ? $email : $prefix;
152
+	$args = array(
153
+		'user_login' => wpinv_generate_user_name($prefix),
154 154
 		'user_pass'  => wp_generate_password(),
155 155
 		'user_email' => $email,
156 156
         'role'       => 'subscriber',
157 157
     );
158 158
 
159
-    return wp_insert_user( $args );
159
+    return wp_insert_user($args);
160 160
 
161 161
 }
162 162
 
@@ -166,26 +166,26 @@  discard block
 block discarded – undo
166 166
  * @since 1.0.19
167 167
  * @return bool|WP_User
168 168
  */
169
-function wpinv_generate_user_name( $prefix = '' ) {
169
+function wpinv_generate_user_name($prefix = '') {
170 170
 
171 171
     // If prefix is an email, retrieve the part before the email.
172
-	$prefix = strtok( $prefix, '@' );
173
-    $prefix = trim( $prefix, '.' );
172
+	$prefix = strtok($prefix, '@');
173
+    $prefix = trim($prefix, '.');
174 174
 
175 175
 	// Sanitize the username.
176
-	$prefix = sanitize_user( $prefix, true );
176
+	$prefix = sanitize_user($prefix, true);
177 177
 
178
-	$illegal_logins = (array) apply_filters( 'illegal_user_logins', array() );
179
-	if ( empty( $prefix ) || in_array( strtolower( $prefix ), array_map( 'strtolower', $illegal_logins ), true ) ) {
180
-		$prefix = 'gtp_' . zeroise( wp_rand( 0, 9999 ), 4 );
178
+	$illegal_logins = (array) apply_filters('illegal_user_logins', array());
179
+	if (empty($prefix) || in_array(strtolower($prefix), array_map('strtolower', $illegal_logins), true)) {
180
+		$prefix = 'gtp_' . zeroise(wp_rand(0, 9999), 4);
181 181
 	}
182 182
 
183 183
     $username = $prefix;
184 184
     $postfix  = 2;
185 185
 
186
-    while ( username_exists( $username ) ) {
186
+    while (username_exists($username)) {
187 187
         $username = "{$prefix}{$postfix}";
188
-        $postfix ++;
188
+        $postfix++;
189 189
     }
190 190
 
191 191
     return $username;
@@ -202,31 +202,31 @@  discard block
 block discarded – undo
202 202
     $tabs = array(
203 203
 
204 204
         'gp-invoices'      => array(
205
-            'label'   => __( 'Invoices', 'invoicing' ), // Name of the tab.
205
+            'label'   => __('Invoices', 'invoicing'), // Name of the tab.
206 206
             'content' => '[wpinv_history]', // Content of the tab. Or specify "callback" to provide a callback instead.
207 207
             'icon'    => 'fas fa-file-invoice', // Shown on some profile plugins.
208 208
         ),
209 209
 
210 210
         'gp-subscriptions' => array(
211
-            'label'   => __( 'Subscriptions', 'invoicing' ),
211
+            'label'   => __('Subscriptions', 'invoicing'),
212 212
             'content' => '[wpinv_subscriptions]',
213 213
             'icon'    => 'fas fa-redo',
214 214
         ),
215 215
 
216 216
         'gp-edit-address'  => array(
217
-            'label'    => __( 'Billing Address', 'invoicing' ),
217
+            'label'    => __('Billing Address', 'invoicing'),
218 218
             'callback' => 'getpaid_display_address_edit_tab',
219 219
             'icon'     => 'fas fa-credit-card',
220 220
         ),
221 221
 
222 222
     );
223 223
 
224
-    $tabs = apply_filters( 'getpaid_user_content_tabs', $tabs );
224
+    $tabs = apply_filters('getpaid_user_content_tabs', $tabs);
225 225
 
226 226
     // Make sure address editing is last on the list.
227
-    if ( isset( $tabs['gp-edit-address'] ) ) {
227
+    if (isset($tabs['gp-edit-address'])) {
228 228
         $address = $tabs['gp-edit-address'];
229
-        unset( $tabs['gp-edit-address'] );
229
+        unset($tabs['gp-edit-address']);
230 230
         $tabs['gp-edit-address'] = $address;
231 231
     }
232 232
 
@@ -240,19 +240,19 @@  discard block
 block discarded – undo
240 240
  * @param array $tab
241 241
  * @return array
242 242
  */
243
-function getpaid_prepare_user_content_tab( $tab ) {
243
+function getpaid_prepare_user_content_tab($tab) {
244 244
 
245
-    if ( ! empty( $tab['callback'] ) ) {
246
-        return call_user_func( $tab['callback'] );
245
+    if (!empty($tab['callback'])) {
246
+        return call_user_func($tab['callback']);
247 247
     }
248 248
 
249
-    if ( ! empty( $tab['content'] ) ) {
250
-        return convert_smilies( capital_P_dangit( wp_filter_content_tags( do_shortcode( shortcode_unautop( wpautop( wptexturize( do_blocks( $tab['content'] ) ) ) ) ) ) ) );
249
+    if (!empty($tab['content'])) {
250
+        return convert_smilies(capital_P_dangit(wp_filter_content_tags(do_shortcode(shortcode_unautop(wpautop(wptexturize(do_blocks($tab['content']))))))));
251 251
     }
252 252
 
253 253
     $notice = aui()->alert(
254 254
         array(
255
-            'content' => __( 'This tab has no content or content callback.', 'invoicing' ),
255
+            'content' => __('This tab has no content or content callback.', 'invoicing'),
256 256
             'type'    => 'error',
257 257
         )
258 258
     );
@@ -268,14 +268,14 @@  discard block
 block discarded – undo
268 268
  * @param string $default
269 269
  * @return array
270 270
  */
271
-function getpaid_get_tab_url( $tab, $default ) {
271
+function getpaid_get_tab_url($tab, $default) {
272 272
     global $getpaid_tab_url;
273 273
 
274
-    if ( empty( $getpaid_tab_url ) ) {
274
+    if (empty($getpaid_tab_url)) {
275 275
         return $default;
276 276
     }
277 277
 
278
-    return sprintf( $getpaid_tab_url, $tab );
278
+    return sprintf($getpaid_tab_url, $tab);
279 279
 
280 280
 }
281 281
 
@@ -287,21 +287,21 @@  discard block
 block discarded – undo
287 287
  */
288 288
 function getpaid_display_address_edit_tab() {
289 289
 
290
-    if ( 0 === get_current_user_id() ) {
290
+    if (0 === get_current_user_id()) {
291 291
         return '<div class="bsui">' . aui()->alert(
292 292
             array(
293 293
                 'type'        => 'error',
294
-                'content'     => __( 'Your must be logged in to view this section', 'invoicing' ),
294
+                'content'     => __('Your must be logged in to view this section', 'invoicing'),
295 295
                 'dismissible' => false,
296 296
             )
297 297
         ) . '</div>';
298 298
     }
299 299
 
300
-    $customer = getpaid_get_customer_by_user_id( get_current_user_id() );
300
+    $customer = getpaid_get_customer_by_user_id(get_current_user_id());
301 301
 
302
-    if ( empty( $customer ) ) {
303
-        $customer = new GetPaid_Customer( 0 );
304
-        $customer->clone_user( get_current_user_id() );
302
+    if (empty($customer)) {
303
+        $customer = new GetPaid_Customer(0);
304
+        $customer->clone_user(get_current_user_id());
305 305
         $customer->save();
306 306
     }
307 307
 
@@ -313,21 +313,21 @@  discard block
 block discarded – undo
313 313
 
314 314
                 <?php
315 315
 
316
-                    foreach ( getpaid_user_address_fields() as $key => $label ) {
316
+                    foreach (getpaid_user_address_fields() as $key => $label) {
317 317
 
318
-                        $value = $customer->get( $key );
318
+                        $value = $customer->get($key);
319 319
 
320 320
 					// Display the country.
321
-					if ( 'country' == $key ) {
321
+					if ('country' == $key) {
322 322
 
323 323
 						aui()->select(
324 324
 							array(
325 325
 								'options'     => wpinv_get_country_list(),
326
-								'name'        => 'getpaid_address[' . esc_attr( $key ) . ']',
327
-								'id'          => 'wpinv-' . sanitize_html_class( $key ),
328
-								'value'       => sanitize_text_field( $value ),
326
+								'name'        => 'getpaid_address[' . esc_attr($key) . ']',
327
+								'id'          => 'wpinv-' . sanitize_html_class($key),
328
+								'value'       => sanitize_text_field($value),
329 329
 								'placeholder' => $label,
330
-								'label'       => wp_kses_post( $label ),
330
+								'label'       => wp_kses_post($label),
331 331
 								'label_type'  => 'vertical',
332 332
 								'class'       => 'getpaid-address-field',
333 333
                             ),
@@ -337,17 +337,17 @@  discard block
 block discarded – undo
337 337
 					}
338 338
 
339 339
 					// Display the state.
340
-					elseif ( 'state' == $key ) {
340
+					elseif ('state' == $key) {
341 341
 
342 342
 						getpaid_get_states_select_markup(
343
-                            $customer->get( 'country' ),
343
+                            $customer->get('country'),
344 344
 							$value,
345 345
 							$label,
346 346
 							$label,
347 347
 							'',
348 348
 							false,
349 349
 							'',
350
-							'getpaid_address[' . esc_attr( $key ) . ']',
350
+							'getpaid_address[' . esc_attr($key) . ']',
351 351
                             true
352 352
 						);
353 353
 
@@ -355,13 +355,13 @@  discard block
 block discarded – undo
355 355
 
356 356
 						aui()->input(
357 357
                             array(
358
-                                'name'        => 'getpaid_address[' . esc_attr( $key ) . ']',
359
-                                'id'          => 'wpinv-' . sanitize_html_class( $key ),
358
+                                'name'        => 'getpaid_address[' . esc_attr($key) . ']',
359
+                                'id'          => 'wpinv-' . sanitize_html_class($key),
360 360
                                 'placeholder' => $label,
361
-                                'label'       => wp_kses_post( $label ),
361
+                                'label'       => wp_kses_post($label),
362 362
                                 'label_type'  => 'vertical',
363 363
                                 'type'        => 'text',
364
-                                'value'       => sanitize_text_field( $value ),
364
+                                'value'       => sanitize_text_field($value),
365 365
                                 'class'       => 'getpaid-address-field',
366 366
                             ),
367 367
                             true
@@ -375,32 +375,32 @@  discard block
 block discarded – undo
375 375
                             'name'        => 'getpaid_address[email_cc]',
376 376
                             'id'          => 'wpinv-email_cc',
377 377
                             'placeholder' => '[email protected], [email protected]',
378
-                            'label'       => __( 'Other email addresses', 'invoicing' ),
378
+                            'label'       => __('Other email addresses', 'invoicing'),
379 379
                             'label_type'  => 'vertical',
380 380
                             'type'        => 'text',
381
-                            'value'       => sanitize_text_field( $customer->get( 'email_cc' ) ),
381
+                            'value'       => sanitize_text_field($customer->get('email_cc')),
382 382
                             'class'       => 'getpaid-address-field',
383
-                            'help_text'   => __( 'Optionally provide other email addresses where we should send payment notifications', 'invoicing' ),
383
+                            'help_text'   => __('Optionally provide other email addresses where we should send payment notifications', 'invoicing'),
384 384
                         ),
385 385
                         true
386 386
                     );
387 387
 
388
-                    do_action( 'getpaid_display_address_edit_tab' );
388
+                    do_action('getpaid_display_address_edit_tab');
389 389
 
390 390
                     aui()->input(
391 391
                         array(
392 392
                             'name'      => 'getpaid_profile_edit_submit_button',
393 393
                             'id'        => 'getpaid_profile_edit_submit_button',
394
-                            'value'     => __( 'Save Address', 'invoicing' ),
395
-                            'help_text' => __( 'New invoices will use this address as the billing address.', 'invoicing' ),
394
+                            'value'     => __('Save Address', 'invoicing'),
395
+                            'help_text' => __('New invoices will use this address as the billing address.', 'invoicing'),
396 396
                             'type'      => 'submit',
397 397
                             'class'     => 'btn btn-primary btn-block submit-button',
398 398
                         ),
399 399
                         true
400 400
                     );
401 401
 
402
-                    wp_nonce_field( 'getpaid-nonce', 'getpaid-nonce' );
403
-                    getpaid_hidden_field( 'getpaid-action', 'edit_billing_details' );
402
+                    wp_nonce_field('getpaid-nonce', 'getpaid-nonce');
403
+                    getpaid_hidden_field('getpaid-action', 'edit_billing_details');
404 404
                 ?>
405 405
 
406 406
             </form>
@@ -410,7 +410,7 @@  discard block
 block discarded – undo
410 410
 
411 411
     return ob_get_clean();
412 412
 }
413
-add_shortcode( 'getpaid_edit_address', 'getpaid_display_address_edit_tab' );
413
+add_shortcode('getpaid_edit_address', 'getpaid_display_address_edit_tab');
414 414
 
415 415
 /**
416 416
  * Saves the billing address edit tab.
@@ -418,35 +418,35 @@  discard block
 block discarded – undo
418 418
  * @since 2.1.4
419 419
  * @param array $data
420 420
  */
421
-function getpaid_save_address_edit_tab( $data ) {
421
+function getpaid_save_address_edit_tab($data) {
422 422
 
423
-    if ( empty( $data['getpaid_address'] ) || ! is_array( $data['getpaid_address'] ) ) {
423
+    if (empty($data['getpaid_address']) || !is_array($data['getpaid_address'])) {
424 424
         return;
425 425
     }
426 426
 
427 427
     $data     = $data['getpaid_address'];
428
-    $customer = getpaid_get_customer_by_user_id( get_current_user_id() );
428
+    $customer = getpaid_get_customer_by_user_id(get_current_user_id());
429 429
 
430
-    if ( empty( $customer ) ) {
431
-        $customer = new GetPaid_Customer( 0 );
432
-        $customer->clone_user( get_current_user_id() );
430
+    if (empty($customer)) {
431
+        $customer = new GetPaid_Customer(0);
432
+        $customer->clone_user(get_current_user_id());
433 433
     }
434 434
 
435
-    foreach ( array_keys( getpaid_user_address_fields() ) as $field ) {
435
+    foreach (array_keys(getpaid_user_address_fields()) as $field) {
436 436
 
437
-        if ( isset( $data[ $field ] ) ) {
438
-            $customer->set( $field, sanitize_text_field( $data[ $field ] ) );
437
+        if (isset($data[$field])) {
438
+            $customer->set($field, sanitize_text_field($data[$field]));
439 439
         }
440 440
     }
441 441
 
442
-    if ( isset( $data['email_cc'] ) ) {
443
-        $customer->set( 'email_cc', sanitize_text_field( $data['email_cc'] ) );
442
+    if (isset($data['email_cc'])) {
443
+        $customer->set('email_cc', sanitize_text_field($data['email_cc']));
444 444
     }
445 445
 
446 446
     $customer->save();
447
-    wpinv_set_error( 'address_updated' );
447
+    wpinv_set_error('address_updated');
448 448
 }
449
-add_action( 'getpaid_authenticated_action_edit_billing_details', 'getpaid_save_address_edit_tab' );
449
+add_action('getpaid_authenticated_action_edit_billing_details', 'getpaid_save_address_edit_tab');
450 450
 
451 451
 
452 452
 /*
@@ -464,27 +464,27 @@  discard block
 block discarded – undo
464 464
  * @param  array $tabs
465 465
  * @return array
466 466
  */
467
-function getpaid_filter_userswp_account_tabs( $tabs ) {
467
+function getpaid_filter_userswp_account_tabs($tabs) {
468 468
 
469 469
     // Abort if the integration is inactive.
470
-    if ( ! getpaid_is_userswp_integration_active() ) {
470
+    if (!getpaid_is_userswp_integration_active()) {
471 471
         return $tabs;
472 472
     }
473 473
 
474
-    $new_tabs   = array();
474
+    $new_tabs = array();
475 475
 
476
-    foreach ( getpaid_get_user_content_tabs() as $slug => $tab ) {
476
+    foreach (getpaid_get_user_content_tabs() as $slug => $tab) {
477 477
 
478
-        $new_tabs[ $slug ] = array(
478
+        $new_tabs[$slug] = array(
479 479
             'title' => $tab['label'],
480 480
             'icon'  => $tab['icon'],
481 481
         );
482 482
 
483 483
     }
484 484
 
485
-    return array_merge( $tabs, $new_tabs );
485
+    return array_merge($tabs, $new_tabs);
486 486
 }
487
-add_filter( 'uwp_account_available_tabs', 'getpaid_filter_userswp_account_tabs' );
487
+add_filter('uwp_account_available_tabs', 'getpaid_filter_userswp_account_tabs');
488 488
 
489 489
 /**
490 490
  * Display our UsersWP account tabs.
@@ -493,21 +493,21 @@  discard block
 block discarded – undo
493 493
  * @param  array $tabs
494 494
  * @return array
495 495
  */
496
-function getpaid_display_userswp_account_tabs( $tab ) {
496
+function getpaid_display_userswp_account_tabs($tab) {
497 497
     global $getpaid_tab_url;
498 498
 
499 499
     $our_tabs = getpaid_get_user_content_tabs();
500 500
 
501
-    if ( getpaid_is_userswp_integration_active() && isset( $our_tabs[ $tab ] ) ) {
502
-        $getpaid_tab_url = add_query_arg( 'type', '%s', uwp_get_account_page_url() );
503
-        echo wp_kses( getpaid_prepare_user_content_tab( $our_tabs[ $tab ] ), getpaid_allowed_html() );
501
+    if (getpaid_is_userswp_integration_active() && isset($our_tabs[$tab])) {
502
+        $getpaid_tab_url = add_query_arg('type', '%s', uwp_get_account_page_url());
503
+        echo wp_kses(getpaid_prepare_user_content_tab($our_tabs[$tab]), getpaid_allowed_html());
504 504
     }
505 505
 
506 506
 }
507
-add_action( 'uwp_account_form_display', 'getpaid_display_userswp_account_tabs' );
507
+add_action('uwp_account_form_display', 'getpaid_display_userswp_account_tabs');
508 508
 
509 509
 function getpaid_allowed_html() {
510
-    $allowed_html = wp_kses_allowed_html( 'post' );
510
+    $allowed_html = wp_kses_allowed_html('post');
511 511
 
512 512
 	// form fields
513 513
     $allowed_html['form'] = array(
@@ -578,17 +578,17 @@  discard block
 block discarded – undo
578 578
  * @param  string $tab   Current tab.
579 579
  * @return string Title.
580 580
  */
581
-function getpaid_filter_userswp_account_title( $title, $tab ) {
581
+function getpaid_filter_userswp_account_title($title, $tab) {
582 582
 
583
-    $our_tabs   = getpaid_get_user_content_tabs();
583
+    $our_tabs = getpaid_get_user_content_tabs();
584 584
 
585
-    if ( getpaid_is_userswp_integration_active() && isset( $our_tabs[ $tab ] ) ) {
586
-        return $our_tabs[ $tab ]['label'];
585
+    if (getpaid_is_userswp_integration_active() && isset($our_tabs[$tab])) {
586
+        return $our_tabs[$tab]['label'];
587 587
     }
588 588
 
589 589
     return $title;
590 590
 }
591
-add_filter( 'uwp_account_page_title', 'getpaid_filter_userswp_account_title', 10, 2 );
591
+add_filter('uwp_account_page_title', 'getpaid_filter_userswp_account_title', 10, 2);
592 592
 
593 593
 /**
594 594
  * Registers the UsersWP integration settings.
@@ -597,26 +597,26 @@  discard block
 block discarded – undo
597 597
  * @param  array $settings An array of integration settings.
598 598
  * @return array
599 599
  */
600
-function getpaid_register_userswp_settings( $settings ) {
600
+function getpaid_register_userswp_settings($settings) {
601 601
 
602
-    if ( defined( 'USERSWP_PLUGIN_FILE' ) ) {
602
+    if (defined('USERSWP_PLUGIN_FILE')) {
603 603
 
604 604
         $settings[] = array(
605 605
 
606 606
             'id'       => 'userswp',
607
-            'label'    => __( 'UsersWP', 'invoicing' ),
607
+            'label'    => __('UsersWP', 'invoicing'),
608 608
             'settings' => array(
609 609
 
610 610
                 'userswp_settings' => array(
611 611
                     'id'   => 'userswp_settings',
612
-                    'name' => '<h3>' . __( 'UsersWP', 'invoicing' ) . '</h3>',
612
+                    'name' => '<h3>' . __('UsersWP', 'invoicing') . '</h3>',
613 613
                     'type' => 'header',
614 614
                 ),
615 615
 
616 616
                 'enable_userswp'   => array(
617 617
                     'id'   => 'enable_userswp',
618
-                    'name' => __( 'Enable Integration', 'invoicing' ),
619
-                    'desc' => __( 'Display GetPaid items on UsersWP account page.', 'invoicing' ),
618
+                    'name' => __('Enable Integration', 'invoicing'),
619
+                    'desc' => __('Display GetPaid items on UsersWP account page.', 'invoicing'),
620 620
                     'type' => 'checkbox',
621 621
                     'std'  => 1,
622 622
                 ),
@@ -629,7 +629,7 @@  discard block
 block discarded – undo
629 629
 
630 630
     return $settings;
631 631
 }
632
-add_filter( 'getpaid_integration_settings', 'getpaid_register_userswp_settings' );
632
+add_filter('getpaid_integration_settings', 'getpaid_register_userswp_settings');
633 633
 
634 634
 /**
635 635
  * Ovewrites the invoices history page to UsersWP.
@@ -637,18 +637,18 @@  discard block
 block discarded – undo
637 637
  * @since  2.3.1
638 638
  * @return bool
639 639
  */
640
-function getpaid_userswp_overwrite_invoice_history_page( $url, $post_type ) {
640
+function getpaid_userswp_overwrite_invoice_history_page($url, $post_type) {
641 641
 
642 642
     $our_tabs = getpaid_get_user_content_tabs();
643 643
     $tab      = "gp-{$post_type}s";
644
-    if ( getpaid_is_userswp_integration_active() && isset( $our_tabs[ $tab ] ) ) {
645
-        return add_query_arg( 'type', $tab, uwp_get_account_page_url() );
644
+    if (getpaid_is_userswp_integration_active() && isset($our_tabs[$tab])) {
645
+        return add_query_arg('type', $tab, uwp_get_account_page_url());
646 646
     }
647 647
 
648 648
     return $url;
649 649
 
650 650
 }
651
-add_filter( 'wpinv_get_history_page_uri', 'getpaid_userswp_overwrite_invoice_history_page', 10, 2 );
651
+add_filter('wpinv_get_history_page_uri', 'getpaid_userswp_overwrite_invoice_history_page', 10, 2);
652 652
 
653 653
 /**
654 654
  * Checks if the integration is enabled.
@@ -657,8 +657,8 @@  discard block
 block discarded – undo
657 657
  * @return bool
658 658
  */
659 659
 function getpaid_is_userswp_integration_active() {
660
-    $enabled = wpinv_get_option( 'enable_userswp', 1 );
661
-    return defined( 'USERSWP_PLUGIN_FILE' ) && ! empty( $enabled );
660
+    $enabled = wpinv_get_option('enable_userswp', 1);
661
+    return defined('USERSWP_PLUGIN_FILE') && !empty($enabled);
662 662
 }
663 663
 
664 664
 /*
@@ -676,26 +676,26 @@  discard block
 block discarded – undo
676 676
  * @param  array $settings An array of integration settings.
677 677
  * @return array
678 678
  */
679
-function getpaid_register_buddypress_settings( $settings ) {
679
+function getpaid_register_buddypress_settings($settings) {
680 680
 
681
-    if ( class_exists( 'BuddyPress' ) ) {
681
+    if (class_exists('BuddyPress')) {
682 682
 
683 683
         $settings[] = array(
684 684
 
685 685
             'id'       => 'buddypress',
686
-            'label'    => __( 'BuddyPress', 'invoicing' ),
686
+            'label'    => __('BuddyPress', 'invoicing'),
687 687
             'settings' => array(
688 688
 
689 689
                 'buddypress_settings' => array(
690 690
                     'id'   => 'buddypress_settings',
691
-                    'name' => '<h3>' . __( 'BuddyPress', 'invoicing' ) . '</h3>',
691
+                    'name' => '<h3>' . __('BuddyPress', 'invoicing') . '</h3>',
692 692
                     'type' => 'header',
693 693
                 ),
694 694
 
695 695
                 'enable_buddypress'   => array(
696 696
                     'id'   => 'enable_buddypress',
697
-                    'name' => __( 'Enable Integration', 'invoicing' ),
698
-                    'desc' => __( 'Display GetPaid items on BuddyPress account pages.', 'invoicing' ),
697
+                    'name' => __('Enable Integration', 'invoicing'),
698
+                    'desc' => __('Display GetPaid items on BuddyPress account pages.', 'invoicing'),
699 699
                     'type' => 'checkbox',
700 700
                     'std'  => 1,
701 701
                 ),
@@ -708,7 +708,7 @@  discard block
 block discarded – undo
708 708
 
709 709
     return $settings;
710 710
 }
711
-add_filter( 'getpaid_integration_settings', 'getpaid_register_buddypress_settings' );
711
+add_filter('getpaid_integration_settings', 'getpaid_register_buddypress_settings');
712 712
 
713 713
 /**
714 714
  * Checks if the integration is enabled.
@@ -717,8 +717,8 @@  discard block
 block discarded – undo
717 717
  * @return bool
718 718
  */
719 719
 function getpaid_is_buddypress_integration_active() {
720
-    $enabled = wpinv_get_option( 'enable_buddypress', 1 );
721
-    return class_exists( 'BuddyPress' ) && ! empty( $enabled );
720
+    $enabled = wpinv_get_option('enable_buddypress', 1);
721
+    return class_exists('BuddyPress') && !empty($enabled);
722 722
 }
723 723
 
724 724
 /**
@@ -729,13 +729,13 @@  discard block
 block discarded – undo
729 729
  */
730 730
 function getpaid_setup_buddypress_integration() {
731 731
 
732
-    if ( getpaid_is_buddypress_integration_active() ) {
732
+    if (getpaid_is_buddypress_integration_active()) {
733 733
         require_once WPINV_PLUGIN_DIR . 'includes/class-bp-getpaid-component.php';
734 734
         buddypress()->getpaid = new BP_GetPaid_Component();
735 735
     }
736 736
 
737 737
 }
738
-add_action( 'bp_setup_components', 'getpaid_setup_buddypress_integration' );
738
+add_action('bp_setup_components', 'getpaid_setup_buddypress_integration');
739 739
 
740 740
 /**
741 741
  * Checks if a given user has purchased a given item.
@@ -744,10 +744,10 @@  discard block
 block discarded – undo
744 744
  * @param int $item_id The item id.
745 745
  * @return int The IDs of users who purchased the item.
746 746
  */
747
-function getpaid_user_ids_who_purchased_item( $item_id ) {
747
+function getpaid_user_ids_who_purchased_item($item_id) {
748 748
     global $wpdb;
749 749
 
750
-    if ( empty( $item_id ) ) {
750
+    if (empty($item_id)) {
751 751
         return false;
752 752
     }
753 753
 
@@ -760,7 +760,7 @@  discard block
 block discarded – undo
760 760
         )
761 761
     );
762 762
 
763
-    return wp_parse_id_list( $ids );
763
+    return wp_parse_id_list($ids);
764 764
 }
765 765
 
766 766
 /**
@@ -769,10 +769,10 @@  discard block
 block discarded – undo
769 769
  * @since 2.6.17
770 770
  * @param int $user_id The user id.
771 771
  */
772
-function getpaid_has_user_purchased_item( $user_id, $item_id ) {
772
+function getpaid_has_user_purchased_item($user_id, $item_id) {
773 773
     global $wpdb;
774 774
 
775
-    if ( empty( $user_id ) ) {
775
+    if (empty($user_id)) {
776 776
         return false;
777 777
     }
778 778
 
@@ -787,7 +787,7 @@  discard block
 block discarded – undo
787 787
         )
788 788
     );
789 789
 
790
-    return ! empty( $count );
790
+    return !empty($count);
791 791
 }
792 792
 
793 793
 /**
@@ -796,7 +796,7 @@  discard block
 block discarded – undo
796 796
  * @since 2.6.17
797 797
  * @param int $user_id The user id.
798 798
  */
799
-function getpaid_get_user_total_spend( $user_id ) {
799
+function getpaid_get_user_total_spend($user_id) {
800 800
     $args = array(
801 801
         'data'           => array(
802 802
 
@@ -811,17 +811,17 @@  discard block
 block discarded – undo
811 811
 
812 812
             'author' => array(
813 813
                 'type'     => 'post_data',
814
-                'value'    => absint( $user_id ),
814
+                'value'    => absint($user_id),
815 815
                 'key'      => 'posts.post_author',
816 816
                 'operator' => '=',
817 817
             ),
818 818
 
819 819
         ),
820 820
         'query_type'     => 'get_var',
821
-        'invoice_status' => array( 'wpi-renewal', 'wpi-processing', 'publish' ),
821
+        'invoice_status' => array('wpi-renewal', 'wpi-processing', 'publish'),
822 822
     );
823 823
 
824
-    return wpinv_round_amount( GetPaid_Reports_Helper::get_invoice_report_data( $args ) );
824
+    return wpinv_round_amount(GetPaid_Reports_Helper::get_invoice_report_data($args));
825 825
 }
826 826
 
827 827
 /**
@@ -830,7 +830,7 @@  discard block
 block discarded – undo
830 830
  * @since 2.6.17
831 831
  * @param int $user_id The user id.
832 832
  */
833
-function getpaid_count_user_invoices( $user_id ) {
833
+function getpaid_count_user_invoices($user_id) {
834 834
     $args = array(
835 835
         'data'           => array(
836 836
 
@@ -846,15 +846,15 @@  discard block
 block discarded – undo
846 846
 
847 847
             'author' => array(
848 848
                 'type'     => 'post_data',
849
-                'value'    => absint( $user_id ),
849
+                'value'    => absint($user_id),
850 850
                 'key'      => 'posts.post_author',
851 851
                 'operator' => '=',
852 852
             ),
853 853
 
854 854
         ),
855 855
         'query_type'     => 'get_var',
856
-        'invoice_status' => array_keys( wpinv_get_invoice_statuses() ),
856
+        'invoice_status' => array_keys(wpinv_get_invoice_statuses()),
857 857
     );
858 858
 
859
-    return absint( GetPaid_Reports_Helper::get_invoice_report_data( $args ) );
859
+    return absint(GetPaid_Reports_Helper::get_invoice_report_data($args));
860 860
 }
Please login to merge, or discard this patch.
includes/class-getpaid-customer.php 2 patches
Indentation   +176 added lines, -176 removed lines patch added patch discarded remove patch
@@ -15,69 +15,69 @@  discard block
 block discarded – undo
15 15
  */
16 16
 class GetPaid_Customer extends GetPaid_Data {
17 17
 
18
-	/**
19
-	 * Which data store to load.
20
-	 *
21
-	 * @var string
22
-	 */
18
+    /**
19
+     * Which data store to load.
20
+     *
21
+     * @var string
22
+     */
23 23
     protected $data_store_name = 'customer';
24 24
 
25 25
     /**
26
-	 * This is the name of this object type.
27
-	 *
28
-	 * @var string
29
-	 */
30
-	protected $object_type = 'customer';
31
-
32
-	/**
33
-	 * Get the customer if ID is passed, otherwise the customer is new and empty.
34
-	 *
35
-	 * @param int|string|GetPaid_Customer|object $customer customer id, object, or email.
36
-	 */
37
-	public function __construct( $customer = 0 ) {
26
+     * This is the name of this object type.
27
+     *
28
+     * @var string
29
+     */
30
+    protected $object_type = 'customer';
31
+
32
+    /**
33
+     * Get the customer if ID is passed, otherwise the customer is new and empty.
34
+     *
35
+     * @param int|string|GetPaid_Customer|object $customer customer id, object, or email.
36
+     */
37
+    public function __construct( $customer = 0 ) {
38 38
 
39 39
         // Setup default customer data.
40 40
         $this->setup_default_data();
41 41
 
42
-		if ( is_numeric( $customer ) ) {
43
-			$this->set_id( $customer );
44
-		} elseif ( $customer instanceof self ) {
45
-			$this->set_id( $customer->get_id() );
46
-		} elseif ( is_string( $customer ) && $customer_id = self::get_customer_id_by( $customer, 'email' ) ) {
47
-			$this->set_id( $customer_id );
48
-		} elseif ( ! empty( $customer->id ) ) {
49
-			$this->set_id( $customer->id );
50
-		}
42
+        if ( is_numeric( $customer ) ) {
43
+            $this->set_id( $customer );
44
+        } elseif ( $customer instanceof self ) {
45
+            $this->set_id( $customer->get_id() );
46
+        } elseif ( is_string( $customer ) && $customer_id = self::get_customer_id_by( $customer, 'email' ) ) {
47
+            $this->set_id( $customer_id );
48
+        } elseif ( ! empty( $customer->id ) ) {
49
+            $this->set_id( $customer->id );
50
+        }
51 51
 
52 52
         // Load the datastore.
53
-		$this->data_store = GetPaid_Data_Store::load( $this->data_store_name );
53
+        $this->data_store = GetPaid_Data_Store::load( $this->data_store_name );
54 54
 
55
-		if ( $this->get_id() > 0 ) {
56
-			$this->data_store->read( $this );
55
+        if ( $this->get_id() > 0 ) {
56
+            $this->data_store->read( $this );
57 57
         }
58 58
 
59 59
         $this->set_object_read( true );
60
-	}
60
+    }
61 61
 
62 62
     /**
63
-	 * Sets up default customer data.
64
-	 */
65
-	private function setup_default_data() {
63
+     * Sets up default customer data.
64
+     */
65
+    private function setup_default_data() {
66 66
 
67 67
         $this->data = array(
68
-			'user_id'        => 0,
69
-			'email'          => '',
70
-			'email_cc'       => '',
71
-			'status'         => 'active',
72
-			'purchase_value' => 0,
73
-			'purchase_count' => 0,
74
-			'date_created'   => current_time( 'mysql' ),
75
-			'date_modified'  => current_time( 'mysql' ),
76
-			'uuid'           => wp_generate_uuid4(),
77
-		);
68
+            'user_id'        => 0,
69
+            'email'          => '',
70
+            'email_cc'       => '',
71
+            'status'         => 'active',
72
+            'purchase_value' => 0,
73
+            'purchase_count' => 0,
74
+            'date_created'   => current_time( 'mysql' ),
75
+            'date_modified'  => current_time( 'mysql' ),
76
+            'uuid'           => wp_generate_uuid4(),
77
+        );
78 78
 
79 79
         // Add address fields.
80
-		foreach ( array_keys( getpaid_user_address_fields() ) as $field ) {
80
+        foreach ( array_keys( getpaid_user_address_fields() ) as $field ) {
81 81
 
82 82
             if ( isset( $this->data[ $field ] ) ) {
83 83
                 continue;
@@ -95,22 +95,22 @@  discard block
 block discarded – undo
95 95
                 continue;
96 96
             }
97 97
 
98
-			$this->data[ $field ] = '';
99
-		}
98
+            $this->data[ $field ] = '';
99
+        }
100 100
 
101 101
         $this->default_data = $this->data;
102
-	}
103
-
104
-	/**
105
-	 * Given a customer email or user id, it returns a customer id.
106
-	 *
107
-	 * @static
108
-	 * @param string $value
109
-	 * @since 1.0.15
110
-	 * @return int
111
-	 */
112
-	public static function get_customer_id_by( $value, $by = 'email' ) {
113
-		global $wpdb;
102
+    }
103
+
104
+    /**
105
+     * Given a customer email or user id, it returns a customer id.
106
+     *
107
+     * @static
108
+     * @param string $value
109
+     * @since 1.0.15
110
+     * @return int
111
+     */
112
+    public static function get_customer_id_by( $value, $by = 'email' ) {
113
+        global $wpdb;
114 114
 
115 115
         // Prepare value.
116 116
         if ( 'email' === $by ) {
@@ -125,12 +125,12 @@  discard block
 block discarded – undo
125 125
             return 0;
126 126
         }
127 127
 
128
-		// Maybe retrieve from the cache.
128
+        // Maybe retrieve from the cache.
129 129
         $cache_key   = 'getpaid_customer_ids_by_' . $by;
130
-		$customer_id = wp_cache_get( $value, $cache_key );
131
-		if ( false !== $customer_id ) {
132
-			return $customer_id;
133
-		}
130
+        $customer_id = wp_cache_get( $value, $cache_key );
131
+        if ( false !== $customer_id ) {
132
+            return $customer_id;
133
+        }
134 134
 
135 135
         if ( 'email' === $by ) {
136 136
             $customer_id = (int) $wpdb->get_var(
@@ -142,23 +142,23 @@  discard block
 block discarded – undo
142 142
             );
143 143
         }
144 144
 
145
-		// Update the cache with our data
146
-		wp_cache_set( $value, $customer_id, $cache_key );
145
+        // Update the cache with our data
146
+        wp_cache_set( $value, $customer_id, $cache_key );
147 147
 
148
-		return $customer_id;
148
+        return $customer_id;
149 149
 
150
-	}
150
+    }
151 151
 
152
-	/**
152
+    /**
153 153
      * Clears the customer's cache.
154 154
      */
155 155
     public function clear_cache() {
156 156
         wp_cache_delete( $this->get( 'email' ), 'getpaid_customer_ids_by_email' );
157 157
         wp_cache_delete( $this->get( 'user_id' ), 'getpaid_customer_ids_by_user_id' );
158
-		wp_cache_delete( $this->get_id(), 'getpaid_customers' );
159
-	}
158
+        wp_cache_delete( $this->get_id(), 'getpaid_customers' );
159
+    }
160 160
 
161
-	/*
161
+    /*
162 162
 	|--------------------------------------------------------------------------
163 163
 	| CRUD methods
164 164
 	|--------------------------------------------------------------------------
@@ -189,11 +189,11 @@  discard block
 block discarded – undo
189 189
             return call_user_func( array( $this, 'get_' . $key ), $context );
190 190
         }
191 191
 
192
-		return $this->get_prop( $key, $context );
192
+        return $this->get_prop( $key, $context );
193 193
 
194 194
     }
195 195
 
196
-	/*
196
+    /*
197 197
 	|--------------------------------------------------------------------------
198 198
 	| Setters
199 199
 	|--------------------------------------------------------------------------
@@ -216,114 +216,114 @@  discard block
 block discarded – undo
216 216
             return call_user_func( array( $this, 'set_' . $key ), $value );
217 217
         }
218 218
 
219
-		return $this->set_prop( $key, $value );
219
+        return $this->set_prop( $key, $value );
220 220
 
221 221
     }
222 222
 
223
-	/**
224
-	 * Sets customer status.
225
-	 *
226
-	 * @since 1.0.0
227
-	 * @param  string $status New status.
228
-	 */
229
-	public function set_status( $status ) {
230
-
231
-		if ( in_array( $status, array( 'active', 'inactive', 'blocked' ), true ) ) {
232
-			return $this->set_prop( 'status', $status );
233
-		}
234
-
235
-		$this->set_prop( 'status', 'inactive' );
236
-	}
237
-
238
-	/**
239
-	 * Sets the purchase value.
240
-	 *
241
-	 * @since 1.0.0
242
-	 * @param float $purchase_value.
243
-	 */
244
-	public function set_purchase_value( $purchase_value ) {
245
-		$this->set_prop( 'purchase_value', (float) $purchase_value );
246
-	}
223
+    /**
224
+     * Sets customer status.
225
+     *
226
+     * @since 1.0.0
227
+     * @param  string $status New status.
228
+     */
229
+    public function set_status( $status ) {
230
+
231
+        if ( in_array( $status, array( 'active', 'inactive', 'blocked' ), true ) ) {
232
+            return $this->set_prop( 'status', $status );
233
+        }
234
+
235
+        $this->set_prop( 'status', 'inactive' );
236
+    }
237
+
238
+    /**
239
+     * Sets the purchase value.
240
+     *
241
+     * @since 1.0.0
242
+     * @param float $purchase_value.
243
+     */
244
+    public function set_purchase_value( $purchase_value ) {
245
+        $this->set_prop( 'purchase_value', (float) $purchase_value );
246
+    }
247 247
 
248 248
     /**
249
-	 * Sets the purchase count.
250
-	 *
251
-	 * @since 1.0.0
252
-	 * @param int $purchase_count.
253
-	 */
254
-	public function set_purchase_count( $purchase_count ) {
255
-		$this->set_prop( 'purchase_count', absint( $purchase_count ) );
256
-	}
249
+     * Sets the purchase count.
250
+     *
251
+     * @since 1.0.0
252
+     * @param int $purchase_count.
253
+     */
254
+    public function set_purchase_count( $purchase_count ) {
255
+        $this->set_prop( 'purchase_count', absint( $purchase_count ) );
256
+    }
257 257
 
258 258
     /**
259
-	 * Sets the user id.
260
-	 *
261
-	 * @since 1.0.0
262
-	 * @param int $user_id.
263
-	 */
264
-	public function set_user_id( $user_id ) {
265
-		$this->set_prop( 'user_id', absint( $user_id ) );
266
-	}
259
+     * Sets the user id.
260
+     *
261
+     * @since 1.0.0
262
+     * @param int $user_id.
263
+     */
264
+    public function set_user_id( $user_id ) {
265
+        $this->set_prop( 'user_id', absint( $user_id ) );
266
+    }
267 267
 
268 268
     /**
269
-	 * Sets the email.
270
-	 *
271
-	 * @since 1.0.0
272
-	 * @param string $email.
273
-	 */
274
-	public function set_email( $email ) {
269
+     * Sets the email.
270
+     *
271
+     * @since 1.0.0
272
+     * @param string $email.
273
+     */
274
+    public function set_email( $email ) {
275 275
         $email = is_string( $email ) ? sanitize_email( $email ) : '';
276
-		$this->set_prop( 'email', $email );
277
-	}
276
+        $this->set_prop( 'email', $email );
277
+    }
278 278
 
279 279
     /**
280
-	 * Sets the email cc.
281
-	 *
282
-	 * @since 1.0.0
283
-	 * @param string $email_cc.
284
-	 */
285
-	public function set_email_cc( $email_cc ) {
280
+     * Sets the email cc.
281
+     *
282
+     * @since 1.0.0
283
+     * @param string $email_cc.
284
+     */
285
+    public function set_email_cc( $email_cc ) {
286 286
         $email_cc = implode( ', ', wp_parse_list( $email_cc ) );
287
-		$this->set_prop( 'email_cc', $email_cc );
288
-	}
287
+        $this->set_prop( 'email_cc', $email_cc );
288
+    }
289 289
 
290 290
     /**
291
-	 * Sets the created date.
292
-	 *
293
-	 * @since 1.0.0
294
-	 * @param  string $date_created date created.
295
-	 */
296
-	public function set_date_created( $date_created ) {
291
+     * Sets the created date.
292
+     *
293
+     * @since 1.0.0
294
+     * @param  string $date_created date created.
295
+     */
296
+    public function set_date_created( $date_created ) {
297 297
 
298
-		$date = strtotime( $date_created );
298
+        $date = strtotime( $date_created );
299 299
 
300 300
         if ( $date && $date_created !== '0000-00-00 00:00:00'  && $date_created !== '0000-00-00 00:00' ) {
301 301
             $this->set_prop( 'date_created', gmdate( 'Y-m-d H:i:s', $date ) );
302 302
             return;
303
-		}
303
+        }
304 304
 
305
-		$this->set_prop( 'date_created', null );
306
-	}
305
+        $this->set_prop( 'date_created', null );
306
+    }
307 307
 
308 308
     /**
309
-	 * Sets the created date.
310
-	 *
311
-	 * @since 1.0.0
312
-	 * @param  string $date_modified date created.
313
-	 */
314
-	public function set_date_modified( $date_modified ) {
309
+     * Sets the created date.
310
+     *
311
+     * @since 1.0.0
312
+     * @param  string $date_modified date created.
313
+     */
314
+    public function set_date_modified( $date_modified ) {
315 315
 
316
-		$date = strtotime( $date_modified );
316
+        $date = strtotime( $date_modified );
317 317
 
318 318
         if ( $date && $date_modified !== '0000-00-00 00:00:00'  && $date_modified !== '0000-00-00 00:00' ) {
319 319
             $this->set_prop( 'date_modified', gmdate( 'Y-m-d H:i:s', $date ) );
320 320
             return;
321
-		}
321
+        }
322 322
 
323
-		$this->set_prop( 'date_modified', null );
324
-	}
323
+        $this->set_prop( 'date_modified', null );
324
+    }
325 325
 
326
-	/*
326
+    /*
327 327
 	|--------------------------------------------------------------------------
328 328
 	| Additional methods
329 329
 	|--------------------------------------------------------------------------
@@ -332,12 +332,12 @@  discard block
 block discarded – undo
332 332
 	|
333 333
 	*/
334 334
 
335
-	/**
336
-	 * Saves the customer.
337
-	 *
338
-	 * @since 1.0.0
339
-	 */
340
-	public function save() {
335
+    /**
336
+     * Saves the customer.
337
+     *
338
+     * @since 1.0.0
339
+     */
340
+    public function save() {
341 341
 
342 342
         $maybe_set = array(
343 343
             'uuid'         => wp_generate_uuid4(),
@@ -354,29 +354,29 @@  discard block
 block discarded – undo
354 354
 
355 355
         $this->set( 'date_modified', current_time( 'mysql' ) );
356 356
 
357
-		return parent::save();
358
-	}
357
+        return parent::save();
358
+    }
359 359
 
360 360
     /**
361
-	 * Helper method to clone a customer from a user ID.
362
-	 *
363
-	 * @since 1.0.0
364
-	 * @param int $user_id.
365
-	 */
366
-	public function clone_user( $user_id ) {
361
+     * Helper method to clone a customer from a user ID.
362
+     *
363
+     * @since 1.0.0
364
+     * @param int $user_id.
365
+     */
366
+    public function clone_user( $user_id ) {
367 367
         $user = get_userdata( $user_id );
368 368
 
369 369
         if ( empty( $user ) ) {
370 370
             return;
371 371
         }
372 372
 
373
-		$this->set_user_id( $user->ID );
373
+        $this->set_user_id( $user->ID );
374 374
         $this->set_email( $user->user_email );
375 375
         $this->set_purchase_value( getpaid_get_user_total_spend( $user->ID ) );
376 376
         $this->set_purchase_count( getpaid_count_user_invoices( $user->ID ) );
377 377
         $this->set( 'first_name', $user->first_name );
378 378
         $this->set( 'last_name', $user->last_name );
379
-		$this->set_date_created( $user->user_registered );
379
+        $this->set_date_created( $user->user_registered );
380 380
 
381 381
         // Fetch extra data from WC or old GetPaid.
382 382
         $prefixes = array(
@@ -400,18 +400,18 @@  discard block
 block discarded – undo
400 400
                     continue;
401 401
                 }
402 402
             }
403
-		}
404
-	}
403
+        }
404
+    }
405 405
 
406 406
     /**
407
-	 * Helper method to migrate an existing user ID to the new customers table.
408
-	 *
409
-	 * @since 1.0.0
410
-	 * @param int $user_id.
411
-	 */
412
-	public function migrate_from_user( $user_id ) {
407
+     * Helper method to migrate an existing user ID to the new customers table.
408
+     *
409
+     * @since 1.0.0
410
+     * @param int $user_id.
411
+     */
412
+    public function migrate_from_user( $user_id ) {
413 413
         $this->clone_user( $user_id );
414 414
         do_action( 'getpaid_customer_migrated_from_user', $this, $user_id );
415 415
         $this->save();
416
-	}
416
+    }
417 417
 }
Please login to merge, or discard this patch.
Spacing   +100 added lines, -100 removed lines patch added patch discarded remove patch
@@ -5,7 +5,7 @@  discard block
 block discarded – undo
5 5
  * @since   1.0.15
6 6
  */
7 7
 
8
-defined( 'ABSPATH' ) || exit;
8
+defined('ABSPATH') || exit;
9 9
 
10 10
 /**
11 11
  * Customer class.
@@ -34,29 +34,29 @@  discard block
 block discarded – undo
34 34
 	 *
35 35
 	 * @param int|string|GetPaid_Customer|object $customer customer id, object, or email.
36 36
 	 */
37
-	public function __construct( $customer = 0 ) {
37
+	public function __construct($customer = 0) {
38 38
 
39 39
         // Setup default customer data.
40 40
         $this->setup_default_data();
41 41
 
42
-		if ( is_numeric( $customer ) ) {
43
-			$this->set_id( $customer );
44
-		} elseif ( $customer instanceof self ) {
45
-			$this->set_id( $customer->get_id() );
46
-		} elseif ( is_string( $customer ) && $customer_id = self::get_customer_id_by( $customer, 'email' ) ) {
47
-			$this->set_id( $customer_id );
48
-		} elseif ( ! empty( $customer->id ) ) {
49
-			$this->set_id( $customer->id );
42
+		if (is_numeric($customer)) {
43
+			$this->set_id($customer);
44
+		} elseif ($customer instanceof self) {
45
+			$this->set_id($customer->get_id());
46
+		} elseif (is_string($customer) && $customer_id = self::get_customer_id_by($customer, 'email')) {
47
+			$this->set_id($customer_id);
48
+		} elseif (!empty($customer->id)) {
49
+			$this->set_id($customer->id);
50 50
 		}
51 51
 
52 52
         // Load the datastore.
53
-		$this->data_store = GetPaid_Data_Store::load( $this->data_store_name );
53
+		$this->data_store = GetPaid_Data_Store::load($this->data_store_name);
54 54
 
55
-		if ( $this->get_id() > 0 ) {
56
-			$this->data_store->read( $this );
55
+		if ($this->get_id() > 0) {
56
+			$this->data_store->read($this);
57 57
         }
58 58
 
59
-        $this->set_object_read( true );
59
+        $this->set_object_read(true);
60 60
 	}
61 61
 
62 62
     /**
@@ -71,31 +71,31 @@  discard block
 block discarded – undo
71 71
 			'status'         => 'active',
72 72
 			'purchase_value' => 0,
73 73
 			'purchase_count' => 0,
74
-			'date_created'   => current_time( 'mysql' ),
75
-			'date_modified'  => current_time( 'mysql' ),
74
+			'date_created'   => current_time('mysql'),
75
+			'date_modified'  => current_time('mysql'),
76 76
 			'uuid'           => wp_generate_uuid4(),
77 77
 		);
78 78
 
79 79
         // Add address fields.
80
-		foreach ( array_keys( getpaid_user_address_fields() ) as $field ) {
80
+		foreach (array_keys(getpaid_user_address_fields()) as $field) {
81 81
 
82
-            if ( isset( $this->data[ $field ] ) ) {
82
+            if (isset($this->data[$field])) {
83 83
                 continue;
84 84
             }
85 85
 
86 86
             // Country.
87
-            if ( 'country' === $field ) {
88
-                $this->data[ $field ] = wpinv_get_default_country();
87
+            if ('country' === $field) {
88
+                $this->data[$field] = wpinv_get_default_country();
89 89
                 continue;
90 90
             }
91 91
 
92 92
             // State.
93
-            if ( 'state' === $field ) {
94
-                $this->data[ $field ] = wpinv_get_default_state();
93
+            if ('state' === $field) {
94
+                $this->data[$field] = wpinv_get_default_state();
95 95
                 continue;
96 96
             }
97 97
 
98
-			$this->data[ $field ] = '';
98
+			$this->data[$field] = '';
99 99
 		}
100 100
 
101 101
         $this->default_data = $this->data;
@@ -109,41 +109,41 @@  discard block
 block discarded – undo
109 109
 	 * @since 1.0.15
110 110
 	 * @return int
111 111
 	 */
112
-	public static function get_customer_id_by( $value, $by = 'email' ) {
112
+	public static function get_customer_id_by($value, $by = 'email') {
113 113
 		global $wpdb;
114 114
 
115 115
         // Prepare value.
116
-        if ( 'email' === $by ) {
117
-            $value = sanitize_email( $value );
118
-        } elseif ( 'user_id' === $by ) {
119
-            $value = absint( $value );
116
+        if ('email' === $by) {
117
+            $value = sanitize_email($value);
118
+        } elseif ('user_id' === $by) {
119
+            $value = absint($value);
120 120
         } else {
121 121
             return 0;
122 122
         }
123 123
 
124
-        if ( empty( $value ) ) {
124
+        if (empty($value)) {
125 125
             return 0;
126 126
         }
127 127
 
128 128
 		// Maybe retrieve from the cache.
129
-        $cache_key   = 'getpaid_customer_ids_by_' . $by;
130
-		$customer_id = wp_cache_get( $value, $cache_key );
131
-		if ( false !== $customer_id ) {
129
+        $cache_key = 'getpaid_customer_ids_by_' . $by;
130
+		$customer_id = wp_cache_get($value, $cache_key);
131
+		if (false !== $customer_id) {
132 132
 			return $customer_id;
133 133
 		}
134 134
 
135
-        if ( 'email' === $by ) {
135
+        if ('email' === $by) {
136 136
             $customer_id = (int) $wpdb->get_var(
137
-                $wpdb->prepare( "SELECT id FROM {$wpdb->prefix}getpaid_customers WHERE email=%s LIMIT 1", $value )
137
+                $wpdb->prepare("SELECT id FROM {$wpdb->prefix}getpaid_customers WHERE email=%s LIMIT 1", $value)
138 138
             );
139
-        } elseif ( 'user_id' === $by ) {
139
+        } elseif ('user_id' === $by) {
140 140
             $customer_id = (int) $wpdb->get_var(
141
-                $wpdb->prepare( "SELECT id FROM {$wpdb->prefix}getpaid_customers WHERE user_id=%d LIMIT 1", $value )
141
+                $wpdb->prepare("SELECT id FROM {$wpdb->prefix}getpaid_customers WHERE user_id=%d LIMIT 1", $value)
142 142
             );
143 143
         }
144 144
 
145 145
 		// Update the cache with our data
146
-		wp_cache_set( $value, $customer_id, $cache_key );
146
+		wp_cache_set($value, $customer_id, $cache_key);
147 147
 
148 148
 		return $customer_id;
149 149
 
@@ -153,9 +153,9 @@  discard block
 block discarded – undo
153 153
      * Clears the customer's cache.
154 154
      */
155 155
     public function clear_cache() {
156
-        wp_cache_delete( $this->get( 'email' ), 'getpaid_customer_ids_by_email' );
157
-        wp_cache_delete( $this->get( 'user_id' ), 'getpaid_customer_ids_by_user_id' );
158
-		wp_cache_delete( $this->get_id(), 'getpaid_customers' );
156
+        wp_cache_delete($this->get('email'), 'getpaid_customer_ids_by_email');
157
+        wp_cache_delete($this->get('user_id'), 'getpaid_customer_ids_by_user_id');
158
+		wp_cache_delete($this->get_id(), 'getpaid_customers');
159 159
 	}
160 160
 
161 161
 	/*
@@ -179,17 +179,17 @@  discard block
 block discarded – undo
179 179
      * @param  string $key The key to fetch.
180 180
      * @param  string $context View or edit context.
181 181
      */
182
-    public function get( $key, $context = 'view' ) {
182
+    public function get($key, $context = 'view') {
183 183
 
184 184
         // Maybe strip _wpinv_ prefix from key.
185
-        $key = str_replace( '_wpinv_', '', $key );
185
+        $key = str_replace('_wpinv_', '', $key);
186 186
 
187 187
         // Check if we have a helper method for that.
188
-        if ( method_exists( $this, 'get_' . $key ) ) {
189
-            return call_user_func( array( $this, 'get_' . $key ), $context );
188
+        if (method_exists($this, 'get_' . $key)) {
189
+            return call_user_func(array($this, 'get_' . $key), $context);
190 190
         }
191 191
 
192
-		return $this->get_prop( $key, $context );
192
+		return $this->get_prop($key, $context);
193 193
 
194 194
     }
195 195
 
@@ -209,14 +209,14 @@  discard block
 block discarded – undo
209 209
      * @param string $key The key to fetch.
210 210
      * @param mixed $value The new value.
211 211
      */
212
-    public function set( $key, $value ) {
212
+    public function set($key, $value) {
213 213
 
214 214
         // Check if we have a helper method for that.
215
-        if ( method_exists( $this, 'set_' . $key ) ) {
216
-            return call_user_func( array( $this, 'set_' . $key ), $value );
215
+        if (method_exists($this, 'set_' . $key)) {
216
+            return call_user_func(array($this, 'set_' . $key), $value);
217 217
         }
218 218
 
219
-		return $this->set_prop( $key, $value );
219
+		return $this->set_prop($key, $value);
220 220
 
221 221
     }
222 222
 
@@ -226,13 +226,13 @@  discard block
 block discarded – undo
226 226
 	 * @since 1.0.0
227 227
 	 * @param  string $status New status.
228 228
 	 */
229
-	public function set_status( $status ) {
229
+	public function set_status($status) {
230 230
 
231
-		if ( in_array( $status, array( 'active', 'inactive', 'blocked' ), true ) ) {
232
-			return $this->set_prop( 'status', $status );
231
+		if (in_array($status, array('active', 'inactive', 'blocked'), true)) {
232
+			return $this->set_prop('status', $status);
233 233
 		}
234 234
 
235
-		$this->set_prop( 'status', 'inactive' );
235
+		$this->set_prop('status', 'inactive');
236 236
 	}
237 237
 
238 238
 	/**
@@ -241,8 +241,8 @@  discard block
 block discarded – undo
241 241
 	 * @since 1.0.0
242 242
 	 * @param float $purchase_value.
243 243
 	 */
244
-	public function set_purchase_value( $purchase_value ) {
245
-		$this->set_prop( 'purchase_value', (float) $purchase_value );
244
+	public function set_purchase_value($purchase_value) {
245
+		$this->set_prop('purchase_value', (float) $purchase_value);
246 246
 	}
247 247
 
248 248
     /**
@@ -251,8 +251,8 @@  discard block
 block discarded – undo
251 251
 	 * @since 1.0.0
252 252
 	 * @param int $purchase_count.
253 253
 	 */
254
-	public function set_purchase_count( $purchase_count ) {
255
-		$this->set_prop( 'purchase_count', absint( $purchase_count ) );
254
+	public function set_purchase_count($purchase_count) {
255
+		$this->set_prop('purchase_count', absint($purchase_count));
256 256
 	}
257 257
 
258 258
     /**
@@ -261,8 +261,8 @@  discard block
 block discarded – undo
261 261
 	 * @since 1.0.0
262 262
 	 * @param int $user_id.
263 263
 	 */
264
-	public function set_user_id( $user_id ) {
265
-		$this->set_prop( 'user_id', absint( $user_id ) );
264
+	public function set_user_id($user_id) {
265
+		$this->set_prop('user_id', absint($user_id));
266 266
 	}
267 267
 
268 268
     /**
@@ -271,9 +271,9 @@  discard block
 block discarded – undo
271 271
 	 * @since 1.0.0
272 272
 	 * @param string $email.
273 273
 	 */
274
-	public function set_email( $email ) {
275
-        $email = is_string( $email ) ? sanitize_email( $email ) : '';
276
-		$this->set_prop( 'email', $email );
274
+	public function set_email($email) {
275
+        $email = is_string($email) ? sanitize_email($email) : '';
276
+		$this->set_prop('email', $email);
277 277
 	}
278 278
 
279 279
     /**
@@ -282,9 +282,9 @@  discard block
 block discarded – undo
282 282
 	 * @since 1.0.0
283 283
 	 * @param string $email_cc.
284 284
 	 */
285
-	public function set_email_cc( $email_cc ) {
286
-        $email_cc = implode( ', ', wp_parse_list( $email_cc ) );
287
-		$this->set_prop( 'email_cc', $email_cc );
285
+	public function set_email_cc($email_cc) {
286
+        $email_cc = implode(', ', wp_parse_list($email_cc));
287
+		$this->set_prop('email_cc', $email_cc);
288 288
 	}
289 289
 
290 290
     /**
@@ -293,16 +293,16 @@  discard block
 block discarded – undo
293 293
 	 * @since 1.0.0
294 294
 	 * @param  string $date_created date created.
295 295
 	 */
296
-	public function set_date_created( $date_created ) {
296
+	public function set_date_created($date_created) {
297 297
 
298
-		$date = strtotime( $date_created );
298
+		$date = strtotime($date_created);
299 299
 
300
-        if ( $date && $date_created !== '0000-00-00 00:00:00'  && $date_created !== '0000-00-00 00:00' ) {
301
-            $this->set_prop( 'date_created', gmdate( 'Y-m-d H:i:s', $date ) );
300
+        if ($date && $date_created !== '0000-00-00 00:00:00' && $date_created !== '0000-00-00 00:00') {
301
+            $this->set_prop('date_created', gmdate('Y-m-d H:i:s', $date));
302 302
             return;
303 303
 		}
304 304
 
305
-		$this->set_prop( 'date_created', null );
305
+		$this->set_prop('date_created', null);
306 306
 	}
307 307
 
308 308
     /**
@@ -311,16 +311,16 @@  discard block
 block discarded – undo
311 311
 	 * @since 1.0.0
312 312
 	 * @param  string $date_modified date created.
313 313
 	 */
314
-	public function set_date_modified( $date_modified ) {
314
+	public function set_date_modified($date_modified) {
315 315
 
316
-		$date = strtotime( $date_modified );
316
+		$date = strtotime($date_modified);
317 317
 
318
-        if ( $date && $date_modified !== '0000-00-00 00:00:00'  && $date_modified !== '0000-00-00 00:00' ) {
319
-            $this->set_prop( 'date_modified', gmdate( 'Y-m-d H:i:s', $date ) );
318
+        if ($date && $date_modified !== '0000-00-00 00:00:00' && $date_modified !== '0000-00-00 00:00') {
319
+            $this->set_prop('date_modified', gmdate('Y-m-d H:i:s', $date));
320 320
             return;
321 321
 		}
322 322
 
323
-		$this->set_prop( 'date_modified', null );
323
+		$this->set_prop('date_modified', null);
324 324
 	}
325 325
 
326 326
 	/*
@@ -341,18 +341,18 @@  discard block
 block discarded – undo
341 341
 
342 342
         $maybe_set = array(
343 343
             'uuid'         => wp_generate_uuid4(),
344
-            'date_created' => current_time( 'mysql' ),
344
+            'date_created' => current_time('mysql'),
345 345
         );
346 346
 
347
-        foreach ( $maybe_set as $key => $value ) {
348
-            $current_value = $this->get( $key );
347
+        foreach ($maybe_set as $key => $value) {
348
+            $current_value = $this->get($key);
349 349
 
350
-            if ( empty( $current_value ) ) {
351
-                $this->set( $key, $value );
350
+            if (empty($current_value)) {
351
+                $this->set($key, $value);
352 352
             }
353 353
         }
354 354
 
355
-        $this->set( 'date_modified', current_time( 'mysql' ) );
355
+        $this->set('date_modified', current_time('mysql'));
356 356
 
357 357
 		return parent::save();
358 358
 	}
@@ -363,20 +363,20 @@  discard block
 block discarded – undo
363 363
 	 * @since 1.0.0
364 364
 	 * @param int $user_id.
365 365
 	 */
366
-	public function clone_user( $user_id ) {
367
-        $user = get_userdata( $user_id );
366
+	public function clone_user($user_id) {
367
+        $user = get_userdata($user_id);
368 368
 
369
-        if ( empty( $user ) ) {
369
+        if (empty($user)) {
370 370
             return;
371 371
         }
372 372
 
373
-		$this->set_user_id( $user->ID );
374
-        $this->set_email( $user->user_email );
375
-        $this->set_purchase_value( getpaid_get_user_total_spend( $user->ID ) );
376
-        $this->set_purchase_count( getpaid_count_user_invoices( $user->ID ) );
377
-        $this->set( 'first_name', $user->first_name );
378
-        $this->set( 'last_name', $user->last_name );
379
-		$this->set_date_created( $user->user_registered );
373
+		$this->set_user_id($user->ID);
374
+        $this->set_email($user->user_email);
375
+        $this->set_purchase_value(getpaid_get_user_total_spend($user->ID));
376
+        $this->set_purchase_count(getpaid_count_user_invoices($user->ID));
377
+        $this->set('first_name', $user->first_name);
378
+        $this->set('last_name', $user->last_name);
379
+		$this->set_date_created($user->user_registered);
380 380
 
381 381
         // Fetch extra data from WC or old GetPaid.
382 382
         $prefixes = array(
@@ -385,18 +385,18 @@  discard block
 block discarded – undo
385 385
             '',
386 386
         );
387 387
 
388
-        foreach ( array_keys( getpaid_user_address_fields() ) as $field ) {
388
+        foreach (array_keys(getpaid_user_address_fields()) as $field) {
389 389
 
390
-            foreach ( $prefixes as $prefix ) {
390
+            foreach ($prefixes as $prefix) {
391 391
 
392 392
                 // Meta table.
393
-                $value = get_user_meta( $user_id, $prefix . $field, true );
393
+                $value = get_user_meta($user_id, $prefix . $field, true);
394 394
 
395 395
                 // UWP table.
396
-                $value = ( empty( $value ) && function_exists( 'uwp_get_usermeta' ) ) ? uwp_get_usermeta( $user_id, $prefix . $field ) : $value;
396
+                $value = (empty($value) && function_exists('uwp_get_usermeta')) ? uwp_get_usermeta($user_id, $prefix . $field) : $value;
397 397
 
398
-                if ( ! empty( $value ) ) {
399
-                    $this->set( $field, $value );
398
+                if (!empty($value)) {
399
+                    $this->set($field, $value);
400 400
                     continue;
401 401
                 }
402 402
             }
@@ -409,9 +409,9 @@  discard block
 block discarded – undo
409 409
 	 * @since 1.0.0
410 410
 	 * @param int $user_id.
411 411
 	 */
412
-	public function migrate_from_user( $user_id ) {
413
-        $this->clone_user( $user_id );
414
-        do_action( 'getpaid_customer_migrated_from_user', $this, $user_id );
412
+	public function migrate_from_user($user_id) {
413
+        $this->clone_user($user_id);
414
+        do_action('getpaid_customer_migrated_from_user', $this, $user_id);
415 415
         $this->save();
416 416
 	}
417 417
 }
Please login to merge, or discard this patch.
includes/payments/class-getpaid-checkout.php 2 patches
Indentation   +309 added lines, -309 removed lines patch added patch discarded remove patch
@@ -12,184 +12,184 @@  discard block
 block discarded – undo
12 12
  */
13 13
 class GetPaid_Checkout {
14 14
 
15
-	/**
16
-	 * @var GetPaid_Payment_Form_Submission
17
-	 */
18
-	protected $payment_form_submission;
19
-
20
-	/**
21
-	 * Class constructor.
22
-	 *
23
-	 * @param GetPaid_Payment_Form_Submission $submission
24
-	 */
25
-	public function __construct( $submission ) {
26
-		$this->payment_form_submission = $submission;
27
-	}
28
-
29
-	/**
30
-	 * Processes the checkout.
31
-	 *
32
-	 */
33
-	public function process_checkout() {
34
-
35
-		// Validate the submission.
36
-		$this->validate_submission();
37
-
38
-		// Prepare the invoice.
39
-		$items    = $this->get_submission_items();
40
-		$invoice  = $this->get_submission_invoice();
41
-		$invoice  = $this->process_submission_invoice( $invoice, $items );
42
-		$prepared = $this->prepare_submission_data_for_saving();
43
-
44
-		$this->prepare_billing_info( $invoice );
45
-
46
-		$shipping   = $this->prepare_shipping_info( $invoice );
47
-
48
-		// Save the invoice.
49
-		$invoice->set_is_viewed( true );
50
-		$invoice->recalculate_total();
15
+    /**
16
+     * @var GetPaid_Payment_Form_Submission
17
+     */
18
+    protected $payment_form_submission;
19
+
20
+    /**
21
+     * Class constructor.
22
+     *
23
+     * @param GetPaid_Payment_Form_Submission $submission
24
+     */
25
+    public function __construct( $submission ) {
26
+        $this->payment_form_submission = $submission;
27
+    }
28
+
29
+    /**
30
+     * Processes the checkout.
31
+     *
32
+     */
33
+    public function process_checkout() {
34
+
35
+        // Validate the submission.
36
+        $this->validate_submission();
37
+
38
+        // Prepare the invoice.
39
+        $items    = $this->get_submission_items();
40
+        $invoice  = $this->get_submission_invoice();
41
+        $invoice  = $this->process_submission_invoice( $invoice, $items );
42
+        $prepared = $this->prepare_submission_data_for_saving();
43
+
44
+        $this->prepare_billing_info( $invoice );
45
+
46
+        $shipping   = $this->prepare_shipping_info( $invoice );
47
+
48
+        // Save the invoice.
49
+        $invoice->set_is_viewed( true );
50
+        $invoice->recalculate_total();
51 51
         $invoice->save();
52 52
 
53
-		do_action( 'getpaid_checkout_invoice_updated', $invoice );
53
+        do_action( 'getpaid_checkout_invoice_updated', $invoice );
54 54
 
55
-		// Send to the gateway.
56
-		$this->post_process_submission( $invoice, $prepared, $shipping );
57
-	}
55
+        // Send to the gateway.
56
+        $this->post_process_submission( $invoice, $prepared, $shipping );
57
+    }
58 58
 
59
-	/**
60
-	 * Validates the submission.
61
-	 *
62
-	 */
63
-	protected function validate_submission() {
59
+    /**
60
+     * Validates the submission.
61
+     *
62
+     */
63
+    protected function validate_submission() {
64 64
 
65
-		$submission = $this->payment_form_submission;
66
-		$data       = $submission->get_data();
65
+        $submission = $this->payment_form_submission;
66
+        $data       = $submission->get_data();
67 67
 
68
-		// Do we have an error?
68
+        // Do we have an error?
69 69
         if ( ! empty( $submission->last_error ) ) {
70
-			wp_send_json_error( $submission->last_error );
70
+            wp_send_json_error( $submission->last_error );
71 71
         }
72 72
 
73
-		// We need a billing email.
73
+        // We need a billing email.
74 74
         if ( ! $submission->has_billing_email() ) {
75 75
             wp_send_json_error( __( 'Provide a valid billing email.', 'invoicing' ) );
76
-		}
76
+        }
77 77
 
78
-		// Non-recurring gateways should not be allowed to process recurring invoices.
79
-		if ( $submission->should_collect_payment_details() && $submission->has_recurring && ! wpinv_gateway_support_subscription( $data['wpi-gateway'] ) ) {
80
-			wp_send_json_error( __( 'The selected payment gateway does not support subscription payments.', 'invoicing' ) );
81
-		}
78
+        // Non-recurring gateways should not be allowed to process recurring invoices.
79
+        if ( $submission->should_collect_payment_details() && $submission->has_recurring && ! wpinv_gateway_support_subscription( $data['wpi-gateway'] ) ) {
80
+            wp_send_json_error( __( 'The selected payment gateway does not support subscription payments.', 'invoicing' ) );
81
+        }
82 82
 
83
-		// Ensure the gateway is active.
84
-		if ( $submission->should_collect_payment_details() && ! wpinv_is_gateway_active( $data['wpi-gateway'] ) ) {
85
-			wp_send_json_error( __( 'The selected payment gateway is not active', 'invoicing' ) );
86
-		}
83
+        // Ensure the gateway is active.
84
+        if ( $submission->should_collect_payment_details() && ! wpinv_is_gateway_active( $data['wpi-gateway'] ) ) {
85
+            wp_send_json_error( __( 'The selected payment gateway is not active', 'invoicing' ) );
86
+        }
87 87
 
88
-		// Clear any existing errors.
89
-		wpinv_clear_errors();
88
+        // Clear any existing errors.
89
+        wpinv_clear_errors();
90 90
 
91
-		// Allow themes and plugins to hook to errors
92
-		do_action( 'getpaid_checkout_error_checks', $submission );
91
+        // Allow themes and plugins to hook to errors
92
+        do_action( 'getpaid_checkout_error_checks', $submission );
93 93
 
94
-		// Do we have any errors?
94
+        // Do we have any errors?
95 95
         if ( wpinv_get_errors() ) {
96 96
             wp_send_json_error( getpaid_get_errors_html() );
97
-		}
97
+        }
98 98
 
99
-	}
99
+    }
100 100
 
101
-	/**
102
-	 * Retrieves submission items.
103
-	 *
104
-	 * @return GetPaid_Form_Item[]
105
-	 */
106
-	protected function get_submission_items() {
101
+    /**
102
+     * Retrieves submission items.
103
+     *
104
+     * @return GetPaid_Form_Item[]
105
+     */
106
+    protected function get_submission_items() {
107 107
 
108
-		$items = $this->payment_form_submission->get_items();
108
+        $items = $this->payment_form_submission->get_items();
109 109
 
110 110
         // Ensure that we have items.
111 111
         if ( empty( $items ) && ! $this->payment_form_submission->has_fees() ) {
112 112
             wp_send_json_error( __( 'Please provide at least one item or amount.', 'invoicing' ) );
113
-		}
114
-
115
-		return $items;
116
-	}
117
-
118
-	/**
119
-	 * Retrieves submission invoice.
120
-	 *
121
-	 * @return WPInv_Invoice
122
-	 */
123
-	protected function get_submission_invoice() {
124
-		$submission = $this->payment_form_submission;
125
-
126
-		if ( ! $submission->has_invoice() ) {
127
-			$invoice = new WPInv_Invoice();
128
-			$invoice->set_created_via( 'payment_form' );
129
-			return $invoice;
130 113
         }
131 114
 
132
-		$invoice = $submission->get_invoice();
115
+        return $items;
116
+    }
117
+
118
+    /**
119
+     * Retrieves submission invoice.
120
+     *
121
+     * @return WPInv_Invoice
122
+     */
123
+    protected function get_submission_invoice() {
124
+        $submission = $this->payment_form_submission;
133 125
 
134
-		// Make sure that it is neither paid or refunded.
135
-		if ( $invoice->is_paid() || $invoice->is_refunded() ) {
136
-			wp_send_json_error( __( 'This invoice has already been paid for.', 'invoicing' ) );
137
-		}
126
+        if ( ! $submission->has_invoice() ) {
127
+            $invoice = new WPInv_Invoice();
128
+            $invoice->set_created_via( 'payment_form' );
129
+            return $invoice;
130
+        }
138 131
 
139
-		return $invoice;
140
-	}
132
+        $invoice = $submission->get_invoice();
141 133
 
142
-	/**
143
-	 * Processes the submission invoice.
144
-	 *
145
-	 * @param WPInv_Invoice $invoice
146
-	 * @param GetPaid_Form_Item[] $items
147
-	 * @return WPInv_Invoice
148
-	 */
149
-	protected function process_submission_invoice( $invoice, $items ) {
134
+        // Make sure that it is neither paid or refunded.
135
+        if ( $invoice->is_paid() || $invoice->is_refunded() ) {
136
+            wp_send_json_error( __( 'This invoice has already been paid for.', 'invoicing' ) );
137
+        }
150 138
 
151
-		$submission = $this->payment_form_submission;
139
+        return $invoice;
140
+    }
152 141
 
153
-		// Set-up the invoice details.
154
-		$invoice->set_email( sanitize_email( $submission->get_billing_email() ) );
155
-		$invoice->set_user_id( $this->get_submission_customer() );
156
-		$invoice->set_payment_form( absint( $submission->get_payment_form()->get_id() ) );
142
+    /**
143
+     * Processes the submission invoice.
144
+     *
145
+     * @param WPInv_Invoice $invoice
146
+     * @param GetPaid_Form_Item[] $items
147
+     * @return WPInv_Invoice
148
+     */
149
+    protected function process_submission_invoice( $invoice, $items ) {
150
+
151
+        $submission = $this->payment_form_submission;
152
+
153
+        // Set-up the invoice details.
154
+        $invoice->set_email( sanitize_email( $submission->get_billing_email() ) );
155
+        $invoice->set_user_id( $this->get_submission_customer() );
156
+        $invoice->set_payment_form( absint( $submission->get_payment_form()->get_id() ) );
157 157
         $invoice->set_items( $items );
158 158
         $invoice->set_fees( $submission->get_fees() );
159 159
         $invoice->set_taxes( $submission->get_taxes() );
160
-		$invoice->set_discounts( $submission->get_discounts() );
161
-		$invoice->set_gateway( $submission->get_field( 'wpi-gateway' ) );
162
-		$invoice->set_currency( $submission->get_currency() );
160
+        $invoice->set_discounts( $submission->get_discounts() );
161
+        $invoice->set_gateway( $submission->get_field( 'wpi-gateway' ) );
162
+        $invoice->set_currency( $submission->get_currency() );
163 163
 
164
-		if ( $submission->has_shipping() ) {
165
-			$invoice->set_shipping( $submission->get_shipping() );
166
-		}
164
+        if ( $submission->has_shipping() ) {
165
+            $invoice->set_shipping( $submission->get_shipping() );
166
+        }
167 167
 
168
-		$address_confirmed = $submission->get_field( 'confirm-address' );
169
-		$invoice->set_address_confirmed( ! empty( $address_confirmed ) );
168
+        $address_confirmed = $submission->get_field( 'confirm-address' );
169
+        $invoice->set_address_confirmed( ! empty( $address_confirmed ) );
170 170
 
171
-		if ( $submission->has_discount_code() ) {
171
+        if ( $submission->has_discount_code() ) {
172 172
             $invoice->set_discount_code( $submission->get_discount_code() );
173
-		}
174
-
175
-		getpaid_maybe_add_default_address( $invoice );
176
-		return $invoice;
177
-	}
178
-
179
-	/**
180
-	 * Retrieves the submission's customer.
181
-	 *
182
-	 * @return int The customer id.
183
-	 */
184
-	protected function get_submission_customer() {
185
-		$submission = $this->payment_form_submission;
186
-
187
-		// If this is an existing invoice...
188
-		if ( $submission->has_invoice() ) {
189
-			return $submission->get_invoice()->get_user_id();
190
-		}
191
-
192
-		// (Maybe) create the user.
173
+        }
174
+
175
+        getpaid_maybe_add_default_address( $invoice );
176
+        return $invoice;
177
+    }
178
+
179
+    /**
180
+     * Retrieves the submission's customer.
181
+     *
182
+     * @return int The customer id.
183
+     */
184
+    protected function get_submission_customer() {
185
+        $submission = $this->payment_form_submission;
186
+
187
+        // If this is an existing invoice...
188
+        if ( $submission->has_invoice() ) {
189
+            return $submission->get_invoice()->get_user_id();
190
+        }
191
+
192
+        // (Maybe) create the user.
193 193
         $user = get_current_user_id();
194 194
 
195 195
         if ( empty( $user ) ) {
@@ -197,16 +197,16 @@  discard block
 block discarded – undo
197 197
         }
198 198
 
199 199
         if ( empty( $user ) ) {
200
-			$name = array( $submission->get_field( 'wpinv_first_name', 'billing' ), $submission->get_field( 'wpinv_last_name', 'billing' ) );
201
-			$name = implode( '', array_filter( $name ) );
200
+            $name = array( $submission->get_field( 'wpinv_first_name', 'billing' ), $submission->get_field( 'wpinv_last_name', 'billing' ) );
201
+            $name = implode( '', array_filter( $name ) );
202 202
             $user = wpinv_create_user( $submission->get_billing_email(), $name );
203 203
 
204
-			// (Maybe) send new user notification.
205
-			$should_send_notification = wpinv_get_option( 'disable_new_user_emails' );
206
-			if ( ! empty( $user ) && is_numeric( $user ) && apply_filters( 'getpaid_send_new_user_notification', empty( $should_send_notification ), $user ) ) {
207
-				wp_send_new_user_notifications( $user, 'user' );
208
-			}
209
-		}
204
+            // (Maybe) send new user notification.
205
+            $should_send_notification = wpinv_get_option( 'disable_new_user_emails' );
206
+            if ( ! empty( $user ) && is_numeric( $user ) && apply_filters( 'getpaid_send_new_user_notification', empty( $should_send_notification ), $user ) ) {
207
+                wp_send_new_user_notifications( $user, 'user' );
208
+            }
209
+        }
210 210
 
211 211
         if ( is_wp_error( $user ) ) {
212 212
             wp_send_json_error( $user->get_error_message() );
@@ -214,49 +214,49 @@  discard block
 block discarded – undo
214 214
 
215 215
         if ( is_numeric( $user ) ) {
216 216
             return $user;
217
-		}
217
+        }
218 218
 
219
-		return $user->ID;
219
+        return $user->ID;
220 220
 
221
-	}
221
+    }
222 222
 
223
-	/**
223
+    /**
224 224
      * Prepares submission data for saving to the database.
225 225
      *
226
-	 * @return array
226
+     * @return array
227 227
      */
228 228
     public function prepare_submission_data_for_saving() {
229 229
 
230
-		$submission = $this->payment_form_submission;
230
+        $submission = $this->payment_form_submission;
231 231
 
232
-		// Prepared submission details.
232
+        // Prepared submission details.
233 233
         $prepared = array(
234
-			'all'  => array(),
235
-			'meta' => array(),
236
-		);
234
+            'all'  => array(),
235
+            'meta' => array(),
236
+        );
237 237
 
238 238
         // Raw submission details.
239
-		$data     = $submission->get_data();
239
+        $data     = $submission->get_data();
240 240
 
241
-		// Loop through the submitted details.
241
+        // Loop through the submitted details.
242 242
         foreach ( $submission->get_payment_form()->get_elements() as $field ) {
243 243
 
244
-			// Skip premade fields.
244
+            // Skip premade fields.
245 245
             if ( ! empty( $field['premade'] ) ) {
246 246
                 continue;
247 247
             }
248 248
 
249
-			// Ensure address is provided.
250
-			if ( 'address' === $field['type'] ) {
249
+            // Ensure address is provided.
250
+            if ( 'address' === $field['type'] ) {
251 251
                 $address_type = isset( $field['address_type'] ) && 'shipping' === $field['address_type'] ? 'shipping' : 'billing';
252 252
 
253
-				foreach ( $field['fields'] as $address_field ) {
253
+                foreach ( $field['fields'] as $address_field ) {
254 254
 
255
-					if ( ! empty( $address_field['visible'] ) && ! empty( $address_field['required'] ) && '' === trim( $_POST[ $address_type ][ $address_field['name'] ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
256
-						wp_send_json_error( __( 'Please fill all required fields.', 'invoicing' ) );
257
-					}
258
-			}
259
-		}
255
+                    if ( ! empty( $address_field['visible'] ) && ! empty( $address_field['required'] ) && '' === trim( $_POST[ $address_type ][ $address_field['name'] ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
256
+                        wp_send_json_error( __( 'Please fill all required fields.', 'invoicing' ) );
257
+                    }
258
+            }
259
+        }
260 260
 
261 261
             // If it is required and not set, abort.
262 262
             if ( ! $submission->is_required_field_set( $field ) ) {
@@ -266,31 +266,31 @@  discard block
 block discarded – undo
266 266
             // Handle misc fields.
267 267
             if ( isset( $data[ $field['id'] ] ) ) {
268 268
 
269
-				// Uploads.
270
-				if ( 'file_upload' === $field['type'] ) {
271
-					$max_file_num = empty( $field['max_file_num'] ) ? 1 : absint( $field['max_file_num'] );
269
+                // Uploads.
270
+                if ( 'file_upload' === $field['type'] ) {
271
+                    $max_file_num = empty( $field['max_file_num'] ) ? 1 : absint( $field['max_file_num'] );
272 272
 
273
-					if ( count( $data[ $field['id'] ] ) > $max_file_num ) {
274
-						wp_send_json_error( __( 'Maximum number of allowed files exceeded.', 'invoicing' ) );
275
-					}
273
+                    if ( count( $data[ $field['id'] ] ) > $max_file_num ) {
274
+                        wp_send_json_error( __( 'Maximum number of allowed files exceeded.', 'invoicing' ) );
275
+                    }
276 276
 
277
-					$value = array();
277
+                    $value = array();
278 278
 
279
-					foreach ( $data[ $field['id'] ] as $url => $name ) {
280
-						$value[] = sprintf(
281
-							'<a href="%s" target="_blank">%s</a>',
282
-							esc_url_raw( $url ),
283
-							esc_html( $name )
284
-						);
285
-					}
279
+                    foreach ( $data[ $field['id'] ] as $url => $name ) {
280
+                        $value[] = sprintf(
281
+                            '<a href="%s" target="_blank">%s</a>',
282
+                            esc_url_raw( $url ),
283
+                            esc_html( $name )
284
+                        );
285
+                    }
286 286
 
287
-					$value = implode( ' | ', $value );
287
+                    $value = implode( ' | ', $value );
288 288
 
289
-				} elseif ( 'checkbox' === $field['type'] ) {
290
-					$value = ! empty( $data[ $field['id'] ] ) ? __( 'Yes', 'invoicing' ) : __( 'No', 'invoicing' );
291
-				} else {
292
-					$value = wp_kses_post( $data[ $field['id'] ] );
293
-				}
289
+                } elseif ( 'checkbox' === $field['type'] ) {
290
+                    $value = ! empty( $data[ $field['id'] ] ) ? __( 'Yes', 'invoicing' ) : __( 'No', 'invoicing' );
291
+                } else {
292
+                    $value = wp_kses_post( $data[ $field['id'] ] );
293
+                }
294 294
 
295 295
                 $label = $field['id'];
296 296
 
@@ -298,192 +298,192 @@  discard block
 block discarded – undo
298 298
                     $label = $field['label'];
299 299
                 }
300 300
 
301
-				if ( ! empty( $field['add_meta'] ) ) {
302
-					$prepared['meta'][ wpinv_clean( $label ) ] = wp_kses_post_deep( $value );
303
-				}
304
-				$prepared['all'][ wpinv_clean( $label ) ] = wp_kses_post_deep( $value );
301
+                if ( ! empty( $field['add_meta'] ) ) {
302
+                    $prepared['meta'][ wpinv_clean( $label ) ] = wp_kses_post_deep( $value );
303
+                }
304
+                $prepared['all'][ wpinv_clean( $label ) ] = wp_kses_post_deep( $value );
305 305
 
306 306
             }
307
-		}
307
+        }
308 308
 
309
-		return $prepared;
309
+        return $prepared;
310 310
 
311
-	}
311
+    }
312 312
 
313
-	/**
313
+    /**
314 314
      * Retrieves address details.
315 315
      *
316
-	 * @return array
317
-	 * @param WPInv_Invoice $invoice
318
-	 * @param string $type
316
+     * @return array
317
+     * @param WPInv_Invoice $invoice
318
+     * @param string $type
319 319
      */
320 320
     public function prepare_address_details( $invoice, $type = 'billing' ) {
321 321
 
322
-		$data     = $this->payment_form_submission->get_data();
323
-		$type     = sanitize_key( $type );
324
-		$address  = array();
325
-		$prepared = array();
322
+        $data     = $this->payment_form_submission->get_data();
323
+        $type     = sanitize_key( $type );
324
+        $address  = array();
325
+        $prepared = array();
326 326
 
327
-		if ( ! empty( $data[ $type ] ) ) {
328
-			$address = $data[ $type ];
329
-		}
327
+        if ( ! empty( $data[ $type ] ) ) {
328
+            $address = $data[ $type ];
329
+        }
330 330
 
331
-		// Clean address details.
332
-		foreach ( $address as $key => $value ) {
333
-			$key             = sanitize_key( $key );
334
-			$key             = str_replace( 'wpinv_', '', $key );
335
-			$value           = wpinv_clean( $value );
336
-			$prepared[ $key ] = apply_filters( "getpaid_checkout_{$type}_address_$key", $value, $this->payment_form_submission, $invoice );
337
-		}
331
+        // Clean address details.
332
+        foreach ( $address as $key => $value ) {
333
+            $key             = sanitize_key( $key );
334
+            $key             = str_replace( 'wpinv_', '', $key );
335
+            $value           = wpinv_clean( $value );
336
+            $prepared[ $key ] = apply_filters( "getpaid_checkout_{$type}_address_$key", $value, $this->payment_form_submission, $invoice );
337
+        }
338 338
 
339
-		// Filter address details.
340
-		$prepared = apply_filters( "getpaid_checkout_{$type}_address", $prepared, $this->payment_form_submission, $invoice );
339
+        // Filter address details.
340
+        $prepared = apply_filters( "getpaid_checkout_{$type}_address", $prepared, $this->payment_form_submission, $invoice );
341 341
 
342
-		// Remove non-whitelisted values.
343
-		return array_filter( $prepared, 'getpaid_is_address_field_whitelisted', ARRAY_FILTER_USE_KEY );
342
+        // Remove non-whitelisted values.
343
+        return array_filter( $prepared, 'getpaid_is_address_field_whitelisted', ARRAY_FILTER_USE_KEY );
344 344
 
345
-	}
345
+    }
346 346
 
347
-	/**
347
+    /**
348 348
      * Prepares the billing details.
349 349
      *
350
-	 * @return array
351
-	 * @param WPInv_Invoice $invoice
350
+     * @return array
351
+     * @param WPInv_Invoice $invoice
352 352
      */
353 353
     protected function prepare_billing_info( &$invoice ) {
354 354
 
355
-		$billing_address = $this->prepare_address_details( $invoice, 'billing' );
355
+        $billing_address = $this->prepare_address_details( $invoice, 'billing' );
356 356
 
357
-		// Update the invoice with the billing details.
358
-		$invoice->set_props( $billing_address );
357
+        // Update the invoice with the billing details.
358
+        $invoice->set_props( $billing_address );
359 359
 
360
-	}
360
+    }
361 361
 
362
-	/**
362
+    /**
363 363
      * Prepares the shipping details.
364 364
      *
365
-	 * @return array
366
-	 * @param WPInv_Invoice $invoice
365
+     * @return array
366
+     * @param WPInv_Invoice $invoice
367 367
      */
368 368
     protected function prepare_shipping_info( $invoice ) {
369 369
 
370
-		$data = $this->payment_form_submission->get_data();
370
+        $data = $this->payment_form_submission->get_data();
371 371
 
372
-		if ( empty( $data['same-shipping-address'] ) ) {
373
-			return $this->prepare_address_details( $invoice, 'shipping' );
374
-		}
372
+        if ( empty( $data['same-shipping-address'] ) ) {
373
+            return $this->prepare_address_details( $invoice, 'shipping' );
374
+        }
375 375
 
376
-		return $this->prepare_address_details( $invoice, 'billing' );
376
+        return $this->prepare_address_details( $invoice, 'billing' );
377 377
 
378
-	}
378
+    }
379 379
 
380
-	/**
381
-	 * Confirms the submission is valid and send users to the gateway.
382
-	 *
383
-	 * @param WPInv_Invoice $invoice
384
-	 * @param array $prepared_payment_form_data
385
-	 * @param array $shipping
386
-	 */
387
-	protected function post_process_submission( $invoice, $prepared_payment_form_data, $shipping ) {
380
+    /**
381
+     * Confirms the submission is valid and send users to the gateway.
382
+     *
383
+     * @param WPInv_Invoice $invoice
384
+     * @param array $prepared_payment_form_data
385
+     * @param array $shipping
386
+     */
387
+    protected function post_process_submission( $invoice, $prepared_payment_form_data, $shipping ) {
388 388
 
389
-		// Ensure the invoice exists.
389
+        // Ensure the invoice exists.
390 390
         if ( ! $invoice->exists() ) {
391 391
             wp_send_json_error( __( 'An error occured while saving your invoice. Please try again.', 'invoicing' ) );
392 392
         }
393 393
 
394
-		// Save payment form data.
395
-		$prepared_payment_form_data = apply_filters( 'getpaid_prepared_payment_form_data', $prepared_payment_form_data, $invoice );
394
+        // Save payment form data.
395
+        $prepared_payment_form_data = apply_filters( 'getpaid_prepared_payment_form_data', $prepared_payment_form_data, $invoice );
396 396
         delete_post_meta( $invoice->get_id(), 'payment_form_data' );
397
-		delete_post_meta( $invoice->get_id(), 'additional_meta_data' );
398
-		if ( ! empty( $prepared_payment_form_data ) ) {
397
+        delete_post_meta( $invoice->get_id(), 'additional_meta_data' );
398
+        if ( ! empty( $prepared_payment_form_data ) ) {
399 399
 
400
-			if ( ! empty( $prepared_payment_form_data['all'] ) ) {
401
-				update_post_meta( $invoice->get_id(), 'payment_form_data', $prepared_payment_form_data['all'] );
402
-			}
400
+            if ( ! empty( $prepared_payment_form_data['all'] ) ) {
401
+                update_post_meta( $invoice->get_id(), 'payment_form_data', $prepared_payment_form_data['all'] );
402
+            }
403 403
 
404
-			if ( ! empty( $prepared_payment_form_data['meta'] ) ) {
405
-				update_post_meta( $invoice->get_id(), 'additional_meta_data', $prepared_payment_form_data['meta'] );
406
-			}
407
-		}
404
+            if ( ! empty( $prepared_payment_form_data['meta'] ) ) {
405
+                update_post_meta( $invoice->get_id(), 'additional_meta_data', $prepared_payment_form_data['meta'] );
406
+            }
407
+        }
408 408
 
409
-		// Save payment form data.
410
-		$shipping = apply_filters( 'getpaid_checkout_shipping_details', $shipping, $this->payment_form_submission );
409
+        // Save payment form data.
410
+        $shipping = apply_filters( 'getpaid_checkout_shipping_details', $shipping, $this->payment_form_submission );
411 411
         if ( ! empty( $shipping ) ) {
412 412
             update_post_meta( $invoice->get_id(), 'shipping_address', $shipping );
413
-		}
413
+        }
414 414
 
415
-		// Backwards compatibility.
415
+        // Backwards compatibility.
416 416
         add_filter( 'wp_redirect', array( $this, 'send_redirect_response' ) );
417 417
 
418
-		try {
419
-			$this->process_payment( $invoice );
420
-		} catch ( Exception $e ) {
421
-			wpinv_set_error( 'payment_error', $e->getMessage() );
422
-		}
418
+        try {
419
+            $this->process_payment( $invoice );
420
+        } catch ( Exception $e ) {
421
+            wpinv_set_error( 'payment_error', $e->getMessage() );
422
+        }
423 423
 
424 424
         // If we are here, there was an error.
425
-		wpinv_send_back_to_checkout( $invoice );
425
+        wpinv_send_back_to_checkout( $invoice );
426 426
 
427
-	}
427
+    }
428 428
 
429
-	/**
430
-	 * Processes the actual payment.
431
-	 *
432
-	 * @param WPInv_Invoice $invoice
433
-	 */
434
-	protected function process_payment( $invoice ) {
429
+    /**
430
+     * Processes the actual payment.
431
+     *
432
+     * @param WPInv_Invoice $invoice
433
+     */
434
+    protected function process_payment( $invoice ) {
435 435
 
436
-		// Clear any checkout errors.
437
-		wpinv_clear_errors();
436
+        // Clear any checkout errors.
437
+        wpinv_clear_errors();
438 438
 
439
-		// No need to send free invoices to the gateway.
440
-		if ( $invoice->is_free() ) {
441
-			$this->process_free_payment( $invoice );
442
-		}
439
+        // No need to send free invoices to the gateway.
440
+        if ( $invoice->is_free() ) {
441
+            $this->process_free_payment( $invoice );
442
+        }
443 443
 
444
-		$submission = $this->payment_form_submission;
444
+        $submission = $this->payment_form_submission;
445 445
 
446
-		// Fires before sending to the gateway.
447
-		do_action( 'getpaid_checkout_before_gateway', $invoice, $submission );
446
+        // Fires before sending to the gateway.
447
+        do_action( 'getpaid_checkout_before_gateway', $invoice, $submission );
448 448
 
449
-		// Allow the sumission data to be modified before it is sent to the gateway.
450
-		$submission_data    = $submission->get_data();
451
-		$submission_gateway = apply_filters( 'getpaid_gateway_submission_gateway', $invoice->get_gateway(), $submission, $invoice );
452
-		$submission_data    = apply_filters( 'getpaid_gateway_submission_data', $submission_data, $submission, $invoice );
449
+        // Allow the sumission data to be modified before it is sent to the gateway.
450
+        $submission_data    = $submission->get_data();
451
+        $submission_gateway = apply_filters( 'getpaid_gateway_submission_gateway', $invoice->get_gateway(), $submission, $invoice );
452
+        $submission_data    = apply_filters( 'getpaid_gateway_submission_data', $submission_data, $submission, $invoice );
453 453
 
454
-		// Validate the currency.
455
-		if ( ! apply_filters( "getpaid_gateway_{$submission_gateway}_is_valid_for_currency", true, $invoice->get_currency() ) ) {
456
-			wpinv_set_error( 'invalid_currency' );
457
-		}
454
+        // Validate the currency.
455
+        if ( ! apply_filters( "getpaid_gateway_{$submission_gateway}_is_valid_for_currency", true, $invoice->get_currency() ) ) {
456
+            wpinv_set_error( 'invalid_currency' );
457
+        }
458 458
 
459
-		// Check to see if we have any errors.
460
-		if ( wpinv_get_errors() ) {
461
-			wpinv_send_back_to_checkout( $invoice );
462
-		}
459
+        // Check to see if we have any errors.
460
+        if ( wpinv_get_errors() ) {
461
+            wpinv_send_back_to_checkout( $invoice );
462
+        }
463 463
 
464
-		// Send info to the gateway for payment processing
465
-		do_action( "getpaid_gateway_$submission_gateway", $invoice, $submission_data, $submission );
464
+        // Send info to the gateway for payment processing
465
+        do_action( "getpaid_gateway_$submission_gateway", $invoice, $submission_data, $submission );
466 466
 
467
-		// Backwards compatibility.
468
-		wpinv_send_to_gateway( $submission_gateway, $invoice );
467
+        // Backwards compatibility.
468
+        wpinv_send_to_gateway( $submission_gateway, $invoice );
469 469
 
470
-	}
470
+    }
471 471
 
472
-	/**
473
-	 * Marks the invoice as paid in case the checkout is free.
474
-	 *
475
-	 * @param WPInv_Invoice $invoice
476
-	 */
477
-	protected function process_free_payment( $invoice ) {
472
+    /**
473
+     * Marks the invoice as paid in case the checkout is free.
474
+     *
475
+     * @param WPInv_Invoice $invoice
476
+     */
477
+    protected function process_free_payment( $invoice ) {
478 478
 
479
-		$invoice->set_gateway( 'none' );
480
-		$invoice->add_note( __( "This is a free invoice and won't be sent to the payment gateway", 'invoicing' ), false, false, true );
481
-		$invoice->mark_paid();
482
-		wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) );
479
+        $invoice->set_gateway( 'none' );
480
+        $invoice->add_note( __( "This is a free invoice and won't be sent to the payment gateway", 'invoicing' ), false, false, true );
481
+        $invoice->mark_paid();
482
+        wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) );
483 483
 
484
-	}
484
+    }
485 485
 
486
-	/**
486
+    /**
487 487
      * Sends a redrect response to payment details.
488 488
      *
489 489
      */
Please login to merge, or discard this patch.
Spacing   +138 added lines, -138 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
4 4
  *
5 5
  */
6 6
 
7
-defined( 'ABSPATH' ) || exit;
7
+defined('ABSPATH') || exit;
8 8
 
9 9
 /**
10 10
  * Main Checkout Class.
@@ -22,7 +22,7 @@  discard block
 block discarded – undo
22 22
 	 *
23 23
 	 * @param GetPaid_Payment_Form_Submission $submission
24 24
 	 */
25
-	public function __construct( $submission ) {
25
+	public function __construct($submission) {
26 26
 		$this->payment_form_submission = $submission;
27 27
 	}
28 28
 
@@ -38,22 +38,22 @@  discard block
 block discarded – undo
38 38
 		// Prepare the invoice.
39 39
 		$items    = $this->get_submission_items();
40 40
 		$invoice  = $this->get_submission_invoice();
41
-		$invoice  = $this->process_submission_invoice( $invoice, $items );
41
+		$invoice  = $this->process_submission_invoice($invoice, $items);
42 42
 		$prepared = $this->prepare_submission_data_for_saving();
43 43
 
44
-		$this->prepare_billing_info( $invoice );
44
+		$this->prepare_billing_info($invoice);
45 45
 
46
-		$shipping   = $this->prepare_shipping_info( $invoice );
46
+		$shipping = $this->prepare_shipping_info($invoice);
47 47
 
48 48
 		// Save the invoice.
49
-		$invoice->set_is_viewed( true );
49
+		$invoice->set_is_viewed(true);
50 50
 		$invoice->recalculate_total();
51 51
         $invoice->save();
52 52
 
53
-		do_action( 'getpaid_checkout_invoice_updated', $invoice );
53
+		do_action('getpaid_checkout_invoice_updated', $invoice);
54 54
 
55 55
 		// Send to the gateway.
56
-		$this->post_process_submission( $invoice, $prepared, $shipping );
56
+		$this->post_process_submission($invoice, $prepared, $shipping);
57 57
 	}
58 58
 
59 59
 	/**
@@ -66,34 +66,34 @@  discard block
 block discarded – undo
66 66
 		$data       = $submission->get_data();
67 67
 
68 68
 		// Do we have an error?
69
-        if ( ! empty( $submission->last_error ) ) {
70
-			wp_send_json_error( $submission->last_error );
69
+        if (!empty($submission->last_error)) {
70
+			wp_send_json_error($submission->last_error);
71 71
         }
72 72
 
73 73
 		// We need a billing email.
74
-        if ( ! $submission->has_billing_email() ) {
75
-            wp_send_json_error( __( 'Provide a valid billing email.', 'invoicing' ) );
74
+        if (!$submission->has_billing_email()) {
75
+            wp_send_json_error(__('Provide a valid billing email.', 'invoicing'));
76 76
 		}
77 77
 
78 78
 		// Non-recurring gateways should not be allowed to process recurring invoices.
79
-		if ( $submission->should_collect_payment_details() && $submission->has_recurring && ! wpinv_gateway_support_subscription( $data['wpi-gateway'] ) ) {
80
-			wp_send_json_error( __( 'The selected payment gateway does not support subscription payments.', 'invoicing' ) );
79
+		if ($submission->should_collect_payment_details() && $submission->has_recurring && !wpinv_gateway_support_subscription($data['wpi-gateway'])) {
80
+			wp_send_json_error(__('The selected payment gateway does not support subscription payments.', 'invoicing'));
81 81
 		}
82 82
 
83 83
 		// Ensure the gateway is active.
84
-		if ( $submission->should_collect_payment_details() && ! wpinv_is_gateway_active( $data['wpi-gateway'] ) ) {
85
-			wp_send_json_error( __( 'The selected payment gateway is not active', 'invoicing' ) );
84
+		if ($submission->should_collect_payment_details() && !wpinv_is_gateway_active($data['wpi-gateway'])) {
85
+			wp_send_json_error(__('The selected payment gateway is not active', 'invoicing'));
86 86
 		}
87 87
 
88 88
 		// Clear any existing errors.
89 89
 		wpinv_clear_errors();
90 90
 
91 91
 		// Allow themes and plugins to hook to errors
92
-		do_action( 'getpaid_checkout_error_checks', $submission );
92
+		do_action('getpaid_checkout_error_checks', $submission);
93 93
 
94 94
 		// Do we have any errors?
95
-        if ( wpinv_get_errors() ) {
96
-            wp_send_json_error( getpaid_get_errors_html() );
95
+        if (wpinv_get_errors()) {
96
+            wp_send_json_error(getpaid_get_errors_html());
97 97
 		}
98 98
 
99 99
 	}
@@ -108,8 +108,8 @@  discard block
 block discarded – undo
108 108
 		$items = $this->payment_form_submission->get_items();
109 109
 
110 110
         // Ensure that we have items.
111
-        if ( empty( $items ) && ! $this->payment_form_submission->has_fees() ) {
112
-            wp_send_json_error( __( 'Please provide at least one item or amount.', 'invoicing' ) );
111
+        if (empty($items) && !$this->payment_form_submission->has_fees()) {
112
+            wp_send_json_error(__('Please provide at least one item or amount.', 'invoicing'));
113 113
 		}
114 114
 
115 115
 		return $items;
@@ -123,17 +123,17 @@  discard block
 block discarded – undo
123 123
 	protected function get_submission_invoice() {
124 124
 		$submission = $this->payment_form_submission;
125 125
 
126
-		if ( ! $submission->has_invoice() ) {
126
+		if (!$submission->has_invoice()) {
127 127
 			$invoice = new WPInv_Invoice();
128
-			$invoice->set_created_via( 'payment_form' );
128
+			$invoice->set_created_via('payment_form');
129 129
 			return $invoice;
130 130
         }
131 131
 
132 132
 		$invoice = $submission->get_invoice();
133 133
 
134 134
 		// Make sure that it is neither paid or refunded.
135
-		if ( $invoice->is_paid() || $invoice->is_refunded() ) {
136
-			wp_send_json_error( __( 'This invoice has already been paid for.', 'invoicing' ) );
135
+		if ($invoice->is_paid() || $invoice->is_refunded()) {
136
+			wp_send_json_error(__('This invoice has already been paid for.', 'invoicing'));
137 137
 		}
138 138
 
139 139
 		return $invoice;
@@ -146,33 +146,33 @@  discard block
 block discarded – undo
146 146
 	 * @param GetPaid_Form_Item[] $items
147 147
 	 * @return WPInv_Invoice
148 148
 	 */
149
-	protected function process_submission_invoice( $invoice, $items ) {
149
+	protected function process_submission_invoice($invoice, $items) {
150 150
 
151 151
 		$submission = $this->payment_form_submission;
152 152
 
153 153
 		// Set-up the invoice details.
154
-		$invoice->set_email( sanitize_email( $submission->get_billing_email() ) );
155
-		$invoice->set_user_id( $this->get_submission_customer() );
156
-		$invoice->set_payment_form( absint( $submission->get_payment_form()->get_id() ) );
157
-        $invoice->set_items( $items );
158
-        $invoice->set_fees( $submission->get_fees() );
159
-        $invoice->set_taxes( $submission->get_taxes() );
160
-		$invoice->set_discounts( $submission->get_discounts() );
161
-		$invoice->set_gateway( $submission->get_field( 'wpi-gateway' ) );
162
-		$invoice->set_currency( $submission->get_currency() );
163
-
164
-		if ( $submission->has_shipping() ) {
165
-			$invoice->set_shipping( $submission->get_shipping() );
154
+		$invoice->set_email(sanitize_email($submission->get_billing_email()));
155
+		$invoice->set_user_id($this->get_submission_customer());
156
+		$invoice->set_payment_form(absint($submission->get_payment_form()->get_id()));
157
+        $invoice->set_items($items);
158
+        $invoice->set_fees($submission->get_fees());
159
+        $invoice->set_taxes($submission->get_taxes());
160
+		$invoice->set_discounts($submission->get_discounts());
161
+		$invoice->set_gateway($submission->get_field('wpi-gateway'));
162
+		$invoice->set_currency($submission->get_currency());
163
+
164
+		if ($submission->has_shipping()) {
165
+			$invoice->set_shipping($submission->get_shipping());
166 166
 		}
167 167
 
168
-		$address_confirmed = $submission->get_field( 'confirm-address' );
169
-		$invoice->set_address_confirmed( ! empty( $address_confirmed ) );
168
+		$address_confirmed = $submission->get_field('confirm-address');
169
+		$invoice->set_address_confirmed(!empty($address_confirmed));
170 170
 
171
-		if ( $submission->has_discount_code() ) {
172
-            $invoice->set_discount_code( $submission->get_discount_code() );
171
+		if ($submission->has_discount_code()) {
172
+            $invoice->set_discount_code($submission->get_discount_code());
173 173
 		}
174 174
 
175
-		getpaid_maybe_add_default_address( $invoice );
175
+		getpaid_maybe_add_default_address($invoice);
176 176
 		return $invoice;
177 177
 	}
178 178
 
@@ -185,34 +185,34 @@  discard block
 block discarded – undo
185 185
 		$submission = $this->payment_form_submission;
186 186
 
187 187
 		// If this is an existing invoice...
188
-		if ( $submission->has_invoice() ) {
188
+		if ($submission->has_invoice()) {
189 189
 			return $submission->get_invoice()->get_user_id();
190 190
 		}
191 191
 
192 192
 		// (Maybe) create the user.
193 193
         $user = get_current_user_id();
194 194
 
195
-        if ( empty( $user ) ) {
196
-            $user = get_user_by( 'email', $submission->get_billing_email() );
195
+        if (empty($user)) {
196
+            $user = get_user_by('email', $submission->get_billing_email());
197 197
         }
198 198
 
199
-        if ( empty( $user ) ) {
200
-			$name = array( $submission->get_field( 'wpinv_first_name', 'billing' ), $submission->get_field( 'wpinv_last_name', 'billing' ) );
201
-			$name = implode( '', array_filter( $name ) );
202
-            $user = wpinv_create_user( $submission->get_billing_email(), $name );
199
+        if (empty($user)) {
200
+			$name = array($submission->get_field('wpinv_first_name', 'billing'), $submission->get_field('wpinv_last_name', 'billing'));
201
+			$name = implode('', array_filter($name));
202
+            $user = wpinv_create_user($submission->get_billing_email(), $name);
203 203
 
204 204
 			// (Maybe) send new user notification.
205
-			$should_send_notification = wpinv_get_option( 'disable_new_user_emails' );
206
-			if ( ! empty( $user ) && is_numeric( $user ) && apply_filters( 'getpaid_send_new_user_notification', empty( $should_send_notification ), $user ) ) {
207
-				wp_send_new_user_notifications( $user, 'user' );
205
+			$should_send_notification = wpinv_get_option('disable_new_user_emails');
206
+			if (!empty($user) && is_numeric($user) && apply_filters('getpaid_send_new_user_notification', empty($should_send_notification), $user)) {
207
+				wp_send_new_user_notifications($user, 'user');
208 208
 			}
209 209
 		}
210 210
 
211
-        if ( is_wp_error( $user ) ) {
212
-            wp_send_json_error( $user->get_error_message() );
211
+        if (is_wp_error($user)) {
212
+            wp_send_json_error($user->get_error_message());
213 213
         }
214 214
 
215
-        if ( is_numeric( $user ) ) {
215
+        if (is_numeric($user)) {
216 216
             return $user;
217 217
 		}
218 218
 
@@ -236,72 +236,72 @@  discard block
 block discarded – undo
236 236
 		);
237 237
 
238 238
         // Raw submission details.
239
-		$data     = $submission->get_data();
239
+		$data = $submission->get_data();
240 240
 
241 241
 		// Loop through the submitted details.
242
-        foreach ( $submission->get_payment_form()->get_elements() as $field ) {
242
+        foreach ($submission->get_payment_form()->get_elements() as $field) {
243 243
 
244 244
 			// Skip premade fields.
245
-            if ( ! empty( $field['premade'] ) ) {
245
+            if (!empty($field['premade'])) {
246 246
                 continue;
247 247
             }
248 248
 
249 249
 			// Ensure address is provided.
250
-			if ( 'address' === $field['type'] ) {
251
-                $address_type = isset( $field['address_type'] ) && 'shipping' === $field['address_type'] ? 'shipping' : 'billing';
250
+			if ('address' === $field['type']) {
251
+                $address_type = isset($field['address_type']) && 'shipping' === $field['address_type'] ? 'shipping' : 'billing';
252 252
 
253
-				foreach ( $field['fields'] as $address_field ) {
253
+				foreach ($field['fields'] as $address_field) {
254 254
 
255
-					if ( ! empty( $address_field['visible'] ) && ! empty( $address_field['required'] ) && '' === trim( $_POST[ $address_type ][ $address_field['name'] ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
256
-						wp_send_json_error( __( 'Please fill all required fields.', 'invoicing' ) );
255
+					if (!empty($address_field['visible']) && !empty($address_field['required']) && '' === trim($_POST[$address_type][$address_field['name']])) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
256
+						wp_send_json_error(__('Please fill all required fields.', 'invoicing'));
257 257
 					}
258 258
 			}
259 259
 		}
260 260
 
261 261
             // If it is required and not set, abort.
262
-            if ( ! $submission->is_required_field_set( $field ) ) {
263
-                wp_send_json_error( __( 'Please fill all required fields.', 'invoicing' ) );
262
+            if (!$submission->is_required_field_set($field)) {
263
+                wp_send_json_error(__('Please fill all required fields.', 'invoicing'));
264 264
             }
265 265
 
266 266
             // Handle misc fields.
267
-            if ( isset( $data[ $field['id'] ] ) ) {
267
+            if (isset($data[$field['id']])) {
268 268
 
269 269
 				// Uploads.
270
-				if ( 'file_upload' === $field['type'] ) {
271
-					$max_file_num = empty( $field['max_file_num'] ) ? 1 : absint( $field['max_file_num'] );
270
+				if ('file_upload' === $field['type']) {
271
+					$max_file_num = empty($field['max_file_num']) ? 1 : absint($field['max_file_num']);
272 272
 
273
-					if ( count( $data[ $field['id'] ] ) > $max_file_num ) {
274
-						wp_send_json_error( __( 'Maximum number of allowed files exceeded.', 'invoicing' ) );
273
+					if (count($data[$field['id']]) > $max_file_num) {
274
+						wp_send_json_error(__('Maximum number of allowed files exceeded.', 'invoicing'));
275 275
 					}
276 276
 
277 277
 					$value = array();
278 278
 
279
-					foreach ( $data[ $field['id'] ] as $url => $name ) {
279
+					foreach ($data[$field['id']] as $url => $name) {
280 280
 						$value[] = sprintf(
281 281
 							'<a href="%s" target="_blank">%s</a>',
282
-							esc_url_raw( $url ),
283
-							esc_html( $name )
282
+							esc_url_raw($url),
283
+							esc_html($name)
284 284
 						);
285 285
 					}
286 286
 
287
-					$value = implode( ' | ', $value );
287
+					$value = implode(' | ', $value);
288 288
 
289
-				} elseif ( 'checkbox' === $field['type'] ) {
290
-					$value = ! empty( $data[ $field['id'] ] ) ? __( 'Yes', 'invoicing' ) : __( 'No', 'invoicing' );
289
+				} elseif ('checkbox' === $field['type']) {
290
+					$value = !empty($data[$field['id']]) ? __('Yes', 'invoicing') : __('No', 'invoicing');
291 291
 				} else {
292
-					$value = wp_kses_post( $data[ $field['id'] ] );
292
+					$value = wp_kses_post($data[$field['id']]);
293 293
 				}
294 294
 
295 295
                 $label = $field['id'];
296 296
 
297
-                if ( isset( $field['label'] ) ) {
297
+                if (isset($field['label'])) {
298 298
                     $label = $field['label'];
299 299
                 }
300 300
 
301
-				if ( ! empty( $field['add_meta'] ) ) {
302
-					$prepared['meta'][ wpinv_clean( $label ) ] = wp_kses_post_deep( $value );
301
+				if (!empty($field['add_meta'])) {
302
+					$prepared['meta'][wpinv_clean($label)] = wp_kses_post_deep($value);
303 303
 				}
304
-				$prepared['all'][ wpinv_clean( $label ) ] = wp_kses_post_deep( $value );
304
+				$prepared['all'][wpinv_clean($label)] = wp_kses_post_deep($value);
305 305
 
306 306
             }
307 307
 		}
@@ -317,30 +317,30 @@  discard block
 block discarded – undo
317 317
 	 * @param WPInv_Invoice $invoice
318 318
 	 * @param string $type
319 319
      */
320
-    public function prepare_address_details( $invoice, $type = 'billing' ) {
320
+    public function prepare_address_details($invoice, $type = 'billing') {
321 321
 
322 322
 		$data     = $this->payment_form_submission->get_data();
323
-		$type     = sanitize_key( $type );
323
+		$type     = sanitize_key($type);
324 324
 		$address  = array();
325 325
 		$prepared = array();
326 326
 
327
-		if ( ! empty( $data[ $type ] ) ) {
328
-			$address = $data[ $type ];
327
+		if (!empty($data[$type])) {
328
+			$address = $data[$type];
329 329
 		}
330 330
 
331 331
 		// Clean address details.
332
-		foreach ( $address as $key => $value ) {
333
-			$key             = sanitize_key( $key );
334
-			$key             = str_replace( 'wpinv_', '', $key );
335
-			$value           = wpinv_clean( $value );
336
-			$prepared[ $key ] = apply_filters( "getpaid_checkout_{$type}_address_$key", $value, $this->payment_form_submission, $invoice );
332
+		foreach ($address as $key => $value) {
333
+			$key             = sanitize_key($key);
334
+			$key             = str_replace('wpinv_', '', $key);
335
+			$value           = wpinv_clean($value);
336
+			$prepared[$key] = apply_filters("getpaid_checkout_{$type}_address_$key", $value, $this->payment_form_submission, $invoice);
337 337
 		}
338 338
 
339 339
 		// Filter address details.
340
-		$prepared = apply_filters( "getpaid_checkout_{$type}_address", $prepared, $this->payment_form_submission, $invoice );
340
+		$prepared = apply_filters("getpaid_checkout_{$type}_address", $prepared, $this->payment_form_submission, $invoice);
341 341
 
342 342
 		// Remove non-whitelisted values.
343
-		return array_filter( $prepared, 'getpaid_is_address_field_whitelisted', ARRAY_FILTER_USE_KEY );
343
+		return array_filter($prepared, 'getpaid_is_address_field_whitelisted', ARRAY_FILTER_USE_KEY);
344 344
 
345 345
 	}
346 346
 
@@ -350,12 +350,12 @@  discard block
 block discarded – undo
350 350
 	 * @return array
351 351
 	 * @param WPInv_Invoice $invoice
352 352
      */
353
-    protected function prepare_billing_info( &$invoice ) {
353
+    protected function prepare_billing_info(&$invoice) {
354 354
 
355
-		$billing_address = $this->prepare_address_details( $invoice, 'billing' );
355
+		$billing_address = $this->prepare_address_details($invoice, 'billing');
356 356
 
357 357
 		// Update the invoice with the billing details.
358
-		$invoice->set_props( $billing_address );
358
+		$invoice->set_props($billing_address);
359 359
 
360 360
 	}
361 361
 
@@ -365,15 +365,15 @@  discard block
 block discarded – undo
365 365
 	 * @return array
366 366
 	 * @param WPInv_Invoice $invoice
367 367
      */
368
-    protected function prepare_shipping_info( $invoice ) {
368
+    protected function prepare_shipping_info($invoice) {
369 369
 
370 370
 		$data = $this->payment_form_submission->get_data();
371 371
 
372
-		if ( empty( $data['same-shipping-address'] ) ) {
373
-			return $this->prepare_address_details( $invoice, 'shipping' );
372
+		if (empty($data['same-shipping-address'])) {
373
+			return $this->prepare_address_details($invoice, 'shipping');
374 374
 		}
375 375
 
376
-		return $this->prepare_address_details( $invoice, 'billing' );
376
+		return $this->prepare_address_details($invoice, 'billing');
377 377
 
378 378
 	}
379 379
 
@@ -384,45 +384,45 @@  discard block
 block discarded – undo
384 384
 	 * @param array $prepared_payment_form_data
385 385
 	 * @param array $shipping
386 386
 	 */
387
-	protected function post_process_submission( $invoice, $prepared_payment_form_data, $shipping ) {
387
+	protected function post_process_submission($invoice, $prepared_payment_form_data, $shipping) {
388 388
 
389 389
 		// Ensure the invoice exists.
390
-        if ( ! $invoice->exists() ) {
391
-            wp_send_json_error( __( 'An error occured while saving your invoice. Please try again.', 'invoicing' ) );
390
+        if (!$invoice->exists()) {
391
+            wp_send_json_error(__('An error occured while saving your invoice. Please try again.', 'invoicing'));
392 392
         }
393 393
 
394 394
 		// Save payment form data.
395
-		$prepared_payment_form_data = apply_filters( 'getpaid_prepared_payment_form_data', $prepared_payment_form_data, $invoice );
396
-        delete_post_meta( $invoice->get_id(), 'payment_form_data' );
397
-		delete_post_meta( $invoice->get_id(), 'additional_meta_data' );
398
-		if ( ! empty( $prepared_payment_form_data ) ) {
395
+		$prepared_payment_form_data = apply_filters('getpaid_prepared_payment_form_data', $prepared_payment_form_data, $invoice);
396
+        delete_post_meta($invoice->get_id(), 'payment_form_data');
397
+		delete_post_meta($invoice->get_id(), 'additional_meta_data');
398
+		if (!empty($prepared_payment_form_data)) {
399 399
 
400
-			if ( ! empty( $prepared_payment_form_data['all'] ) ) {
401
-				update_post_meta( $invoice->get_id(), 'payment_form_data', $prepared_payment_form_data['all'] );
400
+			if (!empty($prepared_payment_form_data['all'])) {
401
+				update_post_meta($invoice->get_id(), 'payment_form_data', $prepared_payment_form_data['all']);
402 402
 			}
403 403
 
404
-			if ( ! empty( $prepared_payment_form_data['meta'] ) ) {
405
-				update_post_meta( $invoice->get_id(), 'additional_meta_data', $prepared_payment_form_data['meta'] );
404
+			if (!empty($prepared_payment_form_data['meta'])) {
405
+				update_post_meta($invoice->get_id(), 'additional_meta_data', $prepared_payment_form_data['meta']);
406 406
 			}
407 407
 		}
408 408
 
409 409
 		// Save payment form data.
410
-		$shipping = apply_filters( 'getpaid_checkout_shipping_details', $shipping, $this->payment_form_submission );
411
-        if ( ! empty( $shipping ) ) {
412
-            update_post_meta( $invoice->get_id(), 'shipping_address', $shipping );
410
+		$shipping = apply_filters('getpaid_checkout_shipping_details', $shipping, $this->payment_form_submission);
411
+        if (!empty($shipping)) {
412
+            update_post_meta($invoice->get_id(), 'shipping_address', $shipping);
413 413
 		}
414 414
 
415 415
 		// Backwards compatibility.
416
-        add_filter( 'wp_redirect', array( $this, 'send_redirect_response' ) );
416
+        add_filter('wp_redirect', array($this, 'send_redirect_response'));
417 417
 
418 418
 		try {
419
-			$this->process_payment( $invoice );
420
-		} catch ( Exception $e ) {
421
-			wpinv_set_error( 'payment_error', $e->getMessage() );
419
+			$this->process_payment($invoice);
420
+		} catch (Exception $e) {
421
+			wpinv_set_error('payment_error', $e->getMessage());
422 422
 		}
423 423
 
424 424
         // If we are here, there was an error.
425
-		wpinv_send_back_to_checkout( $invoice );
425
+		wpinv_send_back_to_checkout($invoice);
426 426
 
427 427
 	}
428 428
 
@@ -431,41 +431,41 @@  discard block
 block discarded – undo
431 431
 	 *
432 432
 	 * @param WPInv_Invoice $invoice
433 433
 	 */
434
-	protected function process_payment( $invoice ) {
434
+	protected function process_payment($invoice) {
435 435
 
436 436
 		// Clear any checkout errors.
437 437
 		wpinv_clear_errors();
438 438
 
439 439
 		// No need to send free invoices to the gateway.
440
-		if ( $invoice->is_free() ) {
441
-			$this->process_free_payment( $invoice );
440
+		if ($invoice->is_free()) {
441
+			$this->process_free_payment($invoice);
442 442
 		}
443 443
 
444 444
 		$submission = $this->payment_form_submission;
445 445
 
446 446
 		// Fires before sending to the gateway.
447
-		do_action( 'getpaid_checkout_before_gateway', $invoice, $submission );
447
+		do_action('getpaid_checkout_before_gateway', $invoice, $submission);
448 448
 
449 449
 		// Allow the sumission data to be modified before it is sent to the gateway.
450 450
 		$submission_data    = $submission->get_data();
451
-		$submission_gateway = apply_filters( 'getpaid_gateway_submission_gateway', $invoice->get_gateway(), $submission, $invoice );
452
-		$submission_data    = apply_filters( 'getpaid_gateway_submission_data', $submission_data, $submission, $invoice );
451
+		$submission_gateway = apply_filters('getpaid_gateway_submission_gateway', $invoice->get_gateway(), $submission, $invoice);
452
+		$submission_data    = apply_filters('getpaid_gateway_submission_data', $submission_data, $submission, $invoice);
453 453
 
454 454
 		// Validate the currency.
455
-		if ( ! apply_filters( "getpaid_gateway_{$submission_gateway}_is_valid_for_currency", true, $invoice->get_currency() ) ) {
456
-			wpinv_set_error( 'invalid_currency' );
455
+		if (!apply_filters("getpaid_gateway_{$submission_gateway}_is_valid_for_currency", true, $invoice->get_currency())) {
456
+			wpinv_set_error('invalid_currency');
457 457
 		}
458 458
 
459 459
 		// Check to see if we have any errors.
460
-		if ( wpinv_get_errors() ) {
461
-			wpinv_send_back_to_checkout( $invoice );
460
+		if (wpinv_get_errors()) {
461
+			wpinv_send_back_to_checkout($invoice);
462 462
 		}
463 463
 
464 464
 		// Send info to the gateway for payment processing
465
-		do_action( "getpaid_gateway_$submission_gateway", $invoice, $submission_data, $submission );
465
+		do_action("getpaid_gateway_$submission_gateway", $invoice, $submission_data, $submission);
466 466
 
467 467
 		// Backwards compatibility.
468
-		wpinv_send_to_gateway( $submission_gateway, $invoice );
468
+		wpinv_send_to_gateway($submission_gateway, $invoice);
469 469
 
470 470
 	}
471 471
 
@@ -474,12 +474,12 @@  discard block
 block discarded – undo
474 474
 	 *
475 475
 	 * @param WPInv_Invoice $invoice
476 476
 	 */
477
-	protected function process_free_payment( $invoice ) {
477
+	protected function process_free_payment($invoice) {
478 478
 
479
-		$invoice->set_gateway( 'none' );
480
-		$invoice->add_note( __( "This is a free invoice and won't be sent to the payment gateway", 'invoicing' ), false, false, true );
479
+		$invoice->set_gateway('none');
480
+		$invoice->add_note(__("This is a free invoice and won't be sent to the payment gateway", 'invoicing'), false, false, true);
481 481
 		$invoice->mark_paid();
482
-		wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) );
482
+		wpinv_send_to_success_page(array('invoice_key' => $invoice->get_key()));
483 483
 
484 484
 	}
485 485
 
@@ -487,9 +487,9 @@  discard block
 block discarded – undo
487 487
      * Sends a redrect response to payment details.
488 488
      *
489 489
      */
490
-    public function send_redirect_response( $url ) {
491
-        $url = rawurlencode( $url );
492
-        wp_send_json_success( $url );
490
+    public function send_redirect_response($url) {
491
+        $url = rawurlencode($url);
492
+        wp_send_json_success($url);
493 493
     }
494 494
 
495 495
 }
Please login to merge, or discard this patch.
includes/admin/meta-boxes/class-getpaid-meta-box-invoice-items.php 2 patches
Indentation   +150 added lines, -150 removed lines patch added patch discarded remove patch
@@ -8,7 +8,7 @@  discard block
 block discarded – undo
8 8
  */
9 9
 
10 10
 if ( ! defined( 'ABSPATH' ) ) {
11
-	exit; // Exit if accessed directly
11
+    exit; // Exit if accessed directly
12 12
 }
13 13
 
14 14
 /**
@@ -75,16 +75,16 @@  discard block
 block discarded – undo
75 75
             $class .= ' wpi-recurring';
76 76
         }
77 77
 
78
-		$refund_url = wp_nonce_url(
79
-			add_query_arg(
80
-				array(
81
-					'getpaid-admin-action' => 'refund_invoice',
82
-					'invoice_id'           => $invoice->get_id(),
83
-				)
84
-			),
85
-			'getpaid-nonce',
86
-			'getpaid-nonce'
87
-		);
78
+        $refund_url = wp_nonce_url(
79
+            add_query_arg(
80
+                array(
81
+                    'getpaid-admin-action' => 'refund_invoice',
82
+                    'invoice_id'           => $invoice->get_id(),
83
+                )
84
+            ),
85
+            'getpaid-nonce',
86
+            'getpaid-nonce'
87
+        );
88 88
     ?>
89 89
 
90 90
         <div class="wpinv-items-wrap<?php echo esc_attr( $class ); ?>" id="wpinv_items_wrap" data-status="<?php echo esc_attr( $invoice->get_status() ); ?>">
@@ -96,8 +96,8 @@  discard block
 block discarded – undo
96 96
                             <th class="
97 97
                             <?php
98 98
                             echo esc_attr( $key );
99
-							echo 'total' == $key || 'qty' == $key ? ' hide-if-amount' : '';
100
-							?>
99
+                            echo 'total' == $key || 'qty' == $key ? ' hide-if-amount' : '';
100
+                            ?>
101 101
 							"><?php echo wp_kses_post( $label ); ?></th>
102 102
                         <?php endforeach; ?>
103 103
                     </tr>
@@ -106,7 +106,7 @@  discard block
 block discarded – undo
106 106
                 <tbody class="wpinv-line-items">
107 107
                     <?php
108 108
                         foreach ( $invoice->get_items() as $int => $item ) {
109
-						self::output_row( $columns, $item, $invoice, $int % 2 == 0 ? 'even' : 'odd' );
109
+                        self::output_row( $columns, $item, $invoice, $int % 2 == 0 ? 'even' : 'odd' );
110 110
                         }
111 111
                     ?>
112 112
                 </tbody>
@@ -151,13 +151,13 @@  discard block
 block discarded – undo
151 151
                                                         <?php
152 152
                                                         wpinv_html_select(
153 153
                                                             array(
154
-																'options'          => $item_types,
155
-																'name'             => '_wpinv_quick[type]',
156
-																'id'               => '_wpinv_quick_type',
157
-																'selected'         => 'custom',
158
-																'show_option_all'  => false,
159
-																'show_option_none' => false,
160
-																'class'            => 'gdmbx2-text-medium wpinv-quick-type',
154
+                                                                'options'          => $item_types,
155
+                                                                'name'             => '_wpinv_quick[type]',
156
+                                                                'id'               => '_wpinv_quick_type',
157
+                                                                'selected'         => 'custom',
158
+                                                                'show_option_all'  => false,
159
+                                                                'show_option_none' => false,
160
+                                                                'class'            => 'gdmbx2-text-medium wpinv-quick-type',
161 161
                                                             )
162 162
                                                         );
163 163
                                                             ?>
@@ -172,16 +172,16 @@  discard block
 block discarded – undo
172 172
                                                             <?php
173 173
                                                                 wpinv_html_select(
174 174
                                                                     array(
175
-																		'options'          => array_merge(
176
-																			array( '' => __( 'Select VAT Rule', 'invoicing' ) ),
177
-																			getpaid_get_tax_rules()
178
-																		),
179
-																		'name'             => '_wpinv_quick[vat_rule]',
180
-																		'id'               => '_wpinv_quick_vat_rule',
181
-																		'show_option_all'  => false,
182
-																		'show_option_none' => false,
183
-																		'class'            => 'gdmbx2-text-medium wpinv-quick-vat-rule',
184
-																		'selected'         => 'digital',
175
+                                                                        'options'          => array_merge(
176
+                                                                            array( '' => __( 'Select VAT Rule', 'invoicing' ) ),
177
+                                                                            getpaid_get_tax_rules()
178
+                                                                        ),
179
+                                                                        'name'             => '_wpinv_quick[vat_rule]',
180
+                                                                        'id'               => '_wpinv_quick_vat_rule',
181
+                                                                        'show_option_all'  => false,
182
+                                                                        'show_option_none' => false,
183
+                                                                        'class'            => 'gdmbx2-text-medium wpinv-quick-vat-rule',
184
+                                                                        'selected'         => 'digital',
185 185
                                                                     )
186 186
                                                                 );
187 187
                                                             ?>
@@ -194,16 +194,16 @@  discard block
 block discarded – undo
194 194
                                                             <?php
195 195
                                                                 wpinv_html_select(
196 196
                                                                     array(
197
-																		'options'          => array_merge(
198
-																			array( '' => __( 'Select VAT Class', 'invoicing' ) ),
199
-																			getpaid_get_tax_classes()
200
-																		),
201
-																		'name'             => '_wpinv_quick[vat_class]',
202
-																		'id'               => '_wpinv_quick_vat_class',
203
-																		'show_option_all'  => false,
204
-																		'show_option_none' => false,
205
-																		'class'            => 'gdmbx2-text-medium wpinv-quick-vat-class',
206
-																		'selected'         => '_standard',
197
+                                                                        'options'          => array_merge(
198
+                                                                            array( '' => __( 'Select VAT Class', 'invoicing' ) ),
199
+                                                                            getpaid_get_tax_classes()
200
+                                                                        ),
201
+                                                                        'name'             => '_wpinv_quick[vat_class]',
202
+                                                                        'id'               => '_wpinv_quick_vat_class',
203
+                                                                        'show_option_all'  => false,
204
+                                                                        'show_option_none' => false,
205
+                                                                        'class'            => 'gdmbx2-text-medium wpinv-quick-vat-class',
206
+                                                                        'selected'         => '_standard',
207 207
                                                                     )
208 208
                                                                 );
209 209
                                                             ?>
@@ -294,37 +294,37 @@  discard block
 block discarded – undo
294 294
 								</p>
295 295
 								<?php if ( getpaid_payment_gateway_supports( $invoice->get_gateway(), 'refunds' ) ) : ?>
296 296
 									<?php
297
-										aui()->input(
298
-											array(
299
-												'type'  => 'checkbox',
300
-												'name'  => 'getpaid_refund_remote',
301
-												'id'    => 'getpaid_refund_remote',
302
-												'label' => sprintf(
303
-													'Refund payment in %s',
304
-													wpinv_get_gateway_admin_label( $invoice->get_gateway() )
305
-												),
306
-												'value' => 1,
307
-												'class' => 'getpaid-refund-field',
308
-											),
309
-											true
310
-										);
311
-									?>
297
+                                        aui()->input(
298
+                                            array(
299
+                                                'type'  => 'checkbox',
300
+                                                'name'  => 'getpaid_refund_remote',
301
+                                                'id'    => 'getpaid_refund_remote',
302
+                                                'label' => sprintf(
303
+                                                    'Refund payment in %s',
304
+                                                    wpinv_get_gateway_admin_label( $invoice->get_gateway() )
305
+                                                ),
306
+                                                'value' => 1,
307
+                                                'class' => 'getpaid-refund-field',
308
+                                            ),
309
+                                            true
310
+                                        );
311
+                                    ?>
312 312
 								<?php endif; ?>
313 313
 
314 314
 								<?php if ( getpaid_get_invoice_subscriptions( $invoice ) ) : ?>
315 315
 									<?php
316
-										aui()->input(
317
-											array(
318
-												'type'  => 'checkbox',
319
-												'name'  => 'getpaid_cancel_subscription',
320
-												'id'    => 'getpaid_cancel_subscription',
321
-												'label' => __( 'Cancel subscription', 'invoicing' ),
322
-												'value' => 1,
323
-												'class' => 'getpaid-refund-field',
324
-											),
325
-											true
326
-										);
327
-									?>
316
+                                        aui()->input(
317
+                                            array(
318
+                                                'type'  => 'checkbox',
319
+                                                'name'  => 'getpaid_cancel_subscription',
320
+                                                'id'    => 'getpaid_cancel_subscription',
321
+                                                'label' => __( 'Cancel subscription', 'invoicing' ),
322
+                                                'value' => 1,
323
+                                                'class' => 'getpaid-refund-field',
324
+                                            ),
325
+                                            true
326
+                                        );
327
+                                    ?>
328 328
 								<?php endif; ?>
329 329
                             </div>
330 330
                             <div class="modal-footer">
@@ -364,23 +364,23 @@  discard block
 block discarded – undo
364 364
                 <?php
365 365
                     if ( $invoice->is_paid() ) {
366 366
 
367
-						printf(
368
-							'<span class="bsui"><button type="button" class="button button-primary" data-toggle="modal" data-bs-toggle="modal" data-bs-target="#getpaid-refund-invoice-modal" data-target="#getpaid-refund-invoice-modal">%s</button></span>',
369
-							esc_html__( 'Refund', 'invoicing' )
370
-						);
367
+                        printf(
368
+                            '<span class="bsui"><button type="button" class="button button-primary" data-toggle="modal" data-bs-toggle="modal" data-bs-target="#getpaid-refund-invoice-modal" data-target="#getpaid-refund-invoice-modal">%s</button></span>',
369
+                            esc_html__( 'Refund', 'invoicing' )
370
+                        );
371 371
                     } elseif ( ! $invoice->is_refunded() ) {
372
-						wpinv_item_dropdown(
373
-							array(
374
-								'name'           => 'wpinv_invoice_item',
375
-								'id'             => 'wpinv_invoice_item',
376
-								'show_recurring' => true,
377
-								'class'          => 'wpi_select2',
378
-							)
379
-						);
380
-
381
-						echo '&nbsp;' . '<button type="button" class="button button-primary" id="wpinv-add-item">' . sprintf( esc_html__( 'Add item to %s', 'invoicing' ), esc_html( $invoice->get_label() ) ) . '</button>';
382
-						echo '&nbsp;' . '<button type="button" class="button button-primary" id="wpinv-new-item">' . esc_html__( 'Create new item', 'invoicing' ) . '</button>';
383
-						echo '&nbsp;' . '<button type="button" class="button button-primary wpinv-flr" id="wpinv-recalc-totals">' . esc_html__( 'Recalculate Totals', 'invoicing' ) . '</button>';
372
+                        wpinv_item_dropdown(
373
+                            array(
374
+                                'name'           => 'wpinv_invoice_item',
375
+                                'id'             => 'wpinv_invoice_item',
376
+                                'show_recurring' => true,
377
+                                'class'          => 'wpi_select2',
378
+                            )
379
+                        );
380
+
381
+                        echo '&nbsp;' . '<button type="button" class="button button-primary" id="wpinv-add-item">' . sprintf( esc_html__( 'Add item to %s', 'invoicing' ), esc_html( $invoice->get_label() ) ) . '</button>';
382
+                        echo '&nbsp;' . '<button type="button" class="button button-primary" id="wpinv-new-item">' . esc_html__( 'Create new item', 'invoicing' ) . '</button>';
383
+                        echo '&nbsp;' . '<button type="button" class="button button-primary wpinv-flr" id="wpinv-recalc-totals">' . esc_html__( 'Recalculate Totals', 'invoicing' ) . '</button>';
384 384
 
385 385
                     }
386 386
                 ?>
@@ -397,72 +397,72 @@  discard block
 block discarded – undo
397 397
             <?php foreach ( array_keys( $columns ) as $column ) : ?>
398 398
                 <td class="
399 399
 					<?php
400
-						echo esc_attr( $column );
401
-						echo 'total' == $column || 'qty' == $column ? ' hide-if-amount' : '';
402
-					?>
400
+                        echo esc_attr( $column );
401
+                        echo 'total' == $column || 'qty' == $column ? ' hide-if-amount' : '';
402
+                    ?>
403 403
 				">
404 404
                     <?php
405 405
                         switch ( $column ) {
406
-						case 'id':
407
-							echo (int) $item->get_id();
408
-							break;
409
-						case 'title':
410
-							printf(
411
-								'<a href="%s" target="_blank">%s</a>',
412
-								esc_url( get_edit_post_link( $item->get_id() ) ),
413
-								esc_html( $item->get_raw_name() )
414
-							);
415
-
416
-							$summary = apply_filters( 'getpaid_admin_invoice_line_item_summary', $item->get_description(), $item, $invoice );
417
-							if ( $summary !== '' ) {
418
-								printf(
419
-									'<span class="meta">%s</span>',
420
-									wp_kses_post( wpautop( $summary ) )
421
-								);
422
-							}
423
-
424
-							printf(
425
-								'<input type="hidden" value="%s" name="getpaid_items[%s][name]" class="getpaid-recalculate-prices-on-change" />',
426
-								esc_attr( $item->get_raw_name() ),
427
-								(int) $item->get_id()
428
-							);
429
-
430
-							printf(
431
-								'<textarea style="display: none;" name="getpaid_items[%s][description]" class="getpaid-recalculate-prices-on-change">%s</textarea>',
432
-								(int) $item->get_id(),
433
-								esc_attr( $item->get_description() )
434
-							);
435
-
436
-							break;
437
-						case 'price':
438
-							printf(
439
-								'<input type="text" value="%s" name="getpaid_items[%s][price]" style="width: 100px;" class="getpaid-admin-invoice-item-price getpaid-recalculate-prices-on-change" />',
440
-								esc_attr( getpaid_unstandardize_amount( $item->get_price() ) ),
441
-								(int) $item->get_id()
442
-							);
443
-
444
-							break;
445
-						case 'qty':
446
-							printf(
447
-								'<input type="text" style="width: 100px;" value="%s" name="getpaid_items[%s][quantity]" class="getpaid-admin-invoice-item-quantity getpaid-recalculate-prices-on-change" />',
448
-								floatval( $item->get_quantity() ),
449
-								(int) $item->get_id()
450
-							);
451
-
452
-							break;
453
-						case 'total':
454
-							wpinv_the_price( $item->get_sub_total(), $invoice->get_currency() );
455
-
456
-							break;
457
-						case 'tax':
458
-							echo floatval( wpinv_round_amount( getpaid_get_invoice_tax_rate( $invoice, $item ), 2 ) ) . '%';
459
-
460
-							break;
461
-						case 'action':
462
-							if ( ! $invoice->is_paid() && ! $invoice->is_refunded() ) {
463
-								echo '<i class="fa fa-trash wpinv-item-remove"></i>';
406
+                        case 'id':
407
+                            echo (int) $item->get_id();
408
+                            break;
409
+                        case 'title':
410
+                            printf(
411
+                                '<a href="%s" target="_blank">%s</a>',
412
+                                esc_url( get_edit_post_link( $item->get_id() ) ),
413
+                                esc_html( $item->get_raw_name() )
414
+                            );
415
+
416
+                            $summary = apply_filters( 'getpaid_admin_invoice_line_item_summary', $item->get_description(), $item, $invoice );
417
+                            if ( $summary !== '' ) {
418
+                                printf(
419
+                                    '<span class="meta">%s</span>',
420
+                                    wp_kses_post( wpautop( $summary ) )
421
+                                );
422
+                            }
423
+
424
+                            printf(
425
+                                '<input type="hidden" value="%s" name="getpaid_items[%s][name]" class="getpaid-recalculate-prices-on-change" />',
426
+                                esc_attr( $item->get_raw_name() ),
427
+                                (int) $item->get_id()
428
+                            );
429
+
430
+                            printf(
431
+                                '<textarea style="display: none;" name="getpaid_items[%s][description]" class="getpaid-recalculate-prices-on-change">%s</textarea>',
432
+                                (int) $item->get_id(),
433
+                                esc_attr( $item->get_description() )
434
+                            );
435
+
436
+                            break;
437
+                        case 'price':
438
+                            printf(
439
+                                '<input type="text" value="%s" name="getpaid_items[%s][price]" style="width: 100px;" class="getpaid-admin-invoice-item-price getpaid-recalculate-prices-on-change" />',
440
+                                esc_attr( getpaid_unstandardize_amount( $item->get_price() ) ),
441
+                                (int) $item->get_id()
442
+                            );
443
+
444
+                            break;
445
+                        case 'qty':
446
+                            printf(
447
+                                '<input type="text" style="width: 100px;" value="%s" name="getpaid_items[%s][quantity]" class="getpaid-admin-invoice-item-quantity getpaid-recalculate-prices-on-change" />',
448
+                                floatval( $item->get_quantity() ),
449
+                                (int) $item->get_id()
450
+                            );
451
+
452
+                            break;
453
+                        case 'total':
454
+                            wpinv_the_price( $item->get_sub_total(), $invoice->get_currency() );
455
+
456
+                            break;
457
+                        case 'tax':
458
+                            echo floatval( wpinv_round_amount( getpaid_get_invoice_tax_rate( $invoice, $item ), 2 ) ) . '%';
459
+
460
+                            break;
461
+                        case 'action':
462
+                            if ( ! $invoice->is_paid() && ! $invoice->is_refunded() ) {
463
+                                echo '<i class="fa fa-trash wpinv-item-remove"></i>';
464 464
                                 }
465
-							break;
465
+                            break;
466 466
                         }
467 467
                         do_action( 'getpaid_admin_edit_invoice_item_' . $column, $item, $invoice );
468 468
                     ?>
@@ -473,10 +473,10 @@  discard block
 block discarded – undo
473 473
     }
474 474
 
475 475
     /**
476
-	 * Output the metabox.
477
-	 *
478
-	 * @param WP_Post $post
479
-	 */
476
+     * Output the metabox.
477
+     *
478
+     * @param WP_Post $post
479
+     */
480 480
     public static function output2( $post ) {
481 481
 
482 482
         // Prepare the invoice.
Please login to merge, or discard this patch.
Spacing   +168 added lines, -168 removed lines patch added patch discarded remove patch
@@ -7,7 +7,7 @@  discard block
 block discarded – undo
7 7
  *
8 8
  */
9 9
 
10
-if ( ! defined( 'ABSPATH' ) ) {
10
+if (!defined('ABSPATH')) {
11 11
 	exit; // Exit if accessed directly
12 12
 }
13 13
 
@@ -16,62 +16,62 @@  discard block
 block discarded – undo
16 16
  */
17 17
 class GetPaid_Meta_Box_Invoice_Items {
18 18
 
19
-    public static function get_columns( $invoice ) {
19
+    public static function get_columns($invoice) {
20 20
         $use_taxes = $invoice->is_taxable() && wpinv_use_taxes();
21 21
         $columns   = array(
22
-            'id'     => __( 'ID', 'invoicing' ),
23
-            'title'  => __( 'Item', 'invoicing' ),
22
+            'id'     => __('ID', 'invoicing'),
23
+            'title'  => __('Item', 'invoicing'),
24 24
             'price'  => sprintf(
25 25
                 '<span class="getpaid-hide-if-hours getpaid-hide-if-quantity">%s</span>
26 26
                 <span class="getpaid-hide-if-hours hide-if-amount">%s</span>
27 27
                 <span class="getpaid-hide-if-quantity hide-if-amount">%s</span>',
28
-                __( 'Amount', 'invoicing' ),
29
-                __( 'Price', 'invoicing' ),
30
-                __( 'Rate', 'invoicing' )
28
+                __('Amount', 'invoicing'),
29
+                __('Price', 'invoicing'),
30
+                __('Rate', 'invoicing')
31 31
             ),
32 32
             'qty'    => sprintf(
33 33
                 '<span class="getpaid-hide-if-hours">%s</span><span class="getpaid-hide-if-quantity">%s</span>',
34
-                __( 'Quantity', 'invoicing' ),
35
-                __( 'Hours', 'invoicing' )
34
+                __('Quantity', 'invoicing'),
35
+                __('Hours', 'invoicing')
36 36
             ),
37
-            'total'  => __( 'Total', 'invoicing' ),
38
-            'tax'    => __( 'Tax (%)', 'invoicing' ),
37
+            'total'  => __('Total', 'invoicing'),
38
+            'tax'    => __('Tax (%)', 'invoicing'),
39 39
             'action' => '',
40 40
         );
41 41
 
42
-        if ( ! $use_taxes ) {
43
-            unset( $columns['tax'] );
42
+        if (!$use_taxes) {
43
+            unset($columns['tax']);
44 44
         }
45 45
 
46 46
         return $columns;
47 47
     }
48 48
 
49
-    public static function output( $post, $invoice = false ) {
49
+    public static function output($post, $invoice = false) {
50 50
 
51
-        if ( apply_filters( 'getpaid_use_new_invoice_items_metabox', false ) ) {
52
-            return self::output2( $post );
51
+        if (apply_filters('getpaid_use_new_invoice_items_metabox', false)) {
52
+            return self::output2($post);
53 53
         }
54 54
 
55
-        $post_id    = ! empty( $post->ID ) ? $post->ID : 0;
56
-        $invoice    = $invoice instanceof WPInv_Invoice ? $invoice : new WPInv_Invoice( $post_id );
55
+        $post_id    = !empty($post->ID) ? $post->ID : 0;
56
+        $invoice    = $invoice instanceof WPInv_Invoice ? $invoice : new WPInv_Invoice($post_id);
57 57
         $use_taxes  = $invoice->is_taxable() && wpinv_use_taxes();
58
-        $item_types = apply_filters( 'wpinv_item_types_for_quick_add_item', wpinv_get_item_types(), $post );
59
-        $columns    = self::get_columns( $invoice );
60
-        $cols       = count( $columns );
58
+        $item_types = apply_filters('wpinv_item_types_for_quick_add_item', wpinv_get_item_types(), $post);
59
+        $columns    = self::get_columns($invoice);
60
+        $cols       = count($columns);
61 61
         $class      = '';
62 62
 
63
-        unset( $item_types['adv'] );
64
-        unset( $item_types['package'] );
63
+        unset($item_types['adv']);
64
+        unset($item_types['package']);
65 65
 
66
-        if ( $invoice->is_paid() ) {
66
+        if ($invoice->is_paid()) {
67 67
             $class .= ' wpinv-paid';
68 68
         }
69 69
 
70
-        if ( $invoice->is_refunded() ) {
70
+        if ($invoice->is_refunded()) {
71 71
             $class .= ' wpinv-refunded';
72 72
         }
73 73
 
74
-        if ( $invoice->is_recurring() ) {
74
+        if ($invoice->is_recurring()) {
75 75
             $class .= ' wpi-recurring';
76 76
         }
77 77
 
@@ -87,26 +87,26 @@  discard block
 block discarded – undo
87 87
 		);
88 88
     ?>
89 89
 
90
-        <div class="wpinv-items-wrap<?php echo esc_attr( $class ); ?>" id="wpinv_items_wrap" data-status="<?php echo esc_attr( $invoice->get_status() ); ?>">
90
+        <div class="wpinv-items-wrap<?php echo esc_attr($class); ?>" id="wpinv_items_wrap" data-status="<?php echo esc_attr($invoice->get_status()); ?>">
91 91
             <table id="wpinv_items" class="wpinv-items" cellspacing="0" cellpadding="0">
92 92
 
93 93
                 <thead>
94 94
                     <tr>
95
-                        <?php foreach ( $columns as $key => $label ) : ?>
95
+                        <?php foreach ($columns as $key => $label) : ?>
96 96
                             <th class="
97 97
                             <?php
98
-                            echo esc_attr( $key );
98
+                            echo esc_attr($key);
99 99
 							echo 'total' == $key || 'qty' == $key ? ' hide-if-amount' : '';
100 100
 							?>
101
-							"><?php echo wp_kses_post( $label ); ?></th>
101
+							"><?php echo wp_kses_post($label); ?></th>
102 102
                         <?php endforeach; ?>
103 103
                     </tr>
104 104
                 </thead>
105 105
 
106 106
                 <tbody class="wpinv-line-items">
107 107
                     <?php
108
-                        foreach ( $invoice->get_items() as $int => $item ) {
109
-						self::output_row( $columns, $item, $invoice, $int % 2 == 0 ? 'even' : 'odd' );
108
+                        foreach ($invoice->get_items() as $int => $item) {
109
+						self::output_row($columns, $item, $invoice, $int % 2 == 0 ? 'even' : 'odd');
110 110
                         }
111 111
                     ?>
112 112
                 </tbody>
@@ -123,7 +123,7 @@  discard block
 block discarded – undo
123 123
                                             <div class="wp-clearfix">
124 124
                                                 <label class="wpi-item-name">
125 125
                                                     <span class="input-text-wrap">
126
-                                                        <input type="text" style="width: 100%" placeholder="<?php esc_attr_e( 'Item Name', 'invoicing' ); ?>" class="wpinv-quick-item-name" name="_wpinv_quick[name]">
126
+                                                        <input type="text" style="width: 100%" placeholder="<?php esc_attr_e('Item Name', 'invoicing'); ?>" class="wpinv-quick-item-name" name="_wpinv_quick[name]">
127 127
                                                     </span>
128 128
                                                 </label>
129 129
                                             </div>
@@ -131,8 +131,8 @@  discard block
 block discarded – undo
131 131
                                             <div class="wp-clearfix">
132 132
                                                 <label class="wpi-item-price">
133 133
                                                     <span class="input-text-wrap">
134
-                                                    <input type="text" style="width: 200px" placeholder="<?php esc_attr_e( 'Item Price', 'invoicing' ); ?>" class="wpinv-quick-item-price" name="_wpinv_quick[price]">
135
-                                                        &times; <input type="text" style="width: 140px" placeholder="<?php esc_attr_e( 'Item Quantity', 'invoicing' ); ?>" class="wpinv-quick-item-qty" name="_wpinv_quick[qty]">
134
+                                                    <input type="text" style="width: 200px" placeholder="<?php esc_attr_e('Item Price', 'invoicing'); ?>" class="wpinv-quick-item-price" name="_wpinv_quick[price]">
135
+                                                        &times; <input type="text" style="width: 140px" placeholder="<?php esc_attr_e('Item Quantity', 'invoicing'); ?>" class="wpinv-quick-item-qty" name="_wpinv_quick[qty]">
136 136
                                                     </span>
137 137
                                                 </label>
138 138
                                             </div>
@@ -140,7 +140,7 @@  discard block
 block discarded – undo
140 140
                                             <div class="wp-clearfix">
141 141
                                                 <label class="wpi-item-name">
142 142
                                                     <span class="input-text-wrap">
143
-                                                        <textarea rows="4" style="width: 100%" placeholder="<?php esc_attr_e( 'Item Description', 'invoicing' ); ?>" class="wpinv-quick-item-description" name="_wpinv_quick[description]"></textarea>
143
+                                                        <textarea rows="4" style="width: 100%" placeholder="<?php esc_attr_e('Item Description', 'invoicing'); ?>" class="wpinv-quick-item-description" name="_wpinv_quick[description]"></textarea>
144 144
                                                     </span>
145 145
                                                 </label>
146 146
                                             </div>
@@ -165,7 +165,7 @@  discard block
 block discarded – undo
165 165
                                                 </label>
166 166
                                             </div>
167 167
 
168
-                                            <?php if ( $use_taxes ) : ?>
168
+                                            <?php if ($use_taxes) : ?>
169 169
                                                 <div class="wp-clearfix">
170 170
                                                     <label class="wpi-vat-rule">
171 171
                                                         <span class="input-text-wrap">
@@ -173,7 +173,7 @@  discard block
 block discarded – undo
173 173
                                                                 wpinv_html_select(
174 174
                                                                     array(
175 175
 																		'options'          => array_merge(
176
-																			array( '' => __( 'Select VAT Rule', 'invoicing' ) ),
176
+																			array('' => __('Select VAT Rule', 'invoicing')),
177 177
 																			getpaid_get_tax_rules()
178 178
 																		),
179 179
 																		'name'             => '_wpinv_quick[vat_rule]',
@@ -195,7 +195,7 @@  discard block
 block discarded – undo
195 195
                                                                 wpinv_html_select(
196 196
                                                                     array(
197 197
 																		'options'          => array_merge(
198
-																			array( '' => __( 'Select VAT Class', 'invoicing' ) ),
198
+																			array('' => __('Select VAT Class', 'invoicing')),
199 199
 																			getpaid_get_tax_classes()
200 200
 																		),
201 201
 																		'name'             => '_wpinv_quick[vat_class]',
@@ -219,7 +219,7 @@  discard block
 block discarded – undo
219 219
                                                             'type'    => 'checkbox',
220 220
                                                             'name'    => '_wpinv_quick[one-time]',
221 221
                                                             'id'      => '_wpinv_quick-one-time',
222
-                                                            'label'   => __( "One time item (won't be saved to regular items list)", 'invoicing' ),
222
+                                                            'label'   => __("One time item (won't be saved to regular items list)", 'invoicing'),
223 223
                                                             'value'   => 1,
224 224
                                                             'no_wrap' => true,
225 225
                                                             'checked' => false,
@@ -243,29 +243,29 @@  discard block
 block discarded – undo
243 243
                         </td>
244 244
                     </tr>
245 245
                     <tr class="totals">
246
-                        <td colspan="<?php echo ( (int) $cols - 4 ); ?>"></td>
246
+                        <td colspan="<?php echo ((int) $cols - 4); ?>"></td>
247 247
                         <td colspan="4">
248 248
                             <table cellspacing="0" cellpadding="0">
249 249
                                 <tr class="subtotal">
250
-                                    <td class="name"><?php esc_html_e( 'Sub Total:', 'invoicing' ); ?></td>
251
-                                    <td class="total"><?php wpinv_the_price( $invoice->get_subtotal(), $invoice->get_currency() ); ?></td>
250
+                                    <td class="name"><?php esc_html_e('Sub Total:', 'invoicing'); ?></td>
251
+                                    <td class="total"><?php wpinv_the_price($invoice->get_subtotal(), $invoice->get_currency()); ?></td>
252 252
                                     <td class="action"></td>
253 253
                                 </tr>
254 254
                                 <tr class="discount">
255
-                                    <td class="name"><?php esc_html_e( 'Discount:', 'invoicing' ); ?></td>
256
-                                    <td class="total"><?php wpinv_the_price( $invoice->get_total_discount(), $invoice->get_currency() ); ?></td>
255
+                                    <td class="name"><?php esc_html_e('Discount:', 'invoicing'); ?></td>
256
+                                    <td class="total"><?php wpinv_the_price($invoice->get_total_discount(), $invoice->get_currency()); ?></td>
257 257
                                     <td class="action"></td>
258 258
                                 </tr>
259
-                                <?php if ( $use_taxes ) : ?>
259
+                                <?php if ($use_taxes) : ?>
260 260
                                 <tr class="tax">
261
-                                    <td class="name"><?php esc_html_e( 'Tax:', 'invoicing' ); ?></td>
262
-                                    <td class="total"><?php wpinv_the_price( $invoice->get_total_tax(), $invoice->get_currency() ); ?></td>
261
+                                    <td class="name"><?php esc_html_e('Tax:', 'invoicing'); ?></td>
262
+                                    <td class="total"><?php wpinv_the_price($invoice->get_total_tax(), $invoice->get_currency()); ?></td>
263 263
                                     <td class="action"></td>
264 264
                                 </tr>
265 265
                                 <?php endif; ?>
266 266
                                 <tr class="total">
267
-                                    <td class="name"><?php esc_html_e( 'Total:', 'invoicing' ); ?></td>
268
-                                    <td class="total"><?php wpinv_the_price( $invoice->get_total(), $invoice->get_currency() ); ?></td>
267
+                                    <td class="name"><?php esc_html_e('Total:', 'invoicing'); ?></td>
268
+                                    <td class="total"><?php wpinv_the_price($invoice->get_total(), $invoice->get_currency()); ?></td>
269 269
                                     <td class="action"></td>
270 270
                                 </tr>
271 271
                             </table>
@@ -281,18 +281,18 @@  discard block
 block discarded – undo
281 281
                      <div class="modal-dialog modal-dialog-centered" role="document">
282 282
                         <div class="modal-content">
283 283
                             <div class="modal-header">
284
-                                <h5 class="modal-title" id="getpaid-refund-invoice-modal-label"><?php esc_html_e( 'Refund Payment', 'invoicing' ); ?></h5>
285
-                                <button type="button" class="close btn-close" data-bs-dismiss="modal" data-dismiss="modal" aria-label="<?php esc_html_e( 'Close', 'invoicing' ); ?>">
286
-                                    <?php if ( empty( $GLOBALS['aui_bs5'] ) ) : ?>
284
+                                <h5 class="modal-title" id="getpaid-refund-invoice-modal-label"><?php esc_html_e('Refund Payment', 'invoicing'); ?></h5>
285
+                                <button type="button" class="close btn-close" data-bs-dismiss="modal" data-dismiss="modal" aria-label="<?php esc_html_e('Close', 'invoicing'); ?>">
286
+                                    <?php if (empty($GLOBALS['aui_bs5'])) : ?>
287 287
                                         <span aria-hidden="true">×</span>
288 288
                                     <?php endif; ?>
289 289
                                 </button>
290 290
                             </div>
291 291
                             <div class="modal-body">
292 292
 								<p>
293
-									<?php esc_html_e( 'Are you sure you want to refund this payment?', 'invoicing' ); ?>
293
+									<?php esc_html_e('Are you sure you want to refund this payment?', 'invoicing'); ?>
294 294
 								</p>
295
-								<?php if ( getpaid_payment_gateway_supports( $invoice->get_gateway(), 'refunds' ) ) : ?>
295
+								<?php if (getpaid_payment_gateway_supports($invoice->get_gateway(), 'refunds')) : ?>
296 296
 									<?php
297 297
 										aui()->input(
298 298
 											array(
@@ -301,7 +301,7 @@  discard block
 block discarded – undo
301 301
 												'id'    => 'getpaid_refund_remote',
302 302
 												'label' => sprintf(
303 303
 													'Refund payment in %s',
304
-													wpinv_get_gateway_admin_label( $invoice->get_gateway() )
304
+													wpinv_get_gateway_admin_label($invoice->get_gateway())
305 305
 												),
306 306
 												'value' => 1,
307 307
 												'class' => 'getpaid-refund-field',
@@ -311,14 +311,14 @@  discard block
 block discarded – undo
311 311
 									?>
312 312
 								<?php endif; ?>
313 313
 
314
-								<?php if ( getpaid_get_invoice_subscriptions( $invoice ) ) : ?>
314
+								<?php if (getpaid_get_invoice_subscriptions($invoice)) : ?>
315 315
 									<?php
316 316
 										aui()->input(
317 317
 											array(
318 318
 												'type'  => 'checkbox',
319 319
 												'name'  => 'getpaid_cancel_subscription',
320 320
 												'id'    => 'getpaid_cancel_subscription',
321
-												'label' => __( 'Cancel subscription', 'invoicing' ),
321
+												'label' => __('Cancel subscription', 'invoicing'),
322 322
 												'value' => 1,
323 323
 												'class' => 'getpaid-refund-field',
324 324
 											),
@@ -328,12 +328,12 @@  discard block
 block discarded – undo
328 328
 								<?php endif; ?>
329 329
                             </div>
330 330
                             <div class="modal-footer">
331
-                                <button type="button" class="btn btn-secondary getpaid-cancel" data-bs-dismiss="modal" data-dismiss="modal"><?php esc_html_e( 'Cancel', 'invoicing' ); ?></button>
331
+                                <button type="button" class="btn btn-secondary getpaid-cancel" data-bs-dismiss="modal" data-dismiss="modal"><?php esc_html_e('Cancel', 'invoicing'); ?></button>
332 332
                                 <a
333
-									href="<?php echo esc_url_raw( $refund_url ); ?>"
334
-									data-href="<?php echo esc_url_raw( $refund_url ); ?>"
333
+									href="<?php echo esc_url_raw($refund_url); ?>"
334
+									data-href="<?php echo esc_url_raw($refund_url); ?>"
335 335
 									class="btn btn-primary getpaid-refund-payment-button"
336
-								><?php esc_html_e( 'Refund', 'invoicing' ); ?></a>
336
+								><?php esc_html_e('Refund', 'invoicing'); ?></a>
337 337
 								<script>
338 338
 									// Update the refund URL when the user changes the refund options.
339 339
 									jQuery( function( $ ) {
@@ -359,13 +359,13 @@  discard block
 block discarded – undo
359 359
 
360 360
             <div class="wpinv-actions">
361 361
                 <?php
362
-                    if ( $invoice->is_paid() ) {
362
+                    if ($invoice->is_paid()) {
363 363
 
364 364
 						printf(
365 365
 							'<span class="bsui"><button type="button" class="button button-primary" data-toggle="modal" data-bs-toggle="modal" data-bs-target="#getpaid-refund-invoice-modal" data-target="#getpaid-refund-invoice-modal">%s</button></span>',
366
-							esc_html__( 'Refund', 'invoicing' )
366
+							esc_html__('Refund', 'invoicing')
367 367
 						);
368
-                    } elseif ( ! $invoice->is_refunded() ) {
368
+                    } elseif (!$invoice->is_refunded()) {
369 369
 						wpinv_item_dropdown(
370 370
 							array(
371 371
 								'name'           => 'wpinv_invoice_item',
@@ -375,66 +375,66 @@  discard block
 block discarded – undo
375 375
 							)
376 376
 						);
377 377
 
378
-						echo '&nbsp;' . '<button type="button" class="button button-primary" id="wpinv-add-item">' . sprintf( esc_html__( 'Add item to %s', 'invoicing' ), esc_html( $invoice->get_label() ) ) . '</button>';
379
-						echo '&nbsp;' . '<button type="button" class="button button-primary" id="wpinv-new-item">' . esc_html__( 'Create new item', 'invoicing' ) . '</button>';
380
-						echo '&nbsp;' . '<button type="button" class="button button-primary wpinv-flr" id="wpinv-recalc-totals">' . esc_html__( 'Recalculate Totals', 'invoicing' ) . '</button>';
378
+						echo '&nbsp;' . '<button type="button" class="button button-primary" id="wpinv-add-item">' . sprintf(esc_html__('Add item to %s', 'invoicing'), esc_html($invoice->get_label())) . '</button>';
379
+						echo '&nbsp;' . '<button type="button" class="button button-primary" id="wpinv-new-item">' . esc_html__('Create new item', 'invoicing') . '</button>';
380
+						echo '&nbsp;' . '<button type="button" class="button button-primary wpinv-flr" id="wpinv-recalc-totals">' . esc_html__('Recalculate Totals', 'invoicing') . '</button>';
381 381
 
382 382
                     }
383 383
                 ?>
384
-                <?php do_action( 'wpinv_invoice_items_actions', $invoice ); ?>
384
+                <?php do_action('wpinv_invoice_items_actions', $invoice); ?>
385 385
             </div>
386 386
         </div>
387 387
         <?php
388 388
     }
389 389
 
390
-    public static function output_row( $columns, $item, $invoice, $class = 'even' ) {
390
+    public static function output_row($columns, $item, $invoice, $class = 'even') {
391 391
 
392 392
     ?>
393
-        <tr class="item item-<?php echo esc_attr( $class ); ?>" data-item-id="<?php echo esc_attr( $item->get_id() ); ?>">
394
-            <?php foreach ( array_keys( $columns ) as $column ) : ?>
393
+        <tr class="item item-<?php echo esc_attr($class); ?>" data-item-id="<?php echo esc_attr($item->get_id()); ?>">
394
+            <?php foreach (array_keys($columns) as $column) : ?>
395 395
                 <td class="
396 396
 					<?php
397
-						echo esc_attr( $column );
397
+						echo esc_attr($column);
398 398
 						echo 'total' == $column || 'qty' == $column ? ' hide-if-amount' : '';
399 399
 					?>
400 400
 				">
401 401
                     <?php
402
-                        switch ( $column ) {
402
+                        switch ($column) {
403 403
 						case 'id':
404 404
 							echo (int) $item->get_id();
405 405
 							break;
406 406
 						case 'title':
407 407
 							printf(
408 408
 								'<a href="%s" target="_blank">%s</a>',
409
-								esc_url( get_edit_post_link( $item->get_id() ) ),
410
-								esc_html( $item->get_raw_name() )
409
+								esc_url(get_edit_post_link($item->get_id())),
410
+								esc_html($item->get_raw_name())
411 411
 							);
412 412
 
413
-							$summary = apply_filters( 'getpaid_admin_invoice_line_item_summary', $item->get_description(), $item, $invoice );
414
-							if ( $summary !== '' ) {
413
+							$summary = apply_filters('getpaid_admin_invoice_line_item_summary', $item->get_description(), $item, $invoice);
414
+							if ($summary !== '') {
415 415
 								printf(
416 416
 									'<span class="meta">%s</span>',
417
-									wp_kses_post( wpautop( $summary ) )
417
+									wp_kses_post(wpautop($summary))
418 418
 								);
419 419
 							}
420 420
 
421 421
 							printf(
422 422
 								'<input type="hidden" value="%s" name="getpaid_items[%s][name]" class="getpaid-recalculate-prices-on-change" />',
423
-								esc_attr( $item->get_raw_name() ),
423
+								esc_attr($item->get_raw_name()),
424 424
 								(int) $item->get_id()
425 425
 							);
426 426
 
427 427
 							printf(
428 428
 								'<textarea style="display: none;" name="getpaid_items[%s][description]" class="getpaid-recalculate-prices-on-change">%s</textarea>',
429 429
 								(int) $item->get_id(),
430
-								esc_attr( $item->get_description() )
430
+								esc_attr($item->get_description())
431 431
 							);
432 432
 
433 433
 							break;
434 434
 						case 'price':
435 435
 							printf(
436 436
 								'<input type="text" value="%s" name="getpaid_items[%s][price]" style="width: 100px;" class="getpaid-admin-invoice-item-price getpaid-recalculate-prices-on-change" />',
437
-								esc_attr( getpaid_unstandardize_amount( $item->get_price() ) ),
437
+								esc_attr(getpaid_unstandardize_amount($item->get_price())),
438 438
 								(int) $item->get_id()
439 439
 							);
440 440
 
@@ -442,26 +442,26 @@  discard block
 block discarded – undo
442 442
 						case 'qty':
443 443
 							printf(
444 444
 								'<input type="text" style="width: 100px;" value="%s" name="getpaid_items[%s][quantity]" class="getpaid-admin-invoice-item-quantity getpaid-recalculate-prices-on-change" />',
445
-								floatval( $item->get_quantity() ),
445
+								floatval($item->get_quantity()),
446 446
 								(int) $item->get_id()
447 447
 							);
448 448
 
449 449
 							break;
450 450
 						case 'total':
451
-							wpinv_the_price( $item->get_sub_total(), $invoice->get_currency() );
451
+							wpinv_the_price($item->get_sub_total(), $invoice->get_currency());
452 452
 
453 453
 							break;
454 454
 						case 'tax':
455
-							echo floatval( wpinv_round_amount( getpaid_get_invoice_tax_rate( $invoice, $item ), 2 ) ) . '%';
455
+							echo floatval(wpinv_round_amount(getpaid_get_invoice_tax_rate($invoice, $item), 2)) . '%';
456 456
 
457 457
 							break;
458 458
 						case 'action':
459
-							if ( ! $invoice->is_paid() && ! $invoice->is_refunded() ) {
459
+							if (!$invoice->is_paid() && !$invoice->is_refunded()) {
460 460
 								echo '<i class="fa fa-trash wpinv-item-remove"></i>';
461 461
                                 }
462 462
 							break;
463 463
                         }
464
-                        do_action( 'getpaid_admin_edit_invoice_item_' . $column, $item, $invoice );
464
+                        do_action('getpaid_admin_edit_invoice_item_' . $column, $item, $invoice);
465 465
                     ?>
466 466
                 </td>
467 467
             <?php endforeach; ?>
@@ -474,10 +474,10 @@  discard block
 block discarded – undo
474 474
 	 *
475 475
 	 * @param WP_Post $post
476 476
 	 */
477
-    public static function output2( $post ) {
477
+    public static function output2($post) {
478 478
 
479 479
         // Prepare the invoice.
480
-        $invoice = new WPInv_Invoice( $post );
480
+        $invoice = new WPInv_Invoice($post);
481 481
 
482 482
         // Invoice items.
483 483
         $items = $invoice->get_items();
@@ -485,28 +485,28 @@  discard block
 block discarded – undo
485 485
         $totals = array(
486 486
 
487 487
             'subtotal' => array(
488
-                'label' => __( 'Items Subtotal', 'invoicing' ),
489
-                'value' => wpinv_price( $invoice->get_subtotal(), $invoice->get_currency() ),
488
+                'label' => __('Items Subtotal', 'invoicing'),
489
+                'value' => wpinv_price($invoice->get_subtotal(), $invoice->get_currency()),
490 490
             ),
491 491
 
492 492
             'discount' => array(
493
-                'label' => __( 'Total Discount', 'invoicing' ),
494
-                'value' => wpinv_price( $invoice->get_total_discount(), $invoice->get_currency() ),
493
+                'label' => __('Total Discount', 'invoicing'),
494
+                'value' => wpinv_price($invoice->get_total_discount(), $invoice->get_currency()),
495 495
             ),
496 496
 
497 497
             'tax'      => array(
498
-                'label' => __( 'Total Tax', 'invoicing' ),
499
-                'value' => wpinv_price( $invoice->get_total_tax(), $invoice->get_currency() ),
498
+                'label' => __('Total Tax', 'invoicing'),
499
+                'value' => wpinv_price($invoice->get_total_tax(), $invoice->get_currency()),
500 500
             ),
501 501
 
502 502
             'total'    => array(
503
-                'label' => __( 'Invoice Total', 'invoicing' ),
504
-                'value' => wpinv_price( $invoice->get_total(), $invoice->get_currency() ),
503
+                'label' => __('Invoice Total', 'invoicing'),
504
+                'value' => wpinv_price($invoice->get_total(), $invoice->get_currency()),
505 505
             ),
506 506
         );
507 507
 
508
-        if ( ! wpinv_use_taxes() ) {
509
-            unset( $totals['tax'] );
508
+        if (!wpinv_use_taxes()) {
509
+            unset($totals['tax']);
510 510
         }
511 511
 
512 512
         $item_args = array(
@@ -514,7 +514,7 @@  discard block
 block discarded – undo
514 514
             'orderby'        => 'title',
515 515
             'order'          => 'ASC',
516 516
             'posts_per_page' => -1,
517
-            'post_status'    => array( 'publish' ),
517
+            'post_status'    => array('publish'),
518 518
             'meta_query'     => array(
519 519
                 array(
520 520
                     'key'     => '_wpinv_type',
@@ -542,10 +542,10 @@  discard block
 block discarded – undo
542 542
             }
543 543
         </style>
544 544
 
545
-                <div class="bsui getpaid-invoice-items-inner <?php echo empty( $items ) ? 'no-items' : 'has-items'; ?> <?php echo $invoice->is_paid() || $invoice->is_refunded() ? 'not-editable' : 'editable'; ?>" style="margin-top: 1.5rem; padding: 0 12px 12px;">
545
+                <div class="bsui getpaid-invoice-items-inner <?php echo empty($items) ? 'no-items' : 'has-items'; ?> <?php echo $invoice->is_paid() || $invoice->is_refunded() ? 'not-editable' : 'editable'; ?>" style="margin-top: 1.5rem; padding: 0 12px 12px;">
546 546
 
547
-                    <?php if ( ! $invoice->is_paid() && ! $invoice->is_refunded() ) : ?>
548
-                        <?php do_action( 'wpinv_meta_box_before_invoice_template_row', $invoice->get_id() ); ?>
547
+                    <?php if (!$invoice->is_paid() && !$invoice->is_refunded()) : ?>
548
+                        <?php do_action('wpinv_meta_box_before_invoice_template_row', $invoice->get_id()); ?>
549 549
 
550 550
                         <div class="row">
551 551
                             <div class="col-12 col-sm-6">
@@ -554,15 +554,15 @@  discard block
 block discarded – undo
554 554
                                         array(
555 555
                                             'id'          => 'wpinv_template',
556 556
                                             'name'        => 'wpinv_template',
557
-                                            'label'       => __( 'Template', 'invoicing' ),
557
+                                            'label'       => __('Template', 'invoicing'),
558 558
                                             'label_type'  => 'vertical',
559
-                                            'placeholder' => __( 'Choose a template', 'invoicing' ),
559
+                                            'placeholder' => __('Choose a template', 'invoicing'),
560 560
                                             'class'       => 'form-control-sm',
561
-                                            'value'       => $invoice->get_template( 'edit' ),
561
+                                            'value'       => $invoice->get_template('edit'),
562 562
                                             'options'     => array(
563
-                                                'quantity' => __( 'Quantity', 'invoicing' ),
564
-                                                'hours'    => __( 'Hours', 'invoicing' ),
565
-                                                'amount'   => __( 'Amount Only', 'invoicing' ),
563
+                                                'quantity' => __('Quantity', 'invoicing'),
564
+                                                'hours'    => __('Hours', 'invoicing'),
565
+                                                'amount'   => __('Amount Only', 'invoicing'),
566 566
                                             ),
567 567
                                             'data-allow-clear' => 'false',
568 568
                                             'select2'     => true,
@@ -579,11 +579,11 @@  discard block
 block discarded – undo
579 579
                                         array(
580 580
                                             'id'          => 'wpinv_currency',
581 581
                                             'name'        => 'wpinv_currency',
582
-                                            'label'       => __( 'Currency', 'invoicing' ),
582
+                                            'label'       => __('Currency', 'invoicing'),
583 583
                                             'label_type'  => 'vertical',
584
-                                            'placeholder' => __( 'Select Invoice Currency', 'invoicing' ),
584
+                                            'placeholder' => __('Select Invoice Currency', 'invoicing'),
585 585
                                             'class'       => 'form-control-sm',
586
-                                            'value'       => $invoice->get_currency( 'edit' ),
586
+                                            'value'       => $invoice->get_currency('edit'),
587 587
                                             'required'    => false,
588 588
                                             'data-allow-clear' => 'false',
589 589
                                             'select2'     => true,
@@ -596,24 +596,24 @@  discard block
 block discarded – undo
596 596
                             </div>
597 597
                         </div>
598 598
 
599
-                        <?php do_action( 'wpinv_meta_box_invoice_template_row', $invoice->get_id() ); ?>
599
+                        <?php do_action('wpinv_meta_box_invoice_template_row', $invoice->get_id()); ?>
600 600
                     <?php endif; ?>
601 601
 
602 602
                     <table cellpadding="0" cellspacing="0" class="getpaid_invoice_items">
603 603
                         <thead>
604 604
                             <tr>
605
-                                <th class="getpaid-item" colspan="2"><?php esc_html_e( 'Item', 'invoicing' ); ?></th>
605
+                                <th class="getpaid-item" colspan="2"><?php esc_html_e('Item', 'invoicing'); ?></th>
606 606
                                 <th class="getpaid-quantity hide-if-amount text-right">
607
-                                    <span class="getpaid-hide-if-hours"><?php esc_html_e( 'Quantity', 'invoicing' ); ?></span>
608
-                                    <span class="getpaid-hide-if-quantity"><?php esc_html_e( 'Hours', 'invoicing' ); ?></span>
607
+                                    <span class="getpaid-hide-if-hours"><?php esc_html_e('Quantity', 'invoicing'); ?></span>
608
+                                    <span class="getpaid-hide-if-quantity"><?php esc_html_e('Hours', 'invoicing'); ?></span>
609 609
                                 </th>
610 610
                                 <th class="getpaid-price hide-if-amount text-right">
611
-                                    <span class="getpaid-hide-if-hours"><?php esc_html_e( 'Price', 'invoicing' ); ?></span>
612
-                                    <span class="getpaid-hide-if-quantity"><?php esc_html_e( 'Rate', 'invoicing' ); ?></span>
611
+                                    <span class="getpaid-hide-if-hours"><?php esc_html_e('Price', 'invoicing'); ?></span>
612
+                                    <span class="getpaid-hide-if-quantity"><?php esc_html_e('Rate', 'invoicing'); ?></span>
613 613
                                 </th>
614 614
                                 <th class="getpaid-item-subtotal text-right">
615
-                                    <span class="getpaid-hide-if-hours getpaid-hide-if-quantity"><?php esc_html_e( 'Amount', 'invoicing' ); ?></span>
616
-                                    <span class="hide-if-amount"><?php esc_html_e( 'Total', 'invoicing' ); ?></span>
615
+                                    <span class="getpaid-hide-if-hours getpaid-hide-if-quantity"><?php esc_html_e('Amount', 'invoicing'); ?></span>
616
+                                    <span class="hide-if-amount"><?php esc_html_e('Total', 'invoicing'); ?></span>
617 617
                                 </th>
618 618
                                 <th class="getpaid-item-actions hide-if-not-editable" width="70px">&nbsp;</th>
619 619
                             </tr>
@@ -621,8 +621,8 @@  discard block
 block discarded – undo
621 621
 		                <tbody class="getpaid_invoice_line_items">
622 622
                             <tr class="hide-if-has-items hide-if-not-editable">
623 623
                                 <td colspan="2" class="pt-4 pb-4">
624
-                                    <button type="button" class="button button-primary add-invoice-item" data-toggle="modal" data-target="#getpaid-add-items-to-invoice"><?php esc_html_e( 'Add Existing Items', 'invoicing' ); ?></button>
625
-                                    <button type="button" class="button button-secondary create-invoice-item" data-toggle="modal" data-target="#getpaid-create-invoice-item"><?php esc_html_e( 'Create New Item', 'invoicing' ); ?></button>
624
+                                    <button type="button" class="button button-primary add-invoice-item" data-toggle="modal" data-target="#getpaid-add-items-to-invoice"><?php esc_html_e('Add Existing Items', 'invoicing'); ?></button>
625
+                                    <button type="button" class="button button-secondary create-invoice-item" data-toggle="modal" data-target="#getpaid-create-invoice-item"><?php esc_html_e('Create New Item', 'invoicing'); ?></button>
626 626
                                 </td>
627 627
                                 <td class="hide-if-amount">&nbsp;</th>
628 628
                                 <td class="hide-if-amount">&nbsp;</th>
@@ -654,11 +654,11 @@  discard block
 block discarded – undo
654 654
                             <div class="col-12 col-sm-6 offset-sm-6">
655 655
                                 <table class="getpaid-invoice-totals text-right w-100">
656 656
                                     <tbody>
657
-                                        <?php foreach ( apply_filters( 'getpaid_invoice_subtotal_rows', $totals, $invoice ) as $key => $data ) : ?>
658
-                                            <tr class="getpaid-totals-<?php echo esc_attr( $key ); ?>">
659
-                                                <td class="label"><?php echo esc_html( $data['label'] ); ?>:</td>
657
+                                        <?php foreach (apply_filters('getpaid_invoice_subtotal_rows', $totals, $invoice) as $key => $data) : ?>
658
+                                            <tr class="getpaid-totals-<?php echo esc_attr($key); ?>">
659
+                                                <td class="label"><?php echo esc_html($data['label']); ?>:</td>
660 660
                                                 <td width="1%"></td>
661
-                                                <td class="value"><?php echo wp_kses_post( $data['value'] ); ?></td>
661
+                                                <td class="value"><?php echo wp_kses_post($data['value']); ?></td>
662 662
                                             </tr>
663 663
                                         <?php endforeach; ?>
664 664
                                     </tbody>
@@ -671,18 +671,18 @@  discard block
 block discarded – undo
671 671
                     <div class="getpaid-invoice-item-actions hide-if-no-items hide-if-not-editable">
672 672
                         <div class="row">
673 673
                             <div class="text-left col-12 col-sm-8">
674
-                                <button type="button" class="button button-primary add-invoice-item" data-toggle="modal" data-target="#getpaid-add-items-to-invoice"><?php esc_html_e( 'Add Existing Item', 'invoicing' ); ?></button>
675
-                                <button type="button" class="button button-secondary create-invoice-item" data-toggle="modal" data-target="#getpaid-create-invoice-item"><?php esc_html_e( 'Create New Item', 'invoicing' ); ?></button>
676
-                                <?php do_action( 'getpaid-invoice-items-actions', $invoice ); ?>
674
+                                <button type="button" class="button button-primary add-invoice-item" data-toggle="modal" data-target="#getpaid-add-items-to-invoice"><?php esc_html_e('Add Existing Item', 'invoicing'); ?></button>
675
+                                <button type="button" class="button button-secondary create-invoice-item" data-toggle="modal" data-target="#getpaid-create-invoice-item"><?php esc_html_e('Create New Item', 'invoicing'); ?></button>
676
+                                <?php do_action('getpaid-invoice-items-actions', $invoice); ?>
677 677
                             </div>
678 678
                             <div class="text-right col-12 col-sm-4">
679
-                                <button type="button" class="button button-primary recalculate-totals-button"><?php esc_html_e( 'Recalculate Totals', 'invoicing' ); ?></button>
679
+                                <button type="button" class="button button-primary recalculate-totals-button"><?php esc_html_e('Recalculate Totals', 'invoicing'); ?></button>
680 680
                             </div>
681 681
                         </div>
682 682
                     </div>
683 683
 
684 684
                     <div class="getpaid-invoice-item-actions hide-if-editable">
685
-                        <p class="description m-2 text-right text-muted"><?php esc_html_e( 'This invoice is no longer editable', 'invoicing' ); ?></p>
685
+                        <p class="description m-2 text-right text-muted"><?php esc_html_e('This invoice is no longer editable', 'invoicing'); ?></p>
686 686
                     </div>
687 687
 
688 688
                     <!-- Add items to an invoice -->
@@ -690,9 +690,9 @@  discard block
 block discarded – undo
690 690
                         <div class="modal-dialog modal-dialog-centered" role="document">
691 691
                             <div class="modal-content">
692 692
                                 <div class="modal-header">
693
-                                    <h5 class="modal-title" id="getpaid-add-item-to-invoice-label"><?php esc_html_e( 'Add Item(s)', 'invoicing' ); ?></h5>
694
-                                    <button type="button" class="close btn-close" data-dismiss="modal" aria-label="<?php esc_html_e( 'Close', 'invoicing' ); ?>">
695
-                                        <?php if ( empty( $GLOBALS['aui_bs5'] ) ) : ?>
693
+                                    <h5 class="modal-title" id="getpaid-add-item-to-invoice-label"><?php esc_html_e('Add Item(s)', 'invoicing'); ?></h5>
694
+                                    <button type="button" class="close btn-close" data-dismiss="modal" aria-label="<?php esc_html_e('Close', 'invoicing'); ?>">
695
+                                        <?php if (empty($GLOBALS['aui_bs5'])) : ?>
696 696
                                             <span aria-hidden="true">×</span>
697 697
                                         <?php endif; ?>
698 698
                                     </button>
@@ -701,10 +701,10 @@  discard block
 block discarded – undo
701 701
                                     <table class="widefat">
702 702
                                         <thead>
703 703
                                             <tr>
704
-                                                <th class="pl-0 text-left"><?php esc_html_e( 'Item', 'invoicing' ); ?></th>
704
+                                                <th class="pl-0 text-left"><?php esc_html_e('Item', 'invoicing'); ?></th>
705 705
                                                 <th class="pr-0 text-right hide-if-amount">
706
-                                                    <span class="getpaid-hide-if-hours"><?php esc_html_e( 'Quantity', 'invoicing' ); ?></span>
707
-                                                    <span class="getpaid-hide-if-quantity"><?php esc_html_e( 'Hours', 'invoicing' ); ?></span>
706
+                                                    <span class="getpaid-hide-if-hours"><?php esc_html_e('Quantity', 'invoicing'); ?></span>
707
+                                                    <span class="getpaid-hide-if-quantity"><?php esc_html_e('Hours', 'invoicing'); ?></span>
708 708
                                                 </th>
709 709
                                             </tr>
710 710
                                         </thead>
@@ -712,9 +712,9 @@  discard block
 block discarded – undo
712 712
 								            <tr>
713 713
 									            <td class="pl-0 text-left">
714 714
                                                     <select class="regular-text getpaid-add-invoice-item-select">
715
-                                                        <option value="" selected="selected" disabled><?php esc_html_e( 'Select an item…', 'invoicing' ); ?></option>
716
-                                                        <?php foreach ( get_posts( $item_args ) as $item ) : ?>
717
-                                                        <option value="<?php echo (int) $item->ID; ?>"><?php echo esc_html( $item->post_title ); ?></option>
715
+                                                        <option value="" selected="selected" disabled><?php esc_html_e('Select an item…', 'invoicing'); ?></option>
716
+                                                        <?php foreach (get_posts($item_args) as $item) : ?>
717
+                                                        <option value="<?php echo (int) $item->ID; ?>"><?php echo esc_html($item->post_title); ?></option>
718 718
                                                         <?php endforeach; ?>
719 719
                                                     </select>
720 720
                                                 </td>
@@ -726,8 +726,8 @@  discard block
 block discarded – undo
726 726
 						            </table>
727 727
                                 </div>
728 728
                                 <div class="modal-footer">
729
-                                    <button type="button" class="btn btn-secondary getpaid-cancel" data-dismiss="modal"><?php esc_html_e( 'Cancel', 'invoicing' ); ?></button>
730
-                                    <button type="button" class="btn btn-primary getpaid-add" data-dismiss="modal"><?php esc_html_e( 'Add', 'invoicing' ); ?></button>
729
+                                    <button type="button" class="btn btn-secondary getpaid-cancel" data-dismiss="modal"><?php esc_html_e('Cancel', 'invoicing'); ?></button>
730
+                                    <button type="button" class="btn btn-primary getpaid-add" data-dismiss="modal"><?php esc_html_e('Add', 'invoicing'); ?></button>
731 731
                                 </div>
732 732
                             </div>
733 733
                         </div>
@@ -738,9 +738,9 @@  discard block
 block discarded – undo
738 738
                         <div class="modal-dialog modal-dialog-centered" role="document">
739 739
                             <div class="modal-content">
740 740
                                 <div class="modal-header">
741
-                                    <h5 class="modal-title" id="getpaid-create-invoice-item-label"><?php esc_html_e( 'Create Item', 'invoicing' ); ?></h5>
742
-                                    <button type="button" class="close btn-close" data-dismiss="modal" aria-label="<?php esc_html_e( 'Close', 'invoicing' ); ?>">
743
-                                        <?php if ( empty( $GLOBALS['aui_bs5'] ) ) : ?>
741
+                                    <h5 class="modal-title" id="getpaid-create-invoice-item-label"><?php esc_html_e('Create Item', 'invoicing'); ?></h5>
742
+                                    <button type="button" class="close btn-close" data-dismiss="modal" aria-label="<?php esc_html_e('Close', 'invoicing'); ?>">
743
+                                        <?php if (empty($GLOBALS['aui_bs5'])) : ?>
744 744
                                             <span aria-hidden="true">×</span>
745 745
                                         <?php endif; ?>
746 746
                                     </button>
@@ -749,27 +749,27 @@  discard block
 block discarded – undo
749 749
                                     <div class="getpaid-create-item-div">
750 750
                                         <input type="hidden" name="id" value="new" class="form-control form-control-sm item-id">
751 751
                                         <label class="form-group mb-3 w-100">
752
-                                            <span><?php esc_html_e( 'Name', 'invoicing' ); ?></span>
753
-                                            <input type="text" name="name" placeholder="<?php esc_attr_e( 'Item Name', 'invoicing' ); ?>" class="form-control form-control-sm item-name">
752
+                                            <span><?php esc_html_e('Name', 'invoicing'); ?></span>
753
+                                            <input type="text" name="name" placeholder="<?php esc_attr_e('Item Name', 'invoicing'); ?>" class="form-control form-control-sm item-name">
754 754
                                         </label>
755 755
                                         <label class="form-group mb-3 w-100">
756
-                                            <span class="getpaid-hide-if-hours getpaid-hide-if-quantity item-price"><?php esc_html_e( 'Amount', 'invoicing' ); ?></span>
757
-                                            <span class="hide-if-amount"><?php esc_html_e( 'Price', 'invoicing' ); ?></span>
758
-                                            <input type="text" name="price" placeholder="<?php echo esc_attr( wpinv_sanitize_amount( 0 ) ); ?>" class="form-control form-control-sm item-price">
756
+                                            <span class="getpaid-hide-if-hours getpaid-hide-if-quantity item-price"><?php esc_html_e('Amount', 'invoicing'); ?></span>
757
+                                            <span class="hide-if-amount"><?php esc_html_e('Price', 'invoicing'); ?></span>
758
+                                            <input type="text" name="price" placeholder="<?php echo esc_attr(wpinv_sanitize_amount(0)); ?>" class="form-control form-control-sm item-price">
759 759
                                         </label>
760 760
                                         <label class="form-group mb-3 w-100 hide-if-amount">
761
-                                            <span><?php esc_html_e( 'Quantity', 'invoicing' ); ?></span>
761
+                                            <span><?php esc_html_e('Quantity', 'invoicing'); ?></span>
762 762
                                             <input type="text" name="quantity" placeholder="1" class="form-control form-control-sm item-quantity">
763 763
                                         </label>
764 764
                                         <label class="form-group mb-3 w-100">
765
-                                            <span><?php esc_html_e( 'Item Description', 'invoicing' ); ?></span>
766
-                                            <textarea name="description" placeholder="<?php esc_attr_e( 'Enter a description for this item', 'invoicing' ); ?>" class="form-control item-description"></textarea>
765
+                                            <span><?php esc_html_e('Item Description', 'invoicing'); ?></span>
766
+                                            <textarea name="description" placeholder="<?php esc_attr_e('Enter a description for this item', 'invoicing'); ?>" class="form-control item-description"></textarea>
767 767
                                         </label>
768 768
                                     </div>
769 769
                                 </div>
770 770
                                 <div class="modal-footer">
771
-                                    <button type="button" class="btn btn-secondary getpaid-cancel" data-dismiss="modal"><?php esc_html_e( 'Cancel', 'invoicing' ); ?></button>
772
-                                    <button type="button" class="btn btn-primary getpaid-save" data-dismiss="modal"><?php esc_html_e( 'Create', 'invoicing' ); ?></button>
771
+                                    <button type="button" class="btn btn-secondary getpaid-cancel" data-dismiss="modal"><?php esc_html_e('Cancel', 'invoicing'); ?></button>
772
+                                    <button type="button" class="btn btn-primary getpaid-save" data-dismiss="modal"><?php esc_html_e('Create', 'invoicing'); ?></button>
773 773
                                 </div>
774 774
                             </div>
775 775
                         </div>
@@ -780,9 +780,9 @@  discard block
 block discarded – undo
780 780
                         <div class="modal-dialog modal-dialog-centered" role="document">
781 781
                             <div class="modal-content">
782 782
                                 <div class="modal-header">
783
-                                    <h5 class="modal-title" id="getpaid-edit-invoice-item-label"><?php esc_html_e( 'Edit Item', 'invoicing' ); ?></h5>
784
-                                    <button type="button" class="close close" data-dismiss="modal" aria-label="<?php esc_html_e( 'Close', 'invoicing' ); ?>">
785
-                                        <?php if ( empty( $GLOBALS['aui_bs5'] ) ) : ?>
783
+                                    <h5 class="modal-title" id="getpaid-edit-invoice-item-label"><?php esc_html_e('Edit Item', 'invoicing'); ?></h5>
784
+                                    <button type="button" class="close close" data-dismiss="modal" aria-label="<?php esc_html_e('Close', 'invoicing'); ?>">
785
+                                        <?php if (empty($GLOBALS['aui_bs5'])) : ?>
786 786
                                             <span aria-hidden="true">×</span>
787 787
                                         <?php endif; ?>
788 788
                                     </button>
@@ -791,27 +791,27 @@  discard block
 block discarded – undo
791 791
                                     <div class="getpaid-edit-item-div">
792 792
                                         <input type="hidden" name="id" class="form-control form-control-sm item-id">
793 793
                                         <label class="form-group mb-3 w-100">
794
-                                            <span><?php esc_html_e( 'Name', 'invoicing' ); ?></span>
795
-                                            <input type="text" name="name" placeholder="<?php esc_attr_e( 'Item Name', 'invoicing' ); ?>" class="form-control form-control-sm item-name">
794
+                                            <span><?php esc_html_e('Name', 'invoicing'); ?></span>
795
+                                            <input type="text" name="name" placeholder="<?php esc_attr_e('Item Name', 'invoicing'); ?>" class="form-control form-control-sm item-name">
796 796
                                         </label>
797 797
                                         <label class="form-group mb-3 w-100">
798
-                                            <span class="getpaid-hide-if-hours getpaid-hide-if-quantity item-price"><?php esc_html_e( 'Amount', 'invoicing' ); ?></span>
799
-                                            <span class="hide-if-amount"><?php esc_html_e( 'Price', 'invoicing' ); ?></span>
800
-                                            <input type="text" name="price" placeholder="<?php wpinv_sanitize_amount( 0 ); ?>" class="form-control form-control-sm item-price">
798
+                                            <span class="getpaid-hide-if-hours getpaid-hide-if-quantity item-price"><?php esc_html_e('Amount', 'invoicing'); ?></span>
799
+                                            <span class="hide-if-amount"><?php esc_html_e('Price', 'invoicing'); ?></span>
800
+                                            <input type="text" name="price" placeholder="<?php wpinv_sanitize_amount(0); ?>" class="form-control form-control-sm item-price">
801 801
                                         </label>
802 802
                                         <label class="form-group mb-3 w-100 hide-if-amount">
803
-                                            <span><?php esc_html_e( 'Quantity', 'invoicing' ); ?></span>
803
+                                            <span><?php esc_html_e('Quantity', 'invoicing'); ?></span>
804 804
                                             <input type="text" name="quantity" placeholder="1" class="form-control form-control-sm item-quantity">
805 805
                                         </label>
806 806
                                         <label class="form-group mb-3 w-100">
807
-                                            <span><?php esc_html_e( 'Item Description', 'invoicing' ); ?></span>
808
-                                            <textarea name="description" placeholder="<?php esc_attr_e( 'Enter a description for this item', 'invoicing' ); ?>" class="form-control item-description"></textarea>
807
+                                            <span><?php esc_html_e('Item Description', 'invoicing'); ?></span>
808
+                                            <textarea name="description" placeholder="<?php esc_attr_e('Enter a description for this item', 'invoicing'); ?>" class="form-control item-description"></textarea>
809 809
                                         </label>
810 810
                                     </div>
811 811
                                 </div>
812 812
                                 <div class="modal-footer">
813
-                                    <button type="button" class="btn btn-secondary getpaid-cancel" data-dismiss="modal"><?php esc_html_e( 'Cancel', 'invoicing' ); ?></button>
814
-                                    <button type="button" class="btn btn-primary getpaid-save" data-dismiss="modal"><?php esc_html_e( 'Save', 'invoicing' ); ?></button>
813
+                                    <button type="button" class="btn btn-secondary getpaid-cancel" data-dismiss="modal"><?php esc_html_e('Cancel', 'invoicing'); ?></button>
814
+                                    <button type="button" class="btn btn-primary getpaid-save" data-dismiss="modal"><?php esc_html_e('Save', 'invoicing'); ?></button>
815 815
                                 </div>
816 816
                             </div>
817 817
                         </div>
Please login to merge, or discard this patch.