@@ -10,7 +10,7 @@ discard block |
||
10 | 10 | defined( 'ABSPATH' ) || exit; |
11 | 11 | |
12 | 12 | if ( empty( $fields ) ) { |
13 | - return; |
|
13 | + return; |
|
14 | 14 | } |
15 | 15 | |
16 | 16 | // A prefix for all ids (so that a form can be included in the same page multiple times). |
@@ -18,12 +18,12 @@ discard block |
||
18 | 18 | |
19 | 19 | // Prepare the user's country. |
20 | 20 | if ( ! empty( $form->invoice ) ) { |
21 | - $country = $form->invoice->get_country(); |
|
21 | + $country = $form->invoice->get_country(); |
|
22 | 22 | } |
23 | 23 | |
24 | 24 | if ( empty( $country ) ) { |
25 | - $country = empty( $country ) ? getpaid_get_ip_country() : $country; |
|
26 | - $country = empty( $country ) ? wpinv_get_default_country() : $country; |
|
25 | + $country = empty( $country ) ? getpaid_get_ip_country() : $country; |
|
26 | + $country = empty( $country ) ? wpinv_get_default_country() : $country; |
|
27 | 27 | } |
28 | 28 | |
29 | 29 | // A prefix for all ids (so that a form can be included in the same page multiple times). |
@@ -55,10 +55,10 @@ discard block |
||
55 | 55 | <!-- Start Billing Address --> |
56 | 56 | <div class="getpaid-billing-address-wrapper"> |
57 | 57 | <?php |
58 | - $field_type = 'billing'; |
|
59 | - include plugin_dir_path( __FILE__ ) . 'address-fields.php'; |
|
60 | - do_action( 'getpaid_after_payment_form_billing_fields', $form ); |
|
61 | - ?> |
|
58 | + $field_type = 'billing'; |
|
59 | + include plugin_dir_path( __FILE__ ) . 'address-fields.php'; |
|
60 | + do_action( 'getpaid_after_payment_form_billing_fields', $form ); |
|
61 | + ?> |
|
62 | 62 | </div> |
63 | 63 | <!-- End Billing Address --> |
64 | 64 | |
@@ -70,19 +70,19 @@ discard block |
||
70 | 70 | |
71 | 71 | <?php |
72 | 72 | |
73 | - echo aui()->input( |
|
74 | - array( |
|
75 | - 'type' => 'checkbox', |
|
76 | - 'name' => 'same-shipping-address', |
|
77 | - 'id' => "shipping-toggle$uniqid", |
|
78 | - 'required' => false, |
|
79 | - 'label' => wp_kses_post( $shipping_address_toggle ), |
|
80 | - 'value' => 1, |
|
81 | - 'checked' => true, |
|
82 | - ) |
|
83 | - ); |
|
73 | + echo aui()->input( |
|
74 | + array( |
|
75 | + 'type' => 'checkbox', |
|
76 | + 'name' => 'same-shipping-address', |
|
77 | + 'id' => "shipping-toggle$uniqid", |
|
78 | + 'required' => false, |
|
79 | + 'label' => wp_kses_post( $shipping_address_toggle ), |
|
80 | + 'value' => 1, |
|
81 | + 'checked' => true, |
|
82 | + ) |
|
83 | + ); |
|
84 | 84 | |
85 | - ?> |
|
85 | + ?> |
|
86 | 86 | |
87 | 87 | |
88 | 88 | <!-- Start Shipping Address Title --> |
@@ -101,10 +101,10 @@ discard block |
||
101 | 101 | <!-- Start Shipping Address --> |
102 | 102 | <div class="getpaid-shipping-address-wrapper"> |
103 | 103 | <?php |
104 | - $field_type = 'shipping'; |
|
105 | - include plugin_dir_path( __FILE__ ) . 'address-fields.php'; |
|
106 | - do_action( 'getpaid_after_payment_form_shipping_fields', $form ); |
|
107 | - ?> |
|
104 | + $field_type = 'shipping'; |
|
105 | + include plugin_dir_path( __FILE__ ) . 'address-fields.php'; |
|
106 | + do_action( 'getpaid_after_payment_form_shipping_fields', $form ); |
|
107 | + ?> |
|
108 | 108 | </div> |
109 | 109 | <!-- End Shipping Address --> |
110 | 110 |
@@ -7,57 +7,57 @@ discard block |
||
7 | 7 | * @version 1.0.19 |
8 | 8 | */ |
9 | 9 | |
10 | -defined( 'ABSPATH' ) || exit; |
|
10 | +defined('ABSPATH') || exit; |
|
11 | 11 | |
12 | -if ( empty( $fields ) ) { |
|
12 | +if (empty($fields)) { |
|
13 | 13 | return; |
14 | 14 | } |
15 | 15 | |
16 | 16 | // A prefix for all ids (so that a form can be included in the same page multiple times). |
17 | -$uniqid = uniqid( '_' ); |
|
17 | +$uniqid = uniqid('_'); |
|
18 | 18 | |
19 | 19 | // Prepare the user's country. |
20 | -if ( ! empty( $form->invoice ) ) { |
|
20 | +if (!empty($form->invoice)) { |
|
21 | 21 | $country = $form->invoice->get_country(); |
22 | 22 | } |
23 | 23 | |
24 | -if ( empty( $country ) ) { |
|
25 | - $country = empty( $country ) ? getpaid_get_ip_country() : $country; |
|
26 | - $country = empty( $country ) ? wpinv_get_default_country() : $country; |
|
24 | +if (empty($country)) { |
|
25 | + $country = empty($country) ? getpaid_get_ip_country() : $country; |
|
26 | + $country = empty($country) ? wpinv_get_default_country() : $country; |
|
27 | 27 | } |
28 | 28 | |
29 | 29 | // A prefix for all ids (so that a form can be included in the same page multiple times). |
30 | -$uniqid = uniqid( '_' ); |
|
30 | +$uniqid = uniqid('_'); |
|
31 | 31 | |
32 | -$address_type = empty( $address_type ) ? 'billing' : $address_type; |
|
32 | +$address_type = empty($address_type) ? 'billing' : $address_type; |
|
33 | 33 | |
34 | 34 | ?> |
35 | 35 | |
36 | -<?php if ( 'both' === $address_type ) : ?> |
|
36 | +<?php if ('both' === $address_type) : ?> |
|
37 | 37 | |
38 | 38 | <!-- Start Billing/Shipping Address Title --> |
39 | 39 | <h4 class="mb-3 getpaid-shipping-billing-address-title"> |
40 | - <?php _e( 'Billing / Shipping Address', 'invoicing' ); ?> |
|
40 | + <?php _e('Billing / Shipping Address', 'invoicing'); ?> |
|
41 | 41 | </h4> |
42 | 42 | <!-- End Billing Address Title --> |
43 | 43 | |
44 | 44 | <!-- Start Billing Address Title --> |
45 | 45 | <h4 class="mb-3 getpaid-billing-address-title"> |
46 | - <?php _e( 'Billing Address', 'invoicing' ); ?> |
|
46 | + <?php _e('Billing Address', 'invoicing'); ?> |
|
47 | 47 | </h4> |
48 | 48 | <!-- End Billing Address Title --> |
49 | 49 | |
50 | 50 | <?php endif; ?> |
51 | 51 | |
52 | 52 | |
53 | -<?php if ( 'both' === $address_type || 'billing' === $address_type ) : ?> |
|
53 | +<?php if ('both' === $address_type || 'billing' === $address_type) : ?> |
|
54 | 54 | |
55 | 55 | <!-- Start Billing Address --> |
56 | 56 | <div class="getpaid-billing-address-wrapper"> |
57 | 57 | <?php |
58 | 58 | $field_type = 'billing'; |
59 | - include plugin_dir_path( __FILE__ ) . 'address-fields.php'; |
|
60 | - do_action( 'getpaid_after_payment_form_billing_fields', $form ); |
|
59 | + include plugin_dir_path(__FILE__) . 'address-fields.php'; |
|
60 | + do_action('getpaid_after_payment_form_billing_fields', $form); |
|
61 | 61 | ?> |
62 | 62 | </div> |
63 | 63 | <!-- End Billing Address --> |
@@ -65,7 +65,7 @@ discard block |
||
65 | 65 | <?php endif; ?> |
66 | 66 | |
67 | 67 | |
68 | -<?php if ( 'both' === $address_type ) : ?> |
|
68 | +<?php if ('both' === $address_type) : ?> |
|
69 | 69 | |
70 | 70 | |
71 | 71 | <?php |
@@ -76,7 +76,7 @@ discard block |
||
76 | 76 | 'name' => 'same-shipping-address', |
77 | 77 | 'id' => "shipping-toggle$uniqid", |
78 | 78 | 'required' => false, |
79 | - 'label' => wp_kses_post( $shipping_address_toggle ), |
|
79 | + 'label' => wp_kses_post($shipping_address_toggle), |
|
80 | 80 | 'value' => 1, |
81 | 81 | 'checked' => true, |
82 | 82 | ) |
@@ -87,7 +87,7 @@ discard block |
||
87 | 87 | |
88 | 88 | <!-- Start Shipping Address Title --> |
89 | 89 | <h4 class="mb-3 getpaid-shipping-address-title"> |
90 | - <?php _e( 'Shipping Address', 'invoicing' ); ?> |
|
90 | + <?php _e('Shipping Address', 'invoicing'); ?> |
|
91 | 91 | </h4> |
92 | 92 | <!-- End Shipping Address Title --> |
93 | 93 | |
@@ -96,14 +96,14 @@ discard block |
||
96 | 96 | |
97 | 97 | |
98 | 98 | |
99 | -<?php if ( 'both' === $address_type || 'shipping' === $address_type ) : ?> |
|
99 | +<?php if ('both' === $address_type || 'shipping' === $address_type) : ?> |
|
100 | 100 | |
101 | 101 | <!-- Start Shipping Address --> |
102 | 102 | <div class="getpaid-shipping-address-wrapper"> |
103 | 103 | <?php |
104 | 104 | $field_type = 'shipping'; |
105 | - include plugin_dir_path( __FILE__ ) . 'address-fields.php'; |
|
106 | - do_action( 'getpaid_after_payment_form_shipping_fields', $form ); |
|
105 | + include plugin_dir_path(__FILE__) . 'address-fields.php'; |
|
106 | + do_action('getpaid_after_payment_form_shipping_fields', $form); |
|
107 | 107 | ?> |
108 | 108 | </div> |
109 | 109 | <!-- End Shipping Address --> |
@@ -11,58 +11,58 @@ discard block |
||
11 | 11 | * @var string $country The current user's country |
12 | 12 | */ |
13 | 13 | |
14 | -defined( 'ABSPATH' ) || exit; |
|
14 | +defined('ABSPATH') || exit; |
|
15 | 15 | |
16 | 16 | |
17 | -$field_type = sanitize_key( $field_type ); |
|
17 | +$field_type = sanitize_key($field_type); |
|
18 | 18 | |
19 | 19 | echo "<div class='row $field_type'>"; |
20 | 20 | |
21 | -foreach ( $fields as $address_field ) { |
|
21 | +foreach ($fields as $address_field) { |
|
22 | 22 | |
23 | 23 | // Skip if it is hidden. |
24 | - if ( empty( $address_field['visible'] ) ) { |
|
24 | + if (empty($address_field['visible'])) { |
|
25 | 25 | continue; |
26 | 26 | } |
27 | 27 | |
28 | - do_action( 'getpaid_payment_form_address_field_before_' . $address_field['name'], $field_type, $address_field ); |
|
28 | + do_action('getpaid_payment_form_address_field_before_' . $address_field['name'], $field_type, $address_field); |
|
29 | 29 | |
30 | 30 | // Prepare variables. |
31 | - if ( ! empty( $form->invoice ) ) { |
|
31 | + if (!empty($form->invoice)) { |
|
32 | 32 | $user_id = $form->invoice->get_user_id(); |
33 | 33 | } |
34 | 34 | |
35 | - if ( empty( $user_id ) && is_user_logged_in() ) { |
|
35 | + if (empty($user_id) && is_user_logged_in()) { |
|
36 | 36 | $user_id = get_current_user_id(); |
37 | 37 | } |
38 | 38 | |
39 | 39 | $field_name = $address_field['name']; |
40 | 40 | $field_name = "{$field_type}[$field_name]"; |
41 | - $wrap_class = getpaid_get_form_element_grid_class( $address_field ); |
|
42 | - $wrap_class = esc_attr( "$wrap_class getpaid-address-field-wrapper" ); |
|
43 | - $placeholder = empty( $address_field['placeholder'] ) ? '' : esc_attr( $address_field['placeholder'] ); |
|
44 | - $description = empty( $address_field['description'] ) ? '' : wp_kses_post( $address_field['description'] ); |
|
45 | - $value = ! empty( $user_id ) ? get_user_meta( $user_id, '_' . $address_field['name'], true ) : ''; |
|
46 | - $label = empty( $address_field['label'] ) ? '' : wp_kses_post( $address_field['label'] ); |
|
47 | - |
|
48 | - if ( ! empty( $address_field['required'] ) ) { |
|
41 | + $wrap_class = getpaid_get_form_element_grid_class($address_field); |
|
42 | + $wrap_class = esc_attr("$wrap_class getpaid-address-field-wrapper"); |
|
43 | + $placeholder = empty($address_field['placeholder']) ? '' : esc_attr($address_field['placeholder']); |
|
44 | + $description = empty($address_field['description']) ? '' : wp_kses_post($address_field['description']); |
|
45 | + $value = !empty($user_id) ? get_user_meta($user_id, '_' . $address_field['name'], true) : ''; |
|
46 | + $label = empty($address_field['label']) ? '' : wp_kses_post($address_field['label']); |
|
47 | + |
|
48 | + if (!empty($address_field['required'])) { |
|
49 | 49 | $label .= "<span class='text-danger'> *</span>"; |
50 | 50 | } |
51 | 51 | |
52 | 52 | // Display the country. |
53 | - if ( 'wpinv_country' == $address_field['name'] ) { |
|
53 | + if ('wpinv_country' == $address_field['name']) { |
|
54 | 54 | |
55 | 55 | echo "<div class='form-group $wrap_class getpaid-address-field-wrapper__country'"; |
56 | 56 | |
57 | 57 | echo aui()->select( |
58 | 58 | array( |
59 | 59 | 'options' => wpinv_get_country_list(), |
60 | - 'name' => esc_attr( $field_name ), |
|
61 | - 'id' => sanitize_html_class( $field_name ) . $uniqid, |
|
62 | - 'value' => sanitize_text_field( $country ), |
|
60 | + 'name' => esc_attr($field_name), |
|
61 | + 'id' => sanitize_html_class($field_name) . $uniqid, |
|
62 | + 'value' => sanitize_text_field($country), |
|
63 | 63 | 'placeholder' => $placeholder, |
64 | - 'required' => ! empty( $address_field['required'] ), |
|
65 | - 'label' => wp_kses_post( $label ), |
|
64 | + 'required' => !empty($address_field['required']), |
|
65 | + 'label' => wp_kses_post($label), |
|
66 | 66 | 'label_type' => 'vertical', |
67 | 67 | 'help_text' => $description, |
68 | 68 | 'class' => 'getpaid-address-field wpinv_country', |
@@ -75,7 +75,7 @@ discard block |
||
75 | 75 | ) |
76 | 76 | ); |
77 | 77 | |
78 | - if ( wpinv_should_validate_vat_number() ) { |
|
78 | + if (wpinv_should_validate_vat_number()) { |
|
79 | 79 | |
80 | 80 | echo aui()->input( |
81 | 81 | array( |
@@ -84,7 +84,7 @@ discard block |
||
84 | 84 | 'id' => "shipping-toggle$uniqid", |
85 | 85 | 'wrap_class' => "getpaid-address-field-wrapper__address-confirm mt-1 d-none", |
86 | 86 | 'required' => false, |
87 | - 'label' => __( 'I certify that I live in the country selected above', 'invoicing' ) . "<span class='text-danger'> *</span>", |
|
87 | + 'label' => __('I certify that I live in the country selected above', 'invoicing') . "<span class='text-danger'> *</span>", |
|
88 | 88 | 'value' => 1, |
89 | 89 | 'checked' => true, |
90 | 90 | ) |
@@ -97,27 +97,27 @@ discard block |
||
97 | 97 | } |
98 | 98 | |
99 | 99 | // Display the state. |
100 | - else if ( 'wpinv_state' == $address_field['name'] ) { |
|
100 | + else if ('wpinv_state' == $address_field['name']) { |
|
101 | 101 | |
102 | - if ( empty( $value ) ) { |
|
102 | + if (empty($value)) { |
|
103 | 103 | $value = wpinv_get_default_state(); |
104 | 104 | } |
105 | 105 | |
106 | - echo getpaid_get_states_select_markup ( |
|
106 | + echo getpaid_get_states_select_markup( |
|
107 | 107 | $country, |
108 | 108 | $value, |
109 | 109 | $placeholder, |
110 | 110 | $label, |
111 | 111 | $description, |
112 | - ! empty( $address_field['required'] ), |
|
112 | + !empty($address_field['required']), |
|
113 | 113 | $wrap_class, |
114 | 114 | $field_name |
115 | 115 | ); |
116 | 116 | |
117 | 117 | } else { |
118 | 118 | |
119 | - $key = str_replace( 'wpinv_', '', $address_field['name'] ); |
|
120 | - $key = esc_attr( str_replace( '_', '-', $key ) ); |
|
119 | + $key = str_replace('wpinv_', '', $address_field['name']); |
|
120 | + $key = esc_attr(str_replace('_', '-', $key)); |
|
121 | 121 | $autocomplete = ''; |
122 | 122 | $replacements = array( |
123 | 123 | 'zip' => 'postal-code', |
@@ -130,33 +130,33 @@ discard block |
||
130 | 130 | ); |
131 | 131 | |
132 | 132 | |
133 | - if ( isset( $replacements[ $key ] ) ) { |
|
133 | + if (isset($replacements[$key])) { |
|
134 | 134 | $autocomplete = array( |
135 | - 'autocomplete' => "$field_type {$replacements[ $key ]}", |
|
135 | + 'autocomplete' => "$field_type {$replacements[$key]}", |
|
136 | 136 | ); |
137 | 137 | } |
138 | 138 | |
139 | 139 | $append = ''; |
140 | 140 | |
141 | - if ( 'billing' === $field_type && wpinv_should_validate_vat_number() && 'vat-number' === $key ) { |
|
142 | - $valid = esc_attr__( 'Valid', 'invoicing' ); |
|
143 | - $invalid = esc_attr__( 'Invalid', 'invoicing' ); |
|
144 | - $validate = esc_attr__( 'Validate', 'invoicing' ); |
|
141 | + if ('billing' === $field_type && wpinv_should_validate_vat_number() && 'vat-number' === $key) { |
|
142 | + $valid = esc_attr__('Valid', 'invoicing'); |
|
143 | + $invalid = esc_attr__('Invalid', 'invoicing'); |
|
144 | + $validate = esc_attr__('Validate', 'invoicing'); |
|
145 | 145 | $append = "<span class='btn btn-secondary getpaid-vat-number-validate' data-valid='$valid' data-invalid='$invalid' data-validate='$validate'>$validate</span>"; |
146 | 146 | } |
147 | 147 | |
148 | 148 | echo aui()->input( |
149 | 149 | array( |
150 | - 'name' => esc_attr( $field_name ), |
|
151 | - 'id' => sanitize_html_class( $field_name ) . $uniqid, |
|
152 | - 'required' => ! empty( $address_field['required'] ), |
|
150 | + 'name' => esc_attr($field_name), |
|
151 | + 'id' => sanitize_html_class($field_name) . $uniqid, |
|
152 | + 'required' => !empty($address_field['required']), |
|
153 | 153 | 'placeholder' => $placeholder, |
154 | - 'label' => wp_kses_post( $label ), |
|
154 | + 'label' => wp_kses_post($label), |
|
155 | 155 | 'label_type' => 'vertical', |
156 | 156 | 'help_text' => $description, |
157 | 157 | 'type' => 'text', |
158 | - 'value' => sanitize_text_field( $value ), |
|
159 | - 'class' => 'getpaid-address-field ' . esc_attr( $address_field['name'] ), |
|
158 | + 'value' => sanitize_text_field($value), |
|
159 | + 'class' => 'getpaid-address-field ' . esc_attr($address_field['name']), |
|
160 | 160 | 'wrap_class' => "$wrap_class getpaid-address-field-wrapper__$key", |
161 | 161 | 'label_class' => 'getpaid-address-field-label getpaid-address-field-label__' . $key, |
162 | 162 | 'extra_attributes' => $autocomplete, |
@@ -166,7 +166,7 @@ discard block |
||
166 | 166 | |
167 | 167 | } |
168 | 168 | |
169 | - do_action( 'getpaid_payment_form_address_field_after_' . $address_field['name'], $field_type, $address_field ); |
|
169 | + do_action('getpaid_payment_form_address_field_after_' . $address_field['name'], $field_type, $address_field); |
|
170 | 170 | } |
171 | 171 | |
172 | 172 | echo "</div>"; |
@@ -8,197 +8,197 @@ discard block |
||
8 | 8 | * @version 1.0.19 |
9 | 9 | */ |
10 | 10 | |
11 | -defined( 'ABSPATH' ) || exit; |
|
11 | +defined('ABSPATH') || exit; |
|
12 | 12 | |
13 | -$pages = wpinv_get_pages( true ); |
|
13 | +$pages = wpinv_get_pages(true); |
|
14 | 14 | |
15 | 15 | $currencies = wpinv_get_currencies(); |
16 | 16 | |
17 | 17 | $currency_code_options = array(); |
18 | -foreach ( $currencies as $code => $name ) { |
|
19 | - $currency_code_options[ $code ] = $code . ' - ' . $name . ' (' . wpinv_currency_symbol( $code ) . ')'; |
|
18 | +foreach ($currencies as $code => $name) { |
|
19 | + $currency_code_options[$code] = $code . ' - ' . $name . ' (' . wpinv_currency_symbol($code) . ')'; |
|
20 | 20 | } |
21 | 21 | |
22 | 22 | $due_payment_options = array(); |
23 | -$due_payment_options[0] = __( 'Now', 'invoicing' ); |
|
24 | -for ( $i = 1; $i <= 30; $i++ ) { |
|
23 | +$due_payment_options[0] = __('Now', 'invoicing'); |
|
24 | +for ($i = 1; $i <= 30; $i++) { |
|
25 | 25 | $due_payment_options[$i] = $i; |
26 | 26 | } |
27 | 27 | |
28 | 28 | $invoice_number_padd_options = array(); |
29 | -for ( $i = 0; $i <= 20; $i++ ) { |
|
29 | +for ($i = 0; $i <= 20; $i++) { |
|
30 | 30 | $invoice_number_padd_options[$i] = $i; |
31 | 31 | } |
32 | 32 | |
33 | 33 | $currency_symbol = wpinv_currency_symbol(); |
34 | 34 | |
35 | 35 | $last_number = $reset_number = ''; |
36 | -if ( $last_invoice_number = get_option( 'wpinv_last_invoice_number' ) ) { |
|
37 | - $last_invoice_number = preg_replace( '/[^0-9]/', '', $last_invoice_number ); |
|
36 | +if ($last_invoice_number = get_option('wpinv_last_invoice_number')) { |
|
37 | + $last_invoice_number = preg_replace('/[^0-9]/', '', $last_invoice_number); |
|
38 | 38 | |
39 | - if ( !empty( $last_invoice_number ) ) { |
|
40 | - $last_number = ' ' . wp_sprintf( __( "( Last Invoice's sequential number: <b>%s</b> )", 'invoicing' ), $last_invoice_number ); |
|
39 | + if (!empty($last_invoice_number)) { |
|
40 | + $last_number = ' ' . wp_sprintf(__("( Last Invoice's sequential number: <b>%s</b> )", 'invoicing'), $last_invoice_number); |
|
41 | 41 | } |
42 | 42 | |
43 | 43 | $nonce = wp_create_nonce('reset_invoice_count'); |
44 | - $reset_number = '<a href="'.add_query_arg(array('reset_invoice_count' => 1, '_nonce' => $nonce)).'" class="btn button">'.__('Force Reset Sequence', 'invoicing' ). '</a>'; |
|
44 | + $reset_number = '<a href="' . add_query_arg(array('reset_invoice_count' => 1, '_nonce' => $nonce)) . '" class="btn button">' . __('Force Reset Sequence', 'invoicing') . '</a>'; |
|
45 | 45 | } |
46 | 46 | |
47 | 47 | $alert_wrapper_start = '<p style="color: #F00">'; |
48 | 48 | $alert_wrapper_close = '</p>'; |
49 | 49 | |
50 | 50 | return array( |
51 | - 'general' => apply_filters( 'wpinv_settings_general', |
|
51 | + 'general' => apply_filters('wpinv_settings_general', |
|
52 | 52 | array( |
53 | 53 | 'main' => array( |
54 | 54 | 'location_settings' => array( |
55 | 55 | 'id' => 'location_settings', |
56 | - 'name' => '<h3>' . __( 'Default Location', 'invoicing' ) . '</h3>', |
|
56 | + 'name' => '<h3>' . __('Default Location', 'invoicing') . '</h3>', |
|
57 | 57 | 'desc' => '', |
58 | 58 | 'type' => 'header', |
59 | 59 | ), |
60 | 60 | 'default_country' => array( |
61 | 61 | 'id' => 'default_country', |
62 | - 'name' => __( 'Default Country', 'invoicing' ), |
|
63 | - 'desc' => __( 'Where does your store operate from?', 'invoicing' ), |
|
62 | + 'name' => __('Default Country', 'invoicing'), |
|
63 | + 'desc' => __('Where does your store operate from?', 'invoicing'), |
|
64 | 64 | 'type' => 'select', |
65 | 65 | 'options' => wpinv_get_country_list(), |
66 | 66 | 'std' => 'GB', |
67 | 67 | 'class' => 'wpi_select2', |
68 | - 'placeholder' => __( 'Select a country', 'invoicing' ), |
|
68 | + 'placeholder' => __('Select a country', 'invoicing'), |
|
69 | 69 | ), |
70 | 70 | 'default_state' => array( |
71 | 71 | 'id' => 'default_state', |
72 | - 'name' => __( 'Default State / Province', 'invoicing' ), |
|
73 | - 'desc' => __( 'What state / province does your store operate from?', 'invoicing' ), |
|
72 | + 'name' => __('Default State / Province', 'invoicing'), |
|
73 | + 'desc' => __('What state / province does your store operate from?', 'invoicing'), |
|
74 | 74 | 'type' => 'country_states', |
75 | 75 | 'class' => 'wpi_select2', |
76 | - 'placeholder' => __( 'Select a state', 'invoicing' ), |
|
76 | + 'placeholder' => __('Select a state', 'invoicing'), |
|
77 | 77 | ), |
78 | 78 | 'store_name' => array( |
79 | 79 | 'id' => 'store_name', |
80 | - 'name' => __( 'Store Name', 'invoicing' ), |
|
81 | - 'desc' => __( 'Store name to print on invoices.', 'invoicing' ), |
|
80 | + 'name' => __('Store Name', 'invoicing'), |
|
81 | + 'desc' => __('Store name to print on invoices.', 'invoicing'), |
|
82 | 82 | 'std' => get_option('blogname'), |
83 | 83 | 'type' => 'text', |
84 | 84 | ), |
85 | 85 | 'logo' => array( |
86 | 86 | 'id' => 'logo', |
87 | - 'name' => __( 'Logo URL', 'invoicing' ), |
|
88 | - 'desc' => __( 'Store logo to print on invoices.', 'invoicing' ), |
|
87 | + 'name' => __('Logo URL', 'invoicing'), |
|
88 | + 'desc' => __('Store logo to print on invoices.', 'invoicing'), |
|
89 | 89 | 'type' => 'text', |
90 | 90 | ), |
91 | 91 | 'store_address' => array( |
92 | 92 | 'id' => 'store_address', |
93 | - 'name' => __( 'Store Address', 'invoicing' ), |
|
94 | - 'desc' => __( 'Enter the store address to display on invoice', 'invoicing' ), |
|
93 | + 'name' => __('Store Address', 'invoicing'), |
|
94 | + 'desc' => __('Enter the store address to display on invoice', 'invoicing'), |
|
95 | 95 | 'type' => 'textarea', |
96 | 96 | ), |
97 | 97 | 'page_settings' => array( |
98 | 98 | 'id' => 'page_settings', |
99 | - 'name' => '<h3>' . __( 'Page Settings', 'invoicing' ) . '</h3>', |
|
99 | + 'name' => '<h3>' . __('Page Settings', 'invoicing') . '</h3>', |
|
100 | 100 | 'desc' => '', |
101 | 101 | 'type' => 'header', |
102 | 102 | ), |
103 | 103 | 'checkout_page' => array( |
104 | 104 | 'id' => 'checkout_page', |
105 | - 'name' => __( 'Checkout Page', 'invoicing' ), |
|
106 | - 'desc' => __( 'This is the checkout page where buyers will complete their payments. The <b>[wpinv_checkout]</b> short code must be on this page.', 'invoicing' ), |
|
105 | + 'name' => __('Checkout Page', 'invoicing'), |
|
106 | + 'desc' => __('This is the checkout page where buyers will complete their payments. The <b>[wpinv_checkout]</b> short code must be on this page.', 'invoicing'), |
|
107 | 107 | 'type' => 'select', |
108 | 108 | 'options' => $pages, |
109 | 109 | 'class' => 'wpi_select2', |
110 | - 'placeholder' => __( 'Select a page', 'invoicing' ), |
|
110 | + 'placeholder' => __('Select a page', 'invoicing'), |
|
111 | 111 | 'help-tip' => true, |
112 | 112 | ), |
113 | 113 | 'success_page' => array( |
114 | 114 | 'id' => 'success_page', |
115 | - 'name' => __( 'Success Page', 'invoicing' ), |
|
116 | - 'desc' => __( 'This is the page buyers are sent to after completing their payments. The <b>[wpinv_receipt]</b> short code should be on this page.', 'invoicing' ), |
|
115 | + 'name' => __('Success Page', 'invoicing'), |
|
116 | + 'desc' => __('This is the page buyers are sent to after completing their payments. The <b>[wpinv_receipt]</b> short code should be on this page.', 'invoicing'), |
|
117 | 117 | 'type' => 'select', |
118 | 118 | 'options' => $pages, |
119 | 119 | 'class' => 'wpi_select2', |
120 | - 'placeholder' => __( 'Select a page', 'invoicing' ), |
|
120 | + 'placeholder' => __('Select a page', 'invoicing'), |
|
121 | 121 | 'help-tip' => true, |
122 | 122 | ), |
123 | 123 | 'failure_page' => array( |
124 | 124 | 'id' => 'failure_page', |
125 | - 'name' => __( 'Failed Transaction Page', 'invoicing' ), |
|
126 | - 'desc' => __( 'This is the page buyers are sent to if their transaction is cancelled or fails.', 'invoicing' ), |
|
125 | + 'name' => __('Failed Transaction Page', 'invoicing'), |
|
126 | + 'desc' => __('This is the page buyers are sent to if their transaction is cancelled or fails.', 'invoicing'), |
|
127 | 127 | 'type' => 'select', |
128 | 128 | 'options' => $pages, |
129 | 129 | 'class' => 'wpi_select2', |
130 | - 'placeholder' => __( 'Select a page', 'invoicing' ), |
|
130 | + 'placeholder' => __('Select a page', 'invoicing'), |
|
131 | 131 | 'help-tip' => true, |
132 | 132 | ), |
133 | 133 | 'invoice_history_page' => array( |
134 | 134 | 'id' => 'invoice_history_page', |
135 | - 'name' => __( 'Invoice History Page', 'invoicing' ), |
|
136 | - 'desc' => __( 'This page shows an invoice history for the current user. The <b>[wpinv_history]</b> short code should be on this page.', 'invoicing' ), |
|
135 | + 'name' => __('Invoice History Page', 'invoicing'), |
|
136 | + 'desc' => __('This page shows an invoice history for the current user. The <b>[wpinv_history]</b> short code should be on this page.', 'invoicing'), |
|
137 | 137 | 'type' => 'select', |
138 | 138 | 'options' => $pages, |
139 | 139 | 'class' => 'wpi_select2', |
140 | - 'placeholder' => __( 'Select a page', 'invoicing' ), |
|
140 | + 'placeholder' => __('Select a page', 'invoicing'), |
|
141 | 141 | 'help-tip' => true, |
142 | 142 | ), |
143 | 143 | 'invoice_subscription_page' => array( |
144 | 144 | 'id' => 'invoice_subscription_page', |
145 | - 'name' => __( 'Invoice Subscriptions Page', 'invoicing' ), |
|
146 | - 'desc' => __( 'This page shows subscriptions history for the current user. The <b>[wpinv_subscriptions]</b> short code should be on this page.', 'invoicing' ), |
|
145 | + 'name' => __('Invoice Subscriptions Page', 'invoicing'), |
|
146 | + 'desc' => __('This page shows subscriptions history for the current user. The <b>[wpinv_subscriptions]</b> short code should be on this page.', 'invoicing'), |
|
147 | 147 | 'type' => 'select', |
148 | 148 | 'options' => $pages, |
149 | 149 | 'class' => 'wpi_select2', |
150 | - 'placeholder' => __( 'Select a page', 'invoicing' ), |
|
150 | + 'placeholder' => __('Select a page', 'invoicing'), |
|
151 | 151 | 'help-tip' => true, |
152 | 152 | ), |
153 | 153 | ), |
154 | 154 | 'currency_section' => array( |
155 | 155 | 'currency_settings' => array( |
156 | 156 | 'id' => 'currency_settings', |
157 | - 'name' => '<h3>' . __( 'Currency Settings', 'invoicing' ) . '</h3>', |
|
157 | + 'name' => '<h3>' . __('Currency Settings', 'invoicing') . '</h3>', |
|
158 | 158 | 'desc' => '', |
159 | 159 | 'type' => 'header', |
160 | 160 | ), |
161 | 161 | 'currency' => array( |
162 | 162 | 'id' => 'currency', |
163 | - 'name' => __( 'Currency', 'invoicing' ), |
|
164 | - 'desc' => __( 'Choose your currency. Note that some payment gateways have currency restrictions.', 'invoicing' ), |
|
163 | + 'name' => __('Currency', 'invoicing'), |
|
164 | + 'desc' => __('Choose your currency. Note that some payment gateways have currency restrictions.', 'invoicing'), |
|
165 | 165 | 'type' => 'select', |
166 | 166 | 'class' => 'wpi_select2', |
167 | 167 | 'options' => $currency_code_options, |
168 | 168 | ), |
169 | 169 | 'currency_position' => array( |
170 | 170 | 'id' => 'currency_position', |
171 | - 'name' => __( 'Currency Position', 'invoicing' ), |
|
172 | - 'desc' => __( 'Choose the location of the currency sign.', 'invoicing' ), |
|
171 | + 'name' => __('Currency Position', 'invoicing'), |
|
172 | + 'desc' => __('Choose the location of the currency sign.', 'invoicing'), |
|
173 | 173 | 'type' => 'select', |
174 | 174 | 'class' => 'wpi_select2', |
175 | 175 | 'options' => array( |
176 | - 'left' => __( 'Left', 'invoicing' ) . ' (' . $currency_symbol . wpinv_format_amount( '99.99' ) . ')', |
|
177 | - 'right' => __( 'Right', 'invoicing' ) . ' ('. wpinv_format_amount( '99.99' ) . $currency_symbol . ')', |
|
178 | - 'left_space' => __( 'Left with space', 'invoicing' ) . ' (' . $currency_symbol . ' ' . wpinv_format_amount( '99.99' ) . ')', |
|
179 | - 'right_space' => __( 'Right with space', 'invoicing' ) . ' (' . wpinv_format_amount( '99.99' ) . ' ' . $currency_symbol . ')' |
|
176 | + 'left' => __('Left', 'invoicing') . ' (' . $currency_symbol . wpinv_format_amount('99.99') . ')', |
|
177 | + 'right' => __('Right', 'invoicing') . ' (' . wpinv_format_amount('99.99') . $currency_symbol . ')', |
|
178 | + 'left_space' => __('Left with space', 'invoicing') . ' (' . $currency_symbol . ' ' . wpinv_format_amount('99.99') . ')', |
|
179 | + 'right_space' => __('Right with space', 'invoicing') . ' (' . wpinv_format_amount('99.99') . ' ' . $currency_symbol . ')' |
|
180 | 180 | ) |
181 | 181 | ), |
182 | 182 | 'thousands_separator' => array( |
183 | 183 | 'id' => 'thousands_separator', |
184 | - 'name' => __( 'Thousands Separator', 'invoicing' ), |
|
185 | - 'desc' => __( 'The symbol (usually , or .) to separate thousands', 'invoicing' ), |
|
184 | + 'name' => __('Thousands Separator', 'invoicing'), |
|
185 | + 'desc' => __('The symbol (usually , or .) to separate thousands', 'invoicing'), |
|
186 | 186 | 'type' => 'text', |
187 | 187 | 'size' => 'small', |
188 | 188 | 'std' => ',', |
189 | 189 | ), |
190 | 190 | 'decimal_separator' => array( |
191 | 191 | 'id' => 'decimal_separator', |
192 | - 'name' => __( 'Decimal Separator', 'invoicing' ), |
|
193 | - 'desc' => __( 'The symbol (usually , or .) to separate decimal points', 'invoicing' ), |
|
192 | + 'name' => __('Decimal Separator', 'invoicing'), |
|
193 | + 'desc' => __('The symbol (usually , or .) to separate decimal points', 'invoicing'), |
|
194 | 194 | 'type' => 'text', |
195 | 195 | 'size' => 'small', |
196 | 196 | 'std' => '.', |
197 | 197 | ), |
198 | 198 | 'decimals' => array( |
199 | 199 | 'id' => 'decimals', |
200 | - 'name' => __( 'Number of Decimals', 'invoicing' ), |
|
201 | - 'desc' => __( 'This sets the number of decimal points shown in displayed prices.', 'invoicing' ), |
|
200 | + 'name' => __('Number of Decimals', 'invoicing'), |
|
201 | + 'desc' => __('This sets the number of decimal points shown in displayed prices.', 'invoicing'), |
|
202 | 202 | 'type' => 'number', |
203 | 203 | 'size' => 'small', |
204 | 204 | 'std' => '2', |
@@ -210,21 +210,21 @@ discard block |
||
210 | 210 | 'labels' => array( |
211 | 211 | 'labels' => array( |
212 | 212 | 'id' => 'labels_settings', |
213 | - 'name' => '<h3>' . __( 'Invoice Labels', 'invoicing' ) . '</h3>', |
|
213 | + 'name' => '<h3>' . __('Invoice Labels', 'invoicing') . '</h3>', |
|
214 | 214 | 'desc' => '', |
215 | 215 | 'type' => 'header', |
216 | 216 | ), |
217 | 217 | 'vat_invoice_notice_label' => array( |
218 | 218 | 'id' => 'vat_invoice_notice_label', |
219 | - 'name' => __( 'Invoice Notice Label', 'invoicing' ), |
|
220 | - 'desc' => __( 'Use this to add an invoice notice section (label) to your invoices', 'invoicing' ), |
|
219 | + 'name' => __('Invoice Notice Label', 'invoicing'), |
|
220 | + 'desc' => __('Use this to add an invoice notice section (label) to your invoices', 'invoicing'), |
|
221 | 221 | 'type' => 'text', |
222 | 222 | 'size' => 'regular', |
223 | 223 | ), |
224 | 224 | 'vat_invoice_notice' => array( |
225 | 225 | 'id' => 'vat_invoice_notice', |
226 | - 'name' => __( 'Invoice notice', 'invoicing' ), |
|
227 | - 'desc' => __( 'Use this to add an invoice notice section (description) to your invoices', 'invoicing' ), |
|
226 | + 'name' => __('Invoice notice', 'invoicing'), |
|
227 | + 'desc' => __('Use this to add an invoice notice section (description) to your invoices', 'invoicing'), |
|
228 | 228 | 'type' => 'text', |
229 | 229 | 'size' => 'regular', |
230 | 230 | ), |
@@ -236,22 +236,22 @@ discard block |
||
236 | 236 | 'main' => array( |
237 | 237 | 'gateway_settings' => array( |
238 | 238 | 'id' => 'api_header', |
239 | - 'name' => '<h3>' . __( 'Gateway Settings', 'invoicing' ) . '</h3>', |
|
239 | + 'name' => '<h3>' . __('Gateway Settings', 'invoicing') . '</h3>', |
|
240 | 240 | 'desc' => '', |
241 | 241 | 'type' => 'header', |
242 | 242 | ), |
243 | 243 | 'gateways' => array( |
244 | 244 | 'id' => 'gateways', |
245 | - 'name' => __( 'Payment Gateways', 'invoicing' ), |
|
246 | - 'desc' => __( 'Choose the payment gateways you want to enable.', 'invoicing' ), |
|
245 | + 'name' => __('Payment Gateways', 'invoicing'), |
|
246 | + 'desc' => __('Choose the payment gateways you want to enable.', 'invoicing'), |
|
247 | 247 | 'type' => 'gateways', |
248 | 248 | 'std' => array('manual'=>1), |
249 | 249 | 'options' => wpinv_get_payment_gateways(), |
250 | 250 | ), |
251 | 251 | 'default_gateway' => array( |
252 | 252 | 'id' => 'default_gateway', |
253 | - 'name' => __( 'Default Gateway', 'invoicing' ), |
|
254 | - 'desc' => __( 'This gateway will be loaded automatically with the checkout page.', 'invoicing' ), |
|
253 | + 'name' => __('Default Gateway', 'invoicing'), |
|
254 | + 'desc' => __('This gateway will be loaded automatically with the checkout page.', 'invoicing'), |
|
255 | 255 | 'type' => 'gateway_select', |
256 | 256 | 'std' => 'manual', |
257 | 257 | 'class' => 'wpi_select2', |
@@ -266,32 +266,32 @@ discard block |
||
266 | 266 | 'main' => array( |
267 | 267 | 'tax_settings' => array( |
268 | 268 | 'id' => 'tax_settings', |
269 | - 'name' => '<h3>' . __( 'Tax Settings', 'invoicing' ) . '</h3>', |
|
269 | + 'name' => '<h3>' . __('Tax Settings', 'invoicing') . '</h3>', |
|
270 | 270 | 'type' => 'header', |
271 | 271 | ), |
272 | 272 | |
273 | 273 | 'enable_taxes' => array( |
274 | 274 | 'id' => 'enable_taxes', |
275 | - 'name' => __( 'Enable Taxes', 'invoicing' ), |
|
276 | - 'desc' => __( 'Enable tax rates and calculations.', 'invoicing' ), |
|
275 | + 'name' => __('Enable Taxes', 'invoicing'), |
|
276 | + 'desc' => __('Enable tax rates and calculations.', 'invoicing'), |
|
277 | 277 | 'type' => 'checkbox', |
278 | 278 | 'std' => 0, |
279 | 279 | ), |
280 | 280 | |
281 | 281 | 'tax_subtotal_rounding' => array( |
282 | 282 | 'id' => 'tax_subtotal_rounding', |
283 | - 'name' => __( 'Rounding', 'invoicing' ), |
|
284 | - 'desc' => __( 'Round tax at subtotal level, instead of rounding per tax rate', 'invoicing' ), |
|
283 | + 'name' => __('Rounding', 'invoicing'), |
|
284 | + 'desc' => __('Round tax at subtotal level, instead of rounding per tax rate', 'invoicing'), |
|
285 | 285 | 'type' => 'checkbox', |
286 | 286 | 'std' => 1, |
287 | 287 | ), |
288 | 288 | |
289 | 289 | 'prices_include_tax' => array( |
290 | 290 | 'id' => 'prices_include_tax', |
291 | - 'name' => __( 'Prices entered with tax', 'invoicing' ), |
|
291 | + 'name' => __('Prices entered with tax', 'invoicing'), |
|
292 | 292 | 'options' => array( |
293 | - 'yes' => __( 'Yes, I will enter prices inclusive of tax', 'invoicing' ), |
|
294 | - 'no' => __( 'No, I will enter prices exclusive of tax', 'invoicing' ), |
|
293 | + 'yes' => __('Yes, I will enter prices inclusive of tax', 'invoicing'), |
|
294 | + 'no' => __('No, I will enter prices exclusive of tax', 'invoicing'), |
|
295 | 295 | ), |
296 | 296 | 'type' => 'select', |
297 | 297 | 'std' => 'no', |
@@ -299,10 +299,10 @@ discard block |
||
299 | 299 | |
300 | 300 | 'tax_base' => array( |
301 | 301 | 'id' => 'tax_base', |
302 | - 'name' => __( 'Calculate tax based on', 'invoicing' ), |
|
302 | + 'name' => __('Calculate tax based on', 'invoicing'), |
|
303 | 303 | 'options' => array( |
304 | - 'billing' => __( 'Customer billing address', 'invoicing' ), |
|
305 | - 'base' => __( 'Shop base address', 'invoicing' ), |
|
304 | + 'billing' => __('Customer billing address', 'invoicing'), |
|
305 | + 'base' => __('Shop base address', 'invoicing'), |
|
306 | 306 | ), |
307 | 307 | 'type' => 'select', |
308 | 308 | 'std' => 'billing', |
@@ -310,10 +310,10 @@ discard block |
||
310 | 310 | |
311 | 311 | 'tax_display_totals' => array( |
312 | 312 | 'id' => 'tax_display_totals', |
313 | - 'name' => __( 'Display tax totals', 'invoicing' ), |
|
313 | + 'name' => __('Display tax totals', 'invoicing'), |
|
314 | 314 | 'options' => array( |
315 | - 'single' => __( 'As a single total', 'invoicing' ), |
|
316 | - 'individual' => __( 'As individual tax rates', 'invoicing' ), |
|
315 | + 'single' => __('As a single total', 'invoicing'), |
|
316 | + 'individual' => __('As individual tax rates', 'invoicing'), |
|
317 | 317 | ), |
318 | 318 | 'type' => 'select', |
319 | 319 | 'std' => 'individual', |
@@ -321,8 +321,8 @@ discard block |
||
321 | 321 | |
322 | 322 | 'tax_rate' => array( |
323 | 323 | 'id' => 'tax_rate', |
324 | - 'name' => __( 'Fallback Tax Rate', 'invoicing' ), |
|
325 | - 'desc' => __( 'Enter a percentage, such as 6.5. Customers not in a specific rate will be charged this rate.', 'invoicing' ), |
|
324 | + 'name' => __('Fallback Tax Rate', 'invoicing'), |
|
325 | + 'desc' => __('Enter a percentage, such as 6.5. Customers not in a specific rate will be charged this rate.', 'invoicing'), |
|
326 | 326 | 'type' => 'number', |
327 | 327 | 'size' => 'small', |
328 | 328 | 'min' => '0', |
@@ -334,8 +334,8 @@ discard block |
||
334 | 334 | 'rates' => array( |
335 | 335 | 'tax_rates' => array( |
336 | 336 | 'id' => 'tax_rates', |
337 | - 'name' => '<h3>' . __( 'Tax Rates', 'invoicing' ) . '</h3>', |
|
338 | - 'desc' => __( 'Enter tax rates for specific regions.', 'invoicing' ), |
|
337 | + 'name' => '<h3>' . __('Tax Rates', 'invoicing') . '</h3>', |
|
338 | + 'desc' => __('Enter tax rates for specific regions.', 'invoicing'), |
|
339 | 339 | 'type' => 'tax_rates', |
340 | 340 | ), |
341 | 341 | ), |
@@ -344,45 +344,45 @@ discard block |
||
344 | 344 | |
345 | 345 | 'vat_company_name' => array( |
346 | 346 | 'id' => 'vat_company_name', |
347 | - 'name' => __( 'Company Name', 'invoicing' ), |
|
348 | - 'desc' => wp_sprintf(__( 'Verify your company name and VAT number on the %sEU VIES System.%s', 'invoicing' ), '<a href="http://ec.europa.eu/taxation_customs/vies/" target="_blank">', '</a>' ), |
|
347 | + 'name' => __('Company Name', 'invoicing'), |
|
348 | + 'desc' => wp_sprintf(__('Verify your company name and VAT number on the %sEU VIES System.%s', 'invoicing'), '<a href="http://ec.europa.eu/taxation_customs/vies/" target="_blank">', '</a>'), |
|
349 | 349 | 'type' => 'text', |
350 | 350 | 'size' => 'regular', |
351 | 351 | ), |
352 | 352 | |
353 | 353 | 'vat_number' => array( |
354 | 354 | 'id' => 'vat_number', |
355 | - 'name' => __( 'VAT Number', 'invoicing' ), |
|
356 | - 'desc' => __( 'Enter your VAT number including the country identifier, eg: GB123456789', 'invoicing' ), |
|
355 | + 'name' => __('VAT Number', 'invoicing'), |
|
356 | + 'desc' => __('Enter your VAT number including the country identifier, eg: GB123456789', 'invoicing'), |
|
357 | 357 | 'type' => 'text', |
358 | 358 | 'size' => 'regular', |
359 | 359 | ), |
360 | 360 | |
361 | 361 | 'vat_prevent_b2c_purchase' => array( |
362 | 362 | 'id' => 'vat_prevent_b2c_purchase', |
363 | - 'name' => __( 'Prevent B2C Sales', 'invoicing' ), |
|
364 | - 'desc' => __( 'Require everyone in the EU to provide a VAT number.', 'invoicing' ), |
|
363 | + 'name' => __('Prevent B2C Sales', 'invoicing'), |
|
364 | + 'desc' => __('Require everyone in the EU to provide a VAT number.', 'invoicing'), |
|
365 | 365 | 'type' => 'checkbox' |
366 | 366 | ), |
367 | 367 | |
368 | 368 | 'validate_vat_number' => array( |
369 | 369 | 'id' => 'validate_vat_number', |
370 | - 'name' => __( 'Validate VAT Number', 'invoicing' ), |
|
371 | - 'desc' => __( 'Validate VAT numbers with VIES.', 'invoicing' ), |
|
370 | + 'name' => __('Validate VAT Number', 'invoicing'), |
|
371 | + 'desc' => __('Validate VAT numbers with VIES.', 'invoicing'), |
|
372 | 372 | 'type' => 'checkbox' |
373 | 373 | ), |
374 | 374 | |
375 | 375 | 'vat_same_country_rule' => array( |
376 | 376 | 'id' => 'vat_same_country_rule', |
377 | - 'name' => __( 'Same Country Rule', 'invoicing' ), |
|
378 | - 'desc' => __( 'What should happen if a customer is from the same country as your business?', 'invoicing' ), |
|
377 | + 'name' => __('Same Country Rule', 'invoicing'), |
|
378 | + 'desc' => __('What should happen if a customer is from the same country as your business?', 'invoicing'), |
|
379 | 379 | 'type' => 'select', |
380 | 380 | 'options' => array( |
381 | - 'no' => __( 'Do not charge Tax', 'invoicing' ), |
|
382 | - 'always' => __( 'Charge Tax', 'invoicing' ), |
|
383 | - 'vat_too' => __( 'Charge tax even if vat number is validated', 'invoicing' ) |
|
381 | + 'no' => __('Do not charge Tax', 'invoicing'), |
|
382 | + 'always' => __('Charge Tax', 'invoicing'), |
|
383 | + 'vat_too' => __('Charge tax even if vat number is validated', 'invoicing') |
|
384 | 384 | ), |
385 | - 'placeholder' => __( 'Select an option', 'invoicing' ), |
|
385 | + 'placeholder' => __('Select an option', 'invoicing'), |
|
386 | 386 | 'std' => 'always', |
387 | 387 | ), |
388 | 388 | |
@@ -396,68 +396,68 @@ discard block |
||
396 | 396 | 'main' => array( |
397 | 397 | 'email_settings_header' => array( |
398 | 398 | 'id' => 'email_settings_header', |
399 | - 'name' => '<h3>' . __( 'Email Sender Options', 'invoicing' ) . '</h3>', |
|
399 | + 'name' => '<h3>' . __('Email Sender Options', 'invoicing') . '</h3>', |
|
400 | 400 | 'type' => 'header', |
401 | 401 | ), |
402 | 402 | 'email_from_name' => array( |
403 | 403 | 'id' => 'email_from_name', |
404 | - 'name' => __( 'From Name', 'invoicing' ), |
|
405 | - 'desc' => __( 'Enter the sender\'s name appears in outgoing invoice emails. This should be your site name.', 'invoicing' ), |
|
406 | - 'std' => esc_attr( get_bloginfo( 'name', 'display' ) ), |
|
404 | + 'name' => __('From Name', 'invoicing'), |
|
405 | + 'desc' => __('Enter the sender\'s name appears in outgoing invoice emails. This should be your site name.', 'invoicing'), |
|
406 | + 'std' => esc_attr(get_bloginfo('name', 'display')), |
|
407 | 407 | 'type' => 'text', |
408 | 408 | ), |
409 | 409 | 'email_from' => array( |
410 | 410 | 'id' => 'email_from', |
411 | - 'name' => __( 'From Email', 'invoicing' ), |
|
412 | - 'desc' => sprintf (__( 'Email address to send invoice emails from. This will act as the "from" and "reply-to" address. %s If emails are not being sent it may be that your hosting prevents emails being sent if the email domains do not match.%s', 'invoicing' ), $alert_wrapper_start, $alert_wrapper_close), |
|
413 | - 'std' => get_option( 'admin_email' ), |
|
411 | + 'name' => __('From Email', 'invoicing'), |
|
412 | + 'desc' => sprintf(__('Email address to send invoice emails from. This will act as the "from" and "reply-to" address. %s If emails are not being sent it may be that your hosting prevents emails being sent if the email domains do not match.%s', 'invoicing'), $alert_wrapper_start, $alert_wrapper_close), |
|
413 | + 'std' => get_option('admin_email'), |
|
414 | 414 | 'type' => 'text', |
415 | 415 | ), |
416 | 416 | 'admin_email' => array( |
417 | 417 | 'id' => 'admin_email', |
418 | - 'name' => __( 'Admin Email', 'invoicing' ), |
|
419 | - 'desc' => __( 'Where should we send admin notifications?', 'invoicing' ), |
|
420 | - 'std' => get_option( 'admin_email' ), |
|
418 | + 'name' => __('Admin Email', 'invoicing'), |
|
419 | + 'desc' => __('Where should we send admin notifications?', 'invoicing'), |
|
420 | + 'std' => get_option('admin_email'), |
|
421 | 421 | 'type' => 'text', |
422 | 422 | ), |
423 | 423 | 'overdue_settings_header' => array( |
424 | 424 | 'id' => 'overdue_settings_header', |
425 | - 'name' => '<h3>' . __( 'Due Date Settings', 'invoicing' ) . '</h3>', |
|
425 | + 'name' => '<h3>' . __('Due Date Settings', 'invoicing') . '</h3>', |
|
426 | 426 | 'type' => 'header', |
427 | 427 | ), |
428 | 428 | 'overdue_active' => array( |
429 | 429 | 'id' => 'overdue_active', |
430 | - 'name' => __( 'Enable Due Date', 'invoicing' ), |
|
431 | - 'desc' => __( 'Check this to enable due date option for invoices.', 'invoicing' ), |
|
430 | + 'name' => __('Enable Due Date', 'invoicing'), |
|
431 | + 'desc' => __('Check this to enable due date option for invoices.', 'invoicing'), |
|
432 | 432 | 'type' => 'checkbox', |
433 | 433 | 'std' => false, |
434 | 434 | ), |
435 | 435 | 'overdue_days' => array( |
436 | 436 | 'id' => 'overdue_days', |
437 | - 'name' => __( 'Default Due Date', 'invoicing' ), |
|
438 | - 'desc' => __( 'Number of days each Invoice is due after the created date. This will automatically set the date in the "Due Date" field. Can be overridden on individual Invoices.', 'invoicing' ), |
|
437 | + 'name' => __('Default Due Date', 'invoicing'), |
|
438 | + 'desc' => __('Number of days each Invoice is due after the created date. This will automatically set the date in the "Due Date" field. Can be overridden on individual Invoices.', 'invoicing'), |
|
439 | 439 | 'type' => 'select', |
440 | 440 | 'options' => $due_payment_options, |
441 | 441 | 'std' => 0, |
442 | - 'placeholder' => __( 'Select a page', 'invoicing' ), |
|
442 | + 'placeholder' => __('Select a page', 'invoicing'), |
|
443 | 443 | ), |
444 | 444 | 'email_template_header' => array( |
445 | 445 | 'id' => 'email_template_header', |
446 | - 'name' => '<h3>' . __( 'Email Template', 'invoicing' ) . '</h3>', |
|
446 | + 'name' => '<h3>' . __('Email Template', 'invoicing') . '</h3>', |
|
447 | 447 | 'type' => 'header', |
448 | 448 | ), |
449 | 449 | 'email_header_image' => array( |
450 | 450 | 'id' => 'email_header_image', |
451 | - 'name' => __( 'Header Image', 'invoicing' ), |
|
452 | - 'desc' => __( 'URL to an image you want to show in the email header. Upload images using the media uploader (Admin > Media).', 'invoicing' ), |
|
451 | + 'name' => __('Header Image', 'invoicing'), |
|
452 | + 'desc' => __('URL to an image you want to show in the email header. Upload images using the media uploader (Admin > Media).', 'invoicing'), |
|
453 | 453 | 'std' => '', |
454 | 454 | 'type' => 'text', |
455 | 455 | ), |
456 | 456 | 'email_footer_text' => array( |
457 | 457 | 'id' => 'email_footer_text', |
458 | - 'name' => __( 'Footer Text', 'invoicing' ), |
|
459 | - 'desc' => __( 'The text to appear in the footer of all invoice emails.', 'invoicing' ), |
|
460 | - 'std' => get_bloginfo( 'name', 'display' ) . ' - ' . __( 'Powered by GetPaid', 'invoicing' ), |
|
458 | + 'name' => __('Footer Text', 'invoicing'), |
|
459 | + 'desc' => __('The text to appear in the footer of all invoice emails.', 'invoicing'), |
|
460 | + 'std' => get_bloginfo('name', 'display') . ' - ' . __('Powered by GetPaid', 'invoicing'), |
|
461 | 461 | 'type' => 'textarea', |
462 | 462 | 'class' => 'regular-text', |
463 | 463 | 'rows' => 2, |
@@ -465,29 +465,29 @@ discard block |
||
465 | 465 | ), |
466 | 466 | 'email_base_color' => array( |
467 | 467 | 'id' => 'email_base_color', |
468 | - 'name' => __( 'Base Color', 'invoicing' ), |
|
469 | - 'desc' => __( 'The base color for invoice email template. Default <code>#557da2</code>.', 'invoicing' ), |
|
468 | + 'name' => __('Base Color', 'invoicing'), |
|
469 | + 'desc' => __('The base color for invoice email template. Default <code>#557da2</code>.', 'invoicing'), |
|
470 | 470 | 'std' => '#557da2', |
471 | 471 | 'type' => 'color', |
472 | 472 | ), |
473 | 473 | 'email_background_color' => array( |
474 | 474 | 'id' => 'email_background_color', |
475 | - 'name' => __( 'Background Color', 'invoicing' ), |
|
476 | - 'desc' => __( 'The background color of email template. Default <code>#f5f5f5</code>.', 'invoicing' ), |
|
475 | + 'name' => __('Background Color', 'invoicing'), |
|
476 | + 'desc' => __('The background color of email template. Default <code>#f5f5f5</code>.', 'invoicing'), |
|
477 | 477 | 'std' => '#f5f5f5', |
478 | 478 | 'type' => 'color', |
479 | 479 | ), |
480 | 480 | 'email_body_background_color' => array( |
481 | 481 | 'id' => 'email_body_background_color', |
482 | - 'name' => __( 'Body Background Color', 'invoicing' ), |
|
483 | - 'desc' => __( 'The main body background color of email template. Default <code>#fdfdfd</code>.', 'invoicing' ), |
|
482 | + 'name' => __('Body Background Color', 'invoicing'), |
|
483 | + 'desc' => __('The main body background color of email template. Default <code>#fdfdfd</code>.', 'invoicing'), |
|
484 | 484 | 'std' => '#fdfdfd', |
485 | 485 | 'type' => 'color', |
486 | 486 | ), |
487 | 487 | 'email_text_color' => array( |
488 | 488 | 'id' => 'email_text_color', |
489 | - 'name' => __( 'Body Text Color', 'invoicing' ), |
|
490 | - 'desc' => __( 'The main body text color. Default <code>#505050</code>.', 'invoicing' ), |
|
489 | + 'name' => __('Body Text Color', 'invoicing'), |
|
490 | + 'desc' => __('The main body text color. Default <code>#505050</code>.', 'invoicing'), |
|
491 | 491 | 'std' => '#505050', |
492 | 492 | 'type' => 'color', |
493 | 493 | ), |
@@ -502,7 +502,7 @@ discard block |
||
502 | 502 | ), |
503 | 503 | |
504 | 504 | // Integrations. |
505 | - 'integrations' => wp_list_pluck( getpaid_get_integration_settings(), 'settings', 'id' ), |
|
505 | + 'integrations' => wp_list_pluck(getpaid_get_integration_settings(), 'settings', 'id'), |
|
506 | 506 | |
507 | 507 | /** Privacy Settings */ |
508 | 508 | 'privacy' => apply_filters('wpinv_settings_privacy', |
@@ -510,17 +510,17 @@ discard block |
||
510 | 510 | 'main' => array( |
511 | 511 | 'invoicing_privacy_policy_settings' => array( |
512 | 512 | 'id' => 'invoicing_privacy_policy_settings', |
513 | - 'name' => '<h3>' . __( 'Privacy Policy', 'invoicing' ) . '</h3>', |
|
513 | + 'name' => '<h3>' . __('Privacy Policy', 'invoicing') . '</h3>', |
|
514 | 514 | 'type' => 'header', |
515 | 515 | ), |
516 | 516 | 'privacy_page' => array( |
517 | 517 | 'id' => 'privacy_page', |
518 | - 'name' => __( 'Privacy Page', 'invoicing' ), |
|
519 | - 'desc' => __( 'If no privacy policy page set in Settings->Privacy default settings, this page will be used on checkout page.', 'invoicing' ), |
|
518 | + 'name' => __('Privacy Page', 'invoicing'), |
|
519 | + 'desc' => __('If no privacy policy page set in Settings->Privacy default settings, this page will be used on checkout page.', 'invoicing'), |
|
520 | 520 | 'type' => 'select', |
521 | - 'options' => wpinv_get_pages( true, __( 'Select a page', 'invoicing' )), |
|
521 | + 'options' => wpinv_get_pages(true, __('Select a page', 'invoicing')), |
|
522 | 522 | 'class' => 'wpi_select2', |
523 | - 'placeholder' => __( 'Select a page', 'invoicing' ), |
|
523 | + 'placeholder' => __('Select a page', 'invoicing'), |
|
524 | 524 | ), |
525 | 525 | ), |
526 | 526 | ) |
@@ -531,19 +531,19 @@ discard block |
||
531 | 531 | 'main' => array( |
532 | 532 | 'invoice_number_format_settings' => array( |
533 | 533 | 'id' => 'invoice_number_format_settings', |
534 | - 'name' => '<h3>' . __( 'Invoice Number', 'invoicing' ) . '</h3>', |
|
534 | + 'name' => '<h3>' . __('Invoice Number', 'invoicing') . '</h3>', |
|
535 | 535 | 'type' => 'header', |
536 | 536 | ), |
537 | 537 | 'sequential_invoice_number' => array( |
538 | 538 | 'id' => 'sequential_invoice_number', |
539 | - 'name' => __( 'Sequential Invoice Numbers', 'invoicing' ), |
|
540 | - 'desc' => __('Check this box to enable sequential invoice numbers.', 'invoicing' ) . $reset_number, |
|
539 | + 'name' => __('Sequential Invoice Numbers', 'invoicing'), |
|
540 | + 'desc' => __('Check this box to enable sequential invoice numbers.', 'invoicing') . $reset_number, |
|
541 | 541 | 'type' => 'checkbox', |
542 | 542 | ), |
543 | 543 | 'invoice_sequence_start' => array( |
544 | 544 | 'id' => 'invoice_sequence_start', |
545 | - 'name' => __( 'Sequential Starting Number', 'invoicing' ), |
|
546 | - 'desc' => __( 'The number at which the invoice number sequence should begin.', 'invoicing' ) . $last_number, |
|
545 | + 'name' => __('Sequential Starting Number', 'invoicing'), |
|
546 | + 'desc' => __('The number at which the invoice number sequence should begin.', 'invoicing') . $last_number, |
|
547 | 547 | 'type' => 'number', |
548 | 548 | 'size' => 'small', |
549 | 549 | 'std' => '1', |
@@ -551,8 +551,8 @@ discard block |
||
551 | 551 | ), |
552 | 552 | 'invoice_number_padd' => array( |
553 | 553 | 'id' => 'invoice_number_padd', |
554 | - 'name' => __( 'Minimum Digits', 'invoicing' ), |
|
555 | - 'desc' => __( 'If the invoice number has less digits than this number, it is left padded with 0s. Ex: invoice number 108 will padded to 00108 if digits set to 5. The default 0 means no padding.', 'invoicing' ), |
|
554 | + 'name' => __('Minimum Digits', 'invoicing'), |
|
555 | + 'desc' => __('If the invoice number has less digits than this number, it is left padded with 0s. Ex: invoice number 108 will padded to 00108 if digits set to 5. The default 0 means no padding.', 'invoicing'), |
|
556 | 556 | 'type' => 'select', |
557 | 557 | 'options' => $invoice_number_padd_options, |
558 | 558 | 'std' => 5, |
@@ -560,8 +560,8 @@ discard block |
||
560 | 560 | ), |
561 | 561 | 'invoice_number_prefix' => array( |
562 | 562 | 'id' => 'invoice_number_prefix', |
563 | - 'name' => __( 'Invoice Number Prefix', 'invoicing' ), |
|
564 | - 'desc' => __( 'Prefix for all invoice numbers. Ex: INV-', 'invoicing' ), |
|
563 | + 'name' => __('Invoice Number Prefix', 'invoicing'), |
|
564 | + 'desc' => __('Prefix for all invoice numbers. Ex: INV-', 'invoicing'), |
|
565 | 565 | 'type' => 'text', |
566 | 566 | 'size' => 'regular', |
567 | 567 | 'std' => 'INV-', |
@@ -569,41 +569,41 @@ discard block |
||
569 | 569 | ), |
570 | 570 | 'invoice_number_postfix' => array( |
571 | 571 | 'id' => 'invoice_number_postfix', |
572 | - 'name' => __( 'Invoice Number Postfix', 'invoicing' ), |
|
573 | - 'desc' => __( 'Postfix for all invoice numbers.', 'invoicing' ), |
|
572 | + 'name' => __('Invoice Number Postfix', 'invoicing'), |
|
573 | + 'desc' => __('Postfix for all invoice numbers.', 'invoicing'), |
|
574 | 574 | 'type' => 'text', |
575 | 575 | 'size' => 'regular', |
576 | 576 | 'std' => '' |
577 | 577 | ), |
578 | 578 | 'checkout_settings' => array( |
579 | 579 | 'id' => 'checkout_settings', |
580 | - 'name' => '<h3>' . __( 'Checkout Settings', 'invoicing' ) . '</h3>', |
|
580 | + 'name' => '<h3>' . __('Checkout Settings', 'invoicing') . '</h3>', |
|
581 | 581 | 'type' => 'header', |
582 | 582 | ), |
583 | 583 | 'login_to_checkout' => array( |
584 | 584 | 'id' => 'login_to_checkout', |
585 | - 'name' => __( 'Require Login To Checkout', 'invoicing' ), |
|
586 | - 'desc' => __( 'If ticked then user needs to be logged in to view or pay invoice, can only view or pay their own invoice. If unticked then anyone can view or pay the invoice.', 'invoicing' ), |
|
585 | + 'name' => __('Require Login To Checkout', 'invoicing'), |
|
586 | + 'desc' => __('If ticked then user needs to be logged in to view or pay invoice, can only view or pay their own invoice. If unticked then anyone can view or pay the invoice.', 'invoicing'), |
|
587 | 587 | 'type' => 'checkbox', |
588 | 588 | ), |
589 | 589 | |
590 | 590 | 'maxmind_license_key' => array( |
591 | 591 | 'id' => 'maxmind_license_key', |
592 | - 'name' => __( 'MaxMind License Key', 'invoicing' ), |
|
592 | + 'name' => __('MaxMind License Key', 'invoicing'), |
|
593 | 593 | 'type' => 'text', |
594 | 594 | 'size' => 'regular', |
595 | - 'desc' => __( "Enter you license key if you would like to use MaxMind to automatically detect a customer's country.", 'invoicing' ) . ' <a href="https://support.maxmind.com/account-faq/license-keys/how-do-i-generate-a-license-key/">' . __( 'How to generate a free license key.', 'invoicing' ) . '</a>', |
|
595 | + 'desc' => __("Enter you license key if you would like to use MaxMind to automatically detect a customer's country.", 'invoicing') . ' <a href="https://support.maxmind.com/account-faq/license-keys/how-do-i-generate-a-license-key/">' . __('How to generate a free license key.', 'invoicing') . '</a>', |
|
596 | 596 | ), |
597 | 597 | |
598 | 598 | 'uninstall_settings' => array( |
599 | 599 | 'id' => 'uninstall_settings', |
600 | - 'name' => '<h3>' . __( 'Uninstall Settings', 'invoicing' ) . '</h3>', |
|
600 | + 'name' => '<h3>' . __('Uninstall Settings', 'invoicing') . '</h3>', |
|
601 | 601 | 'type' => 'header', |
602 | 602 | ), |
603 | 603 | 'remove_data_on_unistall' => array( |
604 | 604 | 'id' => 'remove_data_on_unistall', |
605 | - 'name' => __( 'Remove Data on Uninstall?', 'invoicing' ), |
|
606 | - 'desc' => __( 'Check this box if you would like Invoicing plugin to completely remove all of its data when the plugin is deleted/uninstalled.', 'invoicing' ), |
|
605 | + 'name' => __('Remove Data on Uninstall?', 'invoicing'), |
|
606 | + 'desc' => __('Check this box if you would like Invoicing plugin to completely remove all of its data when the plugin is deleted/uninstalled.', 'invoicing'), |
|
607 | 607 | 'type' => 'checkbox', |
608 | 608 | 'std' => '' |
609 | 609 | ), |
@@ -612,13 +612,13 @@ discard block |
||
612 | 612 | 'custom-css' => array( |
613 | 613 | 'css_settings' => array( |
614 | 614 | 'id' => 'css_settings', |
615 | - 'name' => '<h3>' . __( 'Custom CSS', 'invoicing' ) . '</h3>', |
|
615 | + 'name' => '<h3>' . __('Custom CSS', 'invoicing') . '</h3>', |
|
616 | 616 | 'type' => 'header', |
617 | 617 | ), |
618 | 618 | 'template_custom_css' => array( |
619 | 619 | 'id' => 'template_custom_css', |
620 | - 'name' => __( 'Invoice Template CSS', 'invoicing' ), |
|
621 | - 'desc' => __( 'Add CSS to modify appearance of the print invoice page.', 'invoicing' ), |
|
620 | + 'name' => __('Invoice Template CSS', 'invoicing'), |
|
621 | + 'desc' => __('Add CSS to modify appearance of the print invoice page.', 'invoicing'), |
|
622 | 622 | 'type' => 'textarea', |
623 | 623 | 'class'=> 'regular-text', |
624 | 624 | 'rows' => 10, |
@@ -632,8 +632,8 @@ discard block |
||
632 | 632 | 'main' => array( |
633 | 633 | 'tool_settings' => array( |
634 | 634 | 'id' => 'tool_settings', |
635 | - 'name' => '<h3>' . __( 'Diagnostic Tools', 'invoicing' ) . '</h3>', |
|
636 | - 'desc' => __( 'Invoicing diagnostic tools', 'invoicing' ), |
|
635 | + 'name' => '<h3>' . __('Diagnostic Tools', 'invoicing') . '</h3>', |
|
636 | + 'desc' => __('Invoicing diagnostic tools', 'invoicing'), |
|
637 | 637 | 'type' => 'tools', |
638 | 638 | ), |
639 | 639 | ), |
@@ -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 | * Returns an array of eu states. |
@@ -12,7 +12,7 @@ discard block |
||
12 | 12 | * @return array |
13 | 13 | */ |
14 | 14 | function getpaid_get_eu_states() { |
15 | - return wpinv_get_data( 'eu-states' ); |
|
15 | + return wpinv_get_data('eu-states'); |
|
16 | 16 | } |
17 | 17 | |
18 | 18 | /** |
@@ -20,8 +20,8 @@ discard block |
||
20 | 20 | * |
21 | 21 | * @return bool |
22 | 22 | */ |
23 | -function getpaid_is_eu_state( $country ) { |
|
24 | - return ! empty( $country ) && in_array( strtoupper( $country ), getpaid_get_eu_states() ) ? true : false; |
|
23 | +function getpaid_is_eu_state($country) { |
|
24 | + return !empty($country) && in_array(strtoupper($country), getpaid_get_eu_states()) ? true : false; |
|
25 | 25 | } |
26 | 26 | |
27 | 27 | /** |
@@ -30,7 +30,7 @@ discard block |
||
30 | 30 | * @return array |
31 | 31 | */ |
32 | 32 | function getpaid_get_gst_states() { |
33 | - return array( 'AU', 'NZ', 'CA', 'CN' ); |
|
33 | + return array('AU', 'NZ', 'CA', 'CN'); |
|
34 | 34 | } |
35 | 35 | |
36 | 36 | /** |
@@ -38,8 +38,8 @@ discard block |
||
38 | 38 | * |
39 | 39 | * @return bool |
40 | 40 | */ |
41 | -function getpaid_is_gst_country( $country ) { |
|
42 | - return ! empty( $country ) && in_array( strtoupper( $country ), getpaid_get_gst_states() ) ? true : false; |
|
41 | +function getpaid_is_gst_country($country) { |
|
42 | + return !empty($country) && in_array(strtoupper($country), getpaid_get_gst_states()) ? true : false; |
|
43 | 43 | } |
44 | 44 | |
45 | 45 | /** |
@@ -49,8 +49,8 @@ discard block |
||
49 | 49 | */ |
50 | 50 | function wpinv_use_taxes() { |
51 | 51 | |
52 | - $ret = wpinv_get_option( 'enable_taxes', false ); |
|
53 | - return (bool) apply_filters( 'wpinv_use_taxes', ! empty( $ret ) ); |
|
52 | + $ret = wpinv_get_option('enable_taxes', false); |
|
53 | + return (bool) apply_filters('wpinv_use_taxes', !empty($ret)); |
|
54 | 54 | |
55 | 55 | } |
56 | 56 | |
@@ -60,7 +60,7 @@ discard block |
||
60 | 60 | * @param WPInv_Invoice $invoice |
61 | 61 | * @return bool |
62 | 62 | */ |
63 | -function wpinv_is_invoice_taxable( $invoice ) { |
|
63 | +function wpinv_is_invoice_taxable($invoice) { |
|
64 | 64 | return $invoice->is_taxable(); |
65 | 65 | } |
66 | 66 | |
@@ -70,11 +70,11 @@ discard block |
||
70 | 70 | * @param string $country |
71 | 71 | * @return bool |
72 | 72 | */ |
73 | -function wpinv_is_country_taxable( $country ) { |
|
74 | - $is_eu = getpaid_is_eu_state( $country ); |
|
75 | - $is_exempt = $is_eu && $country == wpinv_is_base_country( $country ) && wpinv_same_country_exempt_vat(); |
|
73 | +function wpinv_is_country_taxable($country) { |
|
74 | + $is_eu = getpaid_is_eu_state($country); |
|
75 | + $is_exempt = $is_eu && $country == wpinv_is_base_country($country) && wpinv_same_country_exempt_vat(); |
|
76 | 76 | |
77 | - return (bool) apply_filters( 'wpinv_is_country_taxable', ! $is_exempt, $country ); |
|
77 | + return (bool) apply_filters('wpinv_is_country_taxable', !$is_exempt, $country); |
|
78 | 78 | |
79 | 79 | } |
80 | 80 | |
@@ -84,7 +84,7 @@ discard block |
||
84 | 84 | * @param WPInv_Item|GetPaid_Form_Item $item |
85 | 85 | * @return bool |
86 | 86 | */ |
87 | -function wpinv_is_item_taxable( $item ) { |
|
87 | +function wpinv_is_item_taxable($item) { |
|
88 | 88 | return '_exempt' != $item->get_vat_rule(); |
89 | 89 | } |
90 | 90 | |
@@ -94,8 +94,8 @@ discard block |
||
94 | 94 | * @return bool |
95 | 95 | */ |
96 | 96 | function wpinv_use_store_address_as_tax_base() { |
97 | - $use_base = wpinv_get_option( 'tax_base', 'billing' ) == 'base'; |
|
98 | - return (bool) apply_filters( 'wpinv_use_store_address_as_tax_base', $use_base ); |
|
97 | + $use_base = wpinv_get_option('tax_base', 'billing') == 'base'; |
|
98 | + return (bool) apply_filters('wpinv_use_store_address_as_tax_base', $use_base); |
|
99 | 99 | } |
100 | 100 | |
101 | 101 | /** |
@@ -104,8 +104,8 @@ discard block |
||
104 | 104 | * @return bool |
105 | 105 | */ |
106 | 106 | function wpinv_prices_include_tax() { |
107 | - $is_inclusive = wpinv_get_option( 'prices_include_tax', 'no' ) == 'yes'; |
|
108 | - return (bool) apply_filters( 'wpinv_prices_include_tax', $is_inclusive ); |
|
107 | + $is_inclusive = wpinv_get_option('prices_include_tax', 'no') == 'yes'; |
|
108 | + return (bool) apply_filters('wpinv_prices_include_tax', $is_inclusive); |
|
109 | 109 | } |
110 | 110 | |
111 | 111 | /** |
@@ -114,8 +114,8 @@ discard block |
||
114 | 114 | * @return bool |
115 | 115 | */ |
116 | 116 | function wpinv_round_tax_per_tax_rate() { |
117 | - $subtotal_rounding = wpinv_get_option( 'tax_subtotal_rounding', 1 ); |
|
118 | - return (bool) apply_filters( 'wpinv_round_tax_per_tax_rate', empty( $subtotal_rounding ) ); |
|
117 | + $subtotal_rounding = wpinv_get_option('tax_subtotal_rounding', 1); |
|
118 | + return (bool) apply_filters('wpinv_round_tax_per_tax_rate', empty($subtotal_rounding)); |
|
119 | 119 | } |
120 | 120 | |
121 | 121 | /** |
@@ -124,8 +124,8 @@ discard block |
||
124 | 124 | * @return bool |
125 | 125 | */ |
126 | 126 | function wpinv_display_individual_tax_rates() { |
127 | - $individual = wpinv_get_option( 'tax_display_totals', 'single' ) == 'individual'; |
|
128 | - return (bool) apply_filters( 'wpinv_display_individual_tax_rates', $individual ); |
|
127 | + $individual = wpinv_get_option('tax_display_totals', 'single') == 'individual'; |
|
128 | + return (bool) apply_filters('wpinv_display_individual_tax_rates', $individual); |
|
129 | 129 | } |
130 | 130 | |
131 | 131 | /** |
@@ -134,8 +134,8 @@ discard block |
||
134 | 134 | * @return float |
135 | 135 | */ |
136 | 136 | function wpinv_get_default_tax_rate() { |
137 | - $rate = wpinv_get_option( 'tax_rate', 20 ); |
|
138 | - return (float) apply_filters( 'wpinv_get_default_tax_rate', floatval( $rate ) ); |
|
137 | + $rate = wpinv_get_option('tax_rate', 20); |
|
138 | + return (float) apply_filters('wpinv_get_default_tax_rate', floatval($rate)); |
|
139 | 139 | } |
140 | 140 | |
141 | 141 | /** |
@@ -144,7 +144,7 @@ discard block |
||
144 | 144 | * @return bool |
145 | 145 | */ |
146 | 146 | function wpinv_same_country_exempt_vat() { |
147 | - return 'no' == wpinv_get_option( 'vat_same_country_rule', 'always' ); |
|
147 | + return 'no' == wpinv_get_option('vat_same_country_rule', 'always'); |
|
148 | 148 | } |
149 | 149 | |
150 | 150 | /** |
@@ -164,28 +164,28 @@ discard block |
||
164 | 164 | * @param string $state |
165 | 165 | * @return array |
166 | 166 | */ |
167 | -function getpaid_get_item_tax_rates( $item, $country = '', $state = '' ) { |
|
167 | +function getpaid_get_item_tax_rates($item, $country = '', $state = '') { |
|
168 | 168 | |
169 | 169 | // Abort if the item is not taxable. |
170 | - if ( ! wpinv_is_item_taxable( $item ) ) { |
|
170 | + if (!wpinv_is_item_taxable($item)) { |
|
171 | 171 | return array(); |
172 | 172 | } |
173 | 173 | |
174 | 174 | // Maybe use the store address. |
175 | - if ( wpinv_use_store_address_as_tax_base() ) { |
|
175 | + if (wpinv_use_store_address_as_tax_base()) { |
|
176 | 176 | $country = wpinv_get_default_country(); |
177 | 177 | $state = wpinv_get_default_state(); |
178 | 178 | } |
179 | 179 | |
180 | 180 | // Retrieve tax rates. |
181 | - $tax_rates = GetPaid_Tax::get_address_tax_rates( $country, $state ); |
|
181 | + $tax_rates = GetPaid_Tax::get_address_tax_rates($country, $state); |
|
182 | 182 | |
183 | 183 | // Fallback to the default tax rates if non were found. |
184 | - if ( empty( $tax_rates ) ) { |
|
184 | + if (empty($tax_rates)) { |
|
185 | 185 | $tax_rates = GetPaid_Tax::get_default_tax_rates(); |
186 | 186 | } |
187 | 187 | |
188 | - return apply_filters( 'getpaid_get_item_tax_rates', $tax_rates, $item, $country, $state ); |
|
188 | + return apply_filters('getpaid_get_item_tax_rates', $tax_rates, $item, $country, $state); |
|
189 | 189 | } |
190 | 190 | |
191 | 191 | /** |
@@ -195,23 +195,23 @@ discard block |
||
195 | 195 | * @param array $rates |
196 | 196 | * @return array |
197 | 197 | */ |
198 | -function getpaid_filter_item_tax_rates( $item, $rates ) { |
|
198 | +function getpaid_filter_item_tax_rates($item, $rates) { |
|
199 | 199 | |
200 | 200 | $tax_class = $item->get_vat_class(); |
201 | 201 | |
202 | - foreach ( $rates as $i => $rate ) { |
|
202 | + foreach ($rates as $i => $rate) { |
|
203 | 203 | |
204 | - if ( $tax_class == '_reduced' ) { |
|
205 | - $rates[ $i ]['rate'] = empty( $rate['reduced_rate'] ) ? 0 : $rate['reduced_rate']; |
|
204 | + if ($tax_class == '_reduced') { |
|
205 | + $rates[$i]['rate'] = empty($rate['reduced_rate']) ? 0 : $rate['reduced_rate']; |
|
206 | 206 | } |
207 | 207 | |
208 | - if ( $tax_class == '_exempt' ) { |
|
209 | - $rates[ $i ]['rate'] = 0; |
|
208 | + if ($tax_class == '_exempt') { |
|
209 | + $rates[$i]['rate'] = 0; |
|
210 | 210 | } |
211 | 211 | |
212 | 212 | } |
213 | 213 | |
214 | - return apply_filters( 'getpaid_filter_item_tax_rates', $rates, $item ); |
|
214 | + return apply_filters('getpaid_filter_item_tax_rates', $rates, $item); |
|
215 | 215 | } |
216 | 216 | |
217 | 217 | /** |
@@ -221,12 +221,12 @@ discard block |
||
221 | 221 | * @param array $rates |
222 | 222 | * @return array |
223 | 223 | */ |
224 | -function getpaid_calculate_item_taxes( $amount, $rates ) { |
|
224 | +function getpaid_calculate_item_taxes($amount, $rates) { |
|
225 | 225 | |
226 | 226 | $is_inclusive = wpinv_prices_include_tax(); |
227 | - $taxes = GetPaid_Tax::calc_tax( $amount, $rates, $is_inclusive ); |
|
227 | + $taxes = GetPaid_Tax::calc_tax($amount, $rates, $is_inclusive); |
|
228 | 228 | |
229 | - return apply_filters( 'getpaid_calculate_taxes', $taxes, $amount, $rates ); |
|
229 | + return apply_filters('getpaid_calculate_taxes', $taxes, $amount, $rates); |
|
230 | 230 | } |
231 | 231 | |
232 | 232 | /** |
@@ -238,17 +238,17 @@ discard block |
||
238 | 238 | * @param float $recurring_tax_amount |
239 | 239 | * @return array |
240 | 240 | */ |
241 | -function getpaid_prepare_item_tax( $item, $tax_name, $tax_amount, $recurring_tax_amount ) { |
|
241 | +function getpaid_prepare_item_tax($item, $tax_name, $tax_amount, $recurring_tax_amount) { |
|
242 | 242 | |
243 | - $initial_tax = $tax_amount; |
|
243 | + $initial_tax = $tax_amount; |
|
244 | 244 | $recurring_tax = 0; |
245 | 245 | |
246 | - if ( $item->is_recurring() ) { |
|
246 | + if ($item->is_recurring()) { |
|
247 | 247 | $recurring_tax = $recurring_tax_amount; |
248 | 248 | } |
249 | 249 | |
250 | 250 | return array( |
251 | - 'name' => sanitize_text_field( $tax_name ), |
|
251 | + 'name' => sanitize_text_field($tax_name), |
|
252 | 252 | 'initial_tax' => $initial_tax, |
253 | 253 | 'recurring_tax' => $recurring_tax, |
254 | 254 | ); |
@@ -261,8 +261,8 @@ discard block |
||
261 | 261 | * @param string $vat_number |
262 | 262 | * @return string |
263 | 263 | */ |
264 | -function wpinv_sanitize_vat_number( $vat_number ) { |
|
265 | - return str_replace( array(' ', '.', '-', '_', ',' ), '', strtoupper( trim( $vat_number ) ) ); |
|
264 | +function wpinv_sanitize_vat_number($vat_number) { |
|
265 | + return str_replace(array(' ', '.', '-', '_', ','), '', strtoupper(trim($vat_number))); |
|
266 | 266 | } |
267 | 267 | |
268 | 268 | /** |
@@ -271,22 +271,22 @@ discard block |
||
271 | 271 | * @param string $vat_number |
272 | 272 | * @return bool |
273 | 273 | */ |
274 | -function wpinv_regex_validate_vat_number( $vat_number ) { |
|
274 | +function wpinv_regex_validate_vat_number($vat_number) { |
|
275 | 275 | |
276 | - $country = substr( $vat_number, 0, 2 ); |
|
277 | - $vatin = substr( $vat_number, 2 ); |
|
278 | - $regexes = wpinv_get_data( 'vat-number-regexes' ); |
|
276 | + $country = substr($vat_number, 0, 2); |
|
277 | + $vatin = substr($vat_number, 2); |
|
278 | + $regexes = wpinv_get_data('vat-number-regexes'); |
|
279 | 279 | |
280 | - if ( isset( $regexes[ $country ] ) ) { |
|
280 | + if (isset($regexes[$country])) { |
|
281 | 281 | |
282 | - $regex = $regexes[ $country ]; |
|
282 | + $regex = $regexes[$country]; |
|
283 | 283 | $regex = '/^(?:' . $regex . ')$/'; |
284 | - return 1 === preg_match( $regex, $vatin ); |
|
284 | + return 1 === preg_match($regex, $vatin); |
|
285 | 285 | |
286 | 286 | } |
287 | 287 | |
288 | 288 | // Not an EU state, use filters to validate the number. |
289 | - return apply_filters( 'wpinv_regex_validate_vat_number', true, $vat_number ); |
|
289 | + return apply_filters('wpinv_regex_validate_vat_number', true, $vat_number); |
|
290 | 290 | } |
291 | 291 | |
292 | 292 | /** |
@@ -295,29 +295,29 @@ discard block |
||
295 | 295 | * @param string $vat_number |
296 | 296 | * @return bool |
297 | 297 | */ |
298 | -function wpinv_vies_validate_vat_number( $vat_number ) { |
|
298 | +function wpinv_vies_validate_vat_number($vat_number) { |
|
299 | 299 | |
300 | - $country = substr( $vat_number, 0, 2 ); |
|
301 | - $vatin = substr( $vat_number, 2 ); |
|
300 | + $country = substr($vat_number, 0, 2); |
|
301 | + $vatin = substr($vat_number, 2); |
|
302 | 302 | |
303 | 303 | $url = add_query_arg( |
304 | 304 | array( |
305 | - 'ms' => urlencode( $country ), |
|
306 | - 'iso' => urlencode( $country ), |
|
307 | - 'vat' => urlencode( $vatin ), |
|
305 | + 'ms' => urlencode($country), |
|
306 | + 'iso' => urlencode($country), |
|
307 | + 'vat' => urlencode($vatin), |
|
308 | 308 | ), |
309 | 309 | 'http://ec.europa.eu/taxation_customs/vies/viesquer.do' |
310 | 310 | ); |
311 | 311 | |
312 | - $response = wp_remote_get( $url ); |
|
313 | - $response = wp_remote_retrieve_body( $response ); |
|
312 | + $response = wp_remote_get($url); |
|
313 | + $response = wp_remote_retrieve_body($response); |
|
314 | 314 | |
315 | 315 | // Fallback gracefully if the VIES website is down. |
316 | - if ( empty( $response ) ) { |
|
316 | + if (empty($response)) { |
|
317 | 317 | return true; |
318 | 318 | } |
319 | 319 | |
320 | - return 1 !== preg_match( '/invalid VAT number/i', $response ); |
|
320 | + return 1 !== preg_match('/invalid VAT number/i', $response); |
|
321 | 321 | |
322 | 322 | } |
323 | 323 | |
@@ -328,18 +328,18 @@ discard block |
||
328 | 328 | * @param string $country |
329 | 329 | * @return bool |
330 | 330 | */ |
331 | -function wpinv_validate_vat_number( $vat_number, $country ) { |
|
331 | +function wpinv_validate_vat_number($vat_number, $country) { |
|
332 | 332 | |
333 | 333 | // In case the vat number does not have a country code... |
334 | - $vat_number = wpinv_sanitize_vat_number( $vat_number ); |
|
335 | - $_country = substr( $vat_number, 0, 2 ); |
|
336 | - $_country = $_country == wpinv_country_name( $_country ); |
|
334 | + $vat_number = wpinv_sanitize_vat_number($vat_number); |
|
335 | + $_country = substr($vat_number, 0, 2); |
|
336 | + $_country = $_country == wpinv_country_name($_country); |
|
337 | 337 | |
338 | - if ( $_country ) { |
|
339 | - $vat_number = strtoupper( $country ) . $vat_number; |
|
338 | + if ($_country) { |
|
339 | + $vat_number = strtoupper($country) . $vat_number; |
|
340 | 340 | } |
341 | 341 | |
342 | - return wpinv_regex_validate_vat_number( $vat_number ) && wpinv_vies_validate_vat_number( $vat_number ); |
|
342 | + return wpinv_regex_validate_vat_number($vat_number) && wpinv_vies_validate_vat_number($vat_number); |
|
343 | 343 | } |
344 | 344 | |
345 | 345 | /** |
@@ -348,40 +348,40 @@ discard block |
||
348 | 348 | * @return bool |
349 | 349 | */ |
350 | 350 | function wpinv_should_validate_vat_number() { |
351 | - $validate = wpinv_get_option( 'validate_vat_number' ); |
|
352 | - return ! empty( $validate ); |
|
351 | + $validate = wpinv_get_option('validate_vat_number'); |
|
352 | + return !empty($validate); |
|
353 | 353 | } |
354 | 354 | |
355 | -function wpinv_sales_tax_for_year( $year = null ) { |
|
356 | - return wpinv_price( wpinv_get_sales_tax_for_year( $year ) ); |
|
355 | +function wpinv_sales_tax_for_year($year = null) { |
|
356 | + return wpinv_price(wpinv_get_sales_tax_for_year($year)); |
|
357 | 357 | } |
358 | 358 | |
359 | -function wpinv_get_sales_tax_for_year( $year = null ) { |
|
359 | +function wpinv_get_sales_tax_for_year($year = null) { |
|
360 | 360 | global $wpdb; |
361 | 361 | |
362 | 362 | // Start at zero |
363 | 363 | $tax = 0; |
364 | 364 | |
365 | - if ( ! empty( $year ) ) { |
|
365 | + if (!empty($year)) { |
|
366 | 366 | $args = array( |
367 | 367 | 'post_type' => 'wpi_invoice', |
368 | - 'post_status' => array( 'publish' ), |
|
368 | + 'post_status' => array('publish'), |
|
369 | 369 | 'posts_per_page' => -1, |
370 | 370 | 'year' => $year, |
371 | 371 | 'fields' => 'ids' |
372 | 372 | ); |
373 | 373 | |
374 | - $payments = get_posts( $args ); |
|
375 | - $payment_ids = implode( ',', $payments ); |
|
374 | + $payments = get_posts($args); |
|
375 | + $payment_ids = implode(',', $payments); |
|
376 | 376 | |
377 | - if ( count( $payments ) > 0 ) { |
|
377 | + if (count($payments) > 0) { |
|
378 | 378 | $sql = "SELECT SUM( meta_value ) FROM $wpdb->postmeta WHERE meta_key = '_wpinv_tax' AND post_id IN( $payment_ids )"; |
379 | - $tax = $wpdb->get_var( $sql ); |
|
379 | + $tax = $wpdb->get_var($sql); |
|
380 | 380 | } |
381 | 381 | |
382 | 382 | } |
383 | 383 | |
384 | - return apply_filters( 'wpinv_get_sales_tax_for_year', $tax, $year ); |
|
384 | + return apply_filters('wpinv_get_sales_tax_for_year', $tax, $year); |
|
385 | 385 | } |
386 | 386 | |
387 | 387 | function wpinv_is_cart_taxed() { |
@@ -390,33 +390,33 @@ discard block |
||
390 | 390 | |
391 | 391 | function wpinv_prices_show_tax_on_checkout() { |
392 | 392 | return false; // TODO |
393 | - $ret = ( wpinv_get_option( 'checkout_include_tax', false ) == 'yes' && wpinv_use_taxes() ); |
|
393 | + $ret = (wpinv_get_option('checkout_include_tax', false) == 'yes' && wpinv_use_taxes()); |
|
394 | 394 | |
395 | - return apply_filters( 'wpinv_taxes_on_prices_on_checkout', $ret ); |
|
395 | + return apply_filters('wpinv_taxes_on_prices_on_checkout', $ret); |
|
396 | 396 | } |
397 | 397 | |
398 | 398 | function wpinv_display_tax_rate() { |
399 | - $ret = wpinv_use_taxes() && wpinv_get_option( 'display_tax_rate', false ); |
|
399 | + $ret = wpinv_use_taxes() && wpinv_get_option('display_tax_rate', false); |
|
400 | 400 | |
401 | - return apply_filters( 'wpinv_display_tax_rate', $ret ); |
|
401 | + return apply_filters('wpinv_display_tax_rate', $ret); |
|
402 | 402 | } |
403 | 403 | |
404 | 404 | function wpinv_cart_needs_tax_address_fields() { |
405 | - if( !wpinv_is_cart_taxed() ) |
|
405 | + if (!wpinv_is_cart_taxed()) |
|
406 | 406 | return false; |
407 | 407 | |
408 | - return ! did_action( 'wpinv_after_cc_fields', 'wpinv_default_cc_address_fields' ); |
|
408 | + return !did_action('wpinv_after_cc_fields', 'wpinv_default_cc_address_fields'); |
|
409 | 409 | } |
410 | 410 | |
411 | -function wpinv_item_is_tax_exclusive( $item_id = 0 ) { |
|
412 | - $ret = (bool)get_post_meta( $item_id, '_wpinv_tax_exclusive', false ); |
|
413 | - return apply_filters( 'wpinv_is_tax_exclusive', $ret, $item_id ); |
|
411 | +function wpinv_item_is_tax_exclusive($item_id = 0) { |
|
412 | + $ret = (bool) get_post_meta($item_id, '_wpinv_tax_exclusive', false); |
|
413 | + return apply_filters('wpinv_is_tax_exclusive', $ret, $item_id); |
|
414 | 414 | } |
415 | 415 | |
416 | -function wpinv_currency_decimal_filter( $decimals = 2 ) { |
|
416 | +function wpinv_currency_decimal_filter($decimals = 2) { |
|
417 | 417 | $currency = wpinv_get_currency(); |
418 | 418 | |
419 | - switch ( $currency ) { |
|
419 | + switch ($currency) { |
|
420 | 420 | case 'RIAL' : |
421 | 421 | case 'JPY' : |
422 | 422 | case 'TWD' : |
@@ -425,13 +425,13 @@ discard block |
||
425 | 425 | break; |
426 | 426 | } |
427 | 427 | |
428 | - return apply_filters( 'wpinv_currency_decimal_count', $decimals, $currency ); |
|
428 | + return apply_filters('wpinv_currency_decimal_count', $decimals, $currency); |
|
429 | 429 | } |
430 | 430 | |
431 | 431 | function wpinv_tax_amount() { |
432 | 432 | $output = 0.00; |
433 | 433 | |
434 | - return apply_filters( 'wpinv_tax_amount', $output ); |
|
434 | + return apply_filters('wpinv_tax_amount', $output); |
|
435 | 435 | } |
436 | 436 | |
437 | 437 | /** |
@@ -439,25 +439,25 @@ discard block |
||
439 | 439 | * |
440 | 440 | * @param string|bool|null $vat_rule |
441 | 441 | */ |
442 | -function getpaid_filter_vat_rule( $vat_rule ) { |
|
442 | +function getpaid_filter_vat_rule($vat_rule) { |
|
443 | 443 | |
444 | - if ( empty( $vat_rule ) ) { |
|
444 | + if (empty($vat_rule)) { |
|
445 | 445 | return 'digital'; |
446 | 446 | } |
447 | 447 | |
448 | 448 | return $vat_rule; |
449 | 449 | } |
450 | -add_filter( 'wpinv_get_item_vat_rule', 'getpaid_filter_vat_rule' ); |
|
450 | +add_filter('wpinv_get_item_vat_rule', 'getpaid_filter_vat_rule'); |
|
451 | 451 | |
452 | 452 | /** |
453 | 453 | * Filters the VAT class to ensure that each item has a VAT class. |
454 | 454 | * |
455 | 455 | * @param string|bool|null $vat_rule |
456 | 456 | */ |
457 | -function getpaid_filter_vat_class( $vat_class ) { |
|
458 | - return empty( $vat_class ) ? '_standard' : $vat_class; |
|
457 | +function getpaid_filter_vat_class($vat_class) { |
|
458 | + return empty($vat_class) ? '_standard' : $vat_class; |
|
459 | 459 | } |
460 | -add_filter( 'wpinv_get_item_vat_class', 'getpaid_filter_vat_class' ); |
|
460 | +add_filter('wpinv_get_item_vat_class', 'getpaid_filter_vat_class'); |
|
461 | 461 | |
462 | 462 | /** |
463 | 463 | * Returns a list of all tax classes. |
@@ -469,9 +469,9 @@ discard block |
||
469 | 469 | return apply_filters( |
470 | 470 | 'getpaid_tax_classes', |
471 | 471 | array( |
472 | - '_standard' => __( 'Standard Tax Rate', 'invoicing' ), |
|
473 | - '_reduced' => __( 'Reduced Tax Rate', 'invoicing' ), |
|
474 | - '_exempt' => __( 'Tax Exempt', 'invoicing' ), |
|
472 | + '_standard' => __('Standard Tax Rate', 'invoicing'), |
|
473 | + '_reduced' => __('Reduced Tax Rate', 'invoicing'), |
|
474 | + '_exempt' => __('Tax Exempt', 'invoicing'), |
|
475 | 475 | ) |
476 | 476 | ); |
477 | 477 | |
@@ -487,8 +487,8 @@ discard block |
||
487 | 487 | return apply_filters( |
488 | 488 | 'getpaid_tax_rules', |
489 | 489 | array( |
490 | - 'physical' => __( 'Physical Item', 'invoicing' ), |
|
491 | - 'digital' => __( 'Digital Item', 'invoicing' ), |
|
490 | + 'physical' => __('Physical Item', 'invoicing'), |
|
491 | + 'digital' => __('Digital Item', 'invoicing'), |
|
492 | 492 | ) |
493 | 493 | ); |
494 | 494 | |
@@ -500,15 +500,15 @@ discard block |
||
500 | 500 | * @param string $tax_class |
501 | 501 | * @return string |
502 | 502 | */ |
503 | -function getpaid_get_tax_class_label( $tax_class ) { |
|
503 | +function getpaid_get_tax_class_label($tax_class) { |
|
504 | 504 | |
505 | 505 | $classes = getpaid_get_tax_classes(); |
506 | 506 | |
507 | - if ( isset( $classes[ $tax_class ] ) ) { |
|
508 | - return sanitize_text_field( $classes[ $tax_class ] ); |
|
507 | + if (isset($classes[$tax_class])) { |
|
508 | + return sanitize_text_field($classes[$tax_class]); |
|
509 | 509 | } |
510 | 510 | |
511 | - return sanitize_text_field( $tax_class ); |
|
511 | + return sanitize_text_field($tax_class); |
|
512 | 512 | |
513 | 513 | } |
514 | 514 | |
@@ -518,14 +518,14 @@ discard block |
||
518 | 518 | * @param string $tax_rule |
519 | 519 | * @return string |
520 | 520 | */ |
521 | -function getpaid_get_tax_rule_label( $tax_rule ) { |
|
521 | +function getpaid_get_tax_rule_label($tax_rule) { |
|
522 | 522 | |
523 | 523 | $rules = getpaid_get_tax_rules(); |
524 | 524 | |
525 | - if ( isset( $rules[ $tax_rule ] ) ) { |
|
526 | - return sanitize_text_field( $rules[ $tax_rule ] ); |
|
525 | + if (isset($rules[$tax_rule])) { |
|
526 | + return sanitize_text_field($rules[$tax_rule]); |
|
527 | 527 | } |
528 | 528 | |
529 | - return sanitize_text_field( $tax_rule ); |
|
529 | + return sanitize_text_field($tax_rule); |
|
530 | 530 | |
531 | 531 | } |
@@ -12,180 +12,180 @@ discard block |
||
12 | 12 | */ |
13 | 13 | class GetPaid_Checkout { |
14 | 14 | |
15 | - /** |
|
16 | - * @var GetPaid_Payment_Form_Submission |
|
17 | - */ |
|
18 | - protected $payment_form_submission; |
|
19 | - |
|
20 | - /** |
|
21 | - * Class constructor. |
|
22 | - * |
|
23 | - * @param GetPaid_Payment_Form_Submission $submission |
|
24 | - */ |
|
25 | - public function __construct( $submission ) { |
|
26 | - $this->payment_form_submission = $submission; |
|
27 | - } |
|
28 | - |
|
29 | - /** |
|
30 | - * Processes the checkout. |
|
31 | - * |
|
32 | - */ |
|
33 | - public function process_checkout() { |
|
34 | - |
|
35 | - // Validate the submission. |
|
36 | - $this->validate_submission(); |
|
37 | - |
|
38 | - // Prepare the invoice. |
|
39 | - $items = $this->get_submission_items(); |
|
40 | - $invoice = $this->get_submission_invoice(); |
|
41 | - $invoice = $this->process_submission_invoice( $invoice, $items ); |
|
42 | - $prepared = $this->prepare_submission_data_for_saving(); |
|
43 | - |
|
44 | - $this->prepare_billing_info( $invoice ); |
|
45 | - |
|
46 | - $shipping = $this->prepare_shipping_info( $invoice ); |
|
47 | - |
|
48 | - // Save the invoice. |
|
49 | - $invoice->set_is_viewed( true ); |
|
50 | - $invoice->recalculate_total(); |
|
15 | + /** |
|
16 | + * @var GetPaid_Payment_Form_Submission |
|
17 | + */ |
|
18 | + protected $payment_form_submission; |
|
19 | + |
|
20 | + /** |
|
21 | + * Class constructor. |
|
22 | + * |
|
23 | + * @param GetPaid_Payment_Form_Submission $submission |
|
24 | + */ |
|
25 | + public function __construct( $submission ) { |
|
26 | + $this->payment_form_submission = $submission; |
|
27 | + } |
|
28 | + |
|
29 | + /** |
|
30 | + * Processes the checkout. |
|
31 | + * |
|
32 | + */ |
|
33 | + public function process_checkout() { |
|
34 | + |
|
35 | + // Validate the submission. |
|
36 | + $this->validate_submission(); |
|
37 | + |
|
38 | + // Prepare the invoice. |
|
39 | + $items = $this->get_submission_items(); |
|
40 | + $invoice = $this->get_submission_invoice(); |
|
41 | + $invoice = $this->process_submission_invoice( $invoice, $items ); |
|
42 | + $prepared = $this->prepare_submission_data_for_saving(); |
|
43 | + |
|
44 | + $this->prepare_billing_info( $invoice ); |
|
45 | + |
|
46 | + $shipping = $this->prepare_shipping_info( $invoice ); |
|
47 | + |
|
48 | + // Save the invoice. |
|
49 | + $invoice->set_is_viewed( true ); |
|
50 | + $invoice->recalculate_total(); |
|
51 | 51 | $invoice->save(); |
52 | 52 | |
53 | - do_action( 'getpaid_checkout_invoice_updated', $invoice ); |
|
53 | + do_action( 'getpaid_checkout_invoice_updated', $invoice ); |
|
54 | 54 | |
55 | - // Send to the gateway. |
|
56 | - $this->post_process_submission( $invoice, $prepared, $shipping ); |
|
57 | - } |
|
55 | + // Send to the gateway. |
|
56 | + $this->post_process_submission( $invoice, $prepared, $shipping ); |
|
57 | + } |
|
58 | 58 | |
59 | - /** |
|
60 | - * Validates the submission. |
|
61 | - * |
|
62 | - */ |
|
63 | - protected function validate_submission() { |
|
59 | + /** |
|
60 | + * Validates the submission. |
|
61 | + * |
|
62 | + */ |
|
63 | + protected function validate_submission() { |
|
64 | 64 | |
65 | - $submission = $this->payment_form_submission; |
|
66 | - $data = $submission->get_data(); |
|
65 | + $submission = $this->payment_form_submission; |
|
66 | + $data = $submission->get_data(); |
|
67 | 67 | |
68 | - // Do we have an error? |
|
68 | + // Do we have an error? |
|
69 | 69 | if ( ! empty( $submission->last_error ) ) { |
70 | - wp_send_json_error( $submission->last_error ); |
|
70 | + wp_send_json_error( $submission->last_error ); |
|
71 | 71 | } |
72 | 72 | |
73 | - // We need a billing email. |
|
73 | + // We need a billing email. |
|
74 | 74 | if ( ! $submission->has_billing_email() ) { |
75 | 75 | wp_send_json_error( __( 'Provide a valid billing email.', 'invoicing' ) ); |
76 | - } |
|
76 | + } |
|
77 | 77 | |
78 | - // Non-recurring gateways should not be allowed to process recurring invoices. |
|
79 | - if ( $submission->should_collect_payment_details() && $submission->has_recurring && ! wpinv_gateway_support_subscription( $data['wpi-gateway'] ) ) { |
|
80 | - wp_send_json_error( __( 'The selected payment gateway does not support subscription payments.', 'invoicing' ) ); |
|
81 | - } |
|
78 | + // Non-recurring gateways should not be allowed to process recurring invoices. |
|
79 | + if ( $submission->should_collect_payment_details() && $submission->has_recurring && ! wpinv_gateway_support_subscription( $data['wpi-gateway'] ) ) { |
|
80 | + wp_send_json_error( __( 'The selected payment gateway does not support subscription payments.', 'invoicing' ) ); |
|
81 | + } |
|
82 | 82 | |
83 | - // Ensure the gateway is active. |
|
84 | - if ( $submission->should_collect_payment_details() && ! wpinv_is_gateway_active( $data['wpi-gateway'] ) ) { |
|
85 | - wpinv_set_error( 'invalid_gateway', __( 'The selected payment gateway is not active', 'invoicing' ) ); |
|
86 | - } |
|
83 | + // Ensure the gateway is active. |
|
84 | + if ( $submission->should_collect_payment_details() && ! wpinv_is_gateway_active( $data['wpi-gateway'] ) ) { |
|
85 | + wpinv_set_error( 'invalid_gateway', __( 'The selected payment gateway is not active', 'invoicing' ) ); |
|
86 | + } |
|
87 | 87 | |
88 | - // Clear any existing errors. |
|
89 | - wpinv_clear_errors(); |
|
88 | + // Clear any existing errors. |
|
89 | + wpinv_clear_errors(); |
|
90 | 90 | |
91 | - // Allow themes and plugins to hook to errors |
|
92 | - do_action( 'getpaid_checkout_error_checks', $submission ); |
|
91 | + // Allow themes and plugins to hook to errors |
|
92 | + do_action( 'getpaid_checkout_error_checks', $submission ); |
|
93 | 93 | |
94 | - // Do we have any errors? |
|
94 | + // Do we have any errors? |
|
95 | 95 | if ( wpinv_get_errors() ) { |
96 | 96 | wp_send_json_error( getpaid_get_errors_html() ); |
97 | - } |
|
97 | + } |
|
98 | 98 | |
99 | - } |
|
99 | + } |
|
100 | 100 | |
101 | - /** |
|
102 | - * Retrieves submission items. |
|
103 | - * |
|
104 | - * @return GetPaid_Form_Item[] |
|
105 | - */ |
|
106 | - protected function get_submission_items() { |
|
101 | + /** |
|
102 | + * Retrieves submission items. |
|
103 | + * |
|
104 | + * @return GetPaid_Form_Item[] |
|
105 | + */ |
|
106 | + protected function get_submission_items() { |
|
107 | 107 | |
108 | - $items = $this->payment_form_submission->get_items(); |
|
108 | + $items = $this->payment_form_submission->get_items(); |
|
109 | 109 | |
110 | 110 | // Ensure that we have items. |
111 | 111 | if ( empty( $items ) && ! $this->payment_form_submission->has_fees() ) { |
112 | 112 | wp_send_json_error( __( 'Please provide at least one item or amount.', 'invoicing' ) ); |
113 | - } |
|
114 | - |
|
115 | - return $items; |
|
116 | - } |
|
117 | - |
|
118 | - /** |
|
119 | - * Retrieves submission invoice. |
|
120 | - * |
|
121 | - * @return WPInv_Invoice |
|
122 | - */ |
|
123 | - protected function get_submission_invoice() { |
|
124 | - $submission = $this->payment_form_submission; |
|
125 | - |
|
126 | - if ( ! $submission->has_invoice() ) { |
|
127 | - $invoice = new WPInv_Invoice(); |
|
128 | - $invoice->created_via( 'payment_form' ); |
|
129 | - return $invoice; |
|
130 | 113 | } |
131 | 114 | |
132 | - $invoice = $submission->get_invoice(); |
|
115 | + return $items; |
|
116 | + } |
|
133 | 117 | |
134 | - // Make sure that it is neither paid or refunded. |
|
135 | - if ( $invoice->is_paid() || $invoice->is_refunded() ) { |
|
136 | - wp_send_json_error( __( 'This invoice has already been paid for.', 'invoicing' ) ); |
|
137 | - } |
|
118 | + /** |
|
119 | + * Retrieves submission invoice. |
|
120 | + * |
|
121 | + * @return WPInv_Invoice |
|
122 | + */ |
|
123 | + protected function get_submission_invoice() { |
|
124 | + $submission = $this->payment_form_submission; |
|
138 | 125 | |
139 | - return $invoice; |
|
140 | - } |
|
126 | + if ( ! $submission->has_invoice() ) { |
|
127 | + $invoice = new WPInv_Invoice(); |
|
128 | + $invoice->created_via( 'payment_form' ); |
|
129 | + return $invoice; |
|
130 | + } |
|
141 | 131 | |
142 | - /** |
|
143 | - * Processes the submission invoice. |
|
144 | - * |
|
145 | - * @param WPInv_Invoice $invoice |
|
146 | - * @param GetPaid_Form_Item[] $items |
|
147 | - * @return WPInv_Invoice |
|
148 | - */ |
|
149 | - protected function process_submission_invoice( $invoice, $items ) { |
|
132 | + $invoice = $submission->get_invoice(); |
|
150 | 133 | |
151 | - $submission = $this->payment_form_submission; |
|
152 | - $data = $submission->get_data(); |
|
134 | + // Make sure that it is neither paid or refunded. |
|
135 | + if ( $invoice->is_paid() || $invoice->is_refunded() ) { |
|
136 | + wp_send_json_error( __( 'This invoice has already been paid for.', 'invoicing' ) ); |
|
137 | + } |
|
153 | 138 | |
154 | - // Set-up the invoice details. |
|
155 | - $invoice->set_email( sanitize_email( $submission->get_billing_email() ) ); |
|
156 | - $invoice->set_user_id( $this->get_submission_customer() ); |
|
157 | - $invoice->set_payment_form( absint( $submission->get_payment_form()->get_id() ) ); |
|
139 | + return $invoice; |
|
140 | + } |
|
141 | + |
|
142 | + /** |
|
143 | + * Processes the submission invoice. |
|
144 | + * |
|
145 | + * @param WPInv_Invoice $invoice |
|
146 | + * @param GetPaid_Form_Item[] $items |
|
147 | + * @return WPInv_Invoice |
|
148 | + */ |
|
149 | + protected function process_submission_invoice( $invoice, $items ) { |
|
150 | + |
|
151 | + $submission = $this->payment_form_submission; |
|
152 | + $data = $submission->get_data(); |
|
153 | + |
|
154 | + // Set-up the invoice details. |
|
155 | + $invoice->set_email( sanitize_email( $submission->get_billing_email() ) ); |
|
156 | + $invoice->set_user_id( $this->get_submission_customer() ); |
|
157 | + $invoice->set_payment_form( absint( $submission->get_payment_form()->get_id() ) ); |
|
158 | 158 | $invoice->set_items( $items ); |
159 | 159 | $invoice->set_fees( $submission->get_fees() ); |
160 | 160 | $invoice->set_taxes( $submission->get_taxes() ); |
161 | - $invoice->set_discounts( $submission->get_discounts() ); |
|
162 | - $invoice->set_gateway( $data['wpi-gateway'] ); |
|
161 | + $invoice->set_discounts( $submission->get_discounts() ); |
|
162 | + $invoice->set_gateway( $data['wpi-gateway'] ); |
|
163 | 163 | |
164 | - $address_confirmed = $submission->get_field( 'confirm-address' ); |
|
165 | - $invoice->set_address_confirmed( ! empty( $address_confirmed ) ); |
|
164 | + $address_confirmed = $submission->get_field( 'confirm-address' ); |
|
165 | + $invoice->set_address_confirmed( ! empty( $address_confirmed ) ); |
|
166 | 166 | |
167 | - if ( $submission->has_discount_code() ) { |
|
167 | + if ( $submission->has_discount_code() ) { |
|
168 | 168 | $invoice->set_discount_code( $submission->get_discount_code() ); |
169 | - } |
|
170 | - |
|
171 | - getpaid_maybe_add_default_address( $invoice ); |
|
172 | - return $invoice; |
|
173 | - } |
|
174 | - |
|
175 | - /** |
|
176 | - * Retrieves the submission's customer. |
|
177 | - * |
|
178 | - * @return int The customer id. |
|
179 | - */ |
|
180 | - protected function get_submission_customer() { |
|
181 | - $submission = $this->payment_form_submission; |
|
182 | - |
|
183 | - // If this is an existing invoice... |
|
184 | - if ( $submission->has_invoice() ) { |
|
185 | - return $submission->get_invoice()->get_user_id(); |
|
186 | - } |
|
187 | - |
|
188 | - // (Maybe) create the user. |
|
169 | + } |
|
170 | + |
|
171 | + getpaid_maybe_add_default_address( $invoice ); |
|
172 | + return $invoice; |
|
173 | + } |
|
174 | + |
|
175 | + /** |
|
176 | + * Retrieves the submission's customer. |
|
177 | + * |
|
178 | + * @return int The customer id. |
|
179 | + */ |
|
180 | + protected function get_submission_customer() { |
|
181 | + $submission = $this->payment_form_submission; |
|
182 | + |
|
183 | + // If this is an existing invoice... |
|
184 | + if ( $submission->has_invoice() ) { |
|
185 | + return $submission->get_invoice()->get_user_id(); |
|
186 | + } |
|
187 | + |
|
188 | + // (Maybe) create the user. |
|
189 | 189 | $user = get_current_user_id(); |
190 | 190 | |
191 | 191 | if ( empty( $user ) ) { |
@@ -202,31 +202,31 @@ discard block |
||
202 | 202 | |
203 | 203 | if ( is_numeric( $user ) ) { |
204 | 204 | return $user; |
205 | - } |
|
205 | + } |
|
206 | 206 | |
207 | - return $user->ID; |
|
207 | + return $user->ID; |
|
208 | 208 | |
209 | - } |
|
209 | + } |
|
210 | 210 | |
211 | - /** |
|
211 | + /** |
|
212 | 212 | * Prepares submission data for saving to the database. |
213 | 213 | * |
214 | - * @return array |
|
214 | + * @return array |
|
215 | 215 | */ |
216 | 216 | public function prepare_submission_data_for_saving() { |
217 | 217 | |
218 | - $submission = $this->payment_form_submission; |
|
218 | + $submission = $this->payment_form_submission; |
|
219 | 219 | |
220 | - // Prepared submission details. |
|
220 | + // Prepared submission details. |
|
221 | 221 | $prepared = array(); |
222 | 222 | |
223 | 223 | // Raw submission details. |
224 | - $data = $submission->get_data(); |
|
224 | + $data = $submission->get_data(); |
|
225 | 225 | |
226 | - // Loop through the submitted details. |
|
226 | + // Loop through the submitted details. |
|
227 | 227 | foreach ( $submission->get_payment_form()->get_elements() as $field ) { |
228 | 228 | |
229 | - // Skip premade fields. |
|
229 | + // Skip premade fields. |
|
230 | 230 | if ( ! empty( $field['premade'] ) || $field['type'] == 'address' ) { |
231 | 231 | continue; |
232 | 232 | } |
@@ -244,93 +244,93 @@ discard block |
||
244 | 244 | $label = $field['label']; |
245 | 245 | } |
246 | 246 | |
247 | - $prepared[ wpinv_clean( $label ) ] = wp_kses_post( $data[ $field['id'] ] ); |
|
247 | + $prepared[ wpinv_clean( $label ) ] = wp_kses_post( $data[ $field['id'] ] ); |
|
248 | 248 | |
249 | 249 | } |
250 | 250 | |
251 | - } |
|
251 | + } |
|
252 | 252 | |
253 | - return $prepared; |
|
253 | + return $prepared; |
|
254 | 254 | |
255 | - } |
|
255 | + } |
|
256 | 256 | |
257 | - /** |
|
257 | + /** |
|
258 | 258 | * Retrieves address details. |
259 | 259 | * |
260 | - * @return array |
|
261 | - * @param WPInv_Invoice $invoice |
|
262 | - * @param string $type |
|
260 | + * @return array |
|
261 | + * @param WPInv_Invoice $invoice |
|
262 | + * @param string $type |
|
263 | 263 | */ |
264 | 264 | public function prepare_address_details( $invoice, $type = 'billing' ) { |
265 | 265 | |
266 | - $data = $this->payment_form_submission->get_data(); |
|
267 | - $type = sanitize_key( $type ); |
|
268 | - $address = array(); |
|
269 | - $prepared = array(); |
|
266 | + $data = $this->payment_form_submission->get_data(); |
|
267 | + $type = sanitize_key( $type ); |
|
268 | + $address = array(); |
|
269 | + $prepared = array(); |
|
270 | 270 | |
271 | - if ( ! empty( $data[ $type ] ) ) { |
|
272 | - $address = $data[ $type ]; |
|
273 | - } |
|
271 | + if ( ! empty( $data[ $type ] ) ) { |
|
272 | + $address = $data[ $type ]; |
|
273 | + } |
|
274 | 274 | |
275 | - // Clean address details. |
|
276 | - foreach ( $address as $key => $value ) { |
|
277 | - $key = sanitize_key( $key ); |
|
278 | - $key = str_replace( 'wpinv_', '', $key ); |
|
279 | - $value = wpinv_clean( $value ); |
|
280 | - $prepared[ $key] = apply_filters( "getpaid_checkout_{$type}_address_$key", $value, $this->payment_form_submission, $invoice ); |
|
281 | - } |
|
275 | + // Clean address details. |
|
276 | + foreach ( $address as $key => $value ) { |
|
277 | + $key = sanitize_key( $key ); |
|
278 | + $key = str_replace( 'wpinv_', '', $key ); |
|
279 | + $value = wpinv_clean( $value ); |
|
280 | + $prepared[ $key] = apply_filters( "getpaid_checkout_{$type}_address_$key", $value, $this->payment_form_submission, $invoice ); |
|
281 | + } |
|
282 | 282 | |
283 | - // Filter address details. |
|
284 | - $prepared = apply_filters( "getpaid_checkout_{$type}_address", $prepared, $this->payment_form_submission, $invoice ); |
|
283 | + // Filter address details. |
|
284 | + $prepared = apply_filters( "getpaid_checkout_{$type}_address", $prepared, $this->payment_form_submission, $invoice ); |
|
285 | 285 | |
286 | - // Remove non-whitelisted values. |
|
287 | - return array_filter( $prepared, 'getpaid_is_address_field_whitelisted', ARRAY_FILTER_USE_KEY ); |
|
286 | + // Remove non-whitelisted values. |
|
287 | + return array_filter( $prepared, 'getpaid_is_address_field_whitelisted', ARRAY_FILTER_USE_KEY ); |
|
288 | 288 | |
289 | - } |
|
289 | + } |
|
290 | 290 | |
291 | - /** |
|
291 | + /** |
|
292 | 292 | * Prepares the billing details. |
293 | 293 | * |
294 | - * @return array |
|
295 | - * @param WPInv_Invoice $invoice |
|
294 | + * @return array |
|
295 | + * @param WPInv_Invoice $invoice |
|
296 | 296 | */ |
297 | 297 | protected function prepare_billing_info( &$invoice ) { |
298 | 298 | |
299 | - $billing_address = $this->prepare_address_details( $invoice, 'billing' ); |
|
299 | + $billing_address = $this->prepare_address_details( $invoice, 'billing' ); |
|
300 | 300 | |
301 | - // Update the invoice with the billing details. |
|
302 | - $invoice->set_props( $billing_address ); |
|
301 | + // Update the invoice with the billing details. |
|
302 | + $invoice->set_props( $billing_address ); |
|
303 | 303 | |
304 | - } |
|
304 | + } |
|
305 | 305 | |
306 | - /** |
|
306 | + /** |
|
307 | 307 | * Prepares the shipping details. |
308 | 308 | * |
309 | - * @return array |
|
310 | - * @param WPInv_Invoice $invoice |
|
309 | + * @return array |
|
310 | + * @param WPInv_Invoice $invoice |
|
311 | 311 | */ |
312 | 312 | protected function prepare_shipping_info( $invoice ) { |
313 | 313 | |
314 | - $data = $this->payment_form_submission->get_data(); |
|
314 | + $data = $this->payment_form_submission->get_data(); |
|
315 | 315 | |
316 | - if ( empty( $data['same-shipping-address'] ) ) { |
|
317 | - return $this->prepare_address_details( $invoice, 'shipping' ); |
|
318 | - } |
|
316 | + if ( empty( $data['same-shipping-address'] ) ) { |
|
317 | + return $this->prepare_address_details( $invoice, 'shipping' ); |
|
318 | + } |
|
319 | 319 | |
320 | - return $this->prepare_address_details( $invoice, 'billing' ); |
|
320 | + return $this->prepare_address_details( $invoice, 'billing' ); |
|
321 | 321 | |
322 | - } |
|
322 | + } |
|
323 | 323 | |
324 | - /** |
|
325 | - * Confirms the submission is valid and send users to the gateway. |
|
326 | - * |
|
327 | - * @param WPInv_Invoice $invoice |
|
328 | - * @param array $prepared_payment_form_data |
|
329 | - * @param array $shipping |
|
330 | - */ |
|
331 | - protected function post_process_submission( $invoice, $prepared_payment_form_data, $shipping ) { |
|
324 | + /** |
|
325 | + * Confirms the submission is valid and send users to the gateway. |
|
326 | + * |
|
327 | + * @param WPInv_Invoice $invoice |
|
328 | + * @param array $prepared_payment_form_data |
|
329 | + * @param array $shipping |
|
330 | + */ |
|
331 | + protected function post_process_submission( $invoice, $prepared_payment_form_data, $shipping ) { |
|
332 | 332 | |
333 | - // Ensure the invoice exists. |
|
333 | + // Ensure the invoice exists. |
|
334 | 334 | if ( ! $invoice->exists() ) { |
335 | 335 | wp_send_json_error( __( 'An error occured while saving your invoice. Please try again.', 'invoicing' ) ); |
336 | 336 | } |
@@ -338,81 +338,81 @@ discard block |
||
338 | 338 | // Save payment form data. |
339 | 339 | if ( ! empty( $prepared_payment_form_data ) ) { |
340 | 340 | update_post_meta( $invoice->get_id(), 'payment_form_data', $prepared_payment_form_data ); |
341 | - } |
|
341 | + } |
|
342 | 342 | |
343 | - // Save payment form data. |
|
343 | + // Save payment form data. |
|
344 | 344 | if ( ! empty( $shipping ) ) { |
345 | 345 | update_post_meta( $invoice->get_id(), 'shipping_address', $shipping ); |
346 | - } |
|
346 | + } |
|
347 | 347 | |
348 | - // Backwards compatibility. |
|
348 | + // Backwards compatibility. |
|
349 | 349 | add_filter( 'wp_redirect', array( $this, 'send_redirect_response' ) ); |
350 | 350 | |
351 | - $this->process_payment( $invoice ); |
|
351 | + $this->process_payment( $invoice ); |
|
352 | 352 | |
353 | 353 | // If we are here, there was an error. |
354 | - wpinv_send_back_to_checkout( $invoice ); |
|
354 | + wpinv_send_back_to_checkout( $invoice ); |
|
355 | 355 | |
356 | - } |
|
356 | + } |
|
357 | 357 | |
358 | - /** |
|
359 | - * Processes the actual payment. |
|
360 | - * |
|
361 | - * @param WPInv_Invoice $invoice |
|
362 | - */ |
|
363 | - protected function process_payment( $invoice ) { |
|
358 | + /** |
|
359 | + * Processes the actual payment. |
|
360 | + * |
|
361 | + * @param WPInv_Invoice $invoice |
|
362 | + */ |
|
363 | + protected function process_payment( $invoice ) { |
|
364 | 364 | |
365 | - // Clear any checkout errors. |
|
366 | - wpinv_clear_errors(); |
|
365 | + // Clear any checkout errors. |
|
366 | + wpinv_clear_errors(); |
|
367 | 367 | |
368 | - // No need to send free invoices to the gateway. |
|
369 | - if ( $invoice->is_free() ) { |
|
370 | - $this->process_free_payment( $invoice ); |
|
371 | - } |
|
368 | + // No need to send free invoices to the gateway. |
|
369 | + if ( $invoice->is_free() ) { |
|
370 | + $this->process_free_payment( $invoice ); |
|
371 | + } |
|
372 | 372 | |
373 | - $submission = $this->payment_form_submission; |
|
373 | + $submission = $this->payment_form_submission; |
|
374 | 374 | |
375 | - // Fires before sending to the gateway. |
|
376 | - do_action( 'getpaid_checkout_before_gateway', $invoice, $submission ); |
|
375 | + // Fires before sending to the gateway. |
|
376 | + do_action( 'getpaid_checkout_before_gateway', $invoice, $submission ); |
|
377 | 377 | |
378 | - // Allow the sumission data to be modified before it is sent to the gateway. |
|
379 | - $submission_data = $submission->get_data(); |
|
380 | - $submission_gateway = apply_filters( 'getpaid_gateway_submission_gateway', $invoice->get_gateway(), $submission, $invoice ); |
|
381 | - $submission_data = apply_filters( 'getpaid_gateway_submission_data', $submission_data, $submission, $invoice ); |
|
378 | + // Allow the sumission data to be modified before it is sent to the gateway. |
|
379 | + $submission_data = $submission->get_data(); |
|
380 | + $submission_gateway = apply_filters( 'getpaid_gateway_submission_gateway', $invoice->get_gateway(), $submission, $invoice ); |
|
381 | + $submission_data = apply_filters( 'getpaid_gateway_submission_data', $submission_data, $submission, $invoice ); |
|
382 | 382 | |
383 | - // Validate the currency. |
|
384 | - if ( ! apply_filters( "getpaid_gateway_{$submission_gateway}_is_valid_for_currency", true, $invoice->get_currency() ) ) { |
|
385 | - wpinv_set_error( 'invalid_currency', __( 'The chosen payment gateway does not support this currency', 'invoicing' ) ); |
|
386 | - } |
|
383 | + // Validate the currency. |
|
384 | + if ( ! apply_filters( "getpaid_gateway_{$submission_gateway}_is_valid_for_currency", true, $invoice->get_currency() ) ) { |
|
385 | + wpinv_set_error( 'invalid_currency', __( 'The chosen payment gateway does not support this currency', 'invoicing' ) ); |
|
386 | + } |
|
387 | 387 | |
388 | - // Check to see if we have any errors. |
|
389 | - if ( wpinv_get_errors() ) { |
|
390 | - wpinv_send_back_to_checkout( $invoice ); |
|
391 | - } |
|
388 | + // Check to see if we have any errors. |
|
389 | + if ( wpinv_get_errors() ) { |
|
390 | + wpinv_send_back_to_checkout( $invoice ); |
|
391 | + } |
|
392 | 392 | |
393 | - // Send info to the gateway for payment processing |
|
394 | - do_action( "getpaid_gateway_$submission_gateway", $invoice, $submission_data, $submission ); |
|
393 | + // Send info to the gateway for payment processing |
|
394 | + do_action( "getpaid_gateway_$submission_gateway", $invoice, $submission_data, $submission ); |
|
395 | 395 | |
396 | - // Backwards compatibility. |
|
397 | - wpinv_send_to_gateway( $submission_gateway, $invoice ); |
|
396 | + // Backwards compatibility. |
|
397 | + wpinv_send_to_gateway( $submission_gateway, $invoice ); |
|
398 | 398 | |
399 | - } |
|
399 | + } |
|
400 | 400 | |
401 | - /** |
|
402 | - * Marks the invoice as paid in case the checkout is free. |
|
403 | - * |
|
404 | - * @param WPInv_Invoice $invoice |
|
405 | - */ |
|
406 | - protected function process_free_payment( $invoice ) { |
|
401 | + /** |
|
402 | + * Marks the invoice as paid in case the checkout is free. |
|
403 | + * |
|
404 | + * @param WPInv_Invoice $invoice |
|
405 | + */ |
|
406 | + protected function process_free_payment( $invoice ) { |
|
407 | 407 | |
408 | - $invoice->set_gateway( 'none' ); |
|
409 | - $invoice->add_note( __( "This is a free invoice and won't be sent to the payment gateway", 'invoicing' ), false, false, true ); |
|
410 | - $invoice->mark_paid(); |
|
411 | - wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) ); |
|
408 | + $invoice->set_gateway( 'none' ); |
|
409 | + $invoice->add_note( __( "This is a free invoice and won't be sent to the payment gateway", 'invoicing' ), false, false, true ); |
|
410 | + $invoice->mark_paid(); |
|
411 | + wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) ); |
|
412 | 412 | |
413 | - } |
|
413 | + } |
|
414 | 414 | |
415 | - /** |
|
415 | + /** |
|
416 | 416 | * Sends a redrect response to payment details. |
417 | 417 | * |
418 | 418 | */ |
@@ -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 | * Main Checkout Class. |
@@ -22,7 +22,7 @@ discard block |
||
22 | 22 | * |
23 | 23 | * @param GetPaid_Payment_Form_Submission $submission |
24 | 24 | */ |
25 | - public function __construct( $submission ) { |
|
25 | + public function __construct($submission) { |
|
26 | 26 | $this->payment_form_submission = $submission; |
27 | 27 | } |
28 | 28 | |
@@ -38,22 +38,22 @@ discard block |
||
38 | 38 | // Prepare the invoice. |
39 | 39 | $items = $this->get_submission_items(); |
40 | 40 | $invoice = $this->get_submission_invoice(); |
41 | - $invoice = $this->process_submission_invoice( $invoice, $items ); |
|
41 | + $invoice = $this->process_submission_invoice($invoice, $items); |
|
42 | 42 | $prepared = $this->prepare_submission_data_for_saving(); |
43 | 43 | |
44 | - $this->prepare_billing_info( $invoice ); |
|
44 | + $this->prepare_billing_info($invoice); |
|
45 | 45 | |
46 | - $shipping = $this->prepare_shipping_info( $invoice ); |
|
46 | + $shipping = $this->prepare_shipping_info($invoice); |
|
47 | 47 | |
48 | 48 | // Save the invoice. |
49 | - $invoice->set_is_viewed( true ); |
|
49 | + $invoice->set_is_viewed(true); |
|
50 | 50 | $invoice->recalculate_total(); |
51 | 51 | $invoice->save(); |
52 | 52 | |
53 | - do_action( 'getpaid_checkout_invoice_updated', $invoice ); |
|
53 | + do_action('getpaid_checkout_invoice_updated', $invoice); |
|
54 | 54 | |
55 | 55 | // Send to the gateway. |
56 | - $this->post_process_submission( $invoice, $prepared, $shipping ); |
|
56 | + $this->post_process_submission($invoice, $prepared, $shipping); |
|
57 | 57 | } |
58 | 58 | |
59 | 59 | /** |
@@ -66,34 +66,34 @@ discard block |
||
66 | 66 | $data = $submission->get_data(); |
67 | 67 | |
68 | 68 | // Do we have an error? |
69 | - if ( ! empty( $submission->last_error ) ) { |
|
70 | - wp_send_json_error( $submission->last_error ); |
|
69 | + if (!empty($submission->last_error)) { |
|
70 | + wp_send_json_error($submission->last_error); |
|
71 | 71 | } |
72 | 72 | |
73 | 73 | // We need a billing email. |
74 | - if ( ! $submission->has_billing_email() ) { |
|
75 | - wp_send_json_error( __( 'Provide a valid billing email.', 'invoicing' ) ); |
|
74 | + if (!$submission->has_billing_email()) { |
|
75 | + wp_send_json_error(__('Provide a valid billing email.', 'invoicing')); |
|
76 | 76 | } |
77 | 77 | |
78 | 78 | // Non-recurring gateways should not be allowed to process recurring invoices. |
79 | - if ( $submission->should_collect_payment_details() && $submission->has_recurring && ! wpinv_gateway_support_subscription( $data['wpi-gateway'] ) ) { |
|
80 | - wp_send_json_error( __( 'The selected payment gateway does not support subscription payments.', 'invoicing' ) ); |
|
79 | + if ($submission->should_collect_payment_details() && $submission->has_recurring && !wpinv_gateway_support_subscription($data['wpi-gateway'])) { |
|
80 | + wp_send_json_error(__('The selected payment gateway does not support subscription payments.', 'invoicing')); |
|
81 | 81 | } |
82 | 82 | |
83 | 83 | // Ensure the gateway is active. |
84 | - if ( $submission->should_collect_payment_details() && ! wpinv_is_gateway_active( $data['wpi-gateway'] ) ) { |
|
85 | - wpinv_set_error( 'invalid_gateway', __( 'The selected payment gateway is not active', 'invoicing' ) ); |
|
84 | + if ($submission->should_collect_payment_details() && !wpinv_is_gateway_active($data['wpi-gateway'])) { |
|
85 | + wpinv_set_error('invalid_gateway', __('The selected payment gateway is not active', 'invoicing')); |
|
86 | 86 | } |
87 | 87 | |
88 | 88 | // Clear any existing errors. |
89 | 89 | wpinv_clear_errors(); |
90 | 90 | |
91 | 91 | // Allow themes and plugins to hook to errors |
92 | - do_action( 'getpaid_checkout_error_checks', $submission ); |
|
92 | + do_action('getpaid_checkout_error_checks', $submission); |
|
93 | 93 | |
94 | 94 | // Do we have any errors? |
95 | - if ( wpinv_get_errors() ) { |
|
96 | - wp_send_json_error( getpaid_get_errors_html() ); |
|
95 | + if (wpinv_get_errors()) { |
|
96 | + wp_send_json_error(getpaid_get_errors_html()); |
|
97 | 97 | } |
98 | 98 | |
99 | 99 | } |
@@ -108,8 +108,8 @@ discard block |
||
108 | 108 | $items = $this->payment_form_submission->get_items(); |
109 | 109 | |
110 | 110 | // Ensure that we have items. |
111 | - if ( empty( $items ) && ! $this->payment_form_submission->has_fees() ) { |
|
112 | - wp_send_json_error( __( 'Please provide at least one item or amount.', 'invoicing' ) ); |
|
111 | + if (empty($items) && !$this->payment_form_submission->has_fees()) { |
|
112 | + wp_send_json_error(__('Please provide at least one item or amount.', 'invoicing')); |
|
113 | 113 | } |
114 | 114 | |
115 | 115 | return $items; |
@@ -123,17 +123,17 @@ discard block |
||
123 | 123 | protected function get_submission_invoice() { |
124 | 124 | $submission = $this->payment_form_submission; |
125 | 125 | |
126 | - if ( ! $submission->has_invoice() ) { |
|
126 | + if (!$submission->has_invoice()) { |
|
127 | 127 | $invoice = new WPInv_Invoice(); |
128 | - $invoice->created_via( 'payment_form' ); |
|
128 | + $invoice->created_via('payment_form'); |
|
129 | 129 | return $invoice; |
130 | 130 | } |
131 | 131 | |
132 | 132 | $invoice = $submission->get_invoice(); |
133 | 133 | |
134 | 134 | // Make sure that it is neither paid or refunded. |
135 | - if ( $invoice->is_paid() || $invoice->is_refunded() ) { |
|
136 | - wp_send_json_error( __( 'This invoice has already been paid for.', 'invoicing' ) ); |
|
135 | + if ($invoice->is_paid() || $invoice->is_refunded()) { |
|
136 | + wp_send_json_error(__('This invoice has already been paid for.', 'invoicing')); |
|
137 | 137 | } |
138 | 138 | |
139 | 139 | return $invoice; |
@@ -146,29 +146,29 @@ discard block |
||
146 | 146 | * @param GetPaid_Form_Item[] $items |
147 | 147 | * @return WPInv_Invoice |
148 | 148 | */ |
149 | - protected function process_submission_invoice( $invoice, $items ) { |
|
149 | + protected function process_submission_invoice($invoice, $items) { |
|
150 | 150 | |
151 | 151 | $submission = $this->payment_form_submission; |
152 | 152 | $data = $submission->get_data(); |
153 | 153 | |
154 | 154 | // Set-up the invoice details. |
155 | - $invoice->set_email( sanitize_email( $submission->get_billing_email() ) ); |
|
156 | - $invoice->set_user_id( $this->get_submission_customer() ); |
|
157 | - $invoice->set_payment_form( absint( $submission->get_payment_form()->get_id() ) ); |
|
158 | - $invoice->set_items( $items ); |
|
159 | - $invoice->set_fees( $submission->get_fees() ); |
|
160 | - $invoice->set_taxes( $submission->get_taxes() ); |
|
161 | - $invoice->set_discounts( $submission->get_discounts() ); |
|
162 | - $invoice->set_gateway( $data['wpi-gateway'] ); |
|
163 | - |
|
164 | - $address_confirmed = $submission->get_field( 'confirm-address' ); |
|
165 | - $invoice->set_address_confirmed( ! empty( $address_confirmed ) ); |
|
166 | - |
|
167 | - if ( $submission->has_discount_code() ) { |
|
168 | - $invoice->set_discount_code( $submission->get_discount_code() ); |
|
155 | + $invoice->set_email(sanitize_email($submission->get_billing_email())); |
|
156 | + $invoice->set_user_id($this->get_submission_customer()); |
|
157 | + $invoice->set_payment_form(absint($submission->get_payment_form()->get_id())); |
|
158 | + $invoice->set_items($items); |
|
159 | + $invoice->set_fees($submission->get_fees()); |
|
160 | + $invoice->set_taxes($submission->get_taxes()); |
|
161 | + $invoice->set_discounts($submission->get_discounts()); |
|
162 | + $invoice->set_gateway($data['wpi-gateway']); |
|
163 | + |
|
164 | + $address_confirmed = $submission->get_field('confirm-address'); |
|
165 | + $invoice->set_address_confirmed(!empty($address_confirmed)); |
|
166 | + |
|
167 | + if ($submission->has_discount_code()) { |
|
168 | + $invoice->set_discount_code($submission->get_discount_code()); |
|
169 | 169 | } |
170 | 170 | |
171 | - getpaid_maybe_add_default_address( $invoice ); |
|
171 | + getpaid_maybe_add_default_address($invoice); |
|
172 | 172 | return $invoice; |
173 | 173 | } |
174 | 174 | |
@@ -181,26 +181,26 @@ discard block |
||
181 | 181 | $submission = $this->payment_form_submission; |
182 | 182 | |
183 | 183 | // If this is an existing invoice... |
184 | - if ( $submission->has_invoice() ) { |
|
184 | + if ($submission->has_invoice()) { |
|
185 | 185 | return $submission->get_invoice()->get_user_id(); |
186 | 186 | } |
187 | 187 | |
188 | 188 | // (Maybe) create the user. |
189 | 189 | $user = get_current_user_id(); |
190 | 190 | |
191 | - if ( empty( $user ) ) { |
|
192 | - $user = get_user_by( 'email', $submission->get_billing_email() ); |
|
191 | + if (empty($user)) { |
|
192 | + $user = get_user_by('email', $submission->get_billing_email()); |
|
193 | 193 | } |
194 | 194 | |
195 | - if ( empty( $user ) ) { |
|
196 | - $user = wpinv_create_user( $submission->get_billing_email() ); |
|
195 | + if (empty($user)) { |
|
196 | + $user = wpinv_create_user($submission->get_billing_email()); |
|
197 | 197 | } |
198 | 198 | |
199 | - if ( is_wp_error( $user ) ) { |
|
200 | - wp_send_json_error( $user->get_error_message() ); |
|
199 | + if (is_wp_error($user)) { |
|
200 | + wp_send_json_error($user->get_error_message()); |
|
201 | 201 | } |
202 | 202 | |
203 | - if ( is_numeric( $user ) ) { |
|
203 | + if (is_numeric($user)) { |
|
204 | 204 | return $user; |
205 | 205 | } |
206 | 206 | |
@@ -221,30 +221,30 @@ discard block |
||
221 | 221 | $prepared = array(); |
222 | 222 | |
223 | 223 | // Raw submission details. |
224 | - $data = $submission->get_data(); |
|
224 | + $data = $submission->get_data(); |
|
225 | 225 | |
226 | 226 | // Loop through the submitted details. |
227 | - foreach ( $submission->get_payment_form()->get_elements() as $field ) { |
|
227 | + foreach ($submission->get_payment_form()->get_elements() as $field) { |
|
228 | 228 | |
229 | 229 | // Skip premade fields. |
230 | - if ( ! empty( $field['premade'] ) || $field['type'] == 'address' ) { |
|
230 | + if (!empty($field['premade']) || $field['type'] == 'address') { |
|
231 | 231 | continue; |
232 | 232 | } |
233 | 233 | |
234 | 234 | // If it is required and not set, abort. |
235 | - if ( ! $submission->is_required_field_set( $field ) ) { |
|
236 | - wp_send_json_error( __( 'Please fill all required fields.', 'invoicing' ) ); |
|
235 | + if (!$submission->is_required_field_set($field)) { |
|
236 | + wp_send_json_error(__('Please fill all required fields.', 'invoicing')); |
|
237 | 237 | } |
238 | 238 | |
239 | 239 | // Handle misc fields. |
240 | - if ( isset( $data[ $field['id'] ] ) ) { |
|
240 | + if (isset($data[$field['id']])) { |
|
241 | 241 | $label = $field['id']; |
242 | 242 | |
243 | - if ( isset( $field['label'] ) ) { |
|
243 | + if (isset($field['label'])) { |
|
244 | 244 | $label = $field['label']; |
245 | 245 | } |
246 | 246 | |
247 | - $prepared[ wpinv_clean( $label ) ] = wp_kses_post( $data[ $field['id'] ] ); |
|
247 | + $prepared[wpinv_clean($label)] = wp_kses_post($data[$field['id']]); |
|
248 | 248 | |
249 | 249 | } |
250 | 250 | |
@@ -261,30 +261,30 @@ discard block |
||
261 | 261 | * @param WPInv_Invoice $invoice |
262 | 262 | * @param string $type |
263 | 263 | */ |
264 | - public function prepare_address_details( $invoice, $type = 'billing' ) { |
|
264 | + public function prepare_address_details($invoice, $type = 'billing') { |
|
265 | 265 | |
266 | 266 | $data = $this->payment_form_submission->get_data(); |
267 | - $type = sanitize_key( $type ); |
|
267 | + $type = sanitize_key($type); |
|
268 | 268 | $address = array(); |
269 | 269 | $prepared = array(); |
270 | 270 | |
271 | - if ( ! empty( $data[ $type ] ) ) { |
|
272 | - $address = $data[ $type ]; |
|
271 | + if (!empty($data[$type])) { |
|
272 | + $address = $data[$type]; |
|
273 | 273 | } |
274 | 274 | |
275 | 275 | // Clean address details. |
276 | - foreach ( $address as $key => $value ) { |
|
277 | - $key = sanitize_key( $key ); |
|
278 | - $key = str_replace( 'wpinv_', '', $key ); |
|
279 | - $value = wpinv_clean( $value ); |
|
280 | - $prepared[ $key] = apply_filters( "getpaid_checkout_{$type}_address_$key", $value, $this->payment_form_submission, $invoice ); |
|
276 | + foreach ($address as $key => $value) { |
|
277 | + $key = sanitize_key($key); |
|
278 | + $key = str_replace('wpinv_', '', $key); |
|
279 | + $value = wpinv_clean($value); |
|
280 | + $prepared[$key] = apply_filters("getpaid_checkout_{$type}_address_$key", $value, $this->payment_form_submission, $invoice); |
|
281 | 281 | } |
282 | 282 | |
283 | 283 | // Filter address details. |
284 | - $prepared = apply_filters( "getpaid_checkout_{$type}_address", $prepared, $this->payment_form_submission, $invoice ); |
|
284 | + $prepared = apply_filters("getpaid_checkout_{$type}_address", $prepared, $this->payment_form_submission, $invoice); |
|
285 | 285 | |
286 | 286 | // Remove non-whitelisted values. |
287 | - return array_filter( $prepared, 'getpaid_is_address_field_whitelisted', ARRAY_FILTER_USE_KEY ); |
|
287 | + return array_filter($prepared, 'getpaid_is_address_field_whitelisted', ARRAY_FILTER_USE_KEY); |
|
288 | 288 | |
289 | 289 | } |
290 | 290 | |
@@ -294,12 +294,12 @@ discard block |
||
294 | 294 | * @return array |
295 | 295 | * @param WPInv_Invoice $invoice |
296 | 296 | */ |
297 | - protected function prepare_billing_info( &$invoice ) { |
|
297 | + protected function prepare_billing_info(&$invoice) { |
|
298 | 298 | |
299 | - $billing_address = $this->prepare_address_details( $invoice, 'billing' ); |
|
299 | + $billing_address = $this->prepare_address_details($invoice, 'billing'); |
|
300 | 300 | |
301 | 301 | // Update the invoice with the billing details. |
302 | - $invoice->set_props( $billing_address ); |
|
302 | + $invoice->set_props($billing_address); |
|
303 | 303 | |
304 | 304 | } |
305 | 305 | |
@@ -309,15 +309,15 @@ discard block |
||
309 | 309 | * @return array |
310 | 310 | * @param WPInv_Invoice $invoice |
311 | 311 | */ |
312 | - protected function prepare_shipping_info( $invoice ) { |
|
312 | + protected function prepare_shipping_info($invoice) { |
|
313 | 313 | |
314 | 314 | $data = $this->payment_form_submission->get_data(); |
315 | 315 | |
316 | - if ( empty( $data['same-shipping-address'] ) ) { |
|
317 | - return $this->prepare_address_details( $invoice, 'shipping' ); |
|
316 | + if (empty($data['same-shipping-address'])) { |
|
317 | + return $this->prepare_address_details($invoice, 'shipping'); |
|
318 | 318 | } |
319 | 319 | |
320 | - return $this->prepare_address_details( $invoice, 'billing' ); |
|
320 | + return $this->prepare_address_details($invoice, 'billing'); |
|
321 | 321 | |
322 | 322 | } |
323 | 323 | |
@@ -328,30 +328,30 @@ discard block |
||
328 | 328 | * @param array $prepared_payment_form_data |
329 | 329 | * @param array $shipping |
330 | 330 | */ |
331 | - protected function post_process_submission( $invoice, $prepared_payment_form_data, $shipping ) { |
|
331 | + protected function post_process_submission($invoice, $prepared_payment_form_data, $shipping) { |
|
332 | 332 | |
333 | 333 | // Ensure the invoice exists. |
334 | - if ( ! $invoice->exists() ) { |
|
335 | - wp_send_json_error( __( 'An error occured while saving your invoice. Please try again.', 'invoicing' ) ); |
|
334 | + if (!$invoice->exists()) { |
|
335 | + wp_send_json_error(__('An error occured while saving your invoice. Please try again.', 'invoicing')); |
|
336 | 336 | } |
337 | 337 | |
338 | 338 | // Save payment form data. |
339 | - if ( ! empty( $prepared_payment_form_data ) ) { |
|
340 | - update_post_meta( $invoice->get_id(), 'payment_form_data', $prepared_payment_form_data ); |
|
339 | + if (!empty($prepared_payment_form_data)) { |
|
340 | + update_post_meta($invoice->get_id(), 'payment_form_data', $prepared_payment_form_data); |
|
341 | 341 | } |
342 | 342 | |
343 | 343 | // Save payment form data. |
344 | - if ( ! empty( $shipping ) ) { |
|
345 | - update_post_meta( $invoice->get_id(), 'shipping_address', $shipping ); |
|
344 | + if (!empty($shipping)) { |
|
345 | + update_post_meta($invoice->get_id(), 'shipping_address', $shipping); |
|
346 | 346 | } |
347 | 347 | |
348 | 348 | // Backwards compatibility. |
349 | - add_filter( 'wp_redirect', array( $this, 'send_redirect_response' ) ); |
|
349 | + add_filter('wp_redirect', array($this, 'send_redirect_response')); |
|
350 | 350 | |
351 | - $this->process_payment( $invoice ); |
|
351 | + $this->process_payment($invoice); |
|
352 | 352 | |
353 | 353 | // If we are here, there was an error. |
354 | - wpinv_send_back_to_checkout( $invoice ); |
|
354 | + wpinv_send_back_to_checkout($invoice); |
|
355 | 355 | |
356 | 356 | } |
357 | 357 | |
@@ -360,41 +360,41 @@ discard block |
||
360 | 360 | * |
361 | 361 | * @param WPInv_Invoice $invoice |
362 | 362 | */ |
363 | - protected function process_payment( $invoice ) { |
|
363 | + protected function process_payment($invoice) { |
|
364 | 364 | |
365 | 365 | // Clear any checkout errors. |
366 | 366 | wpinv_clear_errors(); |
367 | 367 | |
368 | 368 | // No need to send free invoices to the gateway. |
369 | - if ( $invoice->is_free() ) { |
|
370 | - $this->process_free_payment( $invoice ); |
|
369 | + if ($invoice->is_free()) { |
|
370 | + $this->process_free_payment($invoice); |
|
371 | 371 | } |
372 | 372 | |
373 | 373 | $submission = $this->payment_form_submission; |
374 | 374 | |
375 | 375 | // Fires before sending to the gateway. |
376 | - do_action( 'getpaid_checkout_before_gateway', $invoice, $submission ); |
|
376 | + do_action('getpaid_checkout_before_gateway', $invoice, $submission); |
|
377 | 377 | |
378 | 378 | // Allow the sumission data to be modified before it is sent to the gateway. |
379 | 379 | $submission_data = $submission->get_data(); |
380 | - $submission_gateway = apply_filters( 'getpaid_gateway_submission_gateway', $invoice->get_gateway(), $submission, $invoice ); |
|
381 | - $submission_data = apply_filters( 'getpaid_gateway_submission_data', $submission_data, $submission, $invoice ); |
|
380 | + $submission_gateway = apply_filters('getpaid_gateway_submission_gateway', $invoice->get_gateway(), $submission, $invoice); |
|
381 | + $submission_data = apply_filters('getpaid_gateway_submission_data', $submission_data, $submission, $invoice); |
|
382 | 382 | |
383 | 383 | // Validate the currency. |
384 | - if ( ! apply_filters( "getpaid_gateway_{$submission_gateway}_is_valid_for_currency", true, $invoice->get_currency() ) ) { |
|
385 | - wpinv_set_error( 'invalid_currency', __( 'The chosen payment gateway does not support this currency', 'invoicing' ) ); |
|
384 | + if (!apply_filters("getpaid_gateway_{$submission_gateway}_is_valid_for_currency", true, $invoice->get_currency())) { |
|
385 | + wpinv_set_error('invalid_currency', __('The chosen payment gateway does not support this currency', 'invoicing')); |
|
386 | 386 | } |
387 | 387 | |
388 | 388 | // Check to see if we have any errors. |
389 | - if ( wpinv_get_errors() ) { |
|
390 | - wpinv_send_back_to_checkout( $invoice ); |
|
389 | + if (wpinv_get_errors()) { |
|
390 | + wpinv_send_back_to_checkout($invoice); |
|
391 | 391 | } |
392 | 392 | |
393 | 393 | // Send info to the gateway for payment processing |
394 | - do_action( "getpaid_gateway_$submission_gateway", $invoice, $submission_data, $submission ); |
|
394 | + do_action("getpaid_gateway_$submission_gateway", $invoice, $submission_data, $submission); |
|
395 | 395 | |
396 | 396 | // Backwards compatibility. |
397 | - wpinv_send_to_gateway( $submission_gateway, $invoice ); |
|
397 | + wpinv_send_to_gateway($submission_gateway, $invoice); |
|
398 | 398 | |
399 | 399 | } |
400 | 400 | |
@@ -403,12 +403,12 @@ discard block |
||
403 | 403 | * |
404 | 404 | * @param WPInv_Invoice $invoice |
405 | 405 | */ |
406 | - protected function process_free_payment( $invoice ) { |
|
406 | + protected function process_free_payment($invoice) { |
|
407 | 407 | |
408 | - $invoice->set_gateway( 'none' ); |
|
409 | - $invoice->add_note( __( "This is a free invoice and won't be sent to the payment gateway", 'invoicing' ), false, false, true ); |
|
408 | + $invoice->set_gateway('none'); |
|
409 | + $invoice->add_note(__("This is a free invoice and won't be sent to the payment gateway", 'invoicing'), false, false, true); |
|
410 | 410 | $invoice->mark_paid(); |
411 | - wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) ); |
|
411 | + wpinv_send_to_success_page(array('invoice_key' => $invoice->get_key())); |
|
412 | 412 | |
413 | 413 | } |
414 | 414 | |
@@ -416,9 +416,9 @@ discard block |
||
416 | 416 | * Sends a redrect response to payment details. |
417 | 417 | * |
418 | 418 | */ |
419 | - public function send_redirect_response( $url ) { |
|
420 | - $url = urlencode( $url ); |
|
421 | - wp_send_json_success( $url ); |
|
419 | + public function send_redirect_response($url) { |
|
420 | + $url = urlencode($url); |
|
421 | + wp_send_json_success($url); |
|
422 | 422 | } |
423 | 423 | |
424 | 424 | } |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | if ( ! defined( 'ABSPATH' ) ) { |
3 | - exit; |
|
3 | + exit; |
|
4 | 4 | } |
5 | 5 | |
6 | 6 | /** |
@@ -10,187 +10,187 @@ discard block |
||
10 | 10 | class GetPaid_Payment_Form_Submission { |
11 | 11 | |
12 | 12 | /** |
13 | - * Submission ID |
|
14 | - * |
|
15 | - * @var string |
|
16 | - */ |
|
17 | - public $id = null; |
|
18 | - |
|
19 | - /** |
|
20 | - * The raw submission data. |
|
21 | - * |
|
22 | - * @var array |
|
23 | - */ |
|
24 | - protected $data = null; |
|
25 | - |
|
26 | - /** |
|
27 | - * Submission totals |
|
28 | - * |
|
29 | - * @var array |
|
30 | - */ |
|
31 | - protected $totals = array( |
|
32 | - |
|
33 | - 'subtotal' => array( |
|
34 | - 'initial' => 0, |
|
35 | - 'recurring' => 0, |
|
36 | - ), |
|
37 | - |
|
38 | - 'discount' => array( |
|
39 | - 'initial' => 0, |
|
40 | - 'recurring' => 0, |
|
41 | - ), |
|
42 | - |
|
43 | - 'fees' => array( |
|
44 | - 'initial' => 0, |
|
45 | - 'recurring' => 0, |
|
46 | - ), |
|
47 | - |
|
48 | - 'taxes' => array( |
|
49 | - 'initial' => 0, |
|
50 | - 'recurring' => 0, |
|
51 | - ), |
|
52 | - |
|
53 | - ); |
|
54 | - |
|
55 | - /** |
|
56 | - * Sets the associated payment form. |
|
57 | - * |
|
58 | - * @var GetPaid_Payment_Form |
|
59 | - */ |
|
13 | + * Submission ID |
|
14 | + * |
|
15 | + * @var string |
|
16 | + */ |
|
17 | + public $id = null; |
|
18 | + |
|
19 | + /** |
|
20 | + * The raw submission data. |
|
21 | + * |
|
22 | + * @var array |
|
23 | + */ |
|
24 | + protected $data = null; |
|
25 | + |
|
26 | + /** |
|
27 | + * Submission totals |
|
28 | + * |
|
29 | + * @var array |
|
30 | + */ |
|
31 | + protected $totals = array( |
|
32 | + |
|
33 | + 'subtotal' => array( |
|
34 | + 'initial' => 0, |
|
35 | + 'recurring' => 0, |
|
36 | + ), |
|
37 | + |
|
38 | + 'discount' => array( |
|
39 | + 'initial' => 0, |
|
40 | + 'recurring' => 0, |
|
41 | + ), |
|
42 | + |
|
43 | + 'fees' => array( |
|
44 | + 'initial' => 0, |
|
45 | + 'recurring' => 0, |
|
46 | + ), |
|
47 | + |
|
48 | + 'taxes' => array( |
|
49 | + 'initial' => 0, |
|
50 | + 'recurring' => 0, |
|
51 | + ), |
|
52 | + |
|
53 | + ); |
|
54 | + |
|
55 | + /** |
|
56 | + * Sets the associated payment form. |
|
57 | + * |
|
58 | + * @var GetPaid_Payment_Form |
|
59 | + */ |
|
60 | 60 | protected $payment_form = null; |
61 | 61 | |
62 | 62 | /** |
63 | - * The country for the submission. |
|
64 | - * |
|
65 | - * @var string |
|
66 | - */ |
|
67 | - public $country = null; |
|
68 | - |
|
69 | - /** |
|
70 | - * The state for the submission. |
|
71 | - * |
|
72 | - * @since 1.0.19 |
|
73 | - * @var string |
|
74 | - */ |
|
75 | - public $state = null; |
|
76 | - |
|
77 | - /** |
|
78 | - * The invoice associated with the submission. |
|
79 | - * |
|
80 | - * @var WPInv_Invoice |
|
81 | - */ |
|
82 | - protected $invoice = null; |
|
83 | - |
|
84 | - /** |
|
85 | - * The recurring item for the submission. |
|
86 | - * |
|
87 | - * @var int |
|
88 | - */ |
|
89 | - public $has_recurring = 0; |
|
90 | - |
|
91 | - /** |
|
92 | - * An array of fees for the submission. |
|
93 | - * |
|
94 | - * @var array |
|
95 | - */ |
|
96 | - protected $fees = array(); |
|
97 | - |
|
98 | - /** |
|
99 | - * An array of discounts for the submission. |
|
100 | - * |
|
101 | - * @var array |
|
102 | - */ |
|
103 | - protected $discounts = array(); |
|
104 | - |
|
105 | - /** |
|
106 | - * An array of taxes for the submission. |
|
107 | - * |
|
108 | - * @var array |
|
109 | - */ |
|
110 | - protected $taxes = array(); |
|
111 | - |
|
112 | - /** |
|
113 | - * An array of items for the submission. |
|
114 | - * |
|
115 | - * @var GetPaid_Form_Item[] |
|
116 | - */ |
|
117 | - protected $items = array(); |
|
118 | - |
|
119 | - /** |
|
120 | - * The last error. |
|
121 | - * |
|
122 | - * @var string |
|
123 | - */ |
|
124 | - public $last_error = null; |
|
125 | - |
|
126 | - /** |
|
127 | - * Class constructor. |
|
128 | - * |
|
129 | - */ |
|
130 | - public function __construct() { |
|
131 | - |
|
132 | - // Set the state and country to the default state and country. |
|
133 | - $this->country = wpinv_default_billing_country(); |
|
134 | - $this->state = wpinv_get_default_state(); |
|
135 | - |
|
136 | - // Do we have an actual submission? |
|
137 | - if ( isset( $_POST['getpaid_payment_form_submission'] ) ) { |
|
138 | - $this->load_data( $_POST ); |
|
139 | - } |
|
140 | - |
|
141 | - } |
|
142 | - |
|
143 | - /** |
|
144 | - * Loads submission data. |
|
145 | - * |
|
146 | - * @param array $data |
|
147 | - */ |
|
148 | - public function load_data( $data ) { |
|
149 | - |
|
150 | - // Remove slashes from the submitted data... |
|
151 | - $data = wp_unslash( $data ); |
|
152 | - |
|
153 | - // Allow plugins to filter the data. |
|
154 | - $data = apply_filters( 'getpaid_submission_data', $data, $this ); |
|
155 | - |
|
156 | - // Cache it... |
|
157 | - $this->data = $data; |
|
158 | - |
|
159 | - // Then generate a unique id from the data. |
|
160 | - $this->id = md5( wp_json_encode( $data ) ); |
|
161 | - |
|
162 | - // Finally, process the submission. |
|
163 | - try { |
|
164 | - |
|
165 | - // Each process is passed an instance of the class (with reference) |
|
166 | - // and should throw an Exception whenever it encounters one. |
|
167 | - $processors = apply_filters( |
|
168 | - 'getpaid_payment_form_submission_processors', |
|
169 | - array( |
|
170 | - array( $this, 'process_payment_form' ), |
|
171 | - array( $this, 'process_invoice' ), |
|
172 | - array( $this, 'process_fees' ), |
|
173 | - array( $this, 'process_items' ), |
|
174 | - array( $this, 'process_taxes' ), |
|
175 | - array( $this, 'process_discount' ), |
|
176 | - ), |
|
177 | - $this |
|
178 | - ); |
|
179 | - |
|
180 | - foreach ( $processors as $processor ) { |
|
181 | - call_user_func_array( $processor, array( &$this ) ); |
|
182 | - } |
|
183 | - |
|
184 | - } catch ( Exception $e ) { |
|
185 | - $this->last_error = $e->getMessage(); |
|
186 | - } |
|
187 | - |
|
188 | - // Fired when we are done processing a submission. |
|
189 | - do_action_ref_array( 'getpaid_process_submission', array( &$this ) ); |
|
190 | - |
|
191 | - } |
|
192 | - |
|
193 | - /* |
|
63 | + * The country for the submission. |
|
64 | + * |
|
65 | + * @var string |
|
66 | + */ |
|
67 | + public $country = null; |
|
68 | + |
|
69 | + /** |
|
70 | + * The state for the submission. |
|
71 | + * |
|
72 | + * @since 1.0.19 |
|
73 | + * @var string |
|
74 | + */ |
|
75 | + public $state = null; |
|
76 | + |
|
77 | + /** |
|
78 | + * The invoice associated with the submission. |
|
79 | + * |
|
80 | + * @var WPInv_Invoice |
|
81 | + */ |
|
82 | + protected $invoice = null; |
|
83 | + |
|
84 | + /** |
|
85 | + * The recurring item for the submission. |
|
86 | + * |
|
87 | + * @var int |
|
88 | + */ |
|
89 | + public $has_recurring = 0; |
|
90 | + |
|
91 | + /** |
|
92 | + * An array of fees for the submission. |
|
93 | + * |
|
94 | + * @var array |
|
95 | + */ |
|
96 | + protected $fees = array(); |
|
97 | + |
|
98 | + /** |
|
99 | + * An array of discounts for the submission. |
|
100 | + * |
|
101 | + * @var array |
|
102 | + */ |
|
103 | + protected $discounts = array(); |
|
104 | + |
|
105 | + /** |
|
106 | + * An array of taxes for the submission. |
|
107 | + * |
|
108 | + * @var array |
|
109 | + */ |
|
110 | + protected $taxes = array(); |
|
111 | + |
|
112 | + /** |
|
113 | + * An array of items for the submission. |
|
114 | + * |
|
115 | + * @var GetPaid_Form_Item[] |
|
116 | + */ |
|
117 | + protected $items = array(); |
|
118 | + |
|
119 | + /** |
|
120 | + * The last error. |
|
121 | + * |
|
122 | + * @var string |
|
123 | + */ |
|
124 | + public $last_error = null; |
|
125 | + |
|
126 | + /** |
|
127 | + * Class constructor. |
|
128 | + * |
|
129 | + */ |
|
130 | + public function __construct() { |
|
131 | + |
|
132 | + // Set the state and country to the default state and country. |
|
133 | + $this->country = wpinv_default_billing_country(); |
|
134 | + $this->state = wpinv_get_default_state(); |
|
135 | + |
|
136 | + // Do we have an actual submission? |
|
137 | + if ( isset( $_POST['getpaid_payment_form_submission'] ) ) { |
|
138 | + $this->load_data( $_POST ); |
|
139 | + } |
|
140 | + |
|
141 | + } |
|
142 | + |
|
143 | + /** |
|
144 | + * Loads submission data. |
|
145 | + * |
|
146 | + * @param array $data |
|
147 | + */ |
|
148 | + public function load_data( $data ) { |
|
149 | + |
|
150 | + // Remove slashes from the submitted data... |
|
151 | + $data = wp_unslash( $data ); |
|
152 | + |
|
153 | + // Allow plugins to filter the data. |
|
154 | + $data = apply_filters( 'getpaid_submission_data', $data, $this ); |
|
155 | + |
|
156 | + // Cache it... |
|
157 | + $this->data = $data; |
|
158 | + |
|
159 | + // Then generate a unique id from the data. |
|
160 | + $this->id = md5( wp_json_encode( $data ) ); |
|
161 | + |
|
162 | + // Finally, process the submission. |
|
163 | + try { |
|
164 | + |
|
165 | + // Each process is passed an instance of the class (with reference) |
|
166 | + // and should throw an Exception whenever it encounters one. |
|
167 | + $processors = apply_filters( |
|
168 | + 'getpaid_payment_form_submission_processors', |
|
169 | + array( |
|
170 | + array( $this, 'process_payment_form' ), |
|
171 | + array( $this, 'process_invoice' ), |
|
172 | + array( $this, 'process_fees' ), |
|
173 | + array( $this, 'process_items' ), |
|
174 | + array( $this, 'process_taxes' ), |
|
175 | + array( $this, 'process_discount' ), |
|
176 | + ), |
|
177 | + $this |
|
178 | + ); |
|
179 | + |
|
180 | + foreach ( $processors as $processor ) { |
|
181 | + call_user_func_array( $processor, array( &$this ) ); |
|
182 | + } |
|
183 | + |
|
184 | + } catch ( Exception $e ) { |
|
185 | + $this->last_error = $e->getMessage(); |
|
186 | + } |
|
187 | + |
|
188 | + // Fired when we are done processing a submission. |
|
189 | + do_action_ref_array( 'getpaid_process_submission', array( &$this ) ); |
|
190 | + |
|
191 | + } |
|
192 | + |
|
193 | + /* |
|
194 | 194 | |-------------------------------------------------------------------------- |
195 | 195 | | Payment Forms. |
196 | 196 | |-------------------------------------------------------------------------- |
@@ -199,39 +199,39 @@ discard block |
||
199 | 199 | | submission has an active payment form etc. |
200 | 200 | */ |
201 | 201 | |
202 | - /** |
|
203 | - * Prepares the submission's payment form. |
|
204 | - * |
|
205 | - * @since 1.0.19 |
|
206 | - */ |
|
207 | - public function process_payment_form() { |
|
202 | + /** |
|
203 | + * Prepares the submission's payment form. |
|
204 | + * |
|
205 | + * @since 1.0.19 |
|
206 | + */ |
|
207 | + public function process_payment_form() { |
|
208 | 208 | |
209 | - // Every submission needs an active payment form. |
|
210 | - if ( empty( $this->data['form_id'] ) ) { |
|
211 | - throw new Exception( __( 'Missing payment form', 'invoicing' ) ); |
|
212 | - } |
|
209 | + // Every submission needs an active payment form. |
|
210 | + if ( empty( $this->data['form_id'] ) ) { |
|
211 | + throw new Exception( __( 'Missing payment form', 'invoicing' ) ); |
|
212 | + } |
|
213 | 213 | |
214 | - // Fetch the payment form. |
|
215 | - $this->payment_form = new GetPaid_Payment_Form( $this->data['form_id'] ); |
|
214 | + // Fetch the payment form. |
|
215 | + $this->payment_form = new GetPaid_Payment_Form( $this->data['form_id'] ); |
|
216 | 216 | |
217 | - if ( ! $this->payment_form->is_active() ) { |
|
218 | - throw new Exception( __( 'Payment form not active', 'invoicing' ) ); |
|
219 | - } |
|
217 | + if ( ! $this->payment_form->is_active() ) { |
|
218 | + throw new Exception( __( 'Payment form not active', 'invoicing' ) ); |
|
219 | + } |
|
220 | 220 | |
221 | - do_action_ref_array( 'getpaid_submissions_process_payment_form', array( &$this ) ); |
|
222 | - } |
|
221 | + do_action_ref_array( 'getpaid_submissions_process_payment_form', array( &$this ) ); |
|
222 | + } |
|
223 | 223 | |
224 | 224 | /** |
225 | - * Returns the payment form. |
|
226 | - * |
|
227 | - * @since 1.0.19 |
|
228 | - * @return GetPaid_Payment_Form |
|
229 | - */ |
|
230 | - public function get_payment_form() { |
|
231 | - return $this->payment_form; |
|
232 | - } |
|
225 | + * Returns the payment form. |
|
226 | + * |
|
227 | + * @since 1.0.19 |
|
228 | + * @return GetPaid_Payment_Form |
|
229 | + */ |
|
230 | + public function get_payment_form() { |
|
231 | + return $this->payment_form; |
|
232 | + } |
|
233 | 233 | |
234 | - /* |
|
234 | + /* |
|
235 | 235 | |-------------------------------------------------------------------------- |
236 | 236 | | Invoices. |
237 | 237 | |-------------------------------------------------------------------------- |
@@ -240,61 +240,61 @@ discard block |
||
240 | 240 | | might be for an existing invoice. |
241 | 241 | */ |
242 | 242 | |
243 | - /** |
|
244 | - * Prepares the submission's invoice. |
|
245 | - * |
|
246 | - * @since 1.0.19 |
|
247 | - */ |
|
248 | - public function process_invoice() { |
|
243 | + /** |
|
244 | + * Prepares the submission's invoice. |
|
245 | + * |
|
246 | + * @since 1.0.19 |
|
247 | + */ |
|
248 | + public function process_invoice() { |
|
249 | 249 | |
250 | - // Abort if there is no invoice. |
|
251 | - if ( empty( $this->data['invoice_id'] ) ) { |
|
252 | - return; |
|
253 | - } |
|
250 | + // Abort if there is no invoice. |
|
251 | + if ( empty( $this->data['invoice_id'] ) ) { |
|
252 | + return; |
|
253 | + } |
|
254 | 254 | |
255 | - // If the submission is for an existing invoice, ensure that it exists |
|
256 | - // and that it is not paid for. |
|
257 | - $invoice = wpinv_get_invoice( $this->data['invoice_id'] ); |
|
255 | + // If the submission is for an existing invoice, ensure that it exists |
|
256 | + // and that it is not paid for. |
|
257 | + $invoice = wpinv_get_invoice( $this->data['invoice_id'] ); |
|
258 | 258 | |
259 | 259 | if ( empty( $invoice ) ) { |
260 | - throw new Exception( __( 'Invalid invoice', 'invoicing' ) ); |
|
261 | - } |
|
262 | - |
|
263 | - if ( $invoice->is_paid() ) { |
|
264 | - throw new Exception( __( 'This invoice is already paid for.', 'invoicing' ) ); |
|
265 | - } |
|
266 | - |
|
267 | - $this->payment_form->set_items( $invoice->get_items() ); |
|
268 | - $this->payment_form->invoice = $invoice; |
|
269 | - |
|
270 | - $this->country = $invoice->get_country(); |
|
271 | - $this->state = $invoice->get_state(); |
|
272 | - $this->invoice = $invoice; |
|
273 | - |
|
274 | - do_action_ref_array( 'getpaid_submissions_process_invoice', array( &$this ) ); |
|
275 | - } |
|
276 | - |
|
277 | - /** |
|
278 | - * Returns the associated invoice. |
|
279 | - * |
|
280 | - * @since 1.0.19 |
|
281 | - * @return WPInv_Invoice |
|
282 | - */ |
|
283 | - public function get_invoice() { |
|
284 | - return $this->invoice; |
|
285 | - } |
|
286 | - |
|
287 | - /** |
|
288 | - * Checks whether there is an invoice associated with this submission. |
|
289 | - * |
|
290 | - * @since 1.0.19 |
|
291 | - * @return bool |
|
292 | - */ |
|
293 | - public function has_invoice() { |
|
294 | - return ! empty( $this->invoice ); |
|
295 | - } |
|
296 | - |
|
297 | - /* |
|
260 | + throw new Exception( __( 'Invalid invoice', 'invoicing' ) ); |
|
261 | + } |
|
262 | + |
|
263 | + if ( $invoice->is_paid() ) { |
|
264 | + throw new Exception( __( 'This invoice is already paid for.', 'invoicing' ) ); |
|
265 | + } |
|
266 | + |
|
267 | + $this->payment_form->set_items( $invoice->get_items() ); |
|
268 | + $this->payment_form->invoice = $invoice; |
|
269 | + |
|
270 | + $this->country = $invoice->get_country(); |
|
271 | + $this->state = $invoice->get_state(); |
|
272 | + $this->invoice = $invoice; |
|
273 | + |
|
274 | + do_action_ref_array( 'getpaid_submissions_process_invoice', array( &$this ) ); |
|
275 | + } |
|
276 | + |
|
277 | + /** |
|
278 | + * Returns the associated invoice. |
|
279 | + * |
|
280 | + * @since 1.0.19 |
|
281 | + * @return WPInv_Invoice |
|
282 | + */ |
|
283 | + public function get_invoice() { |
|
284 | + return $this->invoice; |
|
285 | + } |
|
286 | + |
|
287 | + /** |
|
288 | + * Checks whether there is an invoice associated with this submission. |
|
289 | + * |
|
290 | + * @since 1.0.19 |
|
291 | + * @return bool |
|
292 | + */ |
|
293 | + public function has_invoice() { |
|
294 | + return ! empty( $this->invoice ); |
|
295 | + } |
|
296 | + |
|
297 | + /* |
|
298 | 298 | |-------------------------------------------------------------------------- |
299 | 299 | | Items. |
300 | 300 | |-------------------------------------------------------------------------- |
@@ -303,115 +303,115 @@ discard block |
||
303 | 303 | | recurring item. But can have an unlimited number of non-recurring items. |
304 | 304 | */ |
305 | 305 | |
306 | - /** |
|
307 | - * Prepares the submission's items. |
|
308 | - * |
|
309 | - * @since 1.0.19 |
|
310 | - */ |
|
311 | - public function process_items() { |
|
312 | - |
|
313 | - $processor = new GetPaid_Payment_Form_Submission_Items( $this ); |
|
314 | - |
|
315 | - foreach ( $processor->items as $item ) { |
|
316 | - $this->add_item( $item ); |
|
317 | - } |
|
318 | - |
|
319 | - do_action_ref_array( 'getpaid_submissions_process_items', array( &$this ) ); |
|
320 | - } |
|
321 | - |
|
322 | - /** |
|
323 | - * Adds an item to the submission. |
|
324 | - * |
|
325 | - * @since 1.0.19 |
|
326 | - * @param GetPaid_Form_Item $item |
|
327 | - */ |
|
328 | - public function add_item( $item ) { |
|
329 | - |
|
330 | - // Make sure that it is available for purchase. |
|
331 | - if ( ! $item->can_purchase() || isset( $this->items[ $item->get_id() ] ) ) { |
|
332 | - return; |
|
333 | - } |
|
334 | - |
|
335 | - // Each submission can only contain one recurring item. |
|
336 | - if ( $item->is_recurring() ) { |
|
337 | - |
|
338 | - if ( $this->has_recurring != 0 ) { |
|
339 | - throw new Exception( __( 'You can only buy one recurring item at a time.', 'invoicing' ) ); |
|
340 | - } |
|
341 | - |
|
342 | - $this->has_recurring = $item->get_id(); |
|
343 | - |
|
344 | - } |
|
345 | - |
|
346 | - // Update the items and totals. |
|
347 | - $this->items[ $item->get_id() ] = $item; |
|
348 | - $this->totals['subtotal']['initial'] += $item->get_sub_total(); |
|
349 | - $this->totals['subtotal']['recurring'] += $item->get_recurring_sub_total(); |
|
350 | - |
|
351 | - } |
|
352 | - |
|
353 | - /** |
|
354 | - * Removes a specific item. |
|
355 | - * |
|
356 | - * You should not call this method after the discounts and taxes |
|
357 | - * have been calculated. |
|
358 | - * |
|
359 | - * @since 1.0.19 |
|
360 | - */ |
|
361 | - public function remove_item( $item_id ) { |
|
362 | - |
|
363 | - if ( isset( $this->items[ $item_id ] ) ) { |
|
364 | - $this->totals['subtotal']['initial'] -= $this->items[ $item_id ]->get_sub_total(); |
|
365 | - $this->totals['subtotal']['recurring'] -= $this->items[ $item_id ]->get_recurring_sub_total(); |
|
366 | - |
|
367 | - if ( $this->items[ $item_id ]->is_recurring() ) { |
|
368 | - $this->has_recurring = 0; |
|
369 | - } |
|
370 | - |
|
371 | - unset( $this->items[ $item_id ] ); |
|
372 | - } |
|
373 | - |
|
374 | - } |
|
375 | - |
|
376 | - /** |
|
377 | - * Returns the subtotal. |
|
378 | - * |
|
379 | - * @since 1.0.19 |
|
380 | - */ |
|
381 | - public function get_subtotal() { |
|
382 | - |
|
383 | - if ( wpinv_prices_include_tax() ) { |
|
384 | - return $this->totals['subtotal']['initial'] - $this->totals['taxes']['initial']; |
|
385 | - } |
|
386 | - |
|
387 | - return $this->totals['subtotal']['initial']; |
|
388 | - } |
|
389 | - |
|
390 | - /** |
|
391 | - * Returns the recurring subtotal. |
|
392 | - * |
|
393 | - * @since 1.0.19 |
|
394 | - */ |
|
395 | - public function get_recurring_subtotal() { |
|
396 | - |
|
397 | - if ( wpinv_prices_include_tax() ) { |
|
398 | - return $this->totals['subtotal']['recurring'] - $this->totals['taxes']['recurring']; |
|
399 | - } |
|
400 | - |
|
401 | - return $this->totals['subtotal']['recurring']; |
|
402 | - } |
|
403 | - |
|
404 | - /** |
|
405 | - * Returns all items. |
|
406 | - * |
|
407 | - * @since 1.0.19 |
|
408 | - * @return GetPaid_Form_Item[] |
|
409 | - */ |
|
410 | - public function get_items() { |
|
411 | - return $this->items; |
|
412 | - } |
|
413 | - |
|
414 | - /* |
|
306 | + /** |
|
307 | + * Prepares the submission's items. |
|
308 | + * |
|
309 | + * @since 1.0.19 |
|
310 | + */ |
|
311 | + public function process_items() { |
|
312 | + |
|
313 | + $processor = new GetPaid_Payment_Form_Submission_Items( $this ); |
|
314 | + |
|
315 | + foreach ( $processor->items as $item ) { |
|
316 | + $this->add_item( $item ); |
|
317 | + } |
|
318 | + |
|
319 | + do_action_ref_array( 'getpaid_submissions_process_items', array( &$this ) ); |
|
320 | + } |
|
321 | + |
|
322 | + /** |
|
323 | + * Adds an item to the submission. |
|
324 | + * |
|
325 | + * @since 1.0.19 |
|
326 | + * @param GetPaid_Form_Item $item |
|
327 | + */ |
|
328 | + public function add_item( $item ) { |
|
329 | + |
|
330 | + // Make sure that it is available for purchase. |
|
331 | + if ( ! $item->can_purchase() || isset( $this->items[ $item->get_id() ] ) ) { |
|
332 | + return; |
|
333 | + } |
|
334 | + |
|
335 | + // Each submission can only contain one recurring item. |
|
336 | + if ( $item->is_recurring() ) { |
|
337 | + |
|
338 | + if ( $this->has_recurring != 0 ) { |
|
339 | + throw new Exception( __( 'You can only buy one recurring item at a time.', 'invoicing' ) ); |
|
340 | + } |
|
341 | + |
|
342 | + $this->has_recurring = $item->get_id(); |
|
343 | + |
|
344 | + } |
|
345 | + |
|
346 | + // Update the items and totals. |
|
347 | + $this->items[ $item->get_id() ] = $item; |
|
348 | + $this->totals['subtotal']['initial'] += $item->get_sub_total(); |
|
349 | + $this->totals['subtotal']['recurring'] += $item->get_recurring_sub_total(); |
|
350 | + |
|
351 | + } |
|
352 | + |
|
353 | + /** |
|
354 | + * Removes a specific item. |
|
355 | + * |
|
356 | + * You should not call this method after the discounts and taxes |
|
357 | + * have been calculated. |
|
358 | + * |
|
359 | + * @since 1.0.19 |
|
360 | + */ |
|
361 | + public function remove_item( $item_id ) { |
|
362 | + |
|
363 | + if ( isset( $this->items[ $item_id ] ) ) { |
|
364 | + $this->totals['subtotal']['initial'] -= $this->items[ $item_id ]->get_sub_total(); |
|
365 | + $this->totals['subtotal']['recurring'] -= $this->items[ $item_id ]->get_recurring_sub_total(); |
|
366 | + |
|
367 | + if ( $this->items[ $item_id ]->is_recurring() ) { |
|
368 | + $this->has_recurring = 0; |
|
369 | + } |
|
370 | + |
|
371 | + unset( $this->items[ $item_id ] ); |
|
372 | + } |
|
373 | + |
|
374 | + } |
|
375 | + |
|
376 | + /** |
|
377 | + * Returns the subtotal. |
|
378 | + * |
|
379 | + * @since 1.0.19 |
|
380 | + */ |
|
381 | + public function get_subtotal() { |
|
382 | + |
|
383 | + if ( wpinv_prices_include_tax() ) { |
|
384 | + return $this->totals['subtotal']['initial'] - $this->totals['taxes']['initial']; |
|
385 | + } |
|
386 | + |
|
387 | + return $this->totals['subtotal']['initial']; |
|
388 | + } |
|
389 | + |
|
390 | + /** |
|
391 | + * Returns the recurring subtotal. |
|
392 | + * |
|
393 | + * @since 1.0.19 |
|
394 | + */ |
|
395 | + public function get_recurring_subtotal() { |
|
396 | + |
|
397 | + if ( wpinv_prices_include_tax() ) { |
|
398 | + return $this->totals['subtotal']['recurring'] - $this->totals['taxes']['recurring']; |
|
399 | + } |
|
400 | + |
|
401 | + return $this->totals['subtotal']['recurring']; |
|
402 | + } |
|
403 | + |
|
404 | + /** |
|
405 | + * Returns all items. |
|
406 | + * |
|
407 | + * @since 1.0.19 |
|
408 | + * @return GetPaid_Form_Item[] |
|
409 | + */ |
|
410 | + public function get_items() { |
|
411 | + return $this->items; |
|
412 | + } |
|
413 | + |
|
414 | + /* |
|
415 | 415 | |-------------------------------------------------------------------------- |
416 | 416 | | Taxes |
417 | 417 | |-------------------------------------------------------------------------- |
@@ -420,128 +420,128 @@ discard block |
||
420 | 420 | | or only one-time. |
421 | 421 | */ |
422 | 422 | |
423 | - /** |
|
424 | - * Prepares the submission's taxes. |
|
425 | - * |
|
426 | - * @since 1.0.19 |
|
427 | - */ |
|
428 | - public function process_taxes() { |
|
429 | - |
|
430 | - // Abort if we're not using taxes. |
|
431 | - if ( ! $this->use_taxes() ) { |
|
432 | - return; |
|
433 | - } |
|
434 | - |
|
435 | - // If a custom country && state has been passed in, use it to calculate taxes. |
|
436 | - $country = $this->get_field( 'wpinv_country', 'billing' ); |
|
437 | - if ( ! empty( $country ) ) { |
|
438 | - $this->country = $country; |
|
439 | - } |
|
440 | - |
|
441 | - $state = $this->get_field( 'wpinv_state', 'billing' ); |
|
442 | - if ( ! empty( $state ) ) { |
|
443 | - $this->state = $state; |
|
444 | - } |
|
445 | - |
|
446 | - // Confirm if the provided country and the ip country are similar. |
|
447 | - $address_confirmed = $this->get_field( 'confirm-address' ); |
|
448 | - if ( wpinv_should_validate_vat_number() && getpaid_get_ip_country() != $this->country && empty( $address_confirmed ) ) { |
|
449 | - throw new Exception( __( 'The country of your current location must be the same as the country of your billing location or you must confirm the billing address is your home country.', 'invoicing' ) ); |
|
450 | - } |
|
451 | - |
|
452 | - // Abort if the country is not taxable. |
|
453 | - if ( ! wpinv_is_country_taxable( $this->country ) ) { |
|
454 | - return; |
|
455 | - } |
|
456 | - |
|
457 | - $processor = new GetPaid_Payment_Form_Submission_Taxes( $this ); |
|
458 | - |
|
459 | - foreach ( $processor->taxes as $tax ) { |
|
460 | - $this->add_tax( $tax ); |
|
461 | - } |
|
462 | - |
|
463 | - do_action_ref_array( 'getpaid_submissions_process_taxes', array( &$this ) ); |
|
464 | - } |
|
465 | - |
|
466 | - /** |
|
467 | - * Adds a tax to the submission. |
|
468 | - * |
|
469 | - * @param array $tax An array of tax details. name, initial_tax, and recurring_tax are required. |
|
470 | - * @since 1.0.19 |
|
471 | - */ |
|
472 | - public function add_tax( $tax ) { |
|
473 | - |
|
474 | - if ( wpinv_round_tax_per_tax_rate() ) { |
|
475 | - $tax['initial_tax'] = wpinv_round_amount( $tax['initial_tax'] ); |
|
476 | - $tax['recurring_tax'] = wpinv_round_amount( $tax['recurring_tax'] ); |
|
477 | - } |
|
478 | - |
|
479 | - $this->taxes[ $tax['name'] ] = $tax; |
|
480 | - $this->totals['taxes']['initial'] += wpinv_sanitize_amount( $tax['initial_tax'] ); |
|
481 | - $this->totals['taxes']['recurring'] += wpinv_sanitize_amount( $tax['recurring_tax'] ); |
|
482 | - |
|
483 | - } |
|
484 | - |
|
485 | - /** |
|
486 | - * Removes a specific tax. |
|
487 | - * |
|
488 | - * @since 1.0.19 |
|
489 | - */ |
|
490 | - public function remove_tax( $tax_name ) { |
|
491 | - |
|
492 | - if ( isset( $this->taxes[ $tax_name ] ) ) { |
|
493 | - $this->totals['taxes']['initial'] -= $this->taxes[ $tax_name ]['initial_tax']; |
|
494 | - $this->totals['taxes']['recurring'] -= $this->taxes[ $tax_name ]['recurring_tax']; |
|
495 | - unset( $this->taxes[ $tax_name ] ); |
|
496 | - } |
|
497 | - |
|
498 | - } |
|
499 | - |
|
500 | - /** |
|
501 | - * Whether or not we'll use taxes for the submission. |
|
502 | - * |
|
503 | - * @since 1.0.19 |
|
504 | - */ |
|
505 | - public function use_taxes() { |
|
506 | - |
|
507 | - $use_taxes = wpinv_use_taxes(); |
|
508 | - |
|
509 | - if ( $this->has_invoice() && ! $this->invoice->is_taxable() ) { |
|
510 | - $use_taxes = false; |
|
511 | - } |
|
512 | - |
|
513 | - return apply_filters( 'getpaid_submission_use_taxes', $use_taxes, $this ); |
|
514 | - |
|
515 | - } |
|
516 | - |
|
517 | - /** |
|
518 | - * Returns the tax. |
|
519 | - * |
|
520 | - * @since 1.0.19 |
|
521 | - */ |
|
522 | - public function get_tax() { |
|
523 | - return $this->totals['taxes']['initial']; |
|
524 | - } |
|
525 | - |
|
526 | - /** |
|
527 | - * Returns the recurring tax. |
|
528 | - * |
|
529 | - * @since 1.0.19 |
|
530 | - */ |
|
531 | - public function get_recurring_tax() { |
|
532 | - return $this->totals['taxes']['recurring']; |
|
533 | - } |
|
534 | - |
|
535 | - /** |
|
536 | - * Returns all taxes. |
|
537 | - * |
|
538 | - * @since 1.0.19 |
|
539 | - */ |
|
540 | - public function get_taxes() { |
|
541 | - return $this->taxes; |
|
542 | - } |
|
543 | - |
|
544 | - /* |
|
423 | + /** |
|
424 | + * Prepares the submission's taxes. |
|
425 | + * |
|
426 | + * @since 1.0.19 |
|
427 | + */ |
|
428 | + public function process_taxes() { |
|
429 | + |
|
430 | + // Abort if we're not using taxes. |
|
431 | + if ( ! $this->use_taxes() ) { |
|
432 | + return; |
|
433 | + } |
|
434 | + |
|
435 | + // If a custom country && state has been passed in, use it to calculate taxes. |
|
436 | + $country = $this->get_field( 'wpinv_country', 'billing' ); |
|
437 | + if ( ! empty( $country ) ) { |
|
438 | + $this->country = $country; |
|
439 | + } |
|
440 | + |
|
441 | + $state = $this->get_field( 'wpinv_state', 'billing' ); |
|
442 | + if ( ! empty( $state ) ) { |
|
443 | + $this->state = $state; |
|
444 | + } |
|
445 | + |
|
446 | + // Confirm if the provided country and the ip country are similar. |
|
447 | + $address_confirmed = $this->get_field( 'confirm-address' ); |
|
448 | + if ( wpinv_should_validate_vat_number() && getpaid_get_ip_country() != $this->country && empty( $address_confirmed ) ) { |
|
449 | + throw new Exception( __( 'The country of your current location must be the same as the country of your billing location or you must confirm the billing address is your home country.', 'invoicing' ) ); |
|
450 | + } |
|
451 | + |
|
452 | + // Abort if the country is not taxable. |
|
453 | + if ( ! wpinv_is_country_taxable( $this->country ) ) { |
|
454 | + return; |
|
455 | + } |
|
456 | + |
|
457 | + $processor = new GetPaid_Payment_Form_Submission_Taxes( $this ); |
|
458 | + |
|
459 | + foreach ( $processor->taxes as $tax ) { |
|
460 | + $this->add_tax( $tax ); |
|
461 | + } |
|
462 | + |
|
463 | + do_action_ref_array( 'getpaid_submissions_process_taxes', array( &$this ) ); |
|
464 | + } |
|
465 | + |
|
466 | + /** |
|
467 | + * Adds a tax to the submission. |
|
468 | + * |
|
469 | + * @param array $tax An array of tax details. name, initial_tax, and recurring_tax are required. |
|
470 | + * @since 1.0.19 |
|
471 | + */ |
|
472 | + public function add_tax( $tax ) { |
|
473 | + |
|
474 | + if ( wpinv_round_tax_per_tax_rate() ) { |
|
475 | + $tax['initial_tax'] = wpinv_round_amount( $tax['initial_tax'] ); |
|
476 | + $tax['recurring_tax'] = wpinv_round_amount( $tax['recurring_tax'] ); |
|
477 | + } |
|
478 | + |
|
479 | + $this->taxes[ $tax['name'] ] = $tax; |
|
480 | + $this->totals['taxes']['initial'] += wpinv_sanitize_amount( $tax['initial_tax'] ); |
|
481 | + $this->totals['taxes']['recurring'] += wpinv_sanitize_amount( $tax['recurring_tax'] ); |
|
482 | + |
|
483 | + } |
|
484 | + |
|
485 | + /** |
|
486 | + * Removes a specific tax. |
|
487 | + * |
|
488 | + * @since 1.0.19 |
|
489 | + */ |
|
490 | + public function remove_tax( $tax_name ) { |
|
491 | + |
|
492 | + if ( isset( $this->taxes[ $tax_name ] ) ) { |
|
493 | + $this->totals['taxes']['initial'] -= $this->taxes[ $tax_name ]['initial_tax']; |
|
494 | + $this->totals['taxes']['recurring'] -= $this->taxes[ $tax_name ]['recurring_tax']; |
|
495 | + unset( $this->taxes[ $tax_name ] ); |
|
496 | + } |
|
497 | + |
|
498 | + } |
|
499 | + |
|
500 | + /** |
|
501 | + * Whether or not we'll use taxes for the submission. |
|
502 | + * |
|
503 | + * @since 1.0.19 |
|
504 | + */ |
|
505 | + public function use_taxes() { |
|
506 | + |
|
507 | + $use_taxes = wpinv_use_taxes(); |
|
508 | + |
|
509 | + if ( $this->has_invoice() && ! $this->invoice->is_taxable() ) { |
|
510 | + $use_taxes = false; |
|
511 | + } |
|
512 | + |
|
513 | + return apply_filters( 'getpaid_submission_use_taxes', $use_taxes, $this ); |
|
514 | + |
|
515 | + } |
|
516 | + |
|
517 | + /** |
|
518 | + * Returns the tax. |
|
519 | + * |
|
520 | + * @since 1.0.19 |
|
521 | + */ |
|
522 | + public function get_tax() { |
|
523 | + return $this->totals['taxes']['initial']; |
|
524 | + } |
|
525 | + |
|
526 | + /** |
|
527 | + * Returns the recurring tax. |
|
528 | + * |
|
529 | + * @since 1.0.19 |
|
530 | + */ |
|
531 | + public function get_recurring_tax() { |
|
532 | + return $this->totals['taxes']['recurring']; |
|
533 | + } |
|
534 | + |
|
535 | + /** |
|
536 | + * Returns all taxes. |
|
537 | + * |
|
538 | + * @since 1.0.19 |
|
539 | + */ |
|
540 | + public function get_taxes() { |
|
541 | + return $this->taxes; |
|
542 | + } |
|
543 | + |
|
544 | + /* |
|
545 | 545 | |-------------------------------------------------------------------------- |
546 | 546 | | Discounts |
547 | 547 | |-------------------------------------------------------------------------- |
@@ -550,99 +550,99 @@ discard block |
||
550 | 550 | | or only one-time. They also do not have to come from a discount code. |
551 | 551 | */ |
552 | 552 | |
553 | - /** |
|
554 | - * Prepares the submission's discount. |
|
555 | - * |
|
556 | - * @since 1.0.19 |
|
557 | - */ |
|
558 | - public function process_discount() { |
|
559 | - |
|
560 | - $initial_total = $this->get_subtotal() + $this->get_fee() + $this->get_tax(); |
|
561 | - $recurring_total = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax(); |
|
562 | - $processor = new GetPaid_Payment_Form_Submission_Discount( $this, $initial_total, $recurring_total ); |
|
563 | - |
|
564 | - foreach ( $processor->discounts as $discount ) { |
|
565 | - $this->add_discount( $discount ); |
|
566 | - } |
|
567 | - |
|
568 | - do_action_ref_array( 'getpaid_submissions_process_discounts', array( &$this ) ); |
|
569 | - } |
|
570 | - |
|
571 | - /** |
|
572 | - * Adds a discount to the submission. |
|
573 | - * |
|
574 | - * @param array $discount An array of discount details. name, initial_discount, and recurring_discount are required. Include discount_code if the discount is from a discount code. |
|
575 | - * @since 1.0.19 |
|
576 | - */ |
|
577 | - public function add_discount( $discount ) { |
|
578 | - $this->discounts[ $discount['name'] ] = $discount; |
|
579 | - $this->totals['discount']['initial'] += wpinv_sanitize_amount( $discount['initial_discount'] ); |
|
580 | - $this->totals['discount']['recurring'] += wpinv_sanitize_amount( $discount['recurring_discount'] ); |
|
581 | - } |
|
582 | - |
|
583 | - /** |
|
584 | - * Removes a discount from the submission. |
|
585 | - * |
|
586 | - * @since 1.0.19 |
|
587 | - */ |
|
588 | - public function remove_discount( $name ) { |
|
589 | - |
|
590 | - if ( isset( $this->discounts[ $name ] ) ) { |
|
591 | - $this->totals['discount']['initial'] -= $this->discounts[ $name ]['initial_discount']; |
|
592 | - $this->totals['discount']['recurring'] -= $this->discounts[ $name ]['recurring_discount']; |
|
593 | - unset( $this->discounts[ $name ] ); |
|
594 | - } |
|
595 | - |
|
596 | - } |
|
597 | - |
|
598 | - /** |
|
599 | - * Checks whether there is a discount code associated with this submission. |
|
600 | - * |
|
601 | - * @since 1.0.19 |
|
602 | - * @return bool |
|
603 | - */ |
|
604 | - public function has_discount_code() { |
|
605 | - return ! empty( $this->discounts['discount_code'] ); |
|
606 | - } |
|
607 | - |
|
608 | - /** |
|
609 | - * Returns the discount code. |
|
610 | - * |
|
611 | - * @since 1.0.19 |
|
612 | - * @return string |
|
613 | - */ |
|
614 | - public function get_discount_code() { |
|
615 | - return $this->has_discount_code() ? $this->discounts['discount_code']['discount_code'] : ''; |
|
616 | - } |
|
617 | - |
|
618 | - /** |
|
619 | - * Returns the discount. |
|
620 | - * |
|
621 | - * @since 1.0.19 |
|
622 | - */ |
|
623 | - public function get_discount() { |
|
624 | - return $this->totals['discount']['initial']; |
|
625 | - } |
|
626 | - |
|
627 | - /** |
|
628 | - * Returns the recurring discount. |
|
629 | - * |
|
630 | - * @since 1.0.19 |
|
631 | - */ |
|
632 | - public function get_recurring_discount() { |
|
633 | - return $this->totals['discount']['recurring']; |
|
634 | - } |
|
635 | - |
|
636 | - /** |
|
637 | - * Returns all discounts. |
|
638 | - * |
|
639 | - * @since 1.0.19 |
|
640 | - */ |
|
641 | - public function get_discounts() { |
|
642 | - return $this->discounts; |
|
643 | - } |
|
644 | - |
|
645 | - /* |
|
553 | + /** |
|
554 | + * Prepares the submission's discount. |
|
555 | + * |
|
556 | + * @since 1.0.19 |
|
557 | + */ |
|
558 | + public function process_discount() { |
|
559 | + |
|
560 | + $initial_total = $this->get_subtotal() + $this->get_fee() + $this->get_tax(); |
|
561 | + $recurring_total = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax(); |
|
562 | + $processor = new GetPaid_Payment_Form_Submission_Discount( $this, $initial_total, $recurring_total ); |
|
563 | + |
|
564 | + foreach ( $processor->discounts as $discount ) { |
|
565 | + $this->add_discount( $discount ); |
|
566 | + } |
|
567 | + |
|
568 | + do_action_ref_array( 'getpaid_submissions_process_discounts', array( &$this ) ); |
|
569 | + } |
|
570 | + |
|
571 | + /** |
|
572 | + * Adds a discount to the submission. |
|
573 | + * |
|
574 | + * @param array $discount An array of discount details. name, initial_discount, and recurring_discount are required. Include discount_code if the discount is from a discount code. |
|
575 | + * @since 1.0.19 |
|
576 | + */ |
|
577 | + public function add_discount( $discount ) { |
|
578 | + $this->discounts[ $discount['name'] ] = $discount; |
|
579 | + $this->totals['discount']['initial'] += wpinv_sanitize_amount( $discount['initial_discount'] ); |
|
580 | + $this->totals['discount']['recurring'] += wpinv_sanitize_amount( $discount['recurring_discount'] ); |
|
581 | + } |
|
582 | + |
|
583 | + /** |
|
584 | + * Removes a discount from the submission. |
|
585 | + * |
|
586 | + * @since 1.0.19 |
|
587 | + */ |
|
588 | + public function remove_discount( $name ) { |
|
589 | + |
|
590 | + if ( isset( $this->discounts[ $name ] ) ) { |
|
591 | + $this->totals['discount']['initial'] -= $this->discounts[ $name ]['initial_discount']; |
|
592 | + $this->totals['discount']['recurring'] -= $this->discounts[ $name ]['recurring_discount']; |
|
593 | + unset( $this->discounts[ $name ] ); |
|
594 | + } |
|
595 | + |
|
596 | + } |
|
597 | + |
|
598 | + /** |
|
599 | + * Checks whether there is a discount code associated with this submission. |
|
600 | + * |
|
601 | + * @since 1.0.19 |
|
602 | + * @return bool |
|
603 | + */ |
|
604 | + public function has_discount_code() { |
|
605 | + return ! empty( $this->discounts['discount_code'] ); |
|
606 | + } |
|
607 | + |
|
608 | + /** |
|
609 | + * Returns the discount code. |
|
610 | + * |
|
611 | + * @since 1.0.19 |
|
612 | + * @return string |
|
613 | + */ |
|
614 | + public function get_discount_code() { |
|
615 | + return $this->has_discount_code() ? $this->discounts['discount_code']['discount_code'] : ''; |
|
616 | + } |
|
617 | + |
|
618 | + /** |
|
619 | + * Returns the discount. |
|
620 | + * |
|
621 | + * @since 1.0.19 |
|
622 | + */ |
|
623 | + public function get_discount() { |
|
624 | + return $this->totals['discount']['initial']; |
|
625 | + } |
|
626 | + |
|
627 | + /** |
|
628 | + * Returns the recurring discount. |
|
629 | + * |
|
630 | + * @since 1.0.19 |
|
631 | + */ |
|
632 | + public function get_recurring_discount() { |
|
633 | + return $this->totals['discount']['recurring']; |
|
634 | + } |
|
635 | + |
|
636 | + /** |
|
637 | + * Returns all discounts. |
|
638 | + * |
|
639 | + * @since 1.0.19 |
|
640 | + */ |
|
641 | + public function get_discounts() { |
|
642 | + return $this->discounts; |
|
643 | + } |
|
644 | + |
|
645 | + /* |
|
646 | 646 | |-------------------------------------------------------------------------- |
647 | 647 | | Fees |
648 | 648 | |-------------------------------------------------------------------------- |
@@ -652,89 +652,89 @@ discard block |
||
652 | 652 | | fees. |
653 | 653 | */ |
654 | 654 | |
655 | - /** |
|
656 | - * Prepares the submission's fees. |
|
657 | - * |
|
658 | - * @since 1.0.19 |
|
659 | - */ |
|
660 | - public function process_fees() { |
|
661 | - |
|
662 | - $fees_processor = new GetPaid_Payment_Form_Submission_Fees( $this ); |
|
663 | - |
|
664 | - foreach ( $fees_processor->fees as $fee ) { |
|
665 | - $this->add_fee( $fee ); |
|
666 | - } |
|
667 | - |
|
668 | - do_action_ref_array( 'getpaid_submissions_process_fees', array( &$this ) ); |
|
669 | - } |
|
670 | - |
|
671 | - /** |
|
672 | - * Adds a fee to the submission. |
|
673 | - * |
|
674 | - * @param array $fee An array of fee details. name, initial_fee, and recurring_fee are required. |
|
675 | - * @since 1.0.19 |
|
676 | - */ |
|
677 | - public function add_fee( $fee ) { |
|
678 | - |
|
679 | - $this->fees[ $fee['name'] ] = $fee; |
|
680 | - $this->totals['fees']['initial'] += wpinv_sanitize_amount( $fee['initial_fee'] ); |
|
681 | - $this->totals['fees']['recurring'] += wpinv_sanitize_amount( $fee['recurring_fee'] ); |
|
682 | - |
|
683 | - } |
|
684 | - |
|
685 | - /** |
|
686 | - * Removes a fee from the submission. |
|
687 | - * |
|
688 | - * @since 1.0.19 |
|
689 | - */ |
|
690 | - public function remove_fee( $name ) { |
|
691 | - |
|
692 | - if ( isset( $this->fees[ $name ] ) ) { |
|
693 | - $this->totals['fees']['initial'] -= $this->fees[ $name ]['initial_fee']; |
|
694 | - $this->totals['fees']['recurring'] -= $this->fees[ $name ]['recurring_fee']; |
|
695 | - unset( $this->fees[ $name ] ); |
|
696 | - } |
|
697 | - |
|
698 | - } |
|
699 | - |
|
700 | - /** |
|
701 | - * Returns the fees. |
|
702 | - * |
|
703 | - * @since 1.0.19 |
|
704 | - */ |
|
705 | - public function get_fee() { |
|
706 | - return $this->totals['fees']['initial']; |
|
707 | - } |
|
708 | - |
|
709 | - /** |
|
710 | - * Returns the recurring fees. |
|
711 | - * |
|
712 | - * @since 1.0.19 |
|
713 | - */ |
|
714 | - public function get_recurring_fee() { |
|
715 | - return $this->totals['fees']['recurring']; |
|
716 | - } |
|
717 | - |
|
718 | - /** |
|
719 | - * Returns all fees. |
|
720 | - * |
|
721 | - * @since 1.0.19 |
|
722 | - */ |
|
723 | - public function get_fees() { |
|
724 | - return $this->fees; |
|
725 | - } |
|
726 | - |
|
727 | - /** |
|
728 | - * Checks if there are any fees for the form. |
|
729 | - * |
|
730 | - * @return bool |
|
731 | - * @since 1.0.19 |
|
732 | - */ |
|
733 | - public function has_fees() { |
|
734 | - return count( $this->fees ) !== 0; |
|
735 | - } |
|
736 | - |
|
737 | - /* |
|
655 | + /** |
|
656 | + * Prepares the submission's fees. |
|
657 | + * |
|
658 | + * @since 1.0.19 |
|
659 | + */ |
|
660 | + public function process_fees() { |
|
661 | + |
|
662 | + $fees_processor = new GetPaid_Payment_Form_Submission_Fees( $this ); |
|
663 | + |
|
664 | + foreach ( $fees_processor->fees as $fee ) { |
|
665 | + $this->add_fee( $fee ); |
|
666 | + } |
|
667 | + |
|
668 | + do_action_ref_array( 'getpaid_submissions_process_fees', array( &$this ) ); |
|
669 | + } |
|
670 | + |
|
671 | + /** |
|
672 | + * Adds a fee to the submission. |
|
673 | + * |
|
674 | + * @param array $fee An array of fee details. name, initial_fee, and recurring_fee are required. |
|
675 | + * @since 1.0.19 |
|
676 | + */ |
|
677 | + public function add_fee( $fee ) { |
|
678 | + |
|
679 | + $this->fees[ $fee['name'] ] = $fee; |
|
680 | + $this->totals['fees']['initial'] += wpinv_sanitize_amount( $fee['initial_fee'] ); |
|
681 | + $this->totals['fees']['recurring'] += wpinv_sanitize_amount( $fee['recurring_fee'] ); |
|
682 | + |
|
683 | + } |
|
684 | + |
|
685 | + /** |
|
686 | + * Removes a fee from the submission. |
|
687 | + * |
|
688 | + * @since 1.0.19 |
|
689 | + */ |
|
690 | + public function remove_fee( $name ) { |
|
691 | + |
|
692 | + if ( isset( $this->fees[ $name ] ) ) { |
|
693 | + $this->totals['fees']['initial'] -= $this->fees[ $name ]['initial_fee']; |
|
694 | + $this->totals['fees']['recurring'] -= $this->fees[ $name ]['recurring_fee']; |
|
695 | + unset( $this->fees[ $name ] ); |
|
696 | + } |
|
697 | + |
|
698 | + } |
|
699 | + |
|
700 | + /** |
|
701 | + * Returns the fees. |
|
702 | + * |
|
703 | + * @since 1.0.19 |
|
704 | + */ |
|
705 | + public function get_fee() { |
|
706 | + return $this->totals['fees']['initial']; |
|
707 | + } |
|
708 | + |
|
709 | + /** |
|
710 | + * Returns the recurring fees. |
|
711 | + * |
|
712 | + * @since 1.0.19 |
|
713 | + */ |
|
714 | + public function get_recurring_fee() { |
|
715 | + return $this->totals['fees']['recurring']; |
|
716 | + } |
|
717 | + |
|
718 | + /** |
|
719 | + * Returns all fees. |
|
720 | + * |
|
721 | + * @since 1.0.19 |
|
722 | + */ |
|
723 | + public function get_fees() { |
|
724 | + return $this->fees; |
|
725 | + } |
|
726 | + |
|
727 | + /** |
|
728 | + * Checks if there are any fees for the form. |
|
729 | + * |
|
730 | + * @return bool |
|
731 | + * @since 1.0.19 |
|
732 | + */ |
|
733 | + public function has_fees() { |
|
734 | + return count( $this->fees ) !== 0; |
|
735 | + } |
|
736 | + |
|
737 | + /* |
|
738 | 738 | |-------------------------------------------------------------------------- |
739 | 739 | | MISC |
740 | 740 | |-------------------------------------------------------------------------- |
@@ -742,109 +742,109 @@ discard block |
||
742 | 742 | | Extra submission functions. |
743 | 743 | */ |
744 | 744 | |
745 | - /** |
|
746 | - * Returns the total amount to collect for this submission. |
|
747 | - * |
|
748 | - * @since 1.0.19 |
|
749 | - */ |
|
750 | - public function get_total() { |
|
751 | - $total = $this->get_subtotal() + $this->get_fee() + $this->get_tax() - $this->get_discount(); |
|
752 | - return max( $total, 0 ); |
|
753 | - } |
|
754 | - |
|
755 | - /** |
|
756 | - * Returns the recurring total amount to collect for this submission. |
|
757 | - * |
|
758 | - * @since 1.0.19 |
|
759 | - */ |
|
760 | - public function get_recurring_total() { |
|
761 | - $total = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax() - $this->get_recurring_discount(); |
|
762 | - return max( $total, 0 ); |
|
763 | - } |
|
764 | - |
|
765 | - /** |
|
766 | - * Whether payment details should be collected for this submission. |
|
767 | - * |
|
768 | - * @since 1.0.19 |
|
769 | - */ |
|
770 | - public function should_collect_payment_details() { |
|
771 | - $initial = $this->get_total(); |
|
772 | - $recurring = $this->get_recurring_total(); |
|
773 | - |
|
774 | - if ( $this->has_recurring == 0 ) { |
|
775 | - $recurring = 0; |
|
776 | - } |
|
777 | - |
|
778 | - $collect = $initial > 0 || $recurring > 0; |
|
779 | - return apply_filters( 'getpaid_submission_should_collect_payment_details', $collect, $this ); |
|
780 | - } |
|
781 | - |
|
782 | - /** |
|
783 | - * Returns the billing email of the user. |
|
784 | - * |
|
785 | - * @since 1.0.19 |
|
786 | - */ |
|
787 | - public function get_billing_email() { |
|
788 | - return apply_filters( 'getpaid_get_submission_billing_email', $this->get_field( 'billing_email' ), $this ); |
|
789 | - } |
|
790 | - |
|
791 | - /** |
|
792 | - * Checks if the submitter has a billing email. |
|
793 | - * |
|
794 | - * @since 1.0.19 |
|
795 | - */ |
|
796 | - public function has_billing_email() { |
|
797 | - $billing_email = $this->get_billing_email(); |
|
798 | - return ! empty( $billing_email ) && is_email( $billing_email ); |
|
799 | - } |
|
800 | - |
|
801 | - /** |
|
802 | - * Returns the appropriate currency for the submission. |
|
803 | - * |
|
804 | - * @since 1.0.19 |
|
805 | - * @return string |
|
806 | - */ |
|
807 | - public function get_currency() { |
|
808 | - return $this->has_invoice() ? $this->invoice->get_currency() : wpinv_get_currency(); |
|
809 | - } |
|
810 | - |
|
811 | - /** |
|
812 | - * Returns the raw submission data. |
|
813 | - * |
|
814 | - * @since 1.0.19 |
|
815 | - * @return array |
|
816 | - */ |
|
817 | - public function get_data() { |
|
818 | - return $this->data; |
|
819 | - } |
|
820 | - |
|
821 | - /** |
|
822 | - * Returns a field from the submission data |
|
823 | - * |
|
824 | - * @param string $field |
|
825 | - * @since 1.0.19 |
|
826 | - * @return mixed|null |
|
827 | - */ |
|
828 | - public function get_field( $field, $sub_array_key = null ) { |
|
829 | - return getpaid_get_array_field( $this->data, $field, $sub_array_key ); |
|
830 | - } |
|
831 | - |
|
832 | - /** |
|
833 | - * Checks if a required field is set. |
|
834 | - * |
|
835 | - * @since 1.0.19 |
|
836 | - */ |
|
837 | - public function is_required_field_set( $field ) { |
|
838 | - return empty( $field['required'] ) || ! empty( $this->data[ $field['id'] ] ); |
|
839 | - } |
|
840 | - |
|
841 | - /** |
|
842 | - * Formats an amount |
|
843 | - * |
|
844 | - * @since 1.0.19 |
|
845 | - */ |
|
846 | - public function format_amount( $amount ) { |
|
847 | - return wpinv_price( $amount, $this->get_currency() ); |
|
848 | - } |
|
745 | + /** |
|
746 | + * Returns the total amount to collect for this submission. |
|
747 | + * |
|
748 | + * @since 1.0.19 |
|
749 | + */ |
|
750 | + public function get_total() { |
|
751 | + $total = $this->get_subtotal() + $this->get_fee() + $this->get_tax() - $this->get_discount(); |
|
752 | + return max( $total, 0 ); |
|
753 | + } |
|
754 | + |
|
755 | + /** |
|
756 | + * Returns the recurring total amount to collect for this submission. |
|
757 | + * |
|
758 | + * @since 1.0.19 |
|
759 | + */ |
|
760 | + public function get_recurring_total() { |
|
761 | + $total = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax() - $this->get_recurring_discount(); |
|
762 | + return max( $total, 0 ); |
|
763 | + } |
|
764 | + |
|
765 | + /** |
|
766 | + * Whether payment details should be collected for this submission. |
|
767 | + * |
|
768 | + * @since 1.0.19 |
|
769 | + */ |
|
770 | + public function should_collect_payment_details() { |
|
771 | + $initial = $this->get_total(); |
|
772 | + $recurring = $this->get_recurring_total(); |
|
773 | + |
|
774 | + if ( $this->has_recurring == 0 ) { |
|
775 | + $recurring = 0; |
|
776 | + } |
|
777 | + |
|
778 | + $collect = $initial > 0 || $recurring > 0; |
|
779 | + return apply_filters( 'getpaid_submission_should_collect_payment_details', $collect, $this ); |
|
780 | + } |
|
781 | + |
|
782 | + /** |
|
783 | + * Returns the billing email of the user. |
|
784 | + * |
|
785 | + * @since 1.0.19 |
|
786 | + */ |
|
787 | + public function get_billing_email() { |
|
788 | + return apply_filters( 'getpaid_get_submission_billing_email', $this->get_field( 'billing_email' ), $this ); |
|
789 | + } |
|
790 | + |
|
791 | + /** |
|
792 | + * Checks if the submitter has a billing email. |
|
793 | + * |
|
794 | + * @since 1.0.19 |
|
795 | + */ |
|
796 | + public function has_billing_email() { |
|
797 | + $billing_email = $this->get_billing_email(); |
|
798 | + return ! empty( $billing_email ) && is_email( $billing_email ); |
|
799 | + } |
|
800 | + |
|
801 | + /** |
|
802 | + * Returns the appropriate currency for the submission. |
|
803 | + * |
|
804 | + * @since 1.0.19 |
|
805 | + * @return string |
|
806 | + */ |
|
807 | + public function get_currency() { |
|
808 | + return $this->has_invoice() ? $this->invoice->get_currency() : wpinv_get_currency(); |
|
809 | + } |
|
810 | + |
|
811 | + /** |
|
812 | + * Returns the raw submission data. |
|
813 | + * |
|
814 | + * @since 1.0.19 |
|
815 | + * @return array |
|
816 | + */ |
|
817 | + public function get_data() { |
|
818 | + return $this->data; |
|
819 | + } |
|
820 | + |
|
821 | + /** |
|
822 | + * Returns a field from the submission data |
|
823 | + * |
|
824 | + * @param string $field |
|
825 | + * @since 1.0.19 |
|
826 | + * @return mixed|null |
|
827 | + */ |
|
828 | + public function get_field( $field, $sub_array_key = null ) { |
|
829 | + return getpaid_get_array_field( $this->data, $field, $sub_array_key ); |
|
830 | + } |
|
831 | + |
|
832 | + /** |
|
833 | + * Checks if a required field is set. |
|
834 | + * |
|
835 | + * @since 1.0.19 |
|
836 | + */ |
|
837 | + public function is_required_field_set( $field ) { |
|
838 | + return empty( $field['required'] ) || ! empty( $this->data[ $field['id'] ] ); |
|
839 | + } |
|
840 | + |
|
841 | + /** |
|
842 | + * Formats an amount |
|
843 | + * |
|
844 | + * @since 1.0.19 |
|
845 | + */ |
|
846 | + public function format_amount( $amount ) { |
|
847 | + return wpinv_price( $amount, $this->get_currency() ); |
|
848 | + } |
|
849 | 849 | |
850 | 850 | } |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if (!defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
@@ -134,8 +134,8 @@ discard block |
||
134 | 134 | $this->state = wpinv_get_default_state(); |
135 | 135 | |
136 | 136 | // Do we have an actual submission? |
137 | - if ( isset( $_POST['getpaid_payment_form_submission'] ) ) { |
|
138 | - $this->load_data( $_POST ); |
|
137 | + if (isset($_POST['getpaid_payment_form_submission'])) { |
|
138 | + $this->load_data($_POST); |
|
139 | 139 | } |
140 | 140 | |
141 | 141 | } |
@@ -145,19 +145,19 @@ discard block |
||
145 | 145 | * |
146 | 146 | * @param array $data |
147 | 147 | */ |
148 | - public function load_data( $data ) { |
|
148 | + public function load_data($data) { |
|
149 | 149 | |
150 | 150 | // Remove slashes from the submitted data... |
151 | - $data = wp_unslash( $data ); |
|
151 | + $data = wp_unslash($data); |
|
152 | 152 | |
153 | 153 | // Allow plugins to filter the data. |
154 | - $data = apply_filters( 'getpaid_submission_data', $data, $this ); |
|
154 | + $data = apply_filters('getpaid_submission_data', $data, $this); |
|
155 | 155 | |
156 | 156 | // Cache it... |
157 | 157 | $this->data = $data; |
158 | 158 | |
159 | 159 | // Then generate a unique id from the data. |
160 | - $this->id = md5( wp_json_encode( $data ) ); |
|
160 | + $this->id = md5(wp_json_encode($data)); |
|
161 | 161 | |
162 | 162 | // Finally, process the submission. |
163 | 163 | try { |
@@ -167,26 +167,26 @@ discard block |
||
167 | 167 | $processors = apply_filters( |
168 | 168 | 'getpaid_payment_form_submission_processors', |
169 | 169 | array( |
170 | - array( $this, 'process_payment_form' ), |
|
171 | - array( $this, 'process_invoice' ), |
|
172 | - array( $this, 'process_fees' ), |
|
173 | - array( $this, 'process_items' ), |
|
174 | - array( $this, 'process_taxes' ), |
|
175 | - array( $this, 'process_discount' ), |
|
170 | + array($this, 'process_payment_form'), |
|
171 | + array($this, 'process_invoice'), |
|
172 | + array($this, 'process_fees'), |
|
173 | + array($this, 'process_items'), |
|
174 | + array($this, 'process_taxes'), |
|
175 | + array($this, 'process_discount'), |
|
176 | 176 | ), |
177 | 177 | $this |
178 | 178 | ); |
179 | 179 | |
180 | - foreach ( $processors as $processor ) { |
|
181 | - call_user_func_array( $processor, array( &$this ) ); |
|
180 | + foreach ($processors as $processor) { |
|
181 | + call_user_func_array($processor, array(&$this)); |
|
182 | 182 | } |
183 | 183 | |
184 | - } catch ( Exception $e ) { |
|
184 | + } catch (Exception $e) { |
|
185 | 185 | $this->last_error = $e->getMessage(); |
186 | 186 | } |
187 | 187 | |
188 | 188 | // Fired when we are done processing a submission. |
189 | - do_action_ref_array( 'getpaid_process_submission', array( &$this ) ); |
|
189 | + do_action_ref_array('getpaid_process_submission', array(&$this)); |
|
190 | 190 | |
191 | 191 | } |
192 | 192 | |
@@ -207,18 +207,18 @@ discard block |
||
207 | 207 | public function process_payment_form() { |
208 | 208 | |
209 | 209 | // Every submission needs an active payment form. |
210 | - if ( empty( $this->data['form_id'] ) ) { |
|
211 | - throw new Exception( __( 'Missing payment form', 'invoicing' ) ); |
|
210 | + if (empty($this->data['form_id'])) { |
|
211 | + throw new Exception(__('Missing payment form', 'invoicing')); |
|
212 | 212 | } |
213 | 213 | |
214 | 214 | // Fetch the payment form. |
215 | - $this->payment_form = new GetPaid_Payment_Form( $this->data['form_id'] ); |
|
215 | + $this->payment_form = new GetPaid_Payment_Form($this->data['form_id']); |
|
216 | 216 | |
217 | - if ( ! $this->payment_form->is_active() ) { |
|
218 | - throw new Exception( __( 'Payment form not active', 'invoicing' ) ); |
|
217 | + if (!$this->payment_form->is_active()) { |
|
218 | + throw new Exception(__('Payment form not active', 'invoicing')); |
|
219 | 219 | } |
220 | 220 | |
221 | - do_action_ref_array( 'getpaid_submissions_process_payment_form', array( &$this ) ); |
|
221 | + do_action_ref_array('getpaid_submissions_process_payment_form', array(&$this)); |
|
222 | 222 | } |
223 | 223 | |
224 | 224 | /** |
@@ -248,30 +248,30 @@ discard block |
||
248 | 248 | public function process_invoice() { |
249 | 249 | |
250 | 250 | // Abort if there is no invoice. |
251 | - if ( empty( $this->data['invoice_id'] ) ) { |
|
251 | + if (empty($this->data['invoice_id'])) { |
|
252 | 252 | return; |
253 | 253 | } |
254 | 254 | |
255 | 255 | // If the submission is for an existing invoice, ensure that it exists |
256 | 256 | // and that it is not paid for. |
257 | - $invoice = wpinv_get_invoice( $this->data['invoice_id'] ); |
|
257 | + $invoice = wpinv_get_invoice($this->data['invoice_id']); |
|
258 | 258 | |
259 | - if ( empty( $invoice ) ) { |
|
260 | - throw new Exception( __( 'Invalid invoice', 'invoicing' ) ); |
|
259 | + if (empty($invoice)) { |
|
260 | + throw new Exception(__('Invalid invoice', 'invoicing')); |
|
261 | 261 | } |
262 | 262 | |
263 | - if ( $invoice->is_paid() ) { |
|
264 | - throw new Exception( __( 'This invoice is already paid for.', 'invoicing' ) ); |
|
263 | + if ($invoice->is_paid()) { |
|
264 | + throw new Exception(__('This invoice is already paid for.', 'invoicing')); |
|
265 | 265 | } |
266 | 266 | |
267 | - $this->payment_form->set_items( $invoice->get_items() ); |
|
267 | + $this->payment_form->set_items($invoice->get_items()); |
|
268 | 268 | $this->payment_form->invoice = $invoice; |
269 | 269 | |
270 | 270 | $this->country = $invoice->get_country(); |
271 | 271 | $this->state = $invoice->get_state(); |
272 | 272 | $this->invoice = $invoice; |
273 | 273 | |
274 | - do_action_ref_array( 'getpaid_submissions_process_invoice', array( &$this ) ); |
|
274 | + do_action_ref_array('getpaid_submissions_process_invoice', array(&$this)); |
|
275 | 275 | } |
276 | 276 | |
277 | 277 | /** |
@@ -291,7 +291,7 @@ discard block |
||
291 | 291 | * @return bool |
292 | 292 | */ |
293 | 293 | public function has_invoice() { |
294 | - return ! empty( $this->invoice ); |
|
294 | + return !empty($this->invoice); |
|
295 | 295 | } |
296 | 296 | |
297 | 297 | /* |
@@ -310,13 +310,13 @@ discard block |
||
310 | 310 | */ |
311 | 311 | public function process_items() { |
312 | 312 | |
313 | - $processor = new GetPaid_Payment_Form_Submission_Items( $this ); |
|
313 | + $processor = new GetPaid_Payment_Form_Submission_Items($this); |
|
314 | 314 | |
315 | - foreach ( $processor->items as $item ) { |
|
316 | - $this->add_item( $item ); |
|
315 | + foreach ($processor->items as $item) { |
|
316 | + $this->add_item($item); |
|
317 | 317 | } |
318 | 318 | |
319 | - do_action_ref_array( 'getpaid_submissions_process_items', array( &$this ) ); |
|
319 | + do_action_ref_array('getpaid_submissions_process_items', array(&$this)); |
|
320 | 320 | } |
321 | 321 | |
322 | 322 | /** |
@@ -325,18 +325,18 @@ discard block |
||
325 | 325 | * @since 1.0.19 |
326 | 326 | * @param GetPaid_Form_Item $item |
327 | 327 | */ |
328 | - public function add_item( $item ) { |
|
328 | + public function add_item($item) { |
|
329 | 329 | |
330 | 330 | // Make sure that it is available for purchase. |
331 | - if ( ! $item->can_purchase() || isset( $this->items[ $item->get_id() ] ) ) { |
|
331 | + if (!$item->can_purchase() || isset($this->items[$item->get_id()])) { |
|
332 | 332 | return; |
333 | 333 | } |
334 | 334 | |
335 | 335 | // Each submission can only contain one recurring item. |
336 | - if ( $item->is_recurring() ) { |
|
336 | + if ($item->is_recurring()) { |
|
337 | 337 | |
338 | - if ( $this->has_recurring != 0 ) { |
|
339 | - throw new Exception( __( 'You can only buy one recurring item at a time.', 'invoicing' ) ); |
|
338 | + if ($this->has_recurring != 0) { |
|
339 | + throw new Exception(__('You can only buy one recurring item at a time.', 'invoicing')); |
|
340 | 340 | } |
341 | 341 | |
342 | 342 | $this->has_recurring = $item->get_id(); |
@@ -344,7 +344,7 @@ discard block |
||
344 | 344 | } |
345 | 345 | |
346 | 346 | // Update the items and totals. |
347 | - $this->items[ $item->get_id() ] = $item; |
|
347 | + $this->items[$item->get_id()] = $item; |
|
348 | 348 | $this->totals['subtotal']['initial'] += $item->get_sub_total(); |
349 | 349 | $this->totals['subtotal']['recurring'] += $item->get_recurring_sub_total(); |
350 | 350 | |
@@ -358,17 +358,17 @@ discard block |
||
358 | 358 | * |
359 | 359 | * @since 1.0.19 |
360 | 360 | */ |
361 | - public function remove_item( $item_id ) { |
|
361 | + public function remove_item($item_id) { |
|
362 | 362 | |
363 | - if ( isset( $this->items[ $item_id ] ) ) { |
|
364 | - $this->totals['subtotal']['initial'] -= $this->items[ $item_id ]->get_sub_total(); |
|
365 | - $this->totals['subtotal']['recurring'] -= $this->items[ $item_id ]->get_recurring_sub_total(); |
|
363 | + if (isset($this->items[$item_id])) { |
|
364 | + $this->totals['subtotal']['initial'] -= $this->items[$item_id]->get_sub_total(); |
|
365 | + $this->totals['subtotal']['recurring'] -= $this->items[$item_id]->get_recurring_sub_total(); |
|
366 | 366 | |
367 | - if ( $this->items[ $item_id ]->is_recurring() ) { |
|
367 | + if ($this->items[$item_id]->is_recurring()) { |
|
368 | 368 | $this->has_recurring = 0; |
369 | 369 | } |
370 | 370 | |
371 | - unset( $this->items[ $item_id ] ); |
|
371 | + unset($this->items[$item_id]); |
|
372 | 372 | } |
373 | 373 | |
374 | 374 | } |
@@ -380,7 +380,7 @@ discard block |
||
380 | 380 | */ |
381 | 381 | public function get_subtotal() { |
382 | 382 | |
383 | - if ( wpinv_prices_include_tax() ) { |
|
383 | + if (wpinv_prices_include_tax()) { |
|
384 | 384 | return $this->totals['subtotal']['initial'] - $this->totals['taxes']['initial']; |
385 | 385 | } |
386 | 386 | |
@@ -394,7 +394,7 @@ discard block |
||
394 | 394 | */ |
395 | 395 | public function get_recurring_subtotal() { |
396 | 396 | |
397 | - if ( wpinv_prices_include_tax() ) { |
|
397 | + if (wpinv_prices_include_tax()) { |
|
398 | 398 | return $this->totals['subtotal']['recurring'] - $this->totals['taxes']['recurring']; |
399 | 399 | } |
400 | 400 | |
@@ -428,39 +428,39 @@ discard block |
||
428 | 428 | public function process_taxes() { |
429 | 429 | |
430 | 430 | // Abort if we're not using taxes. |
431 | - if ( ! $this->use_taxes() ) { |
|
431 | + if (!$this->use_taxes()) { |
|
432 | 432 | return; |
433 | 433 | } |
434 | 434 | |
435 | 435 | // If a custom country && state has been passed in, use it to calculate taxes. |
436 | - $country = $this->get_field( 'wpinv_country', 'billing' ); |
|
437 | - if ( ! empty( $country ) ) { |
|
436 | + $country = $this->get_field('wpinv_country', 'billing'); |
|
437 | + if (!empty($country)) { |
|
438 | 438 | $this->country = $country; |
439 | 439 | } |
440 | 440 | |
441 | - $state = $this->get_field( 'wpinv_state', 'billing' ); |
|
442 | - if ( ! empty( $state ) ) { |
|
441 | + $state = $this->get_field('wpinv_state', 'billing'); |
|
442 | + if (!empty($state)) { |
|
443 | 443 | $this->state = $state; |
444 | 444 | } |
445 | 445 | |
446 | 446 | // Confirm if the provided country and the ip country are similar. |
447 | - $address_confirmed = $this->get_field( 'confirm-address' ); |
|
448 | - if ( wpinv_should_validate_vat_number() && getpaid_get_ip_country() != $this->country && empty( $address_confirmed ) ) { |
|
449 | - throw new Exception( __( 'The country of your current location must be the same as the country of your billing location or you must confirm the billing address is your home country.', 'invoicing' ) ); |
|
447 | + $address_confirmed = $this->get_field('confirm-address'); |
|
448 | + if (wpinv_should_validate_vat_number() && getpaid_get_ip_country() != $this->country && empty($address_confirmed)) { |
|
449 | + throw new Exception(__('The country of your current location must be the same as the country of your billing location or you must confirm the billing address is your home country.', 'invoicing')); |
|
450 | 450 | } |
451 | 451 | |
452 | 452 | // Abort if the country is not taxable. |
453 | - if ( ! wpinv_is_country_taxable( $this->country ) ) { |
|
453 | + if (!wpinv_is_country_taxable($this->country)) { |
|
454 | 454 | return; |
455 | 455 | } |
456 | 456 | |
457 | - $processor = new GetPaid_Payment_Form_Submission_Taxes( $this ); |
|
457 | + $processor = new GetPaid_Payment_Form_Submission_Taxes($this); |
|
458 | 458 | |
459 | - foreach ( $processor->taxes as $tax ) { |
|
460 | - $this->add_tax( $tax ); |
|
459 | + foreach ($processor->taxes as $tax) { |
|
460 | + $this->add_tax($tax); |
|
461 | 461 | } |
462 | 462 | |
463 | - do_action_ref_array( 'getpaid_submissions_process_taxes', array( &$this ) ); |
|
463 | + do_action_ref_array('getpaid_submissions_process_taxes', array(&$this)); |
|
464 | 464 | } |
465 | 465 | |
466 | 466 | /** |
@@ -469,16 +469,16 @@ discard block |
||
469 | 469 | * @param array $tax An array of tax details. name, initial_tax, and recurring_tax are required. |
470 | 470 | * @since 1.0.19 |
471 | 471 | */ |
472 | - public function add_tax( $tax ) { |
|
472 | + public function add_tax($tax) { |
|
473 | 473 | |
474 | - if ( wpinv_round_tax_per_tax_rate() ) { |
|
475 | - $tax['initial_tax'] = wpinv_round_amount( $tax['initial_tax'] ); |
|
476 | - $tax['recurring_tax'] = wpinv_round_amount( $tax['recurring_tax'] ); |
|
474 | + if (wpinv_round_tax_per_tax_rate()) { |
|
475 | + $tax['initial_tax'] = wpinv_round_amount($tax['initial_tax']); |
|
476 | + $tax['recurring_tax'] = wpinv_round_amount($tax['recurring_tax']); |
|
477 | 477 | } |
478 | 478 | |
479 | - $this->taxes[ $tax['name'] ] = $tax; |
|
480 | - $this->totals['taxes']['initial'] += wpinv_sanitize_amount( $tax['initial_tax'] ); |
|
481 | - $this->totals['taxes']['recurring'] += wpinv_sanitize_amount( $tax['recurring_tax'] ); |
|
479 | + $this->taxes[$tax['name']] = $tax; |
|
480 | + $this->totals['taxes']['initial'] += wpinv_sanitize_amount($tax['initial_tax']); |
|
481 | + $this->totals['taxes']['recurring'] += wpinv_sanitize_amount($tax['recurring_tax']); |
|
482 | 482 | |
483 | 483 | } |
484 | 484 | |
@@ -487,12 +487,12 @@ discard block |
||
487 | 487 | * |
488 | 488 | * @since 1.0.19 |
489 | 489 | */ |
490 | - public function remove_tax( $tax_name ) { |
|
490 | + public function remove_tax($tax_name) { |
|
491 | 491 | |
492 | - if ( isset( $this->taxes[ $tax_name ] ) ) { |
|
493 | - $this->totals['taxes']['initial'] -= $this->taxes[ $tax_name ]['initial_tax']; |
|
494 | - $this->totals['taxes']['recurring'] -= $this->taxes[ $tax_name ]['recurring_tax']; |
|
495 | - unset( $this->taxes[ $tax_name ] ); |
|
492 | + if (isset($this->taxes[$tax_name])) { |
|
493 | + $this->totals['taxes']['initial'] -= $this->taxes[$tax_name]['initial_tax']; |
|
494 | + $this->totals['taxes']['recurring'] -= $this->taxes[$tax_name]['recurring_tax']; |
|
495 | + unset($this->taxes[$tax_name]); |
|
496 | 496 | } |
497 | 497 | |
498 | 498 | } |
@@ -506,11 +506,11 @@ discard block |
||
506 | 506 | |
507 | 507 | $use_taxes = wpinv_use_taxes(); |
508 | 508 | |
509 | - if ( $this->has_invoice() && ! $this->invoice->is_taxable() ) { |
|
509 | + if ($this->has_invoice() && !$this->invoice->is_taxable()) { |
|
510 | 510 | $use_taxes = false; |
511 | 511 | } |
512 | 512 | |
513 | - return apply_filters( 'getpaid_submission_use_taxes', $use_taxes, $this ); |
|
513 | + return apply_filters('getpaid_submission_use_taxes', $use_taxes, $this); |
|
514 | 514 | |
515 | 515 | } |
516 | 516 | |
@@ -559,13 +559,13 @@ discard block |
||
559 | 559 | |
560 | 560 | $initial_total = $this->get_subtotal() + $this->get_fee() + $this->get_tax(); |
561 | 561 | $recurring_total = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax(); |
562 | - $processor = new GetPaid_Payment_Form_Submission_Discount( $this, $initial_total, $recurring_total ); |
|
562 | + $processor = new GetPaid_Payment_Form_Submission_Discount($this, $initial_total, $recurring_total); |
|
563 | 563 | |
564 | - foreach ( $processor->discounts as $discount ) { |
|
565 | - $this->add_discount( $discount ); |
|
564 | + foreach ($processor->discounts as $discount) { |
|
565 | + $this->add_discount($discount); |
|
566 | 566 | } |
567 | 567 | |
568 | - do_action_ref_array( 'getpaid_submissions_process_discounts', array( &$this ) ); |
|
568 | + do_action_ref_array('getpaid_submissions_process_discounts', array(&$this)); |
|
569 | 569 | } |
570 | 570 | |
571 | 571 | /** |
@@ -574,10 +574,10 @@ discard block |
||
574 | 574 | * @param array $discount An array of discount details. name, initial_discount, and recurring_discount are required. Include discount_code if the discount is from a discount code. |
575 | 575 | * @since 1.0.19 |
576 | 576 | */ |
577 | - public function add_discount( $discount ) { |
|
578 | - $this->discounts[ $discount['name'] ] = $discount; |
|
579 | - $this->totals['discount']['initial'] += wpinv_sanitize_amount( $discount['initial_discount'] ); |
|
580 | - $this->totals['discount']['recurring'] += wpinv_sanitize_amount( $discount['recurring_discount'] ); |
|
577 | + public function add_discount($discount) { |
|
578 | + $this->discounts[$discount['name']] = $discount; |
|
579 | + $this->totals['discount']['initial'] += wpinv_sanitize_amount($discount['initial_discount']); |
|
580 | + $this->totals['discount']['recurring'] += wpinv_sanitize_amount($discount['recurring_discount']); |
|
581 | 581 | } |
582 | 582 | |
583 | 583 | /** |
@@ -585,12 +585,12 @@ discard block |
||
585 | 585 | * |
586 | 586 | * @since 1.0.19 |
587 | 587 | */ |
588 | - public function remove_discount( $name ) { |
|
588 | + public function remove_discount($name) { |
|
589 | 589 | |
590 | - if ( isset( $this->discounts[ $name ] ) ) { |
|
591 | - $this->totals['discount']['initial'] -= $this->discounts[ $name ]['initial_discount']; |
|
592 | - $this->totals['discount']['recurring'] -= $this->discounts[ $name ]['recurring_discount']; |
|
593 | - unset( $this->discounts[ $name ] ); |
|
590 | + if (isset($this->discounts[$name])) { |
|
591 | + $this->totals['discount']['initial'] -= $this->discounts[$name]['initial_discount']; |
|
592 | + $this->totals['discount']['recurring'] -= $this->discounts[$name]['recurring_discount']; |
|
593 | + unset($this->discounts[$name]); |
|
594 | 594 | } |
595 | 595 | |
596 | 596 | } |
@@ -602,7 +602,7 @@ discard block |
||
602 | 602 | * @return bool |
603 | 603 | */ |
604 | 604 | public function has_discount_code() { |
605 | - return ! empty( $this->discounts['discount_code'] ); |
|
605 | + return !empty($this->discounts['discount_code']); |
|
606 | 606 | } |
607 | 607 | |
608 | 608 | /** |
@@ -659,13 +659,13 @@ discard block |
||
659 | 659 | */ |
660 | 660 | public function process_fees() { |
661 | 661 | |
662 | - $fees_processor = new GetPaid_Payment_Form_Submission_Fees( $this ); |
|
662 | + $fees_processor = new GetPaid_Payment_Form_Submission_Fees($this); |
|
663 | 663 | |
664 | - foreach ( $fees_processor->fees as $fee ) { |
|
665 | - $this->add_fee( $fee ); |
|
664 | + foreach ($fees_processor->fees as $fee) { |
|
665 | + $this->add_fee($fee); |
|
666 | 666 | } |
667 | 667 | |
668 | - do_action_ref_array( 'getpaid_submissions_process_fees', array( &$this ) ); |
|
668 | + do_action_ref_array('getpaid_submissions_process_fees', array(&$this)); |
|
669 | 669 | } |
670 | 670 | |
671 | 671 | /** |
@@ -674,11 +674,11 @@ discard block |
||
674 | 674 | * @param array $fee An array of fee details. name, initial_fee, and recurring_fee are required. |
675 | 675 | * @since 1.0.19 |
676 | 676 | */ |
677 | - public function add_fee( $fee ) { |
|
677 | + public function add_fee($fee) { |
|
678 | 678 | |
679 | - $this->fees[ $fee['name'] ] = $fee; |
|
680 | - $this->totals['fees']['initial'] += wpinv_sanitize_amount( $fee['initial_fee'] ); |
|
681 | - $this->totals['fees']['recurring'] += wpinv_sanitize_amount( $fee['recurring_fee'] ); |
|
679 | + $this->fees[$fee['name']] = $fee; |
|
680 | + $this->totals['fees']['initial'] += wpinv_sanitize_amount($fee['initial_fee']); |
|
681 | + $this->totals['fees']['recurring'] += wpinv_sanitize_amount($fee['recurring_fee']); |
|
682 | 682 | |
683 | 683 | } |
684 | 684 | |
@@ -687,12 +687,12 @@ discard block |
||
687 | 687 | * |
688 | 688 | * @since 1.0.19 |
689 | 689 | */ |
690 | - public function remove_fee( $name ) { |
|
690 | + public function remove_fee($name) { |
|
691 | 691 | |
692 | - if ( isset( $this->fees[ $name ] ) ) { |
|
693 | - $this->totals['fees']['initial'] -= $this->fees[ $name ]['initial_fee']; |
|
694 | - $this->totals['fees']['recurring'] -= $this->fees[ $name ]['recurring_fee']; |
|
695 | - unset( $this->fees[ $name ] ); |
|
692 | + if (isset($this->fees[$name])) { |
|
693 | + $this->totals['fees']['initial'] -= $this->fees[$name]['initial_fee']; |
|
694 | + $this->totals['fees']['recurring'] -= $this->fees[$name]['recurring_fee']; |
|
695 | + unset($this->fees[$name]); |
|
696 | 696 | } |
697 | 697 | |
698 | 698 | } |
@@ -731,7 +731,7 @@ discard block |
||
731 | 731 | * @since 1.0.19 |
732 | 732 | */ |
733 | 733 | public function has_fees() { |
734 | - return count( $this->fees ) !== 0; |
|
734 | + return count($this->fees) !== 0; |
|
735 | 735 | } |
736 | 736 | |
737 | 737 | /* |
@@ -749,7 +749,7 @@ discard block |
||
749 | 749 | */ |
750 | 750 | public function get_total() { |
751 | 751 | $total = $this->get_subtotal() + $this->get_fee() + $this->get_tax() - $this->get_discount(); |
752 | - return max( $total, 0 ); |
|
752 | + return max($total, 0); |
|
753 | 753 | } |
754 | 754 | |
755 | 755 | /** |
@@ -759,7 +759,7 @@ discard block |
||
759 | 759 | */ |
760 | 760 | public function get_recurring_total() { |
761 | 761 | $total = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax() - $this->get_recurring_discount(); |
762 | - return max( $total, 0 ); |
|
762 | + return max($total, 0); |
|
763 | 763 | } |
764 | 764 | |
765 | 765 | /** |
@@ -771,12 +771,12 @@ discard block |
||
771 | 771 | $initial = $this->get_total(); |
772 | 772 | $recurring = $this->get_recurring_total(); |
773 | 773 | |
774 | - if ( $this->has_recurring == 0 ) { |
|
774 | + if ($this->has_recurring == 0) { |
|
775 | 775 | $recurring = 0; |
776 | 776 | } |
777 | 777 | |
778 | 778 | $collect = $initial > 0 || $recurring > 0; |
779 | - return apply_filters( 'getpaid_submission_should_collect_payment_details', $collect, $this ); |
|
779 | + return apply_filters('getpaid_submission_should_collect_payment_details', $collect, $this); |
|
780 | 780 | } |
781 | 781 | |
782 | 782 | /** |
@@ -785,7 +785,7 @@ discard block |
||
785 | 785 | * @since 1.0.19 |
786 | 786 | */ |
787 | 787 | public function get_billing_email() { |
788 | - return apply_filters( 'getpaid_get_submission_billing_email', $this->get_field( 'billing_email' ), $this ); |
|
788 | + return apply_filters('getpaid_get_submission_billing_email', $this->get_field('billing_email'), $this); |
|
789 | 789 | } |
790 | 790 | |
791 | 791 | /** |
@@ -795,7 +795,7 @@ discard block |
||
795 | 795 | */ |
796 | 796 | public function has_billing_email() { |
797 | 797 | $billing_email = $this->get_billing_email(); |
798 | - return ! empty( $billing_email ) && is_email( $billing_email ); |
|
798 | + return !empty($billing_email) && is_email($billing_email); |
|
799 | 799 | } |
800 | 800 | |
801 | 801 | /** |
@@ -825,8 +825,8 @@ discard block |
||
825 | 825 | * @since 1.0.19 |
826 | 826 | * @return mixed|null |
827 | 827 | */ |
828 | - public function get_field( $field, $sub_array_key = null ) { |
|
829 | - return getpaid_get_array_field( $this->data, $field, $sub_array_key ); |
|
828 | + public function get_field($field, $sub_array_key = null) { |
|
829 | + return getpaid_get_array_field($this->data, $field, $sub_array_key); |
|
830 | 830 | } |
831 | 831 | |
832 | 832 | /** |
@@ -834,8 +834,8 @@ discard block |
||
834 | 834 | * |
835 | 835 | * @since 1.0.19 |
836 | 836 | */ |
837 | - public function is_required_field_set( $field ) { |
|
838 | - return empty( $field['required'] ) || ! empty( $this->data[ $field['id'] ] ); |
|
837 | + public function is_required_field_set($field) { |
|
838 | + return empty($field['required']) || !empty($this->data[$field['id']]); |
|
839 | 839 | } |
840 | 840 | |
841 | 841 | /** |
@@ -843,8 +843,8 @@ discard block |
||
843 | 843 | * |
844 | 844 | * @since 1.0.19 |
845 | 845 | */ |
846 | - public function format_amount( $amount ) { |
|
847 | - return wpinv_price( $amount, $this->get_currency() ); |
|
846 | + public function format_amount($amount) { |
|
847 | + return wpinv_price($amount, $this->get_currency()); |
|
848 | 848 | } |
849 | 849 | |
850 | 850 | } |
@@ -12,223 +12,223 @@ |
||
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 | + |
|
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( $item->get_sub_total(), $rates ); |
|
64 | + $r_taxes = getpaid_calculate_item_taxes( $item->get_recurring_sub_total(), $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 | + if ( ! isset( $this->taxes[ $name ] ) ) { |
|
71 | + $this->taxes[ $name ] = $tax; |
|
72 | + continue; |
|
73 | + } |
|
74 | + |
|
75 | + $this->taxes[ $name ]['initial_tax'] += $tax['initial_tax']; |
|
76 | + $this->taxes[ $name ]['recurring_tax'] += $tax['recurring_tax']; |
|
77 | + |
|
78 | + } |
|
79 | + |
|
80 | + } |
|
81 | + |
|
82 | + /** |
|
83 | + * Checks if the submission has a digital item. |
|
84 | + * |
|
85 | + * @param GetPaid_Payment_Form_Submission $submission |
|
86 | + * @since 1.0.19 |
|
87 | + * @return bool |
|
88 | + */ |
|
89 | + public function has_digital_item( $submission ) { |
|
90 | + |
|
91 | + foreach ( $submission->get_items() as $item ) { |
|
92 | + |
|
93 | + if ( 'digital' == $item->get_vat_rule() ) { |
|
94 | + return true; |
|
95 | + } |
|
96 | + |
|
97 | + } |
|
98 | + |
|
99 | + return false; |
|
100 | + } |
|
101 | + |
|
102 | + /** |
|
103 | + * Checks if this is an eu store. |
|
104 | + * |
|
105 | + * @since 1.0.19 |
|
106 | + * @return bool |
|
107 | + */ |
|
108 | + public function is_eu_store() { |
|
109 | + return $this->is_eu_country( wpinv_get_default_country() ); |
|
110 | + } |
|
111 | + |
|
112 | + /** |
|
113 | + * Checks if this is an eu country. |
|
114 | + * |
|
115 | + * @param string $country |
|
116 | + * @since 1.0.19 |
|
117 | + * @return bool |
|
118 | + */ |
|
119 | + public function is_eu_country( $country ) { |
|
120 | + return getpaid_is_eu_state( $country ) || getpaid_is_gst_country( $country ); |
|
121 | + } |
|
122 | + |
|
123 | + /** |
|
124 | + * Checks if this is an eu purchase. |
|
125 | + * |
|
126 | + * @param string $customer_country |
|
127 | + * @since 1.0.19 |
|
128 | + * @return bool |
|
129 | + */ |
|
130 | + public function is_eu_transaction( $customer_country ) { |
|
131 | + return $this->is_eu_country( $customer_country ) && $this->is_eu_store(); |
|
132 | + } |
|
133 | + |
|
134 | + /** |
|
135 | + * Retrieves the vat number. |
|
136 | + * |
|
137 | + * @param GetPaid_Payment_Form_Submission $submission |
|
138 | + * @since 1.0.19 |
|
139 | + * @return string |
|
140 | + */ |
|
141 | + public function get_vat_number( $submission ) { |
|
142 | + |
|
143 | + // Retrieve from the posted number. |
|
144 | + $vat_number = $submission->get_field( 'wpinv_vat_number', 'billing' ); |
|
145 | + if ( ! empty( $vat_number ) ) { |
|
146 | + return wpinv_clean( $vat_number ); |
|
147 | + } |
|
148 | + |
|
149 | + // Retrieve from the invoice. |
|
150 | + return $submission->has_invoice() ? $submission->get_invoice()->get_vat_number() : ''; |
|
151 | + } |
|
152 | + |
|
153 | + /** |
|
154 | + * Retrieves the company. |
|
155 | + * |
|
156 | + * @param GetPaid_Payment_Form_Submission $submission |
|
157 | + * @since 1.0.19 |
|
158 | + * @return string |
|
159 | + */ |
|
160 | + public function get_company( $submission ) { |
|
161 | + |
|
162 | + // Retrieve from the posted data. |
|
163 | + $company = $submission->get_field( 'wpinv_company', 'billing' ); |
|
164 | + if ( ! empty( $company ) ) { |
|
165 | + return wpinv_clean( $company ); |
|
166 | + } |
|
167 | + |
|
168 | + // Retrieve from the invoice. |
|
169 | + return $submission->has_invoice() ? $submission->get_invoice()->get_company() : ''; |
|
170 | + } |
|
26 | 171 | |
27 | 172 | /** |
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( $item->get_sub_total(), $rates ); |
|
64 | - $r_taxes = getpaid_calculate_item_taxes( $item->get_recurring_sub_total(), $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 | - if ( ! isset( $this->taxes[ $name ] ) ) { |
|
71 | - $this->taxes[ $name ] = $tax; |
|
72 | - continue; |
|
73 | - } |
|
74 | - |
|
75 | - $this->taxes[ $name ]['initial_tax'] += $tax['initial_tax']; |
|
76 | - $this->taxes[ $name ]['recurring_tax'] += $tax['recurring_tax']; |
|
77 | - |
|
78 | - } |
|
79 | - |
|
80 | - } |
|
81 | - |
|
82 | - /** |
|
83 | - * Checks if the submission has a digital item. |
|
84 | - * |
|
85 | - * @param GetPaid_Payment_Form_Submission $submission |
|
86 | - * @since 1.0.19 |
|
87 | - * @return bool |
|
88 | - */ |
|
89 | - public function has_digital_item( $submission ) { |
|
90 | - |
|
91 | - foreach ( $submission->get_items() as $item ) { |
|
92 | - |
|
93 | - if ( 'digital' == $item->get_vat_rule() ) { |
|
94 | - return true; |
|
95 | - } |
|
96 | - |
|
97 | - } |
|
98 | - |
|
99 | - return false; |
|
100 | - } |
|
101 | - |
|
102 | - /** |
|
103 | - * Checks if this is an eu store. |
|
104 | - * |
|
105 | - * @since 1.0.19 |
|
106 | - * @return bool |
|
107 | - */ |
|
108 | - public function is_eu_store() { |
|
109 | - return $this->is_eu_country( wpinv_get_default_country() ); |
|
110 | - } |
|
111 | - |
|
112 | - /** |
|
113 | - * Checks if this is an eu country. |
|
114 | - * |
|
115 | - * @param string $country |
|
116 | - * @since 1.0.19 |
|
117 | - * @return bool |
|
118 | - */ |
|
119 | - public function is_eu_country( $country ) { |
|
120 | - return getpaid_is_eu_state( $country ) || getpaid_is_gst_country( $country ); |
|
121 | - } |
|
122 | - |
|
123 | - /** |
|
124 | - * Checks if this is an eu purchase. |
|
125 | - * |
|
126 | - * @param string $customer_country |
|
127 | - * @since 1.0.19 |
|
128 | - * @return bool |
|
129 | - */ |
|
130 | - public function is_eu_transaction( $customer_country ) { |
|
131 | - return $this->is_eu_country( $customer_country ) && $this->is_eu_store(); |
|
132 | - } |
|
133 | - |
|
134 | - /** |
|
135 | - * Retrieves the vat number. |
|
136 | - * |
|
137 | - * @param GetPaid_Payment_Form_Submission $submission |
|
138 | - * @since 1.0.19 |
|
139 | - * @return string |
|
140 | - */ |
|
141 | - public function get_vat_number( $submission ) { |
|
142 | - |
|
143 | - // Retrieve from the posted number. |
|
144 | - $vat_number = $submission->get_field( 'wpinv_vat_number', 'billing' ); |
|
145 | - if ( ! empty( $vat_number ) ) { |
|
146 | - return wpinv_clean( $vat_number ); |
|
147 | - } |
|
148 | - |
|
149 | - // Retrieve from the invoice. |
|
150 | - return $submission->has_invoice() ? $submission->get_invoice()->get_vat_number() : ''; |
|
151 | - } |
|
152 | - |
|
153 | - /** |
|
154 | - * Retrieves the company. |
|
155 | - * |
|
156 | - * @param GetPaid_Payment_Form_Submission $submission |
|
157 | - * @since 1.0.19 |
|
158 | - * @return string |
|
159 | - */ |
|
160 | - public function get_company( $submission ) { |
|
161 | - |
|
162 | - // Retrieve from the posted data. |
|
163 | - $company = $submission->get_field( 'wpinv_company', 'billing' ); |
|
164 | - if ( ! empty( $company ) ) { |
|
165 | - return wpinv_clean( $company ); |
|
166 | - } |
|
167 | - |
|
168 | - // Retrieve from the invoice. |
|
169 | - return $submission->has_invoice() ? $submission->get_invoice()->get_company() : ''; |
|
170 | - } |
|
171 | - |
|
172 | - /** |
|
173 | - * Checks if we require a VAT number. |
|
174 | - * |
|
175 | - * @param bool $ip_in_eu Whether the customer IP is from the EU |
|
176 | - * @param bool $country_in_eu Whether the customer country is from the EU |
|
177 | - * @since 1.0.19 |
|
178 | - * @return string |
|
179 | - */ |
|
180 | - public function requires_vat( $ip_in_eu, $country_in_eu ) { |
|
181 | - |
|
182 | - $prevent_b2c = wpinv_get_option( 'vat_prevent_b2c_purchase' ); |
|
183 | - $prevent_b2c = ! empty( $prevent_b2c ); |
|
184 | - $is_eu = $ip_in_eu || $country_in_eu; |
|
185 | - |
|
186 | - return $prevent_b2c && $is_eu; |
|
187 | - } |
|
188 | - |
|
189 | - /** |
|
190 | - * Validate VAT data. |
|
191 | - * |
|
192 | - * @param GetPaid_Payment_Form_Submission $submission |
|
193 | - * @since 1.0.19 |
|
194 | - */ |
|
195 | - public function validate_vat( $submission ) { |
|
196 | - |
|
197 | - $in_eu = $this->is_eu_transaction( $submission->country ); |
|
198 | - |
|
199 | - // Abort if we are not validating vat numbers. |
|
200 | - if ( ! $in_eu || ! wpinv_should_validate_vat_number() ) { |
|
173 | + * Checks if we require a VAT number. |
|
174 | + * |
|
175 | + * @param bool $ip_in_eu Whether the customer IP is from the EU |
|
176 | + * @param bool $country_in_eu Whether the customer country is from the EU |
|
177 | + * @since 1.0.19 |
|
178 | + * @return string |
|
179 | + */ |
|
180 | + public function requires_vat( $ip_in_eu, $country_in_eu ) { |
|
181 | + |
|
182 | + $prevent_b2c = wpinv_get_option( 'vat_prevent_b2c_purchase' ); |
|
183 | + $prevent_b2c = ! empty( $prevent_b2c ); |
|
184 | + $is_eu = $ip_in_eu || $country_in_eu; |
|
185 | + |
|
186 | + return $prevent_b2c && $is_eu; |
|
187 | + } |
|
188 | + |
|
189 | + /** |
|
190 | + * Validate VAT data. |
|
191 | + * |
|
192 | + * @param GetPaid_Payment_Form_Submission $submission |
|
193 | + * @since 1.0.19 |
|
194 | + */ |
|
195 | + public function validate_vat( $submission ) { |
|
196 | + |
|
197 | + $in_eu = $this->is_eu_transaction( $submission->country ); |
|
198 | + |
|
199 | + // Abort if we are not validating vat numbers. |
|
200 | + if ( ! $in_eu || ! wpinv_should_validate_vat_number() ) { |
|
201 | 201 | return; |
202 | - } |
|
202 | + } |
|
203 | 203 | |
204 | - // Prepare variables. |
|
205 | - $vat_number = $this->get_vat_number( $submission ); |
|
206 | - $ip_country = getpaid_get_ip_country(); |
|
204 | + // Prepare variables. |
|
205 | + $vat_number = $this->get_vat_number( $submission ); |
|
206 | + $ip_country = getpaid_get_ip_country(); |
|
207 | 207 | $is_eu = $this->is_eu_country( $submission->country ); |
208 | 208 | $is_ip_eu = $this->is_eu_country( $ip_country ); |
209 | 209 | |
210 | - // If we're preventing business to consumer purchases, |
|
211 | - if ( $this->requires_vat( $is_ip_eu, $is_eu ) && empty( $vat_number ) ) { |
|
210 | + // If we're preventing business to consumer purchases, |
|
211 | + if ( $this->requires_vat( $is_ip_eu, $is_eu ) && empty( $vat_number ) ) { |
|
212 | 212 | |
213 | - // Ensure that a vat number has been specified. |
|
214 | - throw new Exception( |
|
215 | - __( 'Please enter your VAT number to verify your purchase is by an EU business.', 'invoicing' ) |
|
216 | - ); |
|
213 | + // Ensure that a vat number has been specified. |
|
214 | + throw new Exception( |
|
215 | + __( 'Please enter your VAT number to verify your purchase is by an EU business.', 'invoicing' ) |
|
216 | + ); |
|
217 | 217 | |
218 | - } |
|
218 | + } |
|
219 | 219 | |
220 | - if ( empty( $vat_number ) ) { |
|
221 | - return; |
|
222 | - } |
|
220 | + if ( empty( $vat_number ) ) { |
|
221 | + return; |
|
222 | + } |
|
223 | 223 | |
224 | - if ( ! wpinv_validate_vat_number( $vat_number, $submission->country ) ) { |
|
225 | - throw new Exception( __( 'Your VAT number is invalid', 'invoicing' ) ); |
|
226 | - } |
|
224 | + if ( ! wpinv_validate_vat_number( $vat_number, $submission->country ) ) { |
|
225 | + throw new Exception( __( 'Your VAT number is invalid', 'invoicing' ) ); |
|
226 | + } |
|
227 | 227 | |
228 | - if ( 'vat_too' != wpinv_get_option( 'vat_same_country_rule' ) ) { |
|
229 | - $this->skip_taxes = true; |
|
230 | - } |
|
228 | + if ( 'vat_too' != wpinv_get_option( 'vat_same_country_rule' ) ) { |
|
229 | + $this->skip_taxes = true; |
|
230 | + } |
|
231 | 231 | |
232 | - } |
|
232 | + } |
|
233 | 233 | |
234 | 234 | } |
@@ -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,24 +56,24 @@ 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( $item->get_sub_total(), $rates ); |
|
64 | - $r_taxes = getpaid_calculate_item_taxes( $item->get_recurring_sub_total(), $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($item->get_sub_total(), $rates); |
|
64 | + $r_taxes = getpaid_calculate_item_taxes($item->get_recurring_sub_total(), $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 | - if ( ! isset( $this->taxes[ $name ] ) ) { |
|
71 | - $this->taxes[ $name ] = $tax; |
|
70 | + if (!isset($this->taxes[$name])) { |
|
71 | + $this->taxes[$name] = $tax; |
|
72 | 72 | continue; |
73 | 73 | } |
74 | 74 | |
75 | - $this->taxes[ $name ]['initial_tax'] += $tax['initial_tax']; |
|
76 | - $this->taxes[ $name ]['recurring_tax'] += $tax['recurring_tax']; |
|
75 | + $this->taxes[$name]['initial_tax'] += $tax['initial_tax']; |
|
76 | + $this->taxes[$name]['recurring_tax'] += $tax['recurring_tax']; |
|
77 | 77 | |
78 | 78 | } |
79 | 79 | |
@@ -86,11 +86,11 @@ discard block |
||
86 | 86 | * @since 1.0.19 |
87 | 87 | * @return bool |
88 | 88 | */ |
89 | - public function has_digital_item( $submission ) { |
|
89 | + public function has_digital_item($submission) { |
|
90 | 90 | |
91 | - foreach ( $submission->get_items() as $item ) { |
|
91 | + foreach ($submission->get_items() as $item) { |
|
92 | 92 | |
93 | - if ( 'digital' == $item->get_vat_rule() ) { |
|
93 | + if ('digital' == $item->get_vat_rule()) { |
|
94 | 94 | return true; |
95 | 95 | } |
96 | 96 | |
@@ -106,7 +106,7 @@ discard block |
||
106 | 106 | * @return bool |
107 | 107 | */ |
108 | 108 | public function is_eu_store() { |
109 | - return $this->is_eu_country( wpinv_get_default_country() ); |
|
109 | + return $this->is_eu_country(wpinv_get_default_country()); |
|
110 | 110 | } |
111 | 111 | |
112 | 112 | /** |
@@ -116,8 +116,8 @@ discard block |
||
116 | 116 | * @since 1.0.19 |
117 | 117 | * @return bool |
118 | 118 | */ |
119 | - public function is_eu_country( $country ) { |
|
120 | - return getpaid_is_eu_state( $country ) || getpaid_is_gst_country( $country ); |
|
119 | + public function is_eu_country($country) { |
|
120 | + return getpaid_is_eu_state($country) || getpaid_is_gst_country($country); |
|
121 | 121 | } |
122 | 122 | |
123 | 123 | /** |
@@ -127,8 +127,8 @@ discard block |
||
127 | 127 | * @since 1.0.19 |
128 | 128 | * @return bool |
129 | 129 | */ |
130 | - public function is_eu_transaction( $customer_country ) { |
|
131 | - return $this->is_eu_country( $customer_country ) && $this->is_eu_store(); |
|
130 | + public function is_eu_transaction($customer_country) { |
|
131 | + return $this->is_eu_country($customer_country) && $this->is_eu_store(); |
|
132 | 132 | } |
133 | 133 | |
134 | 134 | /** |
@@ -138,12 +138,12 @@ discard block |
||
138 | 138 | * @since 1.0.19 |
139 | 139 | * @return string |
140 | 140 | */ |
141 | - public function get_vat_number( $submission ) { |
|
141 | + public function get_vat_number($submission) { |
|
142 | 142 | |
143 | 143 | // Retrieve from the posted number. |
144 | - $vat_number = $submission->get_field( 'wpinv_vat_number', 'billing' ); |
|
145 | - if ( ! empty( $vat_number ) ) { |
|
146 | - return wpinv_clean( $vat_number ); |
|
144 | + $vat_number = $submission->get_field('wpinv_vat_number', 'billing'); |
|
145 | + if (!empty($vat_number)) { |
|
146 | + return wpinv_clean($vat_number); |
|
147 | 147 | } |
148 | 148 | |
149 | 149 | // Retrieve from the invoice. |
@@ -157,12 +157,12 @@ discard block |
||
157 | 157 | * @since 1.0.19 |
158 | 158 | * @return string |
159 | 159 | */ |
160 | - public function get_company( $submission ) { |
|
160 | + public function get_company($submission) { |
|
161 | 161 | |
162 | 162 | // Retrieve from the posted data. |
163 | - $company = $submission->get_field( 'wpinv_company', 'billing' ); |
|
164 | - if ( ! empty( $company ) ) { |
|
165 | - return wpinv_clean( $company ); |
|
163 | + $company = $submission->get_field('wpinv_company', 'billing'); |
|
164 | + if (!empty($company)) { |
|
165 | + return wpinv_clean($company); |
|
166 | 166 | } |
167 | 167 | |
168 | 168 | // Retrieve from the invoice. |
@@ -177,10 +177,10 @@ discard block |
||
177 | 177 | * @since 1.0.19 |
178 | 178 | * @return string |
179 | 179 | */ |
180 | - public function requires_vat( $ip_in_eu, $country_in_eu ) { |
|
180 | + public function requires_vat($ip_in_eu, $country_in_eu) { |
|
181 | 181 | |
182 | - $prevent_b2c = wpinv_get_option( 'vat_prevent_b2c_purchase' ); |
|
183 | - $prevent_b2c = ! empty( $prevent_b2c ); |
|
182 | + $prevent_b2c = wpinv_get_option('vat_prevent_b2c_purchase'); |
|
183 | + $prevent_b2c = !empty($prevent_b2c); |
|
184 | 184 | $is_eu = $ip_in_eu || $country_in_eu; |
185 | 185 | |
186 | 186 | return $prevent_b2c && $is_eu; |
@@ -192,40 +192,40 @@ discard block |
||
192 | 192 | * @param GetPaid_Payment_Form_Submission $submission |
193 | 193 | * @since 1.0.19 |
194 | 194 | */ |
195 | - public function validate_vat( $submission ) { |
|
195 | + public function validate_vat($submission) { |
|
196 | 196 | |
197 | - $in_eu = $this->is_eu_transaction( $submission->country ); |
|
197 | + $in_eu = $this->is_eu_transaction($submission->country); |
|
198 | 198 | |
199 | 199 | // Abort if we are not validating vat numbers. |
200 | - if ( ! $in_eu || ! wpinv_should_validate_vat_number() ) { |
|
200 | + if (!$in_eu || !wpinv_should_validate_vat_number()) { |
|
201 | 201 | return; |
202 | 202 | } |
203 | 203 | |
204 | 204 | // Prepare variables. |
205 | - $vat_number = $this->get_vat_number( $submission ); |
|
205 | + $vat_number = $this->get_vat_number($submission); |
|
206 | 206 | $ip_country = getpaid_get_ip_country(); |
207 | - $is_eu = $this->is_eu_country( $submission->country ); |
|
208 | - $is_ip_eu = $this->is_eu_country( $ip_country ); |
|
207 | + $is_eu = $this->is_eu_country($submission->country); |
|
208 | + $is_ip_eu = $this->is_eu_country($ip_country); |
|
209 | 209 | |
210 | 210 | // If we're preventing business to consumer purchases, |
211 | - if ( $this->requires_vat( $is_ip_eu, $is_eu ) && empty( $vat_number ) ) { |
|
211 | + if ($this->requires_vat($is_ip_eu, $is_eu) && empty($vat_number)) { |
|
212 | 212 | |
213 | 213 | // Ensure that a vat number has been specified. |
214 | 214 | throw new Exception( |
215 | - __( 'Please enter your VAT number to verify your purchase is by an EU business.', 'invoicing' ) |
|
215 | + __('Please enter your VAT number to verify your purchase is by an EU business.', 'invoicing') |
|
216 | 216 | ); |
217 | 217 | |
218 | 218 | } |
219 | 219 | |
220 | - if ( empty( $vat_number ) ) { |
|
220 | + if (empty($vat_number)) { |
|
221 | 221 | return; |
222 | 222 | } |
223 | 223 | |
224 | - if ( ! wpinv_validate_vat_number( $vat_number, $submission->country ) ) { |
|
225 | - throw new Exception( __( 'Your VAT number is invalid', 'invoicing' ) ); |
|
224 | + if (!wpinv_validate_vat_number($vat_number, $submission->country)) { |
|
225 | + throw new Exception(__('Your VAT number is invalid', 'invoicing')); |
|
226 | 226 | } |
227 | 227 | |
228 | - if ( 'vat_too' != wpinv_get_option( 'vat_same_country_rule' ) ) { |
|
228 | + if ('vat_too' != wpinv_get_option('vat_same_country_rule')) { |
|
229 | 229 | $this->skip_taxes = true; |
230 | 230 | } |
231 | 231 |