@@ -7,42 +7,42 @@ |
||
7 | 7 | * @version 1.0.19 |
8 | 8 | */ |
9 | 9 | |
10 | -defined( 'ABSPATH' ) || exit; |
|
10 | +defined('ABSPATH') || exit; |
|
11 | 11 | |
12 | 12 | ?> |
13 | 13 | |
14 | 14 | <div class='form-group'> |
15 | 15 | <label class="d-block"> |
16 | - <span><?php esc_html_e( 'Field Label', 'invoicing' ); ?></span> |
|
16 | + <span><?php esc_html_e('Field Label', 'invoicing'); ?></span> |
|
17 | 17 | <input v-model='active_form_element.label' class='form-control' type="text"/> |
18 | 18 | </label> |
19 | 19 | </div> |
20 | 20 | |
21 | 21 | <div class='form-group'> |
22 | 22 | <label class="d-block"> |
23 | - <span><?php esc_html_e( 'Help Text', 'invoicing' ); ?></span> |
|
24 | - <textarea placeholder='<?php esc_attr_e( 'Add some help text for this field', 'invoicing' ); ?>' v-model='active_form_element.description' class='form-control' rows='3'></textarea> |
|
25 | - <small class="form-text text-muted"><?php _e( 'HTML is allowed', 'invoicing' ); ?></small> |
|
23 | + <span><?php esc_html_e('Help Text', 'invoicing'); ?></span> |
|
24 | + <textarea placeholder='<?php esc_attr_e('Add some help text for this field', 'invoicing'); ?>' v-model='active_form_element.description' class='form-control' rows='3'></textarea> |
|
25 | + <small class="form-text text-muted"><?php _e('HTML is allowed', 'invoicing'); ?></small> |
|
26 | 26 | </label> |
27 | 27 | </div> |
28 | 28 | |
29 | 29 | <div class='form-group form-check'> |
30 | 30 | <input :id="active_form_element.id + '_edit'" v-model='active_form_element.required' type='checkbox' class='form-check-input' /> |
31 | - <label class='form-check-label' :for="active_form_element.id + '_edit'"><?php esc_html_e( 'Is this field required?', 'invoicing' ); ?></label> |
|
31 | + <label class='form-check-label' :for="active_form_element.id + '_edit'"><?php esc_html_e('Is this field required?', 'invoicing'); ?></label> |
|
32 | 32 | </div> |
33 | 33 | |
34 | 34 | <div class='form-group form-check'> |
35 | 35 | <input :id="active_form_element.id + '_add_meta'" v-model='active_form_element.add_meta' type='checkbox' class='form-check-input' /> |
36 | - <label class='form-check-label' :for="active_form_element.id + '_add_meta'"><?php esc_html_e( 'Show this field in receipts and emails?', 'invoicing' ); ?></label> |
|
36 | + <label class='form-check-label' :for="active_form_element.id + '_add_meta'"><?php esc_html_e('Show this field in receipts and emails?', 'invoicing'); ?></label> |
|
37 | 37 | </div> |
38 | 38 | |
39 | 39 | <hr class='featurette-divider mt-4'> |
40 | 40 | |
41 | 41 | <div class='form-group'> |
42 | 42 | <label class="d-block"> |
43 | - <span><?php esc_html_e( 'Email Merge Tag', 'invoicing' ); ?></span> |
|
43 | + <span><?php esc_html_e('Email Merge Tag', 'invoicing'); ?></span> |
|
44 | 44 | <input :value='active_form_element.label | formatMergeTag' class='form-control bg-white' type="text" readonly onclick="this.select()" /> |
45 | - <span class="form-text text-muted"><?php esc_html_e( 'You can use this merge tag in notification emails', 'invoicing' ); ?></span> |
|
45 | + <span class="form-text text-muted"><?php esc_html_e('You can use this merge tag in notification emails', 'invoicing'); ?></span> |
|
46 | 46 | </label> |
47 | 47 | </div> |
48 | 48 |
@@ -7,49 +7,49 @@ |
||
7 | 7 | * @version 1.0.19 |
8 | 8 | */ |
9 | 9 | |
10 | -defined( 'ABSPATH' ) || exit; |
|
10 | +defined('ABSPATH') || exit; |
|
11 | 11 | |
12 | 12 | ?> |
13 | 13 | |
14 | 14 | <div class='form-group'> |
15 | 15 | <label class="d-block"> |
16 | - <span><?php esc_html_e( 'Field Label', 'invoicing' ); ?></span> |
|
16 | + <span><?php esc_html_e('Field Label', 'invoicing'); ?></span> |
|
17 | 17 | <input v-model='active_form_element.label' class='form-control' type="text"/> |
18 | 18 | </label> |
19 | 19 | </div> |
20 | 20 | |
21 | 21 | <div class='form-group'> |
22 | 22 | <label class="d-block"> |
23 | - <span><?php esc_html_e( 'Placeholder text', 'invoicing' ); ?></span> |
|
23 | + <span><?php esc_html_e('Placeholder text', 'invoicing'); ?></span> |
|
24 | 24 | <input v-model='active_form_element.placeholder' class='form-control' type="text"/> |
25 | 25 | </label> |
26 | 26 | </div> |
27 | 27 | |
28 | 28 | <div class='form-group'> |
29 | 29 | <label class="d-block"> |
30 | - <span><?php esc_html_e( 'Help Text', 'invoicing' ); ?></span> |
|
31 | - <textarea placeholder='<?php esc_attr_e( 'Add some help text for this field', 'invoicing' ); ?>' v-model='active_form_element.description' class='form-control' rows='3'></textarea> |
|
32 | - <small class="form-text text-muted"><?php _e( 'HTML is allowed', 'invoicing' ); ?></small> |
|
30 | + <span><?php esc_html_e('Help Text', 'invoicing'); ?></span> |
|
31 | + <textarea placeholder='<?php esc_attr_e('Add some help text for this field', 'invoicing'); ?>' v-model='active_form_element.description' class='form-control' rows='3'></textarea> |
|
32 | + <small class="form-text text-muted"><?php _e('HTML is allowed', 'invoicing'); ?></small> |
|
33 | 33 | </label> |
34 | 34 | </div> |
35 | 35 | |
36 | 36 | <div class='form-group form-check'> |
37 | 37 | <input :id="active_form_element.id + '_edit'" v-model='active_form_element.required' type='checkbox' class='form-check-input' /> |
38 | - <label class='form-check-label' :for="active_form_element.id + '_edit'"><?php esc_html_e( 'Is this field required?', 'invoicing' ); ?></label> |
|
38 | + <label class='form-check-label' :for="active_form_element.id + '_edit'"><?php esc_html_e('Is this field required?', 'invoicing'); ?></label> |
|
39 | 39 | </div> |
40 | 40 | |
41 | 41 | <div class='form-group form-check'> |
42 | 42 | <input :id="active_form_element.id + '_add_meta'" v-model='active_form_element.add_meta' type='checkbox' class='form-check-input' /> |
43 | - <label class='form-check-label' :for="active_form_element.id + '_add_meta'"><?php esc_html_e( 'Show this field in receipts and emails?', 'invoicing' ); ?></label> |
|
43 | + <label class='form-check-label' :for="active_form_element.id + '_add_meta'"><?php esc_html_e('Show this field in receipts and emails?', 'invoicing'); ?></label> |
|
44 | 44 | </div> |
45 | 45 | |
46 | 46 | <hr class='featurette-divider mt-4'> |
47 | 47 | |
48 | 48 | <div class='form-group'> |
49 | 49 | <label class="d-block"> |
50 | - <span><?php esc_html_e( 'Email Merge Tag', 'invoicing' ); ?></span> |
|
50 | + <span><?php esc_html_e('Email Merge Tag', 'invoicing'); ?></span> |
|
51 | 51 | <input :value='active_form_element.label | formatMergeTag' class='form-control bg-white' type="text" readonly onclick="this.select()" /> |
52 | - <span class="form-text text-muted"><?php esc_html_e( 'You can use this merge tag in notification emails', 'invoicing' ); ?></span> |
|
52 | + <span class="form-text text-muted"><?php esc_html_e('You can use this merge tag in notification emails', 'invoicing'); ?></span> |
|
53 | 53 | </label> |
54 | 54 | </div> |
55 | 55 |
@@ -7,49 +7,49 @@ |
||
7 | 7 | * @version 1.0.19 |
8 | 8 | */ |
9 | 9 | |
10 | -defined( 'ABSPATH' ) || exit; |
|
10 | +defined('ABSPATH') || exit; |
|
11 | 11 | |
12 | 12 | ?> |
13 | 13 | |
14 | 14 | <div class='form-group'> |
15 | 15 | <label class="d-block"> |
16 | - <span><?php esc_html_e( 'Field Label', 'invoicing' ); ?></span> |
|
16 | + <span><?php esc_html_e('Field Label', 'invoicing'); ?></span> |
|
17 | 17 | <input v-model='active_form_element.label' class='form-control' type="text"/> |
18 | 18 | </label> |
19 | 19 | </div> |
20 | 20 | |
21 | 21 | <div class='form-group'> |
22 | 22 | <label class="d-block"> |
23 | - <span><?php esc_html_e( 'Placeholder text', 'invoicing' ); ?></span> |
|
23 | + <span><?php esc_html_e('Placeholder text', 'invoicing'); ?></span> |
|
24 | 24 | <input v-model='active_form_element.placeholder' class='form-control' type="text"/> |
25 | 25 | </label> |
26 | 26 | </div> |
27 | 27 | |
28 | 28 | <div class='form-group'> |
29 | 29 | <label class="d-block"> |
30 | - <span><?php esc_html_e( 'Help Text', 'invoicing' ); ?></span> |
|
31 | - <textarea placeholder='<?php esc_attr_e( 'Add some help text for this field', 'invoicing' ); ?>' v-model='active_form_element.description' class='form-control' rows='3'></textarea> |
|
32 | - <small class="form-text text-muted"><?php _e( 'HTML is allowed', 'invoicing' ); ?></small> |
|
30 | + <span><?php esc_html_e('Help Text', 'invoicing'); ?></span> |
|
31 | + <textarea placeholder='<?php esc_attr_e('Add some help text for this field', 'invoicing'); ?>' v-model='active_form_element.description' class='form-control' rows='3'></textarea> |
|
32 | + <small class="form-text text-muted"><?php _e('HTML is allowed', 'invoicing'); ?></small> |
|
33 | 33 | </label> |
34 | 34 | </div> |
35 | 35 | |
36 | 36 | <div class='form-group form-check'> |
37 | 37 | <input :id="active_form_element.id + '_edit'" v-model='active_form_element.required' type='checkbox' class='form-check-input' /> |
38 | - <label class='form-check-label' :for="active_form_element.id + '_edit'"><?php esc_html_e( 'Is this field required?', 'invoicing' ); ?></label> |
|
38 | + <label class='form-check-label' :for="active_form_element.id + '_edit'"><?php esc_html_e('Is this field required?', 'invoicing'); ?></label> |
|
39 | 39 | </div> |
40 | 40 | |
41 | 41 | <div class='form-group form-check'> |
42 | 42 | <input :id="active_form_element.id + '_add_meta'" v-model='active_form_element.add_meta' type='checkbox' class='form-check-input' /> |
43 | - <label class='form-check-label' :for="active_form_element.id + '_add_meta'"><?php esc_html_e( 'Show this field in receipts and emails?', 'invoicing' ); ?></label> |
|
43 | + <label class='form-check-label' :for="active_form_element.id + '_add_meta'"><?php esc_html_e('Show this field in receipts and emails?', 'invoicing'); ?></label> |
|
44 | 44 | </div> |
45 | 45 | |
46 | 46 | <hr class='featurette-divider mt-4'> |
47 | 47 | |
48 | 48 | <div class='form-group'> |
49 | 49 | <label class="d-block"> |
50 | - <span><?php esc_html_e( 'Email Merge Tag', 'invoicing' ); ?></span> |
|
50 | + <span><?php esc_html_e('Email Merge Tag', 'invoicing'); ?></span> |
|
51 | 51 | <input :value='active_form_element.label | formatMergeTag' class='form-control bg-white' type="text" readonly onclick="this.select()" /> |
52 | - <span class="form-text text-muted"><?php esc_html_e( 'You can use this merge tag in notification emails', 'invoicing' ); ?></span> |
|
52 | + <span class="form-text text-muted"><?php esc_html_e('You can use this merge tag in notification emails', 'invoicing'); ?></span> |
|
53 | 53 | </label> |
54 | 54 | </div> |
55 | 55 |
@@ -7,49 +7,49 @@ |
||
7 | 7 | * @version 1.0.19 |
8 | 8 | */ |
9 | 9 | |
10 | -defined( 'ABSPATH' ) || exit; |
|
10 | +defined('ABSPATH') || exit; |
|
11 | 11 | |
12 | 12 | ?> |
13 | 13 | |
14 | 14 | <div class='form-group'> |
15 | 15 | <label class="d-block"> |
16 | - <span><?php esc_html_e( 'Field Label', 'invoicing' ); ?></span> |
|
16 | + <span><?php esc_html_e('Field Label', 'invoicing'); ?></span> |
|
17 | 17 | <input v-model='active_form_element.label' class='form-control' type="text"/> |
18 | 18 | </label> |
19 | 19 | </div> |
20 | 20 | |
21 | 21 | <div class='form-group'> |
22 | 22 | <label class="d-block"> |
23 | - <span><?php esc_html_e( 'Placeholder text', 'invoicing' ); ?></span> |
|
23 | + <span><?php esc_html_e('Placeholder text', 'invoicing'); ?></span> |
|
24 | 24 | <input v-model='active_form_element.placeholder' class='form-control' type="text"/> |
25 | 25 | </label> |
26 | 26 | </div> |
27 | 27 | |
28 | 28 | <div class='form-group'> |
29 | 29 | <label class="d-block"> |
30 | - <span><?php esc_html_e( 'Help Text', 'invoicing' ); ?></span> |
|
31 | - <textarea placeholder='<?php esc_attr_e( 'Add some help text for this field', 'invoicing' ); ?>' v-model='active_form_element.description' class='form-control' rows='3'></textarea> |
|
32 | - <small class="form-text text-muted"><?php _e( 'HTML is allowed', 'invoicing' ); ?></small> |
|
30 | + <span><?php esc_html_e('Help Text', 'invoicing'); ?></span> |
|
31 | + <textarea placeholder='<?php esc_attr_e('Add some help text for this field', 'invoicing'); ?>' v-model='active_form_element.description' class='form-control' rows='3'></textarea> |
|
32 | + <small class="form-text text-muted"><?php _e('HTML is allowed', 'invoicing'); ?></small> |
|
33 | 33 | </label> |
34 | 34 | </div> |
35 | 35 | |
36 | 36 | <div class='form-group form-check'> |
37 | 37 | <input :id="active_form_element.id + '_edit'" v-model='active_form_element.required' type='checkbox' class='form-check-input' /> |
38 | - <label class='form-check-label' :for="active_form_element.id + '_edit'"><?php esc_html_e( 'Is this field required?', 'invoicing' ); ?></label> |
|
38 | + <label class='form-check-label' :for="active_form_element.id + '_edit'"><?php esc_html_e('Is this field required?', 'invoicing'); ?></label> |
|
39 | 39 | </div> |
40 | 40 | |
41 | 41 | <div class='form-group form-check'> |
42 | 42 | <input :id="active_form_element.id + '_add_meta'" v-model='active_form_element.add_meta' type='checkbox' class='form-check-input' /> |
43 | - <label class='form-check-label' :for="active_form_element.id + '_add_meta'"><?php esc_html_e( 'Show this field in receipts and emails?', 'invoicing' ); ?></label> |
|
43 | + <label class='form-check-label' :for="active_form_element.id + '_add_meta'"><?php esc_html_e('Show this field in receipts and emails?', 'invoicing'); ?></label> |
|
44 | 44 | </div> |
45 | 45 | |
46 | 46 | <hr class='featurette-divider mt-4'> |
47 | 47 | |
48 | 48 | <div class='form-group'> |
49 | 49 | <label class="d-block"> |
50 | - <span><?php esc_html_e( 'Email Merge Tag', 'invoicing' ); ?></span> |
|
50 | + <span><?php esc_html_e('Email Merge Tag', 'invoicing'); ?></span> |
|
51 | 51 | <input :value='active_form_element.label | formatMergeTag' class='form-control bg-white' type="text" readonly onclick="this.select()" /> |
52 | - <span class="form-text text-muted"><?php esc_html_e( 'You can use this merge tag in notification emails', 'invoicing' ); ?></span> |
|
52 | + <span class="form-text text-muted"><?php esc_html_e('You can use this merge tag in notification emails', 'invoicing'); ?></span> |
|
53 | 53 | </label> |
54 | 54 | </div> |
55 | 55 |
@@ -12,114 +12,114 @@ |
||
12 | 12 | */ |
13 | 13 | class GetPaid_Payment_Form_Submission_Fees { |
14 | 14 | |
15 | - /** |
|
16 | - * The fee validation error. |
|
17 | - * @var string |
|
18 | - */ |
|
19 | - public $fee_error; |
|
20 | - |
|
21 | - /** |
|
22 | - * Submission fees. |
|
23 | - * @var array |
|
24 | - */ |
|
25 | - public $fees = array(); |
|
15 | + /** |
|
16 | + * The fee validation error. |
|
17 | + * @var string |
|
18 | + */ |
|
19 | + public $fee_error; |
|
20 | + |
|
21 | + /** |
|
22 | + * Submission fees. |
|
23 | + * @var array |
|
24 | + */ |
|
25 | + public $fees = array(); |
|
26 | + |
|
27 | + /** |
|
28 | + * Class constructor |
|
29 | + * |
|
30 | + * @param GetPaid_Payment_Form_Submission $submission |
|
31 | + */ |
|
32 | + public function __construct( $submission ) { |
|
33 | + |
|
34 | + // Process any existing invoice fees. |
|
35 | + if ( $submission->has_invoice() ) { |
|
36 | + $this->fees = $submission->get_invoice()->get_fees(); |
|
37 | + } |
|
38 | + |
|
39 | + // Process price fields. |
|
40 | + $data = $submission->get_data(); |
|
41 | + $payment_form = $submission->get_payment_form(); |
|
42 | + |
|
43 | + foreach ( $payment_form->get_elements() as $element ) { |
|
44 | + |
|
45 | + if ( 'price_input' == $element['type'] ) { |
|
46 | + $this->process_price_input( $element, $data, $submission ); |
|
47 | + } |
|
48 | + |
|
49 | + if ( 'price_select' == $element['type'] ) { |
|
50 | + $this->process_price_select( $element, $data ); |
|
51 | + } |
|
52 | + |
|
53 | + } |
|
54 | + |
|
55 | + } |
|
56 | + |
|
57 | + /** |
|
58 | + * Process a price input field. |
|
59 | + * |
|
60 | + * @param array $element |
|
61 | + * @param array $data |
|
62 | + * @param GetPaid_Payment_Form_Submission $submission |
|
63 | + */ |
|
64 | + public function process_price_input( $element, $data, $submission ) { |
|
65 | + |
|
66 | + // Abort if not passed. |
|
67 | + if ( empty( $data[ $element['id'] ] ) ) { |
|
68 | + return; |
|
69 | + } |
|
70 | + |
|
71 | + $amount = (float) wpinv_sanitize_amount( $data[ $element['id'] ] ); |
|
72 | + $minimum = empty( $element['minimum'] ) ? 0 : (float) wpinv_sanitize_amount( $element['minimum'] ); |
|
73 | + |
|
74 | + if ( $amount < $minimum ) { |
|
75 | + throw new Exception( sprintf( __( 'The minimum allowed amount is %s', 'invoicing' ), getpaid_unstandardize_amount( $minimum, $submission->get_currency() ) ) ); |
|
76 | + } |
|
77 | + |
|
78 | + $this->fees[ $element['label'] ] = array( |
|
79 | + 'name' => $element['label'], |
|
80 | + 'initial_fee' => $amount, |
|
81 | + 'recurring_fee' => 0, |
|
82 | + ); |
|
83 | + |
|
84 | + } |
|
26 | 85 | |
27 | 86 | /** |
28 | - * Class constructor |
|
29 | - * |
|
30 | - * @param GetPaid_Payment_Form_Submission $submission |
|
31 | - */ |
|
32 | - public function __construct( $submission ) { |
|
33 | - |
|
34 | - // Process any existing invoice fees. |
|
35 | - if ( $submission->has_invoice() ) { |
|
36 | - $this->fees = $submission->get_invoice()->get_fees(); |
|
37 | - } |
|
38 | - |
|
39 | - // Process price fields. |
|
40 | - $data = $submission->get_data(); |
|
41 | - $payment_form = $submission->get_payment_form(); |
|
42 | - |
|
43 | - foreach ( $payment_form->get_elements() as $element ) { |
|
44 | - |
|
45 | - if ( 'price_input' == $element['type'] ) { |
|
46 | - $this->process_price_input( $element, $data, $submission ); |
|
47 | - } |
|
48 | - |
|
49 | - if ( 'price_select' == $element['type'] ) { |
|
50 | - $this->process_price_select( $element, $data ); |
|
51 | - } |
|
52 | - |
|
53 | - } |
|
54 | - |
|
55 | - } |
|
56 | - |
|
57 | - /** |
|
58 | - * Process a price input field. |
|
59 | - * |
|
60 | - * @param array $element |
|
61 | - * @param array $data |
|
62 | - * @param GetPaid_Payment_Form_Submission $submission |
|
63 | - */ |
|
64 | - public function process_price_input( $element, $data, $submission ) { |
|
65 | - |
|
66 | - // Abort if not passed. |
|
67 | - if ( empty( $data[ $element['id'] ] ) ) { |
|
68 | - return; |
|
69 | - } |
|
70 | - |
|
71 | - $amount = (float) wpinv_sanitize_amount( $data[ $element['id'] ] ); |
|
72 | - $minimum = empty( $element['minimum'] ) ? 0 : (float) wpinv_sanitize_amount( $element['minimum'] ); |
|
73 | - |
|
74 | - if ( $amount < $minimum ) { |
|
75 | - throw new Exception( sprintf( __( 'The minimum allowed amount is %s', 'invoicing' ), getpaid_unstandardize_amount( $minimum, $submission->get_currency() ) ) ); |
|
76 | - } |
|
77 | - |
|
78 | - $this->fees[ $element['label'] ] = array( |
|
79 | - 'name' => $element['label'], |
|
80 | - 'initial_fee' => $amount, |
|
81 | - 'recurring_fee' => 0, |
|
82 | - ); |
|
83 | - |
|
84 | - } |
|
85 | - |
|
86 | - /** |
|
87 | - * Process a price select field. |
|
88 | - * |
|
89 | - * @param array $element |
|
90 | - * @param array $data |
|
91 | - */ |
|
92 | - public function process_price_select( $element, $data ) { |
|
93 | - |
|
94 | - // Abort if not passed. |
|
95 | - if ( empty( $data[ $element['id'] ] ) ) { |
|
96 | - return; |
|
97 | - } |
|
98 | - |
|
99 | - $options = getpaid_convert_price_string_to_options( $element['options'] ); |
|
100 | - $selected = array_filter( array_map( 'trim', explode( ',', $data[ $element['id'] ] ) ) ); |
|
101 | - $total = 0; |
|
102 | - $sub_labels = array(); |
|
103 | - |
|
104 | - foreach ( $selected as $price ) { |
|
105 | - |
|
106 | - if ( ! isset( $options[ $price ] ) ) { |
|
107 | - throw new Exception( __( 'You have selected an invalid amount', 'invoicing' ) ); |
|
108 | - } |
|
109 | - |
|
110 | - $price = explode( '|', $price ); |
|
111 | - |
|
112 | - $sub_labels[] = $price[0]; |
|
113 | - $total += (float) wpinv_sanitize_amount( $price[1] ); |
|
114 | - } |
|
115 | - |
|
116 | - $this->fees[ $element['label'] ] = array( |
|
117 | - 'name' => $element['label'], |
|
118 | - 'initial_fee' => $total, |
|
119 | - 'recurring_fee' => 0, |
|
120 | - 'description' => implode( ', ', $sub_labels ), |
|
121 | - ); |
|
122 | - |
|
123 | - } |
|
87 | + * Process a price select field. |
|
88 | + * |
|
89 | + * @param array $element |
|
90 | + * @param array $data |
|
91 | + */ |
|
92 | + public function process_price_select( $element, $data ) { |
|
93 | + |
|
94 | + // Abort if not passed. |
|
95 | + if ( empty( $data[ $element['id'] ] ) ) { |
|
96 | + return; |
|
97 | + } |
|
98 | + |
|
99 | + $options = getpaid_convert_price_string_to_options( $element['options'] ); |
|
100 | + $selected = array_filter( array_map( 'trim', explode( ',', $data[ $element['id'] ] ) ) ); |
|
101 | + $total = 0; |
|
102 | + $sub_labels = array(); |
|
103 | + |
|
104 | + foreach ( $selected as $price ) { |
|
105 | + |
|
106 | + if ( ! isset( $options[ $price ] ) ) { |
|
107 | + throw new Exception( __( 'You have selected an invalid amount', 'invoicing' ) ); |
|
108 | + } |
|
109 | + |
|
110 | + $price = explode( '|', $price ); |
|
111 | + |
|
112 | + $sub_labels[] = $price[0]; |
|
113 | + $total += (float) wpinv_sanitize_amount( $price[1] ); |
|
114 | + } |
|
115 | + |
|
116 | + $this->fees[ $element['label'] ] = array( |
|
117 | + 'name' => $element['label'], |
|
118 | + 'initial_fee' => $total, |
|
119 | + 'recurring_fee' => 0, |
|
120 | + 'description' => implode( ', ', $sub_labels ), |
|
121 | + ); |
|
122 | + |
|
123 | + } |
|
124 | 124 | |
125 | 125 | } |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | * |
5 | 5 | */ |
6 | 6 | |
7 | -defined( 'ABSPATH' ) || exit; |
|
7 | +defined('ABSPATH') || exit; |
|
8 | 8 | |
9 | 9 | /** |
10 | 10 | * Payment form submission fees class |
@@ -29,10 +29,10 @@ discard block |
||
29 | 29 | * |
30 | 30 | * @param GetPaid_Payment_Form_Submission $submission |
31 | 31 | */ |
32 | - public function __construct( $submission ) { |
|
32 | + public function __construct($submission) { |
|
33 | 33 | |
34 | 34 | // Process any existing invoice fees. |
35 | - if ( $submission->has_invoice() ) { |
|
35 | + if ($submission->has_invoice()) { |
|
36 | 36 | $this->fees = $submission->get_invoice()->get_fees(); |
37 | 37 | } |
38 | 38 | |
@@ -40,14 +40,14 @@ discard block |
||
40 | 40 | $data = $submission->get_data(); |
41 | 41 | $payment_form = $submission->get_payment_form(); |
42 | 42 | |
43 | - foreach ( $payment_form->get_elements() as $element ) { |
|
43 | + foreach ($payment_form->get_elements() as $element) { |
|
44 | 44 | |
45 | - if ( 'price_input' == $element['type'] ) { |
|
46 | - $this->process_price_input( $element, $data, $submission ); |
|
45 | + if ('price_input' == $element['type']) { |
|
46 | + $this->process_price_input($element, $data, $submission); |
|
47 | 47 | } |
48 | 48 | |
49 | - if ( 'price_select' == $element['type'] ) { |
|
50 | - $this->process_price_select( $element, $data ); |
|
49 | + if ('price_select' == $element['type']) { |
|
50 | + $this->process_price_select($element, $data); |
|
51 | 51 | } |
52 | 52 | |
53 | 53 | } |
@@ -61,21 +61,21 @@ discard block |
||
61 | 61 | * @param array $data |
62 | 62 | * @param GetPaid_Payment_Form_Submission $submission |
63 | 63 | */ |
64 | - public function process_price_input( $element, $data, $submission ) { |
|
64 | + public function process_price_input($element, $data, $submission) { |
|
65 | 65 | |
66 | 66 | // Abort if not passed. |
67 | - if ( empty( $data[ $element['id'] ] ) ) { |
|
67 | + if (empty($data[$element['id']])) { |
|
68 | 68 | return; |
69 | 69 | } |
70 | 70 | |
71 | - $amount = (float) wpinv_sanitize_amount( $data[ $element['id'] ] ); |
|
72 | - $minimum = empty( $element['minimum'] ) ? 0 : (float) wpinv_sanitize_amount( $element['minimum'] ); |
|
71 | + $amount = (float) wpinv_sanitize_amount($data[$element['id']]); |
|
72 | + $minimum = empty($element['minimum']) ? 0 : (float) wpinv_sanitize_amount($element['minimum']); |
|
73 | 73 | |
74 | - if ( $amount < $minimum ) { |
|
75 | - throw new Exception( sprintf( __( 'The minimum allowed amount is %s', 'invoicing' ), getpaid_unstandardize_amount( $minimum, $submission->get_currency() ) ) ); |
|
74 | + if ($amount < $minimum) { |
|
75 | + throw new Exception(sprintf(__('The minimum allowed amount is %s', 'invoicing'), getpaid_unstandardize_amount($minimum, $submission->get_currency()))); |
|
76 | 76 | } |
77 | 77 | |
78 | - $this->fees[ $element['label'] ] = array( |
|
78 | + $this->fees[$element['label']] = array( |
|
79 | 79 | 'name' => $element['label'], |
80 | 80 | 'initial_fee' => $amount, |
81 | 81 | 'recurring_fee' => 0, |
@@ -89,35 +89,35 @@ discard block |
||
89 | 89 | * @param array $element |
90 | 90 | * @param array $data |
91 | 91 | */ |
92 | - public function process_price_select( $element, $data ) { |
|
92 | + public function process_price_select($element, $data) { |
|
93 | 93 | |
94 | 94 | // Abort if not passed. |
95 | - if ( empty( $data[ $element['id'] ] ) ) { |
|
95 | + if (empty($data[$element['id']])) { |
|
96 | 96 | return; |
97 | 97 | } |
98 | 98 | |
99 | - $options = getpaid_convert_price_string_to_options( $element['options'] ); |
|
100 | - $selected = array_filter( array_map( 'trim', explode( ',', $data[ $element['id'] ] ) ) ); |
|
99 | + $options = getpaid_convert_price_string_to_options($element['options']); |
|
100 | + $selected = array_filter(array_map('trim', explode(',', $data[$element['id']]))); |
|
101 | 101 | $total = 0; |
102 | 102 | $sub_labels = array(); |
103 | 103 | |
104 | - foreach ( $selected as $price ) { |
|
104 | + foreach ($selected as $price) { |
|
105 | 105 | |
106 | - if ( ! isset( $options[ $price ] ) ) { |
|
107 | - throw new Exception( __( 'You have selected an invalid amount', 'invoicing' ) ); |
|
106 | + if (!isset($options[$price])) { |
|
107 | + throw new Exception(__('You have selected an invalid amount', 'invoicing')); |
|
108 | 108 | } |
109 | 109 | |
110 | - $price = explode( '|', $price ); |
|
110 | + $price = explode('|', $price); |
|
111 | 111 | |
112 | 112 | $sub_labels[] = $price[0]; |
113 | - $total += (float) wpinv_sanitize_amount( $price[1] ); |
|
113 | + $total += (float) wpinv_sanitize_amount($price[1]); |
|
114 | 114 | } |
115 | 115 | |
116 | - $this->fees[ $element['label'] ] = array( |
|
116 | + $this->fees[$element['label']] = array( |
|
117 | 117 | 'name' => $element['label'], |
118 | 118 | 'initial_fee' => $total, |
119 | 119 | 'recurring_fee' => 0, |
120 | - 'description' => implode( ', ', $sub_labels ), |
|
120 | + 'description' => implode(', ', $sub_labels), |
|
121 | 121 | ); |
122 | 122 | |
123 | 123 | } |
@@ -17,397 +17,397 @@ |
||
17 | 17 | */ |
18 | 18 | class GetPaid_Admin_Setup_Wizard { |
19 | 19 | |
20 | - /** |
|
21 | - * @var string Current Step |
|
22 | - */ |
|
23 | - protected $step = ''; |
|
24 | - |
|
25 | - /** |
|
26 | - * @var string|false Previous Step |
|
27 | - */ |
|
28 | - protected $previous_step = ''; |
|
29 | - |
|
30 | - /** |
|
31 | - * @var string|false Next Step |
|
32 | - */ |
|
33 | - protected $next_step = ''; |
|
34 | - |
|
35 | - /** |
|
36 | - * @var array All available steps for the setup wizard |
|
37 | - */ |
|
38 | - protected $steps = array(); |
|
39 | - |
|
40 | - /** |
|
41 | - * Class constructor. |
|
42 | - * |
|
43 | - * @since 2.4.0 |
|
44 | - */ |
|
45 | - public function __construct() { |
|
46 | - |
|
47 | - if ( apply_filters( 'getpaid_enable_setup_wizard', true ) && wpinv_current_user_can_manage_invoicing() ) { |
|
48 | - add_action( 'admin_menu', array( $this, 'add_menu' ) ); |
|
49 | - add_action( 'current_screen', array( $this, 'setup_wizard' ) ); |
|
50 | - } |
|
51 | - |
|
52 | - } |
|
53 | - |
|
54 | - /** |
|
55 | - * Add admin menus/screens. |
|
56 | - * |
|
57 | - * @since 2.4.0 |
|
58 | - */ |
|
59 | - public function add_menu() { |
|
60 | - add_dashboard_page( '', '', wpinv_get_capability(), 'gp-setup', '' ); |
|
61 | - } |
|
62 | - |
|
63 | - /** |
|
64 | - * Sets up the setup wizard. |
|
65 | - * |
|
66 | - * @since 2.4.0 |
|
67 | - */ |
|
68 | - public function setup_wizard() { |
|
69 | - |
|
70 | - if ( isset( $_GET['page'] ) && 'gp-setup' === $_GET['page'] ) { |
|
71 | - $this->setup_globals(); |
|
72 | - $this->maybe_save_current_step(); |
|
73 | - $this->display_wizard(); |
|
74 | - exit; |
|
75 | - } |
|
76 | - |
|
77 | - } |
|
78 | - |
|
79 | - /** |
|
80 | - * Sets up class variables. |
|
81 | - * |
|
82 | - * @since 2.4.0 |
|
83 | - */ |
|
84 | - protected function setup_globals() { |
|
85 | - $this->steps = $this->get_setup_steps(); |
|
86 | - $this->step = $this->get_current_step(); |
|
87 | - $this->previous_step = $this->get_previous_step(); |
|
88 | - $this->next_step = $this->get_next_step(); |
|
89 | - } |
|
90 | - |
|
91 | - /** |
|
92 | - * Saves the current step. |
|
93 | - * |
|
94 | - * @since 2.4.0 |
|
95 | - */ |
|
96 | - protected function maybe_save_current_step() { |
|
97 | - if ( ! empty( $_POST['save_step'] ) && is_callable( $this->steps[ $this->step ]['handler'] ) ) { |
|
98 | - call_user_func( $this->steps[ $this->step ]['handler'], $this ); |
|
99 | - } |
|
100 | - } |
|
101 | - |
|
102 | - /** |
|
103 | - * Returns the setup steps. |
|
104 | - * |
|
105 | - * @since 2.4.0 |
|
106 | - * @return array |
|
107 | - */ |
|
108 | - protected function get_setup_steps() { |
|
109 | - |
|
110 | - $steps = array( |
|
111 | - |
|
112 | - 'introduction' => array( |
|
113 | - 'name' => __( 'Introduction', 'invoicing' ), |
|
114 | - 'view' => array( $this, 'setup_introduction' ), |
|
115 | - 'handler' => '', |
|
116 | - ), |
|
117 | - |
|
118 | - 'business_details' => array( |
|
119 | - 'name' => __( "Business Details", 'invoicing' ), |
|
120 | - 'view' => array( $this, 'setup_business' ), |
|
121 | - 'handler' => '', |
|
122 | - ), |
|
123 | - |
|
124 | - 'currency' => array( |
|
125 | - 'name' => __( 'Currency', 'invoicing' ), |
|
126 | - 'view' => array( $this, 'setup_currency' ), |
|
127 | - 'handler' => '', |
|
128 | - ), |
|
129 | - |
|
130 | - 'payments' => array( |
|
131 | - 'name' => __( 'Payment Gateways', 'invoicing' ), |
|
132 | - 'view' => array( $this, 'setup_payments' ), |
|
133 | - 'handler' => array( $this, 'setup_payments_save' ), |
|
134 | - ), |
|
135 | - |
|
136 | - 'recommend' => array( |
|
137 | - 'name' => __( 'Recommend', 'invoicing' ), |
|
138 | - 'view' => array( $this, 'setup_recommend' ), |
|
139 | - 'handler' => '', |
|
140 | - ), |
|
141 | - |
|
142 | - 'next_steps' => array( |
|
143 | - 'name' => __( 'Get Paid', 'invoicing' ), |
|
144 | - 'view' => array( $this, 'setup_ready' ), |
|
145 | - 'handler' => '', |
|
146 | - ), |
|
147 | - |
|
148 | - ); |
|
149 | - |
|
150 | - return apply_filters( 'getpaid_setup_wizard_steps', $steps ); |
|
151 | - |
|
152 | - } |
|
153 | - |
|
154 | - /** |
|
155 | - * Returns the current step. |
|
156 | - * |
|
157 | - * @since 2.4.0 |
|
158 | - * @return string |
|
159 | - */ |
|
160 | - protected function get_current_step() { |
|
161 | - $step = isset( $_GET['step'] ) ? sanitize_key( $_GET['step'] ) : ''; |
|
162 | - return ! empty( $step ) && in_array( $step, array_keys( $this->steps ) ) ? $step : current( array_keys( $this->steps ) ); |
|
163 | - } |
|
164 | - |
|
165 | - /** |
|
166 | - * Returns the previous step. |
|
167 | - * |
|
168 | - * @since 2.4.0 |
|
169 | - * @return string|false |
|
170 | - */ |
|
171 | - protected function get_previous_step() { |
|
172 | - |
|
173 | - $previous = false; |
|
174 | - $current = $this->step; |
|
175 | - foreach ( array_keys( $this->steps ) as $step ) { |
|
176 | - if ( $current === $step ) { |
|
177 | - return $previous; |
|
178 | - } |
|
179 | - |
|
180 | - $previous = $step; |
|
181 | - } |
|
182 | - |
|
183 | - return false; |
|
184 | - } |
|
185 | - |
|
186 | - /** |
|
187 | - * Returns the next step. |
|
188 | - * |
|
189 | - * @since 2.4.0 |
|
190 | - * @return string|false |
|
191 | - */ |
|
192 | - protected function get_next_step() { |
|
193 | - |
|
194 | - $on_current = false; |
|
195 | - $current = $this->step; |
|
196 | - foreach ( array_keys( $this->steps ) as $step ) { |
|
197 | - |
|
198 | - if ( $on_current ) { |
|
199 | - return $step; |
|
200 | - } |
|
201 | - |
|
202 | - if ( $current === $step ) { |
|
203 | - return $on_current = true; |
|
204 | - } |
|
205 | - |
|
206 | - } |
|
207 | - |
|
208 | - return false; |
|
209 | - } |
|
210 | - |
|
211 | - /** |
|
212 | - * Displays the setup wizard. |
|
213 | - * |
|
214 | - * @since 2.4.0 |
|
215 | - */ |
|
216 | - public function display_wizard() { |
|
217 | - $this->display_header(); |
|
218 | - $this->display_current_step(); |
|
219 | - $this->display_footer(); |
|
220 | - } |
|
221 | - |
|
222 | - /** |
|
223 | - * Displays the Wizard Header. |
|
224 | - * |
|
225 | - * @since 2.0.0 |
|
226 | - */ |
|
227 | - public function display_header() { |
|
228 | - $steps = $this->steps; |
|
229 | - $current = $this->step; |
|
230 | - $next_step = $this->next_step; |
|
231 | - array_shift( $steps ); |
|
232 | - include plugin_dir_path( __FILE__ ) . 'views/wizard-header.php'; |
|
233 | - } |
|
234 | - |
|
235 | - /** |
|
236 | - * Displays the content for the current step. |
|
237 | - * |
|
238 | - * @since 2.4.0 |
|
239 | - */ |
|
240 | - public function display_current_step() { |
|
241 | - ?> |
|
20 | + /** |
|
21 | + * @var string Current Step |
|
22 | + */ |
|
23 | + protected $step = ''; |
|
24 | + |
|
25 | + /** |
|
26 | + * @var string|false Previous Step |
|
27 | + */ |
|
28 | + protected $previous_step = ''; |
|
29 | + |
|
30 | + /** |
|
31 | + * @var string|false Next Step |
|
32 | + */ |
|
33 | + protected $next_step = ''; |
|
34 | + |
|
35 | + /** |
|
36 | + * @var array All available steps for the setup wizard |
|
37 | + */ |
|
38 | + protected $steps = array(); |
|
39 | + |
|
40 | + /** |
|
41 | + * Class constructor. |
|
42 | + * |
|
43 | + * @since 2.4.0 |
|
44 | + */ |
|
45 | + public function __construct() { |
|
46 | + |
|
47 | + if ( apply_filters( 'getpaid_enable_setup_wizard', true ) && wpinv_current_user_can_manage_invoicing() ) { |
|
48 | + add_action( 'admin_menu', array( $this, 'add_menu' ) ); |
|
49 | + add_action( 'current_screen', array( $this, 'setup_wizard' ) ); |
|
50 | + } |
|
51 | + |
|
52 | + } |
|
53 | + |
|
54 | + /** |
|
55 | + * Add admin menus/screens. |
|
56 | + * |
|
57 | + * @since 2.4.0 |
|
58 | + */ |
|
59 | + public function add_menu() { |
|
60 | + add_dashboard_page( '', '', wpinv_get_capability(), 'gp-setup', '' ); |
|
61 | + } |
|
62 | + |
|
63 | + /** |
|
64 | + * Sets up the setup wizard. |
|
65 | + * |
|
66 | + * @since 2.4.0 |
|
67 | + */ |
|
68 | + public function setup_wizard() { |
|
69 | + |
|
70 | + if ( isset( $_GET['page'] ) && 'gp-setup' === $_GET['page'] ) { |
|
71 | + $this->setup_globals(); |
|
72 | + $this->maybe_save_current_step(); |
|
73 | + $this->display_wizard(); |
|
74 | + exit; |
|
75 | + } |
|
76 | + |
|
77 | + } |
|
78 | + |
|
79 | + /** |
|
80 | + * Sets up class variables. |
|
81 | + * |
|
82 | + * @since 2.4.0 |
|
83 | + */ |
|
84 | + protected function setup_globals() { |
|
85 | + $this->steps = $this->get_setup_steps(); |
|
86 | + $this->step = $this->get_current_step(); |
|
87 | + $this->previous_step = $this->get_previous_step(); |
|
88 | + $this->next_step = $this->get_next_step(); |
|
89 | + } |
|
90 | + |
|
91 | + /** |
|
92 | + * Saves the current step. |
|
93 | + * |
|
94 | + * @since 2.4.0 |
|
95 | + */ |
|
96 | + protected function maybe_save_current_step() { |
|
97 | + if ( ! empty( $_POST['save_step'] ) && is_callable( $this->steps[ $this->step ]['handler'] ) ) { |
|
98 | + call_user_func( $this->steps[ $this->step ]['handler'], $this ); |
|
99 | + } |
|
100 | + } |
|
101 | + |
|
102 | + /** |
|
103 | + * Returns the setup steps. |
|
104 | + * |
|
105 | + * @since 2.4.0 |
|
106 | + * @return array |
|
107 | + */ |
|
108 | + protected function get_setup_steps() { |
|
109 | + |
|
110 | + $steps = array( |
|
111 | + |
|
112 | + 'introduction' => array( |
|
113 | + 'name' => __( 'Introduction', 'invoicing' ), |
|
114 | + 'view' => array( $this, 'setup_introduction' ), |
|
115 | + 'handler' => '', |
|
116 | + ), |
|
117 | + |
|
118 | + 'business_details' => array( |
|
119 | + 'name' => __( "Business Details", 'invoicing' ), |
|
120 | + 'view' => array( $this, 'setup_business' ), |
|
121 | + 'handler' => '', |
|
122 | + ), |
|
123 | + |
|
124 | + 'currency' => array( |
|
125 | + 'name' => __( 'Currency', 'invoicing' ), |
|
126 | + 'view' => array( $this, 'setup_currency' ), |
|
127 | + 'handler' => '', |
|
128 | + ), |
|
129 | + |
|
130 | + 'payments' => array( |
|
131 | + 'name' => __( 'Payment Gateways', 'invoicing' ), |
|
132 | + 'view' => array( $this, 'setup_payments' ), |
|
133 | + 'handler' => array( $this, 'setup_payments_save' ), |
|
134 | + ), |
|
135 | + |
|
136 | + 'recommend' => array( |
|
137 | + 'name' => __( 'Recommend', 'invoicing' ), |
|
138 | + 'view' => array( $this, 'setup_recommend' ), |
|
139 | + 'handler' => '', |
|
140 | + ), |
|
141 | + |
|
142 | + 'next_steps' => array( |
|
143 | + 'name' => __( 'Get Paid', 'invoicing' ), |
|
144 | + 'view' => array( $this, 'setup_ready' ), |
|
145 | + 'handler' => '', |
|
146 | + ), |
|
147 | + |
|
148 | + ); |
|
149 | + |
|
150 | + return apply_filters( 'getpaid_setup_wizard_steps', $steps ); |
|
151 | + |
|
152 | + } |
|
153 | + |
|
154 | + /** |
|
155 | + * Returns the current step. |
|
156 | + * |
|
157 | + * @since 2.4.0 |
|
158 | + * @return string |
|
159 | + */ |
|
160 | + protected function get_current_step() { |
|
161 | + $step = isset( $_GET['step'] ) ? sanitize_key( $_GET['step'] ) : ''; |
|
162 | + return ! empty( $step ) && in_array( $step, array_keys( $this->steps ) ) ? $step : current( array_keys( $this->steps ) ); |
|
163 | + } |
|
164 | + |
|
165 | + /** |
|
166 | + * Returns the previous step. |
|
167 | + * |
|
168 | + * @since 2.4.0 |
|
169 | + * @return string|false |
|
170 | + */ |
|
171 | + protected function get_previous_step() { |
|
172 | + |
|
173 | + $previous = false; |
|
174 | + $current = $this->step; |
|
175 | + foreach ( array_keys( $this->steps ) as $step ) { |
|
176 | + if ( $current === $step ) { |
|
177 | + return $previous; |
|
178 | + } |
|
179 | + |
|
180 | + $previous = $step; |
|
181 | + } |
|
182 | + |
|
183 | + return false; |
|
184 | + } |
|
185 | + |
|
186 | + /** |
|
187 | + * Returns the next step. |
|
188 | + * |
|
189 | + * @since 2.4.0 |
|
190 | + * @return string|false |
|
191 | + */ |
|
192 | + protected function get_next_step() { |
|
193 | + |
|
194 | + $on_current = false; |
|
195 | + $current = $this->step; |
|
196 | + foreach ( array_keys( $this->steps ) as $step ) { |
|
197 | + |
|
198 | + if ( $on_current ) { |
|
199 | + return $step; |
|
200 | + } |
|
201 | + |
|
202 | + if ( $current === $step ) { |
|
203 | + return $on_current = true; |
|
204 | + } |
|
205 | + |
|
206 | + } |
|
207 | + |
|
208 | + return false; |
|
209 | + } |
|
210 | + |
|
211 | + /** |
|
212 | + * Displays the setup wizard. |
|
213 | + * |
|
214 | + * @since 2.4.0 |
|
215 | + */ |
|
216 | + public function display_wizard() { |
|
217 | + $this->display_header(); |
|
218 | + $this->display_current_step(); |
|
219 | + $this->display_footer(); |
|
220 | + } |
|
221 | + |
|
222 | + /** |
|
223 | + * Displays the Wizard Header. |
|
224 | + * |
|
225 | + * @since 2.0.0 |
|
226 | + */ |
|
227 | + public function display_header() { |
|
228 | + $steps = $this->steps; |
|
229 | + $current = $this->step; |
|
230 | + $next_step = $this->next_step; |
|
231 | + array_shift( $steps ); |
|
232 | + include plugin_dir_path( __FILE__ ) . 'views/wizard-header.php'; |
|
233 | + } |
|
234 | + |
|
235 | + /** |
|
236 | + * Displays the content for the current step. |
|
237 | + * |
|
238 | + * @since 2.4.0 |
|
239 | + */ |
|
240 | + public function display_current_step() { |
|
241 | + ?> |
|
242 | 242 | <div class="gp-setup-content rowx mw-100 text-center mb-3"> |
243 | 243 | <div class="col-12 col-md-5 m-auto"> |
244 | 244 | <?php call_user_func( $this->steps[ $this->step ]['view'], $this ); ?> |
245 | 245 | </div> |
246 | 246 | </div> |
247 | 247 | <?php |
248 | - } |
|
249 | - |
|
250 | - /** |
|
251 | - * Setup Wizard Footer. |
|
252 | - * |
|
253 | - * @since 2.4.0 |
|
254 | - */ |
|
255 | - public function display_footer() { |
|
256 | - |
|
257 | - if ( isset( $_GET['step'] ) ) { |
|
258 | - $next_url = esc_url( $this->get_next_step_link() ); |
|
259 | - $label = $this->step == 'next_steps' ? __( 'Return to the WordPress Dashboard', 'invoicing' ) : __( 'Skip this step', 'invoicing' ); |
|
260 | - |
|
261 | - echo '<p class="gd-return-to-dashboard-wrap"> <a href="' . $next_url . '" class="gd-return-to-dashboard btn btn-link d-block text-muted">' . $label . '</a></p>'; |
|
262 | - } |
|
263 | - |
|
264 | - echo '</body></html>'; |
|
265 | - } |
|
266 | - |
|
267 | - /** |
|
268 | - * Introduction step. |
|
269 | - * |
|
270 | - * @since 2.0.0 |
|
271 | - */ |
|
272 | - public function setup_introduction() { |
|
273 | - $next_url = $this->get_next_step_link(); |
|
274 | - include plugin_dir_path( __FILE__ ) . 'views/wizard-introduction.php'; |
|
275 | - } |
|
276 | - |
|
277 | - /** |
|
278 | - * Get the URL for the next step's screen. |
|
279 | - * |
|
280 | - * @param string step slug (default: current step) |
|
281 | - * |
|
282 | - * @return string URL for next step if a next step exists. |
|
283 | - * Admin URL if it's the last step. |
|
284 | - * Empty string on failure. |
|
285 | - * @since 3.0.0 |
|
286 | - */ |
|
287 | - public function get_next_step_link( $step = '' ) { |
|
288 | - if ( ! $step ) { |
|
289 | - $step = $this->step; |
|
290 | - } |
|
291 | - |
|
292 | - $keys = array_keys( $this->steps ); |
|
293 | - if ( end( $keys ) === $step ) { |
|
294 | - return admin_url(); |
|
295 | - } |
|
296 | - |
|
297 | - $step_index = array_search( $step, $keys ); |
|
298 | - if ( false === $step_index ) { |
|
299 | - return ''; |
|
300 | - } |
|
301 | - |
|
302 | - return remove_query_arg('settings-updated', add_query_arg( 'step', $keys[ $step_index + 1 ] )); |
|
303 | - } |
|
304 | - |
|
305 | - /** |
|
306 | - * Setup maps api. |
|
307 | - * |
|
308 | - * @since 2.0.0 |
|
309 | - */ |
|
310 | - public function setup_business() { |
|
311 | - $next_url = $this->get_next_step_link(); |
|
312 | - $wizard = $this; |
|
313 | - $page = 'wpinv_settings_general_main'; |
|
314 | - $section = 'wpinv_settings_general_main'; |
|
315 | - include plugin_dir_path( __FILE__ ) . 'views/wizard-settings.php'; |
|
316 | - } |
|
317 | - |
|
318 | - /** |
|
319 | - * Default Location settings. |
|
320 | - * |
|
321 | - * @since 2.0.0 |
|
322 | - */ |
|
323 | - public function setup_currency() { |
|
324 | - $next_url = $this->get_next_step_link(); |
|
325 | - $wizard = $this; |
|
326 | - $page = 'wpinv_settings_general_currency_section'; |
|
327 | - $section = 'wpinv_settings_general_currency_section'; |
|
328 | - include plugin_dir_path( __FILE__ ) . 'views/wizard-settings.php'; |
|
329 | - } |
|
330 | - |
|
331 | - /** |
|
332 | - * Installation of recommended plugins. |
|
333 | - * |
|
334 | - * @since 1.0.0 |
|
335 | - */ |
|
336 | - public function setup_recommend() { |
|
337 | - $next_url = $this->get_next_step_link(); |
|
338 | - $recommended_plugins = self::get_recommend_wp_plugins(); |
|
339 | - include plugin_dir_path( __FILE__ ) . 'views/wizard-plugins.php'; |
|
340 | - } |
|
341 | - |
|
342 | - /** |
|
343 | - * A list of recommended wp.org plugins. |
|
344 | - * @return array |
|
345 | - */ |
|
346 | - public static function get_recommend_wp_plugins(){ |
|
347 | - return array( |
|
348 | - 'ayecode-connect' => array( |
|
349 | - 'file' => 'ayecode-connect/ayecode-connect.php', |
|
350 | - 'url' => 'https://wordpress.org/plugins/ayecode-connect/', |
|
351 | - 'slug' => 'ayecode-connect', |
|
352 | - 'name' => 'AyeCode Connect', |
|
353 | - 'desc' => __( 'Documentation and Support from within your WordPress admin.', 'geodirectory' ), |
|
354 | - ), |
|
355 | - 'invoicing-quotes' => array( |
|
356 | - 'file' => 'invoicing-quotes/wpinv-quote.php', |
|
357 | - 'url' => 'https://wordpress.org/plugins/invoicing-quotes/', |
|
358 | - 'slug' => 'invoicing-quotes', |
|
359 | - 'name' => 'Customer Quotes', |
|
360 | - 'desc' => __('Create & Send Quotes to Customers and have them accept and pay.','geodirectory'), |
|
361 | - ), |
|
362 | - 'userswp' => array( |
|
363 | - 'file' => 'userswp/userswp.php', |
|
364 | - 'url' => 'https://wordpress.org/plugins/userswp/', |
|
365 | - 'slug' => 'userswp', |
|
366 | - 'name' => 'UsersWP', |
|
367 | - 'desc' => __('Frontend user login and registration as well as slick profile pages.','geodirectory'), |
|
368 | - ), |
|
369 | - ); |
|
370 | - } |
|
371 | - |
|
372 | - /** |
|
373 | - * Dummy Data setup. |
|
374 | - * |
|
375 | - * @since 2.4.0 |
|
376 | - */ |
|
377 | - public function setup_payments() { |
|
378 | - $next_url = $this->get_next_step_link(); |
|
379 | - include plugin_dir_path( __FILE__ ) . 'views/wizard-gateways.php'; |
|
380 | - } |
|
381 | - |
|
382 | - /** |
|
383 | - * Dummy data save. |
|
384 | - * |
|
385 | - * This is done via ajax so we just pass onto the next step. |
|
386 | - * |
|
387 | - * @since 2.0.0 |
|
388 | - */ |
|
389 | - public function setup_payments_save() { |
|
390 | - check_admin_referer( 'getpaid-setup-wizard', 'getpaid-setup-wizard' ); |
|
391 | - wpinv_update_option( 'manual_active', ! empty( $_POST['enable-manual-gateway'] ) ); |
|
392 | - |
|
393 | - if ( ! empty( $_POST['paypal-email'] ) ) { |
|
394 | - wpinv_update_option( 'paypal_email', sanitize_email( $_POST['paypal-email'] ) ); |
|
395 | - wpinv_update_option( 'paypal_active', 1 ); |
|
396 | - wpinv_update_option( 'paypal_sandbox', 0 ); |
|
397 | - } |
|
398 | - |
|
399 | - wp_redirect( esc_url_raw( $this->get_next_step_link() ) ); |
|
400 | - exit; |
|
401 | - } |
|
402 | - |
|
403 | - /** |
|
404 | - * Final step. |
|
405 | - * |
|
406 | - * @since 2.0.0 |
|
407 | - */ |
|
408 | - public function setup_ready() { |
|
409 | - include plugin_dir_path( __FILE__ ) . 'views/wizard-thank-you.php'; |
|
410 | - } |
|
248 | + } |
|
249 | + |
|
250 | + /** |
|
251 | + * Setup Wizard Footer. |
|
252 | + * |
|
253 | + * @since 2.4.0 |
|
254 | + */ |
|
255 | + public function display_footer() { |
|
256 | + |
|
257 | + if ( isset( $_GET['step'] ) ) { |
|
258 | + $next_url = esc_url( $this->get_next_step_link() ); |
|
259 | + $label = $this->step == 'next_steps' ? __( 'Return to the WordPress Dashboard', 'invoicing' ) : __( 'Skip this step', 'invoicing' ); |
|
260 | + |
|
261 | + echo '<p class="gd-return-to-dashboard-wrap"> <a href="' . $next_url . '" class="gd-return-to-dashboard btn btn-link d-block text-muted">' . $label . '</a></p>'; |
|
262 | + } |
|
263 | + |
|
264 | + echo '</body></html>'; |
|
265 | + } |
|
266 | + |
|
267 | + /** |
|
268 | + * Introduction step. |
|
269 | + * |
|
270 | + * @since 2.0.0 |
|
271 | + */ |
|
272 | + public function setup_introduction() { |
|
273 | + $next_url = $this->get_next_step_link(); |
|
274 | + include plugin_dir_path( __FILE__ ) . 'views/wizard-introduction.php'; |
|
275 | + } |
|
276 | + |
|
277 | + /** |
|
278 | + * Get the URL for the next step's screen. |
|
279 | + * |
|
280 | + * @param string step slug (default: current step) |
|
281 | + * |
|
282 | + * @return string URL for next step if a next step exists. |
|
283 | + * Admin URL if it's the last step. |
|
284 | + * Empty string on failure. |
|
285 | + * @since 3.0.0 |
|
286 | + */ |
|
287 | + public function get_next_step_link( $step = '' ) { |
|
288 | + if ( ! $step ) { |
|
289 | + $step = $this->step; |
|
290 | + } |
|
291 | + |
|
292 | + $keys = array_keys( $this->steps ); |
|
293 | + if ( end( $keys ) === $step ) { |
|
294 | + return admin_url(); |
|
295 | + } |
|
296 | + |
|
297 | + $step_index = array_search( $step, $keys ); |
|
298 | + if ( false === $step_index ) { |
|
299 | + return ''; |
|
300 | + } |
|
301 | + |
|
302 | + return remove_query_arg('settings-updated', add_query_arg( 'step', $keys[ $step_index + 1 ] )); |
|
303 | + } |
|
304 | + |
|
305 | + /** |
|
306 | + * Setup maps api. |
|
307 | + * |
|
308 | + * @since 2.0.0 |
|
309 | + */ |
|
310 | + public function setup_business() { |
|
311 | + $next_url = $this->get_next_step_link(); |
|
312 | + $wizard = $this; |
|
313 | + $page = 'wpinv_settings_general_main'; |
|
314 | + $section = 'wpinv_settings_general_main'; |
|
315 | + include plugin_dir_path( __FILE__ ) . 'views/wizard-settings.php'; |
|
316 | + } |
|
317 | + |
|
318 | + /** |
|
319 | + * Default Location settings. |
|
320 | + * |
|
321 | + * @since 2.0.0 |
|
322 | + */ |
|
323 | + public function setup_currency() { |
|
324 | + $next_url = $this->get_next_step_link(); |
|
325 | + $wizard = $this; |
|
326 | + $page = 'wpinv_settings_general_currency_section'; |
|
327 | + $section = 'wpinv_settings_general_currency_section'; |
|
328 | + include plugin_dir_path( __FILE__ ) . 'views/wizard-settings.php'; |
|
329 | + } |
|
330 | + |
|
331 | + /** |
|
332 | + * Installation of recommended plugins. |
|
333 | + * |
|
334 | + * @since 1.0.0 |
|
335 | + */ |
|
336 | + public function setup_recommend() { |
|
337 | + $next_url = $this->get_next_step_link(); |
|
338 | + $recommended_plugins = self::get_recommend_wp_plugins(); |
|
339 | + include plugin_dir_path( __FILE__ ) . 'views/wizard-plugins.php'; |
|
340 | + } |
|
341 | + |
|
342 | + /** |
|
343 | + * A list of recommended wp.org plugins. |
|
344 | + * @return array |
|
345 | + */ |
|
346 | + public static function get_recommend_wp_plugins(){ |
|
347 | + return array( |
|
348 | + 'ayecode-connect' => array( |
|
349 | + 'file' => 'ayecode-connect/ayecode-connect.php', |
|
350 | + 'url' => 'https://wordpress.org/plugins/ayecode-connect/', |
|
351 | + 'slug' => 'ayecode-connect', |
|
352 | + 'name' => 'AyeCode Connect', |
|
353 | + 'desc' => __( 'Documentation and Support from within your WordPress admin.', 'geodirectory' ), |
|
354 | + ), |
|
355 | + 'invoicing-quotes' => array( |
|
356 | + 'file' => 'invoicing-quotes/wpinv-quote.php', |
|
357 | + 'url' => 'https://wordpress.org/plugins/invoicing-quotes/', |
|
358 | + 'slug' => 'invoicing-quotes', |
|
359 | + 'name' => 'Customer Quotes', |
|
360 | + 'desc' => __('Create & Send Quotes to Customers and have them accept and pay.','geodirectory'), |
|
361 | + ), |
|
362 | + 'userswp' => array( |
|
363 | + 'file' => 'userswp/userswp.php', |
|
364 | + 'url' => 'https://wordpress.org/plugins/userswp/', |
|
365 | + 'slug' => 'userswp', |
|
366 | + 'name' => 'UsersWP', |
|
367 | + 'desc' => __('Frontend user login and registration as well as slick profile pages.','geodirectory'), |
|
368 | + ), |
|
369 | + ); |
|
370 | + } |
|
371 | + |
|
372 | + /** |
|
373 | + * Dummy Data setup. |
|
374 | + * |
|
375 | + * @since 2.4.0 |
|
376 | + */ |
|
377 | + public function setup_payments() { |
|
378 | + $next_url = $this->get_next_step_link(); |
|
379 | + include plugin_dir_path( __FILE__ ) . 'views/wizard-gateways.php'; |
|
380 | + } |
|
381 | + |
|
382 | + /** |
|
383 | + * Dummy data save. |
|
384 | + * |
|
385 | + * This is done via ajax so we just pass onto the next step. |
|
386 | + * |
|
387 | + * @since 2.0.0 |
|
388 | + */ |
|
389 | + public function setup_payments_save() { |
|
390 | + check_admin_referer( 'getpaid-setup-wizard', 'getpaid-setup-wizard' ); |
|
391 | + wpinv_update_option( 'manual_active', ! empty( $_POST['enable-manual-gateway'] ) ); |
|
392 | + |
|
393 | + if ( ! empty( $_POST['paypal-email'] ) ) { |
|
394 | + wpinv_update_option( 'paypal_email', sanitize_email( $_POST['paypal-email'] ) ); |
|
395 | + wpinv_update_option( 'paypal_active', 1 ); |
|
396 | + wpinv_update_option( 'paypal_sandbox', 0 ); |
|
397 | + } |
|
398 | + |
|
399 | + wp_redirect( esc_url_raw( $this->get_next_step_link() ) ); |
|
400 | + exit; |
|
401 | + } |
|
402 | + |
|
403 | + /** |
|
404 | + * Final step. |
|
405 | + * |
|
406 | + * @since 2.0.0 |
|
407 | + */ |
|
408 | + public function setup_ready() { |
|
409 | + include plugin_dir_path( __FILE__ ) . 'views/wizard-thank-you.php'; |
|
410 | + } |
|
411 | 411 | |
412 | 412 | } |
413 | 413 |
@@ -10,7 +10,7 @@ discard block |
||
10 | 10 | * @version 2.4.0 |
11 | 11 | * @info GetPaid Setup Wizard. |
12 | 12 | */ |
13 | -defined( 'ABSPATH' ) || exit; |
|
13 | +defined('ABSPATH') || exit; |
|
14 | 14 | |
15 | 15 | /** |
16 | 16 | * GetPaid_Admin_Setup_Wizard class. |
@@ -44,9 +44,9 @@ discard block |
||
44 | 44 | */ |
45 | 45 | public function __construct() { |
46 | 46 | |
47 | - if ( apply_filters( 'getpaid_enable_setup_wizard', true ) && wpinv_current_user_can_manage_invoicing() ) { |
|
48 | - add_action( 'admin_menu', array( $this, 'add_menu' ) ); |
|
49 | - add_action( 'current_screen', array( $this, 'setup_wizard' ) ); |
|
47 | + if (apply_filters('getpaid_enable_setup_wizard', true) && wpinv_current_user_can_manage_invoicing()) { |
|
48 | + add_action('admin_menu', array($this, 'add_menu')); |
|
49 | + add_action('current_screen', array($this, 'setup_wizard')); |
|
50 | 50 | } |
51 | 51 | |
52 | 52 | } |
@@ -57,7 +57,7 @@ discard block |
||
57 | 57 | * @since 2.4.0 |
58 | 58 | */ |
59 | 59 | public function add_menu() { |
60 | - add_dashboard_page( '', '', wpinv_get_capability(), 'gp-setup', '' ); |
|
60 | + add_dashboard_page('', '', wpinv_get_capability(), 'gp-setup', ''); |
|
61 | 61 | } |
62 | 62 | |
63 | 63 | /** |
@@ -67,7 +67,7 @@ discard block |
||
67 | 67 | */ |
68 | 68 | public function setup_wizard() { |
69 | 69 | |
70 | - if ( isset( $_GET['page'] ) && 'gp-setup' === $_GET['page'] ) { |
|
70 | + if (isset($_GET['page']) && 'gp-setup' === $_GET['page']) { |
|
71 | 71 | $this->setup_globals(); |
72 | 72 | $this->maybe_save_current_step(); |
73 | 73 | $this->display_wizard(); |
@@ -94,8 +94,8 @@ discard block |
||
94 | 94 | * @since 2.4.0 |
95 | 95 | */ |
96 | 96 | protected function maybe_save_current_step() { |
97 | - if ( ! empty( $_POST['save_step'] ) && is_callable( $this->steps[ $this->step ]['handler'] ) ) { |
|
98 | - call_user_func( $this->steps[ $this->step ]['handler'], $this ); |
|
97 | + if (!empty($_POST['save_step']) && is_callable($this->steps[$this->step]['handler'])) { |
|
98 | + call_user_func($this->steps[$this->step]['handler'], $this); |
|
99 | 99 | } |
100 | 100 | } |
101 | 101 | |
@@ -110,44 +110,44 @@ discard block |
||
110 | 110 | $steps = array( |
111 | 111 | |
112 | 112 | 'introduction' => array( |
113 | - 'name' => __( 'Introduction', 'invoicing' ), |
|
114 | - 'view' => array( $this, 'setup_introduction' ), |
|
113 | + 'name' => __('Introduction', 'invoicing'), |
|
114 | + 'view' => array($this, 'setup_introduction'), |
|
115 | 115 | 'handler' => '', |
116 | 116 | ), |
117 | 117 | |
118 | 118 | 'business_details' => array( |
119 | - 'name' => __( "Business Details", 'invoicing' ), |
|
120 | - 'view' => array( $this, 'setup_business' ), |
|
119 | + 'name' => __("Business Details", 'invoicing'), |
|
120 | + 'view' => array($this, 'setup_business'), |
|
121 | 121 | 'handler' => '', |
122 | 122 | ), |
123 | 123 | |
124 | 124 | 'currency' => array( |
125 | - 'name' => __( 'Currency', 'invoicing' ), |
|
126 | - 'view' => array( $this, 'setup_currency' ), |
|
125 | + 'name' => __('Currency', 'invoicing'), |
|
126 | + 'view' => array($this, 'setup_currency'), |
|
127 | 127 | 'handler' => '', |
128 | 128 | ), |
129 | 129 | |
130 | 130 | 'payments' => array( |
131 | - 'name' => __( 'Payment Gateways', 'invoicing' ), |
|
132 | - 'view' => array( $this, 'setup_payments' ), |
|
133 | - 'handler' => array( $this, 'setup_payments_save' ), |
|
131 | + 'name' => __('Payment Gateways', 'invoicing'), |
|
132 | + 'view' => array($this, 'setup_payments'), |
|
133 | + 'handler' => array($this, 'setup_payments_save'), |
|
134 | 134 | ), |
135 | 135 | |
136 | 136 | 'recommend' => array( |
137 | - 'name' => __( 'Recommend', 'invoicing' ), |
|
138 | - 'view' => array( $this, 'setup_recommend' ), |
|
137 | + 'name' => __('Recommend', 'invoicing'), |
|
138 | + 'view' => array($this, 'setup_recommend'), |
|
139 | 139 | 'handler' => '', |
140 | 140 | ), |
141 | 141 | |
142 | 142 | 'next_steps' => array( |
143 | - 'name' => __( 'Get Paid', 'invoicing' ), |
|
144 | - 'view' => array( $this, 'setup_ready' ), |
|
143 | + 'name' => __('Get Paid', 'invoicing'), |
|
144 | + 'view' => array($this, 'setup_ready'), |
|
145 | 145 | 'handler' => '', |
146 | 146 | ), |
147 | 147 | |
148 | 148 | ); |
149 | 149 | |
150 | - return apply_filters( 'getpaid_setup_wizard_steps', $steps ); |
|
150 | + return apply_filters('getpaid_setup_wizard_steps', $steps); |
|
151 | 151 | |
152 | 152 | } |
153 | 153 | |
@@ -158,8 +158,8 @@ discard block |
||
158 | 158 | * @return string |
159 | 159 | */ |
160 | 160 | protected function get_current_step() { |
161 | - $step = isset( $_GET['step'] ) ? sanitize_key( $_GET['step'] ) : ''; |
|
162 | - return ! empty( $step ) && in_array( $step, array_keys( $this->steps ) ) ? $step : current( array_keys( $this->steps ) ); |
|
161 | + $step = isset($_GET['step']) ? sanitize_key($_GET['step']) : ''; |
|
162 | + return !empty($step) && in_array($step, array_keys($this->steps)) ? $step : current(array_keys($this->steps)); |
|
163 | 163 | } |
164 | 164 | |
165 | 165 | /** |
@@ -172,8 +172,8 @@ discard block |
||
172 | 172 | |
173 | 173 | $previous = false; |
174 | 174 | $current = $this->step; |
175 | - foreach ( array_keys( $this->steps ) as $step ) { |
|
176 | - if ( $current === $step ) { |
|
175 | + foreach (array_keys($this->steps) as $step) { |
|
176 | + if ($current === $step) { |
|
177 | 177 | return $previous; |
178 | 178 | } |
179 | 179 | |
@@ -193,13 +193,13 @@ discard block |
||
193 | 193 | |
194 | 194 | $on_current = false; |
195 | 195 | $current = $this->step; |
196 | - foreach ( array_keys( $this->steps ) as $step ) { |
|
196 | + foreach (array_keys($this->steps) as $step) { |
|
197 | 197 | |
198 | - if ( $on_current ) { |
|
198 | + if ($on_current) { |
|
199 | 199 | return $step; |
200 | 200 | } |
201 | 201 | |
202 | - if ( $current === $step ) { |
|
202 | + if ($current === $step) { |
|
203 | 203 | return $on_current = true; |
204 | 204 | } |
205 | 205 | |
@@ -228,8 +228,8 @@ discard block |
||
228 | 228 | $steps = $this->steps; |
229 | 229 | $current = $this->step; |
230 | 230 | $next_step = $this->next_step; |
231 | - array_shift( $steps ); |
|
232 | - include plugin_dir_path( __FILE__ ) . 'views/wizard-header.php'; |
|
231 | + array_shift($steps); |
|
232 | + include plugin_dir_path(__FILE__) . 'views/wizard-header.php'; |
|
233 | 233 | } |
234 | 234 | |
235 | 235 | /** |
@@ -241,7 +241,7 @@ discard block |
||
241 | 241 | ?> |
242 | 242 | <div class="gp-setup-content rowx mw-100 text-center mb-3"> |
243 | 243 | <div class="col-12 col-md-5 m-auto"> |
244 | - <?php call_user_func( $this->steps[ $this->step ]['view'], $this ); ?> |
|
244 | + <?php call_user_func($this->steps[$this->step]['view'], $this); ?> |
|
245 | 245 | </div> |
246 | 246 | </div> |
247 | 247 | <?php |
@@ -254,9 +254,9 @@ discard block |
||
254 | 254 | */ |
255 | 255 | public function display_footer() { |
256 | 256 | |
257 | - if ( isset( $_GET['step'] ) ) { |
|
258 | - $next_url = esc_url( $this->get_next_step_link() ); |
|
259 | - $label = $this->step == 'next_steps' ? __( 'Return to the WordPress Dashboard', 'invoicing' ) : __( 'Skip this step', 'invoicing' ); |
|
257 | + if (isset($_GET['step'])) { |
|
258 | + $next_url = esc_url($this->get_next_step_link()); |
|
259 | + $label = $this->step == 'next_steps' ? __('Return to the WordPress Dashboard', 'invoicing') : __('Skip this step', 'invoicing'); |
|
260 | 260 | |
261 | 261 | echo '<p class="gd-return-to-dashboard-wrap"> <a href="' . $next_url . '" class="gd-return-to-dashboard btn btn-link d-block text-muted">' . $label . '</a></p>'; |
262 | 262 | } |
@@ -271,7 +271,7 @@ discard block |
||
271 | 271 | */ |
272 | 272 | public function setup_introduction() { |
273 | 273 | $next_url = $this->get_next_step_link(); |
274 | - include plugin_dir_path( __FILE__ ) . 'views/wizard-introduction.php'; |
|
274 | + include plugin_dir_path(__FILE__) . 'views/wizard-introduction.php'; |
|
275 | 275 | } |
276 | 276 | |
277 | 277 | /** |
@@ -284,22 +284,22 @@ discard block |
||
284 | 284 | * Empty string on failure. |
285 | 285 | * @since 3.0.0 |
286 | 286 | */ |
287 | - public function get_next_step_link( $step = '' ) { |
|
288 | - if ( ! $step ) { |
|
287 | + public function get_next_step_link($step = '') { |
|
288 | + if (!$step) { |
|
289 | 289 | $step = $this->step; |
290 | 290 | } |
291 | 291 | |
292 | - $keys = array_keys( $this->steps ); |
|
293 | - if ( end( $keys ) === $step ) { |
|
292 | + $keys = array_keys($this->steps); |
|
293 | + if (end($keys) === $step) { |
|
294 | 294 | return admin_url(); |
295 | 295 | } |
296 | 296 | |
297 | - $step_index = array_search( $step, $keys ); |
|
298 | - if ( false === $step_index ) { |
|
297 | + $step_index = array_search($step, $keys); |
|
298 | + if (false === $step_index) { |
|
299 | 299 | return ''; |
300 | 300 | } |
301 | 301 | |
302 | - return remove_query_arg('settings-updated', add_query_arg( 'step', $keys[ $step_index + 1 ] )); |
|
302 | + return remove_query_arg('settings-updated', add_query_arg('step', $keys[$step_index + 1])); |
|
303 | 303 | } |
304 | 304 | |
305 | 305 | /** |
@@ -312,7 +312,7 @@ discard block |
||
312 | 312 | $wizard = $this; |
313 | 313 | $page = 'wpinv_settings_general_main'; |
314 | 314 | $section = 'wpinv_settings_general_main'; |
315 | - include plugin_dir_path( __FILE__ ) . 'views/wizard-settings.php'; |
|
315 | + include plugin_dir_path(__FILE__) . 'views/wizard-settings.php'; |
|
316 | 316 | } |
317 | 317 | |
318 | 318 | /** |
@@ -325,7 +325,7 @@ discard block |
||
325 | 325 | $wizard = $this; |
326 | 326 | $page = 'wpinv_settings_general_currency_section'; |
327 | 327 | $section = 'wpinv_settings_general_currency_section'; |
328 | - include plugin_dir_path( __FILE__ ) . 'views/wizard-settings.php'; |
|
328 | + include plugin_dir_path(__FILE__) . 'views/wizard-settings.php'; |
|
329 | 329 | } |
330 | 330 | |
331 | 331 | /** |
@@ -336,35 +336,35 @@ discard block |
||
336 | 336 | public function setup_recommend() { |
337 | 337 | $next_url = $this->get_next_step_link(); |
338 | 338 | $recommended_plugins = self::get_recommend_wp_plugins(); |
339 | - include plugin_dir_path( __FILE__ ) . 'views/wizard-plugins.php'; |
|
339 | + include plugin_dir_path(__FILE__) . 'views/wizard-plugins.php'; |
|
340 | 340 | } |
341 | 341 | |
342 | 342 | /** |
343 | 343 | * A list of recommended wp.org plugins. |
344 | 344 | * @return array |
345 | 345 | */ |
346 | - public static function get_recommend_wp_plugins(){ |
|
346 | + public static function get_recommend_wp_plugins() { |
|
347 | 347 | return array( |
348 | 348 | 'ayecode-connect' => array( |
349 | 349 | 'file' => 'ayecode-connect/ayecode-connect.php', |
350 | 350 | 'url' => 'https://wordpress.org/plugins/ayecode-connect/', |
351 | 351 | 'slug' => 'ayecode-connect', |
352 | 352 | 'name' => 'AyeCode Connect', |
353 | - 'desc' => __( 'Documentation and Support from within your WordPress admin.', 'geodirectory' ), |
|
353 | + 'desc' => __('Documentation and Support from within your WordPress admin.', 'geodirectory'), |
|
354 | 354 | ), |
355 | 355 | 'invoicing-quotes' => array( |
356 | 356 | 'file' => 'invoicing-quotes/wpinv-quote.php', |
357 | 357 | 'url' => 'https://wordpress.org/plugins/invoicing-quotes/', |
358 | 358 | 'slug' => 'invoicing-quotes', |
359 | 359 | 'name' => 'Customer Quotes', |
360 | - 'desc' => __('Create & Send Quotes to Customers and have them accept and pay.','geodirectory'), |
|
360 | + 'desc' => __('Create & Send Quotes to Customers and have them accept and pay.', 'geodirectory'), |
|
361 | 361 | ), |
362 | 362 | 'userswp' => array( |
363 | 363 | 'file' => 'userswp/userswp.php', |
364 | 364 | 'url' => 'https://wordpress.org/plugins/userswp/', |
365 | 365 | 'slug' => 'userswp', |
366 | 366 | 'name' => 'UsersWP', |
367 | - 'desc' => __('Frontend user login and registration as well as slick profile pages.','geodirectory'), |
|
367 | + 'desc' => __('Frontend user login and registration as well as slick profile pages.', 'geodirectory'), |
|
368 | 368 | ), |
369 | 369 | ); |
370 | 370 | } |
@@ -376,7 +376,7 @@ discard block |
||
376 | 376 | */ |
377 | 377 | public function setup_payments() { |
378 | 378 | $next_url = $this->get_next_step_link(); |
379 | - include plugin_dir_path( __FILE__ ) . 'views/wizard-gateways.php'; |
|
379 | + include plugin_dir_path(__FILE__) . 'views/wizard-gateways.php'; |
|
380 | 380 | } |
381 | 381 | |
382 | 382 | /** |
@@ -387,16 +387,16 @@ discard block |
||
387 | 387 | * @since 2.0.0 |
388 | 388 | */ |
389 | 389 | public function setup_payments_save() { |
390 | - check_admin_referer( 'getpaid-setup-wizard', 'getpaid-setup-wizard' ); |
|
391 | - wpinv_update_option( 'manual_active', ! empty( $_POST['enable-manual-gateway'] ) ); |
|
390 | + check_admin_referer('getpaid-setup-wizard', 'getpaid-setup-wizard'); |
|
391 | + wpinv_update_option('manual_active', !empty($_POST['enable-manual-gateway'])); |
|
392 | 392 | |
393 | - if ( ! empty( $_POST['paypal-email'] ) ) { |
|
394 | - wpinv_update_option( 'paypal_email', sanitize_email( $_POST['paypal-email'] ) ); |
|
395 | - wpinv_update_option( 'paypal_active', 1 ); |
|
396 | - wpinv_update_option( 'paypal_sandbox', 0 ); |
|
393 | + if (!empty($_POST['paypal-email'])) { |
|
394 | + wpinv_update_option('paypal_email', sanitize_email($_POST['paypal-email'])); |
|
395 | + wpinv_update_option('paypal_active', 1); |
|
396 | + wpinv_update_option('paypal_sandbox', 0); |
|
397 | 397 | } |
398 | 398 | |
399 | - wp_redirect( esc_url_raw( $this->get_next_step_link() ) ); |
|
399 | + wp_redirect(esc_url_raw($this->get_next_step_link())); |
|
400 | 400 | exit; |
401 | 401 | } |
402 | 402 | |
@@ -406,7 +406,7 @@ discard block |
||
406 | 406 | * @since 2.0.0 |
407 | 407 | */ |
408 | 408 | public function setup_ready() { |
409 | - include plugin_dir_path( __FILE__ ) . 'views/wizard-thank-you.php'; |
|
409 | + include plugin_dir_path(__FILE__) . 'views/wizard-thank-you.php'; |
|
410 | 410 | } |
411 | 411 | |
412 | 412 | } |
@@ -36,8 +36,11 @@ |
||
36 | 36 | 'getpaid-nonce' |
37 | 37 | ); ?>" |
38 | 38 | class="btn btn-sm btn-outline-primary"><?php _e( 'Connect', 'invoicing' ); ?></a> |
39 | - <?php else: ?> |
|
40 | - <span class="btn btn-sm btn-success"><?php _e( 'Connected', 'invoicing' ); ?></span> |
|
39 | + <?php else { |
|
40 | + : ?> |
|
41 | + <span class="btn btn-sm btn-success"><?php _e( 'Connected', 'invoicing' ); |
|
42 | +} |
|
43 | +?></span> |
|
41 | 44 | <?php endif; ?> |
42 | 45 | </li> |
43 | 46 |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | * |
5 | 5 | */ |
6 | 6 | |
7 | -defined( 'ABSPATH' ) || exit; |
|
7 | +defined('ABSPATH') || exit; |
|
8 | 8 | |
9 | 9 | ?> |
10 | 10 | |
@@ -12,54 +12,54 @@ discard block |
||
12 | 12 | |
13 | 13 | <form method="post" class="text-center card-body"> |
14 | 14 | <div class="gp-wizard-payments"> |
15 | - <h2 class="gd-settings-title h3 "><?php _e( 'Gateway Setup', 'invoicing' ); ?></h2> |
|
16 | - <p><?php _e( 'Below are a few gateways that can be setup in a few seconds.', 'invoicing' ); ?> |
|
15 | + <h2 class="gd-settings-title h3 "><?php _e('Gateway Setup', 'invoicing'); ?></h2> |
|
16 | + <p><?php _e('Below are a few gateways that can be setup in a few seconds.', 'invoicing'); ?> |
|
17 | 17 | <br> |
18 | - <?php _e( 'We have 20+ Gateways that can be setup later.', 'invoicing' ); ?> |
|
18 | + <?php _e('We have 20+ Gateways that can be setup later.', 'invoicing'); ?> |
|
19 | 19 | </p> |
20 | 20 | |
21 | 21 | <ul class="list-group"> |
22 | 22 | |
23 | 23 | <li class="list-group-item d-flex justify-content-between align-items-center"> |
24 | - <span class="mr-auto"><img src="<?php echo esc_url( WPINV_PLUGIN_URL . 'assets/images/stripe-verified.svg' );?>" class="ml-n2" alt="Stripe"></span> |
|
25 | - <?php if ( false === wpinv_get_option( 'stripe_live_connect_account_id' ) ) : ?> |
|
24 | + <span class="mr-auto"><img src="<?php echo esc_url(WPINV_PLUGIN_URL . 'assets/images/stripe-verified.svg'); ?>" class="ml-n2" alt="Stripe"></span> |
|
25 | + <?php if (false === wpinv_get_option('stripe_live_connect_account_id')) : ?> |
|
26 | 26 | <a href="<?php echo wp_nonce_url( |
27 | 27 | add_query_arg( |
28 | 28 | array( |
29 | 29 | 'getpaid-admin-action' => 'connect_gateway', |
30 | 30 | 'plugin' => 'stripe', |
31 | - 'redirect' => urlencode( add_query_arg( 'step', 'payments' ) ), |
|
31 | + 'redirect' => urlencode(add_query_arg('step', 'payments')), |
|
32 | 32 | ), |
33 | 33 | admin_url() |
34 | 34 | ), |
35 | 35 | 'getpaid-nonce', |
36 | 36 | 'getpaid-nonce' |
37 | 37 | ); ?>" |
38 | - class="btn btn-sm btn-outline-primary"><?php _e( 'Connect', 'invoicing' ); ?></a> |
|
38 | + class="btn btn-sm btn-outline-primary"><?php _e('Connect', 'invoicing'); ?></a> |
|
39 | 39 | <?php else: ?> |
40 | - <span class="btn btn-sm btn-success"><?php _e( 'Connected', 'invoicing' ); ?></span> |
|
40 | + <span class="btn btn-sm btn-success"><?php _e('Connected', 'invoicing'); ?></span> |
|
41 | 41 | <?php endif; ?> |
42 | 42 | </li> |
43 | 43 | |
44 | 44 | <li class="list-group-item"> |
45 | 45 | <div class="d-flex justify-content-between align-items-center"> |
46 | 46 | <span class="mr-auto"> |
47 | - <img src="<?php echo esc_url( WPINV_PLUGIN_URL . 'assets/images/pp-logo-150px.webp' );?>" class="" alt="PayPal" height="25"> |
|
47 | + <img src="<?php echo esc_url(WPINV_PLUGIN_URL . 'assets/images/pp-logo-150px.webp'); ?>" class="" alt="PayPal" height="25"> |
|
48 | 48 | </span> |
49 | 49 | <a |
50 | 50 | href="#" |
51 | 51 | onclick="jQuery('.getpaid-setup-paypal-input').toggleClass('d-none'); return false;" |
52 | - class="getpaid-setup-paypal btn btn-sm btn-outline-primary"><?php _e( 'Set-up', 'invoicing' ); ?></a> |
|
52 | + class="getpaid-setup-paypal btn btn-sm btn-outline-primary"><?php _e('Set-up', 'invoicing'); ?></a> |
|
53 | 53 | </div> |
54 | 54 | <div class="mt-4 getpaid-setup-paypal-input d-none"> |
55 | - <input type="text" placeholder="<?php esc_attr_e( 'PayPal Email', 'invoicing' ); ?>" name="paypal-email" class="form-control" value="<?php echo esc_attr( wpinv_get_option( 'paypal_email' ) ); ?>"> |
|
55 | + <input type="text" placeholder="<?php esc_attr_e('PayPal Email', 'invoicing'); ?>" name="paypal-email" class="form-control" value="<?php echo esc_attr(wpinv_get_option('paypal_email')); ?>"> |
|
56 | 56 | </div> |
57 | 57 | </li> |
58 | 58 | |
59 | 59 | <li class="list-group-item d-flex justify-content-between align-items-center"> |
60 | - <span class="mr-auto"><?php _e( 'Test Gateway', 'invoicing' ); ?></span> |
|
60 | + <span class="mr-auto"><?php _e('Test Gateway', 'invoicing'); ?></span> |
|
61 | 61 | <div class="custom-control custom-switch"> |
62 | - <input type="checkbox" name="enable-manual-gateway" class="custom-control-input" id="enable-manual-gateway" <?php checked( wpinv_is_gateway_active( 'manual' ) ); ?>> |
|
62 | + <input type="checkbox" name="enable-manual-gateway" class="custom-control-input" id="enable-manual-gateway" <?php checked(wpinv_is_gateway_active('manual')); ?>> |
|
63 | 63 | <label class="custom-control-label" for="enable-manual-gateway"></label> |
64 | 64 | </div> |
65 | 65 | </li> |
@@ -68,10 +68,10 @@ discard block |
||
68 | 68 | </div> |
69 | 69 | |
70 | 70 | <p class="gp-setup-actions step text-center mt-4"> |
71 | - <input type="submit" class="btn btn-primary" value="<?php esc_attr_e( 'Continue', 'invoicing' ); ?>" /> |
|
71 | + <input type="submit" class="btn btn-primary" value="<?php esc_attr_e('Continue', 'invoicing'); ?>" /> |
|
72 | 72 | </p> |
73 | 73 | |
74 | - <?php getpaid_hidden_field( 'save_step', 1 ); ?> |
|
75 | - <?php wp_nonce_field( 'getpaid-setup-wizard', 'getpaid-setup-wizard' ); ?> |
|
74 | + <?php getpaid_hidden_field('save_step', 1); ?> |
|
75 | + <?php wp_nonce_field('getpaid-setup-wizard', 'getpaid-setup-wizard'); ?> |
|
76 | 76 | </form> |
77 | 77 | </div> |
@@ -12,145 +12,145 @@ |
||
12 | 12 | */ |
13 | 13 | class GetPaid_Daily_Maintenance { |
14 | 14 | |
15 | - /** |
|
16 | - * Class constructor. |
|
17 | - */ |
|
18 | - public function __construct(){ |
|
19 | - |
|
20 | - // Clear deprecated events. |
|
21 | - add_action( 'wp', array( $this, 'maybe_clear_deprecated_events' ) ); |
|
22 | - |
|
23 | - // (Maybe) schedule a cron that runs daily. |
|
24 | - add_action( 'wp', array( $this, 'maybe_create_scheduled_event' ) ); |
|
25 | - |
|
26 | - // Fired everyday at 7 a.m (this might vary for sites with few visitors) |
|
27 | - add_action( 'getpaid_daily_maintenance', array( $this, 'log_cron_run' ) ); |
|
28 | - add_action( 'getpaid_daily_maintenance', array( $this, 'backwards_compat' ) ); |
|
29 | - add_action( 'getpaid_daily_maintenance', array( $this, 'maybe_expire_subscriptions' ) ); |
|
30 | - add_action( 'getpaid_daily_maintenance', array( $this, 'check_renewing_subscriptions' ) ); |
|
31 | - add_action( 'getpaid_daily_maintenance', array( $this, 'maybe_update_geoip_databases' ) ); |
|
32 | - |
|
33 | - } |
|
34 | - |
|
35 | - /** |
|
36 | - * Schedules a cron to run every day at 7 a.m |
|
37 | - * |
|
38 | - */ |
|
39 | - public function maybe_create_scheduled_event() { |
|
40 | - |
|
41 | - if ( ! wp_next_scheduled( 'getpaid_daily_maintenance' ) ) { |
|
42 | - $timestamp = strtotime( 'tomorrow 07:00:00', current_time( 'timestamp' ) ); |
|
43 | - wp_schedule_event( $timestamp, 'daily', 'getpaid_daily_maintenance' ); |
|
44 | - } |
|
45 | - |
|
46 | - } |
|
47 | - |
|
48 | - /** |
|
49 | - * Clears deprecated events. |
|
50 | - * |
|
51 | - */ |
|
52 | - public function maybe_clear_deprecated_events() { |
|
53 | - |
|
54 | - if ( ! get_option( 'wpinv_cleared_old_events' ) ) { |
|
55 | - wp_clear_scheduled_hook( 'wpinv_register_schedule_event_twicedaily' ); |
|
56 | - wp_clear_scheduled_hook( 'wpinv_register_schedule_event_daily' ); |
|
57 | - update_option( 'wpinv_cleared_old_events', 1 ); |
|
58 | - } |
|
59 | - |
|
60 | - } |
|
61 | - |
|
62 | - /** |
|
63 | - * Fires the old hook for backwards compatibility. |
|
64 | - * |
|
65 | - */ |
|
66 | - public function backwards_compat() { |
|
67 | - do_action( 'wpinv_register_schedule_event_daily' ); |
|
68 | - } |
|
69 | - |
|
70 | - /** |
|
71 | - * Checks for subscriptions that are scheduled to renew. |
|
72 | - * |
|
73 | - */ |
|
74 | - public function check_renewing_subscriptions() { |
|
75 | - |
|
76 | - // Fetch subscriptions that expire today. |
|
77 | - $args = array( |
|
78 | - 'number' => -1, |
|
79 | - 'count_total' => false, |
|
80 | - 'status' => 'trialling active', |
|
81 | - 'date_expires_query' => array( |
|
82 | - array( |
|
83 | - 'year' => date( 'Y', current_time( 'timestamp' ) ), |
|
84 | - 'month' => date( 'n', current_time( 'timestamp' ) ), |
|
85 | - 'day' => date( 'j', current_time( 'timestamp' ) ), |
|
86 | - 'compare' => '=', |
|
87 | - ), |
|
88 | - ), |
|
89 | - ); |
|
90 | - |
|
91 | - $subscriptions = new GetPaid_Subscriptions_Query( $args ); |
|
92 | - |
|
93 | - foreach ( $subscriptions->get_results() as $subscription ) { |
|
94 | - |
|
95 | - /** @var WPInv_Subscription $subscription */ |
|
96 | - if ( $subscription->is_last_renewal() ) { |
|
97 | - $subscription->complete(); |
|
98 | - } else { |
|
99 | - do_action( 'getpaid_should_renew_subscription', $subscription ); |
|
100 | - } |
|
101 | - |
|
102 | - } |
|
103 | - |
|
104 | - } |
|
105 | - |
|
106 | - /** |
|
107 | - * Expires expired subscriptions. |
|
108 | - * |
|
109 | - */ |
|
110 | - public function maybe_expire_subscriptions() { |
|
111 | - |
|
112 | - // Fetch expired subscriptions (skips those that expire today). |
|
113 | - $args = array( |
|
114 | - 'number' => -1, |
|
115 | - 'count_total' => false, |
|
116 | - 'status' => 'trialling active failing cancelled', |
|
117 | - 'date_expires_query' => array( |
|
118 | - 'before' => 'yesterday', |
|
119 | - 'inclusive' => false, |
|
120 | - ), |
|
121 | - ); |
|
122 | - |
|
123 | - $subscriptions = new GetPaid_Subscriptions_Query( $args ); |
|
124 | - |
|
125 | - foreach ( $subscriptions->get_results() as $subscription ) { |
|
126 | - if ( apply_filters( 'getpaid_daily_maintenance_should_expire_subscription', false, $subscription ) ) { |
|
127 | - $subscription->set_status( 'expired' ); |
|
128 | - $subscription->save(); |
|
129 | - } |
|
130 | - } |
|
131 | - |
|
132 | - } |
|
133 | - |
|
134 | - /** |
|
135 | - * Logs cron runs. |
|
136 | - * |
|
137 | - */ |
|
138 | - public function log_cron_run() { |
|
139 | - wpinv_error_log( 'GetPaid Daily Cron', false ); |
|
140 | - } |
|
141 | - |
|
142 | - /** |
|
143 | - * Updates GeoIP databases. |
|
144 | - * |
|
145 | - */ |
|
146 | - public function maybe_update_geoip_databases() { |
|
147 | - $updated = get_transient( 'getpaid_updated_geoip_databases' ); |
|
148 | - |
|
149 | - if ( false === $updated ) { |
|
150 | - set_transient( 'getpaid_updated_geoip_databases', 1, 15 * DAY_IN_SECONDS ); |
|
151 | - do_action( 'getpaid_update_geoip_databases' ); |
|
152 | - } |
|
153 | - |
|
154 | - } |
|
15 | + /** |
|
16 | + * Class constructor. |
|
17 | + */ |
|
18 | + public function __construct(){ |
|
19 | + |
|
20 | + // Clear deprecated events. |
|
21 | + add_action( 'wp', array( $this, 'maybe_clear_deprecated_events' ) ); |
|
22 | + |
|
23 | + // (Maybe) schedule a cron that runs daily. |
|
24 | + add_action( 'wp', array( $this, 'maybe_create_scheduled_event' ) ); |
|
25 | + |
|
26 | + // Fired everyday at 7 a.m (this might vary for sites with few visitors) |
|
27 | + add_action( 'getpaid_daily_maintenance', array( $this, 'log_cron_run' ) ); |
|
28 | + add_action( 'getpaid_daily_maintenance', array( $this, 'backwards_compat' ) ); |
|
29 | + add_action( 'getpaid_daily_maintenance', array( $this, 'maybe_expire_subscriptions' ) ); |
|
30 | + add_action( 'getpaid_daily_maintenance', array( $this, 'check_renewing_subscriptions' ) ); |
|
31 | + add_action( 'getpaid_daily_maintenance', array( $this, 'maybe_update_geoip_databases' ) ); |
|
32 | + |
|
33 | + } |
|
34 | + |
|
35 | + /** |
|
36 | + * Schedules a cron to run every day at 7 a.m |
|
37 | + * |
|
38 | + */ |
|
39 | + public function maybe_create_scheduled_event() { |
|
40 | + |
|
41 | + if ( ! wp_next_scheduled( 'getpaid_daily_maintenance' ) ) { |
|
42 | + $timestamp = strtotime( 'tomorrow 07:00:00', current_time( 'timestamp' ) ); |
|
43 | + wp_schedule_event( $timestamp, 'daily', 'getpaid_daily_maintenance' ); |
|
44 | + } |
|
45 | + |
|
46 | + } |
|
47 | + |
|
48 | + /** |
|
49 | + * Clears deprecated events. |
|
50 | + * |
|
51 | + */ |
|
52 | + public function maybe_clear_deprecated_events() { |
|
53 | + |
|
54 | + if ( ! get_option( 'wpinv_cleared_old_events' ) ) { |
|
55 | + wp_clear_scheduled_hook( 'wpinv_register_schedule_event_twicedaily' ); |
|
56 | + wp_clear_scheduled_hook( 'wpinv_register_schedule_event_daily' ); |
|
57 | + update_option( 'wpinv_cleared_old_events', 1 ); |
|
58 | + } |
|
59 | + |
|
60 | + } |
|
61 | + |
|
62 | + /** |
|
63 | + * Fires the old hook for backwards compatibility. |
|
64 | + * |
|
65 | + */ |
|
66 | + public function backwards_compat() { |
|
67 | + do_action( 'wpinv_register_schedule_event_daily' ); |
|
68 | + } |
|
69 | + |
|
70 | + /** |
|
71 | + * Checks for subscriptions that are scheduled to renew. |
|
72 | + * |
|
73 | + */ |
|
74 | + public function check_renewing_subscriptions() { |
|
75 | + |
|
76 | + // Fetch subscriptions that expire today. |
|
77 | + $args = array( |
|
78 | + 'number' => -1, |
|
79 | + 'count_total' => false, |
|
80 | + 'status' => 'trialling active', |
|
81 | + 'date_expires_query' => array( |
|
82 | + array( |
|
83 | + 'year' => date( 'Y', current_time( 'timestamp' ) ), |
|
84 | + 'month' => date( 'n', current_time( 'timestamp' ) ), |
|
85 | + 'day' => date( 'j', current_time( 'timestamp' ) ), |
|
86 | + 'compare' => '=', |
|
87 | + ), |
|
88 | + ), |
|
89 | + ); |
|
90 | + |
|
91 | + $subscriptions = new GetPaid_Subscriptions_Query( $args ); |
|
92 | + |
|
93 | + foreach ( $subscriptions->get_results() as $subscription ) { |
|
94 | + |
|
95 | + /** @var WPInv_Subscription $subscription */ |
|
96 | + if ( $subscription->is_last_renewal() ) { |
|
97 | + $subscription->complete(); |
|
98 | + } else { |
|
99 | + do_action( 'getpaid_should_renew_subscription', $subscription ); |
|
100 | + } |
|
101 | + |
|
102 | + } |
|
103 | + |
|
104 | + } |
|
105 | + |
|
106 | + /** |
|
107 | + * Expires expired subscriptions. |
|
108 | + * |
|
109 | + */ |
|
110 | + public function maybe_expire_subscriptions() { |
|
111 | + |
|
112 | + // Fetch expired subscriptions (skips those that expire today). |
|
113 | + $args = array( |
|
114 | + 'number' => -1, |
|
115 | + 'count_total' => false, |
|
116 | + 'status' => 'trialling active failing cancelled', |
|
117 | + 'date_expires_query' => array( |
|
118 | + 'before' => 'yesterday', |
|
119 | + 'inclusive' => false, |
|
120 | + ), |
|
121 | + ); |
|
122 | + |
|
123 | + $subscriptions = new GetPaid_Subscriptions_Query( $args ); |
|
124 | + |
|
125 | + foreach ( $subscriptions->get_results() as $subscription ) { |
|
126 | + if ( apply_filters( 'getpaid_daily_maintenance_should_expire_subscription', false, $subscription ) ) { |
|
127 | + $subscription->set_status( 'expired' ); |
|
128 | + $subscription->save(); |
|
129 | + } |
|
130 | + } |
|
131 | + |
|
132 | + } |
|
133 | + |
|
134 | + /** |
|
135 | + * Logs cron runs. |
|
136 | + * |
|
137 | + */ |
|
138 | + public function log_cron_run() { |
|
139 | + wpinv_error_log( 'GetPaid Daily Cron', false ); |
|
140 | + } |
|
141 | + |
|
142 | + /** |
|
143 | + * Updates GeoIP databases. |
|
144 | + * |
|
145 | + */ |
|
146 | + public function maybe_update_geoip_databases() { |
|
147 | + $updated = get_transient( 'getpaid_updated_geoip_databases' ); |
|
148 | + |
|
149 | + if ( false === $updated ) { |
|
150 | + set_transient( 'getpaid_updated_geoip_databases', 1, 15 * DAY_IN_SECONDS ); |
|
151 | + do_action( 'getpaid_update_geoip_databases' ); |
|
152 | + } |
|
153 | + |
|
154 | + } |
|
155 | 155 | |
156 | 156 | } |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | * |
5 | 5 | */ |
6 | 6 | |
7 | -defined( 'ABSPATH' ) || exit; |
|
7 | +defined('ABSPATH') || exit; |
|
8 | 8 | |
9 | 9 | /** |
10 | 10 | * Daily maintenance class. |
@@ -15,20 +15,20 @@ discard block |
||
15 | 15 | /** |
16 | 16 | * Class constructor. |
17 | 17 | */ |
18 | - public function __construct(){ |
|
18 | + public function __construct() { |
|
19 | 19 | |
20 | 20 | // Clear deprecated events. |
21 | - add_action( 'wp', array( $this, 'maybe_clear_deprecated_events' ) ); |
|
21 | + add_action('wp', array($this, 'maybe_clear_deprecated_events')); |
|
22 | 22 | |
23 | 23 | // (Maybe) schedule a cron that runs daily. |
24 | - add_action( 'wp', array( $this, 'maybe_create_scheduled_event' ) ); |
|
24 | + add_action('wp', array($this, 'maybe_create_scheduled_event')); |
|
25 | 25 | |
26 | 26 | // Fired everyday at 7 a.m (this might vary for sites with few visitors) |
27 | - add_action( 'getpaid_daily_maintenance', array( $this, 'log_cron_run' ) ); |
|
28 | - add_action( 'getpaid_daily_maintenance', array( $this, 'backwards_compat' ) ); |
|
29 | - add_action( 'getpaid_daily_maintenance', array( $this, 'maybe_expire_subscriptions' ) ); |
|
30 | - add_action( 'getpaid_daily_maintenance', array( $this, 'check_renewing_subscriptions' ) ); |
|
31 | - add_action( 'getpaid_daily_maintenance', array( $this, 'maybe_update_geoip_databases' ) ); |
|
27 | + add_action('getpaid_daily_maintenance', array($this, 'log_cron_run')); |
|
28 | + add_action('getpaid_daily_maintenance', array($this, 'backwards_compat')); |
|
29 | + add_action('getpaid_daily_maintenance', array($this, 'maybe_expire_subscriptions')); |
|
30 | + add_action('getpaid_daily_maintenance', array($this, 'check_renewing_subscriptions')); |
|
31 | + add_action('getpaid_daily_maintenance', array($this, 'maybe_update_geoip_databases')); |
|
32 | 32 | |
33 | 33 | } |
34 | 34 | |
@@ -38,9 +38,9 @@ discard block |
||
38 | 38 | */ |
39 | 39 | public function maybe_create_scheduled_event() { |
40 | 40 | |
41 | - if ( ! wp_next_scheduled( 'getpaid_daily_maintenance' ) ) { |
|
42 | - $timestamp = strtotime( 'tomorrow 07:00:00', current_time( 'timestamp' ) ); |
|
43 | - wp_schedule_event( $timestamp, 'daily', 'getpaid_daily_maintenance' ); |
|
41 | + if (!wp_next_scheduled('getpaid_daily_maintenance')) { |
|
42 | + $timestamp = strtotime('tomorrow 07:00:00', current_time('timestamp')); |
|
43 | + wp_schedule_event($timestamp, 'daily', 'getpaid_daily_maintenance'); |
|
44 | 44 | } |
45 | 45 | |
46 | 46 | } |
@@ -51,10 +51,10 @@ discard block |
||
51 | 51 | */ |
52 | 52 | public function maybe_clear_deprecated_events() { |
53 | 53 | |
54 | - if ( ! get_option( 'wpinv_cleared_old_events' ) ) { |
|
55 | - wp_clear_scheduled_hook( 'wpinv_register_schedule_event_twicedaily' ); |
|
56 | - wp_clear_scheduled_hook( 'wpinv_register_schedule_event_daily' ); |
|
57 | - update_option( 'wpinv_cleared_old_events', 1 ); |
|
54 | + if (!get_option('wpinv_cleared_old_events')) { |
|
55 | + wp_clear_scheduled_hook('wpinv_register_schedule_event_twicedaily'); |
|
56 | + wp_clear_scheduled_hook('wpinv_register_schedule_event_daily'); |
|
57 | + update_option('wpinv_cleared_old_events', 1); |
|
58 | 58 | } |
59 | 59 | |
60 | 60 | } |
@@ -64,7 +64,7 @@ discard block |
||
64 | 64 | * |
65 | 65 | */ |
66 | 66 | public function backwards_compat() { |
67 | - do_action( 'wpinv_register_schedule_event_daily' ); |
|
67 | + do_action('wpinv_register_schedule_event_daily'); |
|
68 | 68 | } |
69 | 69 | |
70 | 70 | /** |
@@ -74,29 +74,29 @@ discard block |
||
74 | 74 | public function check_renewing_subscriptions() { |
75 | 75 | |
76 | 76 | // Fetch subscriptions that expire today. |
77 | - $args = array( |
|
77 | + $args = array( |
|
78 | 78 | 'number' => -1, |
79 | 79 | 'count_total' => false, |
80 | 80 | 'status' => 'trialling active', |
81 | 81 | 'date_expires_query' => array( |
82 | 82 | array( |
83 | - 'year' => date( 'Y', current_time( 'timestamp' ) ), |
|
84 | - 'month' => date( 'n', current_time( 'timestamp' ) ), |
|
85 | - 'day' => date( 'j', current_time( 'timestamp' ) ), |
|
83 | + 'year' => date('Y', current_time('timestamp')), |
|
84 | + 'month' => date('n', current_time('timestamp')), |
|
85 | + 'day' => date('j', current_time('timestamp')), |
|
86 | 86 | 'compare' => '=', |
87 | 87 | ), |
88 | 88 | ), |
89 | 89 | ); |
90 | 90 | |
91 | - $subscriptions = new GetPaid_Subscriptions_Query( $args ); |
|
91 | + $subscriptions = new GetPaid_Subscriptions_Query($args); |
|
92 | 92 | |
93 | - foreach ( $subscriptions->get_results() as $subscription ) { |
|
93 | + foreach ($subscriptions->get_results() as $subscription) { |
|
94 | 94 | |
95 | 95 | /** @var WPInv_Subscription $subscription */ |
96 | - if ( $subscription->is_last_renewal() ) { |
|
96 | + if ($subscription->is_last_renewal()) { |
|
97 | 97 | $subscription->complete(); |
98 | 98 | } else { |
99 | - do_action( 'getpaid_should_renew_subscription', $subscription ); |
|
99 | + do_action('getpaid_should_renew_subscription', $subscription); |
|
100 | 100 | } |
101 | 101 | |
102 | 102 | } |
@@ -110,7 +110,7 @@ discard block |
||
110 | 110 | public function maybe_expire_subscriptions() { |
111 | 111 | |
112 | 112 | // Fetch expired subscriptions (skips those that expire today). |
113 | - $args = array( |
|
113 | + $args = array( |
|
114 | 114 | 'number' => -1, |
115 | 115 | 'count_total' => false, |
116 | 116 | 'status' => 'trialling active failing cancelled', |
@@ -120,11 +120,11 @@ discard block |
||
120 | 120 | ), |
121 | 121 | ); |
122 | 122 | |
123 | - $subscriptions = new GetPaid_Subscriptions_Query( $args ); |
|
123 | + $subscriptions = new GetPaid_Subscriptions_Query($args); |
|
124 | 124 | |
125 | - foreach ( $subscriptions->get_results() as $subscription ) { |
|
126 | - if ( apply_filters( 'getpaid_daily_maintenance_should_expire_subscription', false, $subscription ) ) { |
|
127 | - $subscription->set_status( 'expired' ); |
|
125 | + foreach ($subscriptions->get_results() as $subscription) { |
|
126 | + if (apply_filters('getpaid_daily_maintenance_should_expire_subscription', false, $subscription)) { |
|
127 | + $subscription->set_status('expired'); |
|
128 | 128 | $subscription->save(); |
129 | 129 | } |
130 | 130 | } |
@@ -136,7 +136,7 @@ discard block |
||
136 | 136 | * |
137 | 137 | */ |
138 | 138 | public function log_cron_run() { |
139 | - wpinv_error_log( 'GetPaid Daily Cron', false ); |
|
139 | + wpinv_error_log('GetPaid Daily Cron', false); |
|
140 | 140 | } |
141 | 141 | |
142 | 142 | /** |
@@ -144,11 +144,11 @@ discard block |
||
144 | 144 | * |
145 | 145 | */ |
146 | 146 | public function maybe_update_geoip_databases() { |
147 | - $updated = get_transient( 'getpaid_updated_geoip_databases' ); |
|
147 | + $updated = get_transient('getpaid_updated_geoip_databases'); |
|
148 | 148 | |
149 | - if ( false === $updated ) { |
|
150 | - set_transient( 'getpaid_updated_geoip_databases', 1, 15 * DAY_IN_SECONDS ); |
|
151 | - do_action( 'getpaid_update_geoip_databases' ); |
|
149 | + if (false === $updated) { |
|
150 | + set_transient('getpaid_updated_geoip_databases', 1, 15 * DAY_IN_SECONDS); |
|
151 | + do_action('getpaid_update_geoip_databases'); |
|
152 | 152 | } |
153 | 153 | |
154 | 154 | } |
@@ -12,228 +12,228 @@ |
||
12 | 12 | */ |
13 | 13 | class GetPaid_Payment_Form_Submission_Taxes { |
14 | 14 | |
15 | - /** |
|
16 | - * Submission taxes. |
|
17 | - * @var array |
|
18 | - */ |
|
19 | - public $taxes = array(); |
|
20 | - |
|
21 | - /** |
|
22 | - * Whether or not we should skip the taxes. |
|
23 | - * @var bool |
|
24 | - */ |
|
25 | - protected $skip_taxes = false; |
|
15 | + /** |
|
16 | + * Submission taxes. |
|
17 | + * @var array |
|
18 | + */ |
|
19 | + public $taxes = array(); |
|
20 | + |
|
21 | + /** |
|
22 | + * Whether or not we should skip the taxes. |
|
23 | + * @var bool |
|
24 | + */ |
|
25 | + protected $skip_taxes = false; |
|
26 | 26 | |
27 | 27 | /** |
28 | - * Class constructor |
|
29 | - * |
|
30 | - * @param GetPaid_Payment_Form_Submission $submission |
|
31 | - */ |
|
32 | - public function __construct( $submission ) { |
|
33 | - |
|
34 | - // Validate VAT number. |
|
35 | - $this->validate_vat( $submission ); |
|
36 | - |
|
37 | - if ( $this->skip_taxes ) { |
|
38 | - return; |
|
39 | - } |
|
40 | - |
|
41 | - foreach ( $submission->get_items() as $item ) { |
|
42 | - $this->process_item_tax( $item, $submission ); |
|
43 | - } |
|
44 | - |
|
45 | - // Process any existing invoice taxes. |
|
46 | - if ( $submission->has_invoice() ) { |
|
47 | - $this->taxes = array_replace( $submission->get_invoice()->get_taxes(), $this->taxes ); |
|
48 | - } |
|
49 | - |
|
50 | - } |
|
51 | - |
|
52 | - /** |
|
53 | - * Maybe process tax. |
|
54 | - * |
|
55 | - * @since 1.0.19 |
|
56 | - * @param GetPaid_Form_Item $item |
|
57 | - * @param GetPaid_Payment_Form_Submission $submission |
|
58 | - */ |
|
59 | - public function process_item_tax( $item, $submission ) { |
|
60 | - |
|
61 | - $rates = getpaid_get_item_tax_rates( $item, $submission->country, $submission->state ); |
|
62 | - $rates = getpaid_filter_item_tax_rates( $item, $rates ); |
|
63 | - $taxes = getpaid_calculate_item_taxes( getpaid_get_taxable_amount( $item, false ), $rates ); |
|
64 | - $r_taxes = getpaid_calculate_item_taxes( getpaid_get_taxable_amount( $item, true ), $rates ); |
|
65 | - |
|
66 | - foreach ( $taxes as $name => $amount ) { |
|
67 | - $recurring = isset( $r_taxes[ $name ] ) ? $r_taxes[ $name ] : 0; |
|
68 | - $tax = getpaid_prepare_item_tax( $item, $name, $amount, $recurring ); |
|
69 | - |
|
70 | - $item->item_tax += wpinv_sanitize_amount( $tax['initial_tax'] ); |
|
71 | - |
|
72 | - if ( ! isset( $this->taxes[ $name ] ) ) { |
|
73 | - $this->taxes[ $name ] = $tax; |
|
74 | - continue; |
|
75 | - } |
|
76 | - |
|
77 | - $this->taxes[ $name ]['initial_tax'] += $tax['initial_tax']; |
|
78 | - $this->taxes[ $name ]['recurring_tax'] += $tax['recurring_tax']; |
|
79 | - |
|
80 | - } |
|
81 | - |
|
82 | - } |
|
83 | - |
|
84 | - /** |
|
85 | - * Checks if the submission has a digital item. |
|
86 | - * |
|
87 | - * @param GetPaid_Payment_Form_Submission $submission |
|
88 | - * @since 1.0.19 |
|
89 | - * @return bool |
|
90 | - */ |
|
91 | - public function has_digital_item( $submission ) { |
|
92 | - |
|
93 | - foreach ( $submission->get_items() as $item ) { |
|
94 | - |
|
95 | - if ( 'digital' == $item->get_vat_rule() ) { |
|
96 | - return true; |
|
97 | - } |
|
98 | - |
|
99 | - } |
|
100 | - |
|
101 | - return false; |
|
102 | - } |
|
103 | - |
|
104 | - /** |
|
105 | - * Checks if this is an eu store. |
|
106 | - * |
|
107 | - * @since 1.0.19 |
|
108 | - * @return bool |
|
109 | - */ |
|
110 | - public static function is_eu_store() { |
|
111 | - return self::is_eu_country( wpinv_get_default_country() ); |
|
112 | - } |
|
113 | - |
|
114 | - /** |
|
115 | - * Checks if this is an eu country. |
|
116 | - * |
|
117 | - * @param string $country |
|
118 | - * @since 1.0.19 |
|
119 | - * @return bool |
|
120 | - */ |
|
121 | - public static function is_eu_country( $country ) { |
|
122 | - return getpaid_is_eu_state( $country ); |
|
123 | - } |
|
124 | - |
|
125 | - /** |
|
126 | - * Checks if this is an eu purchase. |
|
127 | - * |
|
128 | - * @param string $customer_country |
|
129 | - * @since 1.0.19 |
|
130 | - * @return bool |
|
131 | - */ |
|
132 | - public static function is_eu_transaction( $customer_country ) { |
|
133 | - return self::is_eu_country( $customer_country ) && self::is_eu_store(); |
|
134 | - } |
|
135 | - |
|
136 | - /** |
|
137 | - * Retrieves the vat number. |
|
138 | - * |
|
139 | - * @param GetPaid_Payment_Form_Submission $submission |
|
140 | - * @since 1.0.19 |
|
141 | - * @return string |
|
142 | - */ |
|
143 | - public function get_vat_number( $submission ) { |
|
144 | - |
|
145 | - // Retrieve from the posted number. |
|
146 | - $vat_number = $submission->get_field( 'wpinv_vat_number', 'billing' ); |
|
147 | - if ( ! is_null( $vat_number ) ) { |
|
148 | - return wpinv_clean( $vat_number ); |
|
149 | - } |
|
150 | - |
|
151 | - return $submission->has_invoice() ? $submission->get_invoice()->get_vat_number() : ''; |
|
152 | - } |
|
153 | - |
|
154 | - /** |
|
155 | - * Retrieves the company. |
|
156 | - * |
|
157 | - * @param GetPaid_Payment_Form_Submission $submission |
|
158 | - * @since 1.0.19 |
|
159 | - * @return string |
|
160 | - */ |
|
161 | - public function get_company( $submission ) { |
|
162 | - |
|
163 | - // Retrieve from the posted data. |
|
164 | - $company = $submission->get_field( 'wpinv_company', 'billing' ); |
|
165 | - if ( ! empty( $company ) ) { |
|
166 | - return wpinv_clean( $company ); |
|
167 | - } |
|
168 | - |
|
169 | - // Retrieve from the invoice. |
|
170 | - return $submission->has_invoice() ? $submission->get_invoice()->get_company() : ''; |
|
171 | - } |
|
172 | - |
|
173 | - /** |
|
174 | - * Checks if we require a VAT number. |
|
175 | - * |
|
176 | - * @param bool $ip_in_eu Whether the customer IP is from the EU |
|
177 | - * @param bool $country_in_eu Whether the customer country is from the EU |
|
178 | - * @since 1.0.19 |
|
179 | - * @return string |
|
180 | - */ |
|
181 | - public function requires_vat( $ip_in_eu, $country_in_eu ) { |
|
182 | - |
|
183 | - $prevent_b2c = wpinv_get_option( 'vat_prevent_b2c_purchase' ); |
|
184 | - $prevent_b2c = ! empty( $prevent_b2c ); |
|
185 | - $is_eu = $ip_in_eu || $country_in_eu; |
|
186 | - |
|
187 | - return $prevent_b2c && $is_eu; |
|
188 | - } |
|
189 | - |
|
190 | - /** |
|
191 | - * Validate VAT data. |
|
192 | - * |
|
193 | - * @param GetPaid_Payment_Form_Submission $submission |
|
194 | - * @since 1.0.19 |
|
195 | - */ |
|
196 | - public function validate_vat( $submission ) { |
|
197 | - |
|
198 | - $in_eu = $this->is_eu_transaction( $submission->country ); |
|
199 | - |
|
200 | - // Abort if we are not validating vat numbers. |
|
201 | - if ( ! $in_eu ) { |
|
28 | + * Class constructor |
|
29 | + * |
|
30 | + * @param GetPaid_Payment_Form_Submission $submission |
|
31 | + */ |
|
32 | + public function __construct( $submission ) { |
|
33 | + |
|
34 | + // Validate VAT number. |
|
35 | + $this->validate_vat( $submission ); |
|
36 | + |
|
37 | + if ( $this->skip_taxes ) { |
|
202 | 38 | return; |
203 | - } |
|
39 | + } |
|
40 | + |
|
41 | + foreach ( $submission->get_items() as $item ) { |
|
42 | + $this->process_item_tax( $item, $submission ); |
|
43 | + } |
|
44 | + |
|
45 | + // Process any existing invoice taxes. |
|
46 | + if ( $submission->has_invoice() ) { |
|
47 | + $this->taxes = array_replace( $submission->get_invoice()->get_taxes(), $this->taxes ); |
|
48 | + } |
|
49 | + |
|
50 | + } |
|
51 | + |
|
52 | + /** |
|
53 | + * Maybe process tax. |
|
54 | + * |
|
55 | + * @since 1.0.19 |
|
56 | + * @param GetPaid_Form_Item $item |
|
57 | + * @param GetPaid_Payment_Form_Submission $submission |
|
58 | + */ |
|
59 | + public function process_item_tax( $item, $submission ) { |
|
60 | + |
|
61 | + $rates = getpaid_get_item_tax_rates( $item, $submission->country, $submission->state ); |
|
62 | + $rates = getpaid_filter_item_tax_rates( $item, $rates ); |
|
63 | + $taxes = getpaid_calculate_item_taxes( getpaid_get_taxable_amount( $item, false ), $rates ); |
|
64 | + $r_taxes = getpaid_calculate_item_taxes( getpaid_get_taxable_amount( $item, true ), $rates ); |
|
65 | + |
|
66 | + foreach ( $taxes as $name => $amount ) { |
|
67 | + $recurring = isset( $r_taxes[ $name ] ) ? $r_taxes[ $name ] : 0; |
|
68 | + $tax = getpaid_prepare_item_tax( $item, $name, $amount, $recurring ); |
|
69 | + |
|
70 | + $item->item_tax += wpinv_sanitize_amount( $tax['initial_tax'] ); |
|
71 | + |
|
72 | + if ( ! isset( $this->taxes[ $name ] ) ) { |
|
73 | + $this->taxes[ $name ] = $tax; |
|
74 | + continue; |
|
75 | + } |
|
76 | + |
|
77 | + $this->taxes[ $name ]['initial_tax'] += $tax['initial_tax']; |
|
78 | + $this->taxes[ $name ]['recurring_tax'] += $tax['recurring_tax']; |
|
79 | + |
|
80 | + } |
|
81 | + |
|
82 | + } |
|
83 | + |
|
84 | + /** |
|
85 | + * Checks if the submission has a digital item. |
|
86 | + * |
|
87 | + * @param GetPaid_Payment_Form_Submission $submission |
|
88 | + * @since 1.0.19 |
|
89 | + * @return bool |
|
90 | + */ |
|
91 | + public function has_digital_item( $submission ) { |
|
92 | + |
|
93 | + foreach ( $submission->get_items() as $item ) { |
|
94 | + |
|
95 | + if ( 'digital' == $item->get_vat_rule() ) { |
|
96 | + return true; |
|
97 | + } |
|
98 | + |
|
99 | + } |
|
204 | 100 | |
205 | - // Prepare variables. |
|
206 | - $vat_number = $this->get_vat_number( $submission ); |
|
207 | - $ip_country = getpaid_get_ip_country(); |
|
101 | + return false; |
|
102 | + } |
|
103 | + |
|
104 | + /** |
|
105 | + * Checks if this is an eu store. |
|
106 | + * |
|
107 | + * @since 1.0.19 |
|
108 | + * @return bool |
|
109 | + */ |
|
110 | + public static function is_eu_store() { |
|
111 | + return self::is_eu_country( wpinv_get_default_country() ); |
|
112 | + } |
|
113 | + |
|
114 | + /** |
|
115 | + * Checks if this is an eu country. |
|
116 | + * |
|
117 | + * @param string $country |
|
118 | + * @since 1.0.19 |
|
119 | + * @return bool |
|
120 | + */ |
|
121 | + public static function is_eu_country( $country ) { |
|
122 | + return getpaid_is_eu_state( $country ); |
|
123 | + } |
|
124 | + |
|
125 | + /** |
|
126 | + * Checks if this is an eu purchase. |
|
127 | + * |
|
128 | + * @param string $customer_country |
|
129 | + * @since 1.0.19 |
|
130 | + * @return bool |
|
131 | + */ |
|
132 | + public static function is_eu_transaction( $customer_country ) { |
|
133 | + return self::is_eu_country( $customer_country ) && self::is_eu_store(); |
|
134 | + } |
|
135 | + |
|
136 | + /** |
|
137 | + * Retrieves the vat number. |
|
138 | + * |
|
139 | + * @param GetPaid_Payment_Form_Submission $submission |
|
140 | + * @since 1.0.19 |
|
141 | + * @return string |
|
142 | + */ |
|
143 | + public function get_vat_number( $submission ) { |
|
144 | + |
|
145 | + // Retrieve from the posted number. |
|
146 | + $vat_number = $submission->get_field( 'wpinv_vat_number', 'billing' ); |
|
147 | + if ( ! is_null( $vat_number ) ) { |
|
148 | + return wpinv_clean( $vat_number ); |
|
149 | + } |
|
150 | + |
|
151 | + return $submission->has_invoice() ? $submission->get_invoice()->get_vat_number() : ''; |
|
152 | + } |
|
153 | + |
|
154 | + /** |
|
155 | + * Retrieves the company. |
|
156 | + * |
|
157 | + * @param GetPaid_Payment_Form_Submission $submission |
|
158 | + * @since 1.0.19 |
|
159 | + * @return string |
|
160 | + */ |
|
161 | + public function get_company( $submission ) { |
|
162 | + |
|
163 | + // Retrieve from the posted data. |
|
164 | + $company = $submission->get_field( 'wpinv_company', 'billing' ); |
|
165 | + if ( ! empty( $company ) ) { |
|
166 | + return wpinv_clean( $company ); |
|
167 | + } |
|
168 | + |
|
169 | + // Retrieve from the invoice. |
|
170 | + return $submission->has_invoice() ? $submission->get_invoice()->get_company() : ''; |
|
171 | + } |
|
172 | + |
|
173 | + /** |
|
174 | + * Checks if we require a VAT number. |
|
175 | + * |
|
176 | + * @param bool $ip_in_eu Whether the customer IP is from the EU |
|
177 | + * @param bool $country_in_eu Whether the customer country is from the EU |
|
178 | + * @since 1.0.19 |
|
179 | + * @return string |
|
180 | + */ |
|
181 | + public function requires_vat( $ip_in_eu, $country_in_eu ) { |
|
182 | + |
|
183 | + $prevent_b2c = wpinv_get_option( 'vat_prevent_b2c_purchase' ); |
|
184 | + $prevent_b2c = ! empty( $prevent_b2c ); |
|
185 | + $is_eu = $ip_in_eu || $country_in_eu; |
|
186 | + |
|
187 | + return $prevent_b2c && $is_eu; |
|
188 | + } |
|
189 | + |
|
190 | + /** |
|
191 | + * Validate VAT data. |
|
192 | + * |
|
193 | + * @param GetPaid_Payment_Form_Submission $submission |
|
194 | + * @since 1.0.19 |
|
195 | + */ |
|
196 | + public function validate_vat( $submission ) { |
|
197 | + |
|
198 | + $in_eu = $this->is_eu_transaction( $submission->country ); |
|
199 | + |
|
200 | + // Abort if we are not validating vat numbers. |
|
201 | + if ( ! $in_eu ) { |
|
202 | + return; |
|
203 | + } |
|
204 | + |
|
205 | + // Prepare variables. |
|
206 | + $vat_number = $this->get_vat_number( $submission ); |
|
207 | + $ip_country = getpaid_get_ip_country(); |
|
208 | 208 | $is_eu = $this->is_eu_country( $submission->country ); |
209 | 209 | $is_ip_eu = $this->is_eu_country( $ip_country ); |
210 | 210 | |
211 | - // Maybe abort early for initial fetches. |
|
212 | - if ( $submission->is_initial_fetch() && empty( $vat_number ) ) { |
|
213 | - return; |
|
214 | - } |
|
211 | + // Maybe abort early for initial fetches. |
|
212 | + if ( $submission->is_initial_fetch() && empty( $vat_number ) ) { |
|
213 | + return; |
|
214 | + } |
|
215 | 215 | |
216 | - // If we're preventing business to consumer purchases, |
|
217 | - if ( $this->requires_vat( $is_ip_eu, $is_eu ) && empty( $vat_number ) ) { |
|
216 | + // If we're preventing business to consumer purchases, |
|
217 | + if ( $this->requires_vat( $is_ip_eu, $is_eu ) && empty( $vat_number ) ) { |
|
218 | 218 | |
219 | - // Ensure that a vat number has been specified. |
|
220 | - throw new GetPaid_Payment_Exception( '.getpaid-error-billingwpinv_vat_number.getpaid-custom-payment-form-errors', __( 'Please enter your VAT number to verify your purchase is by an EU business.', 'invoicing' ) ); |
|
219 | + // Ensure that a vat number has been specified. |
|
220 | + throw new GetPaid_Payment_Exception( '.getpaid-error-billingwpinv_vat_number.getpaid-custom-payment-form-errors', __( 'Please enter your VAT number to verify your purchase is by an EU business.', 'invoicing' ) ); |
|
221 | 221 | |
222 | - } |
|
222 | + } |
|
223 | 223 | |
224 | - if ( empty( $vat_number ) ) { |
|
225 | - return; |
|
226 | - } |
|
224 | + if ( empty( $vat_number ) ) { |
|
225 | + return; |
|
226 | + } |
|
227 | 227 | |
228 | - if ( wpinv_should_validate_vat_number() && ! wpinv_validate_vat_number( $vat_number, $submission->country ) ) { |
|
229 | - throw new GetPaid_Payment_Exception( '.getpaid-error-billingwpinv_vat_number.getpaid-custom-payment-form-errors', __( 'Your VAT number is invalid', 'invoicing' ) ); |
|
230 | - } |
|
228 | + if ( wpinv_should_validate_vat_number() && ! wpinv_validate_vat_number( $vat_number, $submission->country ) ) { |
|
229 | + throw new GetPaid_Payment_Exception( '.getpaid-error-billingwpinv_vat_number.getpaid-custom-payment-form-errors', __( 'Your VAT number is invalid', 'invoicing' ) ); |
|
230 | + } |
|
231 | 231 | |
232 | - if ( wpinv_default_billing_country() == $submission->country && 'vat_too' == wpinv_get_option( 'vat_same_country_rule', 'vat_too' ) ) { |
|
233 | - return; |
|
234 | - } |
|
232 | + if ( wpinv_default_billing_country() == $submission->country && 'vat_too' == wpinv_get_option( 'vat_same_country_rule', 'vat_too' ) ) { |
|
233 | + return; |
|
234 | + } |
|
235 | 235 | |
236 | - $this->skip_taxes = true; |
|
237 | - } |
|
236 | + $this->skip_taxes = true; |
|
237 | + } |
|
238 | 238 | |
239 | 239 | } |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | * |
5 | 5 | */ |
6 | 6 | |
7 | -defined( 'ABSPATH' ) || exit; |
|
7 | +defined('ABSPATH') || exit; |
|
8 | 8 | |
9 | 9 | /** |
10 | 10 | * Payment form submission taxes class |
@@ -29,22 +29,22 @@ discard block |
||
29 | 29 | * |
30 | 30 | * @param GetPaid_Payment_Form_Submission $submission |
31 | 31 | */ |
32 | - public function __construct( $submission ) { |
|
32 | + public function __construct($submission) { |
|
33 | 33 | |
34 | 34 | // Validate VAT number. |
35 | - $this->validate_vat( $submission ); |
|
35 | + $this->validate_vat($submission); |
|
36 | 36 | |
37 | - if ( $this->skip_taxes ) { |
|
37 | + if ($this->skip_taxes) { |
|
38 | 38 | return; |
39 | 39 | } |
40 | 40 | |
41 | - foreach ( $submission->get_items() as $item ) { |
|
42 | - $this->process_item_tax( $item, $submission ); |
|
41 | + foreach ($submission->get_items() as $item) { |
|
42 | + $this->process_item_tax($item, $submission); |
|
43 | 43 | } |
44 | 44 | |
45 | 45 | // Process any existing invoice taxes. |
46 | - if ( $submission->has_invoice() ) { |
|
47 | - $this->taxes = array_replace( $submission->get_invoice()->get_taxes(), $this->taxes ); |
|
46 | + if ($submission->has_invoice()) { |
|
47 | + $this->taxes = array_replace($submission->get_invoice()->get_taxes(), $this->taxes); |
|
48 | 48 | } |
49 | 49 | |
50 | 50 | } |
@@ -56,26 +56,26 @@ discard block |
||
56 | 56 | * @param GetPaid_Form_Item $item |
57 | 57 | * @param GetPaid_Payment_Form_Submission $submission |
58 | 58 | */ |
59 | - public function process_item_tax( $item, $submission ) { |
|
59 | + public function process_item_tax($item, $submission) { |
|
60 | 60 | |
61 | - $rates = getpaid_get_item_tax_rates( $item, $submission->country, $submission->state ); |
|
62 | - $rates = getpaid_filter_item_tax_rates( $item, $rates ); |
|
63 | - $taxes = getpaid_calculate_item_taxes( getpaid_get_taxable_amount( $item, false ), $rates ); |
|
64 | - $r_taxes = getpaid_calculate_item_taxes( getpaid_get_taxable_amount( $item, true ), $rates ); |
|
61 | + $rates = getpaid_get_item_tax_rates($item, $submission->country, $submission->state); |
|
62 | + $rates = getpaid_filter_item_tax_rates($item, $rates); |
|
63 | + $taxes = getpaid_calculate_item_taxes(getpaid_get_taxable_amount($item, false), $rates); |
|
64 | + $r_taxes = getpaid_calculate_item_taxes(getpaid_get_taxable_amount($item, true), $rates); |
|
65 | 65 | |
66 | - foreach ( $taxes as $name => $amount ) { |
|
67 | - $recurring = isset( $r_taxes[ $name ] ) ? $r_taxes[ $name ] : 0; |
|
68 | - $tax = getpaid_prepare_item_tax( $item, $name, $amount, $recurring ); |
|
66 | + foreach ($taxes as $name => $amount) { |
|
67 | + $recurring = isset($r_taxes[$name]) ? $r_taxes[$name] : 0; |
|
68 | + $tax = getpaid_prepare_item_tax($item, $name, $amount, $recurring); |
|
69 | 69 | |
70 | - $item->item_tax += wpinv_sanitize_amount( $tax['initial_tax'] ); |
|
70 | + $item->item_tax += wpinv_sanitize_amount($tax['initial_tax']); |
|
71 | 71 | |
72 | - if ( ! isset( $this->taxes[ $name ] ) ) { |
|
73 | - $this->taxes[ $name ] = $tax; |
|
72 | + if (!isset($this->taxes[$name])) { |
|
73 | + $this->taxes[$name] = $tax; |
|
74 | 74 | continue; |
75 | 75 | } |
76 | 76 | |
77 | - $this->taxes[ $name ]['initial_tax'] += $tax['initial_tax']; |
|
78 | - $this->taxes[ $name ]['recurring_tax'] += $tax['recurring_tax']; |
|
77 | + $this->taxes[$name]['initial_tax'] += $tax['initial_tax']; |
|
78 | + $this->taxes[$name]['recurring_tax'] += $tax['recurring_tax']; |
|
79 | 79 | |
80 | 80 | } |
81 | 81 | |
@@ -88,11 +88,11 @@ discard block |
||
88 | 88 | * @since 1.0.19 |
89 | 89 | * @return bool |
90 | 90 | */ |
91 | - public function has_digital_item( $submission ) { |
|
91 | + public function has_digital_item($submission) { |
|
92 | 92 | |
93 | - foreach ( $submission->get_items() as $item ) { |
|
93 | + foreach ($submission->get_items() as $item) { |
|
94 | 94 | |
95 | - if ( 'digital' == $item->get_vat_rule() ) { |
|
95 | + if ('digital' == $item->get_vat_rule()) { |
|
96 | 96 | return true; |
97 | 97 | } |
98 | 98 | |
@@ -108,7 +108,7 @@ discard block |
||
108 | 108 | * @return bool |
109 | 109 | */ |
110 | 110 | public static function is_eu_store() { |
111 | - return self::is_eu_country( wpinv_get_default_country() ); |
|
111 | + return self::is_eu_country(wpinv_get_default_country()); |
|
112 | 112 | } |
113 | 113 | |
114 | 114 | /** |
@@ -118,8 +118,8 @@ discard block |
||
118 | 118 | * @since 1.0.19 |
119 | 119 | * @return bool |
120 | 120 | */ |
121 | - public static function is_eu_country( $country ) { |
|
122 | - return getpaid_is_eu_state( $country ); |
|
121 | + public static function is_eu_country($country) { |
|
122 | + return getpaid_is_eu_state($country); |
|
123 | 123 | } |
124 | 124 | |
125 | 125 | /** |
@@ -129,8 +129,8 @@ discard block |
||
129 | 129 | * @since 1.0.19 |
130 | 130 | * @return bool |
131 | 131 | */ |
132 | - public static function is_eu_transaction( $customer_country ) { |
|
133 | - return self::is_eu_country( $customer_country ) && self::is_eu_store(); |
|
132 | + public static function is_eu_transaction($customer_country) { |
|
133 | + return self::is_eu_country($customer_country) && self::is_eu_store(); |
|
134 | 134 | } |
135 | 135 | |
136 | 136 | /** |
@@ -140,12 +140,12 @@ discard block |
||
140 | 140 | * @since 1.0.19 |
141 | 141 | * @return string |
142 | 142 | */ |
143 | - public function get_vat_number( $submission ) { |
|
143 | + public function get_vat_number($submission) { |
|
144 | 144 | |
145 | 145 | // Retrieve from the posted number. |
146 | - $vat_number = $submission->get_field( 'wpinv_vat_number', 'billing' ); |
|
147 | - if ( ! is_null( $vat_number ) ) { |
|
148 | - return wpinv_clean( $vat_number ); |
|
146 | + $vat_number = $submission->get_field('wpinv_vat_number', 'billing'); |
|
147 | + if (!is_null($vat_number)) { |
|
148 | + return wpinv_clean($vat_number); |
|
149 | 149 | } |
150 | 150 | |
151 | 151 | return $submission->has_invoice() ? $submission->get_invoice()->get_vat_number() : ''; |
@@ -158,12 +158,12 @@ discard block |
||
158 | 158 | * @since 1.0.19 |
159 | 159 | * @return string |
160 | 160 | */ |
161 | - public function get_company( $submission ) { |
|
161 | + public function get_company($submission) { |
|
162 | 162 | |
163 | 163 | // Retrieve from the posted data. |
164 | - $company = $submission->get_field( 'wpinv_company', 'billing' ); |
|
165 | - if ( ! empty( $company ) ) { |
|
166 | - return wpinv_clean( $company ); |
|
164 | + $company = $submission->get_field('wpinv_company', 'billing'); |
|
165 | + if (!empty($company)) { |
|
166 | + return wpinv_clean($company); |
|
167 | 167 | } |
168 | 168 | |
169 | 169 | // Retrieve from the invoice. |
@@ -178,10 +178,10 @@ discard block |
||
178 | 178 | * @since 1.0.19 |
179 | 179 | * @return string |
180 | 180 | */ |
181 | - public function requires_vat( $ip_in_eu, $country_in_eu ) { |
|
181 | + public function requires_vat($ip_in_eu, $country_in_eu) { |
|
182 | 182 | |
183 | - $prevent_b2c = wpinv_get_option( 'vat_prevent_b2c_purchase' ); |
|
184 | - $prevent_b2c = ! empty( $prevent_b2c ); |
|
183 | + $prevent_b2c = wpinv_get_option('vat_prevent_b2c_purchase'); |
|
184 | + $prevent_b2c = !empty($prevent_b2c); |
|
185 | 185 | $is_eu = $ip_in_eu || $country_in_eu; |
186 | 186 | |
187 | 187 | return $prevent_b2c && $is_eu; |
@@ -193,43 +193,43 @@ discard block |
||
193 | 193 | * @param GetPaid_Payment_Form_Submission $submission |
194 | 194 | * @since 1.0.19 |
195 | 195 | */ |
196 | - public function validate_vat( $submission ) { |
|
196 | + public function validate_vat($submission) { |
|
197 | 197 | |
198 | - $in_eu = $this->is_eu_transaction( $submission->country ); |
|
198 | + $in_eu = $this->is_eu_transaction($submission->country); |
|
199 | 199 | |
200 | 200 | // Abort if we are not validating vat numbers. |
201 | - if ( ! $in_eu ) { |
|
201 | + if (!$in_eu) { |
|
202 | 202 | return; |
203 | 203 | } |
204 | 204 | |
205 | 205 | // Prepare variables. |
206 | - $vat_number = $this->get_vat_number( $submission ); |
|
206 | + $vat_number = $this->get_vat_number($submission); |
|
207 | 207 | $ip_country = getpaid_get_ip_country(); |
208 | - $is_eu = $this->is_eu_country( $submission->country ); |
|
209 | - $is_ip_eu = $this->is_eu_country( $ip_country ); |
|
208 | + $is_eu = $this->is_eu_country($submission->country); |
|
209 | + $is_ip_eu = $this->is_eu_country($ip_country); |
|
210 | 210 | |
211 | 211 | // Maybe abort early for initial fetches. |
212 | - if ( $submission->is_initial_fetch() && empty( $vat_number ) ) { |
|
212 | + if ($submission->is_initial_fetch() && empty($vat_number)) { |
|
213 | 213 | return; |
214 | 214 | } |
215 | 215 | |
216 | 216 | // If we're preventing business to consumer purchases, |
217 | - if ( $this->requires_vat( $is_ip_eu, $is_eu ) && empty( $vat_number ) ) { |
|
217 | + if ($this->requires_vat($is_ip_eu, $is_eu) && empty($vat_number)) { |
|
218 | 218 | |
219 | 219 | // Ensure that a vat number has been specified. |
220 | - throw new GetPaid_Payment_Exception( '.getpaid-error-billingwpinv_vat_number.getpaid-custom-payment-form-errors', __( 'Please enter your VAT number to verify your purchase is by an EU business.', 'invoicing' ) ); |
|
220 | + throw new GetPaid_Payment_Exception('.getpaid-error-billingwpinv_vat_number.getpaid-custom-payment-form-errors', __('Please enter your VAT number to verify your purchase is by an EU business.', 'invoicing')); |
|
221 | 221 | |
222 | 222 | } |
223 | 223 | |
224 | - if ( empty( $vat_number ) ) { |
|
224 | + if (empty($vat_number)) { |
|
225 | 225 | return; |
226 | 226 | } |
227 | 227 | |
228 | - if ( wpinv_should_validate_vat_number() && ! wpinv_validate_vat_number( $vat_number, $submission->country ) ) { |
|
229 | - throw new GetPaid_Payment_Exception( '.getpaid-error-billingwpinv_vat_number.getpaid-custom-payment-form-errors', __( 'Your VAT number is invalid', 'invoicing' ) ); |
|
228 | + if (wpinv_should_validate_vat_number() && !wpinv_validate_vat_number($vat_number, $submission->country)) { |
|
229 | + throw new GetPaid_Payment_Exception('.getpaid-error-billingwpinv_vat_number.getpaid-custom-payment-form-errors', __('Your VAT number is invalid', 'invoicing')); |
|
230 | 230 | } |
231 | 231 | |
232 | - if ( wpinv_default_billing_country() == $submission->country && 'vat_too' == wpinv_get_option( 'vat_same_country_rule', 'vat_too' ) ) { |
|
232 | + if (wpinv_default_billing_country() == $submission->country && 'vat_too' == wpinv_get_option('vat_same_country_rule', 'vat_too')) { |
|
233 | 233 | return; |
234 | 234 | } |
235 | 235 |