Passed
Push — master ( 0a2366...999d0e )
by Stiofan
16:14
created
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.
includes/admin/class-getpaid-admin.php 2 patches
Indentation   +620 added lines, -620 removed lines patch added patch discarded remove patch
@@ -14,94 +14,94 @@  discard block
 block discarded – undo
14 14
 class GetPaid_Admin {
15 15
 
16 16
     /**
17
-	 * Local path to this plugins admin directory
18
-	 *
19
-	 * @var         string
20
-	 */
21
-	public $admin_path;
22
-
23
-	/**
24
-	 * Web path to this plugins admin directory
25
-	 *
26
-	 * @var         string
27
-	 */
28
-	public $admin_url;
29
-
30
-	/**
31
-	 * Reports components.
32
-	 *
33
-	 * @var GetPaid_Reports
34
-	 */
17
+     * Local path to this plugins admin directory
18
+     *
19
+     * @var         string
20
+     */
21
+    public $admin_path;
22
+
23
+    /**
24
+     * Web path to this plugins admin directory
25
+     *
26
+     * @var         string
27
+     */
28
+    public $admin_url;
29
+
30
+    /**
31
+     * Reports components.
32
+     *
33
+     * @var GetPaid_Reports
34
+     */
35 35
     public $reports;
36 36
 
37 37
     /**
38
-	 * Class constructor.
39
-	 */
40
-	public function __construct() {
38
+     * Class constructor.
39
+     */
40
+    public function __construct() {
41 41
 
42 42
         $this->admin_path  = plugin_dir_path( __FILE__ );
43
-		$this->admin_url   = plugins_url( '/', __FILE__ );
44
-		$this->reports     = new GetPaid_Reports();
43
+        $this->admin_url   = plugins_url( '/', __FILE__ );
44
+        $this->reports     = new GetPaid_Reports();
45 45
 
46 46
         if ( is_admin() ) {
47
-			$this->init_admin_hooks();
47
+            $this->init_admin_hooks();
48 48
         }
49 49
 
50 50
     }
51 51
 
52 52
     /**
53
-	 * Init action and filter hooks
54
-	 *
55
-	 */
56
-	private function init_admin_hooks() {
53
+     * Init action and filter hooks
54
+     *
55
+     */
56
+    private function init_admin_hooks() {
57 57
         add_action( 'admin_enqueue_scripts', array( $this, 'enqeue_scripts' ), 9 );
58 58
         add_filter( 'admin_body_class', array( $this, 'admin_body_class' ) );
59 59
         add_action( 'admin_init', array( $this, 'init_ayecode_connect_helper' ) );
60 60
         add_action( 'admin_init', array( $this, 'activation_redirect' ) );
61 61
         add_action( 'admin_init', array( $this, 'maybe_do_admin_action' ) );
62
-		add_action( 'admin_notices', array( $this, 'show_notices' ) );
63
-		add_action( 'getpaid_authenticated_admin_action_rate_plugin', array( $this, 'redirect_to_wordpress_rating_page' ) );
64
-		add_action( 'getpaid_authenticated_admin_action_duplicate_form', array( $this, 'duplicate_payment_form' ) );
65
-		add_action( 'getpaid_authenticated_admin_action_reset_form_stats', array( $this, 'reset_form_stats' ) );
66
-		add_action( 'getpaid_authenticated_admin_action_duplicate_invoice', array( $this, 'duplicate_invoice' ) );
67
-		add_action( 'getpaid_authenticated_admin_action_refund_invoice', array( $this, 'refund_invoice' ) );
68
-		add_action( 'getpaid_authenticated_admin_action_send_invoice', array( $this, 'send_customer_invoice' ) );
69
-		add_action( 'getpaid_authenticated_admin_action_send_invoice_reminder', array( $this, 'send_customer_payment_reminder' ) );
62
+        add_action( 'admin_notices', array( $this, 'show_notices' ) );
63
+        add_action( 'getpaid_authenticated_admin_action_rate_plugin', array( $this, 'redirect_to_wordpress_rating_page' ) );
64
+        add_action( 'getpaid_authenticated_admin_action_duplicate_form', array( $this, 'duplicate_payment_form' ) );
65
+        add_action( 'getpaid_authenticated_admin_action_reset_form_stats', array( $this, 'reset_form_stats' ) );
66
+        add_action( 'getpaid_authenticated_admin_action_duplicate_invoice', array( $this, 'duplicate_invoice' ) );
67
+        add_action( 'getpaid_authenticated_admin_action_refund_invoice', array( $this, 'refund_invoice' ) );
68
+        add_action( 'getpaid_authenticated_admin_action_send_invoice', array( $this, 'send_customer_invoice' ) );
69
+        add_action( 'getpaid_authenticated_admin_action_send_invoice_reminder', array( $this, 'send_customer_payment_reminder' ) );
70 70
         add_action( 'getpaid_authenticated_admin_action_reset_tax_rates', array( $this, 'admin_reset_tax_rates' ) );
71
-		add_action( 'getpaid_authenticated_admin_action_create_missing_pages', array( $this, 'admin_create_missing_pages' ) );
72
-		add_action( 'getpaid_authenticated_admin_action_refresh_permalinks', array( $this, 'admin_refresh_permalinks' ) );
73
-		add_action( 'getpaid_authenticated_admin_action_create_missing_tables', array( $this, 'admin_create_missing_tables' ) );
74
-		add_action( 'getpaid_authenticated_admin_action_migrate_old_invoices', array( $this, 'admin_migrate_old_invoices' ) );
75
-		add_action( 'getpaid_authenticated_admin_action_download_customers', array( $this, 'admin_download_customers' ) );
76
-		add_action( 'getpaid_authenticated_admin_action_recalculate_discounts', array( $this, 'admin_recalculate_discounts' ) );
77
-		add_action( 'getpaid_authenticated_admin_action_install_plugin', array( $this, 'admin_install_plugin' ) );
78
-		add_action( 'getpaid_authenticated_admin_action_connect_gateway', array( $this, 'admin_connect_gateway' ) );
79
-		add_filter( 'admin_footer_text', array( $this, 'admin_footer_text' ) );
80
-		do_action( 'getpaid_init_admin_hooks', $this );
81
-
82
-		// Setup/welcome
83
-		if ( ! empty( $_GET['page'] ) ) {
84
-			switch ( sanitize_text_field( $_GET['page'] ) ) {
85
-				case 'gp-setup':
86
-					include_once dirname( __FILE__ ) . '/class-getpaid-admin-setup-wizard.php';
87
-					break;
88
-			}
89
-		}
90
-
91
-    }
92
-
93
-    /**
94
-	 * Register admin scripts
95
-	 *
96
-	 */
97
-	public function enqeue_scripts() {
71
+        add_action( 'getpaid_authenticated_admin_action_create_missing_pages', array( $this, 'admin_create_missing_pages' ) );
72
+        add_action( 'getpaid_authenticated_admin_action_refresh_permalinks', array( $this, 'admin_refresh_permalinks' ) );
73
+        add_action( 'getpaid_authenticated_admin_action_create_missing_tables', array( $this, 'admin_create_missing_tables' ) );
74
+        add_action( 'getpaid_authenticated_admin_action_migrate_old_invoices', array( $this, 'admin_migrate_old_invoices' ) );
75
+        add_action( 'getpaid_authenticated_admin_action_download_customers', array( $this, 'admin_download_customers' ) );
76
+        add_action( 'getpaid_authenticated_admin_action_recalculate_discounts', array( $this, 'admin_recalculate_discounts' ) );
77
+        add_action( 'getpaid_authenticated_admin_action_install_plugin', array( $this, 'admin_install_plugin' ) );
78
+        add_action( 'getpaid_authenticated_admin_action_connect_gateway', array( $this, 'admin_connect_gateway' ) );
79
+        add_filter( 'admin_footer_text', array( $this, 'admin_footer_text' ) );
80
+        do_action( 'getpaid_init_admin_hooks', $this );
81
+
82
+        // Setup/welcome
83
+        if ( ! empty( $_GET['page'] ) ) {
84
+            switch ( sanitize_text_field( $_GET['page'] ) ) {
85
+                case 'gp-setup':
86
+                    include_once dirname( __FILE__ ) . '/class-getpaid-admin-setup-wizard.php';
87
+                    break;
88
+            }
89
+        }
90
+
91
+    }
92
+
93
+    /**
94
+     * Register admin scripts
95
+     *
96
+     */
97
+    public function enqeue_scripts() {
98 98
         global $current_screen, $pagenow;
99 99
 
100
-		$page    = isset( $_GET['page'] ) ? sanitize_text_field( $_GET['page'] ) : '';
101
-		$editing = $pagenow == 'post.php' || $pagenow == 'post-new.php';
100
+        $page    = isset( $_GET['page'] ) ? sanitize_text_field( $_GET['page'] ) : '';
101
+        $editing = $pagenow == 'post.php' || $pagenow == 'post-new.php';
102 102
 
103 103
         if ( ! empty( $current_screen->post_type ) ) {
104
-			$page = $current_screen->post_type;
104
+            $page = $current_screen->post_type;
105 105
         }
106 106
 
107 107
         // General styles.
@@ -122,53 +122,53 @@  discard block
 block discarded – undo
122 122
         }
123 123
 
124 124
         // Payment form scripts.
125
-		if ( 'wpi_payment_form' == $page && $editing ) {
125
+        if ( 'wpi_payment_form' == $page && $editing ) {
126 126
             $this->load_payment_form_scripts();
127 127
         }
128 128
 
129
-		if ( $page == 'wpinv-subscriptions' ) {
130
-			wp_enqueue_script( 'postbox' );
131
-		}
129
+        if ( $page == 'wpinv-subscriptions' ) {
130
+            wp_enqueue_script( 'postbox' );
131
+        }
132 132
 
133 133
     }
134 134
 
135 135
     /**
136
-	 * Returns admin js translations.
137
-	 *
138
-	 */
139
-	protected function get_admin_i18() {
136
+     * Returns admin js translations.
137
+     *
138
+     */
139
+    protected function get_admin_i18() {
140 140
         global $post;
141 141
 
142
-		$date_range = array(
143
-			'period' => isset( $_GET['date_range'] ) ? sanitize_text_field( $_GET['date_range'] ) : '7_days',
144
-		);
142
+        $date_range = array(
143
+            'period' => isset( $_GET['date_range'] ) ? sanitize_text_field( $_GET['date_range'] ) : '7_days',
144
+        );
145 145
 
146
-		if ( $date_range['period'] == 'custom' ) {
146
+        if ( $date_range['period'] == 'custom' ) {
147 147
 
148
-			if ( isset( $_GET['from'] ) ) {
149
-				$date_range['after'] = date( 'Y-m-d', strtotime( sanitize_text_field( $_GET['from'] ), current_time( 'timestamp' ) ) - DAY_IN_SECONDS );
150
-			}
148
+            if ( isset( $_GET['from'] ) ) {
149
+                $date_range['after'] = date( 'Y-m-d', strtotime( sanitize_text_field( $_GET['from'] ), current_time( 'timestamp' ) ) - DAY_IN_SECONDS );
150
+            }
151 151
 
152
-			if ( isset( $_GET['to'] ) ) {
153
-				$date_range['before'] = date( 'Y-m-d', strtotime( sanitize_text_field( $_GET['to'] ), current_time( 'timestamp' ) ) + DAY_IN_SECONDS );
154
-			}
152
+            if ( isset( $_GET['to'] ) ) {
153
+                $date_range['before'] = date( 'Y-m-d', strtotime( sanitize_text_field( $_GET['to'] ), current_time( 'timestamp' ) ) + DAY_IN_SECONDS );
154
+            }
155 155
 }
156 156
 
157 157
         $i18n = array(
158 158
             'ajax_url'                  => admin_url( 'admin-ajax.php' ),
159 159
             'post_ID'                   => isset( $post->ID ) ? $post->ID : '',
160
-			'wpinv_nonce'               => wp_create_nonce( 'wpinv-nonce' ),
161
-			'rest_nonce'                => wp_create_nonce( 'wp_rest' ),
162
-			'rest_root'                 => esc_url_raw( rest_url() ),
163
-			'date_range'                => $date_range,
160
+            'wpinv_nonce'               => wp_create_nonce( 'wpinv-nonce' ),
161
+            'rest_nonce'                => wp_create_nonce( 'wp_rest' ),
162
+            'rest_root'                 => esc_url_raw( rest_url() ),
163
+            'date_range'                => $date_range,
164 164
             'add_invoice_note_nonce'    => wp_create_nonce( 'add-invoice-note' ),
165 165
             'delete_invoice_note_nonce' => wp_create_nonce( 'delete-invoice-note' ),
166 166
             'invoice_item_nonce'        => wp_create_nonce( 'invoice-item' ),
167 167
             'billing_details_nonce'     => wp_create_nonce( 'get-billing-details' ),
168 168
             'tax'                       => wpinv_tax_amount(),
169 169
             'discount'                  => 0,
170
-			'currency_symbol'           => wpinv_currency_symbol(),
171
-			'currency'                  => wpinv_get_currency(),
170
+            'currency_symbol'           => wpinv_currency_symbol(),
171
+            'currency'                  => wpinv_get_currency(),
172 172
             'currency_pos'              => wpinv_currency_position(),
173 173
             'thousand_sep'              => wpinv_thousands_separator(),
174 174
             'decimal_sep'               => wpinv_decimal_separator(),
@@ -188,118 +188,118 @@  discard block
 block discarded – undo
188 188
             'item_description'          => __( 'Item Description', 'invoicing' ),
189 189
             'invoice_description'       => __( 'Invoice Description', 'invoicing' ),
190 190
             'discount_description'      => __( 'Discount Description', 'invoicing' ),
191
-			'searching'                 => __( 'Searching', 'invoicing' ),
192
-			'loading'                   => __( 'Loading...', 'invoicing' ),
193
-			'search_customers'          => __( 'Enter customer name or email', 'invoicing' ),
194
-			'search_items'              => __( 'Enter item name', 'invoicing' ),
195
-			'graphs'                    => array_merge( array( 'refunded_fees', 'refunded_items', 'refunded_subtotal', 'refunded_tax' ), array_keys( wpinv_get_report_graphs() ) ),
191
+            'searching'                 => __( 'Searching', 'invoicing' ),
192
+            'loading'                   => __( 'Loading...', 'invoicing' ),
193
+            'search_customers'          => __( 'Enter customer name or email', 'invoicing' ),
194
+            'search_items'              => __( 'Enter item name', 'invoicing' ),
195
+            'graphs'                    => array_merge( array( 'refunded_fees', 'refunded_items', 'refunded_subtotal', 'refunded_tax' ), array_keys( wpinv_get_report_graphs() ) ),
196 196
         );
197 197
 
198
-		if ( ! empty( $post ) && getpaid_is_invoice_post_type( $post->post_type ) ) {
198
+        if ( ! empty( $post ) && getpaid_is_invoice_post_type( $post->post_type ) ) {
199 199
 
200
-			$invoice              = new WPInv_Invoice( $post );
201
-			$i18n['save_invoice'] = sprintf(
202
-				__( 'Save %s', 'invoicing' ),
203
-				ucfirst( $invoice->get_invoice_quote_type() )
204
-			);
200
+            $invoice              = new WPInv_Invoice( $post );
201
+            $i18n['save_invoice'] = sprintf(
202
+                __( 'Save %s', 'invoicing' ),
203
+                ucfirst( $invoice->get_invoice_quote_type() )
204
+            );
205 205
 
206
-			$i18n['invoice_description'] = sprintf(
207
-				__( '%s Description', 'invoicing' ),
208
-				ucfirst( $invoice->get_invoice_quote_type() )
209
-			);
206
+            $i18n['invoice_description'] = sprintf(
207
+                __( '%s Description', 'invoicing' ),
208
+                ucfirst( $invoice->get_invoice_quote_type() )
209
+            );
210 210
 
211
-		}
212
-		return $i18n;
213
-	}
211
+        }
212
+        return $i18n;
213
+    }
214 214
 
215
-	/**
216
-	 * Change the admin footer text on GetPaid admin pages.
217
-	 *
218
-	 * @since  2.0.0
219
-	 * @param  string $footer_text
220
-	 * @return string
221
-	 */
222
-	public function admin_footer_text( $footer_text ) {
223
-		global $current_screen;
215
+    /**
216
+     * Change the admin footer text on GetPaid admin pages.
217
+     *
218
+     * @since  2.0.0
219
+     * @param  string $footer_text
220
+     * @return string
221
+     */
222
+    public function admin_footer_text( $footer_text ) {
223
+        global $current_screen;
224 224
 
225
-		$page    = isset( $_GET['page'] ) ? sanitize_text_field( $_GET['page'] ) : '';
225
+        $page    = isset( $_GET['page'] ) ? sanitize_text_field( $_GET['page'] ) : '';
226 226
 
227 227
         if ( ! empty( $current_screen->post_type ) ) {
228
-			$page = $current_screen->post_type;
228
+            $page = $current_screen->post_type;
229 229
         }
230 230
 
231 231
         // General styles.
232 232
         if ( apply_filters( 'getpaid_display_admin_footer_text', wpinv_current_user_can_manage_invoicing() ) && false !== stripos( $page, 'wpi' ) ) {
233 233
 
234
-			// Change the footer text
235
-			if ( ! get_user_meta( get_current_user_id(), 'getpaid_admin_footer_text_rated', true ) ) {
234
+            // Change the footer text
235
+            if ( ! get_user_meta( get_current_user_id(), 'getpaid_admin_footer_text_rated', true ) ) {
236 236
 
237
-				$rating_url  = esc_url(
238
-					wp_nonce_url(
239
-						admin_url( 'admin.php?page=wpinv-reports&getpaid-admin-action=rate_plugin' ),
240
-						'getpaid-nonce',
241
-						'getpaid-nonce'
237
+                $rating_url  = esc_url(
238
+                    wp_nonce_url(
239
+                        admin_url( 'admin.php?page=wpinv-reports&getpaid-admin-action=rate_plugin' ),
240
+                        'getpaid-nonce',
241
+                        'getpaid-nonce'
242 242
                     )
243
-				);
243
+                );
244 244
 
245
-				$footer_text = sprintf(
246
-					/* translators: %s: five stars */
247
-					__( 'If you like <strong>GetPaid</strong>, please leave us a %s rating. A huge thanks in advance!', 'invoicing' ),
248
-					"<a href='$rating_url'>&#9733;&#9733;&#9733;&#9733;&#9733;</a>"
249
-				);
245
+                $footer_text = sprintf(
246
+                    /* translators: %s: five stars */
247
+                    __( 'If you like <strong>GetPaid</strong>, please leave us a %s rating. A huge thanks in advance!', 'invoicing' ),
248
+                    "<a href='$rating_url'>&#9733;&#9733;&#9733;&#9733;&#9733;</a>"
249
+                );
250 250
 
251
-			} else {
251
+            } else {
252 252
 
253
-				$footer_text = sprintf(
254
-					/* translators: %s: GetPaid */
255
-					__( 'Thank you for using %s!', 'invoicing' ),
256
-					"<a href='https://wpgetpaid.com/' target='_blank'><strong>GetPaid</strong></a>"
257
-				);
253
+                $footer_text = sprintf(
254
+                    /* translators: %s: GetPaid */
255
+                    __( 'Thank you for using %s!', 'invoicing' ),
256
+                    "<a href='https://wpgetpaid.com/' target='_blank'><strong>GetPaid</strong></a>"
257
+                );
258 258
 
259
-			}
259
+            }
260 260
 }
261 261
 
262
-		return $footer_text;
263
-	}
264
-
265
-	/**
266
-	 * Redirects to wp.org to rate the plugin.
267
-	 *
268
-	 * @since  2.0.0
269
-	 */
270
-	public function redirect_to_wordpress_rating_page() {
271
-		update_user_meta( get_current_user_id(), 'getpaid_admin_footer_text_rated', 1 );
272
-		wp_redirect( 'https://wordpress.org/support/plugin/invoicing/reviews?rate=5#new-post' );
273
-		exit;
274
-	}
275
-
276
-    /**
277
-	 * Loads payment form js.
278
-	 *
279
-	 */
280
-	protected function load_payment_form_scripts() {
262
+        return $footer_text;
263
+    }
264
+
265
+    /**
266
+     * Redirects to wp.org to rate the plugin.
267
+     *
268
+     * @since  2.0.0
269
+     */
270
+    public function redirect_to_wordpress_rating_page() {
271
+        update_user_meta( get_current_user_id(), 'getpaid_admin_footer_text_rated', 1 );
272
+        wp_redirect( 'https://wordpress.org/support/plugin/invoicing/reviews?rate=5#new-post' );
273
+        exit;
274
+    }
275
+
276
+    /**
277
+     * Loads payment form js.
278
+     *
279
+     */
280
+    protected function load_payment_form_scripts() {
281 281
         global $post;
282 282
 
283 283
         wp_enqueue_script( 'vue', WPINV_PLUGIN_URL . 'assets/js/vue/vue.min.js', array(), WPINV_VERSION );
284
-		wp_enqueue_script( 'sortable', WPINV_PLUGIN_URL . 'assets/js/sortable.min.js', array(), WPINV_VERSION );
285
-		wp_enqueue_script( 'vue_draggable', WPINV_PLUGIN_URL . 'assets/js/vue/vuedraggable.min.js', array( 'sortable', 'vue' ), WPINV_VERSION );
284
+        wp_enqueue_script( 'sortable', WPINV_PLUGIN_URL . 'assets/js/sortable.min.js', array(), WPINV_VERSION );
285
+        wp_enqueue_script( 'vue_draggable', WPINV_PLUGIN_URL . 'assets/js/vue/vuedraggable.min.js', array( 'sortable', 'vue' ), WPINV_VERSION );
286 286
 
287
-		$version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/admin-payment-forms.js' );
288
-		wp_register_script( 'wpinv-admin-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/admin-payment-forms.js', array( 'wpinv-admin-script', 'vue_draggable', 'wp-hooks' ), $version );
287
+        $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/admin-payment-forms.js' );
288
+        wp_register_script( 'wpinv-admin-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/admin-payment-forms.js', array( 'wpinv-admin-script', 'vue_draggable', 'wp-hooks' ), $version );
289 289
 
290
-		wp_localize_script(
290
+        wp_localize_script(
291 291
             'wpinv-admin-payment-form-script',
292 292
             'wpinvPaymentFormAdmin',
293 293
             array(
294
-				'elements'      => wpinv_get_data( 'payment-form-elements' ),
295
-				'form_elements' => getpaid_get_payment_form_elements( $post->ID ),
296
-				'currency'      => wpinv_currency_symbol(),
297
-				'position'      => wpinv_currency_position(),
298
-				'decimals'      => (int) wpinv_decimals(),
299
-				'thousands_sep' => wpinv_thousands_separator(),
300
-				'decimals_sep'  => wpinv_decimal_separator(),
301
-				'form_items'    => gepaid_get_form_items( $post->ID ),
302
-				'is_default'    => $post->ID == wpinv_get_default_payment_form(),
294
+                'elements'      => wpinv_get_data( 'payment-form-elements' ),
295
+                'form_elements' => getpaid_get_payment_form_elements( $post->ID ),
296
+                'currency'      => wpinv_currency_symbol(),
297
+                'position'      => wpinv_currency_position(),
298
+                'decimals'      => (int) wpinv_decimals(),
299
+                'thousands_sep' => wpinv_thousands_separator(),
300
+                'decimals_sep'  => wpinv_decimal_separator(),
301
+                'form_items'    => gepaid_get_form_items( $post->ID ),
302
+                'is_default'    => $post->ID == wpinv_get_default_payment_form(),
303 303
             )
304 304
         );
305 305
 
@@ -308,19 +308,19 @@  discard block
 block discarded – undo
308 308
     }
309 309
 
310 310
     /**
311
-	 * Add our classes to admin pages.
311
+     * Add our classes to admin pages.
312 312
      *
313 313
      * @param string $classes
314 314
      * @return string
315
-	 *
316
-	 */
315
+     *
316
+     */
317 317
     public function admin_body_class( $classes ) {
318
-		global $pagenow, $post, $current_screen;
318
+        global $pagenow, $post, $current_screen;
319 319
 
320 320
         $page = isset( $_GET['page'] ) ? sanitize_text_field( $_GET['page'] ) : '';
321 321
 
322 322
         if ( ! empty( $current_screen->post_type ) ) {
323
-			$page = $current_screen->post_type;
323
+            $page = $current_screen->post_type;
324 324
         }
325 325
 
326 326
         if ( false !== stripos( $page, 'wpi' ) ) {
@@ -329,70 +329,70 @@  discard block
 block discarded – undo
329 329
 
330 330
         if ( in_array( $page, wpinv_parse_list( 'wpi_invoice wpi_payment_form wpi_quote' ) ) ) {
331 331
             $classes .= ' wpinv-cpt wpinv';
332
-		}
332
+        }
333 333
 
334
-		if ( getpaid_is_invoice_post_type( $page ) ) {
334
+        if ( getpaid_is_invoice_post_type( $page ) ) {
335 335
             $classes .= ' getpaid-is-invoice-cpt';
336 336
         }
337 337
 
338
-		return $classes;
338
+        return $classes;
339 339
     }
340 340
 
341 341
     /**
342
-	 * Maybe show the AyeCode Connect Notice.
343
-	 */
344
-	public function init_ayecode_connect_helper() {
342
+     * Maybe show the AyeCode Connect Notice.
343
+     */
344
+    public function init_ayecode_connect_helper() {
345 345
 
346
-		// Register with the deactivation survey class.
347
-		AyeCode_Deactivation_Survey::instance(
346
+        // Register with the deactivation survey class.
347
+        AyeCode_Deactivation_Survey::instance(
348 348
             array(
349
-				'slug'              => 'invoicing',
350
-				'version'           => WPINV_VERSION,
351
-				'support_url'       => 'https://wpgetpaid.com/support/',
352
-				'documentation_url' => 'https://docs.wpgetpaid.com/',
353
-				'activated'         => (int) get_option( 'gepaid_installed_on' ),
349
+                'slug'              => 'invoicing',
350
+                'version'           => WPINV_VERSION,
351
+                'support_url'       => 'https://wpgetpaid.com/support/',
352
+                'documentation_url' => 'https://docs.wpgetpaid.com/',
353
+                'activated'         => (int) get_option( 'gepaid_installed_on' ),
354 354
             )
355 355
         );
356 356
 
357 357
         new AyeCode_Connect_Helper(
358 358
             array(
359
-				'connect_title'     => __( 'WP Invoicing - an AyeCode product!', 'invoicing' ),
360
-				'connect_external'  => __( 'Please confirm you wish to connect your site?', 'invoicing' ),
361
-				'connect'           => sprintf( __( '<strong>Have a license?</strong> Forget about entering license keys or downloading zip files, connect your site for instant access. %1$slearn more%2$s', 'invoicing' ), "<a href='https://ayecode.io/introducing-ayecode-connect/' target='_blank'>", '</a>' ),
362
-				'connect_button'    => __( 'Connect Site', 'invoicing' ),
363
-				'connecting_button' => __( 'Connecting...', 'invoicing' ),
364
-				'error_localhost'   => __( 'This service will only work with a live domain, not a localhost.', 'invoicing' ),
365
-				'error'             => __( 'Something went wrong, please refresh and try again.', 'invoicing' ),
359
+                'connect_title'     => __( 'WP Invoicing - an AyeCode product!', 'invoicing' ),
360
+                'connect_external'  => __( 'Please confirm you wish to connect your site?', 'invoicing' ),
361
+                'connect'           => sprintf( __( '<strong>Have a license?</strong> Forget about entering license keys or downloading zip files, connect your site for instant access. %1$slearn more%2$s', 'invoicing' ), "<a href='https://ayecode.io/introducing-ayecode-connect/' target='_blank'>", '</a>' ),
362
+                'connect_button'    => __( 'Connect Site', 'invoicing' ),
363
+                'connecting_button' => __( 'Connecting...', 'invoicing' ),
364
+                'error_localhost'   => __( 'This service will only work with a live domain, not a localhost.', 'invoicing' ),
365
+                'error'             => __( 'Something went wrong, please refresh and try again.', 'invoicing' ),
366 366
             ),
367 367
             array( 'wpi-addons' )
368 368
         );
369 369
 
370 370
     }
371 371
 
372
-	/**
373
-	 * Redirect users to settings on activation.
374
-	 *
375
-	 * @return void
376
-	 */
377
-	public function activation_redirect() {
372
+    /**
373
+     * Redirect users to settings on activation.
374
+     *
375
+     * @return void
376
+     */
377
+    public function activation_redirect() {
378 378
 
379
-		$redirected = get_option( 'wpinv_redirected_to_settings' );
379
+        $redirected = get_option( 'wpinv_redirected_to_settings' );
380 380
 
381
-		if ( ! empty( $redirected ) || wp_doing_ajax() || ! current_user_can( 'manage_options' ) ) {
382
-			return;
383
-		}
381
+        if ( ! empty( $redirected ) || wp_doing_ajax() || ! current_user_can( 'manage_options' ) ) {
382
+            return;
383
+        }
384 384
 
385
-		// Bail if activating from network, or bulk
386
-		if ( is_network_admin() || isset( $_GET['activate-multi'] ) ) {
387
-			return;
388
-		}
385
+        // Bail if activating from network, or bulk
386
+        if ( is_network_admin() || isset( $_GET['activate-multi'] ) ) {
387
+            return;
388
+        }
389 389
 
390
-	    update_option( 'wpinv_redirected_to_settings', 1 );
390
+        update_option( 'wpinv_redirected_to_settings', 1 );
391 391
 
392 392
         wp_safe_redirect( admin_url( 'index.php?page=gp-setup' ) );
393 393
         exit;
394 394
 
395
-	}
395
+    }
396 396
 
397 397
     /**
398 398
      * Fires an admin action after verifying that a user can fire them.
@@ -405,555 +405,555 @@  discard block
 block discarded – undo
405 405
         }
406 406
     }
407 407
 
408
-	/**
408
+    /**
409 409
      * Duplicate invoice.
410
-	 *
411
-	 * @param array $args
410
+     *
411
+     * @param array $args
412 412
      */
413 413
     public function duplicate_invoice( $args ) {
414 414
 
415
-		if ( empty( $args['invoice_id'] ) ) {
416
-			return;
417
-		}
415
+        if ( empty( $args['invoice_id'] ) ) {
416
+            return;
417
+        }
418 418
 
419
-		$invoice = new WPInv_Invoice( (int) $args['invoice_id'] );
419
+        $invoice = new WPInv_Invoice( (int) $args['invoice_id'] );
420 420
 
421
-		if ( ! $invoice->exists() ) {
422
-			return;
423
-		}
421
+        if ( ! $invoice->exists() ) {
422
+            return;
423
+        }
424 424
 
425
-		$new_invoice = getpaid_duplicate_invoice( $invoice );
426
-		$new_invoice->save();
425
+        $new_invoice = getpaid_duplicate_invoice( $invoice );
426
+        $new_invoice->save();
427 427
 
428
-		if ( $new_invoice->exists() ) {
428
+        if ( $new_invoice->exists() ) {
429 429
 
430
-			getpaid_admin()->show_success( __( 'Invoice duplicated successfully.', 'invoicing' ) );
430
+            getpaid_admin()->show_success( __( 'Invoice duplicated successfully.', 'invoicing' ) );
431 431
 
432
-			wp_safe_redirect(
433
-				add_query_arg(
434
-					array(
435
-						'action' => 'edit',
436
-						'post'   => $new_invoice->get_id(),
437
-					),
438
-					admin_url( 'post.php' )
439
-				)
440
-			);
441
-			exit;
432
+            wp_safe_redirect(
433
+                add_query_arg(
434
+                    array(
435
+                        'action' => 'edit',
436
+                        'post'   => $new_invoice->get_id(),
437
+                    ),
438
+                    admin_url( 'post.php' )
439
+                )
440
+            );
441
+            exit;
442 442
 
443
-		}
443
+        }
444 444
 
445
-		getpaid_admin()->show_error( __( 'There was an error duplicating this invoice. Please try again.', 'invoicing' ) );
445
+        getpaid_admin()->show_error( __( 'There was an error duplicating this invoice. Please try again.', 'invoicing' ) );
446 446
 
447
-	}
447
+    }
448 448
 
449
-	/**
449
+    /**
450 450
      * Refund an invoice.
451
-	 *
452
-	 * @param array $args
451
+     *
452
+     * @param array $args
453 453
      */
454 454
     public function refund_invoice( $args ) {
455 455
 
456
-		if ( empty( $args['invoice_id'] ) ) {
457
-			return;
458
-		}
459
-
460
-		$invoice = new WPInv_Invoice( (int) $args['invoice_id'] );
461
-
462
-		if ( ! $invoice->exists() || $invoice->is_refunded() ) {
463
-			return;
464
-		}
465
-
466
-		$invoice->refund();
467
-
468
-		// Refund remotely.
469
-		if ( getpaid_payment_gateway_supports( $invoice->get_gateway(), 'refunds' ) && ! empty( $args['getpaid_refund_remote'] ) ) {
470
-			do_action( 'getpaid_refund_invoice_remotely', $invoice );
471
-		}
472
-
473
-		// Cancel subscriptions.
474
-		if ( ! empty( $args['getpaid_cancel_subscription'] ) ) {
475
-			$subscriptions = getpaid_get_invoice_subscriptions( $invoice );
476
-
477
-			if ( ! empty( $subscriptions ) ) {
478
-				if ( ! is_array( $subscriptions ) ) {
479
-					$subscriptions = array( $subscriptions );
480
-				}
481
-
482
-				foreach ( $subscriptions as $subscription ) {
483
-					$subscription->cancel();
484
-					$invoice->add_system_note(
485
-						sprintf(
486
-							// translators: %s: subscription ID.
487
-							__( 'Subscription #%s cancelled', 'invoicing' ),
488
-							$subscription->get_id()
489
-						)
490
-					);
491
-				}
492
-			}
493
-		}
494
-
495
-		// Add notice.
496
-		$this->show_success( __( 'Invoice refunded successfully.', 'invoicing' ) );
497
-
498
-		// Redirect.
499
-		wp_safe_redirect(
500
-			remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id', 'getpaid_cancel_subscription', 'getpaid_refund_remote' ) )
501
-		);
502
-	}
503
-
504
-	/**
456
+        if ( empty( $args['invoice_id'] ) ) {
457
+            return;
458
+        }
459
+
460
+        $invoice = new WPInv_Invoice( (int) $args['invoice_id'] );
461
+
462
+        if ( ! $invoice->exists() || $invoice->is_refunded() ) {
463
+            return;
464
+        }
465
+
466
+        $invoice->refund();
467
+
468
+        // Refund remotely.
469
+        if ( getpaid_payment_gateway_supports( $invoice->get_gateway(), 'refunds' ) && ! empty( $args['getpaid_refund_remote'] ) ) {
470
+            do_action( 'getpaid_refund_invoice_remotely', $invoice );
471
+        }
472
+
473
+        // Cancel subscriptions.
474
+        if ( ! empty( $args['getpaid_cancel_subscription'] ) ) {
475
+            $subscriptions = getpaid_get_invoice_subscriptions( $invoice );
476
+
477
+            if ( ! empty( $subscriptions ) ) {
478
+                if ( ! is_array( $subscriptions ) ) {
479
+                    $subscriptions = array( $subscriptions );
480
+                }
481
+
482
+                foreach ( $subscriptions as $subscription ) {
483
+                    $subscription->cancel();
484
+                    $invoice->add_system_note(
485
+                        sprintf(
486
+                            // translators: %s: subscription ID.
487
+                            __( 'Subscription #%s cancelled', 'invoicing' ),
488
+                            $subscription->get_id()
489
+                        )
490
+                    );
491
+                }
492
+            }
493
+        }
494
+
495
+        // Add notice.
496
+        $this->show_success( __( 'Invoice refunded successfully.', 'invoicing' ) );
497
+
498
+        // Redirect.
499
+        wp_safe_redirect(
500
+            remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id', 'getpaid_cancel_subscription', 'getpaid_refund_remote' ) )
501
+        );
502
+    }
503
+
504
+    /**
505 505
      * Sends a payment reminder to a customer.
506
-	 *
507
-	 * @param array $args
506
+     *
507
+     * @param array $args
508 508
      */
509 509
     public function duplicate_payment_form( $args ) {
510 510
 
511
-		if ( empty( $args['form_id'] ) ) {
512
-			return;
513
-		}
514
-
515
-		$form = new GetPaid_Payment_Form( (int) $args['form_id'] );
511
+        if ( empty( $args['form_id'] ) ) {
512
+            return;
513
+        }
516 514
 
517
-		if ( ! $form->exists() ) {
518
-			return;
519
-		}
515
+        $form = new GetPaid_Payment_Form( (int) $args['form_id'] );
520 516
 
521
-		$new_form = new GetPaid_Payment_Form();
522
-		$new_form->set_author( $form->get_author( 'edit' ) );
523
-		$new_form->set_name( $form->get_name( 'edit' ) . __( '(copy)', 'invoicing' ) );
524
-		$new_form->set_elements( $form->get_elements( 'edit' ) );
525
-		$new_form->set_items( $form->get_items( 'edit' ) );
526
-		$new_form->save();
517
+        if ( ! $form->exists() ) {
518
+            return;
519
+        }
527 520
 
528
-		if ( $new_form->exists() ) {
529
-			$this->show_success( __( 'Form duplicated successfully', 'invoicing' ) );
530
-			$url = get_edit_post_link( $new_form->get_id(), 'edit' );
531
-		} else {
532
-			$this->show_error( __( 'Unable to duplicate form', 'invoicing' ) );
533
-			$url = remove_query_arg( array( 'getpaid-admin-action', 'form_id', 'getpaid-nonce' ) );
534
-		}
521
+        $new_form = new GetPaid_Payment_Form();
522
+        $new_form->set_author( $form->get_author( 'edit' ) );
523
+        $new_form->set_name( $form->get_name( 'edit' ) . __( '(copy)', 'invoicing' ) );
524
+        $new_form->set_elements( $form->get_elements( 'edit' ) );
525
+        $new_form->set_items( $form->get_items( 'edit' ) );
526
+        $new_form->save();
527
+
528
+        if ( $new_form->exists() ) {
529
+            $this->show_success( __( 'Form duplicated successfully', 'invoicing' ) );
530
+            $url = get_edit_post_link( $new_form->get_id(), 'edit' );
531
+        } else {
532
+            $this->show_error( __( 'Unable to duplicate form', 'invoicing' ) );
533
+            $url = remove_query_arg( array( 'getpaid-admin-action', 'form_id', 'getpaid-nonce' ) );
534
+        }
535 535
 
536
-		wp_redirect( $url );
537
-		exit;
538
-	}
536
+        wp_redirect( $url );
537
+        exit;
538
+    }
539 539
 
540
-	/**
540
+    /**
541 541
      * Resets form stats.
542
-	 *
543
-	 * @param array $args
542
+     *
543
+     * @param array $args
544 544
      */
545 545
     public function reset_form_stats( $args ) {
546 546
 
547
-		if ( empty( $args['form_id'] ) ) {
548
-			return;
549
-		}
547
+        if ( empty( $args['form_id'] ) ) {
548
+            return;
549
+        }
550 550
 
551
-		$form = new GetPaid_Payment_Form( (int) $args['form_id'] );
551
+        $form = new GetPaid_Payment_Form( (int) $args['form_id'] );
552 552
 
553
-		if ( ! $form->exists() ) {
554
-			return;
555
-		}
553
+        if ( ! $form->exists() ) {
554
+            return;
555
+        }
556 556
 
557
-		$form->set_earned( 0 );
558
-		$form->set_refunded( 0 );
559
-		$form->set_cancelled( 0 );
560
-		$form->set_failed( 0 );
561
-		$form->save();
557
+        $form->set_earned( 0 );
558
+        $form->set_refunded( 0 );
559
+        $form->set_cancelled( 0 );
560
+        $form->set_failed( 0 );
561
+        $form->save();
562 562
 
563
-		$this->show_success( __( 'Form stats reset successfully', 'invoicing' ) );
563
+        $this->show_success( __( 'Form stats reset successfully', 'invoicing' ) );
564 564
 
565
-		wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'form_id', 'getpaid-nonce' ) ) );
566
-		exit;
567
-	}
565
+        wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'form_id', 'getpaid-nonce' ) ) );
566
+        exit;
567
+    }
568 568
 
569
-	/**
569
+    /**
570 570
      * Sends a payment reminder to a customer.
571
-	 *
572
-	 * @param array $args
571
+     *
572
+     * @param array $args
573 573
      */
574 574
     public function send_customer_invoice( $args ) {
575
-		getpaid()->get( 'invoice_emails' )->user_invoice( new WPInv_Invoice( $args['invoice_id'] ), true );
576
-		wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) );
577
-		exit;
578
-	}
575
+        getpaid()->get( 'invoice_emails' )->user_invoice( new WPInv_Invoice( $args['invoice_id'] ), true );
576
+        wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) );
577
+        exit;
578
+    }
579 579
 
580
-	/**
580
+    /**
581 581
      * Sends a payment reminder to a customer.
582
-	 *
583
-	 * @param array $args
582
+     *
583
+     * @param array $args
584 584
      */
585 585
     public function send_customer_payment_reminder( $args ) {
586
-		$sent = getpaid()->get( 'invoice_emails' )->force_send_overdue_notice( new WPInv_Invoice( $args['invoice_id'] ) );
586
+        $sent = getpaid()->get( 'invoice_emails' )->force_send_overdue_notice( new WPInv_Invoice( $args['invoice_id'] ) );
587 587
 
588
-		if ( $sent ) {
589
-			$this->show_success( __( 'Payment reminder was successfully sent to the customer', 'invoicing' ) );
590
-		} else {
591
-			$this->show_error( __( 'Could not sent payment reminder to the customer', 'invoicing' ) );
592
-		}
588
+        if ( $sent ) {
589
+            $this->show_success( __( 'Payment reminder was successfully sent to the customer', 'invoicing' ) );
590
+        } else {
591
+            $this->show_error( __( 'Could not sent payment reminder to the customer', 'invoicing' ) );
592
+        }
593 593
 
594
-		wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) );
595
-		exit;
596
-	}
594
+        wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) );
595
+        exit;
596
+    }
597 597
 
598
-	/**
598
+    /**
599 599
      * Resets tax rates.
600
-	 *
600
+     *
601 601
      */
602 602
     public function admin_reset_tax_rates() {
603 603
 
604
-		update_option( 'wpinv_tax_rates', wpinv_get_data( 'tax-rates' ) );
605
-		wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) );
606
-		exit;
604
+        update_option( 'wpinv_tax_rates', wpinv_get_data( 'tax-rates' ) );
605
+        wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) );
606
+        exit;
607 607
 
608
-	}
608
+    }
609 609
 
610
-	/**
610
+    /**
611 611
      * Resets admin pages.
612
-	 *
612
+     *
613 613
      */
614 614
     public function admin_create_missing_pages() {
615
-		$installer = new GetPaid_Installer();
616
-		$installer->create_pages();
617
-		$this->show_success( __( 'GetPaid pages updated.', 'invoicing' ) );
618
-		wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) );
619
-		exit;
620
-	}
621
-
622
-	/**
623
-	 * Refreshes the permalinks.
624
-	 */
625
-	public function admin_refresh_permalinks() {
626
-		flush_rewrite_rules();
627
-		$this->show_success( __( 'Permalinks refreshed.', 'invoicing' ) );
628
-		wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) );
629
-		exit;
630
-	}
631
-
632
-	/**
615
+        $installer = new GetPaid_Installer();
616
+        $installer->create_pages();
617
+        $this->show_success( __( 'GetPaid pages updated.', 'invoicing' ) );
618
+        wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) );
619
+        exit;
620
+    }
621
+
622
+    /**
623
+     * Refreshes the permalinks.
624
+     */
625
+    public function admin_refresh_permalinks() {
626
+        flush_rewrite_rules();
627
+        $this->show_success( __( 'Permalinks refreshed.', 'invoicing' ) );
628
+        wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) );
629
+        exit;
630
+    }
631
+
632
+    /**
633 633
      * Creates missing admin tables.
634
-	 *
634
+     *
635 635
      */
636 636
     public function admin_create_missing_tables() {
637
-		global $wpdb;
637
+        global $wpdb;
638 638
 
639
-		GetPaid_Installer::create_db_tables();
640
-		GetPaid_Installer::migrate_old_customers();
639
+        GetPaid_Installer::create_db_tables();
640
+        GetPaid_Installer::migrate_old_customers();
641 641
 
642
-		if ( '' !== $wpdb->last_error ) {
643
-			$this->show_error( __( 'Your GetPaid tables have been updated:', 'invoicing' ) . ' ' . $wpdb->last_error );
644
-		} else {
645
-			$this->show_success( __( 'Your GetPaid tables have been updated.', 'invoicing' ) );
646
-		}
642
+        if ( '' !== $wpdb->last_error ) {
643
+            $this->show_error( __( 'Your GetPaid tables have been updated:', 'invoicing' ) . ' ' . $wpdb->last_error );
644
+        } else {
645
+            $this->show_success( __( 'Your GetPaid tables have been updated.', 'invoicing' ) );
646
+        }
647 647
 
648
-		wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) );
649
-		exit;
650
-	}
648
+        wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) );
649
+        exit;
650
+    }
651 651
 
652
-	/**
652
+    /**
653 653
      * Migrates old invoices to the new database tables.
654
-	 *
654
+     *
655 655
      */
656 656
     public function admin_migrate_old_invoices() {
657 657
 
658
-		// Migrate the invoices.
659
-		$installer = new GetPaid_Installer();
660
-		$installer->migrate_old_invoices();
658
+        // Migrate the invoices.
659
+        $installer = new GetPaid_Installer();
660
+        $installer->migrate_old_invoices();
661 661
 
662
-		// Show an admin message.
663
-		$this->show_success( __( 'Your invoices have been migrated.', 'invoicing' ) );
662
+        // Show an admin message.
663
+        $this->show_success( __( 'Your invoices have been migrated.', 'invoicing' ) );
664 664
 
665
-		// Redirect the admin.
666
-		wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) );
667
-		exit;
665
+        // Redirect the admin.
666
+        wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) );
667
+        exit;
668 668
 
669
-	}
669
+    }
670 670
 
671
-	/**
671
+    /**
672 672
      * Download customers.
673
-	 *
673
+     *
674 674
      */
675 675
     public function admin_download_customers() {
676 676
 
677
-		$output = fopen( 'php://output', 'w' );
677
+        $output = fopen( 'php://output', 'w' );
678 678
 
679
-		if ( false === $output ) {
680
-			wp_die( esc_html__( 'Unsupported server', 'invoicing' ), 500 );
681
-		}
679
+        if ( false === $output ) {
680
+            wp_die( esc_html__( 'Unsupported server', 'invoicing' ), 500 );
681
+        }
682 682
 
683
-		header( 'Content-Type:text/csv' );
684
-		header( 'Content-Disposition:attachment;filename=customers.csv' );
683
+        header( 'Content-Type:text/csv' );
684
+        header( 'Content-Disposition:attachment;filename=customers.csv' );
685 685
 
686
-		/** @var GetPaid_Customer[] $customers */
687
-		$customers = getpaid_get_customers( array( 'number' => -1 ) );
688
-		$columns   = array_keys( GetPaid_Customer_Data_Store::get_database_fields() );
686
+        /** @var GetPaid_Customer[] $customers */
687
+        $customers = getpaid_get_customers( array( 'number' => -1 ) );
688
+        $columns   = array_keys( GetPaid_Customer_Data_Store::get_database_fields() );
689 689
 
690
-		// Output the csv column headers.
691
-		fputcsv( $output, $columns );
690
+        // Output the csv column headers.
691
+        fputcsv( $output, $columns );
692 692
 
693
-		// Loop through
694
-		foreach ( $customers as $customer ) {
693
+        // Loop through
694
+        foreach ( $customers as $customer ) {
695 695
 
696
-			$row  = array();
696
+            $row  = array();
697 697
 
698
-			foreach ( $columns as $column ) {
699
-				$row[]  = (string) maybe_serialize( $customer->get( $column, 'edit' ) );
700
-			}
698
+            foreach ( $columns as $column ) {
699
+                $row[]  = (string) maybe_serialize( $customer->get( $column, 'edit' ) );
700
+            }
701 701
 
702
-			fputcsv( $output, $row );
703
-		}
702
+            fputcsv( $output, $row );
703
+        }
704 704
 
705
-		fclose( $output );
706
-		exit;
705
+        fclose( $output );
706
+        exit;
707 707
 
708
-	}
708
+    }
709 709
 
710
-	/**
710
+    /**
711 711
      * Installs a plugin.
712
-	 *
713
-	 * @param array $data
712
+     *
713
+     * @param array $data
714 714
      */
715 715
     public function admin_install_plugin( $data ) {
716 716
 
717
-		if ( ! empty( $data['plugins'] ) ) {
718
-			include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
719
-			wp_cache_flush();
717
+        if ( ! empty( $data['plugins'] ) ) {
718
+            include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
719
+            wp_cache_flush();
720 720
 
721
-			foreach ( $data['plugins'] as $slug => $file ) {
722
-				$plugin_zip = esc_url( 'https://downloads.wordpress.org/plugin/' . $slug . '.latest-stable.zip' );
723
-				$upgrader   = new Plugin_Upgrader( new Automatic_Upgrader_Skin() );
724
-				$installed  = $upgrader->install( $plugin_zip );
721
+            foreach ( $data['plugins'] as $slug => $file ) {
722
+                $plugin_zip = esc_url( 'https://downloads.wordpress.org/plugin/' . $slug . '.latest-stable.zip' );
723
+                $upgrader   = new Plugin_Upgrader( new Automatic_Upgrader_Skin() );
724
+                $installed  = $upgrader->install( $plugin_zip );
725 725
 
726
-				if ( ! is_wp_error( $installed ) && $installed ) {
727
-					activate_plugin( $file, '', false, true );
728
-				} else {
729
-					wpinv_error_log( $upgrader->skin->get_upgrade_messages(), false );
730
-				}
726
+                if ( ! is_wp_error( $installed ) && $installed ) {
727
+                    activate_plugin( $file, '', false, true );
728
+                } else {
729
+                    wpinv_error_log( $upgrader->skin->get_upgrade_messages(), false );
730
+                }
731 731
 }
732 732
 }
733 733
 
734
-		$redirect = isset( $data['redirect'] ) ? esc_url_raw( $data['redirect'] ) : admin_url( 'plugins.php' );
735
-		wp_safe_redirect( $redirect );
736
-		exit;
734
+        $redirect = isset( $data['redirect'] ) ? esc_url_raw( $data['redirect'] ) : admin_url( 'plugins.php' );
735
+        wp_safe_redirect( $redirect );
736
+        exit;
737 737
 
738
-	}
738
+    }
739 739
 
740
-	/**
740
+    /**
741 741
      * Connects a gateway.
742
-	 *
743
-	 * @param array $data
742
+     *
743
+     * @param array $data
744 744
      */
745 745
     public function admin_connect_gateway( $data ) {
746 746
 
747
-		if ( ! empty( $data['plugin'] ) ) {
747
+        if ( ! empty( $data['plugin'] ) ) {
748 748
 
749
-			$gateway     = sanitize_key( $data['plugin'] );
750
-			$connect_url = apply_filters( "getpaid_get_{$gateway}_connect_url", false, $data );
749
+            $gateway     = sanitize_key( $data['plugin'] );
750
+            $connect_url = apply_filters( "getpaid_get_{$gateway}_connect_url", false, $data );
751 751
 
752
-			if ( ! empty( $connect_url ) ) {
753
-				wp_redirect( $connect_url );
754
-				exit;
755
-			}
752
+            if ( ! empty( $connect_url ) ) {
753
+                wp_redirect( $connect_url );
754
+                exit;
755
+            }
756 756
 
757
-			if ( 'stripe' == $data['plugin'] ) {
758
-				require_once ABSPATH . 'wp-admin/includes/plugin.php';
759
-				include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
760
-				wp_cache_flush();
757
+            if ( 'stripe' == $data['plugin'] ) {
758
+                require_once ABSPATH . 'wp-admin/includes/plugin.php';
759
+                include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
760
+                wp_cache_flush();
761 761
 
762
-				if ( ! array_key_exists( 'getpaid-stripe-payments/getpaid-stripe-payments.php', get_plugins() ) ) {
763
-					$plugin_zip = esc_url( 'https://downloads.wordpress.org/plugin/getpaid-stripe-payments.latest-stable.zip' );
764
-					$upgrader   = new Plugin_Upgrader( new Automatic_Upgrader_Skin() );
765
-					$upgrader->install( $plugin_zip );
766
-				}
762
+                if ( ! array_key_exists( 'getpaid-stripe-payments/getpaid-stripe-payments.php', get_plugins() ) ) {
763
+                    $plugin_zip = esc_url( 'https://downloads.wordpress.org/plugin/getpaid-stripe-payments.latest-stable.zip' );
764
+                    $upgrader   = new Plugin_Upgrader( new Automatic_Upgrader_Skin() );
765
+                    $upgrader->install( $plugin_zip );
766
+                }
767 767
 
768
-				activate_plugin( 'getpaid-stripe-payments/getpaid-stripe-payments.php', '', false, true );
769
-			}
768
+                activate_plugin( 'getpaid-stripe-payments/getpaid-stripe-payments.php', '', false, true );
769
+            }
770 770
 
771
-			$connect_url = apply_filters( "getpaid_get_{$gateway}_connect_url", false, $data );
772
-			if ( ! empty( $connect_url ) ) {
773
-				wp_redirect( $connect_url );
774
-				exit;
775
-			}
771
+            $connect_url = apply_filters( "getpaid_get_{$gateway}_connect_url", false, $data );
772
+            if ( ! empty( $connect_url ) ) {
773
+                wp_redirect( $connect_url );
774
+                exit;
775
+            }
776 776
 }
777 777
 
778
-		$redirect = isset( $data['redirect'] ) ? esc_url_raw( urldecode( $data['redirect'] ) ) : admin_url( 'admin.php?page=wpinv-settings&tab=gateways' );
779
-		wp_safe_redirect( $redirect );
780
-		exit;
778
+        $redirect = isset( $data['redirect'] ) ? esc_url_raw( urldecode( $data['redirect'] ) ) : admin_url( 'admin.php?page=wpinv-settings&tab=gateways' );
779
+        wp_safe_redirect( $redirect );
780
+        exit;
781 781
 
782
-	}
782
+    }
783 783
 
784
-	/**
784
+    /**
785 785
      * Recalculates discounts.
786
-	 *
786
+     *
787 787
      */
788 788
     public function admin_recalculate_discounts() {
789
-		global $wpdb;
789
+        global $wpdb;
790 790
 
791
-		// Fetch all invoices that have discount codes.
792
-		$table    = $wpdb->prefix . 'getpaid_invoices';
793
-		$invoices = $wpdb->get_col( "SELECT `post_id` FROM `$table` WHERE `discount` = 0 && `discount_code` <> ''" );
791
+        // Fetch all invoices that have discount codes.
792
+        $table    = $wpdb->prefix . 'getpaid_invoices';
793
+        $invoices = $wpdb->get_col( "SELECT `post_id` FROM `$table` WHERE `discount` = 0 && `discount_code` <> ''" );
794 794
 
795
-		foreach ( $invoices as $invoice ) {
795
+        foreach ( $invoices as $invoice ) {
796 796
 
797
-			$invoice = new WPInv_Invoice( $invoice );
797
+            $invoice = new WPInv_Invoice( $invoice );
798 798
 
799
-			if ( ! $invoice->exists() ) {
800
-				continue;
801
-			}
799
+            if ( ! $invoice->exists() ) {
800
+                continue;
801
+            }
802 802
 
803
-			// Abort if the discount does not exist or does not apply here.
804
-			$discount = new WPInv_Discount( $invoice->get_discount_code() );
805
-			if ( ! $discount->exists() ) {
806
-				continue;
807
-			}
803
+            // Abort if the discount does not exist or does not apply here.
804
+            $discount = new WPInv_Discount( $invoice->get_discount_code() );
805
+            if ( ! $discount->exists() ) {
806
+                continue;
807
+            }
808 808
 
809
-			$invoice->add_discount( getpaid_calculate_invoice_discount( $invoice, $discount ) );
810
-			$invoice->recalculate_total();
809
+            $invoice->add_discount( getpaid_calculate_invoice_discount( $invoice, $discount ) );
810
+            $invoice->recalculate_total();
811 811
 
812
-			if ( $invoice->get_total_discount() > 0 ) {
813
-				$invoice->save();
814
-			}
812
+            if ( $invoice->get_total_discount() > 0 ) {
813
+                $invoice->save();
814
+            }
815 815
 }
816 816
 
817
-		// Show an admin message.
818
-		$this->show_success( __( 'Discounts have been recalculated.', 'invoicing' ) );
817
+        // Show an admin message.
818
+        $this->show_success( __( 'Discounts have been recalculated.', 'invoicing' ) );
819 819
 
820
-		// Redirect the admin.
821
-		wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) );
822
-		exit;
820
+        // Redirect the admin.
821
+        wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) );
822
+        exit;
823 823
 
824
-	}
824
+    }
825 825
 
826 826
     /**
827
-	 * Returns an array of admin notices.
828
-	 *
829
-	 * @since       1.0.19
827
+     * Returns an array of admin notices.
828
+     *
829
+     * @since       1.0.19
830 830
      * @return array
831
-	 */
832
-	public function get_notices() {
833
-		$notices = get_option( 'wpinv_admin_notices' );
831
+     */
832
+    public function get_notices() {
833
+        $notices = get_option( 'wpinv_admin_notices' );
834 834
         return is_array( $notices ) ? $notices : array();
835
-	}
835
+    }
836 836
 
837
-	/**
838
-	 * Checks if we have any admin notices.
839
-	 *
840
-	 * @since       2.0.4
837
+    /**
838
+     * Checks if we have any admin notices.
839
+     *
840
+     * @since       2.0.4
841 841
      * @return array
842
-	 */
843
-	public function has_notices() {
844
-		return count( $this->get_notices() ) > 0;
845
-	}
846
-
847
-	/**
848
-	 * Clears all admin notices
849
-	 *
850
-	 * @access      public
851
-	 * @since       1.0.19
852
-	 */
853
-	public function clear_notices() {
854
-		delete_option( 'wpinv_admin_notices' );
855
-	}
856
-
857
-	/**
858
-	 * Saves a new admin notice
859
-	 *
860
-	 * @access      public
861
-	 * @since       1.0.19
862
-	 */
863
-	public function save_notice( $type, $message ) {
864
-		$notices = $this->get_notices();
865
-
866
-		if ( empty( $notices[ $type ] ) || ! is_array( $notices[ $type ] ) ) {
867
-			$notices[ $type ] = array();
868
-		}
869
-
870
-		$notices[ $type ][] = $message;
871
-
872
-		update_option( 'wpinv_admin_notices', $notices );
873
-	}
874
-
875
-	/**
876
-	 * Displays a success notice
877
-	 *
878
-	 * @param       string $msg The message to qeue.
879
-	 * @access      public
880
-	 * @since       1.0.19
881
-	 */
882
-	public function show_success( $msg ) {
883
-		$this->save_notice( 'success', $msg );
884
-	}
885
-
886
-	/**
887
-	 * Displays a error notice
888
-	 *
889
-	 * @access      public
890
-	 * @param       string $msg The message to qeue.
891
-	 * @since       1.0.19
892
-	 */
893
-	public function show_error( $msg ) {
894
-		$this->save_notice( 'error', $msg );
895
-	}
896
-
897
-	/**
898
-	 * Displays a warning notice
899
-	 *
900
-	 * @access      public
901
-	 * @param       string $msg The message to qeue.
902
-	 * @since       1.0.19
903
-	 */
904
-	public function show_warning( $msg ) {
905
-		$this->save_notice( 'warning', $msg );
906
-	}
907
-
908
-	/**
909
-	 * Displays a info notice
910
-	 *
911
-	 * @access      public
912
-	 * @param       string $msg The message to qeue.
913
-	 * @since       1.0.19
914
-	 */
915
-	public function show_info( $msg ) {
916
-		$this->save_notice( 'info', $msg );
917
-	}
918
-
919
-	/**
920
-	 * Show notices
921
-	 *
922
-	 * @access      public
923
-	 * @since       1.0.19
924
-	 */
925
-	public function show_notices() {
842
+     */
843
+    public function has_notices() {
844
+        return count( $this->get_notices() ) > 0;
845
+    }
846
+
847
+    /**
848
+     * Clears all admin notices
849
+     *
850
+     * @access      public
851
+     * @since       1.0.19
852
+     */
853
+    public function clear_notices() {
854
+        delete_option( 'wpinv_admin_notices' );
855
+    }
856
+
857
+    /**
858
+     * Saves a new admin notice
859
+     *
860
+     * @access      public
861
+     * @since       1.0.19
862
+     */
863
+    public function save_notice( $type, $message ) {
864
+        $notices = $this->get_notices();
865
+
866
+        if ( empty( $notices[ $type ] ) || ! is_array( $notices[ $type ] ) ) {
867
+            $notices[ $type ] = array();
868
+        }
869
+
870
+        $notices[ $type ][] = $message;
871
+
872
+        update_option( 'wpinv_admin_notices', $notices );
873
+    }
874
+
875
+    /**
876
+     * Displays a success notice
877
+     *
878
+     * @param       string $msg The message to qeue.
879
+     * @access      public
880
+     * @since       1.0.19
881
+     */
882
+    public function show_success( $msg ) {
883
+        $this->save_notice( 'success', $msg );
884
+    }
885
+
886
+    /**
887
+     * Displays a error notice
888
+     *
889
+     * @access      public
890
+     * @param       string $msg The message to qeue.
891
+     * @since       1.0.19
892
+     */
893
+    public function show_error( $msg ) {
894
+        $this->save_notice( 'error', $msg );
895
+    }
896
+
897
+    /**
898
+     * Displays a warning notice
899
+     *
900
+     * @access      public
901
+     * @param       string $msg The message to qeue.
902
+     * @since       1.0.19
903
+     */
904
+    public function show_warning( $msg ) {
905
+        $this->save_notice( 'warning', $msg );
906
+    }
907
+
908
+    /**
909
+     * Displays a info notice
910
+     *
911
+     * @access      public
912
+     * @param       string $msg The message to qeue.
913
+     * @since       1.0.19
914
+     */
915
+    public function show_info( $msg ) {
916
+        $this->save_notice( 'info', $msg );
917
+    }
918
+
919
+    /**
920
+     * Show notices
921
+     *
922
+     * @access      public
923
+     * @since       1.0.19
924
+     */
925
+    public function show_notices() {
926 926
 
927 927
         $notices = $this->get_notices();
928 928
         $this->clear_notices();
929 929
 
930
-		foreach ( $notices as $type => $messages ) {
930
+        foreach ( $notices as $type => $messages ) {
931 931
 
932
-			if ( ! is_array( $messages ) ) {
933
-				continue;
934
-			}
932
+            if ( ! is_array( $messages ) ) {
933
+                continue;
934
+            }
935 935
 
936 936
             $type  = esc_attr( $type );
937
-			foreach ( $messages as $message ) {
938
-				echo wp_kses_post( "<div class='notice notice-$type is-dismissible'><p>$message</p></div>" );
937
+            foreach ( $messages as $message ) {
938
+                echo wp_kses_post( "<div class='notice notice-$type is-dismissible'><p>$message</p></div>" );
939 939
             }
940 940
 }
941 941
 
942
-		foreach ( array( 'checkout_page', 'invoice_history_page', 'success_page', 'failure_page', 'invoice_subscription_page' ) as $page ) {
943
-
944
-			if ( ! is_numeric( wpinv_get_option( $page, false ) ) ) {
945
-				$url     = wp_nonce_url(
946
-					add_query_arg( 'getpaid-admin-action', 'create_missing_pages' ),
947
-					'getpaid-nonce',
948
-					'getpaid-nonce'
949
-				);
950
-				$message  = __( 'Some GetPaid pages are missing. To use GetPaid without any issues, click the button below to generate the missing pages.', 'invoicing' );
951
-				$message2 = __( 'Generate Pages', 'invoicing' );
952
-				echo wp_kses_post( "<div class='notice notice-warning is-dismissible'><p>$message<br><br><a href='$url' class='button button-primary'>$message2</a></p></div>" );
953
-				break;
954
-			}
942
+        foreach ( array( 'checkout_page', 'invoice_history_page', 'success_page', 'failure_page', 'invoice_subscription_page' ) as $page ) {
943
+
944
+            if ( ! is_numeric( wpinv_get_option( $page, false ) ) ) {
945
+                $url     = wp_nonce_url(
946
+                    add_query_arg( 'getpaid-admin-action', 'create_missing_pages' ),
947
+                    'getpaid-nonce',
948
+                    'getpaid-nonce'
949
+                );
950
+                $message  = __( 'Some GetPaid pages are missing. To use GetPaid without any issues, click the button below to generate the missing pages.', 'invoicing' );
951
+                $message2 = __( 'Generate Pages', 'invoicing' );
952
+                echo wp_kses_post( "<div class='notice notice-warning is-dismissible'><p>$message<br><br><a href='$url' class='button button-primary'>$message2</a></p></div>" );
953
+                break;
954
+            }
955 955
 }
956 956
 
957
-	}
957
+    }
958 958
 
959 959
 }
Please login to merge, or discard this patch.
Spacing   +279 added lines, -279 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
  * The main admin class.
@@ -39,11 +39,11 @@  discard block
 block discarded – undo
39 39
 	 */
40 40
 	public function __construct() {
41 41
 
42
-        $this->admin_path  = plugin_dir_path( __FILE__ );
43
-		$this->admin_url   = plugins_url( '/', __FILE__ );
42
+        $this->admin_path = plugin_dir_path(__FILE__);
43
+		$this->admin_url   = plugins_url('/', __FILE__);
44 44
 		$this->reports     = new GetPaid_Reports();
45 45
 
46
-        if ( is_admin() ) {
46
+        if (is_admin()) {
47 47
 			$this->init_admin_hooks();
48 48
         }
49 49
 
@@ -54,36 +54,36 @@  discard block
 block discarded – undo
54 54
 	 *
55 55
 	 */
56 56
 	private function init_admin_hooks() {
57
-        add_action( 'admin_enqueue_scripts', array( $this, 'enqeue_scripts' ), 9 );
58
-        add_filter( 'admin_body_class', array( $this, 'admin_body_class' ) );
59
-        add_action( 'admin_init', array( $this, 'init_ayecode_connect_helper' ) );
60
-        add_action( 'admin_init', array( $this, 'activation_redirect' ) );
61
-        add_action( 'admin_init', array( $this, 'maybe_do_admin_action' ) );
62
-		add_action( 'admin_notices', array( $this, 'show_notices' ) );
63
-		add_action( 'getpaid_authenticated_admin_action_rate_plugin', array( $this, 'redirect_to_wordpress_rating_page' ) );
64
-		add_action( 'getpaid_authenticated_admin_action_duplicate_form', array( $this, 'duplicate_payment_form' ) );
65
-		add_action( 'getpaid_authenticated_admin_action_reset_form_stats', array( $this, 'reset_form_stats' ) );
66
-		add_action( 'getpaid_authenticated_admin_action_duplicate_invoice', array( $this, 'duplicate_invoice' ) );
67
-		add_action( 'getpaid_authenticated_admin_action_refund_invoice', array( $this, 'refund_invoice' ) );
68
-		add_action( 'getpaid_authenticated_admin_action_send_invoice', array( $this, 'send_customer_invoice' ) );
69
-		add_action( 'getpaid_authenticated_admin_action_send_invoice_reminder', array( $this, 'send_customer_payment_reminder' ) );
70
-        add_action( 'getpaid_authenticated_admin_action_reset_tax_rates', array( $this, 'admin_reset_tax_rates' ) );
71
-		add_action( 'getpaid_authenticated_admin_action_create_missing_pages', array( $this, 'admin_create_missing_pages' ) );
72
-		add_action( 'getpaid_authenticated_admin_action_refresh_permalinks', array( $this, 'admin_refresh_permalinks' ) );
73
-		add_action( 'getpaid_authenticated_admin_action_create_missing_tables', array( $this, 'admin_create_missing_tables' ) );
74
-		add_action( 'getpaid_authenticated_admin_action_migrate_old_invoices', array( $this, 'admin_migrate_old_invoices' ) );
75
-		add_action( 'getpaid_authenticated_admin_action_download_customers', array( $this, 'admin_download_customers' ) );
76
-		add_action( 'getpaid_authenticated_admin_action_recalculate_discounts', array( $this, 'admin_recalculate_discounts' ) );
77
-		add_action( 'getpaid_authenticated_admin_action_install_plugin', array( $this, 'admin_install_plugin' ) );
78
-		add_action( 'getpaid_authenticated_admin_action_connect_gateway', array( $this, 'admin_connect_gateway' ) );
79
-		add_filter( 'admin_footer_text', array( $this, 'admin_footer_text' ) );
80
-		do_action( 'getpaid_init_admin_hooks', $this );
57
+        add_action('admin_enqueue_scripts', array($this, 'enqeue_scripts'), 9);
58
+        add_filter('admin_body_class', array($this, 'admin_body_class'));
59
+        add_action('admin_init', array($this, 'init_ayecode_connect_helper'));
60
+        add_action('admin_init', array($this, 'activation_redirect'));
61
+        add_action('admin_init', array($this, 'maybe_do_admin_action'));
62
+		add_action('admin_notices', array($this, 'show_notices'));
63
+		add_action('getpaid_authenticated_admin_action_rate_plugin', array($this, 'redirect_to_wordpress_rating_page'));
64
+		add_action('getpaid_authenticated_admin_action_duplicate_form', array($this, 'duplicate_payment_form'));
65
+		add_action('getpaid_authenticated_admin_action_reset_form_stats', array($this, 'reset_form_stats'));
66
+		add_action('getpaid_authenticated_admin_action_duplicate_invoice', array($this, 'duplicate_invoice'));
67
+		add_action('getpaid_authenticated_admin_action_refund_invoice', array($this, 'refund_invoice'));
68
+		add_action('getpaid_authenticated_admin_action_send_invoice', array($this, 'send_customer_invoice'));
69
+		add_action('getpaid_authenticated_admin_action_send_invoice_reminder', array($this, 'send_customer_payment_reminder'));
70
+        add_action('getpaid_authenticated_admin_action_reset_tax_rates', array($this, 'admin_reset_tax_rates'));
71
+		add_action('getpaid_authenticated_admin_action_create_missing_pages', array($this, 'admin_create_missing_pages'));
72
+		add_action('getpaid_authenticated_admin_action_refresh_permalinks', array($this, 'admin_refresh_permalinks'));
73
+		add_action('getpaid_authenticated_admin_action_create_missing_tables', array($this, 'admin_create_missing_tables'));
74
+		add_action('getpaid_authenticated_admin_action_migrate_old_invoices', array($this, 'admin_migrate_old_invoices'));
75
+		add_action('getpaid_authenticated_admin_action_download_customers', array($this, 'admin_download_customers'));
76
+		add_action('getpaid_authenticated_admin_action_recalculate_discounts', array($this, 'admin_recalculate_discounts'));
77
+		add_action('getpaid_authenticated_admin_action_install_plugin', array($this, 'admin_install_plugin'));
78
+		add_action('getpaid_authenticated_admin_action_connect_gateway', array($this, 'admin_connect_gateway'));
79
+		add_filter('admin_footer_text', array($this, 'admin_footer_text'));
80
+		do_action('getpaid_init_admin_hooks', $this);
81 81
 
82 82
 		// Setup/welcome
83
-		if ( ! empty( $_GET['page'] ) ) {
84
-			switch ( sanitize_text_field( $_GET['page'] ) ) {
83
+		if (!empty($_GET['page'])) {
84
+			switch (sanitize_text_field($_GET['page'])) {
85 85
 				case 'gp-setup':
86
-					include_once dirname( __FILE__ ) . '/class-getpaid-admin-setup-wizard.php';
86
+					include_once dirname(__FILE__) . '/class-getpaid-admin-setup-wizard.php';
87 87
 					break;
88 88
 			}
89 89
 		}
@@ -97,37 +97,37 @@  discard block
 block discarded – undo
97 97
 	public function enqeue_scripts() {
98 98
         global $current_screen, $pagenow;
99 99
 
100
-		$page    = isset( $_GET['page'] ) ? sanitize_text_field( $_GET['page'] ) : '';
100
+		$page    = isset($_GET['page']) ? sanitize_text_field($_GET['page']) : '';
101 101
 		$editing = $pagenow == 'post.php' || $pagenow == 'post-new.php';
102 102
 
103
-        if ( ! empty( $current_screen->post_type ) ) {
103
+        if (!empty($current_screen->post_type)) {
104 104
 			$page = $current_screen->post_type;
105 105
         }
106 106
 
107 107
         // General styles.
108
-        if ( false !== stripos( $page, 'wpi' ) || false !== stripos( $page, 'getpaid' ) || 'gp-setup' == $page || false !== stripos( $page, 'geodir-tickets' ) ) {
108
+        if (false !== stripos($page, 'wpi') || false !== stripos($page, 'getpaid') || 'gp-setup' == $page || false !== stripos($page, 'geodir-tickets')) {
109 109
 
110 110
             // Styles.
111
-            $version = filemtime( WPINV_PLUGIN_DIR . 'assets/css/admin.css' );
112
-            wp_enqueue_style( 'wpinv_admin_style', WPINV_PLUGIN_URL . 'assets/css/admin.css', array( 'wp-color-picker' ), $version );
113
-            wp_enqueue_style( 'select2', WPINV_PLUGIN_URL . 'assets/css/select2/select2.min.css', array(), '4.0.13', 'all' );
111
+            $version = filemtime(WPINV_PLUGIN_DIR . 'assets/css/admin.css');
112
+            wp_enqueue_style('wpinv_admin_style', WPINV_PLUGIN_URL . 'assets/css/admin.css', array('wp-color-picker'), $version);
113
+            wp_enqueue_style('select2', WPINV_PLUGIN_URL . 'assets/css/select2/select2.min.css', array(), '4.0.13', 'all');
114 114
 
115 115
             // Scripts.
116
-            wp_enqueue_script( 'select2', WPINV_PLUGIN_URL . 'assets/js/select2/select2.full.min.js', array( 'jquery' ), WPINV_VERSION );
116
+            wp_enqueue_script('select2', WPINV_PLUGIN_URL . 'assets/js/select2/select2.full.min.js', array('jquery'), WPINV_VERSION);
117 117
 
118
-            $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/admin.js' );
119
-            wp_enqueue_script( 'wpinv-admin-script', WPINV_PLUGIN_URL . 'assets/js/admin.js', array( 'jquery', 'wp-color-picker', 'jquery-ui-tooltip' ), $version );
120
-            wp_localize_script( 'wpinv-admin-script', 'WPInv_Admin', apply_filters( 'wpinv_admin_js_localize', $this->get_admin_i18() ) );
118
+            $version = filemtime(WPINV_PLUGIN_DIR . 'assets/js/admin.js');
119
+            wp_enqueue_script('wpinv-admin-script', WPINV_PLUGIN_URL . 'assets/js/admin.js', array('jquery', 'wp-color-picker', 'jquery-ui-tooltip'), $version);
120
+            wp_localize_script('wpinv-admin-script', 'WPInv_Admin', apply_filters('wpinv_admin_js_localize', $this->get_admin_i18()));
121 121
 
122 122
         }
123 123
 
124 124
         // Payment form scripts.
125
-		if ( 'wpi_payment_form' == $page && $editing ) {
125
+		if ('wpi_payment_form' == $page && $editing) {
126 126
             $this->load_payment_form_scripts();
127 127
         }
128 128
 
129
-		if ( $page == 'wpinv-subscriptions' ) {
130
-			wp_enqueue_script( 'postbox' );
129
+		if ($page == 'wpinv-subscriptions') {
130
+			wp_enqueue_script('postbox');
131 131
 		}
132 132
 
133 133
     }
@@ -140,31 +140,31 @@  discard block
 block discarded – undo
140 140
         global $post;
141 141
 
142 142
 		$date_range = array(
143
-			'period' => isset( $_GET['date_range'] ) ? sanitize_text_field( $_GET['date_range'] ) : '7_days',
143
+			'period' => isset($_GET['date_range']) ? sanitize_text_field($_GET['date_range']) : '7_days',
144 144
 		);
145 145
 
146
-		if ( $date_range['period'] == 'custom' ) {
146
+		if ($date_range['period'] == 'custom') {
147 147
 
148
-			if ( isset( $_GET['from'] ) ) {
149
-				$date_range['after'] = date( 'Y-m-d', strtotime( sanitize_text_field( $_GET['from'] ), current_time( 'timestamp' ) ) - DAY_IN_SECONDS );
148
+			if (isset($_GET['from'])) {
149
+				$date_range['after'] = date('Y-m-d', strtotime(sanitize_text_field($_GET['from']), current_time('timestamp')) - DAY_IN_SECONDS);
150 150
 			}
151 151
 
152
-			if ( isset( $_GET['to'] ) ) {
153
-				$date_range['before'] = date( 'Y-m-d', strtotime( sanitize_text_field( $_GET['to'] ), current_time( 'timestamp' ) ) + DAY_IN_SECONDS );
152
+			if (isset($_GET['to'])) {
153
+				$date_range['before'] = date('Y-m-d', strtotime(sanitize_text_field($_GET['to']), current_time('timestamp')) + DAY_IN_SECONDS);
154 154
 			}
155 155
 }
156 156
 
157 157
         $i18n = array(
158
-            'ajax_url'                  => admin_url( 'admin-ajax.php' ),
159
-            'post_ID'                   => isset( $post->ID ) ? $post->ID : '',
160
-			'wpinv_nonce'               => wp_create_nonce( 'wpinv-nonce' ),
161
-			'rest_nonce'                => wp_create_nonce( 'wp_rest' ),
162
-			'rest_root'                 => esc_url_raw( rest_url() ),
158
+            'ajax_url'                  => admin_url('admin-ajax.php'),
159
+            'post_ID'                   => isset($post->ID) ? $post->ID : '',
160
+			'wpinv_nonce'               => wp_create_nonce('wpinv-nonce'),
161
+			'rest_nonce'                => wp_create_nonce('wp_rest'),
162
+			'rest_root'                 => esc_url_raw(rest_url()),
163 163
 			'date_range'                => $date_range,
164
-            'add_invoice_note_nonce'    => wp_create_nonce( 'add-invoice-note' ),
165
-            'delete_invoice_note_nonce' => wp_create_nonce( 'delete-invoice-note' ),
166
-            'invoice_item_nonce'        => wp_create_nonce( 'invoice-item' ),
167
-            'billing_details_nonce'     => wp_create_nonce( 'get-billing-details' ),
164
+            'add_invoice_note_nonce'    => wp_create_nonce('add-invoice-note'),
165
+            'delete_invoice_note_nonce' => wp_create_nonce('delete-invoice-note'),
166
+            'invoice_item_nonce'        => wp_create_nonce('invoice-item'),
167
+            'billing_details_nonce'     => wp_create_nonce('get-billing-details'),
168 168
             'tax'                       => wpinv_tax_amount(),
169 169
             'discount'                  => 0,
170 170
 			'currency_symbol'           => wpinv_currency_symbol(),
@@ -173,39 +173,39 @@  discard block
 block discarded – undo
173 173
             'thousand_sep'              => wpinv_thousands_separator(),
174 174
             'decimal_sep'               => wpinv_decimal_separator(),
175 175
             'decimals'                  => wpinv_decimals(),
176
-            'save_invoice'              => __( 'Save Invoice', 'invoicing' ),
177
-            'status_publish'            => wpinv_status_nicename( 'publish' ),
178
-            'status_pending'            => wpinv_status_nicename( 'wpi-pending' ),
179
-            'delete_tax_rate'           => __( 'Are you sure you wish to delete this tax rate?', 'invoicing' ),
180
-            'status_pending'            => wpinv_status_nicename( 'wpi-pending' ),
181
-            'FillBillingDetails'        => __( 'Fill the user\'s billing information? This will remove any currently entered billing information', 'invoicing' ),
182
-            'confirmCalcTotals'         => __( 'Recalculate totals? This will recalculate totals based on the user billing country. If no billing country is set it will use the base country.', 'invoicing' ),
183
-            'AreYouSure'                => __( 'Are you sure?', 'invoicing' ),
184
-            'errDeleteItem'             => __( 'This item is in use! Before delete this item, you need to delete all the invoice(s) using this item.', 'invoicing' ),
185
-            'delete_subscription'       => __( 'Are you sure you want to delete this subscription?', 'invoicing' ),
186
-            'action_edit'               => __( 'Edit', 'invoicing' ),
187
-            'action_cancel'             => __( 'Cancel', 'invoicing' ),
188
-            'item_description'          => __( 'Item Description', 'invoicing' ),
189
-            'invoice_description'       => __( 'Invoice Description', 'invoicing' ),
190
-            'discount_description'      => __( 'Discount Description', 'invoicing' ),
191
-			'searching'                 => __( 'Searching', 'invoicing' ),
192
-			'loading'                   => __( 'Loading...', 'invoicing' ),
193
-			'search_customers'          => __( 'Enter customer name or email', 'invoicing' ),
194
-			'search_items'              => __( 'Enter item name', 'invoicing' ),
195
-			'graphs'                    => array_merge( array( 'refunded_fees', 'refunded_items', 'refunded_subtotal', 'refunded_tax' ), array_keys( wpinv_get_report_graphs() ) ),
176
+            'save_invoice'              => __('Save Invoice', 'invoicing'),
177
+            'status_publish'            => wpinv_status_nicename('publish'),
178
+            'status_pending'            => wpinv_status_nicename('wpi-pending'),
179
+            'delete_tax_rate'           => __('Are you sure you wish to delete this tax rate?', 'invoicing'),
180
+            'status_pending'            => wpinv_status_nicename('wpi-pending'),
181
+            'FillBillingDetails'        => __('Fill the user\'s billing information? This will remove any currently entered billing information', 'invoicing'),
182
+            'confirmCalcTotals'         => __('Recalculate totals? This will recalculate totals based on the user billing country. If no billing country is set it will use the base country.', 'invoicing'),
183
+            'AreYouSure'                => __('Are you sure?', 'invoicing'),
184
+            'errDeleteItem'             => __('This item is in use! Before delete this item, you need to delete all the invoice(s) using this item.', 'invoicing'),
185
+            'delete_subscription'       => __('Are you sure you want to delete this subscription?', 'invoicing'),
186
+            'action_edit'               => __('Edit', 'invoicing'),
187
+            'action_cancel'             => __('Cancel', 'invoicing'),
188
+            'item_description'          => __('Item Description', 'invoicing'),
189
+            'invoice_description'       => __('Invoice Description', 'invoicing'),
190
+            'discount_description'      => __('Discount Description', 'invoicing'),
191
+			'searching'                 => __('Searching', 'invoicing'),
192
+			'loading'                   => __('Loading...', 'invoicing'),
193
+			'search_customers'          => __('Enter customer name or email', 'invoicing'),
194
+			'search_items'              => __('Enter item name', 'invoicing'),
195
+			'graphs'                    => array_merge(array('refunded_fees', 'refunded_items', 'refunded_subtotal', 'refunded_tax'), array_keys(wpinv_get_report_graphs())),
196 196
         );
197 197
 
198
-		if ( ! empty( $post ) && getpaid_is_invoice_post_type( $post->post_type ) ) {
198
+		if (!empty($post) && getpaid_is_invoice_post_type($post->post_type)) {
199 199
 
200
-			$invoice              = new WPInv_Invoice( $post );
200
+			$invoice              = new WPInv_Invoice($post);
201 201
 			$i18n['save_invoice'] = sprintf(
202
-				__( 'Save %s', 'invoicing' ),
203
-				ucfirst( $invoice->get_invoice_quote_type() )
202
+				__('Save %s', 'invoicing'),
203
+				ucfirst($invoice->get_invoice_quote_type())
204 204
 			);
205 205
 
206 206
 			$i18n['invoice_description'] = sprintf(
207
-				__( '%s Description', 'invoicing' ),
208
-				ucfirst( $invoice->get_invoice_quote_type() )
207
+				__('%s Description', 'invoicing'),
208
+				ucfirst($invoice->get_invoice_quote_type())
209 209
 			);
210 210
 
211 211
 		}
@@ -219,24 +219,24 @@  discard block
 block discarded – undo
219 219
 	 * @param  string $footer_text
220 220
 	 * @return string
221 221
 	 */
222
-	public function admin_footer_text( $footer_text ) {
222
+	public function admin_footer_text($footer_text) {
223 223
 		global $current_screen;
224 224
 
225
-		$page    = isset( $_GET['page'] ) ? sanitize_text_field( $_GET['page'] ) : '';
225
+		$page = isset($_GET['page']) ? sanitize_text_field($_GET['page']) : '';
226 226
 
227
-        if ( ! empty( $current_screen->post_type ) ) {
227
+        if (!empty($current_screen->post_type)) {
228 228
 			$page = $current_screen->post_type;
229 229
         }
230 230
 
231 231
         // General styles.
232
-        if ( apply_filters( 'getpaid_display_admin_footer_text', wpinv_current_user_can_manage_invoicing() ) && false !== stripos( $page, 'wpi' ) ) {
232
+        if (apply_filters('getpaid_display_admin_footer_text', wpinv_current_user_can_manage_invoicing()) && false !== stripos($page, 'wpi')) {
233 233
 
234 234
 			// Change the footer text
235
-			if ( ! get_user_meta( get_current_user_id(), 'getpaid_admin_footer_text_rated', true ) ) {
235
+			if (!get_user_meta(get_current_user_id(), 'getpaid_admin_footer_text_rated', true)) {
236 236
 
237
-				$rating_url  = esc_url(
237
+				$rating_url = esc_url(
238 238
 					wp_nonce_url(
239
-						admin_url( 'admin.php?page=wpinv-reports&getpaid-admin-action=rate_plugin' ),
239
+						admin_url('admin.php?page=wpinv-reports&getpaid-admin-action=rate_plugin'),
240 240
 						'getpaid-nonce',
241 241
 						'getpaid-nonce'
242 242
                     )
@@ -244,7 +244,7 @@  discard block
 block discarded – undo
244 244
 
245 245
 				$footer_text = sprintf(
246 246
 					/* translators: %s: five stars */
247
-					__( 'If you like <strong>GetPaid</strong>, please leave us a %s rating. A huge thanks in advance!', 'invoicing' ),
247
+					__('If you like <strong>GetPaid</strong>, please leave us a %s rating. A huge thanks in advance!', 'invoicing'),
248 248
 					"<a href='$rating_url'>&#9733;&#9733;&#9733;&#9733;&#9733;</a>"
249 249
 				);
250 250
 
@@ -252,7 +252,7 @@  discard block
 block discarded – undo
252 252
 
253 253
 				$footer_text = sprintf(
254 254
 					/* translators: %s: GetPaid */
255
-					__( 'Thank you for using %s!', 'invoicing' ),
255
+					__('Thank you for using %s!', 'invoicing'),
256 256
 					"<a href='https://wpgetpaid.com/' target='_blank'><strong>GetPaid</strong></a>"
257 257
 				);
258 258
 
@@ -268,8 +268,8 @@  discard block
 block discarded – undo
268 268
 	 * @since  2.0.0
269 269
 	 */
270 270
 	public function redirect_to_wordpress_rating_page() {
271
-		update_user_meta( get_current_user_id(), 'getpaid_admin_footer_text_rated', 1 );
272
-		wp_redirect( 'https://wordpress.org/support/plugin/invoicing/reviews?rate=5#new-post' );
271
+		update_user_meta(get_current_user_id(), 'getpaid_admin_footer_text_rated', 1);
272
+		wp_redirect('https://wordpress.org/support/plugin/invoicing/reviews?rate=5#new-post');
273 273
 		exit;
274 274
 	}
275 275
 
@@ -280,30 +280,30 @@  discard block
 block discarded – undo
280 280
 	protected function load_payment_form_scripts() {
281 281
         global $post;
282 282
 
283
-        wp_enqueue_script( 'vue', WPINV_PLUGIN_URL . 'assets/js/vue/vue.min.js', array(), WPINV_VERSION );
284
-		wp_enqueue_script( 'sortable', WPINV_PLUGIN_URL . 'assets/js/sortable.min.js', array(), WPINV_VERSION );
285
-		wp_enqueue_script( 'vue_draggable', WPINV_PLUGIN_URL . 'assets/js/vue/vuedraggable.min.js', array( 'sortable', 'vue' ), WPINV_VERSION );
283
+        wp_enqueue_script('vue', WPINV_PLUGIN_URL . 'assets/js/vue/vue.min.js', array(), WPINV_VERSION);
284
+		wp_enqueue_script('sortable', WPINV_PLUGIN_URL . 'assets/js/sortable.min.js', array(), WPINV_VERSION);
285
+		wp_enqueue_script('vue_draggable', WPINV_PLUGIN_URL . 'assets/js/vue/vuedraggable.min.js', array('sortable', 'vue'), WPINV_VERSION);
286 286
 
287
-		$version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/admin-payment-forms.js' );
288
-		wp_register_script( 'wpinv-admin-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/admin-payment-forms.js', array( 'wpinv-admin-script', 'vue_draggable', 'wp-hooks' ), $version );
287
+		$version = filemtime(WPINV_PLUGIN_DIR . 'assets/js/admin-payment-forms.js');
288
+		wp_register_script('wpinv-admin-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/admin-payment-forms.js', array('wpinv-admin-script', 'vue_draggable', 'wp-hooks'), $version);
289 289
 
290 290
 		wp_localize_script(
291 291
             'wpinv-admin-payment-form-script',
292 292
             'wpinvPaymentFormAdmin',
293 293
             array(
294
-				'elements'      => wpinv_get_data( 'payment-form-elements' ),
295
-				'form_elements' => getpaid_get_payment_form_elements( $post->ID ),
294
+				'elements'      => wpinv_get_data('payment-form-elements'),
295
+				'form_elements' => getpaid_get_payment_form_elements($post->ID),
296 296
 				'currency'      => wpinv_currency_symbol(),
297 297
 				'position'      => wpinv_currency_position(),
298 298
 				'decimals'      => (int) wpinv_decimals(),
299 299
 				'thousands_sep' => wpinv_thousands_separator(),
300 300
 				'decimals_sep'  => wpinv_decimal_separator(),
301
-				'form_items'    => gepaid_get_form_items( $post->ID ),
301
+				'form_items'    => gepaid_get_form_items($post->ID),
302 302
 				'is_default'    => $post->ID == wpinv_get_default_payment_form(),
303 303
             )
304 304
         );
305 305
 
306
-        wp_enqueue_script( 'wpinv-admin-payment-form-script' );
306
+        wp_enqueue_script('wpinv-admin-payment-form-script');
307 307
 
308 308
     }
309 309
 
@@ -314,24 +314,24 @@  discard block
 block discarded – undo
314 314
      * @return string
315 315
 	 *
316 316
 	 */
317
-    public function admin_body_class( $classes ) {
317
+    public function admin_body_class($classes) {
318 318
 		global $pagenow, $post, $current_screen;
319 319
 
320
-        $page = isset( $_GET['page'] ) ? sanitize_text_field( $_GET['page'] ) : '';
320
+        $page = isset($_GET['page']) ? sanitize_text_field($_GET['page']) : '';
321 321
 
322
-        if ( ! empty( $current_screen->post_type ) ) {
322
+        if (!empty($current_screen->post_type)) {
323 323
 			$page = $current_screen->post_type;
324 324
         }
325 325
 
326
-        if ( false !== stripos( $page, 'wpi' ) ) {
327
-            $classes .= ' wpi-' . sanitize_key( $page );
326
+        if (false !== stripos($page, 'wpi')) {
327
+            $classes .= ' wpi-' . sanitize_key($page);
328 328
         }
329 329
 
330
-        if ( in_array( $page, wpinv_parse_list( 'wpi_invoice wpi_payment_form wpi_quote' ) ) ) {
330
+        if (in_array($page, wpinv_parse_list('wpi_invoice wpi_payment_form wpi_quote'))) {
331 331
             $classes .= ' wpinv-cpt wpinv';
332 332
 		}
333 333
 
334
-		if ( getpaid_is_invoice_post_type( $page ) ) {
334
+		if (getpaid_is_invoice_post_type($page)) {
335 335
             $classes .= ' getpaid-is-invoice-cpt';
336 336
         }
337 337
 
@@ -350,21 +350,21 @@  discard block
 block discarded – undo
350 350
 				'version'           => WPINV_VERSION,
351 351
 				'support_url'       => 'https://wpgetpaid.com/support/',
352 352
 				'documentation_url' => 'https://docs.wpgetpaid.com/',
353
-				'activated'         => (int) get_option( 'gepaid_installed_on' ),
353
+				'activated'         => (int) get_option('gepaid_installed_on'),
354 354
             )
355 355
         );
356 356
 
357 357
         new AyeCode_Connect_Helper(
358 358
             array(
359
-				'connect_title'     => __( 'WP Invoicing - an AyeCode product!', 'invoicing' ),
360
-				'connect_external'  => __( 'Please confirm you wish to connect your site?', 'invoicing' ),
361
-				'connect'           => sprintf( __( '<strong>Have a license?</strong> Forget about entering license keys or downloading zip files, connect your site for instant access. %1$slearn more%2$s', 'invoicing' ), "<a href='https://ayecode.io/introducing-ayecode-connect/' target='_blank'>", '</a>' ),
362
-				'connect_button'    => __( 'Connect Site', 'invoicing' ),
363
-				'connecting_button' => __( 'Connecting...', 'invoicing' ),
364
-				'error_localhost'   => __( 'This service will only work with a live domain, not a localhost.', 'invoicing' ),
365
-				'error'             => __( 'Something went wrong, please refresh and try again.', 'invoicing' ),
359
+				'connect_title'     => __('WP Invoicing - an AyeCode product!', 'invoicing'),
360
+				'connect_external'  => __('Please confirm you wish to connect your site?', 'invoicing'),
361
+				'connect'           => sprintf(__('<strong>Have a license?</strong> Forget about entering license keys or downloading zip files, connect your site for instant access. %1$slearn more%2$s', 'invoicing'), "<a href='https://ayecode.io/introducing-ayecode-connect/' target='_blank'>", '</a>'),
362
+				'connect_button'    => __('Connect Site', 'invoicing'),
363
+				'connecting_button' => __('Connecting...', 'invoicing'),
364
+				'error_localhost'   => __('This service will only work with a live domain, not a localhost.', 'invoicing'),
365
+				'error'             => __('Something went wrong, please refresh and try again.', 'invoicing'),
366 366
             ),
367
-            array( 'wpi-addons' )
367
+            array('wpi-addons')
368 368
         );
369 369
 
370 370
     }
@@ -376,20 +376,20 @@  discard block
 block discarded – undo
376 376
 	 */
377 377
 	public function activation_redirect() {
378 378
 
379
-		$redirected = get_option( 'wpinv_redirected_to_settings' );
379
+		$redirected = get_option('wpinv_redirected_to_settings');
380 380
 
381
-		if ( ! empty( $redirected ) || wp_doing_ajax() || ! current_user_can( 'manage_options' ) ) {
381
+		if (!empty($redirected) || wp_doing_ajax() || !current_user_can('manage_options')) {
382 382
 			return;
383 383
 		}
384 384
 
385 385
 		// Bail if activating from network, or bulk
386
-		if ( is_network_admin() || isset( $_GET['activate-multi'] ) ) {
386
+		if (is_network_admin() || isset($_GET['activate-multi'])) {
387 387
 			return;
388 388
 		}
389 389
 
390
-	    update_option( 'wpinv_redirected_to_settings', 1 );
390
+	    update_option('wpinv_redirected_to_settings', 1);
391 391
 
392
-        wp_safe_redirect( admin_url( 'index.php?page=gp-setup' ) );
392
+        wp_safe_redirect(admin_url('index.php?page=gp-setup'));
393 393
         exit;
394 394
 
395 395
 	}
@@ -398,10 +398,10 @@  discard block
 block discarded – undo
398 398
      * Fires an admin action after verifying that a user can fire them.
399 399
      */
400 400
     public function maybe_do_admin_action() {
401
-        if ( isset( $_REQUEST['getpaid-admin-action'] ) && isset( $_REQUEST['getpaid-nonce'] ) && wp_verify_nonce( $_REQUEST['getpaid-nonce'], 'getpaid-nonce' ) && wpinv_current_user_can( sanitize_text_field( $_REQUEST['getpaid-admin-action'] ), $_REQUEST ) ) {
402
-            $key = sanitize_key( $_REQUEST['getpaid-admin-action'] );
401
+        if (isset($_REQUEST['getpaid-admin-action']) && isset($_REQUEST['getpaid-nonce']) && wp_verify_nonce($_REQUEST['getpaid-nonce'], 'getpaid-nonce') && wpinv_current_user_can(sanitize_text_field($_REQUEST['getpaid-admin-action']), $_REQUEST)) {
402
+            $key = sanitize_key($_REQUEST['getpaid-admin-action']);
403 403
 
404
-            do_action( "getpaid_authenticated_admin_action_$key", $_REQUEST );
404
+            do_action("getpaid_authenticated_admin_action_$key", $_REQUEST);
405 405
         }
406 406
     }
407 407
 
@@ -410,24 +410,24 @@  discard block
 block discarded – undo
410 410
 	 *
411 411
 	 * @param array $args
412 412
      */
413
-    public function duplicate_invoice( $args ) {
413
+    public function duplicate_invoice($args) {
414 414
 
415
-		if ( empty( $args['invoice_id'] ) ) {
415
+		if (empty($args['invoice_id'])) {
416 416
 			return;
417 417
 		}
418 418
 
419
-		$invoice = new WPInv_Invoice( (int) $args['invoice_id'] );
419
+		$invoice = new WPInv_Invoice((int) $args['invoice_id']);
420 420
 
421
-		if ( ! $invoice->exists() ) {
421
+		if (!$invoice->exists()) {
422 422
 			return;
423 423
 		}
424 424
 
425
-		$new_invoice = getpaid_duplicate_invoice( $invoice );
425
+		$new_invoice = getpaid_duplicate_invoice($invoice);
426 426
 		$new_invoice->save();
427 427
 
428
-		if ( $new_invoice->exists() ) {
428
+		if ($new_invoice->exists()) {
429 429
 
430
-			getpaid_admin()->show_success( __( 'Invoice duplicated successfully.', 'invoicing' ) );
430
+			getpaid_admin()->show_success(__('Invoice duplicated successfully.', 'invoicing'));
431 431
 
432 432
 			wp_safe_redirect(
433 433
 				add_query_arg(
@@ -435,14 +435,14 @@  discard block
 block discarded – undo
435 435
 						'action' => 'edit',
436 436
 						'post'   => $new_invoice->get_id(),
437 437
 					),
438
-					admin_url( 'post.php' )
438
+					admin_url('post.php')
439 439
 				)
440 440
 			);
441 441
 			exit;
442 442
 
443 443
 		}
444 444
 
445
-		getpaid_admin()->show_error( __( 'There was an error duplicating this invoice. Please try again.', 'invoicing' ) );
445
+		getpaid_admin()->show_error(__('There was an error duplicating this invoice. Please try again.', 'invoicing'));
446 446
 
447 447
 	}
448 448
 
@@ -451,40 +451,40 @@  discard block
 block discarded – undo
451 451
 	 *
452 452
 	 * @param array $args
453 453
      */
454
-    public function refund_invoice( $args ) {
454
+    public function refund_invoice($args) {
455 455
 
456
-		if ( empty( $args['invoice_id'] ) ) {
456
+		if (empty($args['invoice_id'])) {
457 457
 			return;
458 458
 		}
459 459
 
460
-		$invoice = new WPInv_Invoice( (int) $args['invoice_id'] );
460
+		$invoice = new WPInv_Invoice((int) $args['invoice_id']);
461 461
 
462
-		if ( ! $invoice->exists() || $invoice->is_refunded() ) {
462
+		if (!$invoice->exists() || $invoice->is_refunded()) {
463 463
 			return;
464 464
 		}
465 465
 
466 466
 		$invoice->refund();
467 467
 
468 468
 		// Refund remotely.
469
-		if ( getpaid_payment_gateway_supports( $invoice->get_gateway(), 'refunds' ) && ! empty( $args['getpaid_refund_remote'] ) ) {
470
-			do_action( 'getpaid_refund_invoice_remotely', $invoice );
469
+		if (getpaid_payment_gateway_supports($invoice->get_gateway(), 'refunds') && !empty($args['getpaid_refund_remote'])) {
470
+			do_action('getpaid_refund_invoice_remotely', $invoice);
471 471
 		}
472 472
 
473 473
 		// Cancel subscriptions.
474
-		if ( ! empty( $args['getpaid_cancel_subscription'] ) ) {
475
-			$subscriptions = getpaid_get_invoice_subscriptions( $invoice );
474
+		if (!empty($args['getpaid_cancel_subscription'])) {
475
+			$subscriptions = getpaid_get_invoice_subscriptions($invoice);
476 476
 
477
-			if ( ! empty( $subscriptions ) ) {
478
-				if ( ! is_array( $subscriptions ) ) {
479
-					$subscriptions = array( $subscriptions );
477
+			if (!empty($subscriptions)) {
478
+				if (!is_array($subscriptions)) {
479
+					$subscriptions = array($subscriptions);
480 480
 				}
481 481
 
482
-				foreach ( $subscriptions as $subscription ) {
482
+				foreach ($subscriptions as $subscription) {
483 483
 					$subscription->cancel();
484 484
 					$invoice->add_system_note(
485 485
 						sprintf(
486 486
 							// translators: %s: subscription ID.
487
-							__( 'Subscription #%s cancelled', 'invoicing' ),
487
+							__('Subscription #%s cancelled', 'invoicing'),
488 488
 							$subscription->get_id()
489 489
 						)
490 490
 					);
@@ -493,11 +493,11 @@  discard block
 block discarded – undo
493 493
 		}
494 494
 
495 495
 		// Add notice.
496
-		$this->show_success( __( 'Invoice refunded successfully.', 'invoicing' ) );
496
+		$this->show_success(__('Invoice refunded successfully.', 'invoicing'));
497 497
 
498 498
 		// Redirect.
499 499
 		wp_safe_redirect(
500
-			remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id', 'getpaid_cancel_subscription', 'getpaid_refund_remote' ) )
500
+			remove_query_arg(array('getpaid-admin-action', 'getpaid-nonce', 'invoice_id', 'getpaid_cancel_subscription', 'getpaid_refund_remote'))
501 501
 		);
502 502
 	}
503 503
 
@@ -506,34 +506,34 @@  discard block
 block discarded – undo
506 506
 	 *
507 507
 	 * @param array $args
508 508
      */
509
-    public function duplicate_payment_form( $args ) {
509
+    public function duplicate_payment_form($args) {
510 510
 
511
-		if ( empty( $args['form_id'] ) ) {
511
+		if (empty($args['form_id'])) {
512 512
 			return;
513 513
 		}
514 514
 
515
-		$form = new GetPaid_Payment_Form( (int) $args['form_id'] );
515
+		$form = new GetPaid_Payment_Form((int) $args['form_id']);
516 516
 
517
-		if ( ! $form->exists() ) {
517
+		if (!$form->exists()) {
518 518
 			return;
519 519
 		}
520 520
 
521 521
 		$new_form = new GetPaid_Payment_Form();
522
-		$new_form->set_author( $form->get_author( 'edit' ) );
523
-		$new_form->set_name( $form->get_name( 'edit' ) . __( '(copy)', 'invoicing' ) );
524
-		$new_form->set_elements( $form->get_elements( 'edit' ) );
525
-		$new_form->set_items( $form->get_items( 'edit' ) );
522
+		$new_form->set_author($form->get_author('edit'));
523
+		$new_form->set_name($form->get_name('edit') . __('(copy)', 'invoicing'));
524
+		$new_form->set_elements($form->get_elements('edit'));
525
+		$new_form->set_items($form->get_items('edit'));
526 526
 		$new_form->save();
527 527
 
528
-		if ( $new_form->exists() ) {
529
-			$this->show_success( __( 'Form duplicated successfully', 'invoicing' ) );
530
-			$url = get_edit_post_link( $new_form->get_id(), 'edit' );
528
+		if ($new_form->exists()) {
529
+			$this->show_success(__('Form duplicated successfully', 'invoicing'));
530
+			$url = get_edit_post_link($new_form->get_id(), 'edit');
531 531
 		} else {
532
-			$this->show_error( __( 'Unable to duplicate form', 'invoicing' ) );
533
-			$url = remove_query_arg( array( 'getpaid-admin-action', 'form_id', 'getpaid-nonce' ) );
532
+			$this->show_error(__('Unable to duplicate form', 'invoicing'));
533
+			$url = remove_query_arg(array('getpaid-admin-action', 'form_id', 'getpaid-nonce'));
534 534
 		}
535 535
 
536
-		wp_redirect( $url );
536
+		wp_redirect($url);
537 537
 		exit;
538 538
 	}
539 539
 
@@ -542,27 +542,27 @@  discard block
 block discarded – undo
542 542
 	 *
543 543
 	 * @param array $args
544 544
      */
545
-    public function reset_form_stats( $args ) {
545
+    public function reset_form_stats($args) {
546 546
 
547
-		if ( empty( $args['form_id'] ) ) {
547
+		if (empty($args['form_id'])) {
548 548
 			return;
549 549
 		}
550 550
 
551
-		$form = new GetPaid_Payment_Form( (int) $args['form_id'] );
551
+		$form = new GetPaid_Payment_Form((int) $args['form_id']);
552 552
 
553
-		if ( ! $form->exists() ) {
553
+		if (!$form->exists()) {
554 554
 			return;
555 555
 		}
556 556
 
557
-		$form->set_earned( 0 );
558
-		$form->set_refunded( 0 );
559
-		$form->set_cancelled( 0 );
560
-		$form->set_failed( 0 );
557
+		$form->set_earned(0);
558
+		$form->set_refunded(0);
559
+		$form->set_cancelled(0);
560
+		$form->set_failed(0);
561 561
 		$form->save();
562 562
 
563
-		$this->show_success( __( 'Form stats reset successfully', 'invoicing' ) );
563
+		$this->show_success(__('Form stats reset successfully', 'invoicing'));
564 564
 
565
-		wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'form_id', 'getpaid-nonce' ) ) );
565
+		wp_safe_redirect(remove_query_arg(array('getpaid-admin-action', 'form_id', 'getpaid-nonce')));
566 566
 		exit;
567 567
 	}
568 568
 
@@ -571,9 +571,9 @@  discard block
 block discarded – undo
571 571
 	 *
572 572
 	 * @param array $args
573 573
      */
574
-    public function send_customer_invoice( $args ) {
575
-		getpaid()->get( 'invoice_emails' )->user_invoice( new WPInv_Invoice( $args['invoice_id'] ), true );
576
-		wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) );
574
+    public function send_customer_invoice($args) {
575
+		getpaid()->get('invoice_emails')->user_invoice(new WPInv_Invoice($args['invoice_id']), true);
576
+		wp_safe_redirect(remove_query_arg(array('getpaid-admin-action', 'getpaid-nonce', 'invoice_id')));
577 577
 		exit;
578 578
 	}
579 579
 
@@ -582,16 +582,16 @@  discard block
 block discarded – undo
582 582
 	 *
583 583
 	 * @param array $args
584 584
      */
585
-    public function send_customer_payment_reminder( $args ) {
586
-		$sent = getpaid()->get( 'invoice_emails' )->force_send_overdue_notice( new WPInv_Invoice( $args['invoice_id'] ) );
585
+    public function send_customer_payment_reminder($args) {
586
+		$sent = getpaid()->get('invoice_emails')->force_send_overdue_notice(new WPInv_Invoice($args['invoice_id']));
587 587
 
588
-		if ( $sent ) {
589
-			$this->show_success( __( 'Payment reminder was successfully sent to the customer', 'invoicing' ) );
588
+		if ($sent) {
589
+			$this->show_success(__('Payment reminder was successfully sent to the customer', 'invoicing'));
590 590
 		} else {
591
-			$this->show_error( __( 'Could not sent payment reminder to the customer', 'invoicing' ) );
591
+			$this->show_error(__('Could not sent payment reminder to the customer', 'invoicing'));
592 592
 		}
593 593
 
594
-		wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) );
594
+		wp_safe_redirect(remove_query_arg(array('getpaid-admin-action', 'getpaid-nonce', 'invoice_id')));
595 595
 		exit;
596 596
 	}
597 597
 
@@ -601,8 +601,8 @@  discard block
 block discarded – undo
601 601
      */
602 602
     public function admin_reset_tax_rates() {
603 603
 
604
-		update_option( 'wpinv_tax_rates', wpinv_get_data( 'tax-rates' ) );
605
-		wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) );
604
+		update_option('wpinv_tax_rates', wpinv_get_data('tax-rates'));
605
+		wp_safe_redirect(remove_query_arg(array('getpaid-admin-action', 'getpaid-nonce')));
606 606
 		exit;
607 607
 
608 608
 	}
@@ -614,8 +614,8 @@  discard block
 block discarded – undo
614 614
     public function admin_create_missing_pages() {
615 615
 		$installer = new GetPaid_Installer();
616 616
 		$installer->create_pages();
617
-		$this->show_success( __( 'GetPaid pages updated.', 'invoicing' ) );
618
-		wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) );
617
+		$this->show_success(__('GetPaid pages updated.', 'invoicing'));
618
+		wp_safe_redirect(remove_query_arg(array('getpaid-admin-action', 'getpaid-nonce')));
619 619
 		exit;
620 620
 	}
621 621
 
@@ -624,8 +624,8 @@  discard block
 block discarded – undo
624 624
 	 */
625 625
 	public function admin_refresh_permalinks() {
626 626
 		flush_rewrite_rules();
627
-		$this->show_success( __( 'Permalinks refreshed.', 'invoicing' ) );
628
-		wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) );
627
+		$this->show_success(__('Permalinks refreshed.', 'invoicing'));
628
+		wp_safe_redirect(remove_query_arg(array('getpaid-admin-action', 'getpaid-nonce')));
629 629
 		exit;
630 630
 	}
631 631
 
@@ -639,13 +639,13 @@  discard block
 block discarded – undo
639 639
 		GetPaid_Installer::create_db_tables();
640 640
 		GetPaid_Installer::migrate_old_customers();
641 641
 
642
-		if ( '' !== $wpdb->last_error ) {
643
-			$this->show_error( __( 'Your GetPaid tables have been updated:', 'invoicing' ) . ' ' . $wpdb->last_error );
642
+		if ('' !== $wpdb->last_error) {
643
+			$this->show_error(__('Your GetPaid tables have been updated:', 'invoicing') . ' ' . $wpdb->last_error);
644 644
 		} else {
645
-			$this->show_success( __( 'Your GetPaid tables have been updated.', 'invoicing' ) );
645
+			$this->show_success(__('Your GetPaid tables have been updated.', 'invoicing'));
646 646
 		}
647 647
 
648
-		wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) );
648
+		wp_safe_redirect(remove_query_arg(array('getpaid-admin-action', 'getpaid-nonce')));
649 649
 		exit;
650 650
 	}
651 651
 
@@ -660,10 +660,10 @@  discard block
 block discarded – undo
660 660
 		$installer->migrate_old_invoices();
661 661
 
662 662
 		// Show an admin message.
663
-		$this->show_success( __( 'Your invoices have been migrated.', 'invoicing' ) );
663
+		$this->show_success(__('Your invoices have been migrated.', 'invoicing'));
664 664
 
665 665
 		// Redirect the admin.
666
-		wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) );
666
+		wp_safe_redirect(remove_query_arg(array('getpaid-admin-action', 'getpaid-nonce')));
667 667
 		exit;
668 668
 
669 669
 	}
@@ -674,35 +674,35 @@  discard block
 block discarded – undo
674 674
      */
675 675
     public function admin_download_customers() {
676 676
 
677
-		$output = fopen( 'php://output', 'w' );
677
+		$output = fopen('php://output', 'w');
678 678
 
679
-		if ( false === $output ) {
680
-			wp_die( esc_html__( 'Unsupported server', 'invoicing' ), 500 );
679
+		if (false === $output) {
680
+			wp_die(esc_html__('Unsupported server', 'invoicing'), 500);
681 681
 		}
682 682
 
683
-		header( 'Content-Type:text/csv' );
684
-		header( 'Content-Disposition:attachment;filename=customers.csv' );
683
+		header('Content-Type:text/csv');
684
+		header('Content-Disposition:attachment;filename=customers.csv');
685 685
 
686 686
 		/** @var GetPaid_Customer[] $customers */
687
-		$customers = getpaid_get_customers( array( 'number' => -1 ) );
688
-		$columns   = array_keys( GetPaid_Customer_Data_Store::get_database_fields() );
687
+		$customers = getpaid_get_customers(array('number' => -1));
688
+		$columns   = array_keys(GetPaid_Customer_Data_Store::get_database_fields());
689 689
 
690 690
 		// Output the csv column headers.
691
-		fputcsv( $output, $columns );
691
+		fputcsv($output, $columns);
692 692
 
693 693
 		// Loop through
694
-		foreach ( $customers as $customer ) {
694
+		foreach ($customers as $customer) {
695 695
 
696
-			$row  = array();
696
+			$row = array();
697 697
 
698
-			foreach ( $columns as $column ) {
699
-				$row[]  = (string) maybe_serialize( $customer->get( $column, 'edit' ) );
698
+			foreach ($columns as $column) {
699
+				$row[] = (string) maybe_serialize($customer->get($column, 'edit'));
700 700
 			}
701 701
 
702
-			fputcsv( $output, $row );
702
+			fputcsv($output, $row);
703 703
 		}
704 704
 
705
-		fclose( $output );
705
+		fclose($output);
706 706
 		exit;
707 707
 
708 708
 	}
@@ -712,27 +712,27 @@  discard block
 block discarded – undo
712 712
 	 *
713 713
 	 * @param array $data
714 714
      */
715
-    public function admin_install_plugin( $data ) {
715
+    public function admin_install_plugin($data) {
716 716
 
717
-		if ( ! empty( $data['plugins'] ) ) {
717
+		if (!empty($data['plugins'])) {
718 718
 			include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
719 719
 			wp_cache_flush();
720 720
 
721
-			foreach ( $data['plugins'] as $slug => $file ) {
722
-				$plugin_zip = esc_url( 'https://downloads.wordpress.org/plugin/' . $slug . '.latest-stable.zip' );
723
-				$upgrader   = new Plugin_Upgrader( new Automatic_Upgrader_Skin() );
724
-				$installed  = $upgrader->install( $plugin_zip );
721
+			foreach ($data['plugins'] as $slug => $file) {
722
+				$plugin_zip = esc_url('https://downloads.wordpress.org/plugin/' . $slug . '.latest-stable.zip');
723
+				$upgrader   = new Plugin_Upgrader(new Automatic_Upgrader_Skin());
724
+				$installed  = $upgrader->install($plugin_zip);
725 725
 
726
-				if ( ! is_wp_error( $installed ) && $installed ) {
727
-					activate_plugin( $file, '', false, true );
726
+				if (!is_wp_error($installed) && $installed) {
727
+					activate_plugin($file, '', false, true);
728 728
 				} else {
729
-					wpinv_error_log( $upgrader->skin->get_upgrade_messages(), false );
729
+					wpinv_error_log($upgrader->skin->get_upgrade_messages(), false);
730 730
 				}
731 731
 }
732 732
 }
733 733
 
734
-		$redirect = isset( $data['redirect'] ) ? esc_url_raw( $data['redirect'] ) : admin_url( 'plugins.php' );
735
-		wp_safe_redirect( $redirect );
734
+		$redirect = isset($data['redirect']) ? esc_url_raw($data['redirect']) : admin_url('plugins.php');
735
+		wp_safe_redirect($redirect);
736 736
 		exit;
737 737
 
738 738
 	}
@@ -742,41 +742,41 @@  discard block
 block discarded – undo
742 742
 	 *
743 743
 	 * @param array $data
744 744
      */
745
-    public function admin_connect_gateway( $data ) {
745
+    public function admin_connect_gateway($data) {
746 746
 
747
-		if ( ! empty( $data['plugin'] ) ) {
747
+		if (!empty($data['plugin'])) {
748 748
 
749
-			$gateway     = sanitize_key( $data['plugin'] );
750
-			$connect_url = apply_filters( "getpaid_get_{$gateway}_connect_url", false, $data );
749
+			$gateway     = sanitize_key($data['plugin']);
750
+			$connect_url = apply_filters("getpaid_get_{$gateway}_connect_url", false, $data);
751 751
 
752
-			if ( ! empty( $connect_url ) ) {
753
-				wp_redirect( $connect_url );
752
+			if (!empty($connect_url)) {
753
+				wp_redirect($connect_url);
754 754
 				exit;
755 755
 			}
756 756
 
757
-			if ( 'stripe' == $data['plugin'] ) {
757
+			if ('stripe' == $data['plugin']) {
758 758
 				require_once ABSPATH . 'wp-admin/includes/plugin.php';
759 759
 				include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
760 760
 				wp_cache_flush();
761 761
 
762
-				if ( ! array_key_exists( 'getpaid-stripe-payments/getpaid-stripe-payments.php', get_plugins() ) ) {
763
-					$plugin_zip = esc_url( 'https://downloads.wordpress.org/plugin/getpaid-stripe-payments.latest-stable.zip' );
764
-					$upgrader   = new Plugin_Upgrader( new Automatic_Upgrader_Skin() );
765
-					$upgrader->install( $plugin_zip );
762
+				if (!array_key_exists('getpaid-stripe-payments/getpaid-stripe-payments.php', get_plugins())) {
763
+					$plugin_zip = esc_url('https://downloads.wordpress.org/plugin/getpaid-stripe-payments.latest-stable.zip');
764
+					$upgrader   = new Plugin_Upgrader(new Automatic_Upgrader_Skin());
765
+					$upgrader->install($plugin_zip);
766 766
 				}
767 767
 
768
-				activate_plugin( 'getpaid-stripe-payments/getpaid-stripe-payments.php', '', false, true );
768
+				activate_plugin('getpaid-stripe-payments/getpaid-stripe-payments.php', '', false, true);
769 769
 			}
770 770
 
771
-			$connect_url = apply_filters( "getpaid_get_{$gateway}_connect_url", false, $data );
772
-			if ( ! empty( $connect_url ) ) {
773
-				wp_redirect( $connect_url );
771
+			$connect_url = apply_filters("getpaid_get_{$gateway}_connect_url", false, $data);
772
+			if (!empty($connect_url)) {
773
+				wp_redirect($connect_url);
774 774
 				exit;
775 775
 			}
776 776
 }
777 777
 
778
-		$redirect = isset( $data['redirect'] ) ? esc_url_raw( urldecode( $data['redirect'] ) ) : admin_url( 'admin.php?page=wpinv-settings&tab=gateways' );
779
-		wp_safe_redirect( $redirect );
778
+		$redirect = isset($data['redirect']) ? esc_url_raw(urldecode($data['redirect'])) : admin_url('admin.php?page=wpinv-settings&tab=gateways');
779
+		wp_safe_redirect($redirect);
780 780
 		exit;
781 781
 
782 782
 	}
@@ -790,35 +790,35 @@  discard block
 block discarded – undo
790 790
 
791 791
 		// Fetch all invoices that have discount codes.
792 792
 		$table    = $wpdb->prefix . 'getpaid_invoices';
793
-		$invoices = $wpdb->get_col( "SELECT `post_id` FROM `$table` WHERE `discount` = 0 && `discount_code` <> ''" );
793
+		$invoices = $wpdb->get_col("SELECT `post_id` FROM `$table` WHERE `discount` = 0 && `discount_code` <> ''");
794 794
 
795
-		foreach ( $invoices as $invoice ) {
795
+		foreach ($invoices as $invoice) {
796 796
 
797
-			$invoice = new WPInv_Invoice( $invoice );
797
+			$invoice = new WPInv_Invoice($invoice);
798 798
 
799
-			if ( ! $invoice->exists() ) {
799
+			if (!$invoice->exists()) {
800 800
 				continue;
801 801
 			}
802 802
 
803 803
 			// Abort if the discount does not exist or does not apply here.
804
-			$discount = new WPInv_Discount( $invoice->get_discount_code() );
805
-			if ( ! $discount->exists() ) {
804
+			$discount = new WPInv_Discount($invoice->get_discount_code());
805
+			if (!$discount->exists()) {
806 806
 				continue;
807 807
 			}
808 808
 
809
-			$invoice->add_discount( getpaid_calculate_invoice_discount( $invoice, $discount ) );
809
+			$invoice->add_discount(getpaid_calculate_invoice_discount($invoice, $discount));
810 810
 			$invoice->recalculate_total();
811 811
 
812
-			if ( $invoice->get_total_discount() > 0 ) {
812
+			if ($invoice->get_total_discount() > 0) {
813 813
 				$invoice->save();
814 814
 			}
815 815
 }
816 816
 
817 817
 		// Show an admin message.
818
-		$this->show_success( __( 'Discounts have been recalculated.', 'invoicing' ) );
818
+		$this->show_success(__('Discounts have been recalculated.', 'invoicing'));
819 819
 
820 820
 		// Redirect the admin.
821
-		wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) );
821
+		wp_safe_redirect(remove_query_arg(array('getpaid-admin-action', 'getpaid-nonce')));
822 822
 		exit;
823 823
 
824 824
 	}
@@ -830,8 +830,8 @@  discard block
 block discarded – undo
830 830
      * @return array
831 831
 	 */
832 832
 	public function get_notices() {
833
-		$notices = get_option( 'wpinv_admin_notices' );
834
-        return is_array( $notices ) ? $notices : array();
833
+		$notices = get_option('wpinv_admin_notices');
834
+        return is_array($notices) ? $notices : array();
835 835
 	}
836 836
 
837 837
 	/**
@@ -841,7 +841,7 @@  discard block
 block discarded – undo
841 841
      * @return array
842 842
 	 */
843 843
 	public function has_notices() {
844
-		return count( $this->get_notices() ) > 0;
844
+		return count($this->get_notices()) > 0;
845 845
 	}
846 846
 
847 847
 	/**
@@ -851,7 +851,7 @@  discard block
 block discarded – undo
851 851
 	 * @since       1.0.19
852 852
 	 */
853 853
 	public function clear_notices() {
854
-		delete_option( 'wpinv_admin_notices' );
854
+		delete_option('wpinv_admin_notices');
855 855
 	}
856 856
 
857 857
 	/**
@@ -860,16 +860,16 @@  discard block
 block discarded – undo
860 860
 	 * @access      public
861 861
 	 * @since       1.0.19
862 862
 	 */
863
-	public function save_notice( $type, $message ) {
863
+	public function save_notice($type, $message) {
864 864
 		$notices = $this->get_notices();
865 865
 
866
-		if ( empty( $notices[ $type ] ) || ! is_array( $notices[ $type ] ) ) {
867
-			$notices[ $type ] = array();
866
+		if (empty($notices[$type]) || !is_array($notices[$type])) {
867
+			$notices[$type] = array();
868 868
 		}
869 869
 
870
-		$notices[ $type ][] = $message;
870
+		$notices[$type][] = $message;
871 871
 
872
-		update_option( 'wpinv_admin_notices', $notices );
872
+		update_option('wpinv_admin_notices', $notices);
873 873
 	}
874 874
 
875 875
 	/**
@@ -879,8 +879,8 @@  discard block
 block discarded – undo
879 879
 	 * @access      public
880 880
 	 * @since       1.0.19
881 881
 	 */
882
-	public function show_success( $msg ) {
883
-		$this->save_notice( 'success', $msg );
882
+	public function show_success($msg) {
883
+		$this->save_notice('success', $msg);
884 884
 	}
885 885
 
886 886
 	/**
@@ -890,8 +890,8 @@  discard block
 block discarded – undo
890 890
 	 * @param       string $msg The message to qeue.
891 891
 	 * @since       1.0.19
892 892
 	 */
893
-	public function show_error( $msg ) {
894
-		$this->save_notice( 'error', $msg );
893
+	public function show_error($msg) {
894
+		$this->save_notice('error', $msg);
895 895
 	}
896 896
 
897 897
 	/**
@@ -901,8 +901,8 @@  discard block
 block discarded – undo
901 901
 	 * @param       string $msg The message to qeue.
902 902
 	 * @since       1.0.19
903 903
 	 */
904
-	public function show_warning( $msg ) {
905
-		$this->save_notice( 'warning', $msg );
904
+	public function show_warning($msg) {
905
+		$this->save_notice('warning', $msg);
906 906
 	}
907 907
 
908 908
 	/**
@@ -912,8 +912,8 @@  discard block
 block discarded – undo
912 912
 	 * @param       string $msg The message to qeue.
913 913
 	 * @since       1.0.19
914 914
 	 */
915
-	public function show_info( $msg ) {
916
-		$this->save_notice( 'info', $msg );
915
+	public function show_info($msg) {
916
+		$this->save_notice('info', $msg);
917 917
 	}
918 918
 
919 919
 	/**
@@ -927,29 +927,29 @@  discard block
 block discarded – undo
927 927
         $notices = $this->get_notices();
928 928
         $this->clear_notices();
929 929
 
930
-		foreach ( $notices as $type => $messages ) {
930
+		foreach ($notices as $type => $messages) {
931 931
 
932
-			if ( ! is_array( $messages ) ) {
932
+			if (!is_array($messages)) {
933 933
 				continue;
934 934
 			}
935 935
 
936
-            $type  = esc_attr( $type );
937
-			foreach ( $messages as $message ) {
938
-				echo wp_kses_post( "<div class='notice notice-$type is-dismissible'><p>$message</p></div>" );
936
+            $type = esc_attr($type);
937
+			foreach ($messages as $message) {
938
+				echo wp_kses_post("<div class='notice notice-$type is-dismissible'><p>$message</p></div>");
939 939
             }
940 940
 }
941 941
 
942
-		foreach ( array( 'checkout_page', 'invoice_history_page', 'success_page', 'failure_page', 'invoice_subscription_page' ) as $page ) {
942
+		foreach (array('checkout_page', 'invoice_history_page', 'success_page', 'failure_page', 'invoice_subscription_page') as $page) {
943 943
 
944
-			if ( ! is_numeric( wpinv_get_option( $page, false ) ) ) {
945
-				$url     = wp_nonce_url(
946
-					add_query_arg( 'getpaid-admin-action', 'create_missing_pages' ),
944
+			if (!is_numeric(wpinv_get_option($page, false))) {
945
+				$url = wp_nonce_url(
946
+					add_query_arg('getpaid-admin-action', 'create_missing_pages'),
947 947
 					'getpaid-nonce',
948 948
 					'getpaid-nonce'
949 949
 				);
950
-				$message  = __( 'Some GetPaid pages are missing. To use GetPaid without any issues, click the button below to generate the missing pages.', 'invoicing' );
951
-				$message2 = __( 'Generate Pages', 'invoicing' );
952
-				echo wp_kses_post( "<div class='notice notice-warning is-dismissible'><p>$message<br><br><a href='$url' class='button button-primary'>$message2</a></p></div>" );
950
+				$message  = __('Some GetPaid pages are missing. To use GetPaid without any issues, click the button below to generate the missing pages.', 'invoicing');
951
+				$message2 = __('Generate Pages', 'invoicing');
952
+				echo wp_kses_post("<div class='notice notice-warning is-dismissible'><p>$message<br><br><a href='$url' class='button button-primary'>$message2</a></p></div>");
953 953
 				break;
954 954
 			}
955 955
 }
Please login to merge, or discard this patch.
includes/gateways/class-getpaid-paypal-api.php 2 patches
Indentation   +197 added lines, -197 removed lines patch added patch discarded remove patch
@@ -10,211 +10,211 @@
 block discarded – undo
10 10
  */
11 11
 class GetPaid_PayPal_API {
12 12
 
13
-	/**
14
-	 * Retrieves the bearer token.
15
-	 *
13
+    /**
14
+     * Retrieves the bearer token.
15
+     *
16 16
      * @return string|\WP_Error
17
-	 */
18
-	public static function get_token( $mode = 'live' ) {
17
+     */
18
+    public static function get_token( $mode = 'live' ) {
19 19
 
20
-		$token = get_transient( 'getpaid_paypal_' . $mode . '_token' );
20
+        $token = get_transient( 'getpaid_paypal_' . $mode . '_token' );
21 21
 
22
-		if ( $token ) {
23
-			return $token;
24
-		}
22
+        if ( $token ) {
23
+            return $token;
24
+        }
25 25
 
26
-		$client_id  = 'live' === $mode ? wpinv_get_option( 'paypal_client_id' ) : wpinv_get_option( 'paypal_sandbox_client_id' );
27
-		$secret_key = 'live' === $mode ? wpinv_get_option( 'paypal_secret_key' ) : wpinv_get_option( 'paypal_sandbox_secret_key' );
28
-		$url        = self::get_api_url( 'v1/oauth2/token?grant_type=client_credentials', $mode );
26
+        $client_id  = 'live' === $mode ? wpinv_get_option( 'paypal_client_id' ) : wpinv_get_option( 'paypal_sandbox_client_id' );
27
+        $secret_key = 'live' === $mode ? wpinv_get_option( 'paypal_secret_key' ) : wpinv_get_option( 'paypal_sandbox_secret_key' );
28
+        $url        = self::get_api_url( 'v1/oauth2/token?grant_type=client_credentials', $mode );
29 29
 
30 30
         if ( empty( $client_id ) || empty( $secret_key ) ) {
31 31
             return new \WP_Error( 'invalid_request', 'Missing client id or secret key.', array( 'status' => 400 ) );
32 32
         }
33 33
 
34
-		$args   = array(
35
-			'method'  => 'POST',
36
-			'timeout' => 30,
37
-			'headers' => array(
38
-				'Authorization' => 'Basic ' . base64_encode( $client_id . ':' . $secret_key ), // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_encode
39
-				'Accept'        => 'application/json',
40
-				'Content-Type'  => 'application/x-www-form-urlencoded',
41
-			),
42
-		);
43
-
44
-		$response = self::response_or_error( wp_remote_post( $url, $args ) );
45
-
46
-		if ( is_wp_error( $response ) ) {
47
-			return $response;
48
-		}
49
-
50
-		if ( ! isset( $response->access_token ) ) {
51
-			return new \WP_Error( 'invalid_request', 'Could not create token.', array( 'status' => 400 ) );
52
-		}
53
-
54
-		set_transient( 'getpaid_paypal_' . $mode . '_token', $response->access_token, $response->expires_in - 600 );
55
-		return $response->access_token;
56
-	}
57
-
58
-	/**
59
-	 * Retrieves the PayPal API URL.
60
-	 *
61
-	 * @param string $endpoint
62
-	 * @return string
63
-	 */
64
-	public static function get_api_url( $endpoint = '', $mode = 'live'  ) {
65
-		$endpoint = ltrim( $endpoint, '/' );
66
-		return 'live' === $mode ? 'https://api-m.paypal.com/' . $endpoint : 'https://api-m.sandbox.paypal.com/' . $endpoint;
67
-	}
68
-
69
-	/**
70
-	 * Handles a post request.
71
-	 *
72
-	 * @param string $path The path to the endpoint.
73
-	 * @param mixed $data The data to send.
74
-	 * @param string $method The method to use.
75
-	 *
76
-	 * @return true|\WP_Error
77
-	 */
78
-	public static function post( $path, $data, $mode = 'live', $method = 'POST' ) {
79
-
80
-		$access_token = self::get_token( $mode );
81
-
82
-		if ( is_wp_error( $access_token ) ) {
83
-			return $access_token;
84
-		}
85
-
86
-		$url  = self::get_api_url( $path, $mode );
87
-		$args = array(
88
-			'method'  => $method,
89
-			'headers' => array(
90
-				'Authorization' => 'Bearer ' . $access_token,
91
-				'Content-Type'  => 'application/json',
92
-			),
93
-			'body'    => wp_json_encode( $data ),
94
-		);
95
-
96
-		return self::response_or_error( wp_remote_post( $url, $args ) );
97
-	}
98
-
99
-	/**
100
-	 * Handles a get request.
101
-	 *
102
-	 * @param string $path The path to the endpoint.
103
-	 * @param string $method
104
-	 * @return object|\WP_Error
105
-	 */
106
-	public static function get( $path, $mode = 'live', $method = 'GET' ) {
107
-
108
-		$access_token = self::get_token( $mode );
109
-
110
-		if ( is_wp_error( $access_token ) ) {
111
-			return $access_token;
112
-		}
113
-
114
-		$url  = self::get_api_url( $path, $mode );
115
-		$args = array(
116
-			'method'  => $method,
117
-			'headers' => array(
118
-				'Authorization' => 'Bearer ' . $access_token,
119
-			),
120
-		);
121
-
122
-		return self::response_or_error( wp_remote_get( $url, $args ) );
123
-	}
124
-
125
-	/**
126
-	 * Returns the response body
127
-	 *
128
-	 * @since 1.0.0
129
-	 * @version 1.0.0
130
-	 * @param \WP_Error|array $response
131
-	 * @return \WP_Error|object
132
-	 */
133
-	public static function response_or_error( $response ) {
134
-
135
-		if ( is_wp_error( $response ) ) {
136
-			return new \WP_Error( 'paypal_error', __( 'There was a problem connecting to the PayPal API endpoint.', 'invoicing' ) );
137
-		}
138
-
139
-		if ( empty( $response['body'] ) ) {
140
-			return true;
141
-		}
142
-
143
-		$response_body = json_decode( wp_remote_retrieve_body( $response ) );
144
-
145
-		if ( wp_remote_retrieve_response_code( $response ) > 299 ) {
146
-
147
-			// Normal errors.
148
-			if ( $response_body && isset( $response_body->message ) ) {
149
-				$error_message = $response_body->message;
150
-
151
-			// Identity errors.
152
-			} elseif ( $response_body && isset( $response_body->error_description ) ) {
153
-				$error_message = $response_body->error_description;
154
-				return new \WP_Error( 'paypal_error', wp_kses_post( $response_body->error_description ) );
155
-			} else {
156
-				$error_message = __( 'There was an error connecting to the PayPal API endpoint.', 'invoicing' );
157
-			}
158
-
159
-			return new \WP_Error( 'paypal_error', $error_message );
160
-		}
161
-
162
-		return $response_body;
163
-	}
164
-
165
-	/**
166
-	 * Fetches an order.
167
-	 *
168
-	 * @since 1.0.0
169
-	 * @version 1.0.0
170
-	 * @param string $order_id
171
-	 * @link https://developer.paypal.com/docs/api/orders/v2/#orders_get
172
-	 * @return \WP_Error|object
173
-	 */
174
-	public static function get_order( $order_id, $mode = 'live' ) {
175
-		return self::get( '/v2/checkout/orders/' . $order_id, $mode );
176
-	}
177
-
178
-	/**
179
-	 * Fetches a subscription.
180
-	 *
181
-	 * @since 1.0.0
182
-	 * @version 1.0.0
183
-	 * @param string $subscription_id
184
-	 * @link https://developer.paypal.com/docs/api/subscriptions/v1/#subscriptions_get
185
-	 * @return \WP_Error|object
186
-	 */
187
-	public static function get_subscription( $subscription_id, $mode = 'live' ) {
188
-		return self::get( '/v1/billing/subscriptions/' . $subscription_id, $mode );
189
-	}
190
-
191
-	/**
192
-	 * Fetches a subscription's latest transactions (limits search to last one day).
193
-	 *
194
-	 * @since 1.0.0
195
-	 * @version 1.0.0
196
-	 * @param string $subscription_id
197
-	 * @link https://developer.paypal.com/docs/api/subscriptions/v1/#subscriptions_transactions
198
-	 * @return \WP_Error|object
199
-	 */
200
-	public static function get_subscription_transaction( $subscription_id, $mode = 'live' ) {
201
-		$start_time = gmdate( 'Y-m-d\TH:i:s\Z', strtotime( '-1 day' ) );
202
-		$end_time   = gmdate( 'Y-m-d\TH:i:s\Z' );
203
-		return self::get( "/v1/billing/subscriptions/$subscription_id/transactions?start_time=$start_time&end_time=$end_time", $mode );
204
-	}
205
-
206
-	/**
207
-	 * Refunds a capture.
208
-	 *
209
-	 * @since 1.0.0
210
-	 * @version 1.0.0
211
-	 * @param string $capture_id
212
-	 * @param array  $args
213
-	 * @link https://developer.paypal.com/docs/api/payments/v2/#captures_refund
214
-	 * @return \WP_Error|object
215
-	 */
216
-	public static function refund_capture( $capture_id, $args = array(), $mode = 'live' ) {
217
-		return self::post( '/v2/payments/captures/' . $capture_id . '/refund', $args, $mode );
218
-	}
34
+        $args   = array(
35
+            'method'  => 'POST',
36
+            'timeout' => 30,
37
+            'headers' => array(
38
+                'Authorization' => 'Basic ' . base64_encode( $client_id . ':' . $secret_key ), // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_encode
39
+                'Accept'        => 'application/json',
40
+                'Content-Type'  => 'application/x-www-form-urlencoded',
41
+            ),
42
+        );
43
+
44
+        $response = self::response_or_error( wp_remote_post( $url, $args ) );
45
+
46
+        if ( is_wp_error( $response ) ) {
47
+            return $response;
48
+        }
49
+
50
+        if ( ! isset( $response->access_token ) ) {
51
+            return new \WP_Error( 'invalid_request', 'Could not create token.', array( 'status' => 400 ) );
52
+        }
53
+
54
+        set_transient( 'getpaid_paypal_' . $mode . '_token', $response->access_token, $response->expires_in - 600 );
55
+        return $response->access_token;
56
+    }
57
+
58
+    /**
59
+     * Retrieves the PayPal API URL.
60
+     *
61
+     * @param string $endpoint
62
+     * @return string
63
+     */
64
+    public static function get_api_url( $endpoint = '', $mode = 'live'  ) {
65
+        $endpoint = ltrim( $endpoint, '/' );
66
+        return 'live' === $mode ? 'https://api-m.paypal.com/' . $endpoint : 'https://api-m.sandbox.paypal.com/' . $endpoint;
67
+    }
68
+
69
+    /**
70
+     * Handles a post request.
71
+     *
72
+     * @param string $path The path to the endpoint.
73
+     * @param mixed $data The data to send.
74
+     * @param string $method The method to use.
75
+     *
76
+     * @return true|\WP_Error
77
+     */
78
+    public static function post( $path, $data, $mode = 'live', $method = 'POST' ) {
79
+
80
+        $access_token = self::get_token( $mode );
81
+
82
+        if ( is_wp_error( $access_token ) ) {
83
+            return $access_token;
84
+        }
85
+
86
+        $url  = self::get_api_url( $path, $mode );
87
+        $args = array(
88
+            'method'  => $method,
89
+            'headers' => array(
90
+                'Authorization' => 'Bearer ' . $access_token,
91
+                'Content-Type'  => 'application/json',
92
+            ),
93
+            'body'    => wp_json_encode( $data ),
94
+        );
95
+
96
+        return self::response_or_error( wp_remote_post( $url, $args ) );
97
+    }
98
+
99
+    /**
100
+     * Handles a get request.
101
+     *
102
+     * @param string $path The path to the endpoint.
103
+     * @param string $method
104
+     * @return object|\WP_Error
105
+     */
106
+    public static function get( $path, $mode = 'live', $method = 'GET' ) {
107
+
108
+        $access_token = self::get_token( $mode );
109
+
110
+        if ( is_wp_error( $access_token ) ) {
111
+            return $access_token;
112
+        }
113
+
114
+        $url  = self::get_api_url( $path, $mode );
115
+        $args = array(
116
+            'method'  => $method,
117
+            'headers' => array(
118
+                'Authorization' => 'Bearer ' . $access_token,
119
+            ),
120
+        );
121
+
122
+        return self::response_or_error( wp_remote_get( $url, $args ) );
123
+    }
124
+
125
+    /**
126
+     * Returns the response body
127
+     *
128
+     * @since 1.0.0
129
+     * @version 1.0.0
130
+     * @param \WP_Error|array $response
131
+     * @return \WP_Error|object
132
+     */
133
+    public static function response_or_error( $response ) {
134
+
135
+        if ( is_wp_error( $response ) ) {
136
+            return new \WP_Error( 'paypal_error', __( 'There was a problem connecting to the PayPal API endpoint.', 'invoicing' ) );
137
+        }
138
+
139
+        if ( empty( $response['body'] ) ) {
140
+            return true;
141
+        }
142
+
143
+        $response_body = json_decode( wp_remote_retrieve_body( $response ) );
144
+
145
+        if ( wp_remote_retrieve_response_code( $response ) > 299 ) {
146
+
147
+            // Normal errors.
148
+            if ( $response_body && isset( $response_body->message ) ) {
149
+                $error_message = $response_body->message;
150
+
151
+            // Identity errors.
152
+            } elseif ( $response_body && isset( $response_body->error_description ) ) {
153
+                $error_message = $response_body->error_description;
154
+                return new \WP_Error( 'paypal_error', wp_kses_post( $response_body->error_description ) );
155
+            } else {
156
+                $error_message = __( 'There was an error connecting to the PayPal API endpoint.', 'invoicing' );
157
+            }
158
+
159
+            return new \WP_Error( 'paypal_error', $error_message );
160
+        }
161
+
162
+        return $response_body;
163
+    }
164
+
165
+    /**
166
+     * Fetches an order.
167
+     *
168
+     * @since 1.0.0
169
+     * @version 1.0.0
170
+     * @param string $order_id
171
+     * @link https://developer.paypal.com/docs/api/orders/v2/#orders_get
172
+     * @return \WP_Error|object
173
+     */
174
+    public static function get_order( $order_id, $mode = 'live' ) {
175
+        return self::get( '/v2/checkout/orders/' . $order_id, $mode );
176
+    }
177
+
178
+    /**
179
+     * Fetches a subscription.
180
+     *
181
+     * @since 1.0.0
182
+     * @version 1.0.0
183
+     * @param string $subscription_id
184
+     * @link https://developer.paypal.com/docs/api/subscriptions/v1/#subscriptions_get
185
+     * @return \WP_Error|object
186
+     */
187
+    public static function get_subscription( $subscription_id, $mode = 'live' ) {
188
+        return self::get( '/v1/billing/subscriptions/' . $subscription_id, $mode );
189
+    }
190
+
191
+    /**
192
+     * Fetches a subscription's latest transactions (limits search to last one day).
193
+     *
194
+     * @since 1.0.0
195
+     * @version 1.0.0
196
+     * @param string $subscription_id
197
+     * @link https://developer.paypal.com/docs/api/subscriptions/v1/#subscriptions_transactions
198
+     * @return \WP_Error|object
199
+     */
200
+    public static function get_subscription_transaction( $subscription_id, $mode = 'live' ) {
201
+        $start_time = gmdate( 'Y-m-d\TH:i:s\Z', strtotime( '-1 day' ) );
202
+        $end_time   = gmdate( 'Y-m-d\TH:i:s\Z' );
203
+        return self::get( "/v1/billing/subscriptions/$subscription_id/transactions?start_time=$start_time&end_time=$end_time", $mode );
204
+    }
205
+
206
+    /**
207
+     * Refunds a capture.
208
+     *
209
+     * @since 1.0.0
210
+     * @version 1.0.0
211
+     * @param string $capture_id
212
+     * @param array  $args
213
+     * @link https://developer.paypal.com/docs/api/payments/v2/#captures_refund
214
+     * @return \WP_Error|object
215
+     */
216
+    public static function refund_capture( $capture_id, $args = array(), $mode = 'live' ) {
217
+        return self::post( '/v2/payments/captures/' . $capture_id . '/refund', $args, $mode );
218
+    }
219 219
 
220 220
 }
Please login to merge, or discard this patch.
Spacing   +50 added lines, -50 removed lines patch added patch discarded remove patch
@@ -1,7 +1,7 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3 3
 // Exit if accessed directly.
4
-defined( 'ABSPATH' ) || exit;
4
+defined('ABSPATH') || exit;
5 5
 
6 6
 /**
7 7
  * PayPal API handler.
@@ -15,43 +15,43 @@  discard block
 block discarded – undo
15 15
 	 *
16 16
      * @return string|\WP_Error
17 17
 	 */
18
-	public static function get_token( $mode = 'live' ) {
18
+	public static function get_token($mode = 'live') {
19 19
 
20
-		$token = get_transient( 'getpaid_paypal_' . $mode . '_token' );
20
+		$token = get_transient('getpaid_paypal_' . $mode . '_token');
21 21
 
22
-		if ( $token ) {
22
+		if ($token) {
23 23
 			return $token;
24 24
 		}
25 25
 
26
-		$client_id  = 'live' === $mode ? wpinv_get_option( 'paypal_client_id' ) : wpinv_get_option( 'paypal_sandbox_client_id' );
27
-		$secret_key = 'live' === $mode ? wpinv_get_option( 'paypal_secret_key' ) : wpinv_get_option( 'paypal_sandbox_secret_key' );
28
-		$url        = self::get_api_url( 'v1/oauth2/token?grant_type=client_credentials', $mode );
26
+		$client_id  = 'live' === $mode ? wpinv_get_option('paypal_client_id') : wpinv_get_option('paypal_sandbox_client_id');
27
+		$secret_key = 'live' === $mode ? wpinv_get_option('paypal_secret_key') : wpinv_get_option('paypal_sandbox_secret_key');
28
+		$url        = self::get_api_url('v1/oauth2/token?grant_type=client_credentials', $mode);
29 29
 
30
-        if ( empty( $client_id ) || empty( $secret_key ) ) {
31
-            return new \WP_Error( 'invalid_request', 'Missing client id or secret key.', array( 'status' => 400 ) );
30
+        if (empty($client_id) || empty($secret_key)) {
31
+            return new \WP_Error('invalid_request', 'Missing client id or secret key.', array('status' => 400));
32 32
         }
33 33
 
34
-		$args   = array(
34
+		$args = array(
35 35
 			'method'  => 'POST',
36 36
 			'timeout' => 30,
37 37
 			'headers' => array(
38
-				'Authorization' => 'Basic ' . base64_encode( $client_id . ':' . $secret_key ), // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_encode
38
+				'Authorization' => 'Basic ' . base64_encode($client_id . ':' . $secret_key), // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_encode
39 39
 				'Accept'        => 'application/json',
40 40
 				'Content-Type'  => 'application/x-www-form-urlencoded',
41 41
 			),
42 42
 		);
43 43
 
44
-		$response = self::response_or_error( wp_remote_post( $url, $args ) );
44
+		$response = self::response_or_error(wp_remote_post($url, $args));
45 45
 
46
-		if ( is_wp_error( $response ) ) {
46
+		if (is_wp_error($response)) {
47 47
 			return $response;
48 48
 		}
49 49
 
50
-		if ( ! isset( $response->access_token ) ) {
51
-			return new \WP_Error( 'invalid_request', 'Could not create token.', array( 'status' => 400 ) );
50
+		if (!isset($response->access_token)) {
51
+			return new \WP_Error('invalid_request', 'Could not create token.', array('status' => 400));
52 52
 		}
53 53
 
54
-		set_transient( 'getpaid_paypal_' . $mode . '_token', $response->access_token, $response->expires_in - 600 );
54
+		set_transient('getpaid_paypal_' . $mode . '_token', $response->access_token, $response->expires_in - 600);
55 55
 		return $response->access_token;
56 56
 	}
57 57
 
@@ -61,8 +61,8 @@  discard block
 block discarded – undo
61 61
 	 * @param string $endpoint
62 62
 	 * @return string
63 63
 	 */
64
-	public static function get_api_url( $endpoint = '', $mode = 'live'  ) {
65
-		$endpoint = ltrim( $endpoint, '/' );
64
+	public static function get_api_url($endpoint = '', $mode = 'live') {
65
+		$endpoint = ltrim($endpoint, '/');
66 66
 		return 'live' === $mode ? 'https://api-m.paypal.com/' . $endpoint : 'https://api-m.sandbox.paypal.com/' . $endpoint;
67 67
 	}
68 68
 
@@ -75,25 +75,25 @@  discard block
 block discarded – undo
75 75
 	 *
76 76
 	 * @return true|\WP_Error
77 77
 	 */
78
-	public static function post( $path, $data, $mode = 'live', $method = 'POST' ) {
78
+	public static function post($path, $data, $mode = 'live', $method = 'POST') {
79 79
 
80
-		$access_token = self::get_token( $mode );
80
+		$access_token = self::get_token($mode);
81 81
 
82
-		if ( is_wp_error( $access_token ) ) {
82
+		if (is_wp_error($access_token)) {
83 83
 			return $access_token;
84 84
 		}
85 85
 
86
-		$url  = self::get_api_url( $path, $mode );
86
+		$url  = self::get_api_url($path, $mode);
87 87
 		$args = array(
88 88
 			'method'  => $method,
89 89
 			'headers' => array(
90 90
 				'Authorization' => 'Bearer ' . $access_token,
91 91
 				'Content-Type'  => 'application/json',
92 92
 			),
93
-			'body'    => wp_json_encode( $data ),
93
+			'body'    => wp_json_encode($data),
94 94
 		);
95 95
 
96
-		return self::response_or_error( wp_remote_post( $url, $args ) );
96
+		return self::response_or_error(wp_remote_post($url, $args));
97 97
 	}
98 98
 
99 99
 	/**
@@ -103,15 +103,15 @@  discard block
 block discarded – undo
103 103
 	 * @param string $method
104 104
 	 * @return object|\WP_Error
105 105
 	 */
106
-	public static function get( $path, $mode = 'live', $method = 'GET' ) {
106
+	public static function get($path, $mode = 'live', $method = 'GET') {
107 107
 
108
-		$access_token = self::get_token( $mode );
108
+		$access_token = self::get_token($mode);
109 109
 
110
-		if ( is_wp_error( $access_token ) ) {
110
+		if (is_wp_error($access_token)) {
111 111
 			return $access_token;
112 112
 		}
113 113
 
114
-		$url  = self::get_api_url( $path, $mode );
114
+		$url  = self::get_api_url($path, $mode);
115 115
 		$args = array(
116 116
 			'method'  => $method,
117 117
 			'headers' => array(
@@ -119,7 +119,7 @@  discard block
 block discarded – undo
119 119
 			),
120 120
 		);
121 121
 
122
-		return self::response_or_error( wp_remote_get( $url, $args ) );
122
+		return self::response_or_error(wp_remote_get($url, $args));
123 123
 	}
124 124
 
125 125
 	/**
@@ -130,33 +130,33 @@  discard block
 block discarded – undo
130 130
 	 * @param \WP_Error|array $response
131 131
 	 * @return \WP_Error|object
132 132
 	 */
133
-	public static function response_or_error( $response ) {
133
+	public static function response_or_error($response) {
134 134
 
135
-		if ( is_wp_error( $response ) ) {
136
-			return new \WP_Error( 'paypal_error', __( 'There was a problem connecting to the PayPal API endpoint.', 'invoicing' ) );
135
+		if (is_wp_error($response)) {
136
+			return new \WP_Error('paypal_error', __('There was a problem connecting to the PayPal API endpoint.', 'invoicing'));
137 137
 		}
138 138
 
139
-		if ( empty( $response['body'] ) ) {
139
+		if (empty($response['body'])) {
140 140
 			return true;
141 141
 		}
142 142
 
143
-		$response_body = json_decode( wp_remote_retrieve_body( $response ) );
143
+		$response_body = json_decode(wp_remote_retrieve_body($response));
144 144
 
145
-		if ( wp_remote_retrieve_response_code( $response ) > 299 ) {
145
+		if (wp_remote_retrieve_response_code($response) > 299) {
146 146
 
147 147
 			// Normal errors.
148
-			if ( $response_body && isset( $response_body->message ) ) {
148
+			if ($response_body && isset($response_body->message)) {
149 149
 				$error_message = $response_body->message;
150 150
 
151 151
 			// Identity errors.
152
-			} elseif ( $response_body && isset( $response_body->error_description ) ) {
152
+			} elseif ($response_body && isset($response_body->error_description)) {
153 153
 				$error_message = $response_body->error_description;
154
-				return new \WP_Error( 'paypal_error', wp_kses_post( $response_body->error_description ) );
154
+				return new \WP_Error('paypal_error', wp_kses_post($response_body->error_description));
155 155
 			} else {
156
-				$error_message = __( 'There was an error connecting to the PayPal API endpoint.', 'invoicing' );
156
+				$error_message = __('There was an error connecting to the PayPal API endpoint.', 'invoicing');
157 157
 			}
158 158
 
159
-			return new \WP_Error( 'paypal_error', $error_message );
159
+			return new \WP_Error('paypal_error', $error_message);
160 160
 		}
161 161
 
162 162
 		return $response_body;
@@ -171,8 +171,8 @@  discard block
 block discarded – undo
171 171
 	 * @link https://developer.paypal.com/docs/api/orders/v2/#orders_get
172 172
 	 * @return \WP_Error|object
173 173
 	 */
174
-	public static function get_order( $order_id, $mode = 'live' ) {
175
-		return self::get( '/v2/checkout/orders/' . $order_id, $mode );
174
+	public static function get_order($order_id, $mode = 'live') {
175
+		return self::get('/v2/checkout/orders/' . $order_id, $mode);
176 176
 	}
177 177
 
178 178
 	/**
@@ -184,8 +184,8 @@  discard block
 block discarded – undo
184 184
 	 * @link https://developer.paypal.com/docs/api/subscriptions/v1/#subscriptions_get
185 185
 	 * @return \WP_Error|object
186 186
 	 */
187
-	public static function get_subscription( $subscription_id, $mode = 'live' ) {
188
-		return self::get( '/v1/billing/subscriptions/' . $subscription_id, $mode );
187
+	public static function get_subscription($subscription_id, $mode = 'live') {
188
+		return self::get('/v1/billing/subscriptions/' . $subscription_id, $mode);
189 189
 	}
190 190
 
191 191
 	/**
@@ -197,10 +197,10 @@  discard block
 block discarded – undo
197 197
 	 * @link https://developer.paypal.com/docs/api/subscriptions/v1/#subscriptions_transactions
198 198
 	 * @return \WP_Error|object
199 199
 	 */
200
-	public static function get_subscription_transaction( $subscription_id, $mode = 'live' ) {
201
-		$start_time = gmdate( 'Y-m-d\TH:i:s\Z', strtotime( '-1 day' ) );
202
-		$end_time   = gmdate( 'Y-m-d\TH:i:s\Z' );
203
-		return self::get( "/v1/billing/subscriptions/$subscription_id/transactions?start_time=$start_time&end_time=$end_time", $mode );
200
+	public static function get_subscription_transaction($subscription_id, $mode = 'live') {
201
+		$start_time = gmdate('Y-m-d\TH:i:s\Z', strtotime('-1 day'));
202
+		$end_time   = gmdate('Y-m-d\TH:i:s\Z');
203
+		return self::get("/v1/billing/subscriptions/$subscription_id/transactions?start_time=$start_time&end_time=$end_time", $mode);
204 204
 	}
205 205
 
206 206
 	/**
@@ -213,8 +213,8 @@  discard block
 block discarded – undo
213 213
 	 * @link https://developer.paypal.com/docs/api/payments/v2/#captures_refund
214 214
 	 * @return \WP_Error|object
215 215
 	 */
216
-	public static function refund_capture( $capture_id, $args = array(), $mode = 'live' ) {
217
-		return self::post( '/v2/payments/captures/' . $capture_id . '/refund', $args, $mode );
216
+	public static function refund_capture($capture_id, $args = array(), $mode = 'live') {
217
+		return self::post('/v2/payments/captures/' . $capture_id . '/refund', $args, $mode);
218 218
 	}
219 219
 
220 220
 }
Please login to merge, or discard this patch.
includes/gateways/class-getpaid-paypal-gateway.php 2 patches
Indentation   +399 added lines, -399 removed lines patch added patch discarded remove patch
@@ -13,97 +13,97 @@  discard block
 block discarded – undo
13 13
 class GetPaid_Paypal_Gateway extends GetPaid_Payment_Gateway {
14 14
 
15 15
     /**
16
-	 * Payment method id.
17
-	 *
18
-	 * @var string
19
-	 */
16
+     * Payment method id.
17
+     *
18
+     * @var string
19
+     */
20 20
     public $id = 'paypal';
21 21
 
22 22
     /**
23
-	 * An array of features that this gateway supports.
24
-	 *
25
-	 * @var array
26
-	 */
23
+     * An array of features that this gateway supports.
24
+     *
25
+     * @var array
26
+     */
27 27
     protected $supports = array( 'subscription', 'sandbox', 'single_subscription_group' );
28 28
 
29 29
     /**
30
-	 * Payment method order.
31
-	 *
32
-	 * @var int
33
-	 */
30
+     * Payment method order.
31
+     *
32
+     * @var int
33
+     */
34 34
     public $order = 1;
35 35
 
36 36
     /**
37
-	 * Stores line items to send to PayPal.
38
-	 *
39
-	 * @var array
40
-	 */
37
+     * Stores line items to send to PayPal.
38
+     *
39
+     * @var array
40
+     */
41 41
     protected $line_items = array();
42 42
 
43 43
     /**
44
-	 * Endpoint for requests from PayPal.
45
-	 *
46
-	 * @var string
47
-	 */
48
-	protected $notify_url;
49
-
50
-	/**
51
-	 * Endpoint for requests to PayPal.
52
-	 *
53
-	 * @var string
54
-	 */
44
+     * Endpoint for requests from PayPal.
45
+     *
46
+     * @var string
47
+     */
48
+    protected $notify_url;
49
+
50
+    /**
51
+     * Endpoint for requests to PayPal.
52
+     *
53
+     * @var string
54
+     */
55 55
     protected $endpoint;
56 56
 
57 57
     /**
58
-	 * Currencies this gateway is allowed for.
59
-	 *
60
-	 * @var array
61
-	 */
62
-	public $currencies = array( 'AUD', 'BRL', 'CAD', 'MXN', 'NZD', 'HKD', 'SGD', 'USD', 'EUR', 'JPY', 'TRY', 'NOK', 'CZK', 'DKK', 'HUF', 'ILS', 'MYR', 'PHP', 'PLN', 'SEK', 'CHF', 'TWD', 'THB', 'GBP', 'RMB', 'RUB', 'INR' );
58
+     * Currencies this gateway is allowed for.
59
+     *
60
+     * @var array
61
+     */
62
+    public $currencies = array( 'AUD', 'BRL', 'CAD', 'MXN', 'NZD', 'HKD', 'SGD', 'USD', 'EUR', 'JPY', 'TRY', 'NOK', 'CZK', 'DKK', 'HUF', 'ILS', 'MYR', 'PHP', 'PLN', 'SEK', 'CHF', 'TWD', 'THB', 'GBP', 'RMB', 'RUB', 'INR' );
63 63
 
64 64
     /**
65
-	 * URL to view a transaction.
66
-	 *
67
-	 * @var string
68
-	 */
65
+     * URL to view a transaction.
66
+     *
67
+     * @var string
68
+     */
69 69
     public $view_transaction_url = 'https://www.{sandbox}paypal.com/activity/payment/%s';
70 70
 
71 71
     /**
72
-	 * URL to view a subscription.
73
-	 *
74
-	 * @var string
75
-	 */
76
-	public $view_subscription_url = 'https://www.{sandbox}paypal.com/cgi-bin/webscr?cmd=_profile-recurring-payments&encrypted_profile_id=%s';
72
+     * URL to view a subscription.
73
+     *
74
+     * @var string
75
+     */
76
+    public $view_subscription_url = 'https://www.{sandbox}paypal.com/cgi-bin/webscr?cmd=_profile-recurring-payments&encrypted_profile_id=%s';
77 77
 
78 78
     /**
79
-	 * Class constructor.
80
-	 */
81
-	public function __construct() {
79
+     * Class constructor.
80
+     */
81
+    public function __construct() {
82 82
 
83 83
         $this->title                = __( 'PayPal Standard', 'invoicing' );
84 84
         $this->method_title         = __( 'PayPal Standard', 'invoicing' );
85 85
         $this->checkout_button_text = __( 'Proceed to PayPal', 'invoicing' );
86 86
         $this->notify_url           = wpinv_get_ipn_url( $this->id );
87 87
 
88
-		add_filter( 'wpinv_subscription_cancel_url', array( $this, 'filter_cancel_subscription_url' ), 10, 2 );
89
-		add_filter( 'getpaid_paypal_args', array( $this, 'process_subscription' ), 10, 2 );
88
+        add_filter( 'wpinv_subscription_cancel_url', array( $this, 'filter_cancel_subscription_url' ), 10, 2 );
89
+        add_filter( 'getpaid_paypal_args', array( $this, 'process_subscription' ), 10, 2 );
90 90
         add_filter( 'getpaid_paypal_sandbox_notice', array( $this, 'sandbox_notice' ) );
91
-		add_filter( 'getpaid_get_paypal_connect_url', array( $this, 'maybe_get_connect_url' ), 10, 2 );
92
-		add_action( 'getpaid_authenticated_admin_action_connect_paypal', array( $this, 'connect_paypal' ) );
93
-		add_action( 'wpinv_paypal_connect', array( $this, 'display_connect_buttons' ) );
94
-		parent::__construct();
91
+        add_filter( 'getpaid_get_paypal_connect_url', array( $this, 'maybe_get_connect_url' ), 10, 2 );
92
+        add_action( 'getpaid_authenticated_admin_action_connect_paypal', array( $this, 'connect_paypal' ) );
93
+        add_action( 'wpinv_paypal_connect', array( $this, 'display_connect_buttons' ) );
94
+        parent::__construct();
95 95
     }
96 96
 
97 97
     /**
98
-	 * Process Payment.
99
-	 *
100
-	 *
101
-	 * @param WPInv_Invoice $invoice Invoice.
102
-	 * @param array $submission_data Posted checkout fields.
103
-	 * @param GetPaid_Payment_Form_Submission $submission Checkout submission.
104
-	 * @return array
105
-	 */
106
-	public function process_payment( $invoice, $submission_data, $submission ) {
98
+     * Process Payment.
99
+     *
100
+     *
101
+     * @param WPInv_Invoice $invoice Invoice.
102
+     * @param array $submission_data Posted checkout fields.
103
+     * @param GetPaid_Payment_Form_Submission $submission Checkout submission.
104
+     * @return array
105
+     */
106
+    public function process_payment( $invoice, $submission_data, $submission ) {
107 107
 
108 108
         // Get redirect url.
109 109
         $paypal_redirect = $this->get_request_url( $invoice );
@@ -126,15 +126,15 @@  discard block
 block discarded – undo
126 126
     }
127 127
 
128 128
     /**
129
-	 * Get the PayPal request URL for an invoice.
130
-	 *
131
-	 * @param  WPInv_Invoice $invoice Invoice object.
132
-	 * @return string
133
-	 */
134
-	public function get_request_url( $invoice ) {
129
+     * Get the PayPal request URL for an invoice.
130
+     *
131
+     * @param  WPInv_Invoice $invoice Invoice object.
132
+     * @return string
133
+     */
134
+    public function get_request_url( $invoice ) {
135 135
 
136 136
         // Endpoint for this request
137
-		$this->endpoint    = $this->is_sandbox( $invoice ) ? 'https://www.sandbox.paypal.com/cgi-bin/webscr?test_ipn=1&' : 'https://www.paypal.com/cgi-bin/webscr?';
137
+        $this->endpoint    = $this->is_sandbox( $invoice ) ? 'https://www.sandbox.paypal.com/cgi-bin/webscr?test_ipn=1&' : 'https://www.paypal.com/cgi-bin/webscr?';
138 138
 
139 139
         // Retrieve paypal args.
140 140
         $paypal_args       = map_deep( $this->get_paypal_args( $invoice ), 'urlencode' );
@@ -147,45 +147,45 @@  discard block
 block discarded – undo
147 147
 
148 148
         return add_query_arg( $paypal_args, $this->endpoint );
149 149
 
150
-	}
150
+    }
151 151
 
152 152
     /**
153
-	 * Get PayPal Args for passing to PP.
154
-	 *
155
-	 * @param  WPInv_Invoice $invoice Invoice object.
156
-	 * @return array
157
-	 */
158
-	protected function get_paypal_args( $invoice ) {
153
+     * Get PayPal Args for passing to PP.
154
+     *
155
+     * @param  WPInv_Invoice $invoice Invoice object.
156
+     * @return array
157
+     */
158
+    protected function get_paypal_args( $invoice ) {
159 159
 
160 160
         // Whether or not to send the line items as one item.
161
-		$force_one_line_item = apply_filters( 'getpaid_paypal_force_one_line_item', true, $invoice );
162
-
163
-		if ( $invoice->is_recurring() || ( wpinv_use_taxes() && wpinv_prices_include_tax() ) ) {
164
-			$force_one_line_item = true;
165
-		}
166
-
167
-		$paypal_args = apply_filters(
168
-			'getpaid_paypal_args',
169
-			array_merge(
170
-				$this->get_transaction_args( $invoice ),
171
-				$this->get_line_item_args( $invoice, $force_one_line_item )
172
-			),
173
-			$invoice
174
-		);
175
-
176
-		return $this->fix_request_length( $invoice, $paypal_args );
161
+        $force_one_line_item = apply_filters( 'getpaid_paypal_force_one_line_item', true, $invoice );
162
+
163
+        if ( $invoice->is_recurring() || ( wpinv_use_taxes() && wpinv_prices_include_tax() ) ) {
164
+            $force_one_line_item = true;
165
+        }
166
+
167
+        $paypal_args = apply_filters(
168
+            'getpaid_paypal_args',
169
+            array_merge(
170
+                $this->get_transaction_args( $invoice ),
171
+                $this->get_line_item_args( $invoice, $force_one_line_item )
172
+            ),
173
+            $invoice
174
+        );
175
+
176
+        return $this->fix_request_length( $invoice, $paypal_args );
177 177
     }
178 178
 
179 179
     /**
180
-	 * Get transaction args for paypal request.
181
-	 *
182
-	 * @param WPInv_Invoice $invoice Invoice object.
183
-	 * @return array
184
-	 */
185
-	protected function get_transaction_args( $invoice ) {
186
-
187
-		$email = $this->is_sandbox( $invoice ) ? wpinv_get_option( 'paypal_sandbox_email', wpinv_get_option( 'paypal_email', '' ) ) : wpinv_get_option( 'paypal_email', '' );
188
-		return array(
180
+     * Get transaction args for paypal request.
181
+     *
182
+     * @param WPInv_Invoice $invoice Invoice object.
183
+     * @return array
184
+     */
185
+    protected function get_transaction_args( $invoice ) {
186
+
187
+        $email = $this->is_sandbox( $invoice ) ? wpinv_get_option( 'paypal_sandbox_email', wpinv_get_option( 'paypal_email', '' ) ) : wpinv_get_option( 'paypal_email', '' );
188
+        return array(
189 189
             'cmd'           => '_cart',
190 190
             'business'      => $email,
191 191
             'no_shipping'   => '1',
@@ -210,16 +210,16 @@  discard block
 block discarded – undo
210 210
     }
211 211
 
212 212
     /**
213
-	 * Get line item args for paypal request.
214
-	 *
215
-	 * @param  WPInv_Invoice $invoice Invoice object.
216
-	 * @param  bool     $force_one_line_item Create only one item for this invoice.
217
-	 * @return array
218
-	 */
219
-	protected function get_line_item_args( $invoice, $force_one_line_item = false ) {
213
+     * Get line item args for paypal request.
214
+     *
215
+     * @param  WPInv_Invoice $invoice Invoice object.
216
+     * @param  bool     $force_one_line_item Create only one item for this invoice.
217
+     * @return array
218
+     */
219
+    protected function get_line_item_args( $invoice, $force_one_line_item = false ) {
220 220
 
221 221
         // Maybe send invoice as a single item.
222
-		if ( $force_one_line_item ) {
222
+        if ( $force_one_line_item ) {
223 223
             return $this->get_line_item_args_single_item( $invoice );
224 224
         }
225 225
 
@@ -239,129 +239,129 @@  discard block
 block discarded – undo
239 239
             $line_item_args['discount_amount_cart'] = wpinv_sanitize_amount( (float) $invoice->get_total_discount(), 2 );
240 240
         }
241 241
 
242
-		return array_merge( $line_item_args, $this->get_line_items() );
242
+        return array_merge( $line_item_args, $this->get_line_items() );
243 243
 
244 244
     }
245 245
 
246 246
     /**
247
-	 * Get line item args for paypal request as a single line item.
248
-	 *
249
-	 * @param  WPInv_Invoice $invoice Invoice object.
250
-	 * @return array
251
-	 */
252
-	protected function get_line_item_args_single_item( $invoice ) {
253
-		$this->delete_line_items();
247
+     * Get line item args for paypal request as a single line item.
248
+     *
249
+     * @param  WPInv_Invoice $invoice Invoice object.
250
+     * @return array
251
+     */
252
+    protected function get_line_item_args_single_item( $invoice ) {
253
+        $this->delete_line_items();
254 254
 
255 255
         $item_name = sprintf( __( 'Invoice #%s', 'invoicing' ), $invoice->get_number() );
256
-		$this->add_line_item( $item_name, 1, wpinv_round_amount( (float) $invoice->get_total(), 2, true ), $invoice->get_id() );
256
+        $this->add_line_item( $item_name, 1, wpinv_round_amount( (float) $invoice->get_total(), 2, true ), $invoice->get_id() );
257 257
 
258
-		return $this->get_line_items();
258
+        return $this->get_line_items();
259 259
     }
260 260
 
261 261
     /**
262
-	 * Return all line items.
263
-	 */
264
-	protected function get_line_items() {
265
-		return $this->line_items;
266
-	}
262
+     * Return all line items.
263
+     */
264
+    protected function get_line_items() {
265
+        return $this->line_items;
266
+    }
267 267
 
268 268
     /**
269
-	 * Remove all line items.
270
-	 */
271
-	protected function delete_line_items() {
272
-		$this->line_items = array();
269
+     * Remove all line items.
270
+     */
271
+    protected function delete_line_items() {
272
+        $this->line_items = array();
273 273
     }
274 274
 
275 275
     /**
276
-	 * Prepare line items to send to paypal.
277
-	 *
278
-	 * @param  WPInv_Invoice $invoice Invoice object.
279
-	 */
280
-	protected function prepare_line_items( $invoice ) {
281
-		$this->delete_line_items();
282
-
283
-		// Items.
284
-		foreach ( $invoice->get_items() as $item ) {
285
-			$amount   = $item->get_price();
286
-			$quantity = $invoice->get_template() == 'amount' ? 1 : $item->get_quantity();
287
-			$this->add_line_item( $item->get_raw_name(), $quantity, $amount, $item->get_id() );
276
+     * Prepare line items to send to paypal.
277
+     *
278
+     * @param  WPInv_Invoice $invoice Invoice object.
279
+     */
280
+    protected function prepare_line_items( $invoice ) {
281
+        $this->delete_line_items();
282
+
283
+        // Items.
284
+        foreach ( $invoice->get_items() as $item ) {
285
+            $amount   = $item->get_price();
286
+            $quantity = $invoice->get_template() == 'amount' ? 1 : $item->get_quantity();
287
+            $this->add_line_item( $item->get_raw_name(), $quantity, $amount, $item->get_id() );
288 288
         }
289 289
 
290 290
         // Fees.
291
-		foreach ( $invoice->get_fees() as $fee => $data ) {
291
+        foreach ( $invoice->get_fees() as $fee => $data ) {
292 292
             $this->add_line_item( $fee, 1, wpinv_sanitize_amount( $data['initial_fee'] ) );
293 293
         }
294 294
 
295 295
     }
296 296
 
297 297
     /**
298
-	 * Add PayPal Line Item.
299
-	 *
300
-	 * @param  string $item_name Item name.
301
-	 * @param  float    $quantity Item quantity.
302
-	 * @param  float  $amount Amount.
303
-	 * @param  string $item_number Item number.
304
-	 */
305
-	protected function add_line_item( $item_name, $quantity = 1, $amount = 0.0, $item_number = '' ) {
306
-		$index = ( count( $this->line_items ) / 4 ) + 1;
307
-
308
-		$item = apply_filters(
309
-			'getpaid_paypal_line_item',
310
-			array(
311
-				'item_name'   => html_entity_decode( getpaid_limit_length( $item_name ? wp_strip_all_tags( $item_name ) : __( 'Item', 'invoicing' ), 127 ), ENT_NOQUOTES, 'UTF-8' ),
312
-				'quantity'    => (float) $quantity,
313
-				'amount'      => wpinv_sanitize_amount( (float) $amount, 2 ),
314
-				'item_number' => $item_number,
315
-			),
316
-			$item_name,
317
-			$quantity,
318
-			$amount,
319
-			$item_number
320
-		);
321
-
322
-		$this->line_items[ 'item_name_' . $index ]   = getpaid_limit_length( $item['item_name'], 127 );
298
+     * Add PayPal Line Item.
299
+     *
300
+     * @param  string $item_name Item name.
301
+     * @param  float    $quantity Item quantity.
302
+     * @param  float  $amount Amount.
303
+     * @param  string $item_number Item number.
304
+     */
305
+    protected function add_line_item( $item_name, $quantity = 1, $amount = 0.0, $item_number = '' ) {
306
+        $index = ( count( $this->line_items ) / 4 ) + 1;
307
+
308
+        $item = apply_filters(
309
+            'getpaid_paypal_line_item',
310
+            array(
311
+                'item_name'   => html_entity_decode( getpaid_limit_length( $item_name ? wp_strip_all_tags( $item_name ) : __( 'Item', 'invoicing' ), 127 ), ENT_NOQUOTES, 'UTF-8' ),
312
+                'quantity'    => (float) $quantity,
313
+                'amount'      => wpinv_sanitize_amount( (float) $amount, 2 ),
314
+                'item_number' => $item_number,
315
+            ),
316
+            $item_name,
317
+            $quantity,
318
+            $amount,
319
+            $item_number
320
+        );
321
+
322
+        $this->line_items[ 'item_name_' . $index ]   = getpaid_limit_length( $item['item_name'], 127 );
323 323
         $this->line_items[ 'quantity_' . $index ]    = $item['quantity'];
324 324
 
325 325
         // The price or amount of the product, service, or contribution, not including shipping, handling, or tax.
326
-		$this->line_items[ 'amount_' . $index ]      = $item['amount'] * $item['quantity'];
327
-		$this->line_items[ 'item_number_' . $index ] = getpaid_limit_length( $item['item_number'], 127 );
326
+        $this->line_items[ 'amount_' . $index ]      = $item['amount'] * $item['quantity'];
327
+        $this->line_items[ 'item_number_' . $index ] = getpaid_limit_length( $item['item_number'], 127 );
328 328
     }
329 329
 
330 330
     /**
331
-	 * If the default request with line items is too long, generate a new one with only one line item.
332
-	 *
333
-	 * https://support.microsoft.com/en-us/help/208427/maximum-url-length-is-2-083-characters-in-internet-explorer.
334
-	 *
335
-	 * @param WPInv_Invoice $invoice Invoice to be sent to Paypal.
336
-	 * @param array    $paypal_args Arguments sent to Paypal in the request.
337
-	 * @return array
338
-	 */
339
-	protected function fix_request_length( $invoice, $paypal_args ) {
340
-		$max_paypal_length = 2083;
341
-		$query_candidate   = http_build_query( $paypal_args, '', '&' );
342
-
343
-		if ( strlen( $this->endpoint . $query_candidate ) <= $max_paypal_length ) {
344
-			return $paypal_args;
345
-		}
346
-
347
-		return apply_filters(
348
-			'getpaid_paypal_args',
349
-			array_merge(
350
-				$this->get_transaction_args( $invoice ),
351
-				$this->get_line_item_args( $invoice, true )
352
-			),
353
-			$invoice
354
-		);
331
+     * If the default request with line items is too long, generate a new one with only one line item.
332
+     *
333
+     * https://support.microsoft.com/en-us/help/208427/maximum-url-length-is-2-083-characters-in-internet-explorer.
334
+     *
335
+     * @param WPInv_Invoice $invoice Invoice to be sent to Paypal.
336
+     * @param array    $paypal_args Arguments sent to Paypal in the request.
337
+     * @return array
338
+     */
339
+    protected function fix_request_length( $invoice, $paypal_args ) {
340
+        $max_paypal_length = 2083;
341
+        $query_candidate   = http_build_query( $paypal_args, '', '&' );
342
+
343
+        if ( strlen( $this->endpoint . $query_candidate ) <= $max_paypal_length ) {
344
+            return $paypal_args;
345
+        }
346
+
347
+        return apply_filters(
348
+            'getpaid_paypal_args',
349
+            array_merge(
350
+                $this->get_transaction_args( $invoice ),
351
+                $this->get_line_item_args( $invoice, true )
352
+            ),
353
+            $invoice
354
+        );
355 355
 
356 356
     }
357 357
 
358 358
     /**
359
-	 * Processes recurring invoices.
360
-	 *
361
-	 * @param  array $paypal_args PayPal args.
362
-	 * @param  WPInv_Invoice    $invoice Invoice object.
363
-	 */
364
-	public function process_subscription( $paypal_args, $invoice ) {
359
+     * Processes recurring invoices.
360
+     *
361
+     * @param  array $paypal_args PayPal args.
362
+     * @param  WPInv_Invoice    $invoice Invoice object.
363
+     */
364
+    public function process_subscription( $paypal_args, $invoice ) {
365 365
 
366 366
         // Make sure this is a subscription.
367 367
         if ( ! $invoice->is_recurring() || ! $subscription = getpaid_get_invoice_subscription( $invoice ) ) {
@@ -382,21 +382,21 @@  discard block
 block discarded – undo
382 382
         $recurring_amount       = (float) wpinv_sanitize_amount( $invoice->get_recurring_total(), 2 );
383 383
         $subscription_item      = $invoice->get_recurring( true );
384 384
 
385
-		// Convert 365 days to 1 year.
386
-		if ( 'D' == $period && 365 == $interval ) {
387
-			$period = 'Y';
388
-			$interval = 1;
389
-		}
385
+        // Convert 365 days to 1 year.
386
+        if ( 'D' == $period && 365 == $interval ) {
387
+            $period = 'Y';
388
+            $interval = 1;
389
+        }
390 390
 
391 391
         if ( $subscription_item->has_free_trial() ) {
392 392
 
393 393
             $paypal_args['a1'] = 0 == $initial_amount ? 0 : $initial_amount;
394 394
 
395
-			// Trial period length.
396
-			$paypal_args['p1'] = $subscription_item->get_trial_interval();
395
+            // Trial period length.
396
+            $paypal_args['p1'] = $subscription_item->get_trial_interval();
397 397
 
398
-			// Trial period.
399
-			$paypal_args['t1'] = $subscription_item->get_trial_period();
398
+            // Trial period.
399
+            $paypal_args['t1'] = $subscription_item->get_trial_period();
400 400
 
401 401
         } elseif ( $initial_amount != $recurring_amount ) {
402 402
 
@@ -419,40 +419,40 @@  discard block
 block discarded – undo
419 419
         }
420 420
 
421 421
         // We have a recurring payment
422
-		if ( ! isset( $param_number ) || 1 == $param_number ) {
422
+        if ( ! isset( $param_number ) || 1 == $param_number ) {
423 423
 
424
-			// Subscription price
425
-			$paypal_args['a3'] = $recurring_amount;
424
+            // Subscription price
425
+            $paypal_args['a3'] = $recurring_amount;
426 426
 
427
-			// Subscription duration
428
-			$paypal_args['p3'] = $interval;
427
+            // Subscription duration
428
+            $paypal_args['p3'] = $interval;
429 429
 
430
-			// Subscription period
431
-			$paypal_args['t3'] = $period;
430
+            // Subscription period
431
+            $paypal_args['t3'] = $period;
432 432
 
433 433
         }
434 434
 
435 435
         // Recurring payments
436
-		if ( 1 == $bill_times || ( $initial_amount != $recurring_amount && ! $subscription_item->has_free_trial() && 2 == $bill_times ) ) {
436
+        if ( 1 == $bill_times || ( $initial_amount != $recurring_amount && ! $subscription_item->has_free_trial() && 2 == $bill_times ) ) {
437 437
 
438
-			// Non-recurring payments
439
-			$paypal_args['src'] = 0;
438
+            // Non-recurring payments
439
+            $paypal_args['src'] = 0;
440 440
 
441
-		} else {
441
+        } else {
442 442
 
443
-			$paypal_args['src'] = 1;
443
+            $paypal_args['src'] = 1;
444 444
 
445
-			if ( $bill_times > 0 ) {
445
+            if ( $bill_times > 0 ) {
446 446
 
447
-				// An initial period is being used to charge a sign-up fee
448
-				if ( $initial_amount != $recurring_amount && ! $subscription_item->has_free_trial() ) {
449
-					$bill_times--;
450
-				}
447
+                // An initial period is being used to charge a sign-up fee
448
+                if ( $initial_amount != $recurring_amount && ! $subscription_item->has_free_trial() ) {
449
+                    $bill_times--;
450
+                }
451 451
 
452 452
                 // Make sure it's not over the max of 52
453 453
                 $paypal_args['srt'] = ( $bill_times <= 52 ? absint( $bill_times ) : 52 );
454 454
 
455
-			}
455
+            }
456 456
         }
457 457
 
458 458
         // Force return URL so that order description & instructions display
@@ -467,19 +467,19 @@  discard block
 block discarded – undo
467 467
 }
468 468
 
469 469
         return apply_filters(
470
-			'getpaid_paypal_subscription_args',
471
-			$paypal_args,
472
-			$invoice
470
+            'getpaid_paypal_subscription_args',
471
+            $paypal_args,
472
+            $invoice
473 473
         );
474 474
 
475 475
     }
476 476
 
477 477
     /**
478
-	 * Processes ipns and marks payments as complete.
479
-	 *
480
-	 * @return void
481
-	 */
482
-	public function verify_ipn() {
478
+     * Processes ipns and marks payments as complete.
479
+     *
480
+     * @return void
481
+     */
482
+    public function verify_ipn() {
483 483
         new GetPaid_Paypal_Gateway_IPN_Handler( $this );
484 484
     }
485 485
 
@@ -489,19 +489,19 @@  discard block
 block discarded – undo
489 489
     public function sandbox_notice() {
490 490
 
491 491
         return sprintf(
492
-			__( 'SANDBOX ENABLED. You can use sandbox testing accounts only. See the %1$sPayPal Sandbox Testing Guide%2$s for more details.', 'invoicing' ),
493
-			'<a href="https://developer.paypal.com/docs/classic/lifecycle/ug_sandbox/">',
494
-			'</a>'
495
-		);
492
+            __( 'SANDBOX ENABLED. You can use sandbox testing accounts only. See the %1$sPayPal Sandbox Testing Guide%2$s for more details.', 'invoicing' ),
493
+            '<a href="https://developer.paypal.com/docs/classic/lifecycle/ug_sandbox/">',
494
+            '</a>'
495
+        );
496 496
 
497 497
     }
498 498
 
499
-	/**
500
-	 * Filters the gateway settings.
501
-	 *
502
-	 * @param array $admin_settings
503
-	 */
504
-	public function admin_settings( $admin_settings ) {
499
+    /**
500
+     * Filters the gateway settings.
501
+     *
502
+     * @param array $admin_settings
503
+     */
504
+    public function admin_settings( $admin_settings ) {
505 505
 
506 506
         $currencies = sprintf(
507 507
             __( 'Supported Currencies: %s', 'invoicing' ),
@@ -511,66 +511,66 @@  discard block
 block discarded – undo
511 511
         $admin_settings['paypal_active']['desc'] .= " ($currencies)";
512 512
         $admin_settings['paypal_desc']['std']     = __( 'Pay via PayPal: you can pay with your credit card if you don\'t have a PayPal account.', 'invoicing' );
513 513
 
514
-		// Access tokens.
515
-		$live_email      = wpinv_get_option( 'paypal_email' );
516
-		$sandbox_email   = wpinv_get_option( 'paypal_sandbox_email' );
514
+        // Access tokens.
515
+        $live_email      = wpinv_get_option( 'paypal_email' );
516
+        $sandbox_email   = wpinv_get_option( 'paypal_sandbox_email' );
517 517
 
518
-		$admin_settings['paypal_connect'] = array(
519
-			'type' => 'hook',
520
-			'id'   => 'paypal_connect',
521
-			'name' => __( 'Connect to PayPal', 'invoicing' ),
522
-		);
518
+        $admin_settings['paypal_connect'] = array(
519
+            'type' => 'hook',
520
+            'id'   => 'paypal_connect',
521
+            'name' => __( 'Connect to PayPal', 'invoicing' ),
522
+        );
523 523
 
524 524
         $admin_settings['paypal_email'] = array(
525 525
             'type'  => 'text',
526
-			'class' => 'live-auth-data',
526
+            'class' => 'live-auth-data',
527 527
             'id'    => 'paypal_email',
528 528
             'name'  => __( 'Live Email Address', 'invoicing' ),
529 529
             'desc'  => __( 'The email address of your PayPal account.', 'invoicing' ),
530 530
         );
531 531
 
532
-		$admin_settings['paypal_sandbox_email'] = array(
532
+        $admin_settings['paypal_sandbox_email'] = array(
533 533
             'type'  => 'text',
534
-			'class' => 'sandbox-auth-data',
534
+            'class' => 'sandbox-auth-data',
535 535
             'id'    => 'paypal_sandbox_email',
536 536
             'name'  => __( 'Sandbox Email Address', 'invoicing' ),
537 537
             'desc'  => __( 'The email address of your sandbox PayPal account.', 'invoicing' ),
538
-			'std'   => wpinv_get_option( 'paypal_email', '' ),
538
+            'std'   => wpinv_get_option( 'paypal_email', '' ),
539
+        );
540
+
541
+        // Client ID and secret.
542
+        $admin_settings['paypal_client_id'] = array(
543
+            'type'  => 'text',
544
+            'class' => 'live-auth-data',
545
+            'id'    => 'paypal_client_id',
546
+            'name'  => __( 'Live Client ID', 'invoicing' ),
547
+            'desc'  => __( 'The client ID of your PayPal account. You can retrieve this from your PayPal developer account.', 'invoicing' ),
548
+        );
549
+
550
+        $admin_settings['paypal_sandbox_client_id'] = array(
551
+            'type'  => 'text',
552
+            'class' => 'sandbox-auth-data',
553
+            'id'    => 'paypal_sandbox_client_id',
554
+            'name'  => __( 'Sandbox Client ID', 'invoicing' ),
555
+            'desc'  => __( 'The client ID of your sandbox PayPal account. You can retrieve this from your PayPal developer account.', 'invoicing' ),
556
+            'std'   => wpinv_get_option( 'paypal_client_id', '' ),
539 557
         );
540 558
 
541
-		// Client ID and secret.
542
-		$admin_settings['paypal_client_id'] = array(
543
-			'type'  => 'text',
544
-			'class' => 'live-auth-data',
545
-			'id'    => 'paypal_client_id',
546
-			'name'  => __( 'Live Client ID', 'invoicing' ),
547
-			'desc'  => __( 'The client ID of your PayPal account. You can retrieve this from your PayPal developer account.', 'invoicing' ),
548
-		);
549
-
550
-		$admin_settings['paypal_sandbox_client_id'] = array(
551
-			'type'  => 'text',
552
-			'class' => 'sandbox-auth-data',
553
-			'id'    => 'paypal_sandbox_client_id',
554
-			'name'  => __( 'Sandbox Client ID', 'invoicing' ),
555
-			'desc'  => __( 'The client ID of your sandbox PayPal account. You can retrieve this from your PayPal developer account.', 'invoicing' ),
556
-			'std'   => wpinv_get_option( 'paypal_client_id', '' ),
557
-		);
558
-
559
-		$admin_settings['paypal_secret'] = array(
560
-			'type'  => 'text',
561
-			'class' => 'live-auth-data',
562
-			'id'    => 'paypal_secret',
563
-			'name'  => __( 'Live Secret', 'invoicing' ),
564
-			'desc'  => __( 'The secret of your PayPal account. You can retrieve this from your PayPal developer account.', 'invoicing' ),
565
-		);
566
-
567
-		$admin_settings['paypal_sandbox_secret'] = array(
568
-			'type'  => 'text',
569
-			'class' => 'sandbox-auth-data',
570
-			'id'    => 'paypal_sandbox_secret',
571
-			'name'  => __( 'Sandbox Secret', 'invoicing' ),
572
-			'desc'  => __( 'The secret of your sandbox PayPal account. You can retrieve this from your PayPal developer account.', 'invoicing' ),
573
-		);
559
+        $admin_settings['paypal_secret'] = array(
560
+            'type'  => 'text',
561
+            'class' => 'live-auth-data',
562
+            'id'    => 'paypal_secret',
563
+            'name'  => __( 'Live Secret', 'invoicing' ),
564
+            'desc'  => __( 'The secret of your PayPal account. You can retrieve this from your PayPal developer account.', 'invoicing' ),
565
+        );
566
+
567
+        $admin_settings['paypal_sandbox_secret'] = array(
568
+            'type'  => 'text',
569
+            'class' => 'sandbox-auth-data',
570
+            'id'    => 'paypal_sandbox_secret',
571
+            'name'  => __( 'Sandbox Secret', 'invoicing' ),
572
+            'desc'  => __( 'The secret of your sandbox PayPal account. You can retrieve this from your PayPal developer account.', 'invoicing' ),
573
+        );
574 574
 
575 575
         $admin_settings['paypal_ipn_url'] = array(
576 576
             'type'     => 'ipn_url',
@@ -581,57 +581,57 @@  discard block
 block discarded – undo
581 581
             'readonly' => true,
582 582
         );
583 583
 
584
-		return $admin_settings;
585
-	}
586
-
587
-	/**
588
-	 * Retrieves the URL to cancel a subscription.
589
-	 *
590
-	 * @param string $url
591
-	 * @param WPInv_Subscription $subscription
592
-	 */
593
-	public function filter_cancel_subscription_url( $url, $subscription ) {
594
-
595
-		if ( $this->id !== $subscription->get_gateway() ) {
596
-			return $url;
597
-		}
598
-
599
-		// Get the PayPal profile ID.
600
-		$profile_id = $subscription->get_profile_id();
601
-
602
-		// Bail if no profile ID.
603
-		if ( empty( $profile_id ) ) {
604
-			return $url;
605
-		}
606
-
607
-		$cancel_url = 'https://www.paypal.com/myaccount/autopay/connect/%s/cancel';
608
-		if ( $this->is_sandbox( $subscription->get_parent_payment() ) ) {
609
-			$cancel_url = 'https://www.sandbox.paypal.com/myaccount/autopay/connect/%s/cancel';
610
-		}
611
-
612
-		return sprintf( $cancel_url, $profile_id );
613
-	}
614
-
615
-	/**
616
-	 * Retrieves the PayPal connect URL when using the setup wizzard.
617
-	 *
618
-	 *
584
+        return $admin_settings;
585
+    }
586
+
587
+    /**
588
+     * Retrieves the URL to cancel a subscription.
589
+     *
590
+     * @param string $url
591
+     * @param WPInv_Subscription $subscription
592
+     */
593
+    public function filter_cancel_subscription_url( $url, $subscription ) {
594
+
595
+        if ( $this->id !== $subscription->get_gateway() ) {
596
+            return $url;
597
+        }
598
+
599
+        // Get the PayPal profile ID.
600
+        $profile_id = $subscription->get_profile_id();
601
+
602
+        // Bail if no profile ID.
603
+        if ( empty( $profile_id ) ) {
604
+            return $url;
605
+        }
606
+
607
+        $cancel_url = 'https://www.paypal.com/myaccount/autopay/connect/%s/cancel';
608
+        if ( $this->is_sandbox( $subscription->get_parent_payment() ) ) {
609
+            $cancel_url = 'https://www.sandbox.paypal.com/myaccount/autopay/connect/%s/cancel';
610
+        }
611
+
612
+        return sprintf( $cancel_url, $profile_id );
613
+    }
614
+
615
+    /**
616
+     * Retrieves the PayPal connect URL when using the setup wizzard.
617
+     *
618
+     *
619 619
      * @param array $data
620 620
      * @return string
621
-	 */
622
-	public static function maybe_get_connect_url( $url = '', $data = array() ) {
623
-		return self::get_connect_url( false, urldecode( $data['redirect'] ) );
624
-	}
625
-
626
-	/**
627
-	 * Retrieves the PayPal connect URL.
628
-	 *
629
-	 *
621
+     */
622
+    public static function maybe_get_connect_url( $url = '', $data = array() ) {
623
+        return self::get_connect_url( false, urldecode( $data['redirect'] ) );
624
+    }
625
+
626
+    /**
627
+     * Retrieves the PayPal connect URL.
628
+     *
629
+     *
630 630
      * @param bool $is_sandbox
631
-	 * @param string $redirect
631
+     * @param string $redirect
632 632
      * @return string
633
-	 */
634
-	public static function get_connect_url( $is_sandbox, $redirect = '' ) {
633
+     */
634
+    public static function get_connect_url( $is_sandbox, $redirect = '' ) {
635 635
 
636 636
         $redirect_url = add_query_arg(
637 637
             array(
@@ -641,7 +641,7 @@  discard block
 block discarded – undo
641 641
                 'tab'                  => 'gateways',
642 642
                 'section'              => 'paypal',
643 643
                 'getpaid-nonce'        => wp_create_nonce( 'getpaid-nonce' ),
644
-				'redirect'             => urlencode( $redirect ),
644
+                'redirect'             => urlencode( $redirect ),
645 645
             ),
646 646
             admin_url( 'admin.php' )
647 647
         );
@@ -656,12 +656,12 @@  discard block
 block discarded – undo
656 656
 
657 657
     }
658 658
 
659
-	/**
660
-	 * Generates settings page js.
661
-	 *
659
+    /**
660
+     * Generates settings page js.
661
+     *
662 662
      * @return void
663
-	 */
664
-	public static function display_connect_buttons() {
663
+     */
664
+    public static function display_connect_buttons() {
665 665
 
666 666
         ?>
667 667
 			<div class="wpinv-paypal-connect-live">
@@ -703,70 +703,70 @@  discard block
 block discarded – undo
703 703
         <?php
704 704
     }
705 705
 
706
-	/**
707
-	 * Connects to PayPal.
708
-	 *
709
-	 * @param array $data Connection data.
710
-	 * @return void
711
-	 */
712
-	public function connect_paypal( $data ) {
713
-
714
-		$sandbox      = $this->is_sandbox();
715
-		$data         = wp_unslash( $data );
716
-		$access_token = empty( $data['access_token'] ) ? '' : sanitize_text_field( $data['access_token'] );
717
-
718
-		if ( isset( $data['live_mode'] ) ) {
719
-			$sandbox = empty( $data['live_mode'] );
720
-		}
721
-
722
-		wpinv_update_option( 'paypal_sandbox', (int) $sandbox );
723
-		wpinv_update_option( 'paypal_active', 1 );
724
-
725
-		if ( ! empty( $data['error_description'] ) ) {
726
-			getpaid_admin()->show_error( wp_kses_post( urldecode( $data['error_description'] ) ) );
727
-		} else {
728
-
729
-			// Retrieve the user info.
730
-			$user_info = wp_remote_get(
731
-				! $sandbox ? 'https://api-m.paypal.com/v1/identity/oauth2/userinfo?schema=paypalv1.1' : 'https://api-m.sandbox.paypal.com/v1/identity/oauth2/userinfo?schema=paypalv1.1',
732
-				array(
733
-
734
-					'headers' => array(
735
-						'Authorization' => 'Bearer ' . $access_token,
736
-						'Content-type'  => 'application/json',
737
-					),
738
-
739
-				)
740
-			);
741
-
742
-			if ( is_wp_error( $user_info ) ) {
743
-				getpaid_admin()->show_error( wp_kses_post( $user_info->get_error_message() ) );
744
-			} else {
745
-
746
-				// Create application.
747
-				$user_info = json_decode( wp_remote_retrieve_body( $user_info ) );
748
-
749
-				if ( $sandbox ) {
750
-					wpinv_update_option( 'paypal_sandbox_email', sanitize_email( $user_info->emails[0]->value ) );
751
-					wpinv_update_option( 'paypal_sandbox_refresh_token', sanitize_text_field( urldecode( $data['refresh_token'] ) ) );
752
-					set_transient( 'getpaid_paypal_sandbox_access_token', sanitize_text_field( urldecode( $data['access_token'] ) ), (int) $data['expires_in'] );
753
-					getpaid_admin()->show_success( __( 'Successfully connected your PayPal sandbox account', 'invoicing' ) );
754
-				} else {
755
-					wpinv_update_option( 'paypal_email', sanitize_email( $user_info->emails[0]->value ) );
756
-					wpinv_update_option( 'paypal_refresh_token', sanitize_text_field( urldecode( $data['refresh_token'] ) ) );
757
-					set_transient( 'getpaid_paypal_access_token', sanitize_text_field( urldecode( $data['access_token'] ) ), (int) $data['expires_in'] );
758
-					getpaid_admin()->show_success( __( 'Successfully connected your PayPal account', 'invoicing' ) );
759
-				}
706
+    /**
707
+     * Connects to PayPal.
708
+     *
709
+     * @param array $data Connection data.
710
+     * @return void
711
+     */
712
+    public function connect_paypal( $data ) {
713
+
714
+        $sandbox      = $this->is_sandbox();
715
+        $data         = wp_unslash( $data );
716
+        $access_token = empty( $data['access_token'] ) ? '' : sanitize_text_field( $data['access_token'] );
717
+
718
+        if ( isset( $data['live_mode'] ) ) {
719
+            $sandbox = empty( $data['live_mode'] );
720
+        }
721
+
722
+        wpinv_update_option( 'paypal_sandbox', (int) $sandbox );
723
+        wpinv_update_option( 'paypal_active', 1 );
724
+
725
+        if ( ! empty( $data['error_description'] ) ) {
726
+            getpaid_admin()->show_error( wp_kses_post( urldecode( $data['error_description'] ) ) );
727
+        } else {
728
+
729
+            // Retrieve the user info.
730
+            $user_info = wp_remote_get(
731
+                ! $sandbox ? 'https://api-m.paypal.com/v1/identity/oauth2/userinfo?schema=paypalv1.1' : 'https://api-m.sandbox.paypal.com/v1/identity/oauth2/userinfo?schema=paypalv1.1',
732
+                array(
733
+
734
+                    'headers' => array(
735
+                        'Authorization' => 'Bearer ' . $access_token,
736
+                        'Content-type'  => 'application/json',
737
+                    ),
738
+
739
+                )
740
+            );
741
+
742
+            if ( is_wp_error( $user_info ) ) {
743
+                getpaid_admin()->show_error( wp_kses_post( $user_info->get_error_message() ) );
744
+            } else {
745
+
746
+                // Create application.
747
+                $user_info = json_decode( wp_remote_retrieve_body( $user_info ) );
748
+
749
+                if ( $sandbox ) {
750
+                    wpinv_update_option( 'paypal_sandbox_email', sanitize_email( $user_info->emails[0]->value ) );
751
+                    wpinv_update_option( 'paypal_sandbox_refresh_token', sanitize_text_field( urldecode( $data['refresh_token'] ) ) );
752
+                    set_transient( 'getpaid_paypal_sandbox_access_token', sanitize_text_field( urldecode( $data['access_token'] ) ), (int) $data['expires_in'] );
753
+                    getpaid_admin()->show_success( __( 'Successfully connected your PayPal sandbox account', 'invoicing' ) );
754
+                } else {
755
+                    wpinv_update_option( 'paypal_email', sanitize_email( $user_info->emails[0]->value ) );
756
+                    wpinv_update_option( 'paypal_refresh_token', sanitize_text_field( urldecode( $data['refresh_token'] ) ) );
757
+                    set_transient( 'getpaid_paypal_access_token', sanitize_text_field( urldecode( $data['access_token'] ) ), (int) $data['expires_in'] );
758
+                    getpaid_admin()->show_success( __( 'Successfully connected your PayPal account', 'invoicing' ) );
759
+                }
760 760
 }
761 761
 }
762 762
 
763
-		$redirect = empty( $data['redirect'] ) ? admin_url( 'admin.php?page=wpinv-settings&tab=gateways&section=paypal' ) : urldecode( $data['redirect'] );
763
+        $redirect = empty( $data['redirect'] ) ? admin_url( 'admin.php?page=wpinv-settings&tab=gateways&section=paypal' ) : urldecode( $data['redirect'] );
764 764
 
765
-		if ( isset( $data['step'] ) ) {
766
-			$redirect = add_query_arg( 'step', $data['step'], $redirect );
767
-		}
768
-		wp_redirect( $redirect );
769
-		exit;
770
-	}
765
+        if ( isset( $data['step'] ) ) {
766
+            $redirect = add_query_arg( 'step', $data['step'], $redirect );
767
+        }
768
+        wp_redirect( $redirect );
769
+        exit;
770
+    }
771 771
 
772 772
 }
Please login to merge, or discard this patch.
Spacing   +160 added lines, -160 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
4 4
  *
5 5
  */
6 6
 
7
-defined( 'ABSPATH' ) || exit;
7
+defined('ABSPATH') || exit;
8 8
 
9 9
 /**
10 10
  * Paypal Payment Gateway class.
@@ -24,7 +24,7 @@  discard block
 block discarded – undo
24 24
 	 *
25 25
 	 * @var array
26 26
 	 */
27
-    protected $supports = array( 'subscription', 'sandbox', 'single_subscription_group' );
27
+    protected $supports = array('subscription', 'sandbox', 'single_subscription_group');
28 28
 
29 29
     /**
30 30
 	 * Payment method order.
@@ -59,7 +59,7 @@  discard block
 block discarded – undo
59 59
 	 *
60 60
 	 * @var array
61 61
 	 */
62
-	public $currencies = array( 'AUD', 'BRL', 'CAD', 'MXN', 'NZD', 'HKD', 'SGD', 'USD', 'EUR', 'JPY', 'TRY', 'NOK', 'CZK', 'DKK', 'HUF', 'ILS', 'MYR', 'PHP', 'PLN', 'SEK', 'CHF', 'TWD', 'THB', 'GBP', 'RMB', 'RUB', 'INR' );
62
+	public $currencies = array('AUD', 'BRL', 'CAD', 'MXN', 'NZD', 'HKD', 'SGD', 'USD', 'EUR', 'JPY', 'TRY', 'NOK', 'CZK', 'DKK', 'HUF', 'ILS', 'MYR', 'PHP', 'PLN', 'SEK', 'CHF', 'TWD', 'THB', 'GBP', 'RMB', 'RUB', 'INR');
63 63
 
64 64
     /**
65 65
 	 * URL to view a transaction.
@@ -80,17 +80,17 @@  discard block
 block discarded – undo
80 80
 	 */
81 81
 	public function __construct() {
82 82
 
83
-        $this->title                = __( 'PayPal Standard', 'invoicing' );
84
-        $this->method_title         = __( 'PayPal Standard', 'invoicing' );
85
-        $this->checkout_button_text = __( 'Proceed to PayPal', 'invoicing' );
86
-        $this->notify_url           = wpinv_get_ipn_url( $this->id );
87
-
88
-		add_filter( 'wpinv_subscription_cancel_url', array( $this, 'filter_cancel_subscription_url' ), 10, 2 );
89
-		add_filter( 'getpaid_paypal_args', array( $this, 'process_subscription' ), 10, 2 );
90
-        add_filter( 'getpaid_paypal_sandbox_notice', array( $this, 'sandbox_notice' ) );
91
-		add_filter( 'getpaid_get_paypal_connect_url', array( $this, 'maybe_get_connect_url' ), 10, 2 );
92
-		add_action( 'getpaid_authenticated_admin_action_connect_paypal', array( $this, 'connect_paypal' ) );
93
-		add_action( 'wpinv_paypal_connect', array( $this, 'display_connect_buttons' ) );
83
+        $this->title                = __('PayPal Standard', 'invoicing');
84
+        $this->method_title         = __('PayPal Standard', 'invoicing');
85
+        $this->checkout_button_text = __('Proceed to PayPal', 'invoicing');
86
+        $this->notify_url           = wpinv_get_ipn_url($this->id);
87
+
88
+		add_filter('wpinv_subscription_cancel_url', array($this, 'filter_cancel_subscription_url'), 10, 2);
89
+		add_filter('getpaid_paypal_args', array($this, 'process_subscription'), 10, 2);
90
+        add_filter('getpaid_paypal_sandbox_notice', array($this, 'sandbox_notice'));
91
+		add_filter('getpaid_get_paypal_connect_url', array($this, 'maybe_get_connect_url'), 10, 2);
92
+		add_action('getpaid_authenticated_admin_action_connect_paypal', array($this, 'connect_paypal'));
93
+		add_action('wpinv_paypal_connect', array($this, 'display_connect_buttons'));
94 94
 		parent::__construct();
95 95
     }
96 96
 
@@ -103,16 +103,16 @@  discard block
 block discarded – undo
103 103
 	 * @param GetPaid_Payment_Form_Submission $submission Checkout submission.
104 104
 	 * @return array
105 105
 	 */
106
-	public function process_payment( $invoice, $submission_data, $submission ) {
106
+	public function process_payment($invoice, $submission_data, $submission) {
107 107
 
108 108
         // Get redirect url.
109
-        $paypal_redirect = $this->get_request_url( $invoice );
109
+        $paypal_redirect = $this->get_request_url($invoice);
110 110
 
111 111
         // Add a note about the request url.
112 112
         $invoice->add_note(
113 113
             sprintf(
114
-                __( 'Redirecting to PayPal: %s', 'invoicing' ),
115
-                esc_url( $paypal_redirect )
114
+                __('Redirecting to PayPal: %s', 'invoicing'),
115
+                esc_url($paypal_redirect)
116 116
             ),
117 117
             false,
118 118
             false,
@@ -120,7 +120,7 @@  discard block
 block discarded – undo
120 120
         );
121 121
 
122 122
         // Redirect to PayPal
123
-        wp_redirect( $paypal_redirect );
123
+        wp_redirect($paypal_redirect);
124 124
         exit;
125 125
 
126 126
     }
@@ -131,21 +131,21 @@  discard block
 block discarded – undo
131 131
 	 * @param  WPInv_Invoice $invoice Invoice object.
132 132
 	 * @return string
133 133
 	 */
134
-	public function get_request_url( $invoice ) {
134
+	public function get_request_url($invoice) {
135 135
 
136 136
         // Endpoint for this request
137
-		$this->endpoint    = $this->is_sandbox( $invoice ) ? 'https://www.sandbox.paypal.com/cgi-bin/webscr?test_ipn=1&' : 'https://www.paypal.com/cgi-bin/webscr?';
137
+		$this->endpoint = $this->is_sandbox($invoice) ? 'https://www.sandbox.paypal.com/cgi-bin/webscr?test_ipn=1&' : 'https://www.paypal.com/cgi-bin/webscr?';
138 138
 
139 139
         // Retrieve paypal args.
140
-        $paypal_args       = map_deep( $this->get_paypal_args( $invoice ), 'urlencode' );
140
+        $paypal_args = map_deep($this->get_paypal_args($invoice), 'urlencode');
141 141
 
142
-        if ( $invoice->is_recurring() ) {
142
+        if ($invoice->is_recurring()) {
143 143
             $paypal_args['bn'] = 'GetPaid_Subscribe_WPS_US';
144 144
         } else {
145 145
             $paypal_args['bn'] = 'GetPaid_ShoppingCart_WPS_US';
146 146
         }
147 147
 
148
-        return add_query_arg( $paypal_args, $this->endpoint );
148
+        return add_query_arg($paypal_args, $this->endpoint);
149 149
 
150 150
 	}
151 151
 
@@ -155,25 +155,25 @@  discard block
 block discarded – undo
155 155
 	 * @param  WPInv_Invoice $invoice Invoice object.
156 156
 	 * @return array
157 157
 	 */
158
-	protected function get_paypal_args( $invoice ) {
158
+	protected function get_paypal_args($invoice) {
159 159
 
160 160
         // Whether or not to send the line items as one item.
161
-		$force_one_line_item = apply_filters( 'getpaid_paypal_force_one_line_item', true, $invoice );
161
+		$force_one_line_item = apply_filters('getpaid_paypal_force_one_line_item', true, $invoice);
162 162
 
163
-		if ( $invoice->is_recurring() || ( wpinv_use_taxes() && wpinv_prices_include_tax() ) ) {
163
+		if ($invoice->is_recurring() || (wpinv_use_taxes() && wpinv_prices_include_tax())) {
164 164
 			$force_one_line_item = true;
165 165
 		}
166 166
 
167 167
 		$paypal_args = apply_filters(
168 168
 			'getpaid_paypal_args',
169 169
 			array_merge(
170
-				$this->get_transaction_args( $invoice ),
171
-				$this->get_line_item_args( $invoice, $force_one_line_item )
170
+				$this->get_transaction_args($invoice),
171
+				$this->get_line_item_args($invoice, $force_one_line_item)
172 172
 			),
173 173
 			$invoice
174 174
 		);
175 175
 
176
-		return $this->fix_request_length( $invoice, $paypal_args );
176
+		return $this->fix_request_length($invoice, $paypal_args);
177 177
     }
178 178
 
179 179
     /**
@@ -182,9 +182,9 @@  discard block
 block discarded – undo
182 182
 	 * @param WPInv_Invoice $invoice Invoice object.
183 183
 	 * @return array
184 184
 	 */
185
-	protected function get_transaction_args( $invoice ) {
185
+	protected function get_transaction_args($invoice) {
186 186
 
187
-		$email = $this->is_sandbox( $invoice ) ? wpinv_get_option( 'paypal_sandbox_email', wpinv_get_option( 'paypal_email', '' ) ) : wpinv_get_option( 'paypal_email', '' );
187
+		$email = $this->is_sandbox($invoice) ? wpinv_get_option('paypal_sandbox_email', wpinv_get_option('paypal_email', '')) : wpinv_get_option('paypal_email', '');
188 188
 		return array(
189 189
             'cmd'           => '_cart',
190 190
             'business'      => $email,
@@ -195,16 +195,16 @@  discard block
 block discarded – undo
195 195
             'rm'            => is_ssl() ? 2 : 1,
196 196
             'upload'        => 1,
197 197
             'currency_code' => $invoice->get_currency(), // https://developer.paypal.com/docs/nvp-soap-api/currency-codes/#paypal
198
-            'return'        => esc_url_raw( $this->get_return_url( $invoice ) ),
199
-            'cancel_return' => esc_url_raw( $invoice->get_checkout_payment_url() ),
200
-            'notify_url'    => getpaid_limit_length( $this->notify_url, 255 ),
201
-            'invoice'       => getpaid_limit_length( $invoice->get_number(), 127 ),
198
+            'return'        => esc_url_raw($this->get_return_url($invoice)),
199
+            'cancel_return' => esc_url_raw($invoice->get_checkout_payment_url()),
200
+            'notify_url'    => getpaid_limit_length($this->notify_url, 255),
201
+            'invoice'       => getpaid_limit_length($invoice->get_number(), 127),
202 202
             'custom'        => $invoice->get_id(),
203
-            'first_name'    => getpaid_limit_length( $invoice->get_first_name(), 32 ),
204
-            'last_name'     => getpaid_limit_length( $invoice->get_last_name(), 64 ),
205
-            'country'       => getpaid_limit_length( $invoice->get_country(), 2 ),
206
-            'email'         => getpaid_limit_length( $invoice->get_email(), 127 ),
207
-            'cbt'           => get_bloginfo( 'name' ),
203
+            'first_name'    => getpaid_limit_length($invoice->get_first_name(), 32),
204
+            'last_name'     => getpaid_limit_length($invoice->get_last_name(), 64),
205
+            'country'       => getpaid_limit_length($invoice->get_country(), 2),
206
+            'email'         => getpaid_limit_length($invoice->get_email(), 127),
207
+            'cbt'           => get_bloginfo('name'),
208 208
         );
209 209
 
210 210
     }
@@ -216,30 +216,30 @@  discard block
 block discarded – undo
216 216
 	 * @param  bool     $force_one_line_item Create only one item for this invoice.
217 217
 	 * @return array
218 218
 	 */
219
-	protected function get_line_item_args( $invoice, $force_one_line_item = false ) {
219
+	protected function get_line_item_args($invoice, $force_one_line_item = false) {
220 220
 
221 221
         // Maybe send invoice as a single item.
222
-		if ( $force_one_line_item ) {
223
-            return $this->get_line_item_args_single_item( $invoice );
222
+		if ($force_one_line_item) {
223
+            return $this->get_line_item_args_single_item($invoice);
224 224
         }
225 225
 
226 226
         // Send each line item individually.
227 227
         $line_item_args = array();
228 228
 
229 229
         // Prepare line items.
230
-        $this->prepare_line_items( $invoice );
230
+        $this->prepare_line_items($invoice);
231 231
 
232 232
         // Add taxes to the cart
233
-        if ( wpinv_use_taxes() && $invoice->is_taxable() ) {
234
-            $line_item_args['tax_cart'] = wpinv_sanitize_amount( (float) $invoice->get_total_tax(), 2 );
233
+        if (wpinv_use_taxes() && $invoice->is_taxable()) {
234
+            $line_item_args['tax_cart'] = wpinv_sanitize_amount((float) $invoice->get_total_tax(), 2);
235 235
         }
236 236
 
237 237
         // Add discount.
238
-        if ( $invoice->get_total_discount() > 0 ) {
239
-            $line_item_args['discount_amount_cart'] = wpinv_sanitize_amount( (float) $invoice->get_total_discount(), 2 );
238
+        if ($invoice->get_total_discount() > 0) {
239
+            $line_item_args['discount_amount_cart'] = wpinv_sanitize_amount((float) $invoice->get_total_discount(), 2);
240 240
         }
241 241
 
242
-		return array_merge( $line_item_args, $this->get_line_items() );
242
+		return array_merge($line_item_args, $this->get_line_items());
243 243
 
244 244
     }
245 245
 
@@ -249,11 +249,11 @@  discard block
 block discarded – undo
249 249
 	 * @param  WPInv_Invoice $invoice Invoice object.
250 250
 	 * @return array
251 251
 	 */
252
-	protected function get_line_item_args_single_item( $invoice ) {
252
+	protected function get_line_item_args_single_item($invoice) {
253 253
 		$this->delete_line_items();
254 254
 
255
-        $item_name = sprintf( __( 'Invoice #%s', 'invoicing' ), $invoice->get_number() );
256
-		$this->add_line_item( $item_name, 1, wpinv_round_amount( (float) $invoice->get_total(), 2, true ), $invoice->get_id() );
255
+        $item_name = sprintf(__('Invoice #%s', 'invoicing'), $invoice->get_number());
256
+		$this->add_line_item($item_name, 1, wpinv_round_amount((float) $invoice->get_total(), 2, true), $invoice->get_id());
257 257
 
258 258
 		return $this->get_line_items();
259 259
     }
@@ -277,19 +277,19 @@  discard block
 block discarded – undo
277 277
 	 *
278 278
 	 * @param  WPInv_Invoice $invoice Invoice object.
279 279
 	 */
280
-	protected function prepare_line_items( $invoice ) {
280
+	protected function prepare_line_items($invoice) {
281 281
 		$this->delete_line_items();
282 282
 
283 283
 		// Items.
284
-		foreach ( $invoice->get_items() as $item ) {
284
+		foreach ($invoice->get_items() as $item) {
285 285
 			$amount   = $item->get_price();
286 286
 			$quantity = $invoice->get_template() == 'amount' ? 1 : $item->get_quantity();
287
-			$this->add_line_item( $item->get_raw_name(), $quantity, $amount, $item->get_id() );
287
+			$this->add_line_item($item->get_raw_name(), $quantity, $amount, $item->get_id());
288 288
         }
289 289
 
290 290
         // Fees.
291
-		foreach ( $invoice->get_fees() as $fee => $data ) {
292
-            $this->add_line_item( $fee, 1, wpinv_sanitize_amount( $data['initial_fee'] ) );
291
+		foreach ($invoice->get_fees() as $fee => $data) {
292
+            $this->add_line_item($fee, 1, wpinv_sanitize_amount($data['initial_fee']));
293 293
         }
294 294
 
295 295
     }
@@ -302,15 +302,15 @@  discard block
 block discarded – undo
302 302
 	 * @param  float  $amount Amount.
303 303
 	 * @param  string $item_number Item number.
304 304
 	 */
305
-	protected function add_line_item( $item_name, $quantity = 1, $amount = 0.0, $item_number = '' ) {
306
-		$index = ( count( $this->line_items ) / 4 ) + 1;
305
+	protected function add_line_item($item_name, $quantity = 1, $amount = 0.0, $item_number = '') {
306
+		$index = (count($this->line_items) / 4) + 1;
307 307
 
308 308
 		$item = apply_filters(
309 309
 			'getpaid_paypal_line_item',
310 310
 			array(
311
-				'item_name'   => html_entity_decode( getpaid_limit_length( $item_name ? wp_strip_all_tags( $item_name ) : __( 'Item', 'invoicing' ), 127 ), ENT_NOQUOTES, 'UTF-8' ),
311
+				'item_name'   => html_entity_decode(getpaid_limit_length($item_name ? wp_strip_all_tags($item_name) : __('Item', 'invoicing'), 127), ENT_NOQUOTES, 'UTF-8'),
312 312
 				'quantity'    => (float) $quantity,
313
-				'amount'      => wpinv_sanitize_amount( (float) $amount, 2 ),
313
+				'amount'      => wpinv_sanitize_amount((float) $amount, 2),
314 314
 				'item_number' => $item_number,
315 315
 			),
316 316
 			$item_name,
@@ -319,12 +319,12 @@  discard block
 block discarded – undo
319 319
 			$item_number
320 320
 		);
321 321
 
322
-		$this->line_items[ 'item_name_' . $index ]   = getpaid_limit_length( $item['item_name'], 127 );
323
-        $this->line_items[ 'quantity_' . $index ]    = $item['quantity'];
322
+		$this->line_items['item_name_' . $index] = getpaid_limit_length($item['item_name'], 127);
323
+        $this->line_items['quantity_' . $index] = $item['quantity'];
324 324
 
325 325
         // The price or amount of the product, service, or contribution, not including shipping, handling, or tax.
326
-		$this->line_items[ 'amount_' . $index ]      = $item['amount'] * $item['quantity'];
327
-		$this->line_items[ 'item_number_' . $index ] = getpaid_limit_length( $item['item_number'], 127 );
326
+		$this->line_items['amount_' . $index]      = $item['amount'] * $item['quantity'];
327
+		$this->line_items['item_number_' . $index] = getpaid_limit_length($item['item_number'], 127);
328 328
     }
329 329
 
330 330
     /**
@@ -336,19 +336,19 @@  discard block
 block discarded – undo
336 336
 	 * @param array    $paypal_args Arguments sent to Paypal in the request.
337 337
 	 * @return array
338 338
 	 */
339
-	protected function fix_request_length( $invoice, $paypal_args ) {
339
+	protected function fix_request_length($invoice, $paypal_args) {
340 340
 		$max_paypal_length = 2083;
341
-		$query_candidate   = http_build_query( $paypal_args, '', '&' );
341
+		$query_candidate   = http_build_query($paypal_args, '', '&');
342 342
 
343
-		if ( strlen( $this->endpoint . $query_candidate ) <= $max_paypal_length ) {
343
+		if (strlen($this->endpoint . $query_candidate) <= $max_paypal_length) {
344 344
 			return $paypal_args;
345 345
 		}
346 346
 
347 347
 		return apply_filters(
348 348
 			'getpaid_paypal_args',
349 349
 			array_merge(
350
-				$this->get_transaction_args( $invoice ),
351
-				$this->get_line_item_args( $invoice, true )
350
+				$this->get_transaction_args($invoice),
351
+				$this->get_line_item_args($invoice, true)
352 352
 			),
353 353
 			$invoice
354 354
 		);
@@ -361,10 +361,10 @@  discard block
 block discarded – undo
361 361
 	 * @param  array $paypal_args PayPal args.
362 362
 	 * @param  WPInv_Invoice    $invoice Invoice object.
363 363
 	 */
364
-	public function process_subscription( $paypal_args, $invoice ) {
364
+	public function process_subscription($paypal_args, $invoice) {
365 365
 
366 366
         // Make sure this is a subscription.
367
-        if ( ! $invoice->is_recurring() || ! $subscription = getpaid_get_invoice_subscription( $invoice ) ) {
367
+        if (!$invoice->is_recurring() || !$subscription = getpaid_get_invoice_subscription($invoice)) {
368 368
             return $paypal_args;
369 369
         }
370 370
 
@@ -372,23 +372,23 @@  discard block
 block discarded – undo
372 372
         $paypal_args['cmd'] = '_xclick-subscriptions';
373 373
 
374 374
         // Subscription name.
375
-        $paypal_args['item_name'] = sprintf( __( 'Invoice #%s', 'invoicing' ), $invoice->get_number() );
375
+        $paypal_args['item_name'] = sprintf(__('Invoice #%s', 'invoicing'), $invoice->get_number());
376 376
 
377 377
         // Get subscription args.
378
-        $period                 = strtoupper( substr( $subscription->get_period(), 0, 1 ) );
378
+        $period                 = strtoupper(substr($subscription->get_period(), 0, 1));
379 379
         $interval               = (int) $subscription->get_frequency();
380 380
         $bill_times             = (int) $subscription->get_bill_times();
381
-        $initial_amount         = (float) wpinv_sanitize_amount( $invoice->get_initial_total(), 2 );
382
-        $recurring_amount       = (float) wpinv_sanitize_amount( $invoice->get_recurring_total(), 2 );
383
-        $subscription_item      = $invoice->get_recurring( true );
381
+        $initial_amount         = (float) wpinv_sanitize_amount($invoice->get_initial_total(), 2);
382
+        $recurring_amount       = (float) wpinv_sanitize_amount($invoice->get_recurring_total(), 2);
383
+        $subscription_item      = $invoice->get_recurring(true);
384 384
 
385 385
 		// Convert 365 days to 1 year.
386
-		if ( 'D' == $period && 365 == $interval ) {
386
+		if ('D' == $period && 365 == $interval) {
387 387
 			$period = 'Y';
388 388
 			$interval = 1;
389 389
 		}
390 390
 
391
-        if ( $subscription_item->has_free_trial() ) {
391
+        if ($subscription_item->has_free_trial()) {
392 392
 
393 393
             $paypal_args['a1'] = 0 == $initial_amount ? 0 : $initial_amount;
394 394
 
@@ -398,28 +398,28 @@  discard block
 block discarded – undo
398 398
 			// Trial period.
399 399
 			$paypal_args['t1'] = $subscription_item->get_trial_period();
400 400
 
401
-        } elseif ( $initial_amount != $recurring_amount ) {
401
+        } elseif ($initial_amount != $recurring_amount) {
402 402
 
403 403
             // No trial period, but initial amount includes a sign-up fee and/or other items, so charge it as a separate period.
404 404
 
405
-            if ( 1 == $bill_times ) {
405
+            if (1 == $bill_times) {
406 406
                 $param_number = 3;
407 407
             } else {
408 408
                 $param_number = 1;
409 409
             }
410 410
 
411
-            $paypal_args[ 'a' . $param_number ] = $initial_amount ? $initial_amount : 0;
411
+            $paypal_args['a' . $param_number] = $initial_amount ? $initial_amount : 0;
412 412
 
413 413
             // Sign Up interval
414
-            $paypal_args[ 'p' . $param_number ] = $interval;
414
+            $paypal_args['p' . $param_number] = $interval;
415 415
 
416 416
             // Sign Up unit of duration
417
-            $paypal_args[ 't' . $param_number ] = $period;
417
+            $paypal_args['t' . $param_number] = $period;
418 418
 
419 419
         }
420 420
 
421 421
         // We have a recurring payment
422
-		if ( ! isset( $param_number ) || 1 == $param_number ) {
422
+		if (!isset($param_number) || 1 == $param_number) {
423 423
 
424 424
 			// Subscription price
425 425
 			$paypal_args['a3'] = $recurring_amount;
@@ -433,7 +433,7 @@  discard block
 block discarded – undo
433 433
         }
434 434
 
435 435
         // Recurring payments
436
-		if ( 1 == $bill_times || ( $initial_amount != $recurring_amount && ! $subscription_item->has_free_trial() && 2 == $bill_times ) ) {
436
+		if (1 == $bill_times || ($initial_amount != $recurring_amount && !$subscription_item->has_free_trial() && 2 == $bill_times)) {
437 437
 
438 438
 			// Non-recurring payments
439 439
 			$paypal_args['src'] = 0;
@@ -442,15 +442,15 @@  discard block
 block discarded – undo
442 442
 
443 443
 			$paypal_args['src'] = 1;
444 444
 
445
-			if ( $bill_times > 0 ) {
445
+			if ($bill_times > 0) {
446 446
 
447 447
 				// An initial period is being used to charge a sign-up fee
448
-				if ( $initial_amount != $recurring_amount && ! $subscription_item->has_free_trial() ) {
448
+				if ($initial_amount != $recurring_amount && !$subscription_item->has_free_trial()) {
449 449
 					$bill_times--;
450 450
 				}
451 451
 
452 452
                 // Make sure it's not over the max of 52
453
-                $paypal_args['srt'] = ( $bill_times <= 52 ? absint( $bill_times ) : 52 );
453
+                $paypal_args['srt'] = ($bill_times <= 52 ? absint($bill_times) : 52);
454 454
 
455 455
 			}
456 456
         }
@@ -459,10 +459,10 @@  discard block
 block discarded – undo
459 459
         $paypal_args['rm'] = 2;
460 460
 
461 461
         // Get rid of redudant items.
462
-        foreach ( array( 'item_name_1', 'quantity_1', 'amount_1', 'item_number_1' ) as $arg ) {
462
+        foreach (array('item_name_1', 'quantity_1', 'amount_1', 'item_number_1') as $arg) {
463 463
 
464
-            if ( isset( $paypal_args[ $arg ] ) ) {
465
-                unset( $paypal_args[ $arg ] );
464
+            if (isset($paypal_args[$arg])) {
465
+                unset($paypal_args[$arg]);
466 466
             }
467 467
 }
468 468
 
@@ -480,7 +480,7 @@  discard block
 block discarded – undo
480 480
 	 * @return void
481 481
 	 */
482 482
 	public function verify_ipn() {
483
-        new GetPaid_Paypal_Gateway_IPN_Handler( $this );
483
+        new GetPaid_Paypal_Gateway_IPN_Handler($this);
484 484
     }
485 485
 
486 486
     /**
@@ -489,7 +489,7 @@  discard block
 block discarded – undo
489 489
     public function sandbox_notice() {
490 490
 
491 491
         return sprintf(
492
-			__( 'SANDBOX ENABLED. You can use sandbox testing accounts only. See the %1$sPayPal Sandbox Testing Guide%2$s for more details.', 'invoicing' ),
492
+			__('SANDBOX ENABLED. You can use sandbox testing accounts only. See the %1$sPayPal Sandbox Testing Guide%2$s for more details.', 'invoicing'),
493 493
 			'<a href="https://developer.paypal.com/docs/classic/lifecycle/ug_sandbox/">',
494 494
 			'</a>'
495 495
 		);
@@ -501,41 +501,41 @@  discard block
 block discarded – undo
501 501
 	 *
502 502
 	 * @param array $admin_settings
503 503
 	 */
504
-	public function admin_settings( $admin_settings ) {
504
+	public function admin_settings($admin_settings) {
505 505
 
506 506
         $currencies = sprintf(
507
-            __( 'Supported Currencies: %s', 'invoicing' ),
508
-            implode( ', ', $this->currencies )
507
+            __('Supported Currencies: %s', 'invoicing'),
508
+            implode(', ', $this->currencies)
509 509
         );
510 510
 
511 511
         $admin_settings['paypal_active']['desc'] .= " ($currencies)";
512
-        $admin_settings['paypal_desc']['std']     = __( 'Pay via PayPal: you can pay with your credit card if you don\'t have a PayPal account.', 'invoicing' );
512
+        $admin_settings['paypal_desc']['std']     = __('Pay via PayPal: you can pay with your credit card if you don\'t have a PayPal account.', 'invoicing');
513 513
 
514 514
 		// Access tokens.
515
-		$live_email      = wpinv_get_option( 'paypal_email' );
516
-		$sandbox_email   = wpinv_get_option( 'paypal_sandbox_email' );
515
+		$live_email      = wpinv_get_option('paypal_email');
516
+		$sandbox_email   = wpinv_get_option('paypal_sandbox_email');
517 517
 
518 518
 		$admin_settings['paypal_connect'] = array(
519 519
 			'type' => 'hook',
520 520
 			'id'   => 'paypal_connect',
521
-			'name' => __( 'Connect to PayPal', 'invoicing' ),
521
+			'name' => __('Connect to PayPal', 'invoicing'),
522 522
 		);
523 523
 
524 524
         $admin_settings['paypal_email'] = array(
525 525
             'type'  => 'text',
526 526
 			'class' => 'live-auth-data',
527 527
             'id'    => 'paypal_email',
528
-            'name'  => __( 'Live Email Address', 'invoicing' ),
529
-            'desc'  => __( 'The email address of your PayPal account.', 'invoicing' ),
528
+            'name'  => __('Live Email Address', 'invoicing'),
529
+            'desc'  => __('The email address of your PayPal account.', 'invoicing'),
530 530
         );
531 531
 
532 532
 		$admin_settings['paypal_sandbox_email'] = array(
533 533
             'type'  => 'text',
534 534
 			'class' => 'sandbox-auth-data',
535 535
             'id'    => 'paypal_sandbox_email',
536
-            'name'  => __( 'Sandbox Email Address', 'invoicing' ),
537
-            'desc'  => __( 'The email address of your sandbox PayPal account.', 'invoicing' ),
538
-			'std'   => wpinv_get_option( 'paypal_email', '' ),
536
+            'name'  => __('Sandbox Email Address', 'invoicing'),
537
+            'desc'  => __('The email address of your sandbox PayPal account.', 'invoicing'),
538
+			'std'   => wpinv_get_option('paypal_email', ''),
539 539
         );
540 540
 
541 541
 		// Client ID and secret.
@@ -543,41 +543,41 @@  discard block
 block discarded – undo
543 543
 			'type'  => 'text',
544 544
 			'class' => 'live-auth-data',
545 545
 			'id'    => 'paypal_client_id',
546
-			'name'  => __( 'Live Client ID', 'invoicing' ),
547
-			'desc'  => __( 'The client ID of your PayPal account. You can retrieve this from your PayPal developer account.', 'invoicing' ),
546
+			'name'  => __('Live Client ID', 'invoicing'),
547
+			'desc'  => __('The client ID of your PayPal account. You can retrieve this from your PayPal developer account.', 'invoicing'),
548 548
 		);
549 549
 
550 550
 		$admin_settings['paypal_sandbox_client_id'] = array(
551 551
 			'type'  => 'text',
552 552
 			'class' => 'sandbox-auth-data',
553 553
 			'id'    => 'paypal_sandbox_client_id',
554
-			'name'  => __( 'Sandbox Client ID', 'invoicing' ),
555
-			'desc'  => __( 'The client ID of your sandbox PayPal account. You can retrieve this from your PayPal developer account.', 'invoicing' ),
556
-			'std'   => wpinv_get_option( 'paypal_client_id', '' ),
554
+			'name'  => __('Sandbox Client ID', 'invoicing'),
555
+			'desc'  => __('The client ID of your sandbox PayPal account. You can retrieve this from your PayPal developer account.', 'invoicing'),
556
+			'std'   => wpinv_get_option('paypal_client_id', ''),
557 557
 		);
558 558
 
559 559
 		$admin_settings['paypal_secret'] = array(
560 560
 			'type'  => 'text',
561 561
 			'class' => 'live-auth-data',
562 562
 			'id'    => 'paypal_secret',
563
-			'name'  => __( 'Live Secret', 'invoicing' ),
564
-			'desc'  => __( 'The secret of your PayPal account. You can retrieve this from your PayPal developer account.', 'invoicing' ),
563
+			'name'  => __('Live Secret', 'invoicing'),
564
+			'desc'  => __('The secret of your PayPal account. You can retrieve this from your PayPal developer account.', 'invoicing'),
565 565
 		);
566 566
 
567 567
 		$admin_settings['paypal_sandbox_secret'] = array(
568 568
 			'type'  => 'text',
569 569
 			'class' => 'sandbox-auth-data',
570 570
 			'id'    => 'paypal_sandbox_secret',
571
-			'name'  => __( 'Sandbox Secret', 'invoicing' ),
572
-			'desc'  => __( 'The secret of your sandbox PayPal account. You can retrieve this from your PayPal developer account.', 'invoicing' ),
571
+			'name'  => __('Sandbox Secret', 'invoicing'),
572
+			'desc'  => __('The secret of your sandbox PayPal account. You can retrieve this from your PayPal developer account.', 'invoicing'),
573 573
 		);
574 574
 
575 575
         $admin_settings['paypal_ipn_url'] = array(
576 576
             'type'     => 'ipn_url',
577 577
             'id'       => 'paypal_ipn_url',
578
-            'name'     => __( 'IPN Url', 'invoicing' ),
578
+            'name'     => __('IPN Url', 'invoicing'),
579 579
             'std'      => $this->notify_url,
580
-            'desc'     => __( "If you've not enabled IPNs in your paypal account, use the above URL to enable them.", 'invoicing' ) . ' <a href="https://developer.paypal.com/docs/api-basics/notifications/ipn/"><em>' . __( 'Learn more.', 'invoicing' ) . '</em></a>',
580
+            'desc'     => __("If you've not enabled IPNs in your paypal account, use the above URL to enable them.", 'invoicing') . ' <a href="https://developer.paypal.com/docs/api-basics/notifications/ipn/"><em>' . __('Learn more.', 'invoicing') . '</em></a>',
581 581
             'readonly' => true,
582 582
         );
583 583
 
@@ -590,9 +590,9 @@  discard block
 block discarded – undo
590 590
 	 * @param string $url
591 591
 	 * @param WPInv_Subscription $subscription
592 592
 	 */
593
-	public function filter_cancel_subscription_url( $url, $subscription ) {
593
+	public function filter_cancel_subscription_url($url, $subscription) {
594 594
 
595
-		if ( $this->id !== $subscription->get_gateway() ) {
595
+		if ($this->id !== $subscription->get_gateway()) {
596 596
 			return $url;
597 597
 		}
598 598
 
@@ -600,16 +600,16 @@  discard block
 block discarded – undo
600 600
 		$profile_id = $subscription->get_profile_id();
601 601
 
602 602
 		// Bail if no profile ID.
603
-		if ( empty( $profile_id ) ) {
603
+		if (empty($profile_id)) {
604 604
 			return $url;
605 605
 		}
606 606
 
607 607
 		$cancel_url = 'https://www.paypal.com/myaccount/autopay/connect/%s/cancel';
608
-		if ( $this->is_sandbox( $subscription->get_parent_payment() ) ) {
608
+		if ($this->is_sandbox($subscription->get_parent_payment())) {
609 609
 			$cancel_url = 'https://www.sandbox.paypal.com/myaccount/autopay/connect/%s/cancel';
610 610
 		}
611 611
 
612
-		return sprintf( $cancel_url, $profile_id );
612
+		return sprintf($cancel_url, $profile_id);
613 613
 	}
614 614
 
615 615
 	/**
@@ -619,8 +619,8 @@  discard block
 block discarded – undo
619 619
      * @param array $data
620 620
      * @return string
621 621
 	 */
622
-	public static function maybe_get_connect_url( $url = '', $data = array() ) {
623
-		return self::get_connect_url( false, urldecode( $data['redirect'] ) );
622
+	public static function maybe_get_connect_url($url = '', $data = array()) {
623
+		return self::get_connect_url(false, urldecode($data['redirect']));
624 624
 	}
625 625
 
626 626
 	/**
@@ -631,25 +631,25 @@  discard block
 block discarded – undo
631 631
 	 * @param string $redirect
632 632
      * @return string
633 633
 	 */
634
-	public static function get_connect_url( $is_sandbox, $redirect = '' ) {
634
+	public static function get_connect_url($is_sandbox, $redirect = '') {
635 635
 
636 636
         $redirect_url = add_query_arg(
637 637
             array(
638 638
                 'getpaid-admin-action' => 'connect_paypal',
639 639
                 'page'                 => 'wpinv-settings',
640
-                'live_mode'            => (int) empty( $is_sandbox ),
640
+                'live_mode'            => (int) empty($is_sandbox),
641 641
                 'tab'                  => 'gateways',
642 642
                 'section'              => 'paypal',
643
-                'getpaid-nonce'        => wp_create_nonce( 'getpaid-nonce' ),
644
-				'redirect'             => urlencode( $redirect ),
643
+                'getpaid-nonce'        => wp_create_nonce('getpaid-nonce'),
644
+				'redirect'             => urlencode($redirect),
645 645
             ),
646
-            admin_url( 'admin.php' )
646
+            admin_url('admin.php')
647 647
         );
648 648
 
649 649
         return add_query_arg(
650 650
             array(
651
-                'live_mode'    => (int) empty( $is_sandbox ),
652
-                'redirect_url' => urlencode( str_replace( '&amp;', '&', $redirect_url ) ),
651
+                'live_mode'    => (int) empty($is_sandbox),
652
+                'redirect_url' => urlencode(str_replace('&amp;', '&', $redirect_url)),
653 653
             ),
654 654
             'https://ayecode.io/oauth/paypal'
655 655
         );
@@ -665,10 +665,10 @@  discard block
 block discarded – undo
665 665
 
666 666
         ?>
667 667
 			<div class="wpinv-paypal-connect-live">
668
-				<a class="button button-primary" href="<?php echo esc_url( self::get_connect_url( false ) ); ?>"><?php esc_html_e( 'Connect to PayPal', 'invoicing' ); ?></a>
668
+				<a class="button button-primary" href="<?php echo esc_url(self::get_connect_url(false)); ?>"><?php esc_html_e('Connect to PayPal', 'invoicing'); ?></a>
669 669
 			</div>
670 670
 			<div class="wpinv-paypal-connect-sandbox">
671
-				<a class="button button-primary" href="<?php echo esc_url( self::get_connect_url( true ) ); ?>"><?php esc_html_e( 'Connect to PayPal Sandbox', 'invoicing' ); ?></a>
671
+				<a class="button button-primary" href="<?php echo esc_url(self::get_connect_url(true)); ?>"><?php esc_html_e('Connect to PayPal Sandbox', 'invoicing'); ?></a>
672 672
 			</div>
673 673
 
674 674
             <script>
@@ -709,26 +709,26 @@  discard block
 block discarded – undo
709 709
 	 * @param array $data Connection data.
710 710
 	 * @return void
711 711
 	 */
712
-	public function connect_paypal( $data ) {
712
+	public function connect_paypal($data) {
713 713
 
714 714
 		$sandbox      = $this->is_sandbox();
715
-		$data         = wp_unslash( $data );
716
-		$access_token = empty( $data['access_token'] ) ? '' : sanitize_text_field( $data['access_token'] );
715
+		$data         = wp_unslash($data);
716
+		$access_token = empty($data['access_token']) ? '' : sanitize_text_field($data['access_token']);
717 717
 
718
-		if ( isset( $data['live_mode'] ) ) {
719
-			$sandbox = empty( $data['live_mode'] );
718
+		if (isset($data['live_mode'])) {
719
+			$sandbox = empty($data['live_mode']);
720 720
 		}
721 721
 
722
-		wpinv_update_option( 'paypal_sandbox', (int) $sandbox );
723
-		wpinv_update_option( 'paypal_active', 1 );
722
+		wpinv_update_option('paypal_sandbox', (int) $sandbox);
723
+		wpinv_update_option('paypal_active', 1);
724 724
 
725
-		if ( ! empty( $data['error_description'] ) ) {
726
-			getpaid_admin()->show_error( wp_kses_post( urldecode( $data['error_description'] ) ) );
725
+		if (!empty($data['error_description'])) {
726
+			getpaid_admin()->show_error(wp_kses_post(urldecode($data['error_description'])));
727 727
 		} else {
728 728
 
729 729
 			// Retrieve the user info.
730 730
 			$user_info = wp_remote_get(
731
-				! $sandbox ? 'https://api-m.paypal.com/v1/identity/oauth2/userinfo?schema=paypalv1.1' : 'https://api-m.sandbox.paypal.com/v1/identity/oauth2/userinfo?schema=paypalv1.1',
731
+				!$sandbox ? 'https://api-m.paypal.com/v1/identity/oauth2/userinfo?schema=paypalv1.1' : 'https://api-m.sandbox.paypal.com/v1/identity/oauth2/userinfo?schema=paypalv1.1',
732 732
 				array(
733 733
 
734 734
 					'headers' => array(
@@ -739,33 +739,33 @@  discard block
 block discarded – undo
739 739
 				)
740 740
 			);
741 741
 
742
-			if ( is_wp_error( $user_info ) ) {
743
-				getpaid_admin()->show_error( wp_kses_post( $user_info->get_error_message() ) );
742
+			if (is_wp_error($user_info)) {
743
+				getpaid_admin()->show_error(wp_kses_post($user_info->get_error_message()));
744 744
 			} else {
745 745
 
746 746
 				// Create application.
747
-				$user_info = json_decode( wp_remote_retrieve_body( $user_info ) );
747
+				$user_info = json_decode(wp_remote_retrieve_body($user_info));
748 748
 
749
-				if ( $sandbox ) {
750
-					wpinv_update_option( 'paypal_sandbox_email', sanitize_email( $user_info->emails[0]->value ) );
751
-					wpinv_update_option( 'paypal_sandbox_refresh_token', sanitize_text_field( urldecode( $data['refresh_token'] ) ) );
752
-					set_transient( 'getpaid_paypal_sandbox_access_token', sanitize_text_field( urldecode( $data['access_token'] ) ), (int) $data['expires_in'] );
753
-					getpaid_admin()->show_success( __( 'Successfully connected your PayPal sandbox account', 'invoicing' ) );
749
+				if ($sandbox) {
750
+					wpinv_update_option('paypal_sandbox_email', sanitize_email($user_info->emails[0]->value));
751
+					wpinv_update_option('paypal_sandbox_refresh_token', sanitize_text_field(urldecode($data['refresh_token'])));
752
+					set_transient('getpaid_paypal_sandbox_access_token', sanitize_text_field(urldecode($data['access_token'])), (int) $data['expires_in']);
753
+					getpaid_admin()->show_success(__('Successfully connected your PayPal sandbox account', 'invoicing'));
754 754
 				} else {
755
-					wpinv_update_option( 'paypal_email', sanitize_email( $user_info->emails[0]->value ) );
756
-					wpinv_update_option( 'paypal_refresh_token', sanitize_text_field( urldecode( $data['refresh_token'] ) ) );
757
-					set_transient( 'getpaid_paypal_access_token', sanitize_text_field( urldecode( $data['access_token'] ) ), (int) $data['expires_in'] );
758
-					getpaid_admin()->show_success( __( 'Successfully connected your PayPal account', 'invoicing' ) );
755
+					wpinv_update_option('paypal_email', sanitize_email($user_info->emails[0]->value));
756
+					wpinv_update_option('paypal_refresh_token', sanitize_text_field(urldecode($data['refresh_token'])));
757
+					set_transient('getpaid_paypal_access_token', sanitize_text_field(urldecode($data['access_token'])), (int) $data['expires_in']);
758
+					getpaid_admin()->show_success(__('Successfully connected your PayPal account', 'invoicing'));
759 759
 				}
760 760
 }
761 761
 }
762 762
 
763
-		$redirect = empty( $data['redirect'] ) ? admin_url( 'admin.php?page=wpinv-settings&tab=gateways&section=paypal' ) : urldecode( $data['redirect'] );
763
+		$redirect = empty($data['redirect']) ? admin_url('admin.php?page=wpinv-settings&tab=gateways&section=paypal') : urldecode($data['redirect']);
764 764
 
765
-		if ( isset( $data['step'] ) ) {
766
-			$redirect = add_query_arg( 'step', $data['step'], $redirect );
765
+		if (isset($data['step'])) {
766
+			$redirect = add_query_arg('step', $data['step'], $redirect);
767 767
 		}
768
-		wp_redirect( $redirect );
768
+		wp_redirect($redirect);
769 769
 		exit;
770 770
 	}
771 771
 
Please login to merge, or discard this patch.
includes/class-getpaid-tax.php 2 patches
Indentation   +192 added lines, -192 removed lines patch added patch discarded remove patch
@@ -13,199 +13,199 @@
 block discarded – undo
13 13
  */
14 14
 class GetPaid_Tax {
15 15
 
16
-	/**
17
-	 * Calculates tax for a line item.
18
-	 *
19
-	 * @param  float   $price              The price to calc tax on.
20
-	 * @param  array   $rates              The rates to apply.
21
-	 * @param  boolean $price_includes_tax Whether the passed price has taxes included.
22
-	 * @return array                       Array of tax name => tax amount.
23
-	 */
24
-	public static function calc_tax( $price, $rates, $price_includes_tax = false ) {
25
-
26
-		if ( $price_includes_tax ) {
27
-			$taxes = self::calc_inclusive_tax( $price, $rates );
28
-		} else {
29
-			$taxes = self::calc_exclusive_tax( $price, $rates );
30
-		}
31
-
32
-		return apply_filters( 'getpaid_calc_tax', $taxes, $price, $rates, $price_includes_tax );
33
-
34
-	}
35
-
36
-	/**
37
-	 * Calc tax from inclusive price.
38
-	 *
39
-	 * @param  float $price Price to calculate tax for.
40
-	 * @param  array $rates Array of tax rates.
41
-	 * @return array
42
-	 */
43
-	public static function calc_inclusive_tax( $price, $rates ) {
44
-		$taxes     = array();
45
-		$tax_rates = wp_list_pluck( $rates, 'rate', 'name' );
46
-
47
-		// Add tax rates.
48
-		$tax_rate  = 1 + ( array_sum( $tax_rates ) / 100 );
49
-
50
-		foreach ( $tax_rates as $name => $rate ) {
51
-			$the_rate       = ( $rate / 100 ) / $tax_rate;
52
-			$net_price      = $price - ( $the_rate * $price );
53
-			$tax_amount     = apply_filters( 'getpaid_price_inc_tax_amount', $price - $net_price, $name, $rate, $price );
54
-			$taxes[ $name ] = $tax_amount;
55
-		}
56
-
57
-		// Round all taxes to precision (4DP) before passing them back.
58
-		$taxes = array_map( array( __CLASS__, 'round' ), $taxes );
59
-
60
-		return $taxes;
61
-	}
62
-
63
-	/**
64
-	 * Calc tax from exclusive price.
65
-	 *
66
-	 * @param  float $price Price to calculate tax for.
67
-	 * @param  array $rates Array of tax rates.
68
-	 * @return array
69
-	 */
70
-	public static function calc_exclusive_tax( $price, $rates ) {
71
-		$taxes     = array();
72
-		$tax_rates = wp_list_pluck( $rates, 'rate', 'name' );
73
-
74
-		foreach ( $tax_rates as $name => $rate ) {
75
-
76
-			$tax_amount     = $price * ( $rate / 100 );
77
-			$taxes[ $name ] = apply_filters( 'getpaid_price_ex_tax_amount', $tax_amount, $name, $rate, $price );
78
-
79
-		}
80
-
81
-		// Round all taxes to precision (4DP) before passing them back.
82
-		$taxes = array_map( array( __CLASS__, 'round' ), $taxes );
83
-
84
-		return $taxes;
85
-	}
86
-
87
-	/**
88
-	 * Get's an array of all tax rates.
89
-	 *
90
-	 * @return array
91
-	 */
92
-	public static function get_all_tax_rates() {
93
-
94
-		$rates = get_option( 'wpinv_tax_rates', array() );
95
-
96
-		return apply_filters(
97
-			'getpaid_get_all_tax_rates',
98
-			array_filter( wpinv_parse_list( $rates ) )
99
-		);
100
-
101
-	}
102
-
103
-	/**
104
-	 * Get's an array of default tax rates.
105
-	 *
106
-	 * @return array
107
-	 */
108
-	public static function get_default_tax_rates() {
109
-
110
-		return apply_filters(
111
-			'getpaid_get_default_tax_rates',
112
-			array(
113
-				array(
114
-					'country' => wpinv_get_default_country(),
115
-					'state'   => wpinv_get_default_state(),
116
-					'global'  => true,
117
-					'rate'    => wpinv_get_default_tax_rate(),
118
-					'name'    => __( 'Tax', 'invoicing' ),
119
-				),
120
-			)
121
-		);
122
-
123
-	}
124
-
125
-	/**
126
-	 * Get's an array of all tax rules.
127
-	 *
128
-	 * @return array
129
-	 */
130
-	public static function get_all_tax_rules() {
131
-
132
-		$rules = get_option(
133
-			'wpinv_tax_rules',
134
-			array(
135
-				array(
136
-					'key'               => 'physical',
137
-					'label'             => __( 'Physical Item', 'invoicing' ),
138
-					'tax_base'          => wpinv_get_option( 'tax_base', 'billing' ),
139
-					'same_country_rule' => wpinv_get_option( 'vat_same_country_rule', 'vat_too' ),
140
-				),
141
-				array(
142
-					'key'               => 'digital',
143
-					'label'             => __( 'Digital Item', 'invoicing' ),
144
-					'tax_base'          => wpinv_get_option( 'tax_base', 'billing' ),
145
-					'same_country_rule' => wpinv_get_option( 'vat_same_country_rule', 'vat_too' ),
146
-				),
147
-        	)
148
-		);
149
-
150
-		return apply_filters(
151
-			'getpaid_tax_rules',
152
-			array_filter( array_values( wpinv_parse_list( $rules ) ) )
153
-		);
154
-
155
-	}
156
-
157
-	/**
158
-	 * Get's an array of tax rates for a given address.
159
-	 *
160
-	 * @param string $country
161
-	 * @param string $state
162
-	 * @return array
163
-	 */
164
-	public static function get_address_tax_rates( $country, $state ) {
165
-
166
-		$all_tax_rates  = self::get_all_tax_rates();
167
-		$matching_rates = array_merge(
168
-			wp_list_filter( $all_tax_rates, array( 'country' => $country ) ),
169
-			wp_list_filter( $all_tax_rates, array( 'country' => '' ) )
170
-		);
171
-
172
-		foreach ( $matching_rates as $i => $rate ) {
173
-
174
-			$states = array_filter( wpinv_clean( explode( ',', strtolower( $rate['state'] ) ) ) );
175
-			if ( empty( $rate['global'] ) && ! in_array( strtolower( $state ), $states ) ) {
176
-				unset( $matching_rates[ $i ] );
177
-			}
16
+    /**
17
+     * Calculates tax for a line item.
18
+     *
19
+     * @param  float   $price              The price to calc tax on.
20
+     * @param  array   $rates              The rates to apply.
21
+     * @param  boolean $price_includes_tax Whether the passed price has taxes included.
22
+     * @return array                       Array of tax name => tax amount.
23
+     */
24
+    public static function calc_tax( $price, $rates, $price_includes_tax = false ) {
25
+
26
+        if ( $price_includes_tax ) {
27
+            $taxes = self::calc_inclusive_tax( $price, $rates );
28
+        } else {
29
+            $taxes = self::calc_exclusive_tax( $price, $rates );
30
+        }
31
+
32
+        return apply_filters( 'getpaid_calc_tax', $taxes, $price, $rates, $price_includes_tax );
33
+
34
+    }
35
+
36
+    /**
37
+     * Calc tax from inclusive price.
38
+     *
39
+     * @param  float $price Price to calculate tax for.
40
+     * @param  array $rates Array of tax rates.
41
+     * @return array
42
+     */
43
+    public static function calc_inclusive_tax( $price, $rates ) {
44
+        $taxes     = array();
45
+        $tax_rates = wp_list_pluck( $rates, 'rate', 'name' );
46
+
47
+        // Add tax rates.
48
+        $tax_rate  = 1 + ( array_sum( $tax_rates ) / 100 );
49
+
50
+        foreach ( $tax_rates as $name => $rate ) {
51
+            $the_rate       = ( $rate / 100 ) / $tax_rate;
52
+            $net_price      = $price - ( $the_rate * $price );
53
+            $tax_amount     = apply_filters( 'getpaid_price_inc_tax_amount', $price - $net_price, $name, $rate, $price );
54
+            $taxes[ $name ] = $tax_amount;
55
+        }
56
+
57
+        // Round all taxes to precision (4DP) before passing them back.
58
+        $taxes = array_map( array( __CLASS__, 'round' ), $taxes );
59
+
60
+        return $taxes;
61
+    }
62
+
63
+    /**
64
+     * Calc tax from exclusive price.
65
+     *
66
+     * @param  float $price Price to calculate tax for.
67
+     * @param  array $rates Array of tax rates.
68
+     * @return array
69
+     */
70
+    public static function calc_exclusive_tax( $price, $rates ) {
71
+        $taxes     = array();
72
+        $tax_rates = wp_list_pluck( $rates, 'rate', 'name' );
73
+
74
+        foreach ( $tax_rates as $name => $rate ) {
75
+
76
+            $tax_amount     = $price * ( $rate / 100 );
77
+            $taxes[ $name ] = apply_filters( 'getpaid_price_ex_tax_amount', $tax_amount, $name, $rate, $price );
78
+
79
+        }
80
+
81
+        // Round all taxes to precision (4DP) before passing them back.
82
+        $taxes = array_map( array( __CLASS__, 'round' ), $taxes );
83
+
84
+        return $taxes;
85
+    }
86
+
87
+    /**
88
+     * Get's an array of all tax rates.
89
+     *
90
+     * @return array
91
+     */
92
+    public static function get_all_tax_rates() {
93
+
94
+        $rates = get_option( 'wpinv_tax_rates', array() );
95
+
96
+        return apply_filters(
97
+            'getpaid_get_all_tax_rates',
98
+            array_filter( wpinv_parse_list( $rates ) )
99
+        );
100
+
101
+    }
102
+
103
+    /**
104
+     * Get's an array of default tax rates.
105
+     *
106
+     * @return array
107
+     */
108
+    public static function get_default_tax_rates() {
109
+
110
+        return apply_filters(
111
+            'getpaid_get_default_tax_rates',
112
+            array(
113
+                array(
114
+                    'country' => wpinv_get_default_country(),
115
+                    'state'   => wpinv_get_default_state(),
116
+                    'global'  => true,
117
+                    'rate'    => wpinv_get_default_tax_rate(),
118
+                    'name'    => __( 'Tax', 'invoicing' ),
119
+                ),
120
+            )
121
+        );
122
+
123
+    }
124
+
125
+    /**
126
+     * Get's an array of all tax rules.
127
+     *
128
+     * @return array
129
+     */
130
+    public static function get_all_tax_rules() {
131
+
132
+        $rules = get_option(
133
+            'wpinv_tax_rules',
134
+            array(
135
+                array(
136
+                    'key'               => 'physical',
137
+                    'label'             => __( 'Physical Item', 'invoicing' ),
138
+                    'tax_base'          => wpinv_get_option( 'tax_base', 'billing' ),
139
+                    'same_country_rule' => wpinv_get_option( 'vat_same_country_rule', 'vat_too' ),
140
+                ),
141
+                array(
142
+                    'key'               => 'digital',
143
+                    'label'             => __( 'Digital Item', 'invoicing' ),
144
+                    'tax_base'          => wpinv_get_option( 'tax_base', 'billing' ),
145
+                    'same_country_rule' => wpinv_get_option( 'vat_same_country_rule', 'vat_too' ),
146
+                ),
147
+            )
148
+        );
149
+
150
+        return apply_filters(
151
+            'getpaid_tax_rules',
152
+            array_filter( array_values( wpinv_parse_list( $rules ) ) )
153
+        );
154
+
155
+    }
156
+
157
+    /**
158
+     * Get's an array of tax rates for a given address.
159
+     *
160
+     * @param string $country
161
+     * @param string $state
162
+     * @return array
163
+     */
164
+    public static function get_address_tax_rates( $country, $state ) {
165
+
166
+        $all_tax_rates  = self::get_all_tax_rates();
167
+        $matching_rates = array_merge(
168
+            wp_list_filter( $all_tax_rates, array( 'country' => $country ) ),
169
+            wp_list_filter( $all_tax_rates, array( 'country' => '' ) )
170
+        );
171
+
172
+        foreach ( $matching_rates as $i => $rate ) {
173
+
174
+            $states = array_filter( wpinv_clean( explode( ',', strtolower( $rate['state'] ) ) ) );
175
+            if ( empty( $rate['global'] ) && ! in_array( strtolower( $state ), $states ) ) {
176
+                unset( $matching_rates[ $i ] );
177
+            }
178 178
 }
179 179
 
180
-		return apply_filters( 'getpaid_get_address_tax_rates', $matching_rates, $country, $state );
181
-
182
-	}
183
-
184
-	/**
185
-	 * Sums a set of taxes to form a single total. Result is rounded to precision.
186
-	 *
187
-	 * @param  array $taxes Array of taxes.
188
-	 * @return float
189
-	 */
190
-	public static function get_tax_total( $taxes ) {
191
-		return self::round( array_sum( $taxes ) );
192
-	}
193
-
194
-	/**
195
-	 * Round to precision.
196
-	 *
197
-	 * Filter example: to return rounding to .5 cents you'd use:
198
-	 *
199
-	 * function euro_5cent_rounding( $in ) {
200
-	 *      return round( $in / 5, 2 ) * 5;
201
-	 * }
202
-	 * add_filter( 'getpaid_tax_round', 'euro_5cent_rounding' );
203
-	 *
204
-	 * @param float|int $in Value to round.
205
-	 * @return float
206
-	 */
207
-	public static function round( $in ) {
208
-		return apply_filters( 'getpaid_tax_round', round( $in, 4 ), $in );
209
-	}
180
+        return apply_filters( 'getpaid_get_address_tax_rates', $matching_rates, $country, $state );
181
+
182
+    }
183
+
184
+    /**
185
+     * Sums a set of taxes to form a single total. Result is rounded to precision.
186
+     *
187
+     * @param  array $taxes Array of taxes.
188
+     * @return float
189
+     */
190
+    public static function get_tax_total( $taxes ) {
191
+        return self::round( array_sum( $taxes ) );
192
+    }
193
+
194
+    /**
195
+     * Round to precision.
196
+     *
197
+     * Filter example: to return rounding to .5 cents you'd use:
198
+     *
199
+     * function euro_5cent_rounding( $in ) {
200
+     *      return round( $in / 5, 2 ) * 5;
201
+     * }
202
+     * add_filter( 'getpaid_tax_round', 'euro_5cent_rounding' );
203
+     *
204
+     * @param float|int $in Value to round.
205
+     * @return float
206
+     */
207
+    public static function round( $in ) {
208
+        return apply_filters( 'getpaid_tax_round', round( $in, 4 ), $in );
209
+    }
210 210
 
211 211
 }
Please login to merge, or discard this patch.
Spacing   +43 added lines, -43 removed lines patch added patch discarded remove patch
@@ -5,7 +5,7 @@  discard block
 block discarded – undo
5 5
  *
6 6
  */
7 7
 
8
-defined( 'ABSPATH' ) || exit;
8
+defined('ABSPATH') || exit;
9 9
 
10 10
 /**
11 11
  * Class GetPaid_Tax
@@ -21,15 +21,15 @@  discard block
 block discarded – undo
21 21
 	 * @param  boolean $price_includes_tax Whether the passed price has taxes included.
22 22
 	 * @return array                       Array of tax name => tax amount.
23 23
 	 */
24
-	public static function calc_tax( $price, $rates, $price_includes_tax = false ) {
24
+	public static function calc_tax($price, $rates, $price_includes_tax = false) {
25 25
 
26
-		if ( $price_includes_tax ) {
27
-			$taxes = self::calc_inclusive_tax( $price, $rates );
26
+		if ($price_includes_tax) {
27
+			$taxes = self::calc_inclusive_tax($price, $rates);
28 28
 		} else {
29
-			$taxes = self::calc_exclusive_tax( $price, $rates );
29
+			$taxes = self::calc_exclusive_tax($price, $rates);
30 30
 		}
31 31
 
32
-		return apply_filters( 'getpaid_calc_tax', $taxes, $price, $rates, $price_includes_tax );
32
+		return apply_filters('getpaid_calc_tax', $taxes, $price, $rates, $price_includes_tax);
33 33
 
34 34
 	}
35 35
 
@@ -40,22 +40,22 @@  discard block
 block discarded – undo
40 40
 	 * @param  array $rates Array of tax rates.
41 41
 	 * @return array
42 42
 	 */
43
-	public static function calc_inclusive_tax( $price, $rates ) {
43
+	public static function calc_inclusive_tax($price, $rates) {
44 44
 		$taxes     = array();
45
-		$tax_rates = wp_list_pluck( $rates, 'rate', 'name' );
45
+		$tax_rates = wp_list_pluck($rates, 'rate', 'name');
46 46
 
47 47
 		// Add tax rates.
48
-		$tax_rate  = 1 + ( array_sum( $tax_rates ) / 100 );
48
+		$tax_rate  = 1 + (array_sum($tax_rates) / 100);
49 49
 
50
-		foreach ( $tax_rates as $name => $rate ) {
51
-			$the_rate       = ( $rate / 100 ) / $tax_rate;
52
-			$net_price      = $price - ( $the_rate * $price );
53
-			$tax_amount     = apply_filters( 'getpaid_price_inc_tax_amount', $price - $net_price, $name, $rate, $price );
54
-			$taxes[ $name ] = $tax_amount;
50
+		foreach ($tax_rates as $name => $rate) {
51
+			$the_rate       = ($rate / 100) / $tax_rate;
52
+			$net_price      = $price - ($the_rate * $price);
53
+			$tax_amount     = apply_filters('getpaid_price_inc_tax_amount', $price - $net_price, $name, $rate, $price);
54
+			$taxes[$name] = $tax_amount;
55 55
 		}
56 56
 
57 57
 		// Round all taxes to precision (4DP) before passing them back.
58
-		$taxes = array_map( array( __CLASS__, 'round' ), $taxes );
58
+		$taxes = array_map(array(__CLASS__, 'round'), $taxes);
59 59
 
60 60
 		return $taxes;
61 61
 	}
@@ -67,19 +67,19 @@  discard block
 block discarded – undo
67 67
 	 * @param  array $rates Array of tax rates.
68 68
 	 * @return array
69 69
 	 */
70
-	public static function calc_exclusive_tax( $price, $rates ) {
70
+	public static function calc_exclusive_tax($price, $rates) {
71 71
 		$taxes     = array();
72
-		$tax_rates = wp_list_pluck( $rates, 'rate', 'name' );
72
+		$tax_rates = wp_list_pluck($rates, 'rate', 'name');
73 73
 
74
-		foreach ( $tax_rates as $name => $rate ) {
74
+		foreach ($tax_rates as $name => $rate) {
75 75
 
76
-			$tax_amount     = $price * ( $rate / 100 );
77
-			$taxes[ $name ] = apply_filters( 'getpaid_price_ex_tax_amount', $tax_amount, $name, $rate, $price );
76
+			$tax_amount     = $price * ($rate / 100);
77
+			$taxes[$name] = apply_filters('getpaid_price_ex_tax_amount', $tax_amount, $name, $rate, $price);
78 78
 
79 79
 		}
80 80
 
81 81
 		// Round all taxes to precision (4DP) before passing them back.
82
-		$taxes = array_map( array( __CLASS__, 'round' ), $taxes );
82
+		$taxes = array_map(array(__CLASS__, 'round'), $taxes);
83 83
 
84 84
 		return $taxes;
85 85
 	}
@@ -91,11 +91,11 @@  discard block
 block discarded – undo
91 91
 	 */
92 92
 	public static function get_all_tax_rates() {
93 93
 
94
-		$rates = get_option( 'wpinv_tax_rates', array() );
94
+		$rates = get_option('wpinv_tax_rates', array());
95 95
 
96 96
 		return apply_filters(
97 97
 			'getpaid_get_all_tax_rates',
98
-			array_filter( wpinv_parse_list( $rates ) )
98
+			array_filter(wpinv_parse_list($rates))
99 99
 		);
100 100
 
101 101
 	}
@@ -115,7 +115,7 @@  discard block
 block discarded – undo
115 115
 					'state'   => wpinv_get_default_state(),
116 116
 					'global'  => true,
117 117
 					'rate'    => wpinv_get_default_tax_rate(),
118
-					'name'    => __( 'Tax', 'invoicing' ),
118
+					'name'    => __('Tax', 'invoicing'),
119 119
 				),
120 120
 			)
121 121
 		);
@@ -134,22 +134,22 @@  discard block
 block discarded – undo
134 134
 			array(
135 135
 				array(
136 136
 					'key'               => 'physical',
137
-					'label'             => __( 'Physical Item', 'invoicing' ),
138
-					'tax_base'          => wpinv_get_option( 'tax_base', 'billing' ),
139
-					'same_country_rule' => wpinv_get_option( 'vat_same_country_rule', 'vat_too' ),
137
+					'label'             => __('Physical Item', 'invoicing'),
138
+					'tax_base'          => wpinv_get_option('tax_base', 'billing'),
139
+					'same_country_rule' => wpinv_get_option('vat_same_country_rule', 'vat_too'),
140 140
 				),
141 141
 				array(
142 142
 					'key'               => 'digital',
143
-					'label'             => __( 'Digital Item', 'invoicing' ),
144
-					'tax_base'          => wpinv_get_option( 'tax_base', 'billing' ),
145
-					'same_country_rule' => wpinv_get_option( 'vat_same_country_rule', 'vat_too' ),
143
+					'label'             => __('Digital Item', 'invoicing'),
144
+					'tax_base'          => wpinv_get_option('tax_base', 'billing'),
145
+					'same_country_rule' => wpinv_get_option('vat_same_country_rule', 'vat_too'),
146 146
 				),
147 147
         	)
148 148
 		);
149 149
 
150 150
 		return apply_filters(
151 151
 			'getpaid_tax_rules',
152
-			array_filter( array_values( wpinv_parse_list( $rules ) ) )
152
+			array_filter(array_values(wpinv_parse_list($rules)))
153 153
 		);
154 154
 
155 155
 	}
@@ -161,23 +161,23 @@  discard block
 block discarded – undo
161 161
 	 * @param string $state
162 162
 	 * @return array
163 163
 	 */
164
-	public static function get_address_tax_rates( $country, $state ) {
164
+	public static function get_address_tax_rates($country, $state) {
165 165
 
166 166
 		$all_tax_rates  = self::get_all_tax_rates();
167 167
 		$matching_rates = array_merge(
168
-			wp_list_filter( $all_tax_rates, array( 'country' => $country ) ),
169
-			wp_list_filter( $all_tax_rates, array( 'country' => '' ) )
168
+			wp_list_filter($all_tax_rates, array('country' => $country)),
169
+			wp_list_filter($all_tax_rates, array('country' => ''))
170 170
 		);
171 171
 
172
-		foreach ( $matching_rates as $i => $rate ) {
172
+		foreach ($matching_rates as $i => $rate) {
173 173
 
174
-			$states = array_filter( wpinv_clean( explode( ',', strtolower( $rate['state'] ) ) ) );
175
-			if ( empty( $rate['global'] ) && ! in_array( strtolower( $state ), $states ) ) {
176
-				unset( $matching_rates[ $i ] );
174
+			$states = array_filter(wpinv_clean(explode(',', strtolower($rate['state']))));
175
+			if (empty($rate['global']) && !in_array(strtolower($state), $states)) {
176
+				unset($matching_rates[$i]);
177 177
 			}
178 178
 }
179 179
 
180
-		return apply_filters( 'getpaid_get_address_tax_rates', $matching_rates, $country, $state );
180
+		return apply_filters('getpaid_get_address_tax_rates', $matching_rates, $country, $state);
181 181
 
182 182
 	}
183 183
 
@@ -187,8 +187,8 @@  discard block
 block discarded – undo
187 187
 	 * @param  array $taxes Array of taxes.
188 188
 	 * @return float
189 189
 	 */
190
-	public static function get_tax_total( $taxes ) {
191
-		return self::round( array_sum( $taxes ) );
190
+	public static function get_tax_total($taxes) {
191
+		return self::round(array_sum($taxes));
192 192
 	}
193 193
 
194 194
 	/**
@@ -204,8 +204,8 @@  discard block
 block discarded – undo
204 204
 	 * @param float|int $in Value to round.
205 205
 	 * @return float
206 206
 	 */
207
-	public static function round( $in ) {
208
-		return apply_filters( 'getpaid_tax_round', round( $in, 4 ), $in );
207
+	public static function round($in) {
208
+		return apply_filters('getpaid_tax_round', round($in, 4), $in);
209 209
 	}
210 210
 
211 211
 }
Please login to merge, or discard this patch.
templates/emails/invoice-totals.php 1 patch
Spacing   +25 added lines, -25 removed lines patch added patch discarded remove patch
@@ -8,22 +8,22 @@  discard block
 block discarded – undo
8 8
  * @var WPInv_Invoice $invoice
9 9
  */
10 10
 
11
-defined( 'ABSPATH' ) || exit;
11
+defined('ABSPATH') || exit;
12 12
 
13 13
 // Totals rows.
14
-$totals = getpaid_invoice_totals_rows( $invoice );
14
+$totals = getpaid_invoice_totals_rows($invoice);
15 15
 
16
-do_action( 'getpaid_before_email_line_totals', $invoice, $totals );
16
+do_action('getpaid_before_email_line_totals', $invoice, $totals);
17 17
 
18 18
 ?>
19 19
 
20 20
 
21
-<?php if ( has_action( 'wpinv_email_footer_buttons' ) ) : ?>
21
+<?php if (has_action('wpinv_email_footer_buttons')) : ?>
22 22
 
23 23
     <tr class="wpinv_cart_footer_row">
24 24
 
25
-        <td colspan="<?php echo ( (int) $column_count ); ?>">
26
-            <?php do_action( 'wpinv_email_footer_buttons' ); ?>
25
+        <td colspan="<?php echo ((int) $column_count); ?>">
26
+            <?php do_action('wpinv_email_footer_buttons'); ?>
27 27
         </td>
28 28
 
29 29
     </tr>
@@ -31,49 +31,49 @@  discard block
 block discarded – undo
31 31
 <?php endif; ?>
32 32
 
33 33
 
34
-<?php foreach ( $totals as $key => $label ) : ?>
34
+<?php foreach ($totals as $key => $label) : ?>
35 35
 
36
-    <tr class="wpinv_cart_footer_row wpinv_cart_<?php echo esc_html( $key ); ?>_row">
36
+    <tr class="wpinv_cart_footer_row wpinv_cart_<?php echo esc_html($key); ?>_row">
37 37
 
38
-        <td colspan="<?php echo absint( ( $column_count - 1 ) ); ?>" class="wpinv_cart_<?php echo esc_html( $key ); ?>_label text-right">
39
-            <strong><?php echo esc_html( $label ); ?>:</strong>
38
+        <td colspan="<?php echo absint(($column_count - 1)); ?>" class="wpinv_cart_<?php echo esc_html($key); ?>_label text-right">
39
+            <strong><?php echo esc_html($label); ?>:</strong>
40 40
         </td>
41 41
 
42
-        <td class="wpinv_cart_<?php echo esc_html( $key ); ?> text-right">
42
+        <td class="wpinv_cart_<?php echo esc_html($key); ?> text-right">
43 43
 
44 44
             <?php
45 45
 
46 46
                 // Total tax.
47
-                if ( 'tax' == $key ) {
48
-                    wpinv_the_price( $invoice->get_total_tax(), $invoice->get_currency() );
47
+                if ('tax' == $key) {
48
+                    wpinv_the_price($invoice->get_total_tax(), $invoice->get_currency());
49 49
                 }
50 50
 
51 51
                 // Individual taxes.
52
-                if ( 0 === strpos( $key, 'tax__' ) ) {
53
-                    wpinv_the_price( $invoice->get_tax_total_by_name( str_replace( 'tax__', '', $key ) ), $invoice->get_currency() );
52
+                if (0 === strpos($key, 'tax__')) {
53
+                    wpinv_the_price($invoice->get_tax_total_by_name(str_replace('tax__', '', $key)), $invoice->get_currency());
54 54
                 }
55 55
 
56
-                if ( 'fee' == $key ) {
57
-                    wpinv_the_price( $invoice->get_total_fees(), $invoice->get_currency() );
56
+                if ('fee' == $key) {
57
+                    wpinv_the_price($invoice->get_total_fees(), $invoice->get_currency());
58 58
                 }
59 59
 
60 60
                 // Total discount.
61
-                if ( 'discount' == $key ) {
62
-                    wpinv_the_price( $invoice->get_total_discount(), $invoice->get_currency() );
61
+                if ('discount' == $key) {
62
+                    wpinv_the_price($invoice->get_total_discount(), $invoice->get_currency());
63 63
                 }
64 64
 
65 65
                 // Sub total.
66
-                if ( 'subtotal' == $key ) {
67
-                    wpinv_the_price( $invoice->get_subtotal(), $invoice->get_currency() );
66
+                if ('subtotal' == $key) {
67
+                    wpinv_the_price($invoice->get_subtotal(), $invoice->get_currency());
68 68
                 }
69 69
 
70 70
                 // Total.
71
-                if ( 'total' == $key ) {
72
-                    wpinv_the_price( $invoice->get_total(), $invoice->get_currency() );
71
+                if ('total' == $key) {
72
+                    wpinv_the_price($invoice->get_total(), $invoice->get_currency());
73 73
                 }
74 74
 
75 75
                 // Fires when printing a cart total in an email.
76
-                do_action( "getpaid_email_cart_totals_$key", $invoice );
76
+                do_action("getpaid_email_cart_totals_$key", $invoice);
77 77
 
78 78
             ?>
79 79
 
@@ -85,4 +85,4 @@  discard block
 block discarded – undo
85 85
 
86 86
 <?php
87 87
 
88
-    do_action( 'getpaid_after_email_line_totals', $invoice, $totals );
88
+    do_action('getpaid_after_email_line_totals', $invoice, $totals);
Please login to merge, or discard this patch.
includes/invoice-functions.php 2 patches
Spacing   +373 added lines, -373 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 the current invoice.
@@ -14,15 +14,15 @@  discard block
 block discarded – undo
14 14
 function getpaid_get_current_invoice_id() {
15 15
 
16 16
     // Ensure that we have an invoice key.
17
-    if ( empty( $_GET['invoice_key'] ) ) {
17
+    if (empty($_GET['invoice_key'])) {
18 18
         return 0;
19 19
     }
20 20
 
21 21
     // Retrieve an invoice using the key.
22
-    $invoice = new WPInv_Invoice( sanitize_text_field( $_GET['invoice_key'] ) );
22
+    $invoice = new WPInv_Invoice(sanitize_text_field($_GET['invoice_key']));
23 23
 
24 24
     // Compare the invoice key and the parsed key.
25
-    if ( $invoice->get_id() != 0 && $invoice->get_key() == sanitize_text_field( $_GET['invoice_key'] ) ) {
25
+    if ($invoice->get_id() != 0 && $invoice->get_key() == sanitize_text_field($_GET['invoice_key'])) {
26 26
         return $invoice->get_id();
27 27
     }
28 28
 
@@ -32,42 +32,42 @@  discard block
 block discarded – undo
32 32
 /**
33 33
  * Checks if the current user cna view an invoice.
34 34
  */
35
-function wpinv_user_can_view_invoice( $invoice ) {
36
-    $invoice = new WPInv_Invoice( $invoice );
35
+function wpinv_user_can_view_invoice($invoice) {
36
+    $invoice = new WPInv_Invoice($invoice);
37 37
 
38 38
     // Abort if the invoice does not exist.
39
-    if ( 0 == $invoice->get_id() ) {
39
+    if (0 == $invoice->get_id()) {
40 40
         return false;
41 41
     }
42 42
 
43 43
     // Don't allow trash, draft status
44
-    if ( $invoice->is_draft() ) {
44
+    if ($invoice->is_draft()) {
45 45
         return false;
46 46
     }
47 47
 
48 48
     // If users are not required to login to check out, compare the invoice keys.
49
-    if ( ! wpinv_require_login_to_checkout() && isset( $_GET['invoice_key'] ) && sanitize_text_field( $_GET['invoice_key'] ) == $invoice->get_key() ) {
49
+    if (!wpinv_require_login_to_checkout() && isset($_GET['invoice_key']) && sanitize_text_field($_GET['invoice_key']) == $invoice->get_key()) {
50 50
         return true;
51 51
     }
52 52
 
53 53
     // Always enable for admins..
54
-    if ( wpinv_current_user_can( 'view_invoice', array( 'invoice' => $invoice ) ) || current_user_can( 'view_invoices', $invoice->get_id() ) ) { // Admin user
54
+    if (wpinv_current_user_can('view_invoice', array('invoice' => $invoice)) || current_user_can('view_invoices', $invoice->get_id())) { // Admin user
55 55
         return true;
56 56
     }
57 57
 
58 58
     // Else, ensure that this is their invoice.
59
-    if ( is_user_logged_in() && $invoice->get_user_id() == get_current_user_id() ) {
59
+    if (is_user_logged_in() && $invoice->get_user_id() == get_current_user_id()) {
60 60
         return true;
61 61
     }
62 62
 
63
-    return apply_filters( 'wpinv_current_user_can_view_invoice', false, $invoice );
63
+    return apply_filters('wpinv_current_user_can_view_invoice', false, $invoice);
64 64
 }
65 65
 
66 66
 /**
67 67
  * Checks if the current user cna view an invoice receipt.
68 68
  */
69
-function wpinv_can_view_receipt( $invoice ) {
70
-	return (bool) apply_filters( 'wpinv_can_view_receipt', wpinv_user_can_view_invoice( $invoice ), $invoice );
69
+function wpinv_can_view_receipt($invoice) {
70
+	return (bool) apply_filters('wpinv_can_view_receipt', wpinv_user_can_view_invoice($invoice), $invoice);
71 71
 }
72 72
 
73 73
 /**
@@ -77,16 +77,16 @@  discard block
 block discarded – undo
77 77
  */
78 78
 function getpaid_get_invoice_post_types() {
79 79
     $post_types = array(
80
-        'wpi_quote'   => __( 'Quote', 'invoicing' ),
81
-        'wpi_invoice' => __( 'Invoice', 'invoicing' ),
80
+        'wpi_quote'   => __('Quote', 'invoicing'),
81
+        'wpi_invoice' => __('Invoice', 'invoicing'),
82 82
     );
83 83
 
84 84
     // Ensure the quotes addon is installed.
85
-    if ( ! defined( 'WPINV_QUOTES_VERSION' ) ) {
86
-        unset( $post_types['wpi_quote'] );
85
+    if (!defined('WPINV_QUOTES_VERSION')) {
86
+        unset($post_types['wpi_quote']);
87 87
     }
88 88
 
89
-    return apply_filters( 'getpaid_invoice_post_types', $post_types );
89
+    return apply_filters('getpaid_invoice_post_types', $post_types);
90 90
 }
91 91
 
92 92
 /**
@@ -95,8 +95,8 @@  discard block
 block discarded – undo
95 95
  *
96 96
  * @param string $post_type The post type to check for.
97 97
  */
98
-function getpaid_is_invoice_post_type( $post_type ) {
99
-    return is_scalar( $post_type ) && ! empty( $post_type ) && array_key_exists( $post_type, getpaid_get_invoice_post_types() );
98
+function getpaid_is_invoice_post_type($post_type) {
99
+    return is_scalar($post_type) && !empty($post_type) && array_key_exists($post_type, getpaid_get_invoice_post_types());
100 100
 }
101 101
 
102 102
 /**
@@ -106,9 +106,9 @@  discard block
 block discarded – undo
106 106
  * @param  bool  $wp_error       Whether to return false or WP_Error on failure.
107 107
  * @return int|WP_Error|WPInv_Invoice The value 0 or WP_Error on failure. The WPInv_Invoice object on success.
108 108
  */
109
-function wpinv_create_invoice( $data = array(), $deprecated = null, $wp_error = false ) {
109
+function wpinv_create_invoice($data = array(), $deprecated = null, $wp_error = false) {
110 110
     $data['invoice_id'] = 0;
111
-    return wpinv_insert_invoice( $data, $wp_error );
111
+    return wpinv_insert_invoice($data, $wp_error);
112 112
 }
113 113
 
114 114
 /**
@@ -118,35 +118,35 @@  discard block
 block discarded – undo
118 118
  * @param  bool  $wp_error       Whether to return false or WP_Error on failure.
119 119
  * @return int|WP_Error|WPInv_Invoice The value 0 or WP_Error on failure. The WPInv_Invoice object on success.
120 120
  */
121
-function wpinv_update_invoice( $data = array(), $wp_error = false ) {
121
+function wpinv_update_invoice($data = array(), $wp_error = false) {
122 122
 
123 123
     // Backwards compatibility.
124
-    if ( ! empty( $data['ID'] ) ) {
124
+    if (!empty($data['ID'])) {
125 125
         $data['invoice_id'] = $data['ID'];
126 126
     }
127 127
 
128 128
     // Do we have an invoice id?
129
-    if ( empty( $data['invoice_id'] ) ) {
130
-        return $wp_error ? new WP_Error( 'invalid_invoice_id', __( 'Invalid invoice ID.', 'invoicing' ) ) : 0;
129
+    if (empty($data['invoice_id'])) {
130
+        return $wp_error ? new WP_Error('invalid_invoice_id', __('Invalid invoice ID.', 'invoicing')) : 0;
131 131
     }
132 132
 
133 133
     // Retrieve the invoice.
134
-    $invoice = wpinv_get_invoice( $data['invoice_id'] );
134
+    $invoice = wpinv_get_invoice($data['invoice_id']);
135 135
 
136 136
     // And abort if it does not exist.
137
-    if ( empty( $invoice ) ) {
138
-        return $wp_error ? new WP_Error( 'missing_invoice', __( 'Invoice not found.', 'invoicing' ) ) : 0;
137
+    if (empty($invoice)) {
138
+        return $wp_error ? new WP_Error('missing_invoice', __('Invoice not found.', 'invoicing')) : 0;
139 139
     }
140 140
 
141 141
     // Do not update totals for paid / refunded invoices.
142
-    if ( $invoice->is_paid() || $invoice->is_refunded() ) {
142
+    if ($invoice->is_paid() || $invoice->is_refunded()) {
143 143
 
144
-        if ( ! empty( $data['items'] ) || ! empty( $data['cart_details'] ) ) {
145
-            return $wp_error ? new WP_Error( 'paid_invoice', __( 'You can not update cart items for invoices that have already been paid for.', 'invoicing' ) ) : 0;
144
+        if (!empty($data['items']) || !empty($data['cart_details'])) {
145
+            return $wp_error ? new WP_Error('paid_invoice', __('You can not update cart items for invoices that have already been paid for.', 'invoicing')) : 0;
146 146
         }
147 147
 }
148 148
 
149
-    return wpinv_insert_invoice( $data, $wp_error );
149
+    return wpinv_insert_invoice($data, $wp_error);
150 150
 
151 151
 }
152 152
 
@@ -157,62 +157,62 @@  discard block
 block discarded – undo
157 157
  * @param  bool  $wp_error       Whether to return false or WP_Error on failure.
158 158
  * @return int|WP_Error|WPInv_Invoice The value 0 or WP_Error on failure. The WPInv_Invoice object on success.
159 159
  */
160
-function wpinv_insert_invoice( $data = array(), $wp_error = false ) {
160
+function wpinv_insert_invoice($data = array(), $wp_error = false) {
161 161
 
162 162
     // Ensure that we have invoice data.
163
-    if ( empty( $data ) ) {
163
+    if (empty($data)) {
164 164
         return false;
165 165
     }
166 166
 
167 167
     // The invoice id will be provided when updating an invoice.
168
-    $data['invoice_id'] = ! empty( $data['invoice_id'] ) ? (int) $data['invoice_id'] : false;
168
+    $data['invoice_id'] = !empty($data['invoice_id']) ? (int) $data['invoice_id'] : false;
169 169
 
170 170
     // Retrieve the invoice.
171
-    $invoice = new WPInv_Invoice( $data['invoice_id'] );
171
+    $invoice = new WPInv_Invoice($data['invoice_id']);
172 172
 
173 173
     // Do we have an error?
174
-    if ( ! empty( $invoice->last_error ) ) {
175
-        return $wp_error ? new WP_Error( 'invalid_invoice_id', $invoice->last_error ) : 0;
174
+    if (!empty($invoice->last_error)) {
175
+        return $wp_error ? new WP_Error('invalid_invoice_id', $invoice->last_error) : 0;
176 176
     }
177 177
 
178 178
     // Backwards compatibility (billing address).
179
-    if ( ! empty( $data['user_info'] ) ) {
179
+    if (!empty($data['user_info'])) {
180 180
 
181
-        foreach ( $data['user_info'] as $key => $value ) {
181
+        foreach ($data['user_info'] as $key => $value) {
182 182
 
183
-            if ( $key == 'discounts' ) {
183
+            if ($key == 'discounts') {
184 184
                 $value = (array) $value;
185
-                $data['discount_code'] = empty( $value ) ? null : $value[0];
185
+                $data['discount_code'] = empty($value) ? null : $value[0];
186 186
             } else {
187
-                $data[ $key ] = $value;
187
+                $data[$key] = $value;
188 188
             }
189 189
 }
190 190
 }
191 191
 
192 192
     // Backwards compatibility.
193
-    if ( ! empty( $data['payment_details'] ) ) {
193
+    if (!empty($data['payment_details'])) {
194 194
 
195
-        foreach ( $data['payment_details'] as $key => $value ) {
196
-            $data[ $key ] = $value;
195
+        foreach ($data['payment_details'] as $key => $value) {
196
+            $data[$key] = $value;
197 197
         }
198 198
 }
199 199
 
200 200
     // Set up the owner of the invoice.
201
-    $user_id = ! empty( $data['user_id'] ) ? wpinv_clean( $data['user_id'] ) : get_current_user_id();
201
+    $user_id = !empty($data['user_id']) ? wpinv_clean($data['user_id']) : get_current_user_id();
202 202
 
203 203
     // Make sure the user exists.
204
-    if ( ! get_userdata( $user_id ) ) {
205
-        return $wp_error ? new WP_Error( 'wpinv_invalid_user', __( 'There is no user with that ID.', 'invoicing' ) ) : 0;
204
+    if (!get_userdata($user_id)) {
205
+        return $wp_error ? new WP_Error('wpinv_invalid_user', __('There is no user with that ID.', 'invoicing')) : 0;
206 206
     }
207 207
 
208
-    $address = wpinv_get_user_address( $user_id );
208
+    $address = wpinv_get_user_address($user_id);
209 209
 
210
-    foreach ( $address as $key => $value ) {
210
+    foreach ($address as $key => $value) {
211 211
 
212
-        if ( $value == '' ) {
213
-            $address[ $key ] = null;
212
+        if ($value == '') {
213
+            $address[$key] = null;
214 214
         } else {
215
-            $address[ $key ] = wpinv_clean( $value );
215
+            $address[$key] = wpinv_clean($value);
216 216
         }
217 217
 }
218 218
 
@@ -221,101 +221,101 @@  discard block
 block discarded – undo
221 221
         array(
222 222
 
223 223
             // Basic info.
224
-            'template'          => isset( $data['template'] ) ? wpinv_clean( $data['template'] ) : null,
225
-            'email_cc'          => isset( $data['email_cc'] ) ? wpinv_clean( $data['email_cc'] ) : null,
226
-            'date_created'      => isset( $data['created_date'] ) ? wpinv_clean( $data['created_date'] ) : null,
227
-            'due_date'          => isset( $data['due_date'] ) ? wpinv_clean( $data['due_date'] ) : null,
228
-            'date_completed'    => isset( $data['date_completed'] ) ? wpinv_clean( $data['date_completed'] ) : null,
229
-            'number'            => isset( $data['number'] ) ? wpinv_clean( $data['number'] ) : null,
230
-            'key'               => isset( $data['key'] ) ? wpinv_clean( $data['key'] ) : null,
231
-            'status'            => isset( $data['status'] ) ? wpinv_clean( $data['status'] ) : null,
232
-            'post_type'         => isset( $data['post_type'] ) ? wpinv_clean( $data['post_type'] ) : null,
233
-            'user_ip'           => isset( $data['ip'] ) ? wpinv_clean( $data['ip'] ) : wpinv_get_ip(),
234
-            'parent_id'         => isset( $data['parent'] ) ? intval( $data['parent'] ) : null,
235
-            'mode'              => isset( $data['mode'] ) ? wpinv_clean( $data['mode'] ) : null,
236
-            'description'       => isset( $data['description'] ) ? wp_kses_post( $data['description'] ) : null,
224
+            'template'          => isset($data['template']) ? wpinv_clean($data['template']) : null,
225
+            'email_cc'          => isset($data['email_cc']) ? wpinv_clean($data['email_cc']) : null,
226
+            'date_created'      => isset($data['created_date']) ? wpinv_clean($data['created_date']) : null,
227
+            'due_date'          => isset($data['due_date']) ? wpinv_clean($data['due_date']) : null,
228
+            'date_completed'    => isset($data['date_completed']) ? wpinv_clean($data['date_completed']) : null,
229
+            'number'            => isset($data['number']) ? wpinv_clean($data['number']) : null,
230
+            'key'               => isset($data['key']) ? wpinv_clean($data['key']) : null,
231
+            'status'            => isset($data['status']) ? wpinv_clean($data['status']) : null,
232
+            'post_type'         => isset($data['post_type']) ? wpinv_clean($data['post_type']) : null,
233
+            'user_ip'           => isset($data['ip']) ? wpinv_clean($data['ip']) : wpinv_get_ip(),
234
+            'parent_id'         => isset($data['parent']) ? intval($data['parent']) : null,
235
+            'mode'              => isset($data['mode']) ? wpinv_clean($data['mode']) : null,
236
+            'description'       => isset($data['description']) ? wp_kses_post($data['description']) : null,
237 237
 
238 238
             // Payment info.
239
-            'disable_taxes'     => ! empty( $data['disable_taxes'] ),
240
-            'currency'          => isset( $data['currency'] ) ? wpinv_clean( $data['currency'] ) : wpinv_get_currency(),
241
-            'gateway'           => isset( $data['gateway'] ) ? wpinv_clean( $data['gateway'] ) : null,
242
-            'transaction_id'    => isset( $data['transaction_id'] ) ? wpinv_clean( $data['transaction_id'] ) : null,
243
-            'discount_code'     => isset( $data['discount_code'] ) ? wpinv_clean( $data['discount_code'] ) : null,
244
-            'payment_form'      => isset( $data['payment_form'] ) ? intval( $data['payment_form'] ) : null,
245
-            'submission_id'     => isset( $data['submission_id'] ) ? wpinv_clean( $data['submission_id'] ) : null,
246
-            'subscription_id'   => isset( $data['subscription_id'] ) ? wpinv_clean( $data['subscription_id'] ) : null,
247
-            'is_viewed'         => isset( $data['is_viewed'] ) ? wpinv_clean( $data['is_viewed'] ) : null,
248
-            'fees'              => isset( $data['fees'] ) ? wpinv_clean( $data['fees'] ) : null,
249
-            'discounts'         => isset( $data['discounts'] ) ? wpinv_clean( $data['discounts'] ) : null,
250
-            'taxes'             => isset( $data['taxes'] ) ? wpinv_clean( $data['taxes'] ) : null,
239
+            'disable_taxes'     => !empty($data['disable_taxes']),
240
+            'currency'          => isset($data['currency']) ? wpinv_clean($data['currency']) : wpinv_get_currency(),
241
+            'gateway'           => isset($data['gateway']) ? wpinv_clean($data['gateway']) : null,
242
+            'transaction_id'    => isset($data['transaction_id']) ? wpinv_clean($data['transaction_id']) : null,
243
+            'discount_code'     => isset($data['discount_code']) ? wpinv_clean($data['discount_code']) : null,
244
+            'payment_form'      => isset($data['payment_form']) ? intval($data['payment_form']) : null,
245
+            'submission_id'     => isset($data['submission_id']) ? wpinv_clean($data['submission_id']) : null,
246
+            'subscription_id'   => isset($data['subscription_id']) ? wpinv_clean($data['subscription_id']) : null,
247
+            'is_viewed'         => isset($data['is_viewed']) ? wpinv_clean($data['is_viewed']) : null,
248
+            'fees'              => isset($data['fees']) ? wpinv_clean($data['fees']) : null,
249
+            'discounts'         => isset($data['discounts']) ? wpinv_clean($data['discounts']) : null,
250
+            'taxes'             => isset($data['taxes']) ? wpinv_clean($data['taxes']) : null,
251 251
 
252 252
             // Billing details.
253 253
             'user_id'           => $data['user_id'],
254
-            'first_name'        => isset( $data['first_name'] ) ? wpinv_clean( $data['first_name'] ) : $address['first_name'],
255
-            'last_name'         => isset( $data['last_name'] ) ? wpinv_clean( $data['last_name'] ) : $address['last_name'],
256
-            'address'           => isset( $data['address'] ) ? wpinv_clean( $data['address'] ) : $address['address'],
257
-            'vat_number'        => isset( $data['vat_number'] ) ? wpinv_clean( $data['vat_number'] ) : $address['vat_number'],
258
-            'company'           => isset( $data['company'] ) ? wpinv_clean( $data['company'] ) : $address['company'],
259
-            'zip'               => isset( $data['zip'] ) ? wpinv_clean( $data['zip'] ) : $address['zip'],
260
-            'state'             => isset( $data['state'] ) ? wpinv_clean( $data['state'] ) : $address['state'],
261
-            'city'              => isset( $data['city'] ) ? wpinv_clean( $data['city'] ) : $address['city'],
262
-            'country'           => isset( $data['country'] ) ? wpinv_clean( $data['country'] ) : $address['country'],
263
-            'phone'             => isset( $data['phone'] ) ? wpinv_clean( $data['phone'] ) : $address['phone'],
264
-            'address_confirmed' => ! empty( $data['address_confirmed'] ),
254
+            'first_name'        => isset($data['first_name']) ? wpinv_clean($data['first_name']) : $address['first_name'],
255
+            'last_name'         => isset($data['last_name']) ? wpinv_clean($data['last_name']) : $address['last_name'],
256
+            'address'           => isset($data['address']) ? wpinv_clean($data['address']) : $address['address'],
257
+            'vat_number'        => isset($data['vat_number']) ? wpinv_clean($data['vat_number']) : $address['vat_number'],
258
+            'company'           => isset($data['company']) ? wpinv_clean($data['company']) : $address['company'],
259
+            'zip'               => isset($data['zip']) ? wpinv_clean($data['zip']) : $address['zip'],
260
+            'state'             => isset($data['state']) ? wpinv_clean($data['state']) : $address['state'],
261
+            'city'              => isset($data['city']) ? wpinv_clean($data['city']) : $address['city'],
262
+            'country'           => isset($data['country']) ? wpinv_clean($data['country']) : $address['country'],
263
+            'phone'             => isset($data['phone']) ? wpinv_clean($data['phone']) : $address['phone'],
264
+            'address_confirmed' => !empty($data['address_confirmed']),
265 265
 
266 266
         )
267 267
     );
268 268
 
269 269
     // Backwards compatibililty.
270
-    if ( ! empty( $data['cart_details'] ) && is_array( $data['cart_details'] ) ) {
270
+    if (!empty($data['cart_details']) && is_array($data['cart_details'])) {
271 271
         $data['items'] = array();
272 272
 
273
-        foreach ( $data['cart_details'] as $_item ) {
273
+        foreach ($data['cart_details'] as $_item) {
274 274
 
275 275
             // Ensure that we have an item id.
276
-            if ( empty( $_item['id'] ) ) {
276
+            if (empty($_item['id'])) {
277 277
                 continue;
278 278
             }
279 279
 
280 280
             // Retrieve the item.
281
-            $item = new GetPaid_Form_Item( $_item['id'] );
281
+            $item = new GetPaid_Form_Item($_item['id']);
282 282
 
283 283
             // Ensure that it is purchasable.
284
-            if ( ! $item->can_purchase() ) {
284
+            if (!$item->can_purchase()) {
285 285
                 continue;
286 286
             }
287 287
 
288 288
             // Set quantity.
289
-            if ( ! empty( $_item['quantity'] ) && is_numeric( $_item['quantity'] ) ) {
290
-                $item->set_quantity( $_item['quantity'] );
289
+            if (!empty($_item['quantity']) && is_numeric($_item['quantity'])) {
290
+                $item->set_quantity($_item['quantity']);
291 291
             }
292 292
 
293 293
             // Set price.
294
-            if ( isset( $_item['item_price'] ) ) {
295
-                $item->set_price( $_item['item_price'] );
294
+            if (isset($_item['item_price'])) {
295
+                $item->set_price($_item['item_price']);
296 296
             }
297 297
 
298
-            if ( isset( $_item['custom_price'] ) ) {
299
-                $item->set_price( $_item['custom_price'] );
298
+            if (isset($_item['custom_price'])) {
299
+                $item->set_price($_item['custom_price']);
300 300
             }
301 301
 
302 302
             // Set name.
303
-            if ( ! empty( $_item['name'] ) ) {
304
-                $item->set_name( $_item['name'] );
303
+            if (!empty($_item['name'])) {
304
+                $item->set_name($_item['name']);
305 305
             }
306 306
 
307 307
             // Set description.
308
-            if ( isset( $_item['description'] ) ) {
309
-                $item->set_custom_description( $_item['description'] );
308
+            if (isset($_item['description'])) {
309
+                $item->set_custom_description($_item['description']);
310 310
             }
311 311
 
312 312
             // Set meta.
313
-            if ( isset( $_item['meta'] ) && is_array( $_item['meta'] ) ) {
313
+            if (isset($_item['meta']) && is_array($_item['meta'])) {
314 314
 
315
-                $item->set_item_meta( $_item['meta'] );
315
+                $item->set_item_meta($_item['meta']);
316 316
 
317
-                if ( isset( $_item['meta']['description'] ) ) {
318
-                    $item->set_custom_description( $_item['meta']['description'] );
317
+                if (isset($_item['meta']['description'])) {
318
+                    $item->set_custom_description($_item['meta']['description']);
319 319
                 }
320 320
             }
321 321
 
@@ -325,14 +325,14 @@  discard block
 block discarded – undo
325 325
     }
326 326
 
327 327
     // Add invoice items.
328
-    if ( ! empty( $data['items'] ) && is_array( $data['items'] ) ) {
328
+    if (!empty($data['items']) && is_array($data['items'])) {
329 329
 
330
-        $invoice->set_items( array() );
330
+        $invoice->set_items(array());
331 331
 
332
-        foreach ( $data['items'] as $item ) {
332
+        foreach ($data['items'] as $item) {
333 333
 
334
-            if ( is_object( $item ) && is_a( $item, 'GetPaid_Form_Item' ) && $item->can_purchase() ) {
335
-                $invoice->add_item( $item );
334
+            if (is_object($item) && is_a($item, 'GetPaid_Form_Item') && $item->can_purchase()) {
335
+                $invoice->add_item($item);
336 336
             }
337 337
 }
338 338
 }
@@ -341,30 +341,30 @@  discard block
 block discarded – undo
341 341
     $invoice->recalculate_total();
342 342
     $invoice->save();
343 343
 
344
-    if ( ! $invoice->get_id() ) {
345
-        return $wp_error ? new WP_Error( 'wpinv_insert_invoice_error', __( 'An error occured when saving your invoice.', 'invoicing' ) ) : 0;
344
+    if (!$invoice->get_id()) {
345
+        return $wp_error ? new WP_Error('wpinv_insert_invoice_error', __('An error occured when saving your invoice.', 'invoicing')) : 0;
346 346
     }
347 347
 
348 348
     // Add private note.
349
-    if ( ! empty( $data['private_note'] ) ) {
350
-        $invoice->add_note( $data['private_note'] );
349
+    if (!empty($data['private_note'])) {
350
+        $invoice->add_note($data['private_note']);
351 351
     }
352 352
 
353 353
     // User notes.
354
-    if ( ! empty( $data['user_note'] ) ) {
355
-        $invoice->add_note( $data['user_note'], true );
354
+    if (!empty($data['user_note'])) {
355
+        $invoice->add_note($data['user_note'], true);
356 356
     }
357 357
 
358 358
     // Created via.
359
-    if ( isset( $data['created_via'] ) ) {
360
-        update_post_meta( $invoice->get_id(), 'wpinv_created_via', $data['created_via'] );
359
+    if (isset($data['created_via'])) {
360
+        update_post_meta($invoice->get_id(), 'wpinv_created_via', $data['created_via']);
361 361
     }
362 362
 
363 363
     // Backwards compatiblity.
364
-    if ( $invoice->is_quote() ) {
364
+    if ($invoice->is_quote()) {
365 365
 
366
-        if ( isset( $data['valid_until'] ) ) {
367
-            update_post_meta( $invoice->get_id(), 'wpinv_quote_valid_until', $data['valid_until'] );
366
+        if (isset($data['valid_until'])) {
367
+            update_post_meta($invoice->get_id(), 'wpinv_quote_valid_until', $data['valid_until']);
368 368
         }
369 369
 }
370 370
 
@@ -378,20 +378,20 @@  discard block
 block discarded – undo
378 378
  * @param $bool $deprecated
379 379
  * @return WPInv_Invoice|null
380 380
  */
381
-function wpinv_get_invoice( $invoice = 0, $deprecated = false ) {
381
+function wpinv_get_invoice($invoice = 0, $deprecated = false) {
382 382
 
383 383
     // If we are retrieving the invoice from the cart...
384
-    if ( $deprecated && empty( $invoice ) ) {
384
+    if ($deprecated && empty($invoice)) {
385 385
         $invoice = (int) getpaid_get_current_invoice_id();
386 386
     }
387 387
 
388 388
     // Retrieve the invoice.
389
-    if ( ! is_a( $invoice, 'WPInv_Invoice' ) ) {
390
-        $invoice = new WPInv_Invoice( $invoice );
389
+    if (!is_a($invoice, 'WPInv_Invoice')) {
390
+        $invoice = new WPInv_Invoice($invoice);
391 391
     }
392 392
 
393 393
     // Check if it exists.
394
-    if ( $invoice->exists() ) {
394
+    if ($invoice->exists()) {
395 395
         return $invoice;
396 396
     }
397 397
 
@@ -404,15 +404,15 @@  discard block
 block discarded – undo
404 404
  * @param array $args Args to search for.
405 405
  * @return WPInv_Invoice[]|int[]|object
406 406
  */
407
-function wpinv_get_invoices( $args ) {
407
+function wpinv_get_invoices($args) {
408 408
 
409 409
     // Prepare args.
410 410
     $args = wp_parse_args(
411 411
         $args,
412 412
         array(
413
-            'status' => array_keys( wpinv_get_invoice_statuses() ),
413
+            'status' => array_keys(wpinv_get_invoice_statuses()),
414 414
             'type'   => 'wpi_invoice',
415
-            'limit'  => get_option( 'posts_per_page' ),
415
+            'limit'  => get_option('posts_per_page'),
416 416
             'return' => 'objects',
417 417
         )
418 418
     );
@@ -430,24 +430,24 @@  discard block
 block discarded – undo
430 430
         'post__in'       => 'include',
431 431
     );
432 432
 
433
-    foreach ( $map_legacy as $to => $from ) {
434
-        if ( isset( $args[ $from ] ) ) {
435
-            $args[ $to ] = $args[ $from ];
436
-            unset( $args[ $from ] );
433
+    foreach ($map_legacy as $to => $from) {
434
+        if (isset($args[$from])) {
435
+            $args[$to] = $args[$from];
436
+            unset($args[$from]);
437 437
         }
438 438
     }
439 439
 
440 440
     // Backwards compatibility.
441
-    if ( ! empty( $args['email'] ) && empty( $args['user'] ) ) {
441
+    if (!empty($args['email']) && empty($args['user'])) {
442 442
         $args['user'] = $args['email'];
443
-        unset( $args['email'] );
443
+        unset($args['email']);
444 444
     }
445 445
 
446 446
     // Handle cases where the user is set as an email.
447
-    if ( ! empty( $args['author'] ) && is_email( $args['author'] ) ) {
448
-        $user = get_user_by( 'email', $args['user'] );
447
+    if (!empty($args['author']) && is_email($args['author'])) {
448
+        $user = get_user_by('email', $args['user']);
449 449
 
450
-        if ( $user ) {
450
+        if ($user) {
451 451
             $args['author'] = $user->user_email;
452 452
         }
453 453
 }
@@ -457,31 +457,31 @@  discard block
 block discarded – undo
457 457
 
458 458
     // Show all posts.
459 459
     $paginate = true;
460
-    if ( isset( $args['paginate'] ) ) {
460
+    if (isset($args['paginate'])) {
461 461
 
462 462
         $paginate = $args['paginate'];
463
-        $args['no_found_rows'] = empty( $args['paginate'] );
464
-        unset( $args['paginate'] );
463
+        $args['no_found_rows'] = empty($args['paginate']);
464
+        unset($args['paginate']);
465 465
 
466 466
     }
467 467
 
468 468
     // Whether to return objects or fields.
469 469
     $return = $args['return'];
470
-    unset( $args['return'] );
470
+    unset($args['return']);
471 471
 
472 472
     // Get invoices.
473
-    $invoices = new WP_Query( apply_filters( 'wpinv_get_invoices_args', $args ) );
473
+    $invoices = new WP_Query(apply_filters('wpinv_get_invoices_args', $args));
474 474
 
475 475
     // Prepare the results.
476
-    if ( 'objects' === $return ) {
477
-        $results = array_map( 'wpinv_get_invoice', $invoices->posts );
478
-    } elseif ( 'self' === $return ) {
476
+    if ('objects' === $return) {
477
+        $results = array_map('wpinv_get_invoice', $invoices->posts);
478
+    } elseif ('self' === $return) {
479 479
         return $invoices;
480 480
     } else {
481 481
         $results = $invoices->posts;
482 482
     }
483 483
 
484
-    if ( $paginate ) {
484
+    if ($paginate) {
485 485
         return (object) array(
486 486
             'invoices'      => $results,
487 487
             'total'         => $invoices->found_posts,
@@ -499,8 +499,8 @@  discard block
 block discarded – undo
499 499
  * @param string $transaction_id The transaction id to check.
500 500
  * @return int Invoice id on success or 0 on failure
501 501
  */
502
-function wpinv_get_id_by_transaction_id( $transaction_id ) {
503
-    return WPInv_Invoice::get_invoice_id_by_field( $transaction_id, 'transaction_id' );
502
+function wpinv_get_id_by_transaction_id($transaction_id) {
503
+    return WPInv_Invoice::get_invoice_id_by_field($transaction_id, 'transaction_id');
504 504
 }
505 505
 
506 506
 /**
@@ -509,8 +509,8 @@  discard block
 block discarded – undo
509 509
  * @param string $invoice_number The invoice number to check.
510 510
  * @return int Invoice id on success or 0 on failure
511 511
  */
512
-function wpinv_get_id_by_invoice_number( $invoice_number ) {
513
-    return WPInv_Invoice::get_invoice_id_by_field( $invoice_number, 'number' );
512
+function wpinv_get_id_by_invoice_number($invoice_number) {
513
+    return WPInv_Invoice::get_invoice_id_by_field($invoice_number, 'number');
514 514
 }
515 515
 
516 516
 /**
@@ -519,8 +519,8 @@  discard block
 block discarded – undo
519 519
  * @param string $invoice_key The invoice key to check.
520 520
  * @return int Invoice id on success or 0 on failure
521 521
  */
522
-function wpinv_get_invoice_id_by_key( $invoice_key ) {
523
-    return WPInv_Invoice::get_invoice_id_by_field( $invoice_key, 'key' );
522
+function wpinv_get_invoice_id_by_key($invoice_key) {
523
+    return WPInv_Invoice::get_invoice_id_by_field($invoice_key, 'key');
524 524
 }
525 525
 
526 526
 /**
@@ -530,19 +530,19 @@  discard block
 block discarded – undo
530 530
  * @param string $type Optionally filter by type i.e customer|system
531 531
  * @return array|null
532 532
  */
533
-function wpinv_get_invoice_notes( $invoice = 0, $type = '' ) {
533
+function wpinv_get_invoice_notes($invoice = 0, $type = '') {
534 534
 
535 535
     // Prepare the invoice.
536
-    $invoice = wpinv_get_invoice( $invoice );
537
-    if ( empty( $invoice ) ) {
536
+    $invoice = wpinv_get_invoice($invoice);
537
+    if (empty($invoice)) {
538 538
         return null;
539 539
     }
540 540
 
541 541
     // Fetch notes.
542
-    $notes = getpaid_notes()->get_invoice_notes( $invoice->get_id(), $type );
542
+    $notes = getpaid_notes()->get_invoice_notes($invoice->get_id(), $type);
543 543
 
544 544
     // Filter the notes.
545
-    return apply_filters( 'wpinv_invoice_notes', $notes, $invoice->get_id(), $type );
545
+    return apply_filters('wpinv_invoice_notes', $notes, $invoice->get_id(), $type);
546 546
 }
547 547
 
548 548
 /**
@@ -550,10 +550,10 @@  discard block
 block discarded – undo
550 550
  *
551 551
  * @param string $post_type
552 552
  */
553
-function wpinv_get_user_invoices_columns( $post_type = 'wpi_invoice' ) {
553
+function wpinv_get_user_invoices_columns($post_type = 'wpi_invoice') {
554 554
 
555
-    $label   = getpaid_get_post_type_label( $post_type, false );
556
-    $label   = empty( $label ) ? __( 'Invoice', 'invoicing' ) : sanitize_text_field( $label );
555
+    $label   = getpaid_get_post_type_label($post_type, false);
556
+    $label   = empty($label) ? __('Invoice', 'invoicing') : sanitize_text_field($label);
557 557
     $columns = array(
558 558
 
559 559
 		'invoice-number'  => array(
@@ -562,22 +562,22 @@  discard block
 block discarded – undo
562 562
 		),
563 563
 
564 564
 		'created-date'    => array(
565
-			'title' => __( 'Created Date', 'invoicing' ),
565
+			'title' => __('Created Date', 'invoicing'),
566 566
 			'class' => 'text-left',
567 567
 		),
568 568
 
569 569
 		'payment-date'    => array(
570
-			'title' => __( 'Payment Date', 'invoicing' ),
570
+			'title' => __('Payment Date', 'invoicing'),
571 571
 			'class' => 'text-left',
572 572
 		),
573 573
 
574 574
 		'invoice-status'  => array(
575
-			'title' => __( 'Status', 'invoicing' ),
575
+			'title' => __('Status', 'invoicing'),
576 576
 			'class' => 'text-center',
577 577
 		),
578 578
 
579 579
 		'invoice-total'   => array(
580
-			'title' => __( 'Total', 'invoicing' ),
580
+			'title' => __('Total', 'invoicing'),
581 581
 			'class' => 'text-right',
582 582
 		),
583 583
 
@@ -588,7 +588,7 @@  discard block
 block discarded – undo
588 588
 
589 589
 	);
590 590
 
591
-    return apply_filters( 'wpinv_user_invoices_columns', $columns, $post_type );
591
+    return apply_filters('wpinv_user_invoices_columns', $columns, $post_type);
592 592
 }
593 593
 
594 594
 /**
@@ -598,59 +598,59 @@  discard block
 block discarded – undo
598 598
 
599 599
     // Find the invoice.
600 600
     $invoice_id = getpaid_get_current_invoice_id();
601
-    $invoice = new WPInv_Invoice( $invoice_id );
601
+    $invoice = new WPInv_Invoice($invoice_id);
602 602
 
603 603
     // Abort if non was found.
604
-    if ( empty( $invoice_id ) || $invoice->is_draft() ) {
604
+    if (empty($invoice_id) || $invoice->is_draft()) {
605 605
 
606 606
         return aui()->alert(
607 607
             array(
608 608
                 'type'    => 'warning',
609
-                'content' => __( 'We could not find your invoice', 'invoicing' ),
609
+                'content' => __('We could not find your invoice', 'invoicing'),
610 610
             )
611 611
         );
612 612
 
613 613
     }
614 614
 
615 615
     // Can the user view this invoice?
616
-    if ( ! wpinv_can_view_receipt( $invoice_id ) ) {
616
+    if (!wpinv_can_view_receipt($invoice_id)) {
617 617
 
618 618
         return aui()->alert(
619 619
             array(
620 620
                 'type'    => 'warning',
621
-                'content' => __( 'You are not allowed to view this receipt', 'invoicing' ),
621
+                'content' => __('You are not allowed to view this receipt', 'invoicing'),
622 622
             )
623 623
         );
624 624
 
625 625
     }
626 626
 
627 627
     // Load the template.
628
-    return wpinv_get_template_html( 'invoice-receipt.php', compact( 'invoice' ) );
628
+    return wpinv_get_template_html('invoice-receipt.php', compact('invoice'));
629 629
 
630 630
 }
631 631
 
632 632
 /**
633 633
  * Displays the invoice history.
634 634
  */
635
-function getpaid_invoice_history( $user_id = 0, $post_type = 'wpi_invoice' ) {
635
+function getpaid_invoice_history($user_id = 0, $post_type = 'wpi_invoice') {
636 636
 
637 637
     // Ensure that we have a user id.
638
-    if ( empty( $user_id ) || ! is_numeric( $user_id ) ) {
638
+    if (empty($user_id) || !is_numeric($user_id)) {
639 639
         $user_id = get_current_user_id();
640 640
     }
641 641
 
642
-    $label = getpaid_get_post_type_label( $post_type );
643
-    $label = empty( $label ) ? __( 'Invoices', 'invoicing' ) : sanitize_text_field( $label );
642
+    $label = getpaid_get_post_type_label($post_type);
643
+    $label = empty($label) ? __('Invoices', 'invoicing') : sanitize_text_field($label);
644 644
 
645 645
     // View user id.
646
-    if ( empty( $user_id ) ) {
646
+    if (empty($user_id)) {
647 647
 
648 648
         return aui()->alert(
649 649
             array(
650 650
                 'type'    => 'warning',
651 651
                 'content' => sprintf(
652
-                    __( 'You must be logged in to view your %s.', 'invoicing' ),
653
-                    strtolower( $label )
652
+                    __('You must be logged in to view your %s.', 'invoicing'),
653
+                    strtolower($label)
654 654
                 ),
655 655
             )
656 656
         );
@@ -660,22 +660,22 @@  discard block
 block discarded – undo
660 660
     // Fetch invoices.
661 661
     $invoices = wpinv_get_invoices(
662 662
         array(
663
-            'page'     => ( get_query_var( 'paged' ) ) ? absint( get_query_var( 'paged' ) ) : 1,
663
+            'page'     => (get_query_var('paged')) ? absint(get_query_var('paged')) : 1,
664 664
             'user'     => $user_id,
665 665
             'paginate' => true,
666 666
             'type'     => $post_type,
667
-            'status'   => array_keys( wpinv_get_invoice_statuses( false, false, $post_type ) ),
667
+            'status'   => array_keys(wpinv_get_invoice_statuses(false, false, $post_type)),
668 668
         )
669 669
     );
670 670
 
671
-    if ( empty( $invoices->total ) ) {
671
+    if (empty($invoices->total)) {
672 672
 
673 673
         return aui()->alert(
674 674
             array(
675 675
                 'type'    => 'info',
676 676
                 'content' => sprintf(
677
-                    __( 'No %s found.', 'invoicing' ),
678
-                    strtolower( $label )
677
+                    __('No %s found.', 'invoicing'),
678
+                    strtolower($label)
679 679
                 ),
680 680
             )
681 681
         );
@@ -683,38 +683,38 @@  discard block
 block discarded – undo
683 683
     }
684 684
 
685 685
     // Load the template.
686
-    return wpinv_get_template_html( 'invoice-history.php', compact( 'invoices', 'post_type' ) );
686
+    return wpinv_get_template_html('invoice-history.php', compact('invoices', 'post_type'));
687 687
 
688 688
 }
689 689
 
690 690
 /**
691 691
  * Formats an invoice number given an invoice type.
692 692
  */
693
-function wpinv_format_invoice_number( $number, $type = '' ) {
693
+function wpinv_format_invoice_number($number, $type = '') {
694 694
 
695 695
     // Allow other plugins to overide this.
696
-    $check = apply_filters( 'wpinv_pre_format_invoice_number', null, $number, $type );
697
-    if ( null !== $check ) {
696
+    $check = apply_filters('wpinv_pre_format_invoice_number', null, $number, $type);
697
+    if (null !== $check) {
698 698
         return $check;
699 699
     }
700 700
 
701 701
     // Ensure that we have a numeric number.
702
-    if ( ! is_numeric( $number ) ) {
702
+    if (!is_numeric($number)) {
703 703
         return $number;
704 704
     }
705 705
 
706 706
     // Format the number.
707
-    $padd             = absint( (int) wpinv_get_option( 'invoice_number_padd', 5 ) );
708
-    $prefix           = sanitize_text_field( (string) wpinv_get_option( 'invoice_number_prefix', 'INV-' ) );
709
-    $prefix           = sanitize_text_field( apply_filters( 'getpaid_invoice_type_prefix', $prefix, $type ) );
710
-    $postfix          = sanitize_text_field( (string) wpinv_get_option( 'invoice_number_postfix' ) );
711
-    $postfix          = sanitize_text_field( apply_filters( 'getpaid_invoice_type_postfix', $postfix, $type ) );
712
-    $formatted_number = zeroise( absint( $number ), $padd );
707
+    $padd             = absint((int) wpinv_get_option('invoice_number_padd', 5));
708
+    $prefix           = sanitize_text_field((string) wpinv_get_option('invoice_number_prefix', 'INV-'));
709
+    $prefix           = sanitize_text_field(apply_filters('getpaid_invoice_type_prefix', $prefix, $type));
710
+    $postfix          = sanitize_text_field((string) wpinv_get_option('invoice_number_postfix'));
711
+    $postfix          = sanitize_text_field(apply_filters('getpaid_invoice_type_postfix', $postfix, $type));
712
+    $formatted_number = zeroise(absint($number), $padd);
713 713
 
714 714
     // Add the prefix and post fix.
715 715
     $formatted_number = $prefix . $formatted_number . $postfix;
716 716
 
717
-    return apply_filters( 'wpinv_format_invoice_number', $formatted_number, $number, $prefix, $postfix, $padd );
717
+    return apply_filters('wpinv_format_invoice_number', $formatted_number, $number, $prefix, $postfix, $padd);
718 718
 }
719 719
 
720 720
 /**
@@ -723,58 +723,58 @@  discard block
 block discarded – undo
723 723
  * @param string $type.
724 724
  * @return int|null|bool
725 725
  */
726
-function wpinv_get_next_invoice_number( $type = '' ) {
726
+function wpinv_get_next_invoice_number($type = '') {
727 727
 
728 728
     // Allow plugins to overide this.
729
-    $check = apply_filters( 'wpinv_get_pre_next_invoice_number', null, $type );
730
-    if ( null !== $check ) {
729
+    $check = apply_filters('wpinv_get_pre_next_invoice_number', null, $type);
730
+    if (null !== $check) {
731 731
         return $check;
732 732
     }
733 733
 
734 734
     // Ensure sequential invoice numbers is active.
735
-    if ( ! wpinv_sequential_number_active() ) {
735
+    if (!wpinv_sequential_number_active()) {
736 736
         return false;
737 737
     }
738 738
 
739 739
     // Retrieve the current number and the start number.
740
-    $number = (int) get_option( 'wpinv_last_invoice_number', 0 );
741
-    $start  = absint( (int) wpinv_get_option( 'invoice_sequence_start', 1 ) );
740
+    $number = (int) get_option('wpinv_last_invoice_number', 0);
741
+    $start  = absint((int) wpinv_get_option('invoice_sequence_start', 1));
742 742
 
743 743
     // Ensure that we are starting at a positive integer.
744
-    $start  = max( $start, 1 );
744
+    $start  = max($start, 1);
745 745
 
746 746
     // If this is the first invoice, use the start number.
747
-    $number = max( $start, $number );
747
+    $number = max($start, $number);
748 748
 
749 749
     // Format the invoice number.
750
-    $formatted_number = wpinv_format_invoice_number( $number, $type );
750
+    $formatted_number = wpinv_format_invoice_number($number, $type);
751 751
 
752 752
     // Ensure that this number is unique.
753
-    $invoice_id = WPInv_Invoice::get_invoice_id_by_field( $formatted_number, 'number' );
753
+    $invoice_id = WPInv_Invoice::get_invoice_id_by_field($formatted_number, 'number');
754 754
 
755 755
     // We found a match. Nice.
756
-    if ( empty( $invoice_id ) ) {
757
-        update_option( 'wpinv_last_invoice_number', $number );
758
-        return apply_filters( 'wpinv_get_next_invoice_number', $number );
756
+    if (empty($invoice_id)) {
757
+        update_option('wpinv_last_invoice_number', $number);
758
+        return apply_filters('wpinv_get_next_invoice_number', $number);
759 759
     }
760 760
 
761
-    update_option( 'wpinv_last_invoice_number', $number + 1 );
762
-    return wpinv_get_next_invoice_number( $type );
761
+    update_option('wpinv_last_invoice_number', $number + 1);
762
+    return wpinv_get_next_invoice_number($type);
763 763
 
764 764
 }
765 765
 
766 766
 /**
767 767
  * The prefix used for invoice paths.
768 768
  */
769
-function wpinv_post_name_prefix( $post_type = 'wpi_invoice' ) {
770
-    return apply_filters( 'wpinv_post_name_prefix', 'inv-', $post_type );
769
+function wpinv_post_name_prefix($post_type = 'wpi_invoice') {
770
+    return apply_filters('wpinv_post_name_prefix', 'inv-', $post_type);
771 771
 }
772 772
 
773
-function wpinv_generate_post_name( $post_ID ) {
774
-    $prefix = wpinv_post_name_prefix( get_post_type( $post_ID ) );
775
-    $post_name = sanitize_title( $prefix . $post_ID );
773
+function wpinv_generate_post_name($post_ID) {
774
+    $prefix = wpinv_post_name_prefix(get_post_type($post_ID));
775
+    $post_name = sanitize_title($prefix . $post_ID);
776 776
 
777
-    return apply_filters( 'wpinv_generate_post_name', $post_name, $post_ID, $prefix );
777
+    return apply_filters('wpinv_generate_post_name', $post_name, $post_ID, $prefix);
778 778
 }
779 779
 
780 780
 /**
@@ -782,8 +782,8 @@  discard block
 block discarded – undo
782 782
  *
783 783
  * @param int|string|object|WPInv_Invoice|WPInv_Legacy_Invoice|WP_Post $invoice Invoice id, key, transaction id, number or object.
784 784
  */
785
-function wpinv_is_invoice_viewed( $invoice ) {
786
-    $invoice = new WPInv_Invoice( $invoice );
785
+function wpinv_is_invoice_viewed($invoice) {
786
+    $invoice = new WPInv_Invoice($invoice);
787 787
     return (bool) $invoice->get_is_viewed();
788 788
 }
789 789
 
@@ -792,17 +792,17 @@  discard block
 block discarded – undo
792 792
  *
793 793
  * @param int|string|object|WPInv_Invoice|WPInv_Legacy_Invoice|WP_Post $invoice Invoice id, key, transaction id, number or object.
794 794
  */
795
-function getpaid_maybe_mark_invoice_as_viewed( $invoice ) {
796
-    $invoice = new WPInv_Invoice( $invoice );
795
+function getpaid_maybe_mark_invoice_as_viewed($invoice) {
796
+    $invoice = new WPInv_Invoice($invoice);
797 797
 
798
-    if ( get_current_user_id() == $invoice->get_user_id() && ! $invoice->get_is_viewed() ) {
799
-        $invoice->set_is_viewed( true );
798
+    if (get_current_user_id() == $invoice->get_user_id() && !$invoice->get_is_viewed()) {
799
+        $invoice->set_is_viewed(true);
800 800
         $invoice->save();
801 801
     }
802 802
 
803 803
 }
804
-add_action( 'wpinv_invoice_print_before_display', 'getpaid_maybe_mark_invoice_as_viewed' );
805
-add_action( 'wpinv_before_receipt', 'getpaid_maybe_mark_invoice_as_viewed' );
804
+add_action('wpinv_invoice_print_before_display', 'getpaid_maybe_mark_invoice_as_viewed');
805
+add_action('wpinv_before_receipt', 'getpaid_maybe_mark_invoice_as_viewed');
806 806
 
807 807
 /**
808 808
  * Processes an invoice refund.
@@ -811,26 +811,26 @@  discard block
 block discarded – undo
811 811
  * @param array $status_transition
812 812
  * @todo: descrease customer/store earnings
813 813
  */
814
-function getpaid_maybe_process_refund( $invoice, $status_transition ) {
814
+function getpaid_maybe_process_refund($invoice, $status_transition) {
815 815
 
816
-    if ( empty( $status_transition['from'] ) || ! in_array( $status_transition['from'], array( 'publish', 'wpi-processing', 'wpi-renewal' ) ) ) {
816
+    if (empty($status_transition['from']) || !in_array($status_transition['from'], array('publish', 'wpi-processing', 'wpi-renewal'))) {
817 817
         return;
818 818
     }
819 819
 
820 820
     $discount_code = $invoice->get_discount_code();
821
-    if ( ! empty( $discount_code ) ) {
822
-        $discount = wpinv_get_discount_obj( $discount_code );
821
+    if (!empty($discount_code)) {
822
+        $discount = wpinv_get_discount_obj($discount_code);
823 823
 
824
-        if ( $discount->exists() ) {
824
+        if ($discount->exists()) {
825 825
             $discount->increase_usage( -1 );
826 826
         }
827 827
 }
828 828
 
829
-    do_action( 'wpinv_pre_refund_invoice', $invoice, $invoice->get_id() );
830
-    do_action( 'wpinv_refund_invoice', $invoice, $invoice->get_id() );
831
-    do_action( 'wpinv_post_refund_invoice', $invoice, $invoice->get_id() );
829
+    do_action('wpinv_pre_refund_invoice', $invoice, $invoice->get_id());
830
+    do_action('wpinv_refund_invoice', $invoice, $invoice->get_id());
831
+    do_action('wpinv_post_refund_invoice', $invoice, $invoice->get_id());
832 832
 }
833
-add_action( 'getpaid_invoice_status_wpi-refunded', 'getpaid_maybe_process_refund', 10, 2 );
833
+add_action('getpaid_invoice_status_wpi-refunded', 'getpaid_maybe_process_refund', 10, 2);
834 834
 
835 835
 
836 836
 /**
@@ -838,47 +838,47 @@  discard block
 block discarded – undo
838 838
  *
839 839
  * @param int $invoice_id
840 840
  */
841
-function getpaid_process_invoice_payment( $invoice_id ) {
841
+function getpaid_process_invoice_payment($invoice_id) {
842 842
 
843 843
     // Fetch the invoice.
844
-    $invoice = new WPInv_Invoice( $invoice_id );
844
+    $invoice = new WPInv_Invoice($invoice_id);
845 845
 
846 846
     // We only want to do this once.
847
-    if ( 1 == get_post_meta( $invoice->get_id(), 'wpinv_processed_payment', true ) ) {
847
+    if (1 == get_post_meta($invoice->get_id(), 'wpinv_processed_payment', true)) {
848 848
         return;
849 849
     }
850 850
 
851
-    update_post_meta( $invoice->get_id(), 'wpinv_processed_payment', 1 );
851
+    update_post_meta($invoice->get_id(), 'wpinv_processed_payment', 1);
852 852
 
853 853
     // Fires when processing a payment.
854
-    do_action( 'getpaid_process_payment', $invoice );
854
+    do_action('getpaid_process_payment', $invoice);
855 855
 
856 856
     // Fire an action for each invoice item.
857
-    foreach ( $invoice->get_items() as $item ) {
858
-        do_action( 'getpaid_process_item_payment', $item, $invoice );
857
+    foreach ($invoice->get_items() as $item) {
858
+        do_action('getpaid_process_item_payment', $item, $invoice);
859 859
     }
860 860
 
861 861
     // Increase discount usage.
862 862
     $discount_code = $invoice->get_discount_code();
863
-    if ( ! empty( $discount_code ) && ! $invoice->is_renewal() ) {
864
-        $discount = wpinv_get_discount_obj( $discount_code );
863
+    if (!empty($discount_code) && !$invoice->is_renewal()) {
864
+        $discount = wpinv_get_discount_obj($discount_code);
865 865
 
866
-        if ( $discount->exists() ) {
866
+        if ($discount->exists()) {
867 867
             $discount->increase_usage();
868 868
         }
869 869
 }
870 870
 
871 871
     // Record reverse vat.
872
-    if ( 'invoice' === $invoice->get_type() && wpinv_use_taxes() && ! $invoice->get_disable_taxes() ) {
872
+    if ('invoice' === $invoice->get_type() && wpinv_use_taxes() && !$invoice->get_disable_taxes()) {
873 873
 
874 874
         $taxes = $invoice->get_total_tax();
875
-        if ( empty( $taxes ) && GetPaid_Payment_Form_Submission_Taxes::is_eu_transaction( $invoice->get_country() ) ) {
876
-            $invoice->add_note( __( 'VAT was reverse charged', 'invoicing' ), false, false, true );
875
+        if (empty($taxes) && GetPaid_Payment_Form_Submission_Taxes::is_eu_transaction($invoice->get_country())) {
876
+            $invoice->add_note(__('VAT was reverse charged', 'invoicing'), false, false, true);
877 877
         }
878 878
 }
879 879
 
880 880
 }
881
-add_action( 'getpaid_invoice_payment_status_changed', 'getpaid_process_invoice_payment' );
881
+add_action('getpaid_invoice_payment_status_changed', 'getpaid_process_invoice_payment');
882 882
 
883 883
 /**
884 884
  * Returns an array of invoice item columns
@@ -886,13 +886,13 @@  discard block
 block discarded – undo
886 886
  * @param int|WPInv_Invoice $invoice
887 887
  * @return array
888 888
  */
889
-function getpaid_invoice_item_columns( $invoice ) {
889
+function getpaid_invoice_item_columns($invoice) {
890 890
 
891 891
     // Prepare the invoice.
892
-    $invoice = new WPInv_Invoice( $invoice );
892
+    $invoice = new WPInv_Invoice($invoice);
893 893
 
894 894
     // Abort if there is no invoice.
895
-    if ( 0 == $invoice->get_id() ) {
895
+    if (0 == $invoice->get_id()) {
896 896
         return array();
897 897
     }
898 898
 
@@ -900,52 +900,52 @@  discard block
 block discarded – undo
900 900
     $columns = apply_filters(
901 901
         'getpaid_invoice_item_columns',
902 902
         array(
903
-            'name'     => __( 'Item', 'invoicing' ),
904
-            'price'    => __( 'Price', 'invoicing' ),
905
-            'tax_rate' => __( 'Tax Rate', 'invoicing' ),
906
-            'quantity' => __( 'Quantity', 'invoicing' ),
907
-            'subtotal' => __( 'Item Subtotal', 'invoicing' ),
903
+            'name'     => __('Item', 'invoicing'),
904
+            'price'    => __('Price', 'invoicing'),
905
+            'tax_rate' => __('Tax Rate', 'invoicing'),
906
+            'quantity' => __('Quantity', 'invoicing'),
907
+            'subtotal' => __('Item Subtotal', 'invoicing'),
908 908
         ),
909 909
         $invoice
910 910
     );
911 911
 
912 912
     // Quantities.
913
-    if ( isset( $columns['quantity'] ) ) {
913
+    if (isset($columns['quantity'])) {
914 914
 
915
-        if ( 'hours' == $invoice->get_template() ) {
916
-            $columns['quantity'] = __( 'Hours', 'invoicing' );
915
+        if ('hours' == $invoice->get_template()) {
916
+            $columns['quantity'] = __('Hours', 'invoicing');
917 917
         }
918 918
 
919
-        if ( ! wpinv_item_quantities_enabled() || 'amount' == $invoice->get_template() ) {
920
-            unset( $columns['quantity'] );
919
+        if (!wpinv_item_quantities_enabled() || 'amount' == $invoice->get_template()) {
920
+            unset($columns['quantity']);
921 921
         }
922 922
     }
923 923
 
924 924
     // Price.
925
-    if ( isset( $columns['price'] ) ) {
925
+    if (isset($columns['price'])) {
926 926
 
927
-        if ( 'amount' == $invoice->get_template() ) {
928
-            $columns['price'] = __( 'Amount', 'invoicing' );
927
+        if ('amount' == $invoice->get_template()) {
928
+            $columns['price'] = __('Amount', 'invoicing');
929 929
         }
930 930
 
931
-        if ( 'hours' == $invoice->get_template() ) {
932
-            $columns['price'] = __( 'Rate', 'invoicing' );
931
+        if ('hours' == $invoice->get_template()) {
932
+            $columns['price'] = __('Rate', 'invoicing');
933 933
         }
934 934
 }
935 935
 
936 936
     // Sub total.
937
-    if ( isset( $columns['subtotal'] ) ) {
937
+    if (isset($columns['subtotal'])) {
938 938
 
939
-        if ( 'amount' == $invoice->get_template() ) {
940
-            unset( $columns['subtotal'] );
939
+        if ('amount' == $invoice->get_template()) {
940
+            unset($columns['subtotal']);
941 941
         }
942 942
 }
943 943
 
944 944
     // Tax rates.
945
-    if ( isset( $columns['tax_rate'] ) ) {
945
+    if (isset($columns['tax_rate'])) {
946 946
 
947
-        if ( 0 == $invoice->get_total_tax() ) {
948
-            unset( $columns['tax_rate'] );
947
+        if (0 == $invoice->get_total_tax()) {
948
+            unset($columns['tax_rate']);
949 949
         }
950 950
     }
951 951
 
@@ -958,53 +958,53 @@  discard block
 block discarded – undo
958 958
  * @param int|WPInv_Invoice $invoice
959 959
  * @return array
960 960
  */
961
-function getpaid_invoice_totals_rows( $invoice ) {
961
+function getpaid_invoice_totals_rows($invoice) {
962 962
 
963 963
     // Prepare the invoice.
964
-    $invoice = new WPInv_Invoice( $invoice );
964
+    $invoice = new WPInv_Invoice($invoice);
965 965
 
966 966
     // Abort if there is no invoice.
967
-    if ( 0 == $invoice->get_id() ) {
967
+    if (0 == $invoice->get_id()) {
968 968
         return array();
969 969
     }
970 970
 
971 971
     $totals = apply_filters(
972 972
         'getpaid_invoice_totals_rows',
973 973
         array(
974
-            'subtotal' => __( 'Subtotal', 'invoicing' ),
975
-            'shipping' => __( 'Shipping', 'invoicing' ),
976
-            'tax'      => __( 'Tax', 'invoicing' ),
977
-            'fee'      => __( 'Fee', 'invoicing' ),
978
-            'discount' => __( 'Discount', 'invoicing' ),
979
-            'total'    => __( 'Total', 'invoicing' ),
974
+            'subtotal' => __('Subtotal', 'invoicing'),
975
+            'shipping' => __('Shipping', 'invoicing'),
976
+            'tax'      => __('Tax', 'invoicing'),
977
+            'fee'      => __('Fee', 'invoicing'),
978
+            'discount' => __('Discount', 'invoicing'),
979
+            'total'    => __('Total', 'invoicing'),
980 980
         ),
981 981
         $invoice
982 982
     );
983 983
 
984
-    if ( ! $invoice->has_shipping() ) {
985
-        unset( $totals['shipping'] );
984
+    if (!$invoice->has_shipping()) {
985
+        unset($totals['shipping']);
986 986
     }
987 987
 
988
-    if ( ( $invoice->get_disable_taxes() || ! wpinv_use_taxes() ) && isset( $totals['tax'] ) ) {
989
-        unset( $totals['tax'] );
988
+    if (($invoice->get_disable_taxes() || !wpinv_use_taxes()) && isset($totals['tax'])) {
989
+        unset($totals['tax']);
990 990
     }
991 991
 
992 992
     // If we have taxes, display individual taxes.
993
-    if ( isset( $totals['tax'] ) && wpinv_display_individual_tax_rates() ) {
993
+    if (isset($totals['tax']) && wpinv_display_individual_tax_rates()) {
994 994
 
995 995
         $new_totals = array();
996
-        foreach ( $totals as $key => $label ) {
996
+        foreach ($totals as $key => $label) {
997 997
 
998
-            if ( 'tax' !== $key ) {
999
-                $new_totals[ $key ] = $label;
998
+            if ('tax' !== $key) {
999
+                $new_totals[$key] = $label;
1000 1000
                 continue;
1001 1001
             }
1002 1002
 
1003
-            $taxes = array_keys( $invoice->get_taxes() );
1004
-            if ( ! empty( $taxes ) ) {
1003
+            $taxes = array_keys($invoice->get_taxes());
1004
+            if (!empty($taxes)) {
1005 1005
 
1006
-                foreach ( $taxes as $tax ) {
1007
-                    $new_totals[ 'tax__' . $tax ] = $tax;
1006
+                foreach ($taxes as $tax) {
1007
+                    $new_totals['tax__' . $tax] = $tax;
1008 1008
                 }
1009 1009
             }
1010 1010
         }
@@ -1012,12 +1012,12 @@  discard block
 block discarded – undo
1012 1012
         $totals = $new_totals;
1013 1013
     }
1014 1014
 
1015
-    if ( 0 == $invoice->get_total_fees() && isset( $totals['fee'] ) ) {
1016
-        unset( $totals['fee'] );
1015
+    if (0 == $invoice->get_total_fees() && isset($totals['fee'])) {
1016
+        unset($totals['fee']);
1017 1017
     }
1018 1018
 
1019
-    if ( 0 == $invoice->get_total_discount() && isset( $totals['discount'] ) ) {
1020
-        unset( $totals['discount'] );
1019
+    if (0 == $invoice->get_total_discount() && isset($totals['discount'])) {
1020
+        unset($totals['discount']);
1021 1021
     }
1022 1022
 
1023 1023
     return $totals;
@@ -1028,47 +1028,47 @@  discard block
 block discarded – undo
1028 1028
  *
1029 1029
  * @param WPInv_Invoice $invoice
1030 1030
  */
1031
-function getpaid_new_invoice( $invoice ) {
1031
+function getpaid_new_invoice($invoice) {
1032 1032
 
1033
-    if ( ! $invoice->get_status() ) {
1033
+    if (!$invoice->get_status()) {
1034 1034
         return;
1035 1035
     }
1036 1036
 
1037 1037
     // Add an invoice created note.
1038 1038
     $invoice->add_note(
1039 1039
         sprintf(
1040
-            __( '%1$s created with the status "%2$s".', 'invoicing' ),
1041
-            ucfirst( $invoice->get_invoice_quote_type() ),
1042
-            wpinv_status_nicename( $invoice->get_status(), $invoice )
1040
+            __('%1$s created with the status "%2$s".', 'invoicing'),
1041
+            ucfirst($invoice->get_invoice_quote_type()),
1042
+            wpinv_status_nicename($invoice->get_status(), $invoice)
1043 1043
         )
1044 1044
     );
1045 1045
 
1046 1046
 }
1047
-add_action( 'getpaid_new_invoice', 'getpaid_new_invoice' );
1047
+add_action('getpaid_new_invoice', 'getpaid_new_invoice');
1048 1048
 
1049 1049
 /**
1050 1050
  * This function updates invoice caches.
1051 1051
  *
1052 1052
  * @param WPInv_Invoice $invoice
1053 1053
  */
1054
-function getpaid_update_invoice_caches( $invoice ) {
1054
+function getpaid_update_invoice_caches($invoice) {
1055 1055
 
1056 1056
     // Cache invoice number.
1057
-    wp_cache_set( $invoice->get_number(), $invoice->get_id(), 'getpaid_invoice_numbers_to_invoice_ids' );
1057
+    wp_cache_set($invoice->get_number(), $invoice->get_id(), 'getpaid_invoice_numbers_to_invoice_ids');
1058 1058
 
1059 1059
     // Cache invoice key.
1060
-    wp_cache_set( $invoice->get_key(), $invoice->get_id(), 'getpaid_invoice_keys_to_invoice_ids' );
1060
+    wp_cache_set($invoice->get_key(), $invoice->get_id(), 'getpaid_invoice_keys_to_invoice_ids');
1061 1061
 
1062 1062
     // (Maybe) cache transaction id.
1063 1063
     $transaction_id = $invoice->get_transaction_id();
1064 1064
 
1065
-    if ( ! empty( $transaction_id ) ) {
1066
-        wp_cache_set( $transaction_id, $invoice->get_id(), 'getpaid_invoice_transaction_ids_to_invoice_ids' );
1065
+    if (!empty($transaction_id)) {
1066
+        wp_cache_set($transaction_id, $invoice->get_id(), 'getpaid_invoice_transaction_ids_to_invoice_ids');
1067 1067
     }
1068 1068
 
1069 1069
 }
1070
-add_action( 'getpaid_new_invoice', 'getpaid_update_invoice_caches', 5 );
1071
-add_action( 'getpaid_update_invoice', 'getpaid_update_invoice_caches', 5 );
1070
+add_action('getpaid_new_invoice', 'getpaid_update_invoice_caches', 5);
1071
+add_action('getpaid_update_invoice', 'getpaid_update_invoice_caches', 5);
1072 1072
 
1073 1073
 /**
1074 1074
  * Duplicates an invoice.
@@ -1078,7 +1078,7 @@  discard block
 block discarded – undo
1078 1078
  * @param  WPInv_Invoice $old_invoice The invoice to duplicate
1079 1079
  * @return WPInv_Invoice The new invoice.
1080 1080
  */
1081
-function getpaid_duplicate_invoice( $old_invoice ) {
1081
+function getpaid_duplicate_invoice($old_invoice) {
1082 1082
 
1083 1083
     // Create the new invoice.
1084 1084
     $invoice = new WPInv_Invoice();
@@ -1138,136 +1138,136 @@  discard block
 block discarded – undo
1138 1138
  * @param WPInv_Invoice $invoice
1139 1139
  * @return array
1140 1140
  */
1141
-function getpaid_get_invoice_meta( $invoice ) {
1141
+function getpaid_get_invoice_meta($invoice) {
1142 1142
 
1143 1143
     // Load the invoice meta.
1144 1144
     $meta = array(
1145 1145
 
1146 1146
         'number'         => array(
1147 1147
             'label' => sprintf(
1148
-                __( '%s Number', 'invoicing' ),
1149
-                ucfirst( $invoice->get_invoice_quote_type() )
1148
+                __('%s Number', 'invoicing'),
1149
+                ucfirst($invoice->get_invoice_quote_type())
1150 1150
             ),
1151
-            'value' => sanitize_text_field( $invoice->get_number() ),
1151
+            'value' => sanitize_text_field($invoice->get_number()),
1152 1152
         ),
1153 1153
 
1154 1154
         'status'         => array(
1155 1155
             'label' => sprintf(
1156
-                __( '%s Status', 'invoicing' ),
1157
-                ucfirst( $invoice->get_invoice_quote_type() )
1156
+                __('%s Status', 'invoicing'),
1157
+                ucfirst($invoice->get_invoice_quote_type())
1158 1158
             ),
1159 1159
             'value' => $invoice->get_status_label_html(),
1160 1160
         ),
1161 1161
 
1162 1162
         'date'           => array(
1163 1163
             'label' => sprintf(
1164
-                __( '%s Date', 'invoicing' ),
1165
-                ucfirst( $invoice->get_invoice_quote_type() )
1164
+                __('%s Date', 'invoicing'),
1165
+                ucfirst($invoice->get_invoice_quote_type())
1166 1166
             ),
1167
-            'value' => getpaid_format_date( $invoice->get_created_date() ),
1167
+            'value' => getpaid_format_date($invoice->get_created_date()),
1168 1168
         ),
1169 1169
 
1170 1170
         'date_paid'      => array(
1171
-            'label' => __( 'Paid On', 'invoicing' ),
1172
-            'value' => getpaid_format_date( $invoice->get_completed_date() ),
1171
+            'label' => __('Paid On', 'invoicing'),
1172
+            'value' => getpaid_format_date($invoice->get_completed_date()),
1173 1173
         ),
1174 1174
 
1175 1175
         'gateway'        => array(
1176
-            'label' => __( 'Payment Method', 'invoicing' ),
1177
-            'value' => sanitize_text_field( $invoice->get_gateway_title() ),
1176
+            'label' => __('Payment Method', 'invoicing'),
1177
+            'value' => sanitize_text_field($invoice->get_gateway_title()),
1178 1178
         ),
1179 1179
 
1180 1180
         'transaction_id' => array(
1181
-            'label' => __( 'Transaction ID', 'invoicing' ),
1182
-            'value' => sanitize_text_field( $invoice->get_transaction_id() ),
1181
+            'label' => __('Transaction ID', 'invoicing'),
1182
+            'value' => sanitize_text_field($invoice->get_transaction_id()),
1183 1183
         ),
1184 1184
 
1185 1185
         'due_date'       => array(
1186
-            'label' => __( 'Due Date', 'invoicing' ),
1187
-            'value' => getpaid_format_date( $invoice->get_due_date() ),
1186
+            'label' => __('Due Date', 'invoicing'),
1187
+            'value' => getpaid_format_date($invoice->get_due_date()),
1188 1188
         ),
1189 1189
 
1190 1190
         'vat_number'     => array(
1191
-            'label' => __( 'VAT Number', 'invoicing' ),
1192
-            'value' => sanitize_text_field( $invoice->get_vat_number() ),
1191
+            'label' => __('VAT Number', 'invoicing'),
1192
+            'value' => sanitize_text_field($invoice->get_vat_number()),
1193 1193
         ),
1194 1194
 
1195 1195
     );
1196 1196
 
1197
-    $additional_meta = get_post_meta( $invoice->get_id(), 'additional_meta_data', true );
1197
+    $additional_meta = get_post_meta($invoice->get_id(), 'additional_meta_data', true);
1198 1198
 
1199
-    if ( ! empty( $additional_meta ) ) {
1199
+    if (!empty($additional_meta)) {
1200 1200
 
1201
-        foreach ( $additional_meta as $label => $value ) {
1202
-            $meta[ sanitize_key( $label ) ] = array(
1203
-                'label' => esc_html( $label ),
1204
-                'value' => esc_html( $value ),
1201
+        foreach ($additional_meta as $label => $value) {
1202
+            $meta[sanitize_key($label)] = array(
1203
+                'label' => esc_html($label),
1204
+                'value' => esc_html($value),
1205 1205
             );
1206 1206
         }
1207 1207
 }
1208 1208
     // If it is not paid, remove the date of payment.
1209
-    if ( ! $invoice->is_paid() && ! $invoice->is_refunded() ) {
1210
-        unset( $meta['date_paid'] );
1211
-        unset( $meta['transaction_id'] );
1209
+    if (!$invoice->is_paid() && !$invoice->is_refunded()) {
1210
+        unset($meta['date_paid']);
1211
+        unset($meta['transaction_id']);
1212 1212
     }
1213 1213
 
1214
-    if ( ! $invoice->is_paid() || 'none' == $invoice->get_gateway() ) {
1215
-        unset( $meta['gateway'] );
1214
+    if (!$invoice->is_paid() || 'none' == $invoice->get_gateway()) {
1215
+        unset($meta['gateway']);
1216 1216
     }
1217 1217
 
1218 1218
     // Only display the due date if due dates are enabled.
1219
-    if ( ! $invoice->needs_payment() || ! wpinv_get_option( 'overdue_active' ) ) {
1220
-        unset( $meta['due_date'] );
1219
+    if (!$invoice->needs_payment() || !wpinv_get_option('overdue_active')) {
1220
+        unset($meta['due_date']);
1221 1221
     }
1222 1222
 
1223 1223
     // Only display the vat number if taxes are enabled.
1224
-    if ( ! wpinv_use_taxes() ) {
1225
-        unset( $meta['vat_number'] );
1224
+    if (!wpinv_use_taxes()) {
1225
+        unset($meta['vat_number']);
1226 1226
     }
1227 1227
 
1228 1228
     // Link to the parent invoice.
1229
-    if ( $invoice->get_parent_id() > 0 ) {
1229
+    if ($invoice->get_parent_id() > 0) {
1230 1230
 
1231 1231
         $meta['parent'] = array(
1232 1232
 
1233 1233
             'label' => sprintf(
1234
-                __( 'Parent %s', 'invoicing' ),
1235
-                ucfirst( $invoice->get_invoice_quote_type() )
1234
+                __('Parent %s', 'invoicing'),
1235
+                ucfirst($invoice->get_invoice_quote_type())
1236 1236
             ),
1237 1237
 
1238
-            'value' => wpinv_invoice_link( $invoice->get_parent_id() ),
1238
+            'value' => wpinv_invoice_link($invoice->get_parent_id()),
1239 1239
 
1240 1240
         );
1241 1241
 
1242 1242
     }
1243 1243
 
1244
-    if ( $invoice->is_recurring() ) {
1244
+    if ($invoice->is_recurring()) {
1245 1245
 
1246
-        $subscription = getpaid_get_invoice_subscriptions( $invoice );
1247
-        if ( ! empty( $subscription ) && ! is_array( $subscription ) && $subscription->exists() ) {
1246
+        $subscription = getpaid_get_invoice_subscriptions($invoice);
1247
+        if (!empty($subscription) && !is_array($subscription) && $subscription->exists()) {
1248 1248
 
1249 1249
             // Display the renewal date.
1250
-            if ( $subscription->is_active() && 'cancelled' != $subscription->get_status() ) {
1250
+            if ($subscription->is_active() && 'cancelled' != $subscription->get_status()) {
1251 1251
 
1252 1252
                 $meta['renewal_date'] = array(
1253
-                    'label' => __( 'Renews On', 'invoicing' ),
1254
-                    'value' => getpaid_format_date( $subscription->get_expiration() ) .
1253
+                    'label' => __('Renews On', 'invoicing'),
1254
+                    'value' => getpaid_format_date($subscription->get_expiration()) .
1255 1255
                     sprintf(
1256 1256
                         ' <a class="small" href="%s">%s<a>',
1257 1257
                         $subscription->get_view_url(),
1258
-                        __( '(View Subscription)', 'invoicing' )
1258
+                        __('(View Subscription)', 'invoicing')
1259 1259
                     ),
1260 1260
                 );
1261 1261
 
1262 1262
             }
1263 1263
 
1264
-            if ( $invoice->is_parent() ) {
1264
+            if ($invoice->is_parent()) {
1265 1265
 
1266 1266
                 // Display the recurring amount.
1267 1267
                 $meta['recurring_total'] = array(
1268 1268
 
1269
-                    'label' => __( 'Recurring Amount', 'invoicing' ),
1270
-                    'value' => wpinv_price( $subscription->get_recurring_amount(), $invoice->get_currency() ),
1269
+                    'label' => __('Recurring Amount', 'invoicing'),
1270
+                    'value' => wpinv_price($subscription->get_recurring_amount(), $invoice->get_currency()),
1271 1271
 
1272 1272
                 );
1273 1273
 
@@ -1278,13 +1278,13 @@  discard block
 block discarded – undo
1278 1278
     // Add the invoice total to the meta.
1279 1279
     $meta['invoice_total'] = array(
1280 1280
 
1281
-        'label' => __( 'Total Amount', 'invoicing' ),
1282
-        'value' => wpinv_price( $invoice->get_total(), $invoice->get_currency() ),
1281
+        'label' => __('Total Amount', 'invoicing'),
1282
+        'value' => wpinv_price($invoice->get_total(), $invoice->get_currency()),
1283 1283
 
1284 1284
     );
1285 1285
 
1286 1286
     // Provide a way for third party plugins to filter the meta.
1287
-    $meta = apply_filters( 'getpaid_invoice_meta_data', $meta, $invoice );
1287
+    $meta = apply_filters('getpaid_invoice_meta_data', $meta, $invoice);
1288 1288
 
1289 1289
     return $meta;
1290 1290
 
@@ -1323,12 +1323,12 @@  discard block
 block discarded – undo
1323 1323
  * @param GetPaid_Form_Item $item
1324 1324
  * @return float
1325 1325
  */
1326
-function getpaid_get_invoice_tax_rate( $invoice, $item ) {
1326
+function getpaid_get_invoice_tax_rate($invoice, $item) {
1327 1327
 
1328
-    $rates   = getpaid_get_item_tax_rates( $item, $invoice->get_country(), $invoice->get_state() );
1329
-	$rates   = getpaid_filter_item_tax_rates( $item, $rates );
1330
-    $rates   = wp_list_pluck( $rates, 'rate' );
1328
+    $rates   = getpaid_get_item_tax_rates($item, $invoice->get_country(), $invoice->get_state());
1329
+	$rates = getpaid_filter_item_tax_rates($item, $rates);
1330
+    $rates   = wp_list_pluck($rates, 'rate');
1331 1331
 
1332
-    return array_sum( $rates );
1332
+    return array_sum($rates);
1333 1333
 
1334 1334
 }
Please login to merge, or discard this patch.
Indentation   +37 added lines, -37 removed lines patch added patch discarded remove patch
@@ -67,7 +67,7 @@  discard block
 block discarded – undo
67 67
  * Checks if the current user cna view an invoice receipt.
68 68
  */
69 69
 function wpinv_can_view_receipt( $invoice ) {
70
-	return (bool) apply_filters( 'wpinv_can_view_receipt', wpinv_user_can_view_invoice( $invoice ), $invoice );
70
+    return (bool) apply_filters( 'wpinv_can_view_receipt', wpinv_user_can_view_invoice( $invoice ), $invoice );
71 71
 }
72 72
 
73 73
 /**
@@ -556,37 +556,37 @@  discard block
 block discarded – undo
556 556
     $label   = empty( $label ) ? __( 'Invoice', 'invoicing' ) : sanitize_text_field( $label );
557 557
     $columns = array(
558 558
 
559
-		'invoice-number'  => array(
560
-			'title' => $label,
561
-			'class' => 'text-left',
562
-		),
559
+        'invoice-number'  => array(
560
+            'title' => $label,
561
+            'class' => 'text-left',
562
+        ),
563 563
 
564
-		'created-date'    => array(
565
-			'title' => __( 'Created Date', 'invoicing' ),
566
-			'class' => 'text-left',
567
-		),
564
+        'created-date'    => array(
565
+            'title' => __( 'Created Date', 'invoicing' ),
566
+            'class' => 'text-left',
567
+        ),
568 568
 
569
-		'payment-date'    => array(
570
-			'title' => __( 'Payment Date', 'invoicing' ),
571
-			'class' => 'text-left',
572
-		),
569
+        'payment-date'    => array(
570
+            'title' => __( 'Payment Date', 'invoicing' ),
571
+            'class' => 'text-left',
572
+        ),
573 573
 
574
-		'invoice-status'  => array(
575
-			'title' => __( 'Status', 'invoicing' ),
576
-			'class' => 'text-center',
577
-		),
574
+        'invoice-status'  => array(
575
+            'title' => __( 'Status', 'invoicing' ),
576
+            'class' => 'text-center',
577
+        ),
578 578
 
579
-		'invoice-total'   => array(
580
-			'title' => __( 'Total', 'invoicing' ),
581
-			'class' => 'text-right',
582
-		),
579
+        'invoice-total'   => array(
580
+            'title' => __( 'Total', 'invoicing' ),
581
+            'class' => 'text-right',
582
+        ),
583 583
 
584
-		'invoice-actions' => array(
585
-			'title' => '&nbsp;',
586
-			'class' => 'text-center',
587
-		),
584
+        'invoice-actions' => array(
585
+            'title' => '&nbsp;',
586
+            'class' => 'text-center',
587
+        ),
588 588
 
589
-	);
589
+    );
590 590
 
591 591
     return apply_filters( 'wpinv_user_invoices_columns', $columns, $post_type );
592 592
 }
@@ -1297,22 +1297,22 @@  discard block
 block discarded – undo
1297 1297
  */
1298 1298
 function getpaid_get_invoice_status_classes() {
1299 1299
 
1300
-	return apply_filters(
1301
-		'getpaid_get_invoice_status_classes',
1302
-		array(
1300
+    return apply_filters(
1301
+        'getpaid_get_invoice_status_classes',
1302
+        array(
1303 1303
             'wpi-quote-declined' => 'bg-danger',
1304 1304
             'wpi-failed'         => 'bg-danger',
1305
-			'wpi-processing'     => 'bg-info',
1306
-			'wpi-onhold'         => 'bg-warning text-dark',
1307
-			'wpi-quote-accepted' => 'bg-success',
1308
-			'publish'            => 'bg-success',
1309
-			'wpi-renewal'        => 'bg-primary',
1305
+            'wpi-processing'     => 'bg-info',
1306
+            'wpi-onhold'         => 'bg-warning text-dark',
1307
+            'wpi-quote-accepted' => 'bg-success',
1308
+            'publish'            => 'bg-success',
1309
+            'wpi-renewal'        => 'bg-primary',
1310 1310
             'wpi-cancelled'      => 'bg-secondary',
1311 1311
             'wpi-pending'        => 'bg-dark text-white',
1312 1312
             'wpi-quote-pending'  => 'bg-dark text-white',
1313 1313
             'wpi-refunded'       => 'bg-secondary',
1314
-		)
1315
-	);
1314
+        )
1315
+    );
1316 1316
 
1317 1317
 }
1318 1318
 
@@ -1326,7 +1326,7 @@  discard block
 block discarded – undo
1326 1326
 function getpaid_get_invoice_tax_rate( $invoice, $item ) {
1327 1327
 
1328 1328
     $rates   = getpaid_get_item_tax_rates( $item, $invoice->get_country(), $invoice->get_state() );
1329
-	$rates   = getpaid_filter_item_tax_rates( $item, $rates );
1329
+    $rates   = getpaid_filter_item_tax_rates( $item, $rates );
1330 1330
     $rates   = wp_list_pluck( $rates, 'rate' );
1331 1331
 
1332 1332
     return array_sum( $rates );
Please login to merge, or discard this patch.
includes/payments/class-getpaid-payment-form-submission-refresh-prices.php 2 patches
Indentation   +267 added lines, -267 removed lines patch added patch discarded remove patch
@@ -12,301 +12,301 @@
 block discarded – undo
12 12
  */
13 13
 class GetPaid_Payment_Form_Submission_Refresh_Prices {
14 14
 
15
-	/**
16
-	 * Contains the response for refreshing prices.
17
-	 * @var array
18
-	 */
19
-	public $response = array();
15
+    /**
16
+     * Contains the response for refreshing prices.
17
+     * @var array
18
+     */
19
+    public $response = array();
20 20
 
21 21
     /**
22
-	 * Class constructor
23
-	 *
24
-	 * @param GetPaid_Payment_Form_Submission $submission
25
-	 */
26
-	public function __construct( $submission ) {
27
-
28
-		$this->response = array(
29
-			'submission_id'                    => $submission->id,
22
+     * Class constructor
23
+     *
24
+     * @param GetPaid_Payment_Form_Submission $submission
25
+     */
26
+    public function __construct( $submission ) {
27
+
28
+        $this->response = array(
29
+            'submission_id'                    => $submission->id,
30 30
             'has_recurring'                    => $submission->has_recurring,
31
-			'has_subscription_group'           => $submission->has_subscription_group(),
32
-			'has_multiple_subscription_groups' => $submission->has_multiple_subscription_groups(),
31
+            'has_subscription_group'           => $submission->has_subscription_group(),
32
+            'has_multiple_subscription_groups' => $submission->has_multiple_subscription_groups(),
33 33
             'is_free'                          => ! $submission->should_collect_payment_details(),
34
-		);
35
-
36
-		$payment_form = $submission->get_payment_form();
37
-		if ( ! empty( $payment_form->invoice ) ) {
38
-			$this->response['invoice'] = $payment_form->invoice->get_id();
39
-		}
40
-
41
-		$this->add_totals( $submission );
42
-		$this->add_texts( $submission );
43
-		$this->add_items( $submission );
44
-		$this->add_fees( $submission );
45
-		$this->add_discounts( $submission );
46
-		$this->add_taxes( $submission );
47
-		$this->add_gateways( $submission );
48
-		$this->add_data( $submission );
49
-
50
-	}
51
-
52
-	/**
53
-	 * Adds totals to a response for submission refresh prices.
54
-	 *
55
-	 * @param GetPaid_Payment_Form_Submission $submission
56
-	 */
57
-	public function add_totals( $submission ) {
58
-
59
-		$this->response = array_merge(
60
-			$this->response,
61
-			array(
62
-
63
-				'totals'      => array(
64
-					'subtotal'  => $submission->format_amount( $submission->get_subtotal() ),
65
-					'discount'  => $submission->format_amount( $submission->get_discount() ),
66
-					'fees'      => $submission->format_amount( $submission->get_fee() ),
67
-					'tax'       => $submission->format_amount( $submission->get_tax() ),
68
-					'total'     => $submission->format_amount( $submission->get_total() ),
69
-					'raw_total' => html_entity_decode( sanitize_text_field( $submission->format_amount( $submission->get_total() ) ), ENT_QUOTES ),
70
-				),
71
-
72
-				'recurring'   => array(
73
-					'subtotal' => $submission->format_amount( $submission->get_recurring_subtotal() ),
74
-					'discount' => $submission->format_amount( $submission->get_recurring_discount() ),
75
-					'fees'     => $submission->format_amount( $submission->get_recurring_fee() ),
76
-					'tax'      => $submission->format_amount( $submission->get_recurring_tax() ),
77
-					'total'    => $submission->format_amount( $submission->get_recurring_total() ),
78
-				),
79
-
80
-				'initial_amt' => wpinv_round_amount( $submission->get_total(), null, true ),
81
-				'currency'    => $submission->get_currency(),
82
-
83
-			)
84
-		);
85
-
86
-	}
87
-
88
-	/**
89
-	 * Adds texts to a response for submission refresh prices.
90
-	 *
91
-	 * @param GetPaid_Payment_Form_Submission $submission
92
-	 */
93
-	public function add_texts( $submission ) {
94
-
95
-		$payable = $submission->format_amount( $submission->get_total() );
96
-		$groups  = getpaid_get_subscription_groups( $submission );
97
-
98
-		if ( $submission->has_recurring && 2 > count( $groups ) ) {
99
-
100
-			$recurring = new WPInv_Item( $submission->has_recurring );
101
-			$period    = getpaid_get_subscription_period_label( $recurring->get_recurring_period( true ), $recurring->get_recurring_interval(), '' );
102
-			$main_item = reset( $groups );
103
-
104
-			if ( $submission->get_total() == $submission->get_recurring_total() ) {
105
-				$payable = "$payable / $period";
106
-			} elseif ( $main_item ) {
107
-
108
-				$main_item = reset( $main_item );
109
-
110
-				// Calculate the next renewal date.
111
-				$_period      = $main_item->get_recurring_period( true );
112
-				$_interval    = $main_item->get_recurring_interval();
113
-
114
-				// If the subscription item has a trial period...
115
-				if ( $main_item->has_free_trial() ) {
116
-					$_period   = $main_item->get_trial_period( true );
117
-					$_interval = $main_item->get_trial_interval();
118
-				}
119
-
120
-				$payable = sprintf(
121
-					__( '%1$s (renews at %2$s / %3$s)', 'invoicing' ),
122
-					$submission->format_amount( $submission->get_total() ),
123
-					$submission->format_amount( $submission->get_recurring_total() ),
124
-					$period
125
-				);
126
-
127
-				$payable .= sprintf(
128
-					'<small class="text-muted form-text">%s</small>',
129
-					sprintf(
130
-						__( 'First renewal on %s', 'invoicing' ),
131
-						getpaid_format_date( date( 'Y-m-d H:i:s', strtotime( "+$_interval $_period", current_time( 'timestamp' ) ) ) )
132
-					)
133
-				);
134
-
135
-			} else {
136
-				$payable = sprintf(
137
-					__( '%1$s (renews at %2$s / %3$s)', 'invoicing' ),
138
-					$submission->format_amount( $submission->get_total() ),
139
-					$submission->format_amount( $submission->get_recurring_total() ),
140
-					$period
141
-				);
142
-			}
143
-}
34
+        );
35
+
36
+        $payment_form = $submission->get_payment_form();
37
+        if ( ! empty( $payment_form->invoice ) ) {
38
+            $this->response['invoice'] = $payment_form->invoice->get_id();
39
+        }
40
+
41
+        $this->add_totals( $submission );
42
+        $this->add_texts( $submission );
43
+        $this->add_items( $submission );
44
+        $this->add_fees( $submission );
45
+        $this->add_discounts( $submission );
46
+        $this->add_taxes( $submission );
47
+        $this->add_gateways( $submission );
48
+        $this->add_data( $submission );
49
+
50
+    }
51
+
52
+    /**
53
+     * Adds totals to a response for submission refresh prices.
54
+     *
55
+     * @param GetPaid_Payment_Form_Submission $submission
56
+     */
57
+    public function add_totals( $submission ) {
58
+
59
+        $this->response = array_merge(
60
+            $this->response,
61
+            array(
62
+
63
+                'totals'      => array(
64
+                    'subtotal'  => $submission->format_amount( $submission->get_subtotal() ),
65
+                    'discount'  => $submission->format_amount( $submission->get_discount() ),
66
+                    'fees'      => $submission->format_amount( $submission->get_fee() ),
67
+                    'tax'       => $submission->format_amount( $submission->get_tax() ),
68
+                    'total'     => $submission->format_amount( $submission->get_total() ),
69
+                    'raw_total' => html_entity_decode( sanitize_text_field( $submission->format_amount( $submission->get_total() ) ), ENT_QUOTES ),
70
+                ),
71
+
72
+                'recurring'   => array(
73
+                    'subtotal' => $submission->format_amount( $submission->get_recurring_subtotal() ),
74
+                    'discount' => $submission->format_amount( $submission->get_recurring_discount() ),
75
+                    'fees'     => $submission->format_amount( $submission->get_recurring_fee() ),
76
+                    'tax'      => $submission->format_amount( $submission->get_recurring_tax() ),
77
+                    'total'    => $submission->format_amount( $submission->get_recurring_total() ),
78
+                ),
79
+
80
+                'initial_amt' => wpinv_round_amount( $submission->get_total(), null, true ),
81
+                'currency'    => $submission->get_currency(),
82
+
83
+            )
84
+        );
85
+
86
+    }
144 87
 
145
-		$texts = array(
146
-			'.getpaid-checkout-total-payable' => $payable,
147
-		);
88
+    /**
89
+     * Adds texts to a response for submission refresh prices.
90
+     *
91
+     * @param GetPaid_Payment_Form_Submission $submission
92
+     */
93
+    public function add_texts( $submission ) {
94
+
95
+        $payable = $submission->format_amount( $submission->get_total() );
96
+        $groups  = getpaid_get_subscription_groups( $submission );
97
+
98
+        if ( $submission->has_recurring && 2 > count( $groups ) ) {
99
+
100
+            $recurring = new WPInv_Item( $submission->has_recurring );
101
+            $period    = getpaid_get_subscription_period_label( $recurring->get_recurring_period( true ), $recurring->get_recurring_interval(), '' );
102
+            $main_item = reset( $groups );
103
+
104
+            if ( $submission->get_total() == $submission->get_recurring_total() ) {
105
+                $payable = "$payable / $period";
106
+            } elseif ( $main_item ) {
107
+
108
+                $main_item = reset( $main_item );
109
+
110
+                // Calculate the next renewal date.
111
+                $_period      = $main_item->get_recurring_period( true );
112
+                $_interval    = $main_item->get_recurring_interval();
113
+
114
+                // If the subscription item has a trial period...
115
+                if ( $main_item->has_free_trial() ) {
116
+                    $_period   = $main_item->get_trial_period( true );
117
+                    $_interval = $main_item->get_trial_interval();
118
+                }
119
+
120
+                $payable = sprintf(
121
+                    __( '%1$s (renews at %2$s / %3$s)', 'invoicing' ),
122
+                    $submission->format_amount( $submission->get_total() ),
123
+                    $submission->format_amount( $submission->get_recurring_total() ),
124
+                    $period
125
+                );
126
+
127
+                $payable .= sprintf(
128
+                    '<small class="text-muted form-text">%s</small>',
129
+                    sprintf(
130
+                        __( 'First renewal on %s', 'invoicing' ),
131
+                        getpaid_format_date( date( 'Y-m-d H:i:s', strtotime( "+$_interval $_period", current_time( 'timestamp' ) ) ) )
132
+                    )
133
+                );
134
+
135
+            } else {
136
+                $payable = sprintf(
137
+                    __( '%1$s (renews at %2$s / %3$s)', 'invoicing' ),
138
+                    $submission->format_amount( $submission->get_total() ),
139
+                    $submission->format_amount( $submission->get_recurring_total() ),
140
+                    $period
141
+                );
142
+            }
143
+}
148 144
 
149
-		foreach ( $submission->get_items() as $item ) {
150
-			$item_id                                               = $item->get_id();
151
-			$initial_price                                         = $submission->format_amount( $item->get_sub_total() - $item->item_discount );
152
-			$recurring_price                                       = $submission->format_amount( $item->get_recurring_sub_total() - $item->recurring_item_discount );
153
-			$texts[ ".item-$item_id .getpaid-form-item-price-desc" ] = getpaid_item_recurring_price_help_text( $item, $submission->get_currency(), $initial_price, $recurring_price );
154
-			$texts[ ".item-$item_id .getpaid-mobile-item-subtotal" ] = sprintf( __( 'Subtotal: %s', 'invoicing' ), $submission->format_amount( $item->get_sub_total() ) );
145
+        $texts = array(
146
+            '.getpaid-checkout-total-payable' => $payable,
147
+        );
155 148
 
156
-			if ( $item->get_quantity() == 1 ) {
157
-				$texts[ ".item-$item_id .getpaid-mobile-item-subtotal" ] = '';
158
-			}
149
+        foreach ( $submission->get_items() as $item ) {
150
+            $item_id                                               = $item->get_id();
151
+            $initial_price                                         = $submission->format_amount( $item->get_sub_total() - $item->item_discount );
152
+            $recurring_price                                       = $submission->format_amount( $item->get_recurring_sub_total() - $item->recurring_item_discount );
153
+            $texts[ ".item-$item_id .getpaid-form-item-price-desc" ] = getpaid_item_recurring_price_help_text( $item, $submission->get_currency(), $initial_price, $recurring_price );
154
+            $texts[ ".item-$item_id .getpaid-mobile-item-subtotal" ] = sprintf( __( 'Subtotal: %s', 'invoicing' ), $submission->format_amount( $item->get_sub_total() ) );
155
+
156
+            if ( $item->get_quantity() == 1 ) {
157
+                $texts[ ".item-$item_id .getpaid-mobile-item-subtotal" ] = '';
158
+            }
159 159
 }
160 160
 
161
-		$this->response = array_merge( $this->response, array( 'texts' => $texts ) );
161
+        $this->response = array_merge( $this->response, array( 'texts' => $texts ) );
162 162
 
163
-	}
163
+    }
164 164
 
165
-	/**
166
-	 * Adds items to a response for submission refresh prices.
167
-	 *
168
-	 * @param GetPaid_Payment_Form_Submission $submission
169
-	 */
170
-	public function add_items( $submission ) {
165
+    /**
166
+     * Adds items to a response for submission refresh prices.
167
+     *
168
+     * @param GetPaid_Payment_Form_Submission $submission
169
+     */
170
+    public function add_items( $submission ) {
171 171
 
172
-		// Add items.
173
-		$items          = array();
174
-		$selected_items = array();
172
+        // Add items.
173
+        $items          = array();
174
+        $selected_items = array();
175 175
 
176 176
         foreach ( $submission->get_items() as $item ) {
177
-			$item_id             = $item->get_id();
178
-			$items[ "$item_id" ] = $submission->format_amount( $item->get_sub_total() );
179
-
180
-			$selected_items[ "$item_id" ] = array(
181
-				'quantity'  => $item->get_quantity(),
182
-				'price'     => $item->get_price(),
183
-				'price_fmt' => $submission->format_amount( $item->get_price() ),
184
-			);
185
-		}
186
-
187
-		$this->response = array_merge(
188
-			$this->response,
189
-			array(
190
-				'items'          => $items,
191
-				'selected_items' => $selected_items,
192
-			)
193
-		);
194
-
195
-	}
196
-
197
-	/**
198
-	 * Adds fees to a response for submission refresh prices.
199
-	 *
200
-	 * @param GetPaid_Payment_Form_Submission $submission
201
-	 */
202
-	public function add_fees( $submission ) {
203
-
204
-		$fees = array();
177
+            $item_id             = $item->get_id();
178
+            $items[ "$item_id" ] = $submission->format_amount( $item->get_sub_total() );
179
+
180
+            $selected_items[ "$item_id" ] = array(
181
+                'quantity'  => $item->get_quantity(),
182
+                'price'     => $item->get_price(),
183
+                'price_fmt' => $submission->format_amount( $item->get_price() ),
184
+            );
185
+        }
186
+
187
+        $this->response = array_merge(
188
+            $this->response,
189
+            array(
190
+                'items'          => $items,
191
+                'selected_items' => $selected_items,
192
+            )
193
+        );
194
+
195
+    }
196
+
197
+    /**
198
+     * Adds fees to a response for submission refresh prices.
199
+     *
200
+     * @param GetPaid_Payment_Form_Submission $submission
201
+     */
202
+    public function add_fees( $submission ) {
203
+
204
+        $fees = array();
205 205
 
206 206
         foreach ( $submission->get_fees() as $name => $data ) {
207
-			$fees[ $name ] = $submission->format_amount( $data['initial_fee'] );
208
-		}
207
+            $fees[ $name ] = $submission->format_amount( $data['initial_fee'] );
208
+        }
209 209
 
210
-		$this->response = array_merge(
211
-			$this->response,
212
-			array( 'fees' => $fees )
213
-		);
210
+        $this->response = array_merge(
211
+            $this->response,
212
+            array( 'fees' => $fees )
213
+        );
214 214
 
215
-	}
215
+    }
216 216
 
217
-	/**
218
-	 * Adds discounts to a response for submission refresh prices.
219
-	 *
220
-	 * @param GetPaid_Payment_Form_Submission $submission
221
-	 */
222
-	public function add_discounts( $submission ) {
217
+    /**
218
+     * Adds discounts to a response for submission refresh prices.
219
+     *
220
+     * @param GetPaid_Payment_Form_Submission $submission
221
+     */
222
+    public function add_discounts( $submission ) {
223 223
 
224
-		$discounts = array();
224
+        $discounts = array();
225 225
 
226 226
         foreach ( $submission->get_discounts() as $name => $data ) {
227
-			$discounts[ $name ] = $submission->format_amount( $data['initial_discount'] );
228
-		}
229
-
230
-		$this->response = array_merge(
231
-			$this->response,
232
-			array( 'discounts' => $discounts )
233
-		);
227
+            $discounts[ $name ] = $submission->format_amount( $data['initial_discount'] );
228
+        }
234 229
 
235
-	}
230
+        $this->response = array_merge(
231
+            $this->response,
232
+            array( 'discounts' => $discounts )
233
+        );
236 234
 
237
-	/**
238
-	 * Adds taxes to a response for submission refresh prices.
239
-	 *
240
-	 * @param GetPaid_Payment_Form_Submission $submission
241
-	 */
242
-	public function add_taxes( $submission ) {
235
+    }
243 236
 
244
-		$taxes  = array();
245
-		$markup = '';
237
+    /**
238
+     * Adds taxes to a response for submission refresh prices.
239
+     *
240
+     * @param GetPaid_Payment_Form_Submission $submission
241
+     */
242
+    public function add_taxes( $submission ) {
243
+
244
+        $taxes  = array();
245
+        $markup = '';
246 246
         foreach ( $submission->get_taxes() as $name => $data ) {
247
-			$name           = sanitize_text_field( $name );
248
-			$amount         = $submission->format_amount( $data['initial_tax'] );
249
-			$taxes[ $name ] = $amount;
250
-			$markup        .= "<small class='form-text'>$name : $amount</small>";
251
-		}
252
-
253
-		$this->response = array_merge(
254
-			$this->response,
255
-			array( 'taxes' => $taxes )
256
-		);
257
-
258
-	}
259
-
260
-	/**
261
-	 * Adds gateways to a response for submission refresh prices.
262
-	 *
263
-	 * @param GetPaid_Payment_Form_Submission $submission
264
-	 */
265
-	public function add_gateways( $submission ) {
266
-
267
-		$gateways = array_keys( wpinv_get_enabled_payment_gateways() );
268
-
269
-		if ( $this->response['has_recurring'] ) {
270
-
271
-			foreach ( $gateways as $i => $gateway ) {
272
-
273
-				if (
274
-					! getpaid_payment_gateway_supports( $gateway, 'subscription' )
275
-					|| ( $this->response['has_subscription_group'] && ! getpaid_payment_gateway_supports( $gateway, 'single_subscription_group' ) )
276
-					|| ( $this->response['has_multiple_subscription_groups'] && ! getpaid_payment_gateway_supports( $gateway, 'multiple_subscription_groups' ) ) ) {
277
-					unset( $gateways[ $i ] );
278
-				}
247
+            $name           = sanitize_text_field( $name );
248
+            $amount         = $submission->format_amount( $data['initial_tax'] );
249
+            $taxes[ $name ] = $amount;
250
+            $markup        .= "<small class='form-text'>$name : $amount</small>";
251
+        }
252
+
253
+        $this->response = array_merge(
254
+            $this->response,
255
+            array( 'taxes' => $taxes )
256
+        );
257
+
258
+    }
259
+
260
+    /**
261
+     * Adds gateways to a response for submission refresh prices.
262
+     *
263
+     * @param GetPaid_Payment_Form_Submission $submission
264
+     */
265
+    public function add_gateways( $submission ) {
266
+
267
+        $gateways = array_keys( wpinv_get_enabled_payment_gateways() );
268
+
269
+        if ( $this->response['has_recurring'] ) {
270
+
271
+            foreach ( $gateways as $i => $gateway ) {
272
+
273
+                if (
274
+                    ! getpaid_payment_gateway_supports( $gateway, 'subscription' )
275
+                    || ( $this->response['has_subscription_group'] && ! getpaid_payment_gateway_supports( $gateway, 'single_subscription_group' ) )
276
+                    || ( $this->response['has_multiple_subscription_groups'] && ! getpaid_payment_gateway_supports( $gateway, 'multiple_subscription_groups' ) ) ) {
277
+                    unset( $gateways[ $i ] );
278
+                }
279 279
 }
280 280
 }
281 281
 
282
-		$gateways = apply_filters( 'getpaid_submission_gateways', $gateways, $submission );
283
-		$this->response = array_merge(
284
-			$this->response,
285
-			array( 'gateways' => $gateways )
286
-		);
287
-
288
-	}
289
-
290
-	/**
291
-	 * Adds data to a response for submission refresh prices.
292
-	 *
293
-	 * @param GetPaid_Payment_Form_Submission $submission
294
-	 */
295
-	public function add_data( $submission ) {
296
-
297
-		$this->response = array_merge(
298
-			$this->response,
299
-			array(
300
-				'js_data' => apply_filters(
301
-					'getpaid_submission_js_data',
302
-					array(
303
-						'is_recurring' => $this->response['has_recurring'],
304
-					),
305
-					$submission
306
-				),
307
-			)
308
-		);
309
-
310
-	}
282
+        $gateways = apply_filters( 'getpaid_submission_gateways', $gateways, $submission );
283
+        $this->response = array_merge(
284
+            $this->response,
285
+            array( 'gateways' => $gateways )
286
+        );
287
+
288
+    }
289
+
290
+    /**
291
+     * Adds data to a response for submission refresh prices.
292
+     *
293
+     * @param GetPaid_Payment_Form_Submission $submission
294
+     */
295
+    public function add_data( $submission ) {
296
+
297
+        $this->response = array_merge(
298
+            $this->response,
299
+            array(
300
+                'js_data' => apply_filters(
301
+                    'getpaid_submission_js_data',
302
+                    array(
303
+                        'is_recurring' => $this->response['has_recurring'],
304
+                    ),
305
+                    $submission
306
+                ),
307
+            )
308
+        );
309
+
310
+    }
311 311
 
312 312
 }
Please login to merge, or discard this patch.
Spacing   +84 added lines, -84 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
4 4
  *
5 5
  */
6 6
 
7
-defined( 'ABSPATH' ) || exit;
7
+defined('ABSPATH') || exit;
8 8
 
9 9
 /**
10 10
  * Payment form submission refresh prices class
@@ -23,29 +23,29 @@  discard block
 block discarded – undo
23 23
 	 *
24 24
 	 * @param GetPaid_Payment_Form_Submission $submission
25 25
 	 */
26
-	public function __construct( $submission ) {
26
+	public function __construct($submission) {
27 27
 
28 28
 		$this->response = array(
29 29
 			'submission_id'                    => $submission->id,
30 30
             'has_recurring'                    => $submission->has_recurring,
31 31
 			'has_subscription_group'           => $submission->has_subscription_group(),
32 32
 			'has_multiple_subscription_groups' => $submission->has_multiple_subscription_groups(),
33
-            'is_free'                          => ! $submission->should_collect_payment_details(),
33
+            'is_free'                          => !$submission->should_collect_payment_details(),
34 34
 		);
35 35
 
36 36
 		$payment_form = $submission->get_payment_form();
37
-		if ( ! empty( $payment_form->invoice ) ) {
37
+		if (!empty($payment_form->invoice)) {
38 38
 			$this->response['invoice'] = $payment_form->invoice->get_id();
39 39
 		}
40 40
 
41
-		$this->add_totals( $submission );
42
-		$this->add_texts( $submission );
43
-		$this->add_items( $submission );
44
-		$this->add_fees( $submission );
45
-		$this->add_discounts( $submission );
46
-		$this->add_taxes( $submission );
47
-		$this->add_gateways( $submission );
48
-		$this->add_data( $submission );
41
+		$this->add_totals($submission);
42
+		$this->add_texts($submission);
43
+		$this->add_items($submission);
44
+		$this->add_fees($submission);
45
+		$this->add_discounts($submission);
46
+		$this->add_taxes($submission);
47
+		$this->add_gateways($submission);
48
+		$this->add_data($submission);
49 49
 
50 50
 	}
51 51
 
@@ -54,30 +54,30 @@  discard block
 block discarded – undo
54 54
 	 *
55 55
 	 * @param GetPaid_Payment_Form_Submission $submission
56 56
 	 */
57
-	public function add_totals( $submission ) {
57
+	public function add_totals($submission) {
58 58
 
59 59
 		$this->response = array_merge(
60 60
 			$this->response,
61 61
 			array(
62 62
 
63 63
 				'totals'      => array(
64
-					'subtotal'  => $submission->format_amount( $submission->get_subtotal() ),
65
-					'discount'  => $submission->format_amount( $submission->get_discount() ),
66
-					'fees'      => $submission->format_amount( $submission->get_fee() ),
67
-					'tax'       => $submission->format_amount( $submission->get_tax() ),
68
-					'total'     => $submission->format_amount( $submission->get_total() ),
69
-					'raw_total' => html_entity_decode( sanitize_text_field( $submission->format_amount( $submission->get_total() ) ), ENT_QUOTES ),
64
+					'subtotal'  => $submission->format_amount($submission->get_subtotal()),
65
+					'discount'  => $submission->format_amount($submission->get_discount()),
66
+					'fees'      => $submission->format_amount($submission->get_fee()),
67
+					'tax'       => $submission->format_amount($submission->get_tax()),
68
+					'total'     => $submission->format_amount($submission->get_total()),
69
+					'raw_total' => html_entity_decode(sanitize_text_field($submission->format_amount($submission->get_total())), ENT_QUOTES),
70 70
 				),
71 71
 
72 72
 				'recurring'   => array(
73
-					'subtotal' => $submission->format_amount( $submission->get_recurring_subtotal() ),
74
-					'discount' => $submission->format_amount( $submission->get_recurring_discount() ),
75
-					'fees'     => $submission->format_amount( $submission->get_recurring_fee() ),
76
-					'tax'      => $submission->format_amount( $submission->get_recurring_tax() ),
77
-					'total'    => $submission->format_amount( $submission->get_recurring_total() ),
73
+					'subtotal' => $submission->format_amount($submission->get_recurring_subtotal()),
74
+					'discount' => $submission->format_amount($submission->get_recurring_discount()),
75
+					'fees'     => $submission->format_amount($submission->get_recurring_fee()),
76
+					'tax'      => $submission->format_amount($submission->get_recurring_tax()),
77
+					'total'    => $submission->format_amount($submission->get_recurring_total()),
78 78
 				),
79 79
 
80
-				'initial_amt' => wpinv_round_amount( $submission->get_total(), null, true ),
80
+				'initial_amt' => wpinv_round_amount($submission->get_total(), null, true),
81 81
 				'currency'    => $submission->get_currency(),
82 82
 
83 83
 			)
@@ -90,53 +90,53 @@  discard block
 block discarded – undo
90 90
 	 *
91 91
 	 * @param GetPaid_Payment_Form_Submission $submission
92 92
 	 */
93
-	public function add_texts( $submission ) {
93
+	public function add_texts($submission) {
94 94
 
95
-		$payable = $submission->format_amount( $submission->get_total() );
96
-		$groups  = getpaid_get_subscription_groups( $submission );
95
+		$payable = $submission->format_amount($submission->get_total());
96
+		$groups  = getpaid_get_subscription_groups($submission);
97 97
 
98
-		if ( $submission->has_recurring && 2 > count( $groups ) ) {
98
+		if ($submission->has_recurring && 2 > count($groups)) {
99 99
 
100
-			$recurring = new WPInv_Item( $submission->has_recurring );
101
-			$period    = getpaid_get_subscription_period_label( $recurring->get_recurring_period( true ), $recurring->get_recurring_interval(), '' );
102
-			$main_item = reset( $groups );
100
+			$recurring = new WPInv_Item($submission->has_recurring);
101
+			$period    = getpaid_get_subscription_period_label($recurring->get_recurring_period(true), $recurring->get_recurring_interval(), '');
102
+			$main_item = reset($groups);
103 103
 
104
-			if ( $submission->get_total() == $submission->get_recurring_total() ) {
104
+			if ($submission->get_total() == $submission->get_recurring_total()) {
105 105
 				$payable = "$payable / $period";
106
-			} elseif ( $main_item ) {
106
+			} elseif ($main_item) {
107 107
 
108
-				$main_item = reset( $main_item );
108
+				$main_item = reset($main_item);
109 109
 
110 110
 				// Calculate the next renewal date.
111
-				$_period      = $main_item->get_recurring_period( true );
111
+				$_period      = $main_item->get_recurring_period(true);
112 112
 				$_interval    = $main_item->get_recurring_interval();
113 113
 
114 114
 				// If the subscription item has a trial period...
115
-				if ( $main_item->has_free_trial() ) {
116
-					$_period   = $main_item->get_trial_period( true );
115
+				if ($main_item->has_free_trial()) {
116
+					$_period   = $main_item->get_trial_period(true);
117 117
 					$_interval = $main_item->get_trial_interval();
118 118
 				}
119 119
 
120 120
 				$payable = sprintf(
121
-					__( '%1$s (renews at %2$s / %3$s)', 'invoicing' ),
122
-					$submission->format_amount( $submission->get_total() ),
123
-					$submission->format_amount( $submission->get_recurring_total() ),
121
+					__('%1$s (renews at %2$s / %3$s)', 'invoicing'),
122
+					$submission->format_amount($submission->get_total()),
123
+					$submission->format_amount($submission->get_recurring_total()),
124 124
 					$period
125 125
 				);
126 126
 
127 127
 				$payable .= sprintf(
128 128
 					'<small class="text-muted form-text">%s</small>',
129 129
 					sprintf(
130
-						__( 'First renewal on %s', 'invoicing' ),
131
-						getpaid_format_date( date( 'Y-m-d H:i:s', strtotime( "+$_interval $_period", current_time( 'timestamp' ) ) ) )
130
+						__('First renewal on %s', 'invoicing'),
131
+						getpaid_format_date(date('Y-m-d H:i:s', strtotime("+$_interval $_period", current_time('timestamp'))))
132 132
 					)
133 133
 				);
134 134
 
135 135
 			} else {
136 136
 				$payable = sprintf(
137
-					__( '%1$s (renews at %2$s / %3$s)', 'invoicing' ),
138
-					$submission->format_amount( $submission->get_total() ),
139
-					$submission->format_amount( $submission->get_recurring_total() ),
137
+					__('%1$s (renews at %2$s / %3$s)', 'invoicing'),
138
+					$submission->format_amount($submission->get_total()),
139
+					$submission->format_amount($submission->get_recurring_total()),
140 140
 					$period
141 141
 				);
142 142
 			}
@@ -146,19 +146,19 @@  discard block
 block discarded – undo
146 146
 			'.getpaid-checkout-total-payable' => $payable,
147 147
 		);
148 148
 
149
-		foreach ( $submission->get_items() as $item ) {
149
+		foreach ($submission->get_items() as $item) {
150 150
 			$item_id                                               = $item->get_id();
151
-			$initial_price                                         = $submission->format_amount( $item->get_sub_total() - $item->item_discount );
152
-			$recurring_price                                       = $submission->format_amount( $item->get_recurring_sub_total() - $item->recurring_item_discount );
153
-			$texts[ ".item-$item_id .getpaid-form-item-price-desc" ] = getpaid_item_recurring_price_help_text( $item, $submission->get_currency(), $initial_price, $recurring_price );
154
-			$texts[ ".item-$item_id .getpaid-mobile-item-subtotal" ] = sprintf( __( 'Subtotal: %s', 'invoicing' ), $submission->format_amount( $item->get_sub_total() ) );
151
+			$initial_price                                         = $submission->format_amount($item->get_sub_total() - $item->item_discount);
152
+			$recurring_price                                       = $submission->format_amount($item->get_recurring_sub_total() - $item->recurring_item_discount);
153
+			$texts[".item-$item_id .getpaid-form-item-price-desc"] = getpaid_item_recurring_price_help_text($item, $submission->get_currency(), $initial_price, $recurring_price);
154
+			$texts[".item-$item_id .getpaid-mobile-item-subtotal"] = sprintf(__('Subtotal: %s', 'invoicing'), $submission->format_amount($item->get_sub_total()));
155 155
 
156
-			if ( $item->get_quantity() == 1 ) {
157
-				$texts[ ".item-$item_id .getpaid-mobile-item-subtotal" ] = '';
156
+			if ($item->get_quantity() == 1) {
157
+				$texts[".item-$item_id .getpaid-mobile-item-subtotal"] = '';
158 158
 			}
159 159
 }
160 160
 
161
-		$this->response = array_merge( $this->response, array( 'texts' => $texts ) );
161
+		$this->response = array_merge($this->response, array('texts' => $texts));
162 162
 
163 163
 	}
164 164
 
@@ -167,20 +167,20 @@  discard block
 block discarded – undo
167 167
 	 *
168 168
 	 * @param GetPaid_Payment_Form_Submission $submission
169 169
 	 */
170
-	public function add_items( $submission ) {
170
+	public function add_items($submission) {
171 171
 
172 172
 		// Add items.
173 173
 		$items          = array();
174 174
 		$selected_items = array();
175 175
 
176
-        foreach ( $submission->get_items() as $item ) {
176
+        foreach ($submission->get_items() as $item) {
177 177
 			$item_id             = $item->get_id();
178
-			$items[ "$item_id" ] = $submission->format_amount( $item->get_sub_total() );
178
+			$items["$item_id"] = $submission->format_amount($item->get_sub_total());
179 179
 
180
-			$selected_items[ "$item_id" ] = array(
180
+			$selected_items["$item_id"] = array(
181 181
 				'quantity'  => $item->get_quantity(),
182 182
 				'price'     => $item->get_price(),
183
-				'price_fmt' => $submission->format_amount( $item->get_price() ),
183
+				'price_fmt' => $submission->format_amount($item->get_price()),
184 184
 			);
185 185
 		}
186 186
 
@@ -199,17 +199,17 @@  discard block
 block discarded – undo
199 199
 	 *
200 200
 	 * @param GetPaid_Payment_Form_Submission $submission
201 201
 	 */
202
-	public function add_fees( $submission ) {
202
+	public function add_fees($submission) {
203 203
 
204 204
 		$fees = array();
205 205
 
206
-        foreach ( $submission->get_fees() as $name => $data ) {
207
-			$fees[ $name ] = $submission->format_amount( $data['initial_fee'] );
206
+        foreach ($submission->get_fees() as $name => $data) {
207
+			$fees[$name] = $submission->format_amount($data['initial_fee']);
208 208
 		}
209 209
 
210 210
 		$this->response = array_merge(
211 211
 			$this->response,
212
-			array( 'fees' => $fees )
212
+			array('fees' => $fees)
213 213
 		);
214 214
 
215 215
 	}
@@ -219,17 +219,17 @@  discard block
 block discarded – undo
219 219
 	 *
220 220
 	 * @param GetPaid_Payment_Form_Submission $submission
221 221
 	 */
222
-	public function add_discounts( $submission ) {
222
+	public function add_discounts($submission) {
223 223
 
224 224
 		$discounts = array();
225 225
 
226
-        foreach ( $submission->get_discounts() as $name => $data ) {
227
-			$discounts[ $name ] = $submission->format_amount( $data['initial_discount'] );
226
+        foreach ($submission->get_discounts() as $name => $data) {
227
+			$discounts[$name] = $submission->format_amount($data['initial_discount']);
228 228
 		}
229 229
 
230 230
 		$this->response = array_merge(
231 231
 			$this->response,
232
-			array( 'discounts' => $discounts )
232
+			array('discounts' => $discounts)
233 233
 		);
234 234
 
235 235
 	}
@@ -239,20 +239,20 @@  discard block
 block discarded – undo
239 239
 	 *
240 240
 	 * @param GetPaid_Payment_Form_Submission $submission
241 241
 	 */
242
-	public function add_taxes( $submission ) {
242
+	public function add_taxes($submission) {
243 243
 
244 244
 		$taxes  = array();
245 245
 		$markup = '';
246
-        foreach ( $submission->get_taxes() as $name => $data ) {
247
-			$name           = sanitize_text_field( $name );
248
-			$amount         = $submission->format_amount( $data['initial_tax'] );
249
-			$taxes[ $name ] = $amount;
246
+        foreach ($submission->get_taxes() as $name => $data) {
247
+			$name           = sanitize_text_field($name);
248
+			$amount         = $submission->format_amount($data['initial_tax']);
249
+			$taxes[$name] = $amount;
250 250
 			$markup        .= "<small class='form-text'>$name : $amount</small>";
251 251
 		}
252 252
 
253 253
 		$this->response = array_merge(
254 254
 			$this->response,
255
-			array( 'taxes' => $taxes )
255
+			array('taxes' => $taxes)
256 256
 		);
257 257
 
258 258
 	}
@@ -262,27 +262,27 @@  discard block
 block discarded – undo
262 262
 	 *
263 263
 	 * @param GetPaid_Payment_Form_Submission $submission
264 264
 	 */
265
-	public function add_gateways( $submission ) {
265
+	public function add_gateways($submission) {
266 266
 
267
-		$gateways = array_keys( wpinv_get_enabled_payment_gateways() );
267
+		$gateways = array_keys(wpinv_get_enabled_payment_gateways());
268 268
 
269
-		if ( $this->response['has_recurring'] ) {
269
+		if ($this->response['has_recurring']) {
270 270
 
271
-			foreach ( $gateways as $i => $gateway ) {
271
+			foreach ($gateways as $i => $gateway) {
272 272
 
273 273
 				if (
274
-					! getpaid_payment_gateway_supports( $gateway, 'subscription' )
275
-					|| ( $this->response['has_subscription_group'] && ! getpaid_payment_gateway_supports( $gateway, 'single_subscription_group' ) )
276
-					|| ( $this->response['has_multiple_subscription_groups'] && ! getpaid_payment_gateway_supports( $gateway, 'multiple_subscription_groups' ) ) ) {
277
-					unset( $gateways[ $i ] );
274
+					!getpaid_payment_gateway_supports($gateway, 'subscription')
275
+					|| ($this->response['has_subscription_group'] && !getpaid_payment_gateway_supports($gateway, 'single_subscription_group'))
276
+					|| ($this->response['has_multiple_subscription_groups'] && !getpaid_payment_gateway_supports($gateway, 'multiple_subscription_groups')) ) {
277
+					unset($gateways[$i]);
278 278
 				}
279 279
 }
280 280
 }
281 281
 
282
-		$gateways = apply_filters( 'getpaid_submission_gateways', $gateways, $submission );
282
+		$gateways = apply_filters('getpaid_submission_gateways', $gateways, $submission);
283 283
 		$this->response = array_merge(
284 284
 			$this->response,
285
-			array( 'gateways' => $gateways )
285
+			array('gateways' => $gateways)
286 286
 		);
287 287
 
288 288
 	}
@@ -292,7 +292,7 @@  discard block
 block discarded – undo
292 292
 	 *
293 293
 	 * @param GetPaid_Payment_Form_Submission $submission
294 294
 	 */
295
-	public function add_data( $submission ) {
295
+	public function add_data($submission) {
296 296
 
297 297
 		$this->response = array_merge(
298 298
 			$this->response,
Please login to merge, or discard this patch.
templates/invoice/header-right-actions.php 1 patch
Spacing   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -8,7 +8,7 @@  discard block
 block discarded – undo
8 8
  * @var WPInv_Invoice $invoice
9 9
  */
10 10
 
11
-defined( 'ABSPATH' ) || exit;
11
+defined('ABSPATH') || exit;
12 12
 
13 13
 ?>
14 14
 
@@ -16,48 +16,48 @@  discard block
 block discarded – undo
16 16
 
17 17
         <?php
18 18
 
19
-            $actions   = array();
19
+            $actions = array();
20 20
 
21 21
             echo sprintf(
22 22
                 '<a href="javascript:void(0)" class="btn btn-sm m-1 d-inline-block btn-secondary text-white invoice-action-print d-none d-lg-inline-block" onclick="window.print();">%s</a>',
23 23
                 sprintf(
24
-                    esc_html__( 'Print %s', 'invoicing' ),
25
-                    esc_html( ucfirst( $invoice->get_invoice_quote_type() ) )
24
+                    esc_html__('Print %s', 'invoicing'),
25
+                    esc_html(ucfirst($invoice->get_invoice_quote_type()))
26 26
                 )
27 27
             );
28 28
 
29
-            if ( is_user_logged_in() ) {
29
+            if (is_user_logged_in()) {
30 30
 
31 31
                 $actions[] = sprintf(
32 32
                     '<a href="%s" class="btn btn-sm btn-secondary text-white m-1 d-inline-block invoice-action-history">%s</a>',
33
-                    esc_url( wpinv_get_history_page_uri( $invoice->get_post_type() ) ),
33
+                    esc_url(wpinv_get_history_page_uri($invoice->get_post_type())),
34 34
                     sprintf(
35
-                        __( '%s History', 'invoicing' ),
36
-                        esc_html( ucfirst( $invoice->get_invoice_quote_type() ) )
35
+                        __('%s History', 'invoicing'),
36
+                        esc_html(ucfirst($invoice->get_invoice_quote_type()))
37 37
                     )
38 38
                 );
39 39
 
40 40
             }
41 41
 
42
-            if ( wpinv_current_user_can_manage_invoicing() ) {
42
+            if (wpinv_current_user_can_manage_invoicing()) {
43 43
 
44 44
                 $actions[] = sprintf(
45 45
                     '<a href="%s" class="btn btn-sm btn-secondary text-white m-1 d-inline-block invoice-action-edit">%s</a>',
46
-                    esc_url( get_edit_post_link( $invoice->get_id() ) ),
46
+                    esc_url(get_edit_post_link($invoice->get_id())),
47 47
                     sprintf(
48
-                        __( 'Edit %s', 'invoicing' ),
49
-                        esc_html( ucfirst( $invoice->get_invoice_quote_type() ) )
48
+                        __('Edit %s', 'invoicing'),
49
+                        esc_html(ucfirst($invoice->get_invoice_quote_type()))
50 50
                     )
51 51
                 );
52 52
 
53 53
             }
54 54
 
55
-            $actions = apply_filters( 'getpaid_invoice_header_right_actions_array', $actions, $invoice );
56
-            echo wp_kses_post( implode( '', $actions ) );
55
+            $actions = apply_filters('getpaid_invoice_header_right_actions_array', $actions, $invoice);
56
+            echo wp_kses_post(implode('', $actions));
57 57
 
58 58
         ?>
59 59
 
60
-        <?php do_action( 'wpinv_invoice_display_right_actions', $invoice ); ?>
60
+        <?php do_action('wpinv_invoice_display_right_actions', $invoice); ?>
61 61
     </div>
62 62
 
63 63
 <?php
Please login to merge, or discard this patch.