@@ -1,13 +1,13 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | // Exit if accessed directly |
3 | -if ( ! defined( 'ABSPATH' ) ) exit; |
|
3 | +if (!defined('ABSPATH')) exit; |
|
4 | 4 | |
5 | -add_action( 'wpinv_paypal_cc_form', '__return_false' ); |
|
6 | -add_filter( 'wpinv_paypal_support_subscription', '__return_true' ); |
|
5 | +add_action('wpinv_paypal_cc_form', '__return_false'); |
|
6 | +add_filter('wpinv_paypal_support_subscription', '__return_true'); |
|
7 | 7 | |
8 | -function wpinv_process_paypal_payment( $purchase_data ) { |
|
9 | - if( ! wp_verify_nonce( $purchase_data['gateway_nonce'], 'wpi-gateway' ) ) { |
|
10 | - wp_die( __( 'Nonce verification has failed', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) ); |
|
8 | +function wpinv_process_paypal_payment($purchase_data) { |
|
9 | + if (!wp_verify_nonce($purchase_data['gateway_nonce'], 'wpi-gateway')) { |
|
10 | + wp_die(__('Nonce verification has failed', 'invoicing'), __('Error', 'invoicing'), array('response' => 403)); |
|
11 | 11 | } |
12 | 12 | |
13 | 13 | // Collect payment data |
@@ -25,30 +25,30 @@ discard block |
||
25 | 25 | ); |
26 | 26 | |
27 | 27 | // Record the pending payment |
28 | - $invoice = wpinv_get_invoice( $purchase_data['invoice_id'] ); |
|
28 | + $invoice = wpinv_get_invoice($purchase_data['invoice_id']); |
|
29 | 29 | |
30 | 30 | // Check payment |
31 | - if ( ! $invoice ) { |
|
31 | + if (!$invoice) { |
|
32 | 32 | // Record the error |
33 | - wpinv_record_gateway_error( __( 'Payment Error', 'invoicing' ), sprintf( __( 'Payment creation failed before sending buyer to PayPal. Payment data: %s', 'invoicing' ), json_encode( $payment_data ) ), $payment ); |
|
33 | + wpinv_record_gateway_error(__('Payment Error', 'invoicing'), sprintf(__('Payment creation failed before sending buyer to PayPal. Payment data: %s', 'invoicing'), json_encode($payment_data)), $payment); |
|
34 | 34 | // Problems? send back |
35 | - wpinv_send_back_to_checkout( '?payment-mode=' . $purchase_data['post_data']['wpi-gateway'] ); |
|
35 | + wpinv_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['wpi-gateway']); |
|
36 | 36 | } else { |
37 | 37 | // Only send to PayPal if the pending payment is created successfully |
38 | - $listener_url = wpinv_get_ipn_url( 'paypal' ); |
|
38 | + $listener_url = wpinv_get_ipn_url('paypal'); |
|
39 | 39 | |
40 | 40 | // Get the success url |
41 | - $return_url = add_query_arg( array( |
|
41 | + $return_url = add_query_arg(array( |
|
42 | 42 | 'payment-confirm' => 'paypal', |
43 | 43 | 'invoice-id' => $invoice->ID |
44 | - ), get_permalink( wpinv_get_option( 'success_page', false ) ) ); |
|
44 | + ), get_permalink(wpinv_get_option('success_page', false))); |
|
45 | 45 | |
46 | 46 | // Get the PayPal redirect uri |
47 | - $paypal_redirect = trailingslashit( wpinv_get_paypal_redirect() ) . '?'; |
|
47 | + $paypal_redirect = trailingslashit(wpinv_get_paypal_redirect()) . '?'; |
|
48 | 48 | |
49 | 49 | // Setup PayPal arguments |
50 | 50 | $paypal_args = array( |
51 | - 'business' => wpinv_get_option( 'paypal_email', false ), |
|
51 | + 'business' => wpinv_get_option('paypal_email', false), |
|
52 | 52 | 'email' => $invoice->get_email(), |
53 | 53 | 'first_name' => $invoice->get_first_name(), |
54 | 54 | 'last_name' => $invoice->get_last_name(), |
@@ -57,16 +57,16 @@ discard block |
||
57 | 57 | 'shipping' => '0', |
58 | 58 | 'no_note' => '1', |
59 | 59 | 'currency_code' => wpinv_get_currency(), |
60 | - 'charset' => get_bloginfo( 'charset' ), |
|
60 | + 'charset' => get_bloginfo('charset'), |
|
61 | 61 | 'custom' => $invoice->ID, |
62 | 62 | 'rm' => '2', |
63 | 63 | 'return' => $return_url, |
64 | - 'cancel_return' => wpinv_get_failed_transaction_uri( '?invoice-id=' . $invoice->ID ), |
|
64 | + 'cancel_return' => wpinv_get_failed_transaction_uri('?invoice-id=' . $invoice->ID), |
|
65 | 65 | 'notify_url' => $listener_url, |
66 | - 'cbt' => get_bloginfo( 'name' ), |
|
66 | + 'cbt' => get_bloginfo('name'), |
|
67 | 67 | 'bn' => 'WPInvoicing_SP', |
68 | 68 | 'lc' => 'US', // this will force paypal site to english |
69 | - 'landing_page' => apply_filters( 'wpinv_paypal_standard_landing_page', 'billing', $invoice ), // 'login' or 'billing'. login - PayPal account login, billing - Non-PayPal account. |
|
69 | + 'landing_page' => apply_filters('wpinv_paypal_standard_landing_page', 'billing', $invoice), // 'login' or 'billing'. login - PayPal account login, billing - Non-PayPal account. |
|
70 | 70 | ); |
71 | 71 | |
72 | 72 | $paypal_args['address1'] = $invoice->get_address(); |
@@ -80,57 +80,57 @@ discard block |
||
80 | 80 | 'upload' => '1' |
81 | 81 | ); |
82 | 82 | |
83 | - $paypal_args = array_merge( $paypal_extra_args, $paypal_args ); |
|
83 | + $paypal_args = array_merge($paypal_extra_args, $paypal_args); |
|
84 | 84 | |
85 | 85 | // Add cart items |
86 | 86 | $i = 1; |
87 | - if( is_array( $purchase_data['cart_details'] ) && ! empty( $purchase_data['cart_details'] ) ) { |
|
88 | - foreach ( $purchase_data['cart_details'] as $item ) { |
|
87 | + if (is_array($purchase_data['cart_details']) && !empty($purchase_data['cart_details'])) { |
|
88 | + foreach ($purchase_data['cart_details'] as $item) { |
|
89 | 89 | $item['quantity'] = $item['quantity'] > 0 ? $item['quantity'] : 1; |
90 | - $item_amount = wpinv_sanitize_amount( $item['subtotal'] / $item['quantity'], 2 ); |
|
90 | + $item_amount = wpinv_sanitize_amount($item['subtotal'] / $item['quantity'], 2); |
|
91 | 91 | |
92 | - if ( $item_amount <= 0 ) { |
|
92 | + if ($item_amount <= 0) { |
|
93 | 93 | $item_amount = 0; |
94 | 94 | } |
95 | 95 | |
96 | - $paypal_args['item_number_' . $i ] = $item['id']; |
|
97 | - $paypal_args['item_name_' . $i ] = stripslashes_deep( html_entity_decode( wpinv_get_cart_item_name( $item ), ENT_COMPAT, 'UTF-8' ) ); |
|
98 | - $paypal_args['quantity_' . $i ] = $item['quantity']; |
|
99 | - $paypal_args['amount_' . $i ] = $item_amount; |
|
100 | - $paypal_args['discount_amount_' . $i ] = wpinv_sanitize_amount( $item['discount'], 2 ); |
|
96 | + $paypal_args['item_number_' . $i] = $item['id']; |
|
97 | + $paypal_args['item_name_' . $i] = stripslashes_deep(html_entity_decode(wpinv_get_cart_item_name($item), ENT_COMPAT, 'UTF-8')); |
|
98 | + $paypal_args['quantity_' . $i] = $item['quantity']; |
|
99 | + $paypal_args['amount_' . $i] = $item_amount; |
|
100 | + $paypal_args['discount_amount_' . $i] = wpinv_sanitize_amount($item['discount'], 2); |
|
101 | 101 | |
102 | 102 | $i++; |
103 | 103 | } |
104 | 104 | } |
105 | 105 | |
106 | 106 | // Add taxes to the cart |
107 | - if ( wpinv_use_taxes() ) { |
|
108 | - $paypal_args['tax_cart'] = wpinv_sanitize_amount( (float)$invoice->get_tax(), 2 ); |
|
107 | + if (wpinv_use_taxes()) { |
|
108 | + $paypal_args['tax_cart'] = wpinv_sanitize_amount((float)$invoice->get_tax(), 2); |
|
109 | 109 | } |
110 | 110 | |
111 | - $paypal_args = apply_filters( 'wpinv_paypal_args', $paypal_args, $purchase_data, $invoice ); |
|
111 | + $paypal_args = apply_filters('wpinv_paypal_args', $paypal_args, $purchase_data, $invoice); |
|
112 | 112 | |
113 | 113 | // Build query |
114 | - $paypal_redirect .= http_build_query( $paypal_args ); |
|
114 | + $paypal_redirect .= http_build_query($paypal_args); |
|
115 | 115 | |
116 | 116 | // Fix for some sites that encode the entities |
117 | - $paypal_redirect = str_replace( '&', '&', $paypal_redirect ); |
|
117 | + $paypal_redirect = str_replace('&', '&', $paypal_redirect); |
|
118 | 118 | |
119 | 119 | // Get rid of cart contents |
120 | 120 | wpinv_empty_cart(); |
121 | 121 | |
122 | 122 | // Redirect to PayPal |
123 | - wp_redirect( $paypal_redirect ); |
|
123 | + wp_redirect($paypal_redirect); |
|
124 | 124 | exit; |
125 | 125 | } |
126 | 126 | } |
127 | -add_action( 'wpinv_gateway_paypal', 'wpinv_process_paypal_payment' ); |
|
127 | +add_action('wpinv_gateway_paypal', 'wpinv_process_paypal_payment'); |
|
128 | 128 | |
129 | -function wpinv_get_paypal_recurring_args( $paypal_args, $purchase_data, $invoice ) { |
|
130 | - if ( $invoice->is_recurring() && $item_id = $invoice->get_recurring() ) { |
|
131 | - $item = new WPInv_Item( $item_id ); |
|
129 | +function wpinv_get_paypal_recurring_args($paypal_args, $purchase_data, $invoice) { |
|
130 | + if ($invoice->is_recurring() && $item_id = $invoice->get_recurring()) { |
|
131 | + $item = new WPInv_Item($item_id); |
|
132 | 132 | |
133 | - if ( empty( $item ) ) { |
|
133 | + if (empty($item)) { |
|
134 | 134 | return $paypal_args; |
135 | 135 | } |
136 | 136 | |
@@ -138,24 +138,24 @@ discard block |
||
138 | 138 | $interval = $item->get_recurring_interval(); |
139 | 139 | $bill_times = (int)$item->get_recurring_limit(); |
140 | 140 | |
141 | - $initial_amount = wpinv_sanitize_amount( $invoice->get_total(), 2 ); |
|
142 | - $recurring_amount = wpinv_sanitize_amount( $invoice->get_recurring_details( 'total' ), 2 ); |
|
141 | + $initial_amount = wpinv_sanitize_amount($invoice->get_total(), 2); |
|
142 | + $recurring_amount = wpinv_sanitize_amount($invoice->get_recurring_details('total'), 2); |
|
143 | 143 | |
144 | 144 | $paypal_args['cmd'] = '_xclick-subscriptions'; |
145 | 145 | $paypal_args['sra'] = '1'; |
146 | 146 | $paypal_args['src'] = '1'; |
147 | 147 | |
148 | 148 | // Set item description |
149 | - $paypal_args['item_name'] = stripslashes_deep( html_entity_decode( wpinv_get_cart_item_name( array( 'id' => $item->ID ) ), ENT_COMPAT, 'UTF-8' ) ); |
|
149 | + $paypal_args['item_name'] = stripslashes_deep(html_entity_decode(wpinv_get_cart_item_name(array('id' => $item->ID)), ENT_COMPAT, 'UTF-8')); |
|
150 | 150 | |
151 | - if ( $invoice->is_free_trial() && $item->has_free_trial() ) { |
|
151 | + if ($invoice->is_free_trial() && $item->has_free_trial()) { |
|
152 | 152 | $paypal_args['a1'] = $initial_amount; |
153 | 153 | $paypal_args['p1'] = $item->get_trial_interval(); |
154 | 154 | $paypal_args['t1'] = $item->get_trial_period(); |
155 | 155 | |
156 | 156 | // Set the recurring amount |
157 | 157 | $paypal_args['a3'] = $recurring_amount; |
158 | - } else if ( $initial_amount != $recurring_amount && $bill_times != 1 ) { |
|
158 | + } else if ($initial_amount != $recurring_amount && $bill_times != 1) { |
|
159 | 159 | $paypal_args['a1'] = $initial_amount; |
160 | 160 | $paypal_args['p1'] = $interval; |
161 | 161 | $paypal_args['t1'] = $period; |
@@ -163,63 +163,63 @@ discard block |
||
163 | 163 | // Set the recurring amount |
164 | 164 | $paypal_args['a3'] = $recurring_amount; |
165 | 165 | |
166 | - if ( $bill_times > 1 ) { |
|
166 | + if ($bill_times > 1) { |
|
167 | 167 | $bill_times--; |
168 | 168 | } |
169 | 169 | } else { |
170 | - $paypal_args['a3'] = $initial_amount; |
|
170 | + $paypal_args['a3'] = $initial_amount; |
|
171 | 171 | } |
172 | 172 | |
173 | 173 | $paypal_args['p3'] = $interval; |
174 | 174 | $paypal_args['t3'] = $period; |
175 | 175 | |
176 | - if ( $bill_times > 1 ) { |
|
176 | + if ($bill_times > 1) { |
|
177 | 177 | // Make sure it's not over the max of 52 |
178 | - $paypal_args['srt'] = ( $bill_times <= 52 ? absint( $bill_times ) : 52 ); |
|
178 | + $paypal_args['srt'] = ($bill_times <= 52 ? absint($bill_times) : 52); |
|
179 | 179 | } |
180 | 180 | |
181 | 181 | // Remove cart items |
182 | 182 | $i = 1; |
183 | - if( is_array( $purchase_data['cart_details'] ) && ! empty( $purchase_data['cart_details'] ) ) { |
|
184 | - foreach ( $purchase_data['cart_details'] as $item ) { |
|
185 | - if ( isset( $paypal_args['item_number_' . $i] ) ) { |
|
186 | - unset( $paypal_args['item_number_' . $i] ); |
|
183 | + if (is_array($purchase_data['cart_details']) && !empty($purchase_data['cart_details'])) { |
|
184 | + foreach ($purchase_data['cart_details'] as $item) { |
|
185 | + if (isset($paypal_args['item_number_' . $i])) { |
|
186 | + unset($paypal_args['item_number_' . $i]); |
|
187 | 187 | } |
188 | - if ( isset( $paypal_args['item_name_' . $i] ) ) { |
|
189 | - unset( $paypal_args['item_name_' . $i] ); |
|
188 | + if (isset($paypal_args['item_name_' . $i])) { |
|
189 | + unset($paypal_args['item_name_' . $i]); |
|
190 | 190 | } |
191 | - if ( isset( $paypal_args['quantity_' . $i] ) ) { |
|
192 | - unset( $paypal_args['quantity_' . $i] ); |
|
191 | + if (isset($paypal_args['quantity_' . $i])) { |
|
192 | + unset($paypal_args['quantity_' . $i]); |
|
193 | 193 | } |
194 | - if ( isset( $paypal_args['amount_' . $i] ) ) { |
|
195 | - unset( $paypal_args['amount_' . $i] ); |
|
194 | + if (isset($paypal_args['amount_' . $i])) { |
|
195 | + unset($paypal_args['amount_' . $i]); |
|
196 | 196 | } |
197 | - if ( isset( $paypal_args['discount_amount_' . $i] ) ) { |
|
198 | - unset( $paypal_args['discount_amount_' . $i] ); |
|
197 | + if (isset($paypal_args['discount_amount_' . $i])) { |
|
198 | + unset($paypal_args['discount_amount_' . $i]); |
|
199 | 199 | } |
200 | 200 | |
201 | 201 | $i++; |
202 | 202 | } |
203 | 203 | } |
204 | 204 | |
205 | - if ( isset( $paypal_args['tax_cart'] ) ) { |
|
206 | - unset( $paypal_args['tax_cart'] ); |
|
205 | + if (isset($paypal_args['tax_cart'])) { |
|
206 | + unset($paypal_args['tax_cart']); |
|
207 | 207 | } |
208 | 208 | |
209 | - if ( isset( $paypal_args['upload'] ) ) { |
|
210 | - unset( $paypal_args['upload'] ); |
|
209 | + if (isset($paypal_args['upload'])) { |
|
210 | + unset($paypal_args['upload']); |
|
211 | 211 | } |
212 | 212 | |
213 | - $paypal_args = apply_filters( 'wpinv_paypal_recurring_args', $paypal_args, $purchase_data, $invoice ); |
|
213 | + $paypal_args = apply_filters('wpinv_paypal_recurring_args', $paypal_args, $purchase_data, $invoice); |
|
214 | 214 | } |
215 | 215 | |
216 | 216 | return $paypal_args; |
217 | 217 | } |
218 | -add_filter( 'wpinv_paypal_args', 'wpinv_get_paypal_recurring_args', 10, 3 ); |
|
218 | +add_filter('wpinv_paypal_args', 'wpinv_get_paypal_recurring_args', 10, 3); |
|
219 | 219 | |
220 | 220 | function wpinv_process_paypal_ipn() { |
221 | 221 | // Check the request method is POST |
222 | - if ( isset( $_SERVER['REQUEST_METHOD'] ) && $_SERVER['REQUEST_METHOD'] != 'POST' ) { |
|
222 | + if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] != 'POST') { |
|
223 | 223 | return; |
224 | 224 | } |
225 | 225 | |
@@ -227,11 +227,11 @@ discard block |
||
227 | 227 | $post_data = ''; |
228 | 228 | |
229 | 229 | // Fallback just in case post_max_size is lower than needed |
230 | - if ( ini_get( 'allow_url_fopen' ) ) { |
|
231 | - $post_data = file_get_contents( 'php://input' ); |
|
230 | + if (ini_get('allow_url_fopen')) { |
|
231 | + $post_data = file_get_contents('php://input'); |
|
232 | 232 | } else { |
233 | 233 | // If allow_url_fopen is not enabled, then make sure that post_max_size is large enough |
234 | - ini_set( 'post_max_size', '12M' ); |
|
234 | + ini_set('post_max_size', '12M'); |
|
235 | 235 | } |
236 | 236 | // Start the encoded data collection with notification command |
237 | 237 | $encoded_data = 'cmd=_notify-validate'; |
@@ -240,43 +240,43 @@ discard block |
||
240 | 240 | $arg_separator = wpinv_get_php_arg_separator_output(); |
241 | 241 | |
242 | 242 | // Verify there is a post_data |
243 | - if ( $post_data || strlen( $post_data ) > 0 ) { |
|
243 | + if ($post_data || strlen($post_data) > 0) { |
|
244 | 244 | // Append the data |
245 | - $encoded_data .= $arg_separator.$post_data; |
|
245 | + $encoded_data .= $arg_separator . $post_data; |
|
246 | 246 | } else { |
247 | 247 | // Check if POST is empty |
248 | - if ( empty( $_POST ) ) { |
|
248 | + if (empty($_POST)) { |
|
249 | 249 | // Nothing to do |
250 | 250 | return; |
251 | 251 | } else { |
252 | 252 | // Loop through each POST |
253 | - foreach ( $_POST as $key => $value ) { |
|
253 | + foreach ($_POST as $key => $value) { |
|
254 | 254 | // Encode the value and append the data |
255 | - $encoded_data .= $arg_separator."$key=" . urlencode( $value ); |
|
255 | + $encoded_data .= $arg_separator . "$key=" . urlencode($value); |
|
256 | 256 | } |
257 | 257 | } |
258 | 258 | } |
259 | 259 | |
260 | 260 | // Convert collected post data to an array |
261 | - parse_str( $encoded_data, $encoded_data_array ); |
|
261 | + parse_str($encoded_data, $encoded_data_array); |
|
262 | 262 | |
263 | - foreach ( $encoded_data_array as $key => $value ) { |
|
264 | - if ( false !== strpos( $key, 'amp;' ) ) { |
|
265 | - $new_key = str_replace( '&', '&', $key ); |
|
266 | - $new_key = str_replace( 'amp;', '&' , $new_key ); |
|
263 | + foreach ($encoded_data_array as $key => $value) { |
|
264 | + if (false !== strpos($key, 'amp;')) { |
|
265 | + $new_key = str_replace('&', '&', $key); |
|
266 | + $new_key = str_replace('amp;', '&', $new_key); |
|
267 | 267 | |
268 | - unset( $encoded_data_array[ $key ] ); |
|
269 | - $encoded_data_array[ $new_key ] = $value; |
|
268 | + unset($encoded_data_array[$key]); |
|
269 | + $encoded_data_array[$new_key] = $value; |
|
270 | 270 | } |
271 | 271 | } |
272 | 272 | |
273 | 273 | // Get the PayPal redirect uri |
274 | - $paypal_redirect = wpinv_get_paypal_redirect( true ); |
|
274 | + $paypal_redirect = wpinv_get_paypal_redirect(true); |
|
275 | 275 | |
276 | - if ( !wpinv_get_option( 'disable_paypal_verification', false ) ) { |
|
276 | + if (!wpinv_get_option('disable_paypal_verification', false)) { |
|
277 | 277 | // Validate the IPN |
278 | 278 | |
279 | - $remote_post_vars = array( |
|
279 | + $remote_post_vars = array( |
|
280 | 280 | 'method' => 'POST', |
281 | 281 | 'timeout' => 45, |
282 | 282 | 'redirection' => 5, |
@@ -294,21 +294,21 @@ discard block |
||
294 | 294 | ); |
295 | 295 | |
296 | 296 | // Get response |
297 | - $api_response = wp_remote_post( wpinv_get_paypal_redirect(), $remote_post_vars ); |
|
297 | + $api_response = wp_remote_post(wpinv_get_paypal_redirect(), $remote_post_vars); |
|
298 | 298 | |
299 | - if ( is_wp_error( $api_response ) ) { |
|
300 | - wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid IPN verification response. IPN data: %s', 'invoicing' ), json_encode( $api_response ) ) ); |
|
299 | + if (is_wp_error($api_response)) { |
|
300 | + wpinv_record_gateway_error(__('IPN Error', 'invoicing'), sprintf(__('Invalid IPN verification response. IPN data: %s', 'invoicing'), json_encode($api_response))); |
|
301 | 301 | return; // Something went wrong |
302 | 302 | } |
303 | 303 | |
304 | - if ( $api_response['body'] !== 'VERIFIED' && wpinv_get_option( 'disable_paypal_verification', false ) ) { |
|
305 | - wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid IPN verification response. IPN data: %s', 'invoicing' ), json_encode( $api_response ) ) ); |
|
304 | + if ($api_response['body'] !== 'VERIFIED' && wpinv_get_option('disable_paypal_verification', false)) { |
|
305 | + wpinv_record_gateway_error(__('IPN Error', 'invoicing'), sprintf(__('Invalid IPN verification response. IPN data: %s', 'invoicing'), json_encode($api_response))); |
|
306 | 306 | return; // Response not okay |
307 | 307 | } |
308 | 308 | } |
309 | 309 | |
310 | 310 | // Check if $post_data_array has been populated |
311 | - if ( !is_array( $encoded_data_array ) && !empty( $encoded_data_array ) ) |
|
311 | + if (!is_array($encoded_data_array) && !empty($encoded_data_array)) |
|
312 | 312 | return; |
313 | 313 | |
314 | 314 | $defaults = array( |
@@ -316,215 +316,215 @@ discard block |
||
316 | 316 | 'payment_status' => '' |
317 | 317 | ); |
318 | 318 | |
319 | - $encoded_data_array = wp_parse_args( $encoded_data_array, $defaults ); |
|
319 | + $encoded_data_array = wp_parse_args($encoded_data_array, $defaults); |
|
320 | 320 | |
321 | - $invoice_id = isset( $encoded_data_array['custom'] ) ? absint( $encoded_data_array['custom'] ) : 0; |
|
321 | + $invoice_id = isset($encoded_data_array['custom']) ? absint($encoded_data_array['custom']) : 0; |
|
322 | 322 | |
323 | - wpinv_error_log( $encoded_data_array['txn_type'], 'PayPal txn_type', __FILE__, __LINE__ ); |
|
323 | + wpinv_error_log($encoded_data_array['txn_type'], 'PayPal txn_type', __FILE__, __LINE__); |
|
324 | 324 | |
325 | - if ( has_action( 'wpinv_paypal_' . $encoded_data_array['txn_type'] ) ) { |
|
325 | + if (has_action('wpinv_paypal_' . $encoded_data_array['txn_type'])) { |
|
326 | 326 | // Allow PayPal IPN types to be processed separately |
327 | - do_action( 'wpinv_paypal_' . $encoded_data_array['txn_type'], $encoded_data_array, $invoice_id ); |
|
327 | + do_action('wpinv_paypal_' . $encoded_data_array['txn_type'], $encoded_data_array, $invoice_id); |
|
328 | 328 | } else { |
329 | 329 | // Fallback to web accept just in case the txn_type isn't present |
330 | - do_action( 'wpinv_paypal_web_accept', $encoded_data_array, $invoice_id ); |
|
330 | + do_action('wpinv_paypal_web_accept', $encoded_data_array, $invoice_id); |
|
331 | 331 | } |
332 | 332 | exit; |
333 | 333 | } |
334 | -add_action( 'wpinv_verify_paypal_ipn', 'wpinv_process_paypal_ipn' ); |
|
334 | +add_action('wpinv_verify_paypal_ipn', 'wpinv_process_paypal_ipn'); |
|
335 | 335 | |
336 | -function wpinv_process_paypal_web_accept_and_cart( $data, $invoice_id ) { |
|
337 | - if ( $data['txn_type'] != 'web_accept' && $data['txn_type'] != 'cart' && $data['payment_status'] != 'Refunded' ) { |
|
336 | +function wpinv_process_paypal_web_accept_and_cart($data, $invoice_id) { |
|
337 | + if ($data['txn_type'] != 'web_accept' && $data['txn_type'] != 'cart' && $data['payment_status'] != 'Refunded') { |
|
338 | 338 | return; |
339 | 339 | } |
340 | 340 | |
341 | - if( empty( $invoice_id ) ) { |
|
341 | + if (empty($invoice_id)) { |
|
342 | 342 | return; |
343 | 343 | } |
344 | 344 | |
345 | 345 | // Collect payment details |
346 | - $purchase_key = isset( $data['invoice'] ) ? $data['invoice'] : $data['item_number']; |
|
346 | + $purchase_key = isset($data['invoice']) ? $data['invoice'] : $data['item_number']; |
|
347 | 347 | $paypal_amount = $data['mc_gross']; |
348 | - $payment_status = strtolower( $data['payment_status'] ); |
|
349 | - $currency_code = strtolower( $data['mc_currency'] ); |
|
350 | - $business_email = isset( $data['business'] ) && is_email( $data['business'] ) ? trim( $data['business'] ) : trim( $data['receiver_email'] ); |
|
351 | - $payment_meta = wpinv_get_invoice_meta( $invoice_id ); |
|
348 | + $payment_status = strtolower($data['payment_status']); |
|
349 | + $currency_code = strtolower($data['mc_currency']); |
|
350 | + $business_email = isset($data['business']) && is_email($data['business']) ? trim($data['business']) : trim($data['receiver_email']); |
|
351 | + $payment_meta = wpinv_get_invoice_meta($invoice_id); |
|
352 | 352 | |
353 | - if ( wpinv_get_payment_gateway( $invoice_id ) != 'paypal' ) { |
|
353 | + if (wpinv_get_payment_gateway($invoice_id) != 'paypal') { |
|
354 | 354 | return; // this isn't a PayPal standard IPN |
355 | 355 | } |
356 | 356 | |
357 | 357 | // Verify payment recipient |
358 | - if ( strcasecmp( $business_email, trim( wpinv_get_option( 'paypal_email', false ) ) ) != 0 ) { |
|
359 | - wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid business email in IPN response. IPN data: %s', 'invoicing' ), json_encode( $data ) ), $invoice_id ); |
|
360 | - wpinv_update_payment_status( $invoice_id, 'wpi-failed' ); |
|
361 | - wpinv_insert_payment_note( $invoice_id, __( 'Payment failed due to invalid PayPal business email.', 'invoicing' ) ); |
|
358 | + if (strcasecmp($business_email, trim(wpinv_get_option('paypal_email', false))) != 0) { |
|
359 | + wpinv_record_gateway_error(__('IPN Error', 'invoicing'), sprintf(__('Invalid business email in IPN response. IPN data: %s', 'invoicing'), json_encode($data)), $invoice_id); |
|
360 | + wpinv_update_payment_status($invoice_id, 'wpi-failed'); |
|
361 | + wpinv_insert_payment_note($invoice_id, __('Payment failed due to invalid PayPal business email.', 'invoicing')); |
|
362 | 362 | return; |
363 | 363 | } |
364 | 364 | |
365 | 365 | // Verify payment currency |
366 | - if ( $currency_code != strtolower( $payment_meta['currency'] ) ) { |
|
367 | - wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid currency in IPN response. IPN data: %s', 'invoicing' ), json_encode( $data ) ), $invoice_id ); |
|
368 | - wpinv_update_payment_status( $invoice_id, 'wpi-failed' ); |
|
369 | - wpinv_insert_payment_note( $invoice_id, __( 'Payment failed due to invalid currency in PayPal IPN.', 'invoicing' ) ); |
|
366 | + if ($currency_code != strtolower($payment_meta['currency'])) { |
|
367 | + wpinv_record_gateway_error(__('IPN Error', 'invoicing'), sprintf(__('Invalid currency in IPN response. IPN data: %s', 'invoicing'), json_encode($data)), $invoice_id); |
|
368 | + wpinv_update_payment_status($invoice_id, 'wpi-failed'); |
|
369 | + wpinv_insert_payment_note($invoice_id, __('Payment failed due to invalid currency in PayPal IPN.', 'invoicing')); |
|
370 | 370 | return; |
371 | 371 | } |
372 | 372 | |
373 | - if ( !wpinv_get_payment_user_email( $invoice_id ) ) { |
|
373 | + if (!wpinv_get_payment_user_email($invoice_id)) { |
|
374 | 374 | // This runs when a Buy Now purchase was made. It bypasses checkout so no personal info is collected until PayPal |
375 | 375 | // No email associated with purchase, so store from PayPal |
376 | - wpinv_update_invoice_meta( $invoice_id, '_wpinv_email', $data['payer_email'] ); |
|
376 | + wpinv_update_invoice_meta($invoice_id, '_wpinv_email', $data['payer_email']); |
|
377 | 377 | |
378 | 378 | // Setup and store the customer's details |
379 | 379 | $user_info = array( |
380 | 380 | 'user_id' => '-1', |
381 | - 'email' => sanitize_text_field( $data['payer_email'] ), |
|
382 | - 'first_name' => sanitize_text_field( $data['first_name'] ), |
|
383 | - 'last_name' => sanitize_text_field( $data['last_name'] ), |
|
381 | + 'email' => sanitize_text_field($data['payer_email']), |
|
382 | + 'first_name' => sanitize_text_field($data['first_name']), |
|
383 | + 'last_name' => sanitize_text_field($data['last_name']), |
|
384 | 384 | 'discount' => '', |
385 | 385 | ); |
386 | - $user_info['address'] = ! empty( $data['address_street'] ) ? sanitize_text_field( $data['address_street'] ) : false; |
|
387 | - $user_info['city'] = ! empty( $data['address_city'] ) ? sanitize_text_field( $data['address_city'] ) : false; |
|
388 | - $user_info['state'] = ! empty( $data['address_state'] ) ? sanitize_text_field( $data['address_state'] ) : false; |
|
389 | - $user_info['country'] = ! empty( $data['address_country_code'] ) ? sanitize_text_field( $data['address_country_code'] ) : false; |
|
390 | - $user_info['zip'] = ! empty( $data['address_zip'] ) ? sanitize_text_field( $data['address_zip'] ) : false; |
|
386 | + $user_info['address'] = !empty($data['address_street']) ? sanitize_text_field($data['address_street']) : false; |
|
387 | + $user_info['city'] = !empty($data['address_city']) ? sanitize_text_field($data['address_city']) : false; |
|
388 | + $user_info['state'] = !empty($data['address_state']) ? sanitize_text_field($data['address_state']) : false; |
|
389 | + $user_info['country'] = !empty($data['address_country_code']) ? sanitize_text_field($data['address_country_code']) : false; |
|
390 | + $user_info['zip'] = !empty($data['address_zip']) ? sanitize_text_field($data['address_zip']) : false; |
|
391 | 391 | |
392 | 392 | $payment_meta['user_info'] = $user_info; |
393 | - wpinv_update_invoice_meta( $invoice_id, '_wpinv_payment_meta', $payment_meta ); |
|
393 | + wpinv_update_invoice_meta($invoice_id, '_wpinv_payment_meta', $payment_meta); |
|
394 | 394 | } |
395 | 395 | |
396 | - if ( $payment_status == 'refunded' || $payment_status == 'reversed' ) { |
|
396 | + if ($payment_status == 'refunded' || $payment_status == 'reversed') { |
|
397 | 397 | // Process a refund |
398 | - wpinv_process_paypal_refund( $data, $invoice_id ); |
|
398 | + wpinv_process_paypal_refund($data, $invoice_id); |
|
399 | 399 | } else { |
400 | - if ( get_post_status( $invoice_id ) == 'publish' ) { |
|
400 | + if (get_post_status($invoice_id) == 'publish') { |
|
401 | 401 | return; // Only paid payments once |
402 | 402 | } |
403 | 403 | |
404 | 404 | // Retrieve the total purchase amount (before PayPal) |
405 | - $payment_amount = wpinv_payment_total( $invoice_id ); |
|
405 | + $payment_amount = wpinv_payment_total($invoice_id); |
|
406 | 406 | |
407 | - if ( number_format( (float) $paypal_amount, 2 ) < number_format( (float) $payment_amount, 2 ) ) { |
|
407 | + if (number_format((float)$paypal_amount, 2) < number_format((float)$payment_amount, 2)) { |
|
408 | 408 | // The prices don't match |
409 | - wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid payment amount in IPN response. IPN data: %s', 'invoicing' ), json_encode( $data ) ), $invoice_id ); |
|
410 | - wpinv_update_payment_status( $invoice_id, 'wpi-failed' ); |
|
411 | - wpinv_insert_payment_note( $invoice_id, __( 'Payment failed due to invalid amount in PayPal IPN.', 'invoicing' ) ); |
|
409 | + wpinv_record_gateway_error(__('IPN Error', 'invoicing'), sprintf(__('Invalid payment amount in IPN response. IPN data: %s', 'invoicing'), json_encode($data)), $invoice_id); |
|
410 | + wpinv_update_payment_status($invoice_id, 'wpi-failed'); |
|
411 | + wpinv_insert_payment_note($invoice_id, __('Payment failed due to invalid amount in PayPal IPN.', 'invoicing')); |
|
412 | 412 | return; |
413 | 413 | } |
414 | - if ( $purchase_key != wpinv_get_payment_key( $invoice_id ) ) { |
|
414 | + if ($purchase_key != wpinv_get_payment_key($invoice_id)) { |
|
415 | 415 | // Purchase keys don't match |
416 | - wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid purchase key in IPN response. IPN data: %s', 'invoicing' ), json_encode( $data ) ), $invoice_id ); |
|
417 | - wpinv_update_payment_status( $invoice_id, 'wpi-failed' ); |
|
418 | - wpinv_insert_payment_note( $invoice_id, __( 'Payment failed due to invalid purchase key in PayPal IPN.', 'invoicing' ) ); |
|
416 | + wpinv_record_gateway_error(__('IPN Error', 'invoicing'), sprintf(__('Invalid purchase key in IPN response. IPN data: %s', 'invoicing'), json_encode($data)), $invoice_id); |
|
417 | + wpinv_update_payment_status($invoice_id, 'wpi-failed'); |
|
418 | + wpinv_insert_payment_note($invoice_id, __('Payment failed due to invalid purchase key in PayPal IPN.', 'invoicing')); |
|
419 | 419 | return; |
420 | 420 | } |
421 | 421 | |
422 | - if ( 'complete' == $payment_status || 'completed' == $payment_status || 'processed' == $payment_status || wpinv_is_test_mode( 'paypal' ) ) { |
|
423 | - wpinv_insert_payment_note( $invoice_id, sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ) , $data['txn_id'] ) ); |
|
424 | - wpinv_set_payment_transaction_id( $invoice_id, $data['txn_id'] ); |
|
425 | - wpinv_update_payment_status( $invoice_id, 'publish' ); |
|
426 | - } else if ( 'wpi-pending' == $payment_status && isset( $data['pending_reason'] ) ) { |
|
422 | + if ('complete' == $payment_status || 'completed' == $payment_status || 'processed' == $payment_status || wpinv_is_test_mode('paypal')) { |
|
423 | + wpinv_insert_payment_note($invoice_id, sprintf(__('PayPal Transaction ID: %s', 'invoicing'), $data['txn_id'])); |
|
424 | + wpinv_set_payment_transaction_id($invoice_id, $data['txn_id']); |
|
425 | + wpinv_update_payment_status($invoice_id, 'publish'); |
|
426 | + } else if ('wpi-pending' == $payment_status && isset($data['pending_reason'])) { |
|
427 | 427 | // Look for possible pending reasons, such as an echeck |
428 | 428 | $note = ''; |
429 | 429 | |
430 | - switch( strtolower( $data['pending_reason'] ) ) { |
|
430 | + switch (strtolower($data['pending_reason'])) { |
|
431 | 431 | case 'echeck' : |
432 | - $note = __( 'Payment made via eCheck and will clear automatically in 5-8 days', 'invoicing' ); |
|
432 | + $note = __('Payment made via eCheck and will clear automatically in 5-8 days', 'invoicing'); |
|
433 | 433 | break; |
434 | 434 | |
435 | 435 | case 'address' : |
436 | - $note = __( 'Payment requires a confirmed customer address and must be accepted manually through PayPal', 'invoicing' ); |
|
436 | + $note = __('Payment requires a confirmed customer address and must be accepted manually through PayPal', 'invoicing'); |
|
437 | 437 | break; |
438 | 438 | |
439 | 439 | case 'intl' : |
440 | - $note = __( 'Payment must be accepted manually through PayPal due to international account regulations', 'invoicing' ); |
|
440 | + $note = __('Payment must be accepted manually through PayPal due to international account regulations', 'invoicing'); |
|
441 | 441 | break; |
442 | 442 | |
443 | 443 | case 'multi-currency' : |
444 | - $note = __( 'Payment received in non-shop currency and must be accepted manually through PayPal', 'invoicing' ); |
|
444 | + $note = __('Payment received in non-shop currency and must be accepted manually through PayPal', 'invoicing'); |
|
445 | 445 | break; |
446 | 446 | |
447 | 447 | case 'paymentreview' : |
448 | 448 | case 'regulatory_review' : |
449 | - $note = __( 'Payment is being reviewed by PayPal staff as high-risk or in possible violation of government regulations', 'invoicing' ); |
|
449 | + $note = __('Payment is being reviewed by PayPal staff as high-risk or in possible violation of government regulations', 'invoicing'); |
|
450 | 450 | break; |
451 | 451 | |
452 | 452 | case 'unilateral' : |
453 | - $note = __( 'Payment was sent to non-confirmed or non-registered email address.', 'invoicing' ); |
|
453 | + $note = __('Payment was sent to non-confirmed or non-registered email address.', 'invoicing'); |
|
454 | 454 | break; |
455 | 455 | |
456 | 456 | case 'upgrade' : |
457 | - $note = __( 'PayPal account must be upgraded before this payment can be accepted', 'invoicing' ); |
|
457 | + $note = __('PayPal account must be upgraded before this payment can be accepted', 'invoicing'); |
|
458 | 458 | break; |
459 | 459 | |
460 | 460 | case 'verify' : |
461 | - $note = __( 'PayPal account is not verified. Verify account in order to accept this payment', 'invoicing' ); |
|
461 | + $note = __('PayPal account is not verified. Verify account in order to accept this payment', 'invoicing'); |
|
462 | 462 | break; |
463 | 463 | |
464 | 464 | case 'other' : |
465 | - $note = __( 'Payment is pending for unknown reasons. Contact PayPal support for assistance', 'invoicing' ); |
|
465 | + $note = __('Payment is pending for unknown reasons. Contact PayPal support for assistance', 'invoicing'); |
|
466 | 466 | break; |
467 | 467 | } |
468 | 468 | |
469 | - if ( ! empty( $note ) ) { |
|
470 | - wpinv_insert_payment_note( $invoice_id, $note ); |
|
469 | + if (!empty($note)) { |
|
470 | + wpinv_insert_payment_note($invoice_id, $note); |
|
471 | 471 | } |
472 | 472 | } else { |
473 | - wpinv_insert_payment_note( $invoice_id, wp_sprintf( __( 'PayPal IPN has been received with invalid payment status: %s', 'invoicing' ), $payment_status ) ); |
|
473 | + wpinv_insert_payment_note($invoice_id, wp_sprintf(__('PayPal IPN has been received with invalid payment status: %s', 'invoicing'), $payment_status)); |
|
474 | 474 | } |
475 | 475 | } |
476 | 476 | } |
477 | -add_action( 'wpinv_paypal_web_accept', 'wpinv_process_paypal_web_accept_and_cart', 10, 2 ); |
|
477 | +add_action('wpinv_paypal_web_accept', 'wpinv_process_paypal_web_accept_and_cart', 10, 2); |
|
478 | 478 | |
479 | 479 | // Process PayPal subscription sign ups |
480 | -add_action( 'wpinv_paypal_subscr_signup', 'wpinv_process_paypal_subscr_signup' ); |
|
480 | +add_action('wpinv_paypal_subscr_signup', 'wpinv_process_paypal_subscr_signup'); |
|
481 | 481 | |
482 | 482 | // Process PayPal subscription payments |
483 | -add_action( 'wpinv_paypal_subscr_payment', 'wpinv_process_paypal_subscr_payment' ); |
|
483 | +add_action('wpinv_paypal_subscr_payment', 'wpinv_process_paypal_subscr_payment'); |
|
484 | 484 | |
485 | 485 | // Process PayPal subscription cancellations |
486 | -add_action( 'wpinv_paypal_subscr_cancel', 'wpinv_process_paypal_subscr_cancel' ); |
|
486 | +add_action('wpinv_paypal_subscr_cancel', 'wpinv_process_paypal_subscr_cancel'); |
|
487 | 487 | |
488 | 488 | // Process PayPal subscription end of term notices |
489 | -add_action( 'wpinv_paypal_subscr_eot', 'wpinv_process_paypal_subscr_eot' ); |
|
489 | +add_action('wpinv_paypal_subscr_eot', 'wpinv_process_paypal_subscr_eot'); |
|
490 | 490 | |
491 | 491 | // Process PayPal payment failed |
492 | -add_action( 'wpinv_paypal_subscr_failed', 'wpinv_process_paypal_subscr_failed' ); |
|
492 | +add_action('wpinv_paypal_subscr_failed', 'wpinv_process_paypal_subscr_failed'); |
|
493 | 493 | |
494 | 494 | |
495 | 495 | /** |
496 | 496 | * Process the subscription started IPN. |
497 | 497 | */ |
498 | -function wpinv_process_paypal_subscr_signup( $ipn_data ) { |
|
499 | - $parent_invoice_id = absint( $ipn_data['custom'] ); |
|
500 | - if( empty( $parent_invoice_id ) ) { |
|
498 | +function wpinv_process_paypal_subscr_signup($ipn_data) { |
|
499 | + $parent_invoice_id = absint($ipn_data['custom']); |
|
500 | + if (empty($parent_invoice_id)) { |
|
501 | 501 | return; |
502 | 502 | } |
503 | 503 | |
504 | - $invoice = wpinv_get_invoice( $parent_invoice_id ); |
|
505 | - if ( empty( $invoice ) ) { |
|
504 | + $invoice = wpinv_get_invoice($parent_invoice_id); |
|
505 | + if (empty($invoice)) { |
|
506 | 506 | return; |
507 | 507 | } |
508 | 508 | |
509 | - if ( $invoice->is_free_trial() && !empty( $ipn_data['invoice'] ) ) { |
|
510 | - wpinv_insert_payment_note( $parent_invoice_id, sprintf( __( 'PayPal Invoice ID: %s', 'invoicing' ) , $ipn_data['invoice'] ) ); |
|
511 | - wpinv_set_payment_transaction_id( $parent_invoice_id, $ipn_data['invoice'] ); |
|
509 | + if ($invoice->is_free_trial() && !empty($ipn_data['invoice'])) { |
|
510 | + wpinv_insert_payment_note($parent_invoice_id, sprintf(__('PayPal Invoice ID: %s', 'invoicing'), $ipn_data['invoice'])); |
|
511 | + wpinv_set_payment_transaction_id($parent_invoice_id, $ipn_data['invoice']); |
|
512 | 512 | } |
513 | 513 | |
514 | - wpinv_update_payment_status( $parent_invoice_id, 'publish' ); |
|
514 | + wpinv_update_payment_status($parent_invoice_id, 'publish'); |
|
515 | 515 | sleep(1); |
516 | - wpinv_insert_payment_note( $parent_invoice_id, sprintf( __( 'PayPal Subscription ID: %s', 'invoicing' ) , $ipn_data['subscr_id'] ) ); |
|
516 | + wpinv_insert_payment_note($parent_invoice_id, sprintf(__('PayPal Subscription ID: %s', 'invoicing'), $ipn_data['subscr_id'])); |
|
517 | 517 | |
518 | - $subscription = wpinv_get_paypal_subscription( $ipn_data ); |
|
519 | - if ( false === $subscription ) { |
|
518 | + $subscription = wpinv_get_paypal_subscription($ipn_data); |
|
519 | + if (false === $subscription) { |
|
520 | 520 | return; |
521 | 521 | } |
522 | 522 | |
523 | - $cart_details = $invoice->cart_details; |
|
523 | + $cart_details = $invoice->cart_details; |
|
524 | 524 | |
525 | - if ( !empty( $cart_details ) ) { |
|
526 | - foreach ( $cart_details as $cart_item ) { |
|
527 | - $item = new WPInv_Item( $cart_item['id'] ); |
|
525 | + if (!empty($cart_details)) { |
|
526 | + foreach ($cart_details as $cart_item) { |
|
527 | + $item = new WPInv_Item($cart_item['id']); |
|
528 | 528 | |
529 | 529 | $status = $invoice->is_free_trial() && $item->has_free_trial() ? 'trialing' : 'active'; |
530 | 530 | |
@@ -533,15 +533,15 @@ discard block |
||
533 | 533 | 'status' => $status, |
534 | 534 | 'period' => $item->get_recurring_period(), |
535 | 535 | 'initial_amount' => $invoice->get_total(), |
536 | - 'recurring_amount' => $invoice->get_recurring_details( 'total' ), |
|
536 | + 'recurring_amount' => $invoice->get_recurring_details('total'), |
|
537 | 537 | 'interval' => $item->get_recurring_interval(), |
538 | 538 | 'bill_times' => $item->get_recurring_limit(), |
539 | - 'expiration' => $invoice->get_new_expiration( $cart_item['id'] ), |
|
539 | + 'expiration' => $invoice->get_new_expiration($cart_item['id']), |
|
540 | 540 | 'profile_id' => $ipn_data['subscr_id'], |
541 | - 'created' => date_i18n( 'Y-m-d H:i:s', strtotime( $ipn_data['subscr_date'] ) ) |
|
541 | + 'created' => date_i18n('Y-m-d H:i:s', strtotime($ipn_data['subscr_date'])) |
|
542 | 542 | ); |
543 | 543 | |
544 | - if ( $item->has_free_trial() ) { |
|
544 | + if ($item->has_free_trial()) { |
|
545 | 545 | $args['trial_period'] = $item->get_trial_period(); |
546 | 546 | $args['trial_interval'] = $item->get_trial_interval(); |
547 | 547 | } else { |
@@ -550,7 +550,7 @@ discard block |
||
550 | 550 | } |
551 | 551 | |
552 | 552 | |
553 | - $subscription->update_subscription( $args ); |
|
553 | + $subscription->update_subscription($args); |
|
554 | 554 | } |
555 | 555 | } |
556 | 556 | } |
@@ -558,45 +558,45 @@ discard block |
||
558 | 558 | /** |
559 | 559 | * Process the subscription payment received IPN. |
560 | 560 | */ |
561 | -function wpinv_process_paypal_subscr_payment( $ipn_data ) { |
|
562 | - $parent_invoice_id = absint( $ipn_data['custom'] ); |
|
561 | +function wpinv_process_paypal_subscr_payment($ipn_data) { |
|
562 | + $parent_invoice_id = absint($ipn_data['custom']); |
|
563 | 563 | |
564 | - $subscription = wpinv_get_paypal_subscription( $ipn_data ); |
|
565 | - if ( false === $subscription ) { |
|
564 | + $subscription = wpinv_get_paypal_subscription($ipn_data); |
|
565 | + if (false === $subscription) { |
|
566 | 566 | return; |
567 | 567 | } |
568 | 568 | |
569 | - $parent_invoice = wpinv_get_invoice( $parent_invoice_id ); |
|
570 | - if ( empty( $parent_invoice ) ) { |
|
569 | + $parent_invoice = wpinv_get_invoice($parent_invoice_id); |
|
570 | + if (empty($parent_invoice)) { |
|
571 | 571 | return; |
572 | 572 | } |
573 | 573 | |
574 | - $transaction_id = wpinv_get_payment_transaction_id( $parent_invoice_id ); |
|
574 | + $transaction_id = wpinv_get_payment_transaction_id($parent_invoice_id); |
|
575 | 575 | $signup_date = $subscription->get_subscription_created(); |
576 | 576 | $payment_date = $ipn_data['payment_date']; |
577 | - $times_billed = $parent_invoice->get_total_payments( false ); |
|
577 | + $times_billed = $parent_invoice->get_total_payments(false); |
|
578 | 578 | |
579 | 579 | // Look to see if payment is same day as signup and we have set the transaction ID on the parent payment yet. |
580 | - if ( empty( $times_billed ) && ( !$transaction_id || $transaction_id == $parent_invoice_id ) ) { |
|
581 | - wpinv_update_payment_status( $parent_invoice_id, 'publish' ); |
|
580 | + if (empty($times_billed) && (!$transaction_id || $transaction_id == $parent_invoice_id)) { |
|
581 | + wpinv_update_payment_status($parent_invoice_id, 'publish'); |
|
582 | 582 | sleep(1); |
583 | 583 | |
584 | 584 | // This is the very first payment |
585 | - wpinv_set_payment_transaction_id( $parent_invoice_id, $ipn_data['txn_id'] ); |
|
586 | - wpinv_insert_payment_note( $parent_invoice_id, sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ) , $ipn_data['txn_id'] ) ); |
|
585 | + wpinv_set_payment_transaction_id($parent_invoice_id, $ipn_data['txn_id']); |
|
586 | + wpinv_insert_payment_note($parent_invoice_id, sprintf(__('PayPal Transaction ID: %s', 'invoicing'), $ipn_data['txn_id'])); |
|
587 | 587 | return; |
588 | 588 | } |
589 | 589 | |
590 | - if ( wpinv_get_id_by_transaction_id( $ipn_data['txn_id'] ) ) { |
|
590 | + if (wpinv_get_id_by_transaction_id($ipn_data['txn_id'])) { |
|
591 | 591 | return; // Payment already recorded |
592 | 592 | } |
593 | 593 | |
594 | - $currency_code = strtolower( $ipn_data['mc_currency'] ); |
|
594 | + $currency_code = strtolower($ipn_data['mc_currency']); |
|
595 | 595 | |
596 | 596 | // verify details |
597 | - if ( $currency_code != strtolower( wpinv_get_currency() ) ) { |
|
597 | + if ($currency_code != strtolower(wpinv_get_currency())) { |
|
598 | 598 | // the currency code is invalid |
599 | - wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid currency in IPN response. IPN data: ', 'invoicing' ), json_encode( $ipn_data ) ) ); |
|
599 | + wpinv_record_gateway_error(__('IPN Error', 'invoicing'), sprintf(__('Invalid currency in IPN response. IPN data: ', 'invoicing'), json_encode($ipn_data))); |
|
600 | 600 | return; |
601 | 601 | } |
602 | 602 | |
@@ -605,11 +605,11 @@ discard block |
||
605 | 605 | 'transaction_id' => $ipn_data['txn_id'] |
606 | 606 | ); |
607 | 607 | |
608 | - $invoice = wpinv_recurring_add_subscription_payment( $parent_invoice_id, $args ); |
|
608 | + $invoice = wpinv_recurring_add_subscription_payment($parent_invoice_id, $args); |
|
609 | 609 | |
610 | - if ( !empty( $invoice ) ) { |
|
610 | + if (!empty($invoice)) { |
|
611 | 611 | sleep(1); |
612 | - wpinv_insert_payment_note( $invoice->ID, sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ) , $ipn_data['txn_id'] ) ); |
|
612 | + wpinv_insert_payment_note($invoice->ID, sprintf(__('PayPal Transaction ID: %s', 'invoicing'), $ipn_data['txn_id'])); |
|
613 | 613 | |
614 | 614 | $invoice->renew_subscription(); |
615 | 615 | } |
@@ -618,10 +618,10 @@ discard block |
||
618 | 618 | /** |
619 | 619 | * Process the subscription canceled IPN. |
620 | 620 | */ |
621 | -function wpinv_process_paypal_subscr_cancel( $ipn_data ) { |
|
622 | - $subscription = wpinv_get_paypal_subscription( $ipn_data ); |
|
621 | +function wpinv_process_paypal_subscr_cancel($ipn_data) { |
|
622 | + $subscription = wpinv_get_paypal_subscription($ipn_data); |
|
623 | 623 | |
624 | - if( false === $subscription ) { |
|
624 | + if (false === $subscription) { |
|
625 | 625 | return; |
626 | 626 | } |
627 | 627 | |
@@ -631,10 +631,10 @@ discard block |
||
631 | 631 | /** |
632 | 632 | * Process the subscription expired IPN. |
633 | 633 | */ |
634 | -function wpinv_process_paypal_subscr_eot( $ipn_data ) { |
|
635 | - $subscription = wpinv_get_paypal_subscription( $ipn_data ); |
|
634 | +function wpinv_process_paypal_subscr_eot($ipn_data) { |
|
635 | + $subscription = wpinv_get_paypal_subscription($ipn_data); |
|
636 | 636 | |
637 | - if( false === $subscription ) { |
|
637 | + if (false === $subscription) { |
|
638 | 638 | return; |
639 | 639 | } |
640 | 640 | |
@@ -644,45 +644,45 @@ discard block |
||
644 | 644 | /** |
645 | 645 | * Process the subscription payment failed IPN. |
646 | 646 | */ |
647 | -function wpinv_process_paypal_subscr_failed( $ipn_data ) { |
|
648 | - $subscription = wpinv_get_paypal_subscription( $ipn_data ); |
|
647 | +function wpinv_process_paypal_subscr_failed($ipn_data) { |
|
648 | + $subscription = wpinv_get_paypal_subscription($ipn_data); |
|
649 | 649 | |
650 | - if( false === $subscription ) { |
|
650 | + if (false === $subscription) { |
|
651 | 651 | return; |
652 | 652 | } |
653 | 653 | |
654 | 654 | $subscription->failing_subscription(); |
655 | 655 | |
656 | - do_action( 'wpinv_recurring_payment_failed', $subscription ); |
|
656 | + do_action('wpinv_recurring_payment_failed', $subscription); |
|
657 | 657 | } |
658 | 658 | |
659 | 659 | /** |
660 | 660 | * Retrieve the subscription this IPN notice is for. |
661 | 661 | */ |
662 | -function wpinv_get_paypal_subscription( $ipn_data = array() ) { |
|
663 | - $parent_invoice_id = absint( $ipn_data['custom'] ); |
|
662 | +function wpinv_get_paypal_subscription($ipn_data = array()) { |
|
663 | + $parent_invoice_id = absint($ipn_data['custom']); |
|
664 | 664 | |
665 | - if( empty( $parent_invoice_id ) ) { |
|
665 | + if (empty($parent_invoice_id)) { |
|
666 | 666 | return false; |
667 | 667 | } |
668 | 668 | |
669 | - $invoice = wpinv_get_invoice( $parent_invoice_id ); |
|
670 | - if ( empty( $invoice ) ) { |
|
669 | + $invoice = wpinv_get_invoice($parent_invoice_id); |
|
670 | + if (empty($invoice)) { |
|
671 | 671 | return false; |
672 | 672 | } |
673 | 673 | |
674 | - $subscription = wpinv_get_subscription( $ipn_data['subscr_id'], true ); |
|
674 | + $subscription = wpinv_get_subscription($ipn_data['subscr_id'], true); |
|
675 | 675 | |
676 | - if ( empty( $subscription ) ) { |
|
677 | - $subs = wpinv_get_subscriptions( array( 'parent_invoice_id' => $parent_invoice_id, 'numberposts' => 1 ) ); |
|
678 | - $subscription = reset( $subs ); |
|
676 | + if (empty($subscription)) { |
|
677 | + $subs = wpinv_get_subscriptions(array('parent_invoice_id' => $parent_invoice_id, 'numberposts' => 1)); |
|
678 | + $subscription = reset($subs); |
|
679 | 679 | |
680 | - if ( $subscription && $subscription->ID > 0 ) { |
|
680 | + if ($subscription && $subscription->ID > 0) { |
|
681 | 681 | // Update the profile ID so it is set for future renewals |
682 | - $subscription->update_subscription( array( 'profile_id' => sanitize_text_field( $ipn_data['subscr_id'] ) ) ); |
|
682 | + $subscription->update_subscription(array('profile_id' => sanitize_text_field($ipn_data['subscr_id']))); |
|
683 | 683 | } else { |
684 | 684 | $subscription = $invoice; |
685 | - $subscription->update_subscription( array( 'profile_id' => sanitize_text_field( $ipn_data['subscr_id'] ) ) ); |
|
685 | + $subscription->update_subscription(array('profile_id' => sanitize_text_field($ipn_data['subscr_id']))); |
|
686 | 686 | // No subscription found with a matching payment ID, bail |
687 | 687 | //return false; |
688 | 688 | } |
@@ -692,39 +692,39 @@ discard block |
||
692 | 692 | |
693 | 693 | } |
694 | 694 | |
695 | -function wpinv_process_paypal_refund( $data, $invoice_id = 0 ) { |
|
695 | +function wpinv_process_paypal_refund($data, $invoice_id = 0) { |
|
696 | 696 | // Collect payment details |
697 | 697 | |
698 | - if( empty( $invoice_id ) ) { |
|
698 | + if (empty($invoice_id)) { |
|
699 | 699 | return; |
700 | 700 | } |
701 | 701 | |
702 | - if ( get_post_status( $invoice_id ) == 'wpi-refunded' ) { |
|
702 | + if (get_post_status($invoice_id) == 'wpi-refunded') { |
|
703 | 703 | return; // Only refund payments once |
704 | 704 | } |
705 | 705 | |
706 | - $payment_amount = wpinv_payment_total( $invoice_id ); |
|
706 | + $payment_amount = wpinv_payment_total($invoice_id); |
|
707 | 707 | $refund_amount = $data['mc_gross'] * -1; |
708 | 708 | |
709 | - if ( number_format( (float) $refund_amount, 2 ) < number_format( (float) $payment_amount, 2 ) ) { |
|
710 | - wpinv_insert_payment_note( $invoice_id, sprintf( __( 'Partial PayPal refund processed: %s', 'invoicing' ), $data['parent_txn_id'] ) ); |
|
709 | + if (number_format((float)$refund_amount, 2) < number_format((float)$payment_amount, 2)) { |
|
710 | + wpinv_insert_payment_note($invoice_id, sprintf(__('Partial PayPal refund processed: %s', 'invoicing'), $data['parent_txn_id'])); |
|
711 | 711 | return; // This is a partial refund |
712 | 712 | } |
713 | 713 | |
714 | - wpinv_insert_payment_note( $invoice_id, sprintf( __( 'PayPal Payment #%s Refunded for reason: %s', 'invoicing' ), $data['parent_txn_id'], $data['reason_code'] ) ); |
|
715 | - wpinv_insert_payment_note( $invoice_id, sprintf( __( 'PayPal Refund Transaction ID: %s', 'invoicing' ), $data['txn_id'] ) ); |
|
716 | - wpinv_update_payment_status( $invoice_id, 'wpi-refunded' ); |
|
714 | + wpinv_insert_payment_note($invoice_id, sprintf(__('PayPal Payment #%s Refunded for reason: %s', 'invoicing'), $data['parent_txn_id'], $data['reason_code'])); |
|
715 | + wpinv_insert_payment_note($invoice_id, sprintf(__('PayPal Refund Transaction ID: %s', 'invoicing'), $data['txn_id'])); |
|
716 | + wpinv_update_payment_status($invoice_id, 'wpi-refunded'); |
|
717 | 717 | } |
718 | 718 | |
719 | -function wpinv_get_paypal_redirect( $ssl_check = false ) { |
|
720 | - if ( is_ssl() || ! $ssl_check ) { |
|
719 | +function wpinv_get_paypal_redirect($ssl_check = false) { |
|
720 | + if (is_ssl() || !$ssl_check) { |
|
721 | 721 | $protocol = 'https://'; |
722 | 722 | } else { |
723 | 723 | $protocol = 'http://'; |
724 | 724 | } |
725 | 725 | |
726 | 726 | // Check the current payment mode |
727 | - if ( wpinv_is_test_mode( 'paypal' ) ) { |
|
727 | + if (wpinv_is_test_mode('paypal')) { |
|
728 | 728 | // Test mode |
729 | 729 | $paypal_uri = $protocol . 'www.sandbox.paypal.com/cgi-bin/webscr'; |
730 | 730 | } else { |
@@ -732,67 +732,67 @@ discard block |
||
732 | 732 | $paypal_uri = $protocol . 'www.paypal.com/cgi-bin/webscr'; |
733 | 733 | } |
734 | 734 | |
735 | - return apply_filters( 'wpinv_paypal_uri', $paypal_uri ); |
|
735 | + return apply_filters('wpinv_paypal_uri', $paypal_uri); |
|
736 | 736 | } |
737 | 737 | |
738 | -function wpinv_paypal_success_page_content( $content ) { |
|
738 | +function wpinv_paypal_success_page_content($content) { |
|
739 | 739 | global $wpi_invoice; |
740 | 740 | |
741 | 741 | $session = wpinv_get_checkout_session(); |
742 | 742 | |
743 | - if ( empty( $_GET['invoice-id'] ) && empty( $session['invoice_key'] ) ) { |
|
743 | + if (empty($_GET['invoice-id']) && empty($session['invoice_key'])) { |
|
744 | 744 | return $content; |
745 | 745 | } |
746 | 746 | |
747 | - $invoice_id = !empty( $_GET['invoice-id'] ) ? absint( $_GET['invoice-id'] ) : wpinv_get_invoice_id_by_key( $session['invoice_key'] ); |
|
747 | + $invoice_id = !empty($_GET['invoice-id']) ? absint($_GET['invoice-id']) : wpinv_get_invoice_id_by_key($session['invoice_key']); |
|
748 | 748 | |
749 | - if ( empty( $invoice_id ) ) { |
|
749 | + if (empty($invoice_id)) { |
|
750 | 750 | return $content; |
751 | 751 | } |
752 | 752 | |
753 | - $wpi_invoice = wpinv_get_invoice( $invoice_id ); |
|
753 | + $wpi_invoice = wpinv_get_invoice($invoice_id); |
|
754 | 754 | |
755 | - if ( !empty( $wpi_invoice ) && 'wpi-pending' == $wpi_invoice->status ) { |
|
755 | + if (!empty($wpi_invoice) && 'wpi-pending' == $wpi_invoice->status) { |
|
756 | 756 | // Payment is still pending so show processing indicator to fix the Race Condition, issue # |
757 | 757 | ob_start(); |
758 | - wpinv_get_template_part( 'wpinv-payment-processing' ); |
|
758 | + wpinv_get_template_part('wpinv-payment-processing'); |
|
759 | 759 | $content = ob_get_clean(); |
760 | 760 | } |
761 | 761 | |
762 | 762 | return $content; |
763 | 763 | } |
764 | -add_filter( 'wpinv_payment_confirm_paypal', 'wpinv_paypal_success_page_content' ); |
|
764 | +add_filter('wpinv_payment_confirm_paypal', 'wpinv_paypal_success_page_content'); |
|
765 | 765 | |
766 | -function wpinv_paypal_get_transaction_id( $invoice_id ) { |
|
766 | +function wpinv_paypal_get_transaction_id($invoice_id) { |
|
767 | 767 | $transaction_id = ''; |
768 | - $notes = wpinv_get_invoice_notes( $invoice_id ); |
|
768 | + $notes = wpinv_get_invoice_notes($invoice_id); |
|
769 | 769 | |
770 | - foreach ( $notes as $note ) { |
|
771 | - if ( preg_match( '/^PayPal Transaction ID: ([^\s]+)/', $note->comment_content, $match ) ) { |
|
770 | + foreach ($notes as $note) { |
|
771 | + if (preg_match('/^PayPal Transaction ID: ([^\s]+)/', $note->comment_content, $match)) { |
|
772 | 772 | $transaction_id = $match[1]; |
773 | 773 | continue; |
774 | 774 | } |
775 | 775 | } |
776 | 776 | |
777 | - return apply_filters( 'wpinv_paypal_set_transaction_id', $transaction_id, $invoice_id ); |
|
777 | + return apply_filters('wpinv_paypal_set_transaction_id', $transaction_id, $invoice_id); |
|
778 | 778 | } |
779 | -add_filter( 'wpinv_payment_get_transaction_id-paypal', 'wpinv_paypal_get_transaction_id', 10, 1 ); |
|
779 | +add_filter('wpinv_payment_get_transaction_id-paypal', 'wpinv_paypal_get_transaction_id', 10, 1); |
|
780 | 780 | |
781 | -function wpinv_paypal_link_transaction_id( $transaction_id, $invoice_id, $invoice ) { |
|
782 | - if ( $invoice->is_free_trial() || $transaction_id == $invoice_id ) { // Free trial does not have transaction at PayPal. |
|
781 | +function wpinv_paypal_link_transaction_id($transaction_id, $invoice_id, $invoice) { |
|
782 | + if ($invoice->is_free_trial() || $transaction_id == $invoice_id) { // Free trial does not have transaction at PayPal. |
|
783 | 783 | $transaction_url = $invoice->get_view_url(); |
784 | 784 | } else { |
785 | - $sandbox = wpinv_is_test_mode( 'paypal' ) ? '.sandbox' : ''; |
|
785 | + $sandbox = wpinv_is_test_mode('paypal') ? '.sandbox' : ''; |
|
786 | 786 | $transaction_url = 'https://www' . $sandbox . '.paypal.com/cgi-bin/webscr?cmd=_view-a-trans&id=' . $transaction_id; |
787 | 787 | } |
788 | 788 | |
789 | - $transaction_link = '<a href="' . esc_url( $transaction_url ) . '" target="_blank">' . $transaction_id . '</a>'; |
|
789 | + $transaction_link = '<a href="' . esc_url($transaction_url) . '" target="_blank">' . $transaction_id . '</a>'; |
|
790 | 790 | |
791 | - return apply_filters( 'wpinv_paypal_link_payment_details_transaction_id', $transaction_link, $invoice ); |
|
791 | + return apply_filters('wpinv_paypal_link_payment_details_transaction_id', $transaction_link, $invoice); |
|
792 | 792 | } |
793 | -add_filter( 'wpinv_payment_details_transaction_id-paypal', 'wpinv_paypal_link_transaction_id', 10, 3 ); |
|
793 | +add_filter('wpinv_payment_details_transaction_id-paypal', 'wpinv_paypal_link_transaction_id', 10, 3); |
|
794 | 794 | |
795 | 795 | function wpinv_gateway_paypal_button_label($label) { |
796 | - return __( 'Proceed to PayPal', 'invoicing' ); |
|
796 | + return __('Proceed to PayPal', 'invoicing'); |
|
797 | 797 | } |
798 | -add_filter( 'wpinv_gateway_paypal_button_label', 'wpinv_gateway_paypal_button_label', 10, 1 ); |
|
799 | 798 | \ No newline at end of file |
799 | +add_filter('wpinv_gateway_paypal_button_label', 'wpinv_gateway_paypal_button_label', 10, 1); |
|
800 | 800 | \ No newline at end of file |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | // Exit if accessed directly. |
3 | -if (!defined( 'ABSPATH' ) ) exit; |
|
3 | +if (!defined('ABSPATH')) exit; |
|
4 | 4 | |
5 | 5 | class WPInv_EUVat { |
6 | 6 | private static $is_ajax = false; |
@@ -8,7 +8,7 @@ discard block |
||
8 | 8 | private static $instance = false; |
9 | 9 | |
10 | 10 | public static function get_instance() { |
11 | - if ( !self::$instance ) { |
|
11 | + if (!self::$instance) { |
|
12 | 12 | self::$instance = new self(); |
13 | 13 | self::$instance->actions(); |
14 | 14 | } |
@@ -17,132 +17,132 @@ discard block |
||
17 | 17 | } |
18 | 18 | |
19 | 19 | public function __construct() { |
20 | - self::$is_ajax = defined( 'DOING_AJAX' ) && DOING_AJAX; |
|
20 | + self::$is_ajax = defined('DOING_AJAX') && DOING_AJAX; |
|
21 | 21 | self::$default_country = wpinv_get_default_country(); |
22 | 22 | } |
23 | 23 | |
24 | 24 | public static function actions() { |
25 | - if ( is_admin() ) { |
|
26 | - add_action( 'admin_enqueue_scripts', array( self::$instance, 'enqueue_admin_scripts' ) ); |
|
27 | - add_action( 'wpinv_settings_sections_taxes', array( self::$instance, 'section_vat_settings' ) ); |
|
28 | - add_action( 'wpinv_settings_taxes', array( self::$instance, 'vat_settings' ) ); |
|
29 | - add_filter( 'wpinv_settings_taxes-vat_sanitize', array( self::$instance, 'sanitize_vat_settings' ) ); |
|
30 | - add_filter( 'wpinv_settings_taxes-vat_rates_sanitize', array( self::$instance, 'sanitize_vat_rates' ) ); |
|
31 | - add_action( 'wp_ajax_wpinv_add_vat_class', array( self::$instance, 'add_class' ) ); |
|
32 | - add_action( 'wp_ajax_nopriv_wpinv_add_vat_class', array( self::$instance, 'add_class' ) ); |
|
33 | - add_action( 'wp_ajax_wpinv_delete_vat_class', array( self::$instance, 'delete_class' ) ); |
|
34 | - add_action( 'wp_ajax_nopriv_wpinv_delete_vat_class', array( self::$instance, 'delete_class' ) ); |
|
35 | - add_action( 'wp_ajax_wpinv_update_vat_rates', array( self::$instance, 'update_eu_rates' ) ); |
|
36 | - add_action( 'wp_ajax_nopriv_wpinv_update_vat_rates', array( self::$instance, 'update_eu_rates' ) ); |
|
37 | - add_action( 'wp_ajax_wpinv_geoip2', array( self::$instance, 'geoip2_download_database' ) ); |
|
38 | - add_action( 'wp_ajax_nopriv_wpinv_geoip2', array( self::$instance, 'geoip2_download_database' ) ); |
|
39 | - } |
|
40 | - |
|
41 | - add_action( 'wp_enqueue_scripts', array( self::$instance, 'enqueue_vat_scripts' ) ); |
|
42 | - add_filter( 'wpinv_default_billing_country', array( self::$instance, 'get_user_country' ), 10 ); |
|
43 | - add_filter( 'wpinv_get_user_country', array( self::$instance, 'set_user_country' ), 10 ); |
|
44 | - add_action( 'wp_ajax_wpinv_vat_validate', array( self::$instance, 'ajax_vat_validate' ) ); |
|
45 | - add_action( 'wp_ajax_nopriv_wpinv_vat_validate', array( self::$instance, 'ajax_vat_validate' ) ); |
|
46 | - add_action( 'wp_ajax_wpinv_vat_reset', array( self::$instance, 'ajax_vat_reset' ) ); |
|
47 | - add_action( 'wp_ajax_nopriv_wpinv_vat_reset', array( self::$instance, 'ajax_vat_reset' ) ); |
|
48 | - add_action( 'wpinv_invoice_print_after_line_items', array( self::$instance, 'show_vat_notice' ), 999, 1 ); |
|
49 | - if ( wpinv_use_taxes() ) { |
|
50 | - add_action( 'wpinv_after_billing_fields', array( self::$instance, 'checkout_vat_fields' ) ); |
|
51 | - if ( self::allow_vat_rules() ) { |
|
52 | - add_action( 'wpinv_checkout_error_checks', array( self::$instance, 'checkout_vat_validate' ), 10, 2 ); |
|
53 | - add_filter( 'wpinv_tax_rate', array( self::$instance, 'get_rate' ), 10, 4 ); |
|
25 | + if (is_admin()) { |
|
26 | + add_action('admin_enqueue_scripts', array(self::$instance, 'enqueue_admin_scripts')); |
|
27 | + add_action('wpinv_settings_sections_taxes', array(self::$instance, 'section_vat_settings')); |
|
28 | + add_action('wpinv_settings_taxes', array(self::$instance, 'vat_settings')); |
|
29 | + add_filter('wpinv_settings_taxes-vat_sanitize', array(self::$instance, 'sanitize_vat_settings')); |
|
30 | + add_filter('wpinv_settings_taxes-vat_rates_sanitize', array(self::$instance, 'sanitize_vat_rates')); |
|
31 | + add_action('wp_ajax_wpinv_add_vat_class', array(self::$instance, 'add_class')); |
|
32 | + add_action('wp_ajax_nopriv_wpinv_add_vat_class', array(self::$instance, 'add_class')); |
|
33 | + add_action('wp_ajax_wpinv_delete_vat_class', array(self::$instance, 'delete_class')); |
|
34 | + add_action('wp_ajax_nopriv_wpinv_delete_vat_class', array(self::$instance, 'delete_class')); |
|
35 | + add_action('wp_ajax_wpinv_update_vat_rates', array(self::$instance, 'update_eu_rates')); |
|
36 | + add_action('wp_ajax_nopriv_wpinv_update_vat_rates', array(self::$instance, 'update_eu_rates')); |
|
37 | + add_action('wp_ajax_wpinv_geoip2', array(self::$instance, 'geoip2_download_database')); |
|
38 | + add_action('wp_ajax_nopriv_wpinv_geoip2', array(self::$instance, 'geoip2_download_database')); |
|
39 | + } |
|
40 | + |
|
41 | + add_action('wp_enqueue_scripts', array(self::$instance, 'enqueue_vat_scripts')); |
|
42 | + add_filter('wpinv_default_billing_country', array(self::$instance, 'get_user_country'), 10); |
|
43 | + add_filter('wpinv_get_user_country', array(self::$instance, 'set_user_country'), 10); |
|
44 | + add_action('wp_ajax_wpinv_vat_validate', array(self::$instance, 'ajax_vat_validate')); |
|
45 | + add_action('wp_ajax_nopriv_wpinv_vat_validate', array(self::$instance, 'ajax_vat_validate')); |
|
46 | + add_action('wp_ajax_wpinv_vat_reset', array(self::$instance, 'ajax_vat_reset')); |
|
47 | + add_action('wp_ajax_nopriv_wpinv_vat_reset', array(self::$instance, 'ajax_vat_reset')); |
|
48 | + add_action('wpinv_invoice_print_after_line_items', array(self::$instance, 'show_vat_notice'), 999, 1); |
|
49 | + if (wpinv_use_taxes()) { |
|
50 | + add_action('wpinv_after_billing_fields', array(self::$instance, 'checkout_vat_fields')); |
|
51 | + if (self::allow_vat_rules()) { |
|
52 | + add_action('wpinv_checkout_error_checks', array(self::$instance, 'checkout_vat_validate'), 10, 2); |
|
53 | + add_filter('wpinv_tax_rate', array(self::$instance, 'get_rate'), 10, 4); |
|
54 | 54 | } |
55 | 55 | } |
56 | 56 | } |
57 | 57 | |
58 | - public static function get_eu_states( $sort = true ) { |
|
59 | - $eu_states = array( 'AT', 'BE', 'BG', 'HR', 'CY', 'CZ', 'DK', 'EE', 'FI', 'FR', 'DE', 'GB', 'GR', 'HU', 'IE', 'IT', 'LV', 'LT', 'LU', 'MT', 'NL', 'PL', 'PT', 'RO', 'SK', 'SI', 'ES', 'SE' ); |
|
60 | - if ( $sort ) { |
|
61 | - $sort = sort( $eu_states ); |
|
58 | + public static function get_eu_states($sort = true) { |
|
59 | + $eu_states = array('AT', 'BE', 'BG', 'HR', 'CY', 'CZ', 'DK', 'EE', 'FI', 'FR', 'DE', 'GB', 'GR', 'HU', 'IE', 'IT', 'LV', 'LT', 'LU', 'MT', 'NL', 'PL', 'PT', 'RO', 'SK', 'SI', 'ES', 'SE'); |
|
60 | + if ($sort) { |
|
61 | + $sort = sort($eu_states); |
|
62 | 62 | } |
63 | 63 | |
64 | - return apply_filters( 'wpinv_get_eu_states', $eu_states, $sort ); |
|
64 | + return apply_filters('wpinv_get_eu_states', $eu_states, $sort); |
|
65 | 65 | } |
66 | 66 | |
67 | - public static function get_gst_countries( $sort = true ) { |
|
68 | - $gst_countries = array( 'AU', 'NZ', 'CA', 'CN' ); |
|
67 | + public static function get_gst_countries($sort = true) { |
|
68 | + $gst_countries = array('AU', 'NZ', 'CA', 'CN'); |
|
69 | 69 | |
70 | - if ( $sort ) { |
|
71 | - $sort = sort( $gst_countries ); |
|
70 | + if ($sort) { |
|
71 | + $sort = sort($gst_countries); |
|
72 | 72 | } |
73 | 73 | |
74 | - return apply_filters( 'wpinv_get_gst_countries', $gst_countries, $sort ); |
|
74 | + return apply_filters('wpinv_get_gst_countries', $gst_countries, $sort); |
|
75 | 75 | } |
76 | 76 | |
77 | - public static function is_eu_state( $country_code ) { |
|
78 | - $return = !empty( $country_code ) && in_array( strtoupper( $country_code ), self::get_eu_states() ) ? true : false; |
|
77 | + public static function is_eu_state($country_code) { |
|
78 | + $return = !empty($country_code) && in_array(strtoupper($country_code), self::get_eu_states()) ? true : false; |
|
79 | 79 | |
80 | - return apply_filters( 'wpinv_is_eu_state', $return, $country_code ); |
|
80 | + return apply_filters('wpinv_is_eu_state', $return, $country_code); |
|
81 | 81 | } |
82 | 82 | |
83 | - public static function is_gst_country( $country_code ) { |
|
84 | - $return = !empty( $country_code ) && in_array( strtoupper( $country_code ), self::get_gst_countries() ) ? true : false; |
|
83 | + public static function is_gst_country($country_code) { |
|
84 | + $return = !empty($country_code) && in_array(strtoupper($country_code), self::get_gst_countries()) ? true : false; |
|
85 | 85 | |
86 | - return apply_filters( 'wpinv_is_gst_country', $return, $country_code ); |
|
86 | + return apply_filters('wpinv_is_gst_country', $return, $country_code); |
|
87 | 87 | } |
88 | 88 | |
89 | 89 | public static function enqueue_vat_scripts() { |
90 | - $suffix = '';//defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
90 | + $suffix = ''; //defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
91 | 91 | |
92 | - wp_register_script( 'wpinv-vat-validation-script', WPINV_PLUGIN_URL . 'assets/js/jsvat' . $suffix . '.js', array( 'jquery' ), WPINV_VERSION ); |
|
93 | - wp_register_script( 'wpinv-vat-script', WPINV_PLUGIN_URL . 'assets/js/euvat' . $suffix . '.js', array( 'jquery' ), WPINV_VERSION ); |
|
92 | + wp_register_script('wpinv-vat-validation-script', WPINV_PLUGIN_URL . 'assets/js/jsvat' . $suffix . '.js', array('jquery'), WPINV_VERSION); |
|
93 | + wp_register_script('wpinv-vat-script', WPINV_PLUGIN_URL . 'assets/js/euvat' . $suffix . '.js', array('jquery'), WPINV_VERSION); |
|
94 | 94 | |
95 | - $vat_name = self::get_vat_name(); |
|
95 | + $vat_name = self::get_vat_name(); |
|
96 | 96 | |
97 | 97 | $vars = array(); |
98 | 98 | $vars['UseTaxes'] = wpinv_use_taxes(); |
99 | 99 | $vars['EUStates'] = self::get_eu_states(); |
100 | - $vars['NoRateSet'] = __( 'You have not set a rate. Do you want to continue?', 'invoicing' ); |
|
101 | - $vars['EmptyCompany'] = __( 'Please enter your registered company name!', 'invoicing' ); |
|
102 | - $vars['EmptyVAT'] = wp_sprintf( __( 'Please enter your %s number!', 'invoicing' ), $vat_name ); |
|
103 | - $vars['TotalsRefreshed'] = wp_sprintf( __( 'The invoice totals will be refreshed to update the %s.', 'invoicing' ), $vat_name ); |
|
104 | - $vars['ErrValidateVAT'] = wp_sprintf( __( 'Fail to validate the %s number!', 'invoicing' ), $vat_name ); |
|
105 | - $vars['ErrResetVAT'] = wp_sprintf( __( 'Fail to reset the %s number!', 'invoicing' ), $vat_name ); |
|
106 | - $vars['ErrInvalidVat'] = wp_sprintf( __( 'The %s number supplied does not have a valid format!', 'invoicing' ), $vat_name ); |
|
107 | - $vars['ErrInvalidResponse'] = __( 'An invalid response has been received from the server!', 'invoicing' ); |
|
100 | + $vars['NoRateSet'] = __('You have not set a rate. Do you want to continue?', 'invoicing'); |
|
101 | + $vars['EmptyCompany'] = __('Please enter your registered company name!', 'invoicing'); |
|
102 | + $vars['EmptyVAT'] = wp_sprintf(__('Please enter your %s number!', 'invoicing'), $vat_name); |
|
103 | + $vars['TotalsRefreshed'] = wp_sprintf(__('The invoice totals will be refreshed to update the %s.', 'invoicing'), $vat_name); |
|
104 | + $vars['ErrValidateVAT'] = wp_sprintf(__('Fail to validate the %s number!', 'invoicing'), $vat_name); |
|
105 | + $vars['ErrResetVAT'] = wp_sprintf(__('Fail to reset the %s number!', 'invoicing'), $vat_name); |
|
106 | + $vars['ErrInvalidVat'] = wp_sprintf(__('The %s number supplied does not have a valid format!', 'invoicing'), $vat_name); |
|
107 | + $vars['ErrInvalidResponse'] = __('An invalid response has been received from the server!', 'invoicing'); |
|
108 | 108 | $vars['ApplyVATRules'] = $vars['UseTaxes'] ? self::allow_vat_rules() : false; |
109 | 109 | $vars['HideVatFields'] = $vars['ApplyVATRules'] ? self::hide_vat_fields() : true; |
110 | - $vars['ErrResponse'] = __( 'The request response is invalid!', 'invoicing' ); |
|
111 | - $vars['ErrRateResponse'] = __( 'The get rate request response is invalid', 'invoicing' ); |
|
112 | - $vars['PageRefresh'] = __( 'The page will be refreshed in 10 seconds to show the new options.', 'invoicing' ); |
|
113 | - $vars['RequestResponseNotValidJSON'] = __( 'The get rate request response is not valid JSON', 'invoicing' ); |
|
114 | - $vars['GetRateRequestFailed'] = __( 'The get rate request failed: ', 'invoicing' ); |
|
115 | - $vars['NoRateInformationInResponse'] = __( 'The get rate request response does not contain any rate information', 'invoicing' ); |
|
116 | - $vars['RatesUpdated'] = __( 'The rates have been updated. Press the save button to record these new rates.', 'invoicing' ); |
|
117 | - $vars['IPAddressInformation'] = __( 'IP Address Information', 'invoicing' ); |
|
118 | - $vars['VatValidating'] = wp_sprintf( __( 'Validating %s number...', 'invoicing' ), $vat_name ); |
|
119 | - $vars['VatReseting'] = __( 'Reseting...', 'invoicing' ); |
|
120 | - $vars['VatValidated'] = wp_sprintf( __( '%s number validated', 'invoicing' ), $vat_name ); |
|
121 | - $vars['VatNotValidated'] = wp_sprintf( __( '%s number not validated', 'invoicing' ), $vat_name ); |
|
122 | - $vars['ConfirmDeleteClass'] = __( 'Are you sure you wish to delete this rates class?', 'invoicing' ); |
|
110 | + $vars['ErrResponse'] = __('The request response is invalid!', 'invoicing'); |
|
111 | + $vars['ErrRateResponse'] = __('The get rate request response is invalid', 'invoicing'); |
|
112 | + $vars['PageRefresh'] = __('The page will be refreshed in 10 seconds to show the new options.', 'invoicing'); |
|
113 | + $vars['RequestResponseNotValidJSON'] = __('The get rate request response is not valid JSON', 'invoicing'); |
|
114 | + $vars['GetRateRequestFailed'] = __('The get rate request failed: ', 'invoicing'); |
|
115 | + $vars['NoRateInformationInResponse'] = __('The get rate request response does not contain any rate information', 'invoicing'); |
|
116 | + $vars['RatesUpdated'] = __('The rates have been updated. Press the save button to record these new rates.', 'invoicing'); |
|
117 | + $vars['IPAddressInformation'] = __('IP Address Information', 'invoicing'); |
|
118 | + $vars['VatValidating'] = wp_sprintf(__('Validating %s number...', 'invoicing'), $vat_name); |
|
119 | + $vars['VatReseting'] = __('Reseting...', 'invoicing'); |
|
120 | + $vars['VatValidated'] = wp_sprintf(__('%s number validated', 'invoicing'), $vat_name); |
|
121 | + $vars['VatNotValidated'] = wp_sprintf(__('%s number not validated', 'invoicing'), $vat_name); |
|
122 | + $vars['ConfirmDeleteClass'] = __('Are you sure you wish to delete this rates class?', 'invoicing'); |
|
123 | 123 | $vars['isFront'] = is_admin() ? false : true; |
124 | - $vars['checkoutNonce'] = wp_create_nonce( 'wpinv_checkout_nonce' ); |
|
124 | + $vars['checkoutNonce'] = wp_create_nonce('wpinv_checkout_nonce'); |
|
125 | 125 | $vars['baseCountry'] = wpinv_get_default_country(); |
126 | - $vars['disableVATSameCountry'] = ( self::same_country_rule() == 'no' ? true : false ); |
|
127 | - $vars['disableVATSimpleCheck'] = wpinv_get_option( 'vat_offline_check' ) ? true : false; |
|
126 | + $vars['disableVATSameCountry'] = (self::same_country_rule() == 'no' ? true : false); |
|
127 | + $vars['disableVATSimpleCheck'] = wpinv_get_option('vat_offline_check') ? true : false; |
|
128 | 128 | |
129 | - wp_enqueue_script( 'wpinv-vat-validation-script' ); |
|
130 | - wp_enqueue_script( 'wpinv-vat-script' ); |
|
131 | - wp_localize_script( 'wpinv-vat-script', 'WPInv_VAT_Vars', $vars ); |
|
129 | + wp_enqueue_script('wpinv-vat-validation-script'); |
|
130 | + wp_enqueue_script('wpinv-vat-script'); |
|
131 | + wp_localize_script('wpinv-vat-script', 'WPInv_VAT_Vars', $vars); |
|
132 | 132 | } |
133 | 133 | |
134 | 134 | public static function enqueue_admin_scripts() { |
135 | - if( isset( $_GET['page'] ) && 'wpinv-settings' == $_GET['page'] ) { |
|
135 | + if (isset($_GET['page']) && 'wpinv-settings' == $_GET['page']) { |
|
136 | 136 | self::enqueue_vat_scripts(); |
137 | 137 | } |
138 | 138 | } |
139 | 139 | |
140 | - public static function section_vat_settings( $sections ) { |
|
141 | - if ( !empty( $sections ) ) { |
|
142 | - $sections['vat'] = __( 'EU VAT Settings', 'invoicing' ); |
|
140 | + public static function section_vat_settings($sections) { |
|
141 | + if (!empty($sections)) { |
|
142 | + $sections['vat'] = __('EU VAT Settings', 'invoicing'); |
|
143 | 143 | |
144 | - if ( self::allow_vat_classes() ) { |
|
145 | - $sections['vat_rates'] = __( 'EU VAT Rates', 'invoicing' ); |
|
144 | + if (self::allow_vat_classes()) { |
|
145 | + $sections['vat_rates'] = __('EU VAT Rates', 'invoicing'); |
|
146 | 146 | } |
147 | 147 | } |
148 | 148 | return $sections; |
@@ -151,52 +151,52 @@ discard block |
||
151 | 151 | public static function vat_rates_settings() { |
152 | 152 | $vat_classes = self::get_rate_classes(); |
153 | 153 | $vat_rates = array(); |
154 | - $vat_class = isset( $_REQUEST['wpi_sub'] ) && $_REQUEST['wpi_sub'] !== '' && isset( $vat_classes[$_REQUEST['wpi_sub']] )? sanitize_text_field( $_REQUEST['wpi_sub'] ) : '_new'; |
|
155 | - $current_url = remove_query_arg( 'wpi_sub' ); |
|
154 | + $vat_class = isset($_REQUEST['wpi_sub']) && $_REQUEST['wpi_sub'] !== '' && isset($vat_classes[$_REQUEST['wpi_sub']]) ? sanitize_text_field($_REQUEST['wpi_sub']) : '_new'; |
|
155 | + $current_url = remove_query_arg('wpi_sub'); |
|
156 | 156 | |
157 | 157 | $vat_rates['vat_rates_header'] = array( |
158 | 158 | 'id' => 'vat_rates_header', |
159 | - 'name' => '<h3>' . __( 'Manage VAT Rates', 'invoicing' ) . '</h3>', |
|
159 | + 'name' => '<h3>' . __('Manage VAT Rates', 'invoicing') . '</h3>', |
|
160 | 160 | 'desc' => '', |
161 | 161 | 'type' => 'header', |
162 | 162 | 'size' => 'regular' |
163 | 163 | ); |
164 | 164 | $vat_rates['vat_rates_class'] = array( |
165 | 165 | 'id' => 'vat_rates_class', |
166 | - 'name' => __( 'Edit VAT Rates', 'invoicing' ), |
|
167 | - 'desc' => __( 'The standard rate will apply where no explicit rate is provided.', 'invoicing' ), |
|
166 | + 'name' => __('Edit VAT Rates', 'invoicing'), |
|
167 | + 'desc' => __('The standard rate will apply where no explicit rate is provided.', 'invoicing'), |
|
168 | 168 | 'type' => 'select', |
169 | - 'options' => array_merge( $vat_classes, array( '_new' => __( 'Add New Rate Class', 'invoicing' ) ) ), |
|
169 | + 'options' => array_merge($vat_classes, array('_new' => __('Add New Rate Class', 'invoicing'))), |
|
170 | 170 | 'chosen' => true, |
171 | - 'placeholder' => __( 'Select a VAT Rate', 'invoicing' ), |
|
171 | + 'placeholder' => __('Select a VAT Rate', 'invoicing'), |
|
172 | 172 | 'selected' => $vat_class, |
173 | 173 | 'onchange' => 'document.location.href="' . $current_url . '&wpi_sub=" + this.value;', |
174 | 174 | ); |
175 | 175 | |
176 | - if ( $vat_class != '_standard' && $vat_class != '_new' ) { |
|
176 | + if ($vat_class != '_standard' && $vat_class != '_new') { |
|
177 | 177 | $vat_rates['vat_rate_delete'] = array( |
178 | 178 | 'id' => 'vat_rate_delete', |
179 | 179 | 'type' => 'vat_rate_delete', |
180 | 180 | ); |
181 | 181 | } |
182 | 182 | |
183 | - if ( $vat_class == '_new' ) { |
|
183 | + if ($vat_class == '_new') { |
|
184 | 184 | $vat_rates['vat_rates_settings'] = array( |
185 | 185 | 'id' => 'vat_rates_settings', |
186 | - 'name' => '<h3>' . __( 'Add New Rate Class', 'invoicing' ) . '</h3>', |
|
186 | + 'name' => '<h3>' . __('Add New Rate Class', 'invoicing') . '</h3>', |
|
187 | 187 | 'type' => 'header', |
188 | 188 | ); |
189 | 189 | $vat_rates['vat_rate_name'] = array( |
190 | 190 | 'id' => 'vat_rate_name', |
191 | - 'name' => __( 'Name', 'invoicing' ), |
|
192 | - 'desc' => __( 'A short name for the new VAT Rate class', 'invoicing' ), |
|
191 | + 'name' => __('Name', 'invoicing'), |
|
192 | + 'desc' => __('A short name for the new VAT Rate class', 'invoicing'), |
|
193 | 193 | 'type' => 'text', |
194 | 194 | 'size' => 'regular', |
195 | 195 | ); |
196 | 196 | $vat_rates['vat_rate_desc'] = array( |
197 | 197 | 'id' => 'vat_rate_desc', |
198 | - 'name' => __( 'Description', 'invoicing' ), |
|
199 | - 'desc' => __( 'Manage VAT Rate class', 'invoicing' ), |
|
198 | + 'name' => __('Description', 'invoicing'), |
|
199 | + 'desc' => __('Manage VAT Rate class', 'invoicing'), |
|
200 | 200 | 'type' => 'text', |
201 | 201 | 'size' => 'regular', |
202 | 202 | ); |
@@ -208,7 +208,7 @@ discard block |
||
208 | 208 | $vat_rates['vat_rates'] = array( |
209 | 209 | 'id' => 'vat_rates', |
210 | 210 | 'name' => '<h3>' . $vat_classes[$vat_class] . '</h3>', |
211 | - 'desc' => self::get_class_desc( $vat_class ), |
|
211 | + 'desc' => self::get_class_desc($vat_class), |
|
212 | 212 | 'type' => 'vat_rates', |
213 | 213 | ); |
214 | 214 | } |
@@ -216,12 +216,12 @@ discard block |
||
216 | 216 | return $vat_rates; |
217 | 217 | } |
218 | 218 | |
219 | - public static function vat_settings( $settings ) { |
|
220 | - if ( !empty( $settings ) ) { |
|
219 | + public static function vat_settings($settings) { |
|
220 | + if (!empty($settings)) { |
|
221 | 221 | $vat_settings = array(); |
222 | 222 | $vat_settings['vat_company_title'] = array( |
223 | 223 | 'id' => 'vat_company_title', |
224 | - 'name' => '<h3>' . __( 'Your Company Details', 'invoicing' ) . '</h3>', |
|
224 | + 'name' => '<h3>' . __('Your Company Details', 'invoicing') . '</h3>', |
|
225 | 225 | 'desc' => '', |
226 | 226 | 'type' => 'header', |
227 | 227 | 'size' => 'regular' |
@@ -229,22 +229,22 @@ discard block |
||
229 | 229 | |
230 | 230 | $vat_settings['vat_company_name'] = array( |
231 | 231 | 'id' => 'vat_company_name', |
232 | - 'name' => __( 'Your Company Name', 'invoicing' ), |
|
233 | - 'desc' => wp_sprintf(__( 'Your company name as it appears on your VAT return, you can verify it via your VAT ID on the %sEU VIES System.%s', 'invoicing' ), '<a href="http://ec.europa.eu/taxation_customs/vies/" target="_blank">', '</a>' ), |
|
232 | + 'name' => __('Your Company Name', 'invoicing'), |
|
233 | + 'desc' => wp_sprintf(__('Your company name as it appears on your VAT return, you can verify it via your VAT ID on the %sEU VIES System.%s', 'invoicing'), '<a href="http://ec.europa.eu/taxation_customs/vies/" target="_blank">', '</a>'), |
|
234 | 234 | 'type' => 'text', |
235 | 235 | 'size' => 'regular', |
236 | 236 | ); |
237 | 237 | |
238 | 238 | $vat_settings['vat_number'] = array( |
239 | 239 | 'id' => 'vat_number', |
240 | - 'name' => __( 'Your VAT Number', 'invoicing' ), |
|
240 | + 'name' => __('Your VAT Number', 'invoicing'), |
|
241 | 241 | 'type' => 'vat_number', |
242 | 242 | 'size' => 'regular', |
243 | 243 | ); |
244 | 244 | |
245 | 245 | $vat_settings['vat_settings_title'] = array( |
246 | 246 | 'id' => 'vat_settings_title', |
247 | - 'name' => '<h3>' . __( 'Apply VAT Settings', 'invoicing' ) . '</h3>', |
|
247 | + 'name' => '<h3>' . __('Apply VAT Settings', 'invoicing') . '</h3>', |
|
248 | 248 | 'desc' => '', |
249 | 249 | 'type' => 'header', |
250 | 250 | 'size' => 'regular' |
@@ -252,8 +252,8 @@ discard block |
||
252 | 252 | |
253 | 253 | $vat_settings['apply_vat_rules'] = array( |
254 | 254 | 'id' => 'apply_vat_rules', |
255 | - 'name' => __( 'Enable VAT Rules', 'invoicing' ), |
|
256 | - 'desc' => __( 'Apply VAT to consumer sales from IP addresses within the EU, even if the billing address is outside the EU.', 'invoicing' ) . '<br><font style="color:red">' . __( 'Do not disable unless you know what you are doing.', 'invoicing' ) . '</font>', |
|
255 | + 'name' => __('Enable VAT Rules', 'invoicing'), |
|
256 | + 'desc' => __('Apply VAT to consumer sales from IP addresses within the EU, even if the billing address is outside the EU.', 'invoicing') . '<br><font style="color:red">' . __('Do not disable unless you know what you are doing.', 'invoicing') . '</font>', |
|
257 | 257 | 'type' => 'checkbox', |
258 | 258 | 'std' => '1' |
259 | 259 | ); |
@@ -269,8 +269,8 @@ discard block |
||
269 | 269 | |
270 | 270 | $vat_settings['vat_prevent_b2c_purchase'] = array( |
271 | 271 | 'id' => 'vat_prevent_b2c_purchase', |
272 | - 'name' => __( 'Prevent EU B2C Sales', 'invoicing' ), |
|
273 | - 'desc' => __( 'Enable this option if you are not registered for VAT in the EU.', 'invoicing' ), |
|
272 | + 'name' => __('Prevent EU B2C Sales', 'invoicing'), |
|
273 | + 'desc' => __('Enable this option if you are not registered for VAT in the EU.', 'invoicing'), |
|
274 | 274 | 'type' => 'checkbox' |
275 | 275 | ); |
276 | 276 | |
@@ -278,21 +278,21 @@ discard block |
||
278 | 278 | |
279 | 279 | $vat_settings['vat_same_country_rule'] = array( |
280 | 280 | 'id' => 'vat_same_country_rule', |
281 | - 'name' => __( 'Same Country Rule', 'invoicing' ), |
|
282 | - 'desc' => __( 'Select how you want to handle VAT charge if sales are in the same country as the base country.', 'invoicing' ), |
|
281 | + 'name' => __('Same Country Rule', 'invoicing'), |
|
282 | + 'desc' => __('Select how you want to handle VAT charge if sales are in the same country as the base country.', 'invoicing'), |
|
283 | 283 | 'type' => 'select', |
284 | 284 | 'options' => array( |
285 | - '' => __( 'Normal', 'invoicing' ), |
|
286 | - 'no' => __( 'No VAT', 'invoicing' ), |
|
287 | - 'always' => __( 'Always apply VAT', 'invoicing' ), |
|
285 | + '' => __('Normal', 'invoicing'), |
|
286 | + 'no' => __('No VAT', 'invoicing'), |
|
287 | + 'always' => __('Always apply VAT', 'invoicing'), |
|
288 | 288 | ), |
289 | - 'placeholder' => __( 'Select an option', 'invoicing' ), |
|
289 | + 'placeholder' => __('Select an option', 'invoicing'), |
|
290 | 290 | 'std' => '' |
291 | 291 | ); |
292 | 292 | |
293 | 293 | $vat_settings['vat_checkout_title'] = array( |
294 | 294 | 'id' => 'vat_checkout_title', |
295 | - 'name' => '<h3>' . __( 'Checkout Fields', 'invoicing' ) . '</h3>', |
|
295 | + 'name' => '<h3>' . __('Checkout Fields', 'invoicing') . '</h3>', |
|
296 | 296 | 'desc' => '', |
297 | 297 | 'type' => 'header', |
298 | 298 | 'size' => 'regular' |
@@ -300,14 +300,14 @@ discard block |
||
300 | 300 | |
301 | 301 | $vat_settings['vat_disable_fields'] = array( |
302 | 302 | 'id' => 'vat_disable_fields', |
303 | - 'name' => __( 'Disable VAT Fields', 'invoicing' ), |
|
304 | - 'desc' => __( 'Disable VAT fields if Invoicing is being used for GST.', 'invoicing' ) . '<br><font style="color:red">' . __( 'Do not disable if you have enabled Prevent EU B2C sales, otherwise Prevent EU B2C sales setting will not work.', 'invoicing' ) . '</font>', |
|
303 | + 'name' => __('Disable VAT Fields', 'invoicing'), |
|
304 | + 'desc' => __('Disable VAT fields if Invoicing is being used for GST.', 'invoicing') . '<br><font style="color:red">' . __('Do not disable if you have enabled Prevent EU B2C sales, otherwise Prevent EU B2C sales setting will not work.', 'invoicing') . '</font>', |
|
305 | 305 | 'type' => 'checkbox' |
306 | 306 | ); |
307 | 307 | |
308 | 308 | $vat_settings['vat_ip_lookup'] = array( |
309 | 309 | 'id' => 'vat_ip_lookup', |
310 | - 'name' => __( 'IP Country Look-up', 'invoicing' ), |
|
310 | + 'name' => __('IP Country Look-up', 'invoicing'), |
|
311 | 311 | 'type' => 'vat_ip_lookup', |
312 | 312 | 'size' => 'regular', |
313 | 313 | 'std' => 'default' |
@@ -315,21 +315,21 @@ discard block |
||
315 | 315 | |
316 | 316 | $vat_settings['hide_ip_address'] = array( |
317 | 317 | 'id' => 'hide_ip_address', |
318 | - 'name' => __( 'Hide IP Info at Checkout', 'invoicing' ), |
|
319 | - 'desc' => __( 'Hide the user IP info at checkout.', 'invoicing' ), |
|
318 | + 'name' => __('Hide IP Info at Checkout', 'invoicing'), |
|
319 | + 'desc' => __('Hide the user IP info at checkout.', 'invoicing'), |
|
320 | 320 | 'type' => 'checkbox' |
321 | 321 | ); |
322 | 322 | |
323 | 323 | $vat_settings['vat_ip_country_default'] = array( |
324 | 324 | 'id' => 'vat_ip_country_default', |
325 | - 'name' => __( 'Enable IP Country as Default', 'invoicing' ), |
|
326 | - 'desc' => __( 'Show the country of the users IP as the default country, otherwise the site default country will be used.', 'invoicing' ), |
|
325 | + 'name' => __('Enable IP Country as Default', 'invoicing'), |
|
326 | + 'desc' => __('Show the country of the users IP as the default country, otherwise the site default country will be used.', 'invoicing'), |
|
327 | 327 | 'type' => 'checkbox' |
328 | 328 | ); |
329 | 329 | |
330 | 330 | $vat_settings['vies_validation_title'] = array( |
331 | 331 | 'id' => 'vies_validation_title', |
332 | - 'name' => '<h3>' . __( 'VIES Validation', 'invoicing' ) . '</h3>', |
|
332 | + 'name' => '<h3>' . __('VIES Validation', 'invoicing') . '</h3>', |
|
333 | 333 | 'desc' => '', |
334 | 334 | 'type' => 'header', |
335 | 335 | 'size' => 'regular' |
@@ -337,37 +337,37 @@ discard block |
||
337 | 337 | |
338 | 338 | $vat_settings['vat_vies_check'] = array( |
339 | 339 | 'id' => 'vat_vies_check', |
340 | - 'name' => __( 'Disable VIES VAT ID Check', 'invoicing' ), |
|
341 | - 'desc' => wp_sprintf( __( 'Prevent VAT numbers from being validated by the %sEU VIES System.%s', 'invoicing' ), '<a href="http://ec.europa.eu/taxation_customs/vies/" target="_blank">', '</a>' ), |
|
340 | + 'name' => __('Disable VIES VAT ID Check', 'invoicing'), |
|
341 | + 'desc' => wp_sprintf(__('Prevent VAT numbers from being validated by the %sEU VIES System.%s', 'invoicing'), '<a href="http://ec.europa.eu/taxation_customs/vies/" target="_blank">', '</a>'), |
|
342 | 342 | 'type' => 'checkbox' |
343 | 343 | ); |
344 | 344 | |
345 | 345 | $vat_settings['vat_disable_company_name_check'] = array( |
346 | 346 | 'id' => 'vat_disable_company_name_check', |
347 | - 'name' => __( 'Disable VIES Name Check', 'invoicing' ), |
|
348 | - 'desc' => wp_sprintf( __( 'Prevent company name from being validated by the %sEU VIES System.%s', 'invoicing' ), '<a href="http://ec.europa.eu/taxation_customs/vies/" target="_blank">', '</a>' ), |
|
347 | + 'name' => __('Disable VIES Name Check', 'invoicing'), |
|
348 | + 'desc' => wp_sprintf(__('Prevent company name from being validated by the %sEU VIES System.%s', 'invoicing'), '<a href="http://ec.europa.eu/taxation_customs/vies/" target="_blank">', '</a>'), |
|
349 | 349 | 'type' => 'checkbox' |
350 | 350 | ); |
351 | 351 | |
352 | 352 | $vat_settings['vat_offline_check'] = array( |
353 | 353 | 'id' => 'vat_offline_check', |
354 | - 'name' => __( 'Disable Basic Checks', 'invoicing' ), |
|
355 | - 'desc' => __( 'This will disable basic JS correct format validation attempts, it is very rare this should need to be disabled.', 'invoicing' ), |
|
354 | + 'name' => __('Disable Basic Checks', 'invoicing'), |
|
355 | + 'desc' => __('This will disable basic JS correct format validation attempts, it is very rare this should need to be disabled.', 'invoicing'), |
|
356 | 356 | 'type' => 'checkbox' |
357 | 357 | ); |
358 | 358 | |
359 | 359 | |
360 | 360 | $settings['vat'] = $vat_settings; |
361 | 361 | |
362 | - if ( self::allow_vat_classes() ) { |
|
362 | + if (self::allow_vat_classes()) { |
|
363 | 363 | $settings['vat_rates'] = self::vat_rates_settings(); |
364 | 364 | } |
365 | 365 | |
366 | 366 | $eu_fallback_rate = array( |
367 | 367 | 'id' => 'eu_fallback_rate', |
368 | - 'name' => '<h3>' . __( 'VAT rate for EU member states', 'invoicing' ) . '</h3>', |
|
368 | + 'name' => '<h3>' . __('VAT rate for EU member states', 'invoicing') . '</h3>', |
|
369 | 369 | 'type' => 'eu_fallback_rate', |
370 | - 'desc' => __( 'Enter the VAT rate to be charged for EU member states. You can edit the rates for each member state when a country rate has been set up by pressing this button.', 'invoicing' ), |
|
370 | + 'desc' => __('Enter the VAT rate to be charged for EU member states. You can edit the rates for each member state when a country rate has been set up by pressing this button.', 'invoicing'), |
|
371 | 371 | 'std' => '20', |
372 | 372 | 'size' => 'small' |
373 | 373 | ); |
@@ -383,11 +383,11 @@ discard block |
||
383 | 383 | $database_url = 'http' . (isset($_SERVER["HTTPS"]) && $_SERVER["HTTPS"] === 'on' ? 's' : '') . '://geolite.maxmind.com/download/geoip/database/'; |
384 | 384 | $destination_dir = $upload_dir['basedir'] . '/invoicing'; |
385 | 385 | |
386 | - if ( !is_dir( $destination_dir ) ) { |
|
387 | - mkdir( $destination_dir ); |
|
386 | + if (!is_dir($destination_dir)) { |
|
387 | + mkdir($destination_dir); |
|
388 | 388 | } |
389 | 389 | |
390 | - $database_files = array( |
|
390 | + $database_files = array( |
|
391 | 391 | 'country' => array( |
392 | 392 | 'source' => $database_url . 'GeoLite2-Country.mmdb.gz', |
393 | 393 | 'destination' => $destination_dir . '/GeoLite2-Country.mmdb', |
@@ -398,57 +398,57 @@ discard block |
||
398 | 398 | ) |
399 | 399 | ); |
400 | 400 | |
401 | - foreach( $database_files as $database => $files ) { |
|
402 | - $result = self::geoip2_download_file( $files['source'], $files['destination'] ); |
|
401 | + foreach ($database_files as $database => $files) { |
|
402 | + $result = self::geoip2_download_file($files['source'], $files['destination']); |
|
403 | 403 | |
404 | - if ( empty( $result['success'] ) ) { |
|
404 | + if (empty($result['success'])) { |
|
405 | 405 | echo $result['message']; |
406 | 406 | exit; |
407 | 407 | } |
408 | 408 | |
409 | - wpinv_update_option( 'wpinv_geoip2_date_updated', current_time( 'timestamp' ) ); |
|
410 | - echo sprintf(__( 'GeoIp2 %s database updated successfully.', 'invoicing' ), $database ) . ' '; |
|
409 | + wpinv_update_option('wpinv_geoip2_date_updated', current_time('timestamp')); |
|
410 | + echo sprintf(__('GeoIp2 %s database updated successfully.', 'invoicing'), $database) . ' '; |
|
411 | 411 | } |
412 | 412 | |
413 | 413 | exit; |
414 | 414 | } |
415 | 415 | |
416 | - public static function geoip2_download_file( $source_url, $destination_file ) { |
|
416 | + public static function geoip2_download_file($source_url, $destination_file) { |
|
417 | 417 | $success = false; |
418 | 418 | $message = ''; |
419 | 419 | |
420 | - if ( !function_exists( 'download_url' ) ) { |
|
421 | - require_once( ABSPATH . 'wp-admin/includes/file.php' ); |
|
420 | + if (!function_exists('download_url')) { |
|
421 | + require_once(ABSPATH . 'wp-admin/includes/file.php'); |
|
422 | 422 | } |
423 | 423 | |
424 | - $temp_file = download_url( $source_url ); |
|
424 | + $temp_file = download_url($source_url); |
|
425 | 425 | |
426 | - if ( is_wp_error( $temp_file ) ) { |
|
427 | - $message = sprintf( __( 'Error while downloading GeoIp2 database( %s ): %s', 'invoicing' ), $source_url, $temp_file->get_error_message() ); |
|
426 | + if (is_wp_error($temp_file)) { |
|
427 | + $message = sprintf(__('Error while downloading GeoIp2 database( %s ): %s', 'invoicing'), $source_url, $temp_file->get_error_message()); |
|
428 | 428 | } else { |
429 | - $handle = gzopen( $temp_file, 'rb' ); |
|
429 | + $handle = gzopen($temp_file, 'rb'); |
|
430 | 430 | |
431 | - if ( $handle ) { |
|
432 | - $fopen = fopen( $destination_file, 'wb' ); |
|
433 | - if ( $fopen ) { |
|
434 | - while ( ( $data = gzread( $handle, 4096 ) ) != false ) { |
|
435 | - fwrite( $fopen, $data ); |
|
431 | + if ($handle) { |
|
432 | + $fopen = fopen($destination_file, 'wb'); |
|
433 | + if ($fopen) { |
|
434 | + while (($data = gzread($handle, 4096)) != false) { |
|
435 | + fwrite($fopen, $data); |
|
436 | 436 | } |
437 | 437 | |
438 | - gzclose( $handle ); |
|
439 | - fclose( $fopen ); |
|
438 | + gzclose($handle); |
|
439 | + fclose($fopen); |
|
440 | 440 | |
441 | 441 | $success = true; |
442 | 442 | } else { |
443 | - gzclose( $handle ); |
|
444 | - $message = sprintf( __( 'Error could not open destination GeoIp2 database file for writing: %s', 'invoicing' ), $destination_file ); |
|
443 | + gzclose($handle); |
|
444 | + $message = sprintf(__('Error could not open destination GeoIp2 database file for writing: %s', 'invoicing'), $destination_file); |
|
445 | 445 | } |
446 | 446 | } else { |
447 | - $message = sprintf( __( 'Error could not open GeoIp2 database file for reading: %s', 'invoicing' ), $temp_file ); |
|
447 | + $message = sprintf(__('Error could not open GeoIp2 database file for reading: %s', 'invoicing'), $temp_file); |
|
448 | 448 | } |
449 | 449 | |
450 | - if ( file_exists( $temp_file ) ) { |
|
451 | - unlink( $temp_file ); |
|
450 | + if (file_exists($temp_file)) { |
|
451 | + unlink($temp_file); |
|
452 | 452 | } |
453 | 453 | } |
454 | 454 | |
@@ -460,11 +460,11 @@ discard block |
||
460 | 460 | } |
461 | 461 | |
462 | 462 | public static function load_geoip2() { |
463 | - if ( defined( 'WPINV_GEOIP2_LODDED' ) ) { |
|
463 | + if (defined('WPINV_GEOIP2_LODDED')) { |
|
464 | 464 | return; |
465 | 465 | } |
466 | 466 | |
467 | - if ( !class_exists( '\MaxMind\Db\Reader' ) ) { |
|
467 | + if (!class_exists('\MaxMind\Db\Reader')) { |
|
468 | 468 | $maxmind_db_files = array( |
469 | 469 | 'Reader/Decoder.php', |
470 | 470 | 'Reader/InvalidDatabaseException.php', |
@@ -473,12 +473,12 @@ discard block |
||
473 | 473 | 'Reader.php', |
474 | 474 | ); |
475 | 475 | |
476 | - foreach ( $maxmind_db_files as $key => $file ) { |
|
477 | - require_once( WPINV_PLUGIN_DIR . 'includes/libraries/MaxMind/Db/' . $file ); |
|
476 | + foreach ($maxmind_db_files as $key => $file) { |
|
477 | + require_once(WPINV_PLUGIN_DIR . 'includes/libraries/MaxMind/Db/' . $file); |
|
478 | 478 | } |
479 | 479 | } |
480 | 480 | |
481 | - if ( !class_exists( '\GeoIp2\Database\Reader' ) ) { |
|
481 | + if (!class_exists('\GeoIp2\Database\Reader')) { |
|
482 | 482 | $geoip2_files = array( |
483 | 483 | 'ProviderInterface.php', |
484 | 484 | 'Compat/JsonSerializable.php', |
@@ -512,23 +512,23 @@ discard block |
||
512 | 512 | 'WebService/Client.php', |
513 | 513 | ); |
514 | 514 | |
515 | - foreach ( $geoip2_files as $key => $file ) { |
|
516 | - require_once( WPINV_PLUGIN_DIR . 'includes/libraries/GeoIp2/' . $file ); |
|
515 | + foreach ($geoip2_files as $key => $file) { |
|
516 | + require_once(WPINV_PLUGIN_DIR . 'includes/libraries/GeoIp2/' . $file); |
|
517 | 517 | } |
518 | 518 | } |
519 | 519 | |
520 | - define( 'WPINV_GEOIP2_LODDED', true ); |
|
520 | + define('WPINV_GEOIP2_LODDED', true); |
|
521 | 521 | } |
522 | 522 | |
523 | 523 | public static function geoip2_country_dbfile() { |
524 | 524 | $upload_dir = wp_upload_dir(); |
525 | 525 | |
526 | - if ( !isset( $upload_dir['basedir'] ) ) { |
|
526 | + if (!isset($upload_dir['basedir'])) { |
|
527 | 527 | return false; |
528 | 528 | } |
529 | 529 | |
530 | 530 | $filename = $upload_dir['basedir'] . '/invoicing/GeoLite2-Country.mmdb'; |
531 | - if ( !file_exists( $filename ) ) { |
|
531 | + if (!file_exists($filename)) { |
|
532 | 532 | return false; |
533 | 533 | } |
534 | 534 | |
@@ -538,12 +538,12 @@ discard block |
||
538 | 538 | public static function geoip2_city_dbfile() { |
539 | 539 | $upload_dir = wp_upload_dir(); |
540 | 540 | |
541 | - if ( !isset( $upload_dir['basedir'] ) ) { |
|
541 | + if (!isset($upload_dir['basedir'])) { |
|
542 | 542 | return false; |
543 | 543 | } |
544 | 544 | |
545 | 545 | $filename = $upload_dir['basedir'] . '/invoicing/GeoLite2-City.mmdb'; |
546 | - if ( !file_exists( $filename ) ) { |
|
546 | + if (!file_exists($filename)) { |
|
547 | 547 | return false; |
548 | 548 | } |
549 | 549 | |
@@ -554,10 +554,10 @@ discard block |
||
554 | 554 | try { |
555 | 555 | self::load_geoip2(); |
556 | 556 | |
557 | - if ( $filename = self::geoip2_country_dbfile() ) { |
|
558 | - return new \GeoIp2\Database\Reader( $filename ); |
|
557 | + if ($filename = self::geoip2_country_dbfile()) { |
|
558 | + return new \GeoIp2\Database\Reader($filename); |
|
559 | 559 | } |
560 | - } catch( Exception $e ) { |
|
560 | + } catch (Exception $e) { |
|
561 | 561 | return false; |
562 | 562 | } |
563 | 563 | |
@@ -568,173 +568,173 @@ discard block |
||
568 | 568 | try { |
569 | 569 | self::load_geoip2(); |
570 | 570 | |
571 | - if ( $filename = self::geoip2_city_dbfile() ) { |
|
572 | - return new \GeoIp2\Database\Reader( $filename ); |
|
571 | + if ($filename = self::geoip2_city_dbfile()) { |
|
572 | + return new \GeoIp2\Database\Reader($filename); |
|
573 | 573 | } |
574 | - } catch( Exception $e ) { |
|
574 | + } catch (Exception $e) { |
|
575 | 575 | return false; |
576 | 576 | } |
577 | 577 | |
578 | 578 | return false; |
579 | 579 | } |
580 | 580 | |
581 | - public static function geoip2_country_record( $ip_address ) { |
|
581 | + public static function geoip2_country_record($ip_address) { |
|
582 | 582 | try { |
583 | 583 | $reader = self::geoip2_country_reader(); |
584 | 584 | |
585 | - if ( $reader ) { |
|
586 | - $record = $reader->country( $ip_address ); |
|
585 | + if ($reader) { |
|
586 | + $record = $reader->country($ip_address); |
|
587 | 587 | |
588 | - if ( !empty( $record->country->isoCode ) ) { |
|
588 | + if (!empty($record->country->isoCode)) { |
|
589 | 589 | return $record; |
590 | 590 | } |
591 | 591 | } |
592 | - } catch(\InvalidArgumentException $e) { |
|
593 | - wpinv_error_log( $e->getMessage(), 'GeoIp2 Lookup( ' . $ip_address . ' )' ); |
|
592 | + } catch (\InvalidArgumentException $e) { |
|
593 | + wpinv_error_log($e->getMessage(), 'GeoIp2 Lookup( ' . $ip_address . ' )'); |
|
594 | 594 | |
595 | 595 | return false; |
596 | - } catch(\GeoIp2\Exception\AddressNotFoundException $e) { |
|
597 | - wpinv_error_log( $e->getMessage(), 'GeoIp2 Lookup( ' . $ip_address . ' )' ); |
|
596 | + } catch (\GeoIp2\Exception\AddressNotFoundException $e) { |
|
597 | + wpinv_error_log($e->getMessage(), 'GeoIp2 Lookup( ' . $ip_address . ' )'); |
|
598 | 598 | |
599 | 599 | return false; |
600 | - } catch( Exception $e ) { |
|
600 | + } catch (Exception $e) { |
|
601 | 601 | return false; |
602 | 602 | } |
603 | 603 | |
604 | 604 | return false; |
605 | 605 | } |
606 | 606 | |
607 | - public static function geoip2_city_record( $ip_address ) { |
|
607 | + public static function geoip2_city_record($ip_address) { |
|
608 | 608 | try { |
609 | 609 | $reader = self::geoip2_city_reader(); |
610 | 610 | |
611 | - if ( $reader ) { |
|
612 | - $record = $reader->city( $ip_address ); |
|
611 | + if ($reader) { |
|
612 | + $record = $reader->city($ip_address); |
|
613 | 613 | |
614 | - if ( !empty( $record->country->isoCode ) ) { |
|
614 | + if (!empty($record->country->isoCode)) { |
|
615 | 615 | return $record; |
616 | 616 | } |
617 | 617 | } |
618 | - } catch(\InvalidArgumentException $e) { |
|
619 | - wpinv_error_log( $e->getMessage(), 'GeoIp2 Lookup( ' . $ip_address . ' )' ); |
|
618 | + } catch (\InvalidArgumentException $e) { |
|
619 | + wpinv_error_log($e->getMessage(), 'GeoIp2 Lookup( ' . $ip_address . ' )'); |
|
620 | 620 | |
621 | 621 | return false; |
622 | - } catch(\GeoIp2\Exception\AddressNotFoundException $e) { |
|
623 | - wpinv_error_log( $e->getMessage(), 'GeoIp2 Lookup( ' . $ip_address . ' )' ); |
|
622 | + } catch (\GeoIp2\Exception\AddressNotFoundException $e) { |
|
623 | + wpinv_error_log($e->getMessage(), 'GeoIp2 Lookup( ' . $ip_address . ' )'); |
|
624 | 624 | |
625 | 625 | return false; |
626 | - } catch( Exception $e ) { |
|
626 | + } catch (Exception $e) { |
|
627 | 627 | return false; |
628 | 628 | } |
629 | 629 | |
630 | 630 | return false; |
631 | 631 | } |
632 | 632 | |
633 | - public static function geoip2_country_code( $ip_address ) { |
|
634 | - $record = self::geoip2_country_record( $ip_address ); |
|
635 | - return !empty( $record->country->isoCode ) ? $record->country->isoCode : wpinv_get_default_country(); |
|
633 | + public static function geoip2_country_code($ip_address) { |
|
634 | + $record = self::geoip2_country_record($ip_address); |
|
635 | + return !empty($record->country->isoCode) ? $record->country->isoCode : wpinv_get_default_country(); |
|
636 | 636 | } |
637 | 637 | |
638 | 638 | // Find country by IP address. |
639 | - public static function get_country_by_ip( $ip = '' ) { |
|
639 | + public static function get_country_by_ip($ip = '') { |
|
640 | 640 | global $wpinv_ip_address_country; |
641 | 641 | |
642 | - if ( !empty( $wpinv_ip_address_country ) ) { |
|
642 | + if (!empty($wpinv_ip_address_country)) { |
|
643 | 643 | return $wpinv_ip_address_country; |
644 | 644 | } |
645 | 645 | |
646 | - if ( empty( $ip ) ) { |
|
646 | + if (empty($ip)) { |
|
647 | 647 | $ip = wpinv_get_ip(); |
648 | 648 | } |
649 | 649 | |
650 | - $ip_country_service = wpinv_get_option( 'vat_ip_lookup' ); |
|
651 | - $is_default = empty( $ip_country_service ) || $ip_country_service === 'default' ? true : false; |
|
650 | + $ip_country_service = wpinv_get_option('vat_ip_lookup'); |
|
651 | + $is_default = empty($ip_country_service) || $ip_country_service === 'default' ? true : false; |
|
652 | 652 | |
653 | - if ( !empty( $ip ) && $ip !== '127.0.0.1' ) { // For 127.0.0.1(localhost) use default country. |
|
654 | - if ( function_exists( 'geoip_country_code_by_name') && ( $ip_country_service === 'geoip' || $is_default ) ) { |
|
653 | + if (!empty($ip) && $ip !== '127.0.0.1') { // For 127.0.0.1(localhost) use default country. |
|
654 | + if (function_exists('geoip_country_code_by_name') && ($ip_country_service === 'geoip' || $is_default)) { |
|
655 | 655 | try { |
656 | - $wpinv_ip_address_country = geoip_country_code_by_name( $ip ); |
|
657 | - } catch( Exception $e ) { |
|
658 | - wpinv_error_log( $e->getMessage(), 'GeoIP Lookup( ' . $ip . ' )' ); |
|
656 | + $wpinv_ip_address_country = geoip_country_code_by_name($ip); |
|
657 | + } catch (Exception $e) { |
|
658 | + wpinv_error_log($e->getMessage(), 'GeoIP Lookup( ' . $ip . ' )'); |
|
659 | 659 | } |
660 | - } else if ( self::geoip2_country_dbfile() && ( $ip_country_service === 'geoip2' || $is_default ) ) { |
|
661 | - $wpinv_ip_address_country = self::geoip2_country_code( $ip ); |
|
662 | - } else if ( function_exists( 'simplexml_load_file' ) && ( $ip_country_service === 'geoplugin' || $is_default ) ) { |
|
663 | - $load_xml = simplexml_load_file( 'http://www.geoplugin.net/xml.gp?ip=' . $ip ); |
|
660 | + } else if (self::geoip2_country_dbfile() && ($ip_country_service === 'geoip2' || $is_default)) { |
|
661 | + $wpinv_ip_address_country = self::geoip2_country_code($ip); |
|
662 | + } else if (function_exists('simplexml_load_file') && ($ip_country_service === 'geoplugin' || $is_default)) { |
|
663 | + $load_xml = simplexml_load_file('http://www.geoplugin.net/xml.gp?ip=' . $ip); |
|
664 | 664 | |
665 | - if ( !empty( $load_xml ) && !empty( $load_xml->geoplugin_countryCode ) ) { |
|
665 | + if (!empty($load_xml) && !empty($load_xml->geoplugin_countryCode)) { |
|
666 | 666 | $wpinv_ip_address_country = (string)$load_xml->geoplugin_countryCode; |
667 | 667 | } |
668 | 668 | } |
669 | 669 | } |
670 | 670 | |
671 | - if ( empty( $wpinv_ip_address_country ) ) { |
|
671 | + if (empty($wpinv_ip_address_country)) { |
|
672 | 672 | $wpinv_ip_address_country = wpinv_get_default_country(); |
673 | 673 | } |
674 | 674 | |
675 | 675 | return $wpinv_ip_address_country; |
676 | 676 | } |
677 | 677 | |
678 | - public static function sanitize_vat_settings( $input ) { |
|
678 | + public static function sanitize_vat_settings($input) { |
|
679 | 679 | global $wpinv_options; |
680 | 680 | |
681 | 681 | $valid = false; |
682 | 682 | $message = ''; |
683 | 683 | |
684 | - if ( !empty( $wpinv_options['vat_vies_check'] ) ) { |
|
685 | - if ( empty( $wpinv_options['vat_offline_check'] ) ) { |
|
686 | - $valid = self::offline_check( $input['vat_number'] ); |
|
684 | + if (!empty($wpinv_options['vat_vies_check'])) { |
|
685 | + if (empty($wpinv_options['vat_offline_check'])) { |
|
686 | + $valid = self::offline_check($input['vat_number']); |
|
687 | 687 | } else { |
688 | 688 | $valid = true; |
689 | 689 | } |
690 | 690 | |
691 | - $message = $valid ? '' : __( 'VAT number not validated', 'invoicing' ); |
|
691 | + $message = $valid ? '' : __('VAT number not validated', 'invoicing'); |
|
692 | 692 | } else { |
693 | - $result = self::check_vat( $input['vat_number'] ); |
|
693 | + $result = self::check_vat($input['vat_number']); |
|
694 | 694 | |
695 | - if ( empty( $result['valid'] ) ) { |
|
695 | + if (empty($result['valid'])) { |
|
696 | 696 | $valid = false; |
697 | 697 | $message = $result['message']; |
698 | 698 | } else { |
699 | - $valid = ( isset( $result['company'] ) && ( $result['company'] == '---' || ( strcasecmp( trim( $result['company'] ), trim( $input['vat_company_name'] ) ) == 0 ) ) ) || !empty( $wpinv_options['vat_disable_company_name_check'] ); |
|
700 | - $message = $valid ? '' : __( 'The company name associated with the VAT number provided is not the same as the company name provided.', 'invoicing' ); |
|
699 | + $valid = (isset($result['company']) && ($result['company'] == '---' || (strcasecmp(trim($result['company']), trim($input['vat_company_name'])) == 0))) || !empty($wpinv_options['vat_disable_company_name_check']); |
|
700 | + $message = $valid ? '' : __('The company name associated with the VAT number provided is not the same as the company name provided.', 'invoicing'); |
|
701 | 701 | } |
702 | 702 | } |
703 | 703 | |
704 | - if ( $message && self::is_vat_validated() != $valid ) { |
|
705 | - add_settings_error( 'wpinv-notices', '', $message, ( $valid ? 'updated' : 'error' ) ); |
|
704 | + if ($message && self::is_vat_validated() != $valid) { |
|
705 | + add_settings_error('wpinv-notices', '', $message, ($valid ? 'updated' : 'error')); |
|
706 | 706 | } |
707 | 707 | |
708 | 708 | $input['vat_valid'] = $valid; |
709 | 709 | return $input; |
710 | 710 | } |
711 | 711 | |
712 | - public static function sanitize_vat_rates( $input ) { |
|
713 | - if( !current_user_can( 'manage_options' ) ) { |
|
714 | - add_settings_error( 'wpinv-notices', '', __( 'Your account does not have permission to add rate classes.', 'invoicing' ), 'error' ); |
|
712 | + public static function sanitize_vat_rates($input) { |
|
713 | + if (!current_user_can('manage_options')) { |
|
714 | + add_settings_error('wpinv-notices', '', __('Your account does not have permission to add rate classes.', 'invoicing'), 'error'); |
|
715 | 715 | return $input; |
716 | 716 | } |
717 | 717 | |
718 | 718 | $vat_classes = self::get_rate_classes(); |
719 | - $vat_class = !empty( $_REQUEST['wpi_vat_class'] ) && isset( $vat_classes[$_REQUEST['wpi_vat_class']] )? sanitize_text_field( $_REQUEST['wpi_vat_class'] ) : ''; |
|
719 | + $vat_class = !empty($_REQUEST['wpi_vat_class']) && isset($vat_classes[$_REQUEST['wpi_vat_class']]) ? sanitize_text_field($_REQUEST['wpi_vat_class']) : ''; |
|
720 | 720 | |
721 | - if ( empty( $vat_class ) ) { |
|
722 | - add_settings_error( 'wpinv-notices', '', __( 'No valid VAT rates class contained in the request to save rates.', 'invoicing' ), 'error' ); |
|
721 | + if (empty($vat_class)) { |
|
722 | + add_settings_error('wpinv-notices', '', __('No valid VAT rates class contained in the request to save rates.', 'invoicing'), 'error'); |
|
723 | 723 | |
724 | 724 | return $input; |
725 | 725 | } |
726 | 726 | |
727 | - $new_rates = ! empty( $_POST['vat_rates'] ) ? array_values( $_POST['vat_rates'] ) : array(); |
|
727 | + $new_rates = !empty($_POST['vat_rates']) ? array_values($_POST['vat_rates']) : array(); |
|
728 | 728 | |
729 | - if ( $vat_class === '_standard' ) { |
|
729 | + if ($vat_class === '_standard') { |
|
730 | 730 | // Save the active rates in the invoice settings |
731 | - update_option( 'wpinv_tax_rates', $new_rates ); |
|
731 | + update_option('wpinv_tax_rates', $new_rates); |
|
732 | 732 | } else { |
733 | 733 | // Get the existing set of rates |
734 | 734 | $rates = self::get_non_standard_rates(); |
735 | 735 | $rates[$vat_class] = $new_rates; |
736 | 736 | |
737 | - update_option( 'wpinv_vat_rates', $rates ); |
|
737 | + update_option('wpinv_vat_rates', $rates); |
|
738 | 738 | } |
739 | 739 | |
740 | 740 | return $input; |
@@ -744,71 +744,71 @@ discard block |
||
744 | 744 | $response = array(); |
745 | 745 | $response['success'] = false; |
746 | 746 | |
747 | - if ( !current_user_can( 'manage_options' ) ) { |
|
748 | - $response['error'] = __( 'Invalid access!', 'invoicing' ); |
|
749 | - wp_send_json( $response ); |
|
747 | + if (!current_user_can('manage_options')) { |
|
748 | + $response['error'] = __('Invalid access!', 'invoicing'); |
|
749 | + wp_send_json($response); |
|
750 | 750 | } |
751 | 751 | |
752 | - $vat_class_name = !empty( $_POST['name'] ) ? sanitize_text_field( $_POST['name'] ) : false; |
|
753 | - $vat_class_desc = !empty( $_POST['desc'] ) ? sanitize_text_field( $_POST['desc'] ) : false; |
|
752 | + $vat_class_name = !empty($_POST['name']) ? sanitize_text_field($_POST['name']) : false; |
|
753 | + $vat_class_desc = !empty($_POST['desc']) ? sanitize_text_field($_POST['desc']) : false; |
|
754 | 754 | |
755 | - if ( empty( $vat_class_name ) ) { |
|
756 | - $response['error'] = __( 'Select the VAT rate name', 'invoicing' ); |
|
757 | - wp_send_json( $response ); |
|
755 | + if (empty($vat_class_name)) { |
|
756 | + $response['error'] = __('Select the VAT rate name', 'invoicing'); |
|
757 | + wp_send_json($response); |
|
758 | 758 | } |
759 | 759 | |
760 | 760 | $vat_classes = (array)self::get_rate_classes(); |
761 | 761 | |
762 | - if ( !empty( $vat_classes ) && in_array( strtolower( $vat_class_name ), array_map( 'strtolower', array_values( $vat_classes ) ) ) ) { |
|
763 | - $response['error'] = wp_sprintf( __( 'A VAT Rate name "%s" already exists', 'invoicing' ), $vat_class_name ); |
|
764 | - wp_send_json( $response ); |
|
762 | + if (!empty($vat_classes) && in_array(strtolower($vat_class_name), array_map('strtolower', array_values($vat_classes)))) { |
|
763 | + $response['error'] = wp_sprintf(__('A VAT Rate name "%s" already exists', 'invoicing'), $vat_class_name); |
|
764 | + wp_send_json($response); |
|
765 | 765 | } |
766 | 766 | |
767 | - $rate_class_key = normalize_whitespace( 'wpi-' . $vat_class_name ); |
|
768 | - $rate_class_key = sanitize_key( str_replace( " ", "-", $rate_class_key ) ); |
|
767 | + $rate_class_key = normalize_whitespace('wpi-' . $vat_class_name); |
|
768 | + $rate_class_key = sanitize_key(str_replace(" ", "-", $rate_class_key)); |
|
769 | 769 | |
770 | - $vat_classes = (array)self::get_rate_classes( true ); |
|
771 | - $vat_classes[$rate_class_key] = array( 'name' => $vat_class_name, 'desc' => $vat_class_desc ); |
|
770 | + $vat_classes = (array)self::get_rate_classes(true); |
|
771 | + $vat_classes[$rate_class_key] = array('name' => $vat_class_name, 'desc' => $vat_class_desc); |
|
772 | 772 | |
773 | - update_option( '_wpinv_vat_rate_classes', $vat_classes ); |
|
773 | + update_option('_wpinv_vat_rate_classes', $vat_classes); |
|
774 | 774 | |
775 | 775 | $response['success'] = true; |
776 | - $response['redirect'] = admin_url( 'admin.php?page=wpinv-settings&tab=taxes§ion=vat_rates&wpi_sub=' . $rate_class_key ); |
|
776 | + $response['redirect'] = admin_url('admin.php?page=wpinv-settings&tab=taxes§ion=vat_rates&wpi_sub=' . $rate_class_key); |
|
777 | 777 | |
778 | - wp_send_json( $response ); |
|
778 | + wp_send_json($response); |
|
779 | 779 | } |
780 | 780 | |
781 | 781 | public static function delete_class() { |
782 | 782 | $response = array(); |
783 | 783 | $response['success'] = false; |
784 | 784 | |
785 | - if ( !current_user_can( 'manage_options' ) || !isset( $_POST['class'] ) ) { |
|
786 | - $response['error'] = __( 'Invalid access!', 'invoicing' ); |
|
787 | - wp_send_json( $response ); |
|
785 | + if (!current_user_can('manage_options') || !isset($_POST['class'])) { |
|
786 | + $response['error'] = __('Invalid access!', 'invoicing'); |
|
787 | + wp_send_json($response); |
|
788 | 788 | } |
789 | 789 | |
790 | - $vat_class = isset( $_POST['class'] ) && $_POST['class'] !== '' ? sanitize_text_field( $_POST['class'] ) : false; |
|
790 | + $vat_class = isset($_POST['class']) && $_POST['class'] !== '' ? sanitize_text_field($_POST['class']) : false; |
|
791 | 791 | $vat_classes = (array)self::get_rate_classes(); |
792 | 792 | |
793 | - if ( !isset( $vat_classes[$vat_class] ) ) { |
|
794 | - $response['error'] = __( 'Requested class does not exists', 'invoicing' ); |
|
795 | - wp_send_json( $response ); |
|
793 | + if (!isset($vat_classes[$vat_class])) { |
|
794 | + $response['error'] = __('Requested class does not exists', 'invoicing'); |
|
795 | + wp_send_json($response); |
|
796 | 796 | } |
797 | 797 | |
798 | - if ( $vat_class == '_new' || $vat_class == '_standard' ) { |
|
799 | - $response['error'] = __( 'You can not delete standard rates class', 'invoicing' ); |
|
800 | - wp_send_json( $response ); |
|
798 | + if ($vat_class == '_new' || $vat_class == '_standard') { |
|
799 | + $response['error'] = __('You can not delete standard rates class', 'invoicing'); |
|
800 | + wp_send_json($response); |
|
801 | 801 | } |
802 | 802 | |
803 | - $vat_classes = (array)self::get_rate_classes( true ); |
|
804 | - unset( $vat_classes[$vat_class] ); |
|
803 | + $vat_classes = (array)self::get_rate_classes(true); |
|
804 | + unset($vat_classes[$vat_class]); |
|
805 | 805 | |
806 | - update_option( '_wpinv_vat_rate_classes', $vat_classes ); |
|
806 | + update_option('_wpinv_vat_rate_classes', $vat_classes); |
|
807 | 807 | |
808 | 808 | $response['success'] = true; |
809 | - $response['redirect'] = admin_url( 'admin.php?page=wpinv-settings&tab=taxes§ion=vat_rates&wpi_sub=_new' ); |
|
809 | + $response['redirect'] = admin_url('admin.php?page=wpinv-settings&tab=taxes§ion=vat_rates&wpi_sub=_new'); |
|
810 | 810 | |
811 | - wp_send_json( $response ); |
|
811 | + wp_send_json($response); |
|
812 | 812 | } |
813 | 813 | |
814 | 814 | public static function update_eu_rates() { |
@@ -817,72 +817,72 @@ discard block |
||
817 | 817 | $response['error'] = null; |
818 | 818 | $response['data'] = null; |
819 | 819 | |
820 | - if ( !current_user_can( 'manage_options' ) ) { |
|
821 | - $response['error'] = __( 'Invalid access!', 'invoicing' ); |
|
822 | - wp_send_json( $response ); |
|
820 | + if (!current_user_can('manage_options')) { |
|
821 | + $response['error'] = __('Invalid access!', 'invoicing'); |
|
822 | + wp_send_json($response); |
|
823 | 823 | } |
824 | 824 | |
825 | - $group = !empty( $_POST['group'] ) ? sanitize_text_field( $_POST['group'] ) : ''; |
|
826 | - $euvatrates = self::request_euvatrates( $group ); |
|
825 | + $group = !empty($_POST['group']) ? sanitize_text_field($_POST['group']) : ''; |
|
826 | + $euvatrates = self::request_euvatrates($group); |
|
827 | 827 | |
828 | - if ( !empty( $euvatrates ) ) { |
|
829 | - if ( !empty( $euvatrates['success'] ) && !empty( $euvatrates['rates'] ) ) { |
|
828 | + if (!empty($euvatrates)) { |
|
829 | + if (!empty($euvatrates['success']) && !empty($euvatrates['rates'])) { |
|
830 | 830 | $response['success'] = true; |
831 | 831 | $response['data']['rates'] = $euvatrates['rates']; |
832 | - } else if ( !empty( $euvatrates['error'] ) ) { |
|
832 | + } else if (!empty($euvatrates['error'])) { |
|
833 | 833 | $response['error'] = $euvatrates['error']; |
834 | 834 | } |
835 | 835 | } |
836 | 836 | |
837 | - wp_send_json( $response ); |
|
837 | + wp_send_json($response); |
|
838 | 838 | } |
839 | 839 | |
840 | 840 | public static function hide_vat_fields() { |
841 | - $hide = wpinv_get_option( 'vat_disable_fields' ); |
|
841 | + $hide = wpinv_get_option('vat_disable_fields'); |
|
842 | 842 | |
843 | - return apply_filters( 'wpinv_hide_vat_fields', $hide ); |
|
843 | + return apply_filters('wpinv_hide_vat_fields', $hide); |
|
844 | 844 | } |
845 | 845 | |
846 | 846 | public static function same_country_rule() { |
847 | - $same_country_rule = wpinv_get_option( 'vat_same_country_rule' ); |
|
847 | + $same_country_rule = wpinv_get_option('vat_same_country_rule'); |
|
848 | 848 | |
849 | - return apply_filters( 'wpinv_vat_same_country_rule', $same_country_rule ); |
|
849 | + return apply_filters('wpinv_vat_same_country_rule', $same_country_rule); |
|
850 | 850 | } |
851 | 851 | |
852 | 852 | public static function get_vat_name() { |
853 | - $vat_name = wpinv_get_option( 'vat_name' ); |
|
854 | - $vat_name = !empty( $vat_name ) ? $vat_name : 'VAT'; |
|
853 | + $vat_name = wpinv_get_option('vat_name'); |
|
854 | + $vat_name = !empty($vat_name) ? $vat_name : 'VAT'; |
|
855 | 855 | |
856 | - return apply_filters( 'wpinv_get_owner_vat_name', $vat_name ); |
|
856 | + return apply_filters('wpinv_get_owner_vat_name', $vat_name); |
|
857 | 857 | } |
858 | 858 | |
859 | 859 | public static function get_company_name() { |
860 | - $company_name = wpinv_get_option( 'vat_company_name' ); |
|
860 | + $company_name = wpinv_get_option('vat_company_name'); |
|
861 | 861 | |
862 | - return apply_filters( 'wpinv_get_owner_company_name', $company_name ); |
|
862 | + return apply_filters('wpinv_get_owner_company_name', $company_name); |
|
863 | 863 | } |
864 | 864 | |
865 | 865 | public static function get_vat_number() { |
866 | - $vat_number = wpinv_get_option( 'vat_number' ); |
|
866 | + $vat_number = wpinv_get_option('vat_number'); |
|
867 | 867 | |
868 | - return apply_filters( 'wpinv_get_owner_vat_number', $vat_number ); |
|
868 | + return apply_filters('wpinv_get_owner_vat_number', $vat_number); |
|
869 | 869 | } |
870 | 870 | |
871 | 871 | public static function is_vat_validated() { |
872 | - $validated = self::get_vat_number() && wpinv_get_option( 'vat_valid' ); |
|
872 | + $validated = self::get_vat_number() && wpinv_get_option('vat_valid'); |
|
873 | 873 | |
874 | - return apply_filters( 'wpinv_is_owner_vat_validated', $validated ); |
|
874 | + return apply_filters('wpinv_is_owner_vat_validated', $validated); |
|
875 | 875 | } |
876 | 876 | |
877 | - public static function sanitize_vat( $vat_number, $country_code = '' ) { |
|
878 | - $vat_number = str_replace( array(' ', '.', '-', '_', ',' ), '', strtoupper( trim( $vat_number ) ) ); |
|
877 | + public static function sanitize_vat($vat_number, $country_code = '') { |
|
878 | + $vat_number = str_replace(array(' ', '.', '-', '_', ','), '', strtoupper(trim($vat_number))); |
|
879 | 879 | |
880 | - if ( empty( $country_code ) ) { |
|
881 | - $country_code = substr( $vat_number, 0, 2 ); |
|
880 | + if (empty($country_code)) { |
|
881 | + $country_code = substr($vat_number, 0, 2); |
|
882 | 882 | } |
883 | 883 | |
884 | - if ( strpos( $vat_number , $country_code ) === 0 ) { |
|
885 | - $vat = str_replace( $country_code, '', $vat_number ); |
|
884 | + if (strpos($vat_number, $country_code) === 0) { |
|
885 | + $vat = str_replace($country_code, '', $vat_number); |
|
886 | 886 | } else { |
887 | 887 | $vat = $country_code . $vat_number; |
888 | 888 | } |
@@ -895,140 +895,140 @@ discard block |
||
895 | 895 | return $return; |
896 | 896 | } |
897 | 897 | |
898 | - public static function offline_check( $vat_number, $country_code = '', $formatted = false ) { |
|
899 | - $vat = self::sanitize_vat( $vat_number, $country_code ); |
|
898 | + public static function offline_check($vat_number, $country_code = '', $formatted = false) { |
|
899 | + $vat = self::sanitize_vat($vat_number, $country_code); |
|
900 | 900 | $vat_number = $vat['vat_number']; |
901 | 901 | $country_code = $vat['iso']; |
902 | 902 | $regex = array(); |
903 | 903 | |
904 | - switch ( $country_code ) { |
|
904 | + switch ($country_code) { |
|
905 | 905 | case 'AT': |
906 | - $regex[] = '/^(AT)U(\d{8})$/'; // Austria |
|
906 | + $regex[] = '/^(AT)U(\d{8})$/'; // Austria |
|
907 | 907 | break; |
908 | 908 | case 'BE': |
909 | - $regex[] = '/^(BE)(0?\d{9})$/'; // Belgium |
|
909 | + $regex[] = '/^(BE)(0?\d{9})$/'; // Belgium |
|
910 | 910 | break; |
911 | 911 | case 'BG': |
912 | - $regex[] = '/^(BG)(\d{9,10})$/'; // Bulgaria |
|
912 | + $regex[] = '/^(BG)(\d{9,10})$/'; // Bulgaria |
|
913 | 913 | break; |
914 | 914 | case 'CH': |
915 | 915 | case 'CHE': |
916 | - $regex[] = '/^(CHE)(\d{9})MWST$/'; // Switzerland (Not EU) |
|
916 | + $regex[] = '/^(CHE)(\d{9})MWST$/'; // Switzerland (Not EU) |
|
917 | 917 | break; |
918 | 918 | case 'CY': |
919 | - $regex[] = '/^(CY)([0-5|9]\d{7}[A-Z])$/'; // Cyprus |
|
919 | + $regex[] = '/^(CY)([0-5|9]\d{7}[A-Z])$/'; // Cyprus |
|
920 | 920 | break; |
921 | 921 | case 'CZ': |
922 | - $regex[] = '/^(CZ)(\d{8,13})$/'; // Czech Republic |
|
922 | + $regex[] = '/^(CZ)(\d{8,13})$/'; // Czech Republic |
|
923 | 923 | break; |
924 | 924 | case 'DE': |
925 | - $regex[] = '/^(DE)([1-9]\d{8})$/'; // Germany |
|
925 | + $regex[] = '/^(DE)([1-9]\d{8})$/'; // Germany |
|
926 | 926 | break; |
927 | 927 | case 'DK': |
928 | - $regex[] = '/^(DK)(\d{8})$/'; // Denmark |
|
928 | + $regex[] = '/^(DK)(\d{8})$/'; // Denmark |
|
929 | 929 | break; |
930 | 930 | case 'EE': |
931 | - $regex[] = '/^(EE)(10\d{7})$/'; // Estonia |
|
931 | + $regex[] = '/^(EE)(10\d{7})$/'; // Estonia |
|
932 | 932 | break; |
933 | 933 | case 'EL': |
934 | - $regex[] = '/^(EL)(\d{9})$/'; // Greece |
|
934 | + $regex[] = '/^(EL)(\d{9})$/'; // Greece |
|
935 | 935 | break; |
936 | 936 | case 'ES': |
937 | - $regex[] = '/^(ES)([A-Z]\d{8})$/'; // Spain (National juridical entities) |
|
938 | - $regex[] = '/^(ES)([A-H|N-S|W]\d{7}[A-J])$/'; // Spain (Other juridical entities) |
|
939 | - $regex[] = '/^(ES)([0-9|Y|Z]\d{7}[A-Z])$/'; // Spain (Personal entities type 1) |
|
940 | - $regex[] = '/^(ES)([K|L|M|X]\d{7}[A-Z])$/'; // Spain (Personal entities type 2) |
|
937 | + $regex[] = '/^(ES)([A-Z]\d{8})$/'; // Spain (National juridical entities) |
|
938 | + $regex[] = '/^(ES)([A-H|N-S|W]\d{7}[A-J])$/'; // Spain (Other juridical entities) |
|
939 | + $regex[] = '/^(ES)([0-9|Y|Z]\d{7}[A-Z])$/'; // Spain (Personal entities type 1) |
|
940 | + $regex[] = '/^(ES)([K|L|M|X]\d{7}[A-Z])$/'; // Spain (Personal entities type 2) |
|
941 | 941 | break; |
942 | 942 | case 'EU': |
943 | - $regex[] = '/^(EU)(\d{9})$/'; // EU-type |
|
943 | + $regex[] = '/^(EU)(\d{9})$/'; // EU-type |
|
944 | 944 | break; |
945 | 945 | case 'FI': |
946 | - $regex[] = '/^(FI)(\d{8})$/'; // Finland |
|
946 | + $regex[] = '/^(FI)(\d{8})$/'; // Finland |
|
947 | 947 | break; |
948 | 948 | case 'FR': |
949 | - $regex[] = '/^(FR)(\d{11})$/'; // France (1) |
|
950 | - $regex[] = '/^(FR)[(A-H)|(J-N)|(P-Z)](\d{10})$/'; // France (2) |
|
951 | - $regex[] = '/^(FR)\d[(A-H)|(J-N)|(P-Z)](\d{9})$/'; // France (3) |
|
952 | - $regex[] = '/^(FR)[(A-H)|(J-N)|(P-Z)]{2}(\d{9})$/'; // France (4) |
|
949 | + $regex[] = '/^(FR)(\d{11})$/'; // France (1) |
|
950 | + $regex[] = '/^(FR)[(A-H)|(J-N)|(P-Z)](\d{10})$/'; // France (2) |
|
951 | + $regex[] = '/^(FR)\d[(A-H)|(J-N)|(P-Z)](\d{9})$/'; // France (3) |
|
952 | + $regex[] = '/^(FR)[(A-H)|(J-N)|(P-Z)]{2}(\d{9})$/'; // France (4) |
|
953 | 953 | break; |
954 | 954 | case 'GB': |
955 | - $regex[] = '/^(GB)?(\d{9})$/'; // UK (Standard) |
|
956 | - $regex[] = '/^(GB)?(\d{12})$/'; // UK (Branches) |
|
957 | - $regex[] = '/^(GB)?(GD\d{3})$/'; // UK (Government) |
|
958 | - $regex[] = '/^(GB)?(HA\d{3})$/'; // UK (Health authority) |
|
955 | + $regex[] = '/^(GB)?(\d{9})$/'; // UK (Standard) |
|
956 | + $regex[] = '/^(GB)?(\d{12})$/'; // UK (Branches) |
|
957 | + $regex[] = '/^(GB)?(GD\d{3})$/'; // UK (Government) |
|
958 | + $regex[] = '/^(GB)?(HA\d{3})$/'; // UK (Health authority) |
|
959 | 959 | break; |
960 | 960 | case 'GR': |
961 | - $regex[] = '/^(GR)(\d{8,9})$/'; // Greece |
|
961 | + $regex[] = '/^(GR)(\d{8,9})$/'; // Greece |
|
962 | 962 | break; |
963 | 963 | case 'HR': |
964 | - $regex[] = '/^(HR)(\d{11})$/'; // Croatia |
|
964 | + $regex[] = '/^(HR)(\d{11})$/'; // Croatia |
|
965 | 965 | break; |
966 | 966 | case 'HU': |
967 | - $regex[] = '/^(HU)(\d{8})$/'; // Hungary |
|
967 | + $regex[] = '/^(HU)(\d{8})$/'; // Hungary |
|
968 | 968 | break; |
969 | 969 | case 'IE': |
970 | - $regex[] = '/^(IE)(\d{7}[A-W])$/'; // Ireland (1) |
|
971 | - $regex[] = '/^(IE)([7-9][A-Z\*\+)]\d{5}[A-W])$/'; // Ireland (2) |
|
972 | - $regex[] = '/^(IE)(\d{7}[A-Z][AH])$/'; // Ireland (3) (new format from 1 Jan 2013) |
|
970 | + $regex[] = '/^(IE)(\d{7}[A-W])$/'; // Ireland (1) |
|
971 | + $regex[] = '/^(IE)([7-9][A-Z\*\+)]\d{5}[A-W])$/'; // Ireland (2) |
|
972 | + $regex[] = '/^(IE)(\d{7}[A-Z][AH])$/'; // Ireland (3) (new format from 1 Jan 2013) |
|
973 | 973 | break; |
974 | 974 | case 'IT': |
975 | - $regex[] = '/^(IT)(\d{11})$/'; // Italy |
|
975 | + $regex[] = '/^(IT)(\d{11})$/'; // Italy |
|
976 | 976 | break; |
977 | 977 | case 'LV': |
978 | - $regex[] = '/^(LV)(\d{11})$/'; // Latvia |
|
978 | + $regex[] = '/^(LV)(\d{11})$/'; // Latvia |
|
979 | 979 | break; |
980 | 980 | case 'LT': |
981 | - $regex[] = '/^(LT)(\d{9}|\d{12})$/'; // Lithuania |
|
981 | + $regex[] = '/^(LT)(\d{9}|\d{12})$/'; // Lithuania |
|
982 | 982 | break; |
983 | 983 | case 'LU': |
984 | - $regex[] = '/^(LU)(\d{8})$/'; // Luxembourg |
|
984 | + $regex[] = '/^(LU)(\d{8})$/'; // Luxembourg |
|
985 | 985 | break; |
986 | 986 | case 'MT': |
987 | - $regex[] = '/^(MT)([1-9]\d{7})$/'; // Malta |
|
987 | + $regex[] = '/^(MT)([1-9]\d{7})$/'; // Malta |
|
988 | 988 | break; |
989 | 989 | case 'NL': |
990 | - $regex[] = '/^(NL)(\d{9})B\d{2}$/'; // Netherlands |
|
990 | + $regex[] = '/^(NL)(\d{9})B\d{2}$/'; // Netherlands |
|
991 | 991 | break; |
992 | 992 | case 'NO': |
993 | - $regex[] = '/^(NO)(\d{9})$/'; // Norway (Not EU) |
|
993 | + $regex[] = '/^(NO)(\d{9})$/'; // Norway (Not EU) |
|
994 | 994 | break; |
995 | 995 | case 'PL': |
996 | - $regex[] = '/^(PL)(\d{10})$/'; // Poland |
|
996 | + $regex[] = '/^(PL)(\d{10})$/'; // Poland |
|
997 | 997 | break; |
998 | 998 | case 'PT': |
999 | - $regex[] = '/^(PT)(\d{9})$/'; // Portugal |
|
999 | + $regex[] = '/^(PT)(\d{9})$/'; // Portugal |
|
1000 | 1000 | break; |
1001 | 1001 | case 'RO': |
1002 | - $regex[] = '/^(RO)([1-9]\d{1,9})$/'; // Romania |
|
1002 | + $regex[] = '/^(RO)([1-9]\d{1,9})$/'; // Romania |
|
1003 | 1003 | break; |
1004 | 1004 | case 'RS': |
1005 | - $regex[] = '/^(RS)(\d{9})$/'; // Serbia (Not EU) |
|
1005 | + $regex[] = '/^(RS)(\d{9})$/'; // Serbia (Not EU) |
|
1006 | 1006 | break; |
1007 | 1007 | case 'SI': |
1008 | - $regex[] = '/^(SI)([1-9]\d{7})$/'; // Slovenia |
|
1008 | + $regex[] = '/^(SI)([1-9]\d{7})$/'; // Slovenia |
|
1009 | 1009 | break; |
1010 | 1010 | case 'SK': |
1011 | - $regex[] = '/^(SK)([1-9]\d[(2-4)|(6-9)]\d{7})$/'; // Slovakia Republic |
|
1011 | + $regex[] = '/^(SK)([1-9]\d[(2-4)|(6-9)]\d{7})$/'; // Slovakia Republic |
|
1012 | 1012 | break; |
1013 | 1013 | case 'SE': |
1014 | - $regex[] = '/^(SE)(\d{10}01)$/'; // Sweden |
|
1014 | + $regex[] = '/^(SE)(\d{10}01)$/'; // Sweden |
|
1015 | 1015 | break; |
1016 | 1016 | default: |
1017 | 1017 | $regex = array(); |
1018 | 1018 | break; |
1019 | 1019 | } |
1020 | 1020 | |
1021 | - if ( empty( $regex ) ) { |
|
1021 | + if (empty($regex)) { |
|
1022 | 1022 | return false; |
1023 | 1023 | } |
1024 | 1024 | |
1025 | - foreach ( $regex as $pattern ) { |
|
1025 | + foreach ($regex as $pattern) { |
|
1026 | 1026 | $matches = null; |
1027 | - preg_match_all( $pattern, $vat_number, $matches ); |
|
1027 | + preg_match_all($pattern, $vat_number, $matches); |
|
1028 | 1028 | |
1029 | - if ( !empty( $matches[1][0] ) && !empty( $matches[2][0] ) ) { |
|
1030 | - if ( $formatted ) { |
|
1031 | - return array( 'code' => $matches[1][0], 'number' => $matches[2][0] ); |
|
1029 | + if (!empty($matches[1][0]) && !empty($matches[2][0])) { |
|
1030 | + if ($formatted) { |
|
1031 | + return array('code' => $matches[1][0], 'number' => $matches[2][0]); |
|
1032 | 1032 | } else { |
1033 | 1033 | return true; |
1034 | 1034 | } |
@@ -1038,75 +1038,75 @@ discard block |
||
1038 | 1038 | return false; |
1039 | 1039 | } |
1040 | 1040 | |
1041 | - public static function vies_check( $vat_number, $country_code = '', $result = false ) { |
|
1042 | - $vat = self::sanitize_vat( $vat_number, $country_code ); |
|
1041 | + public static function vies_check($vat_number, $country_code = '', $result = false) { |
|
1042 | + $vat = self::sanitize_vat($vat_number, $country_code); |
|
1043 | 1043 | $vat_number = $vat['vat']; |
1044 | 1044 | $iso = $vat['iso']; |
1045 | 1045 | |
1046 | - $url = 'http://ec.europa.eu/taxation_customs/vies/viesquer.do?ms=' . urlencode( $iso ) . '&iso=' . urlencode( $iso ) . '&vat=' . urlencode( $vat_number ); |
|
1046 | + $url = 'http://ec.europa.eu/taxation_customs/vies/viesquer.do?ms=' . urlencode($iso) . '&iso=' . urlencode($iso) . '&vat=' . urlencode($vat_number); |
|
1047 | 1047 | |
1048 | - if ( ini_get( 'allow_url_fopen' ) ) { |
|
1049 | - $response = file_get_contents( $url ); |
|
1050 | - } else if ( function_exists( 'curl_init' ) ) { |
|
1048 | + if (ini_get('allow_url_fopen')) { |
|
1049 | + $response = file_get_contents($url); |
|
1050 | + } else if (function_exists('curl_init')) { |
|
1051 | 1051 | $ch = curl_init(); |
1052 | 1052 | |
1053 | - curl_setopt( $ch, CURLOPT_URL, $url ); |
|
1054 | - curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT, 30 ); |
|
1055 | - curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true ); |
|
1056 | - curl_setopt( $ch, CURLOPT_SSL_VERIFYHOST, 0 ); |
|
1057 | - curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, 0 ); |
|
1053 | + curl_setopt($ch, CURLOPT_URL, $url); |
|
1054 | + curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30); |
|
1055 | + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
|
1056 | + curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); |
|
1057 | + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); |
|
1058 | 1058 | |
1059 | - $response = curl_exec( $ch ); |
|
1059 | + $response = curl_exec($ch); |
|
1060 | 1060 | |
1061 | - if ( curl_errno( $ch ) ) { |
|
1062 | - wpinv_error_log( curl_error( $ch ), 'VIES CHECK ERROR' ); |
|
1061 | + if (curl_errno($ch)) { |
|
1062 | + wpinv_error_log(curl_error($ch), 'VIES CHECK ERROR'); |
|
1063 | 1063 | $response = ''; |
1064 | 1064 | } |
1065 | 1065 | |
1066 | - curl_close( $ch ); |
|
1066 | + curl_close($ch); |
|
1067 | 1067 | } else { |
1068 | - wpinv_error_log( 'To use VIES CHECK you must have allow_url_fopen is ON or cURL installed & active on your server.', 'VIES CHECK ERROR' ); |
|
1068 | + wpinv_error_log('To use VIES CHECK you must have allow_url_fopen is ON or cURL installed & active on your server.', 'VIES CHECK ERROR'); |
|
1069 | 1069 | } |
1070 | 1070 | |
1071 | - if ( empty( $response ) ) { |
|
1071 | + if (empty($response)) { |
|
1072 | 1072 | return $result; |
1073 | 1073 | } |
1074 | 1074 | |
1075 | - if ( preg_match( '/invalid VAT number/i', $response ) ) { |
|
1075 | + if (preg_match('/invalid VAT number/i', $response)) { |
|
1076 | 1076 | return false; |
1077 | - } else if ( preg_match( '/valid VAT number/i', $response, $matches ) ) { |
|
1078 | - $content = explode( "valid VAT number", htmlentities( $response ) ); |
|
1077 | + } else if (preg_match('/valid VAT number/i', $response, $matches)) { |
|
1078 | + $content = explode("valid VAT number", htmlentities($response)); |
|
1079 | 1079 | |
1080 | - if ( !empty( $content[1] ) ) { |
|
1081 | - preg_match_all( '/<tr>(.*?)<td.*?>(.*?)<\/td>(.*?)<\/tr>/si', html_entity_decode( $content[1] ), $matches ); |
|
1080 | + if (!empty($content[1])) { |
|
1081 | + preg_match_all('/<tr>(.*?)<td.*?>(.*?)<\/td>(.*?)<\/tr>/si', html_entity_decode($content[1]), $matches); |
|
1082 | 1082 | |
1083 | - if ( !empty( $matches[2] ) && $matches[3] ) { |
|
1083 | + if (!empty($matches[2]) && $matches[3]) { |
|
1084 | 1084 | $return = array(); |
1085 | 1085 | |
1086 | - foreach ( $matches[2] as $key => $label ) { |
|
1087 | - $label = trim( $label ); |
|
1086 | + foreach ($matches[2] as $key => $label) { |
|
1087 | + $label = trim($label); |
|
1088 | 1088 | |
1089 | - switch ( strtolower( $label ) ) { |
|
1089 | + switch (strtolower($label)) { |
|
1090 | 1090 | case 'member state': |
1091 | - $return['state'] = trim( strip_tags( $matches[3][$key] ) ); |
|
1091 | + $return['state'] = trim(strip_tags($matches[3][$key])); |
|
1092 | 1092 | break; |
1093 | 1093 | case 'vat number': |
1094 | - $return['number'] = trim( strip_tags( $matches[3][$key] ) ); |
|
1094 | + $return['number'] = trim(strip_tags($matches[3][$key])); |
|
1095 | 1095 | break; |
1096 | 1096 | case 'name': |
1097 | - $return['company'] = trim( strip_tags( $matches[3][$key] ) ); |
|
1097 | + $return['company'] = trim(strip_tags($matches[3][$key])); |
|
1098 | 1098 | break; |
1099 | 1099 | case 'address': |
1100 | - $address = str_replace( array( "<br><br>", "<br /><br />", "<br/><br/>" ), "<br>", html_entity_decode( trim( $matches[3][$key] ) ) ); |
|
1101 | - $return['address'] = trim( strip_tags( $address, '<br>' ) ); |
|
1100 | + $address = str_replace(array("<br><br>", "<br /><br />", "<br/><br/>"), "<br>", html_entity_decode(trim($matches[3][$key]))); |
|
1101 | + $return['address'] = trim(strip_tags($address, '<br>')); |
|
1102 | 1102 | break; |
1103 | 1103 | case 'consultation number': |
1104 | - $return['consultation'] = trim( strip_tags( $matches[3][$key] ) ); |
|
1104 | + $return['consultation'] = trim(strip_tags($matches[3][$key])); |
|
1105 | 1105 | break; |
1106 | 1106 | } |
1107 | 1107 | } |
1108 | 1108 | |
1109 | - if ( !empty( $return ) ) { |
|
1109 | + if (!empty($return)) { |
|
1110 | 1110 | return $return; |
1111 | 1111 | } |
1112 | 1112 | } |
@@ -1118,55 +1118,55 @@ discard block |
||
1118 | 1118 | } |
1119 | 1119 | } |
1120 | 1120 | |
1121 | - public static function check_vat( $vat_number, $country_code = '' ) { |
|
1121 | + public static function check_vat($vat_number, $country_code = '') { |
|
1122 | 1122 | $vat_name = self::get_vat_name(); |
1123 | 1123 | |
1124 | 1124 | $return = array(); |
1125 | 1125 | $return['valid'] = false; |
1126 | - $return['message'] = wp_sprintf( __( '%s number not validated', 'invoicing' ), $vat_name ); |
|
1126 | + $return['message'] = wp_sprintf(__('%s number not validated', 'invoicing'), $vat_name); |
|
1127 | 1127 | |
1128 | - if ( !wpinv_get_option( 'vat_offline_check' ) && !self::offline_check( $vat_number, $country_code ) ) { |
|
1128 | + if (!wpinv_get_option('vat_offline_check') && !self::offline_check($vat_number, $country_code)) { |
|
1129 | 1129 | return $return; |
1130 | 1130 | } |
1131 | 1131 | |
1132 | - $response = self::vies_check( $vat_number, $country_code ); |
|
1132 | + $response = self::vies_check($vat_number, $country_code); |
|
1133 | 1133 | |
1134 | - if ( $response ) { |
|
1135 | - $return['valid'] = true; |
|
1134 | + if ($response) { |
|
1135 | + $return['valid'] = true; |
|
1136 | 1136 | |
1137 | - if ( is_array( $response ) ) { |
|
1138 | - $return['company'] = isset( $response['company'] ) ? $response['company'] : ''; |
|
1139 | - $return['address'] = isset( $response['address'] ) ? $response['address'] : ''; |
|
1137 | + if (is_array($response)) { |
|
1138 | + $return['company'] = isset($response['company']) ? $response['company'] : ''; |
|
1139 | + $return['address'] = isset($response['address']) ? $response['address'] : ''; |
|
1140 | 1140 | $return['message'] = $return['company'] . '<br/>' . $return['address']; |
1141 | 1141 | } |
1142 | 1142 | } else { |
1143 | 1143 | $return['valid'] = false; |
1144 | - $return['message'] = wp_sprintf( __( 'Fail to validate the %s number: EU Commission VAT server (VIES) check fails.', 'invoicing' ), $vat_name ); |
|
1144 | + $return['message'] = wp_sprintf(__('Fail to validate the %s number: EU Commission VAT server (VIES) check fails.', 'invoicing'), $vat_name); |
|
1145 | 1145 | } |
1146 | 1146 | |
1147 | 1147 | return $return; |
1148 | 1148 | } |
1149 | 1149 | |
1150 | - public static function request_euvatrates( $group ) { |
|
1150 | + public static function request_euvatrates($group) { |
|
1151 | 1151 | $response = array(); |
1152 | 1152 | $response['success'] = false; |
1153 | 1153 | $response['error'] = null; |
1154 | 1154 | $response['eurates'] = null; |
1155 | 1155 | |
1156 | 1156 | $euvatrates_url = 'https://euvatrates.com/rates.json'; |
1157 | - $euvatrates_url = apply_filters( 'wpinv_euvatrates_url', $euvatrates_url ); |
|
1158 | - $api_response = wp_remote_get( $euvatrates_url ); |
|
1157 | + $euvatrates_url = apply_filters('wpinv_euvatrates_url', $euvatrates_url); |
|
1158 | + $api_response = wp_remote_get($euvatrates_url); |
|
1159 | 1159 | |
1160 | 1160 | try { |
1161 | - if ( is_wp_error( $api_response ) ) { |
|
1162 | - $response['error'] = __( $api_response->get_error_message(), 'invoicing' ); |
|
1161 | + if (is_wp_error($api_response)) { |
|
1162 | + $response['error'] = __($api_response->get_error_message(), 'invoicing'); |
|
1163 | 1163 | } else { |
1164 | - $body = json_decode( $api_response['body'] ); |
|
1164 | + $body = json_decode($api_response['body']); |
|
1165 | 1165 | |
1166 | - if ( isset( $body->rates ) ) { |
|
1166 | + if (isset($body->rates)) { |
|
1167 | 1167 | $rates = array(); |
1168 | 1168 | |
1169 | - foreach ( $body->rates as $country_code => $rate ) { |
|
1169 | + foreach ($body->rates as $country_code => $rate) { |
|
1170 | 1170 | $vat_rate = array(); |
1171 | 1171 | $vat_rate['country'] = $rate->country; |
1172 | 1172 | $vat_rate['standard'] = (float)$rate->standard_rate; |
@@ -1174,7 +1174,7 @@ discard block |
||
1174 | 1174 | $vat_rate['superreduced'] = (float)$rate->super_reduced_rate; |
1175 | 1175 | $vat_rate['parking'] = (float)$rate->parking_rate; |
1176 | 1176 | |
1177 | - if ( $group !== '' && in_array( $group, array( 'standard', 'reduced', 'superreduced', 'parking' ) ) ) { |
|
1177 | + if ($group !== '' && in_array($group, array('standard', 'reduced', 'superreduced', 'parking'))) { |
|
1178 | 1178 | $vat_rate_group = array(); |
1179 | 1179 | $vat_rate_group['country'] = $rate->country; |
1180 | 1180 | $vat_rate_group[$group] = $vat_rate[$group]; |
@@ -1186,79 +1186,79 @@ discard block |
||
1186 | 1186 | } |
1187 | 1187 | |
1188 | 1188 | $response['success'] = true; |
1189 | - $response['rates'] = apply_filters( 'wpinv_process_euvatrates', $rates, $api_response, $group ); |
|
1189 | + $response['rates'] = apply_filters('wpinv_process_euvatrates', $rates, $api_response, $group); |
|
1190 | 1190 | } else { |
1191 | - $response['error'] = __( 'No EU rates found!', 'invoicing' ); |
|
1191 | + $response['error'] = __('No EU rates found!', 'invoicing'); |
|
1192 | 1192 | } |
1193 | 1193 | } |
1194 | - } catch ( Exception $e ) { |
|
1195 | - $response['error'] = __( $e->getMessage(), 'invoicing' ); |
|
1194 | + } catch (Exception $e) { |
|
1195 | + $response['error'] = __($e->getMessage(), 'invoicing'); |
|
1196 | 1196 | } |
1197 | 1197 | |
1198 | - return apply_filters( 'wpinv_response_euvatrates', $response, $group ); |
|
1198 | + return apply_filters('wpinv_response_euvatrates', $response, $group); |
|
1199 | 1199 | } |
1200 | 1200 | |
1201 | - public static function requires_vat( $requires_vat = false, $user_id = 0, $is_digital = null ) { |
|
1201 | + public static function requires_vat($requires_vat = false, $user_id = 0, $is_digital = null) { |
|
1202 | 1202 | global $wpi_item_id, $wpi_country; |
1203 | 1203 | |
1204 | - if ( !empty( $_POST['wpinv_country'] ) ) { |
|
1205 | - $country_code = trim( $_POST['wpinv_country'] ); |
|
1206 | - } else if ( !empty( $_POST['country'] ) ) { |
|
1207 | - $country_code = trim( $_POST['country'] ); |
|
1208 | - } else if ( !empty( $wpi_country ) ) { |
|
1204 | + if (!empty($_POST['wpinv_country'])) { |
|
1205 | + $country_code = trim($_POST['wpinv_country']); |
|
1206 | + } else if (!empty($_POST['country'])) { |
|
1207 | + $country_code = trim($_POST['country']); |
|
1208 | + } else if (!empty($wpi_country)) { |
|
1209 | 1209 | $country_code = $wpi_country; |
1210 | 1210 | } else { |
1211 | - $country_code = self::get_user_country( '', $user_id ); |
|
1211 | + $country_code = self::get_user_country('', $user_id); |
|
1212 | 1212 | } |
1213 | 1213 | |
1214 | - if ( $is_digital === null && $wpi_item_id ) { |
|
1215 | - $is_digital = $wpi_item_id ? self::item_has_digital_rule( $wpi_item_id ) : self::allow_vat_rules(); |
|
1214 | + if ($is_digital === null && $wpi_item_id) { |
|
1215 | + $is_digital = $wpi_item_id ? self::item_has_digital_rule($wpi_item_id) : self::allow_vat_rules(); |
|
1216 | 1216 | } |
1217 | 1217 | |
1218 | - if ( !empty( $country_code ) ) { |
|
1219 | - $requires_vat = ( self::is_eu_state( $country_code ) && ( self::is_eu_state( self::$default_country ) || $is_digital ) ) || ( self::is_gst_country( $country_code ) && self::is_gst_country( self::$default_country ) ); |
|
1218 | + if (!empty($country_code)) { |
|
1219 | + $requires_vat = (self::is_eu_state($country_code) && (self::is_eu_state(self::$default_country) || $is_digital)) || (self::is_gst_country($country_code) && self::is_gst_country(self::$default_country)); |
|
1220 | 1220 | } |
1221 | 1221 | |
1222 | - return apply_filters( 'wpinv_requires_vat', $requires_vat, $user_id ); |
|
1222 | + return apply_filters('wpinv_requires_vat', $requires_vat, $user_id); |
|
1223 | 1223 | } |
1224 | 1224 | |
1225 | - public static function tax_label( $label = '' ) { |
|
1225 | + public static function tax_label($label = '') { |
|
1226 | 1226 | global $wpi_requires_vat; |
1227 | 1227 | |
1228 | - if ( !( $wpi_requires_vat !== 0 && $wpi_requires_vat ) ) { |
|
1229 | - $wpi_requires_vat = self::requires_vat( 0, false ); |
|
1228 | + if (!($wpi_requires_vat !== 0 && $wpi_requires_vat)) { |
|
1229 | + $wpi_requires_vat = self::requires_vat(0, false); |
|
1230 | 1230 | } |
1231 | 1231 | |
1232 | - return $wpi_requires_vat ? __( self::get_vat_name(), 'invoicing' ) : ( $label ? $label : __( 'Tax', 'invoicing' ) ); |
|
1232 | + return $wpi_requires_vat ? __(self::get_vat_name(), 'invoicing') : ($label ? $label : __('Tax', 'invoicing')); |
|
1233 | 1233 | } |
1234 | 1234 | |
1235 | 1235 | public static function standard_rates_label() { |
1236 | - return __( 'Standard Rates', 'invoicing' ); |
|
1236 | + return __('Standard Rates', 'invoicing'); |
|
1237 | 1237 | } |
1238 | 1238 | |
1239 | - public static function get_rate_classes( $with_desc = false ) { |
|
1240 | - $rate_classes_option = get_option( '_wpinv_vat_rate_classes', true ); |
|
1241 | - $classes = maybe_unserialize( $rate_classes_option ); |
|
1239 | + public static function get_rate_classes($with_desc = false) { |
|
1240 | + $rate_classes_option = get_option('_wpinv_vat_rate_classes', true); |
|
1241 | + $classes = maybe_unserialize($rate_classes_option); |
|
1242 | 1242 | |
1243 | - if ( empty( $classes ) || !is_array( $classes ) ) { |
|
1243 | + if (empty($classes) || !is_array($classes)) { |
|
1244 | 1244 | $classes = array(); |
1245 | 1245 | } |
1246 | 1246 | |
1247 | 1247 | $rate_classes = array(); |
1248 | - if ( !array_key_exists( '_standard', $classes ) ) { |
|
1249 | - if ( $with_desc ) { |
|
1250 | - $rate_classes['_standard'] = array( 'name' => self::standard_rates_label(), 'desc' => __( 'EU member states standard VAT rates', 'invoicing' ) ); |
|
1248 | + if (!array_key_exists('_standard', $classes)) { |
|
1249 | + if ($with_desc) { |
|
1250 | + $rate_classes['_standard'] = array('name' => self::standard_rates_label(), 'desc' => __('EU member states standard VAT rates', 'invoicing')); |
|
1251 | 1251 | } else { |
1252 | 1252 | $rate_classes['_standard'] = self::standard_rates_label(); |
1253 | 1253 | } |
1254 | 1254 | } |
1255 | 1255 | |
1256 | - foreach ( $classes as $key => $class ) { |
|
1257 | - $name = !empty( $class['name'] ) ? __( $class['name'], 'invoicing' ) : $key; |
|
1258 | - $desc = !empty( $class['desc'] ) ? __( $class['desc'], 'invoicing' ) : ''; |
|
1256 | + foreach ($classes as $key => $class) { |
|
1257 | + $name = !empty($class['name']) ? __($class['name'], 'invoicing') : $key; |
|
1258 | + $desc = !empty($class['desc']) ? __($class['desc'], 'invoicing') : ''; |
|
1259 | 1259 | |
1260 | - if ( $with_desc ) { |
|
1261 | - $rate_classes[$key] = array( 'name' => $name, 'desc' => $desc ); |
|
1260 | + if ($with_desc) { |
|
1261 | + $rate_classes[$key] = array('name' => $name, 'desc' => $desc); |
|
1262 | 1262 | } else { |
1263 | 1263 | $rate_classes[$key] = $name; |
1264 | 1264 | } |
@@ -1269,15 +1269,15 @@ discard block |
||
1269 | 1269 | |
1270 | 1270 | public static function get_all_classes() { |
1271 | 1271 | $classes = self::get_rate_classes(); |
1272 | - $classes['_exempt'] = __( 'Exempt (0%)', 'invoicing' ); |
|
1272 | + $classes['_exempt'] = __('Exempt (0%)', 'invoicing'); |
|
1273 | 1273 | |
1274 | - return apply_filters( 'wpinv_vat_get_all_classes', $classes ); |
|
1274 | + return apply_filters('wpinv_vat_get_all_classes', $classes); |
|
1275 | 1275 | } |
1276 | 1276 | |
1277 | - public static function get_class_desc( $rate_class ) { |
|
1278 | - $rate_classes = self::get_rate_classes( true ); |
|
1277 | + public static function get_class_desc($rate_class) { |
|
1278 | + $rate_classes = self::get_rate_classes(true); |
|
1279 | 1279 | |
1280 | - if ( !empty( $rate_classes ) && isset( $rate_classes[$rate_class] ) && isset( $rate_classes[$rate_class]['desc'] ) ) { |
|
1280 | + if (!empty($rate_classes) && isset($rate_classes[$rate_class]) && isset($rate_classes[$rate_class]['desc'])) { |
|
1281 | 1281 | return $rate_classes[$rate_class]['desc']; |
1282 | 1282 | } |
1283 | 1283 | |
@@ -1293,106 +1293,106 @@ discard block |
||
1293 | 1293 | 'increased' => 'Increased' |
1294 | 1294 | ); |
1295 | 1295 | |
1296 | - return apply_filters( 'wpinv_get_vat_groups', $vat_groups ); |
|
1296 | + return apply_filters('wpinv_get_vat_groups', $vat_groups); |
|
1297 | 1297 | } |
1298 | 1298 | |
1299 | 1299 | public static function get_rules() { |
1300 | 1300 | $vat_rules = array( |
1301 | - 'digital' => __( 'Digital Product', 'invoicing' ), |
|
1302 | - 'physical' => __( 'Physical Product', 'invoicing' ) |
|
1301 | + 'digital' => __('Digital Product', 'invoicing'), |
|
1302 | + 'physical' => __('Physical Product', 'invoicing') |
|
1303 | 1303 | ); |
1304 | - return apply_filters( 'wpinv_get_vat_rules', $vat_rules ); |
|
1304 | + return apply_filters('wpinv_get_vat_rules', $vat_rules); |
|
1305 | 1305 | } |
1306 | 1306 | |
1307 | - public static function get_vat_rates( $class ) { |
|
1308 | - if ( $class === '_standard' ) { |
|
1307 | + public static function get_vat_rates($class) { |
|
1308 | + if ($class === '_standard') { |
|
1309 | 1309 | return wpinv_get_tax_rates(); |
1310 | 1310 | } |
1311 | 1311 | |
1312 | 1312 | $rates = self::get_non_standard_rates(); |
1313 | 1313 | |
1314 | - return array_key_exists( $class, $rates ) ? $rates[$class] : array(); |
|
1314 | + return array_key_exists($class, $rates) ? $rates[$class] : array(); |
|
1315 | 1315 | } |
1316 | 1316 | |
1317 | 1317 | public static function get_non_standard_rates() { |
1318 | - $option = get_option( 'wpinv_vat_rates', array()); |
|
1319 | - return is_array( $option ) ? $option : array(); |
|
1318 | + $option = get_option('wpinv_vat_rates', array()); |
|
1319 | + return is_array($option) ? $option : array(); |
|
1320 | 1320 | } |
1321 | 1321 | |
1322 | 1322 | public static function allow_vat_rules() { |
1323 | - return ( wpinv_use_taxes() && wpinv_get_option( 'apply_vat_rules' ) ? true : false ); |
|
1323 | + return (wpinv_use_taxes() && wpinv_get_option('apply_vat_rules') ? true : false); |
|
1324 | 1324 | } |
1325 | 1325 | |
1326 | 1326 | public static function allow_vat_classes() { |
1327 | 1327 | return false; // TODO |
1328 | - return ( wpinv_get_option( 'vat_allow_classes' ) ? true : false ); |
|
1328 | + return (wpinv_get_option('vat_allow_classes') ? true : false); |
|
1329 | 1329 | } |
1330 | 1330 | |
1331 | - public static function get_item_class( $postID ) { |
|
1332 | - $class = get_post_meta( $postID, '_wpinv_vat_class', true ); |
|
1331 | + public static function get_item_class($postID) { |
|
1332 | + $class = get_post_meta($postID, '_wpinv_vat_class', true); |
|
1333 | 1333 | |
1334 | - if ( empty( $class ) ) { |
|
1334 | + if (empty($class)) { |
|
1335 | 1335 | $class = '_standard'; |
1336 | 1336 | } |
1337 | 1337 | |
1338 | - return apply_filters( 'wpinv_get_item_vat_class', $class, $postID ); |
|
1338 | + return apply_filters('wpinv_get_item_vat_class', $class, $postID); |
|
1339 | 1339 | } |
1340 | 1340 | |
1341 | - public static function item_class_label( $postID ) { |
|
1341 | + public static function item_class_label($postID) { |
|
1342 | 1342 | $vat_classes = self::get_all_classes(); |
1343 | 1343 | |
1344 | - $class = self::get_item_class( $postID ); |
|
1345 | - $class = isset( $vat_classes[$class] ) ? $vat_classes[$class] : __( $class, 'invoicing' ); |
|
1344 | + $class = self::get_item_class($postID); |
|
1345 | + $class = isset($vat_classes[$class]) ? $vat_classes[$class] : __($class, 'invoicing'); |
|
1346 | 1346 | |
1347 | - return apply_filters( 'wpinv_item_class_label', $class, $postID ); |
|
1347 | + return apply_filters('wpinv_item_class_label', $class, $postID); |
|
1348 | 1348 | } |
1349 | 1349 | |
1350 | - public static function get_item_rule( $postID ) { |
|
1351 | - $rule_type = get_post_meta( $postID, '_wpinv_vat_rule', true ); |
|
1350 | + public static function get_item_rule($postID) { |
|
1351 | + $rule_type = get_post_meta($postID, '_wpinv_vat_rule', true); |
|
1352 | 1352 | |
1353 | - if ( empty( $rule_type ) ) { |
|
1353 | + if (empty($rule_type)) { |
|
1354 | 1354 | $rule_type = self::allow_vat_rules() ? 'digital' : 'physical'; |
1355 | 1355 | } |
1356 | 1356 | |
1357 | - return apply_filters( 'wpinv_item_get_vat_rule', $rule_type, $postID ); |
|
1357 | + return apply_filters('wpinv_item_get_vat_rule', $rule_type, $postID); |
|
1358 | 1358 | } |
1359 | 1359 | |
1360 | - public static function item_rule_label( $postID ) { |
|
1360 | + public static function item_rule_label($postID) { |
|
1361 | 1361 | $vat_rules = self::get_rules(); |
1362 | - $vat_rule = self::get_item_rule( $postID ); |
|
1363 | - $vat_rule = isset( $vat_rules[$vat_rule] ) ? $vat_rules[$vat_rule] : $vat_rule; |
|
1362 | + $vat_rule = self::get_item_rule($postID); |
|
1363 | + $vat_rule = isset($vat_rules[$vat_rule]) ? $vat_rules[$vat_rule] : $vat_rule; |
|
1364 | 1364 | |
1365 | - return apply_filters( 'wpinv_item_rule_label', $vat_rule, $postID ); |
|
1365 | + return apply_filters('wpinv_item_rule_label', $vat_rule, $postID); |
|
1366 | 1366 | } |
1367 | 1367 | |
1368 | - public static function item_has_digital_rule( $item_id = 0 ) { |
|
1369 | - return self::get_item_rule( $item_id ) == 'digital' ? true : false; |
|
1368 | + public static function item_has_digital_rule($item_id = 0) { |
|
1369 | + return self::get_item_rule($item_id) == 'digital' ? true : false; |
|
1370 | 1370 | } |
1371 | 1371 | |
1372 | - public static function invoice_has_digital_rule( $invoice = 0 ) { |
|
1373 | - if ( !self::allow_vat_rules() ) { |
|
1372 | + public static function invoice_has_digital_rule($invoice = 0) { |
|
1373 | + if (!self::allow_vat_rules()) { |
|
1374 | 1374 | return false; |
1375 | 1375 | } |
1376 | 1376 | |
1377 | - if ( empty( $invoice ) ) { |
|
1377 | + if (empty($invoice)) { |
|
1378 | 1378 | return true; |
1379 | 1379 | } |
1380 | 1380 | |
1381 | - if ( is_int( $invoice ) ) { |
|
1382 | - $invoice = new WPInv_Invoice( $invoice ); |
|
1381 | + if (is_int($invoice)) { |
|
1382 | + $invoice = new WPInv_Invoice($invoice); |
|
1383 | 1383 | } |
1384 | 1384 | |
1385 | - if ( !( is_object( $invoice ) && is_a( $invoice, 'WPInv_Invoice' ) ) ) { |
|
1385 | + if (!(is_object($invoice) && is_a($invoice, 'WPInv_Invoice'))) { |
|
1386 | 1386 | return true; |
1387 | 1387 | } |
1388 | 1388 | |
1389 | - $cart_items = $invoice->get_cart_details(); |
|
1389 | + $cart_items = $invoice->get_cart_details(); |
|
1390 | 1390 | |
1391 | - if ( !empty( $cart_items ) ) { |
|
1391 | + if (!empty($cart_items)) { |
|
1392 | 1392 | $has_digital_rule = false; |
1393 | 1393 | |
1394 | - foreach ( $cart_items as $key => $item ) { |
|
1395 | - if ( self::item_has_digital_rule( $item['id'] ) ) { |
|
1394 | + foreach ($cart_items as $key => $item) { |
|
1395 | + if (self::item_has_digital_rule($item['id'])) { |
|
1396 | 1396 | $has_digital_rule = true; |
1397 | 1397 | break; |
1398 | 1398 | } |
@@ -1404,67 +1404,67 @@ discard block |
||
1404 | 1404 | return $has_digital_rule; |
1405 | 1405 | } |
1406 | 1406 | |
1407 | - public static function item_is_taxable( $item_id = 0, $country = false, $state = false ) { |
|
1408 | - if ( !wpinv_use_taxes() ) { |
|
1407 | + public static function item_is_taxable($item_id = 0, $country = false, $state = false) { |
|
1408 | + if (!wpinv_use_taxes()) { |
|
1409 | 1409 | return false; |
1410 | 1410 | } |
1411 | 1411 | |
1412 | 1412 | $is_taxable = true; |
1413 | 1413 | |
1414 | - if ( !empty( $item_id ) && self::get_item_class( $item_id ) == '_exempt' ) { |
|
1414 | + if (!empty($item_id) && self::get_item_class($item_id) == '_exempt') { |
|
1415 | 1415 | $is_taxable = false; |
1416 | 1416 | } |
1417 | 1417 | |
1418 | - return apply_filters( 'wpinv_item_is_taxable', $is_taxable, $item_id, $country , $state ); |
|
1418 | + return apply_filters('wpinv_item_is_taxable', $is_taxable, $item_id, $country, $state); |
|
1419 | 1419 | } |
1420 | 1420 | |
1421 | - public static function find_rate( $country, $state, $rate, $class ) { |
|
1421 | + public static function find_rate($country, $state, $rate, $class) { |
|
1422 | 1422 | global $wpi_zero_tax; |
1423 | 1423 | |
1424 | - if ( $class === '_exempt' || $wpi_zero_tax ) { |
|
1424 | + if ($class === '_exempt' || $wpi_zero_tax) { |
|
1425 | 1425 | return 0; |
1426 | 1426 | } |
1427 | 1427 | |
1428 | - $tax_rates = wpinv_get_tax_rates(); |
|
1428 | + $tax_rates = wpinv_get_tax_rates(); |
|
1429 | 1429 | |
1430 | - if ( $class !== '_standard' ) { |
|
1431 | - $class_rates = self::get_vat_rates( $class ); |
|
1430 | + if ($class !== '_standard') { |
|
1431 | + $class_rates = self::get_vat_rates($class); |
|
1432 | 1432 | |
1433 | - if ( is_array( $class_rates ) ) { |
|
1433 | + if (is_array($class_rates)) { |
|
1434 | 1434 | $indexed_class_rates = array(); |
1435 | 1435 | |
1436 | - foreach ( $class_rates as $key => $cr ) { |
|
1436 | + foreach ($class_rates as $key => $cr) { |
|
1437 | 1437 | $indexed_class_rates[$cr['country']] = $cr; |
1438 | 1438 | } |
1439 | 1439 | |
1440 | - $tax_rates = array_map( function( $tr ) use( $indexed_class_rates ) { |
|
1440 | + $tax_rates = array_map(function($tr) use($indexed_class_rates) { |
|
1441 | 1441 | $tr_country = $tr['country']; |
1442 | - if ( !isset( $indexed_class_rates[$tr_country] ) ) { |
|
1442 | + if (!isset($indexed_class_rates[$tr_country])) { |
|
1443 | 1443 | return $tr; |
1444 | 1444 | } |
1445 | 1445 | $icr = $indexed_class_rates[$tr_country]; |
1446 | - return ( empty( $icr['rate'] ) && $icr['rate'] !== '0' ) ? $tr : $icr; |
|
1446 | + return (empty($icr['rate']) && $icr['rate'] !== '0') ? $tr : $icr; |
|
1447 | 1447 | |
1448 | - }, $tax_rates, $class_rates ); |
|
1448 | + }, $tax_rates, $class_rates); |
|
1449 | 1449 | } |
1450 | 1450 | } |
1451 | 1451 | |
1452 | - if ( !empty( $tax_rates ) ) { |
|
1453 | - foreach ( $tax_rates as $key => $tax_rate ) { |
|
1454 | - if ( $country != $tax_rate['country'] ) |
|
1452 | + if (!empty($tax_rates)) { |
|
1453 | + foreach ($tax_rates as $key => $tax_rate) { |
|
1454 | + if ($country != $tax_rate['country']) |
|
1455 | 1455 | continue; |
1456 | 1456 | |
1457 | - if ( !empty( $tax_rate['global'] ) ) { |
|
1458 | - if ( 0 !== $tax_rate['rate'] || !empty( $tax_rate['rate'] ) ) { |
|
1459 | - $rate = number_format( $tax_rate['rate'], 4 ); |
|
1457 | + if (!empty($tax_rate['global'])) { |
|
1458 | + if (0 !== $tax_rate['rate'] || !empty($tax_rate['rate'])) { |
|
1459 | + $rate = number_format($tax_rate['rate'], 4); |
|
1460 | 1460 | } |
1461 | 1461 | } else { |
1462 | - if ( empty( $tax_rate['state'] ) || strtolower( $state ) != strtolower( $tax_rate['state'] ) ) |
|
1462 | + if (empty($tax_rate['state']) || strtolower($state) != strtolower($tax_rate['state'])) |
|
1463 | 1463 | continue; |
1464 | 1464 | |
1465 | 1465 | $state_rate = $tax_rate['rate']; |
1466 | - if ( 0 !== $state_rate || !empty( $state_rate ) ) { |
|
1467 | - $rate = number_format( $state_rate, 4 ); |
|
1466 | + if (0 !== $state_rate || !empty($state_rate)) { |
|
1467 | + $rate = number_format($state_rate, 4); |
|
1468 | 1468 | } |
1469 | 1469 | } |
1470 | 1470 | } |
@@ -1473,84 +1473,84 @@ discard block |
||
1473 | 1473 | return $rate; |
1474 | 1474 | } |
1475 | 1475 | |
1476 | - public static function get_rate( $rate = 1, $country = '', $state = '', $item_id = 0 ) { |
|
1476 | + public static function get_rate($rate = 1, $country = '', $state = '', $item_id = 0) { |
|
1477 | 1477 | global $wpinv_options, $wpi_session, $wpi_item_id, $wpi_zero_tax; |
1478 | 1478 | |
1479 | 1479 | $item_id = $item_id > 0 ? $item_id : $wpi_item_id; |
1480 | 1480 | $allow_vat_classes = self::allow_vat_classes(); |
1481 | - $class = $item_id ? self::get_item_class( $item_id ) : '_standard'; |
|
1481 | + $class = $item_id ? self::get_item_class($item_id) : '_standard'; |
|
1482 | 1482 | |
1483 | - if ( $class === '_exempt' || $wpi_zero_tax ) { |
|
1483 | + if ($class === '_exempt' || $wpi_zero_tax) { |
|
1484 | 1484 | return 0; |
1485 | - } else if ( !$allow_vat_classes ) { |
|
1485 | + } else if (!$allow_vat_classes) { |
|
1486 | 1486 | $class = '_standard'; |
1487 | 1487 | } |
1488 | 1488 | |
1489 | - if( !empty( $_POST['wpinv_country'] ) ) { |
|
1489 | + if (!empty($_POST['wpinv_country'])) { |
|
1490 | 1490 | $post_country = $_POST['wpinv_country']; |
1491 | - } elseif( !empty( $_POST['wpinv_country'] ) ) { |
|
1491 | + } elseif (!empty($_POST['wpinv_country'])) { |
|
1492 | 1492 | $post_country = $_POST['wpinv_country']; |
1493 | - } elseif( !empty( $_POST['country'] ) ) { |
|
1493 | + } elseif (!empty($_POST['country'])) { |
|
1494 | 1494 | $post_country = $_POST['country']; |
1495 | 1495 | } else { |
1496 | 1496 | $post_country = ''; |
1497 | 1497 | } |
1498 | 1498 | |
1499 | - $country = !empty( $post_country ) ? $post_country : wpinv_default_billing_country( $country ); |
|
1500 | - $base_country = wpinv_is_base_country( $country ); |
|
1499 | + $country = !empty($post_country) ? $post_country : wpinv_default_billing_country($country); |
|
1500 | + $base_country = wpinv_is_base_country($country); |
|
1501 | 1501 | |
1502 | - $requires_vat = self::requires_vat( 0, false ); |
|
1503 | - $is_digital = self::get_item_rule( $item_id ) == 'digital' ; |
|
1504 | - $rate = $requires_vat && isset( $wpinv_options['eu_fallback_rate'] ) ? $wpinv_options['eu_fallback_rate'] : $rate; |
|
1502 | + $requires_vat = self::requires_vat(0, false); |
|
1503 | + $is_digital = self::get_item_rule($item_id) == 'digital'; |
|
1504 | + $rate = $requires_vat && isset($wpinv_options['eu_fallback_rate']) ? $wpinv_options['eu_fallback_rate'] : $rate; |
|
1505 | 1505 | |
1506 | - if ( self::same_country_rule() == 'no' && $base_country ) { // Disable VAT to same country |
|
1506 | + if (self::same_country_rule() == 'no' && $base_country) { // Disable VAT to same country |
|
1507 | 1507 | $rate = 0; |
1508 | - } else if ( $requires_vat ) { |
|
1509 | - $vat_number = self::get_user_vat_number( '', 0, true ); |
|
1508 | + } else if ($requires_vat) { |
|
1509 | + $vat_number = self::get_user_vat_number('', 0, true); |
|
1510 | 1510 | $vat_info = self::current_vat_data(); |
1511 | 1511 | |
1512 | - if ( is_array( $vat_info ) ) { |
|
1513 | - $vat_number = isset( $vat_info['number'] ) && !empty( $vat_info['valid'] ) ? $vat_info['number'] : ""; |
|
1512 | + if (is_array($vat_info)) { |
|
1513 | + $vat_number = isset($vat_info['number']) && !empty($vat_info['valid']) ? $vat_info['number'] : ""; |
|
1514 | 1514 | } |
1515 | 1515 | |
1516 | - if ( $country == 'UK' ) { |
|
1516 | + if ($country == 'UK') { |
|
1517 | 1517 | $country = 'GB'; |
1518 | 1518 | } |
1519 | 1519 | |
1520 | - if ( !empty( $vat_number ) ) { |
|
1520 | + if (!empty($vat_number)) { |
|
1521 | 1521 | $rate = 0; |
1522 | 1522 | } else { |
1523 | - $rate = self::find_rate( $country, $state, $rate, $class ); // Fix if there are no tax rated and you try to pay an invoice it does not add the fallback tax rate |
|
1523 | + $rate = self::find_rate($country, $state, $rate, $class); // Fix if there are no tax rated and you try to pay an invoice it does not add the fallback tax rate |
|
1524 | 1524 | } |
1525 | 1525 | |
1526 | - if ( empty( $vat_number ) && !$is_digital ) { |
|
1527 | - if ( $base_country ) { |
|
1528 | - $rate = self::find_rate( $country, null, $rate, $class ); |
|
1526 | + if (empty($vat_number) && !$is_digital) { |
|
1527 | + if ($base_country) { |
|
1528 | + $rate = self::find_rate($country, null, $rate, $class); |
|
1529 | 1529 | } else { |
1530 | - if ( empty( $country ) && isset( $wpinv_options['eu_fallback_rate'] ) ) { |
|
1530 | + if (empty($country) && isset($wpinv_options['eu_fallback_rate'])) { |
|
1531 | 1531 | $rate = $wpinv_options['eu_fallback_rate']; |
1532 | - } else if( !empty( $country ) ) { |
|
1533 | - $rate = self::find_rate( $country, $state, $rate, $class ); |
|
1532 | + } else if (!empty($country)) { |
|
1533 | + $rate = self::find_rate($country, $state, $rate, $class); |
|
1534 | 1534 | } |
1535 | 1535 | } |
1536 | - } else if ( empty( $vat_number ) || ( self::same_country_rule() == 'always' && $base_country ) ) { |
|
1537 | - if ( empty( $country ) && isset( $wpinv_options['eu_fallback_rate'] ) ) { |
|
1536 | + } else if (empty($vat_number) || (self::same_country_rule() == 'always' && $base_country)) { |
|
1537 | + if (empty($country) && isset($wpinv_options['eu_fallback_rate'])) { |
|
1538 | 1538 | $rate = $wpinv_options['eu_fallback_rate']; |
1539 | - } else if( !empty( $country ) ) { |
|
1540 | - $rate = self::find_rate( $country, $state, $rate, $class ); |
|
1539 | + } else if (!empty($country)) { |
|
1540 | + $rate = self::find_rate($country, $state, $rate, $class); |
|
1541 | 1541 | } |
1542 | 1542 | } |
1543 | 1543 | } else { |
1544 | - if ( $is_digital ) { |
|
1544 | + if ($is_digital) { |
|
1545 | 1545 | $ip_country_code = self::get_country_by_ip(); |
1546 | 1546 | |
1547 | - if ( $ip_country_code && self::is_eu_state( $ip_country_code ) ) { |
|
1548 | - $rate = self::find_rate( $ip_country_code, '', 0, $class ); |
|
1547 | + if ($ip_country_code && self::is_eu_state($ip_country_code)) { |
|
1548 | + $rate = self::find_rate($ip_country_code, '', 0, $class); |
|
1549 | 1549 | } else { |
1550 | - $rate = self::find_rate( $country, $state, $rate, $class ); |
|
1550 | + $rate = self::find_rate($country, $state, $rate, $class); |
|
1551 | 1551 | } |
1552 | 1552 | } else { |
1553 | - $rate = self::find_rate( $country, $state, $rate, $class ); |
|
1553 | + $rate = self::find_rate($country, $state, $rate, $class); |
|
1554 | 1554 | } |
1555 | 1555 | } |
1556 | 1556 | |
@@ -1560,48 +1560,48 @@ discard block |
||
1560 | 1560 | public static function current_vat_data() { |
1561 | 1561 | global $wpi_session; |
1562 | 1562 | |
1563 | - return $wpi_session->get( 'user_vat_data' ); |
|
1563 | + return $wpi_session->get('user_vat_data'); |
|
1564 | 1564 | } |
1565 | 1565 | |
1566 | - public static function get_user_country( $country = '', $user_id = 0 ) { |
|
1567 | - $user_address = wpinv_get_user_address( $user_id, false ); |
|
1566 | + public static function get_user_country($country = '', $user_id = 0) { |
|
1567 | + $user_address = wpinv_get_user_address($user_id, false); |
|
1568 | 1568 | |
1569 | - if ( wpinv_get_option( 'vat_ip_country_default' ) ) { |
|
1569 | + if (wpinv_get_option('vat_ip_country_default')) { |
|
1570 | 1570 | $country = ''; |
1571 | 1571 | } |
1572 | 1572 | |
1573 | - $country = empty( $user_address ) || !isset( $user_address['country'] ) || empty( $user_address['country'] ) ? $country : $user_address['country']; |
|
1574 | - $result = apply_filters( 'wpinv_get_user_country', $country, $user_id ); |
|
1573 | + $country = empty($user_address) || !isset($user_address['country']) || empty($user_address['country']) ? $country : $user_address['country']; |
|
1574 | + $result = apply_filters('wpinv_get_user_country', $country, $user_id); |
|
1575 | 1575 | |
1576 | - if ( empty( $result ) ) { |
|
1576 | + if (empty($result)) { |
|
1577 | 1577 | $result = self::get_country_by_ip(); |
1578 | 1578 | } |
1579 | 1579 | |
1580 | 1580 | return $result; |
1581 | 1581 | } |
1582 | 1582 | |
1583 | - public static function set_user_country( $country = '', $user_id = 0 ) { |
|
1583 | + public static function set_user_country($country = '', $user_id = 0) { |
|
1584 | 1584 | global $wpi_userID; |
1585 | 1585 | |
1586 | - if ( empty($country) && !empty($wpi_userID) && get_current_user_id() != $wpi_userID ) { |
|
1586 | + if (empty($country) && !empty($wpi_userID) && get_current_user_id() != $wpi_userID) { |
|
1587 | 1587 | $country = wpinv_get_default_country(); |
1588 | 1588 | } |
1589 | 1589 | |
1590 | 1590 | return $country; |
1591 | 1591 | } |
1592 | 1592 | |
1593 | - public static function get_user_vat_number( $vat_number = '', $user_id = 0, $is_valid = false ) { |
|
1593 | + public static function get_user_vat_number($vat_number = '', $user_id = 0, $is_valid = false) { |
|
1594 | 1594 | global $wpi_current_id, $wpi_userID; |
1595 | 1595 | |
1596 | - if ( !empty( $_POST['new_user'] ) ) { |
|
1596 | + if (!empty($_POST['new_user'])) { |
|
1597 | 1597 | return ''; |
1598 | 1598 | } |
1599 | 1599 | |
1600 | - if ( empty( $user_id ) ) { |
|
1601 | - $user_id = !empty( $wpi_userID ) ? $wpi_userID : ( $wpi_current_id ? wpinv_get_user_id( $wpi_current_id ) : get_current_user_id() ); |
|
1600 | + if (empty($user_id)) { |
|
1601 | + $user_id = !empty($wpi_userID) ? $wpi_userID : ($wpi_current_id ? wpinv_get_user_id($wpi_current_id) : get_current_user_id()); |
|
1602 | 1602 | } |
1603 | 1603 | |
1604 | - $vat_number = empty( $user_id ) ? '' : get_user_meta( $user_id, '_wpinv_vat_number', true ); |
|
1604 | + $vat_number = empty($user_id) ? '' : get_user_meta($user_id, '_wpinv_vat_number', true); |
|
1605 | 1605 | |
1606 | 1606 | /* TODO |
1607 | 1607 | if ( $is_valid && $vat_number ) { |
@@ -1612,38 +1612,38 @@ discard block |
||
1612 | 1612 | } |
1613 | 1613 | */ |
1614 | 1614 | |
1615 | - return apply_filters('wpinv_get_user_vat_number', $vat_number, $user_id, $is_valid ); |
|
1615 | + return apply_filters('wpinv_get_user_vat_number', $vat_number, $user_id, $is_valid); |
|
1616 | 1616 | } |
1617 | 1617 | |
1618 | - public static function get_user_company( $company = '', $user_id = 0 ) { |
|
1618 | + public static function get_user_company($company = '', $user_id = 0) { |
|
1619 | 1619 | global $wpi_current_id, $wpi_userID; |
1620 | 1620 | |
1621 | - if ( empty( $user_id ) ) { |
|
1622 | - $user_id = !empty( $wpi_userID ) ? $wpi_userID : ( $wpi_current_id ? wpinv_get_user_id( $wpi_current_id ) : get_current_user_id() ); |
|
1621 | + if (empty($user_id)) { |
|
1622 | + $user_id = !empty($wpi_userID) ? $wpi_userID : ($wpi_current_id ? wpinv_get_user_id($wpi_current_id) : get_current_user_id()); |
|
1623 | 1623 | } |
1624 | 1624 | |
1625 | - $company = empty( $user_id ) ? "" : get_user_meta( $user_id, '_wpinv_company', true ); |
|
1625 | + $company = empty($user_id) ? "" : get_user_meta($user_id, '_wpinv_company', true); |
|
1626 | 1626 | |
1627 | - return apply_filters( 'wpinv_user_company', $company, $user_id ); |
|
1627 | + return apply_filters('wpinv_user_company', $company, $user_id); |
|
1628 | 1628 | } |
1629 | 1629 | |
1630 | - public static function save_user_vat_details( $company = '', $vat_number = '' ) { |
|
1631 | - $save = apply_filters( 'wpinv_allow_save_user_vat_details', true ); |
|
1630 | + public static function save_user_vat_details($company = '', $vat_number = '') { |
|
1631 | + $save = apply_filters('wpinv_allow_save_user_vat_details', true); |
|
1632 | 1632 | |
1633 | - if ( is_user_logged_in() && $save ) { |
|
1633 | + if (is_user_logged_in() && $save) { |
|
1634 | 1634 | $user_id = get_current_user_id(); |
1635 | 1635 | |
1636 | - if ( !empty( $vat_number ) ) { |
|
1637 | - update_user_meta( $user_id, '_wpinv_vat_number', $vat_number ); |
|
1636 | + if (!empty($vat_number)) { |
|
1637 | + update_user_meta($user_id, '_wpinv_vat_number', $vat_number); |
|
1638 | 1638 | } else { |
1639 | - delete_user_meta( $user_id, '_wpinv_vat_number'); |
|
1639 | + delete_user_meta($user_id, '_wpinv_vat_number'); |
|
1640 | 1640 | } |
1641 | 1641 | |
1642 | - if ( !empty( $company ) ) { |
|
1643 | - update_user_meta( $user_id, '_wpinv_company', $company ); |
|
1642 | + if (!empty($company)) { |
|
1643 | + update_user_meta($user_id, '_wpinv_company', $company); |
|
1644 | 1644 | } else { |
1645 | - delete_user_meta( $user_id, '_wpinv_company'); |
|
1646 | - delete_user_meta( $user_id, '_wpinv_vat_number'); |
|
1645 | + delete_user_meta($user_id, '_wpinv_company'); |
|
1646 | + delete_user_meta($user_id, '_wpinv_vat_number'); |
|
1647 | 1647 | } |
1648 | 1648 | } |
1649 | 1649 | |
@@ -1653,113 +1653,113 @@ discard block |
||
1653 | 1653 | public static function ajax_vat_validate() { |
1654 | 1654 | global $wpinv_options, $wpi_session; |
1655 | 1655 | |
1656 | - $is_checkout = ( !empty( $_POST['source'] ) && $_POST['source'] == 'checkout' ) ? true : false; |
|
1656 | + $is_checkout = (!empty($_POST['source']) && $_POST['source'] == 'checkout') ? true : false; |
|
1657 | 1657 | $response = array(); |
1658 | 1658 | $response['success'] = false; |
1659 | 1659 | |
1660 | - if ( empty( $_REQUEST['_wpi_nonce'] ) || ( !empty( $_REQUEST['_wpi_nonce'] ) && !wp_verify_nonce( $_REQUEST['_wpi_nonce'], 'vat_validation' ) ) ) { |
|
1661 | - $response['error'] = __( 'Invalid security nonce', 'invoicing' ); |
|
1662 | - wp_send_json( $response ); |
|
1660 | + if (empty($_REQUEST['_wpi_nonce']) || (!empty($_REQUEST['_wpi_nonce']) && !wp_verify_nonce($_REQUEST['_wpi_nonce'], 'vat_validation'))) { |
|
1661 | + $response['error'] = __('Invalid security nonce', 'invoicing'); |
|
1662 | + wp_send_json($response); |
|
1663 | 1663 | } |
1664 | 1664 | |
1665 | - $vat_name = self::get_vat_name(); |
|
1665 | + $vat_name = self::get_vat_name(); |
|
1666 | 1666 | |
1667 | - if ( $is_checkout ) { |
|
1667 | + if ($is_checkout) { |
|
1668 | 1668 | $invoice = wpinv_get_invoice_cart(); |
1669 | 1669 | |
1670 | - if ( !self::requires_vat( false, 0, self::invoice_has_digital_rule( $invoice ) ) ) { |
|
1670 | + if (!self::requires_vat(false, 0, self::invoice_has_digital_rule($invoice))) { |
|
1671 | 1671 | $vat_info = array(); |
1672 | - $wpi_session->set( 'user_vat_data', $vat_info ); |
|
1672 | + $wpi_session->set('user_vat_data', $vat_info); |
|
1673 | 1673 | |
1674 | 1674 | self::save_user_vat_details(); |
1675 | 1675 | |
1676 | 1676 | $response['success'] = true; |
1677 | - $response['message'] = wp_sprintf( __( 'Ignore %s', 'invoicing' ), $vat_name ); |
|
1678 | - wp_send_json( $response ); |
|
1677 | + $response['message'] = wp_sprintf(__('Ignore %s', 'invoicing'), $vat_name); |
|
1678 | + wp_send_json($response); |
|
1679 | 1679 | } |
1680 | 1680 | } |
1681 | 1681 | |
1682 | - $company = !empty( $_POST['company'] ) ? sanitize_text_field( $_POST['company'] ) : ''; |
|
1683 | - $vat_number = !empty( $_POST['number'] ) ? sanitize_text_field( $_POST['number'] ) : ''; |
|
1682 | + $company = !empty($_POST['company']) ? sanitize_text_field($_POST['company']) : ''; |
|
1683 | + $vat_number = !empty($_POST['number']) ? sanitize_text_field($_POST['number']) : ''; |
|
1684 | 1684 | |
1685 | - $vat_info = $wpi_session->get( 'user_vat_data' ); |
|
1686 | - if ( !is_array( $vat_info ) || empty( $vat_info ) ) { |
|
1687 | - $vat_info = array( 'company'=> $company, 'number' => '', 'valid' => true ); |
|
1685 | + $vat_info = $wpi_session->get('user_vat_data'); |
|
1686 | + if (!is_array($vat_info) || empty($vat_info)) { |
|
1687 | + $vat_info = array('company'=> $company, 'number' => '', 'valid' => true); |
|
1688 | 1688 | } |
1689 | 1689 | |
1690 | - if ( empty( $vat_number ) ) { |
|
1691 | - if ( $is_checkout ) { |
|
1690 | + if (empty($vat_number)) { |
|
1691 | + if ($is_checkout) { |
|
1692 | 1692 | $response['success'] = true; |
1693 | - $response['message'] = wp_sprintf( __( 'No %s number has been applied. %s will be added to invoice totals', 'invoicing' ), $vat_name, $vat_name ); |
|
1693 | + $response['message'] = wp_sprintf(__('No %s number has been applied. %s will be added to invoice totals', 'invoicing'), $vat_name, $vat_name); |
|
1694 | 1694 | |
1695 | - $vat_info = $wpi_session->get( 'user_vat_data' ); |
|
1695 | + $vat_info = $wpi_session->get('user_vat_data'); |
|
1696 | 1696 | $vat_info['number'] = ""; |
1697 | 1697 | $vat_info['valid'] = true; |
1698 | 1698 | |
1699 | - self::save_user_vat_details( $company ); |
|
1699 | + self::save_user_vat_details($company); |
|
1700 | 1700 | } else { |
1701 | - $response['error'] = wp_sprintf( __( 'Please enter your %s number!', 'invoicing' ), $vat_name ); |
|
1701 | + $response['error'] = wp_sprintf(__('Please enter your %s number!', 'invoicing'), $vat_name); |
|
1702 | 1702 | |
1703 | 1703 | $vat_info['valid'] = false; |
1704 | 1704 | } |
1705 | 1705 | |
1706 | - $wpi_session->set( 'user_vat_data', $vat_info ); |
|
1707 | - wp_send_json( $response ); |
|
1706 | + $wpi_session->set('user_vat_data', $vat_info); |
|
1707 | + wp_send_json($response); |
|
1708 | 1708 | } |
1709 | 1709 | |
1710 | - if ( empty( $company ) ) { |
|
1710 | + if (empty($company)) { |
|
1711 | 1711 | $vat_info['valid'] = false; |
1712 | - $wpi_session->set( 'user_vat_data', $vat_info ); |
|
1712 | + $wpi_session->set('user_vat_data', $vat_info); |
|
1713 | 1713 | |
1714 | - $response['error'] = __( 'Please enter your registered company name!', 'invoicing' ); |
|
1715 | - wp_send_json( $response ); |
|
1714 | + $response['error'] = __('Please enter your registered company name!', 'invoicing'); |
|
1715 | + wp_send_json($response); |
|
1716 | 1716 | } |
1717 | 1717 | |
1718 | - if ( !empty( $wpinv_options['vat_vies_check'] ) ) { |
|
1719 | - if ( empty( $wpinv_options['vat_offline_check'] ) && !self::offline_check( $vat_number ) ) { |
|
1718 | + if (!empty($wpinv_options['vat_vies_check'])) { |
|
1719 | + if (empty($wpinv_options['vat_offline_check']) && !self::offline_check($vat_number)) { |
|
1720 | 1720 | $vat_info['valid'] = false; |
1721 | - $wpi_session->set( 'user_vat_data', $vat_info ); |
|
1721 | + $wpi_session->set('user_vat_data', $vat_info); |
|
1722 | 1722 | |
1723 | - $response['error'] = wp_sprintf( __( '%s number not validated', 'invoicing' ), $vat_name ); |
|
1724 | - wp_send_json( $response ); |
|
1723 | + $response['error'] = wp_sprintf(__('%s number not validated', 'invoicing'), $vat_name); |
|
1724 | + wp_send_json($response); |
|
1725 | 1725 | } |
1726 | 1726 | |
1727 | 1727 | $response['success'] = true; |
1728 | - $response['message'] = wp_sprintf( __( '%s number validated', 'invoicing' ), $vat_name ); |
|
1728 | + $response['message'] = wp_sprintf(__('%s number validated', 'invoicing'), $vat_name); |
|
1729 | 1729 | } else { |
1730 | - $result = self::check_vat( $vat_number ); |
|
1730 | + $result = self::check_vat($vat_number); |
|
1731 | 1731 | |
1732 | - if ( empty( $result['valid'] ) ) { |
|
1732 | + if (empty($result['valid'])) { |
|
1733 | 1733 | $response['error'] = $result['message']; |
1734 | - wp_send_json( $response ); |
|
1734 | + wp_send_json($response); |
|
1735 | 1735 | } |
1736 | 1736 | |
1737 | - $vies_company = !empty( $result['company'] ) ? $result['company'] : ''; |
|
1738 | - $vies_company = apply_filters( 'wpinv_vies_company_name', $vies_company ); |
|
1737 | + $vies_company = !empty($result['company']) ? $result['company'] : ''; |
|
1738 | + $vies_company = apply_filters('wpinv_vies_company_name', $vies_company); |
|
1739 | 1739 | |
1740 | - $valid_company = $vies_company && $company && ( $vies_company == '---' || strcasecmp( trim( $vies_company ), trim( $company ) ) == 0 ) ? true : false; |
|
1740 | + $valid_company = $vies_company && $company && ($vies_company == '---' || strcasecmp(trim($vies_company), trim($company)) == 0) ? true : false; |
|
1741 | 1741 | |
1742 | - if ( !empty( $wpinv_options['vat_disable_company_name_check'] ) || $valid_company ) { |
|
1742 | + if (!empty($wpinv_options['vat_disable_company_name_check']) || $valid_company) { |
|
1743 | 1743 | $response['success'] = true; |
1744 | - $response['message'] = wp_sprintf( __( '%s number validated', 'invoicing' ), $vat_name ); |
|
1744 | + $response['message'] = wp_sprintf(__('%s number validated', 'invoicing'), $vat_name); |
|
1745 | 1745 | } else { |
1746 | 1746 | $vat_info['valid'] = false; |
1747 | - $wpi_session->set( 'user_vat_data', $vat_info ); |
|
1747 | + $wpi_session->set('user_vat_data', $vat_info); |
|
1748 | 1748 | |
1749 | 1749 | $response['success'] = false; |
1750 | - $response['message'] = wp_sprintf( __( 'The company name associated with the %s number provided is not the same as the company name provided.', 'invoicing' ), $vat_name ); |
|
1751 | - wp_send_json( $response ); |
|
1750 | + $response['message'] = wp_sprintf(__('The company name associated with the %s number provided is not the same as the company name provided.', 'invoicing'), $vat_name); |
|
1751 | + wp_send_json($response); |
|
1752 | 1752 | } |
1753 | 1753 | } |
1754 | 1754 | |
1755 | - if ( $is_checkout ) { |
|
1756 | - self::save_user_vat_details( $company, $vat_number ); |
|
1755 | + if ($is_checkout) { |
|
1756 | + self::save_user_vat_details($company, $vat_number); |
|
1757 | 1757 | |
1758 | - $vat_info = array('company' => $company, 'number' => $vat_number, 'valid' => true ); |
|
1759 | - $wpi_session->set( 'user_vat_data', $vat_info ); |
|
1758 | + $vat_info = array('company' => $company, 'number' => $vat_number, 'valid' => true); |
|
1759 | + $wpi_session->set('user_vat_data', $vat_info); |
|
1760 | 1760 | } |
1761 | 1761 | |
1762 | - wp_send_json( $response ); |
|
1762 | + wp_send_json($response); |
|
1763 | 1763 | } |
1764 | 1764 | |
1765 | 1765 | public static function ajax_vat_reset() { |
@@ -1768,161 +1768,161 @@ discard block |
||
1768 | 1768 | $company = is_user_logged_in() ? self::get_user_company() : ''; |
1769 | 1769 | $vat_number = self::get_user_vat_number(); |
1770 | 1770 | |
1771 | - $vat_info = array('company' => $company, 'number' => $vat_number, 'valid' => false ); |
|
1772 | - $wpi_session->set( 'user_vat_data', $vat_info ); |
|
1771 | + $vat_info = array('company' => $company, 'number' => $vat_number, 'valid' => false); |
|
1772 | + $wpi_session->set('user_vat_data', $vat_info); |
|
1773 | 1773 | |
1774 | 1774 | $response = array(); |
1775 | 1775 | $response['success'] = true; |
1776 | 1776 | $response['data']['company'] = $company; |
1777 | 1777 | $response['data']['number'] = $vat_number; |
1778 | 1778 | |
1779 | - wp_send_json( $response ); |
|
1779 | + wp_send_json($response); |
|
1780 | 1780 | } |
1781 | 1781 | |
1782 | - public static function checkout_vat_validate( $valid_data, $post ) { |
|
1782 | + public static function checkout_vat_validate($valid_data, $post) { |
|
1783 | 1783 | global $wpinv_options, $wpi_session; |
1784 | 1784 | |
1785 | - $vat_name = __( self::get_vat_name(), 'invoicing' ); |
|
1785 | + $vat_name = __(self::get_vat_name(), 'invoicing'); |
|
1786 | 1786 | |
1787 | - if ( !isset( $_POST['_wpi_nonce'] ) || !wp_verify_nonce( $_POST['_wpi_nonce'], 'vat_validation' ) ) { |
|
1788 | - wpinv_set_error( 'vat_validation', wp_sprintf( __( "Invalid %s validation request.", 'invoicing' ), $vat_name ) ); |
|
1787 | + if (!isset($_POST['_wpi_nonce']) || !wp_verify_nonce($_POST['_wpi_nonce'], 'vat_validation')) { |
|
1788 | + wpinv_set_error('vat_validation', wp_sprintf(__("Invalid %s validation request.", 'invoicing'), $vat_name)); |
|
1789 | 1789 | return; |
1790 | 1790 | } |
1791 | 1791 | |
1792 | - $vat_saved = $wpi_session->get( 'user_vat_data' ); |
|
1793 | - $wpi_session->set( 'user_vat_data', null ); |
|
1792 | + $vat_saved = $wpi_session->get('user_vat_data'); |
|
1793 | + $wpi_session->set('user_vat_data', null); |
|
1794 | 1794 | |
1795 | 1795 | $invoice = wpinv_get_invoice_cart(); |
1796 | 1796 | $amount = $invoice->get_total(); |
1797 | - $is_digital = self::invoice_has_digital_rule( $invoice ); |
|
1798 | - $no_vat = !self::requires_vat( 0, false, $is_digital ); |
|
1797 | + $is_digital = self::invoice_has_digital_rule($invoice); |
|
1798 | + $no_vat = !self::requires_vat(0, false, $is_digital); |
|
1799 | 1799 | |
1800 | - $company = !empty( $_POST['wpinv_company'] ) ? $_POST['wpinv_company'] : null; |
|
1801 | - $vat_number = !empty( $_POST['wpinv_vat_number'] ) ? $_POST['wpinv_vat_number'] : null; |
|
1802 | - $country = !empty( $_POST['wpinv_country'] ) ? $_POST['wpinv_country'] : $invoice->country; |
|
1803 | - if ( empty( $country ) ) { |
|
1800 | + $company = !empty($_POST['wpinv_company']) ? $_POST['wpinv_company'] : null; |
|
1801 | + $vat_number = !empty($_POST['wpinv_vat_number']) ? $_POST['wpinv_vat_number'] : null; |
|
1802 | + $country = !empty($_POST['wpinv_country']) ? $_POST['wpinv_country'] : $invoice->country; |
|
1803 | + if (empty($country)) { |
|
1804 | 1804 | $country = wpinv_default_billing_country(); |
1805 | 1805 | } |
1806 | 1806 | |
1807 | - if ( !$is_digital && $no_vat ) { |
|
1807 | + if (!$is_digital && $no_vat) { |
|
1808 | 1808 | return; |
1809 | 1809 | } |
1810 | 1810 | |
1811 | - $vat_data = array( 'company' => '', 'number' => '', 'valid' => false ); |
|
1811 | + $vat_data = array('company' => '', 'number' => '', 'valid' => false); |
|
1812 | 1812 | |
1813 | 1813 | $ip_country_code = self::get_country_by_ip(); |
1814 | - $is_eu_state = self::is_eu_state( $country ); |
|
1815 | - $is_eu_state_ip = self::is_eu_state( $ip_country_code ); |
|
1814 | + $is_eu_state = self::is_eu_state($country); |
|
1815 | + $is_eu_state_ip = self::is_eu_state($ip_country_code); |
|
1816 | 1816 | $is_non_eu_user = !$is_eu_state && !$is_eu_state_ip; |
1817 | 1817 | |
1818 | - if ( $is_digital && !$is_non_eu_user && empty( $vat_number ) && apply_filters( 'wpinv_checkout_requires_country', true, $amount ) ) { |
|
1818 | + if ($is_digital && !$is_non_eu_user && empty($vat_number) && apply_filters('wpinv_checkout_requires_country', true, $amount)) { |
|
1819 | 1819 | $vat_data['adddress_confirmed'] = false; |
1820 | 1820 | |
1821 | - if ( !isset( $_POST['wpinv_adddress_confirmed'] ) ) { |
|
1822 | - if ( $ip_country_code != $country ) { |
|
1823 | - wpinv_set_error( 'vat_validation', sprintf( __( 'The country of your current location must be the same as the country of your billing location or you must %s confirm %s the billing address is your home country.', 'invoicing' ), '<a href="#wpinv_adddress_confirm">', '</a>' ) ); |
|
1821 | + if (!isset($_POST['wpinv_adddress_confirmed'])) { |
|
1822 | + if ($ip_country_code != $country) { |
|
1823 | + wpinv_set_error('vat_validation', sprintf(__('The country of your current location must be the same as the country of your billing location or you must %s confirm %s the billing address is your home country.', 'invoicing'), '<a href="#wpinv_adddress_confirm">', '</a>')); |
|
1824 | 1824 | } |
1825 | 1825 | } else { |
1826 | 1826 | $vat_data['adddress_confirmed'] = true; |
1827 | 1827 | } |
1828 | 1828 | } |
1829 | 1829 | |
1830 | - if ( !empty( $wpinv_options['vat_prevent_b2c_purchase'] ) && !$is_non_eu_user && ( empty( $vat_number ) || $no_vat ) ) { |
|
1831 | - if ( $is_eu_state ) { |
|
1832 | - wpinv_set_error( 'vat_validation', wp_sprintf( __( 'Please enter and validate your %s number to verify your purchase is by an EU business.', 'invoicing' ), $vat_name ) ); |
|
1833 | - } else if ( $is_digital && $is_eu_state_ip ) { |
|
1834 | - wpinv_set_error( 'vat_validation', wp_sprintf( __( 'Sales to non-EU countries cannot be completed because %s must be applied.', 'invoicing' ), $vat_name ) ); |
|
1830 | + if (!empty($wpinv_options['vat_prevent_b2c_purchase']) && !$is_non_eu_user && (empty($vat_number) || $no_vat)) { |
|
1831 | + if ($is_eu_state) { |
|
1832 | + wpinv_set_error('vat_validation', wp_sprintf(__('Please enter and validate your %s number to verify your purchase is by an EU business.', 'invoicing'), $vat_name)); |
|
1833 | + } else if ($is_digital && $is_eu_state_ip) { |
|
1834 | + wpinv_set_error('vat_validation', wp_sprintf(__('Sales to non-EU countries cannot be completed because %s must be applied.', 'invoicing'), $vat_name)); |
|
1835 | 1835 | } |
1836 | 1836 | } |
1837 | 1837 | |
1838 | - if ( !$is_eu_state || $no_vat || empty( $vat_number ) ) { |
|
1838 | + if (!$is_eu_state || $no_vat || empty($vat_number)) { |
|
1839 | 1839 | return; |
1840 | 1840 | } |
1841 | 1841 | |
1842 | - if ( !empty( $vat_saved ) && isset( $vat_saved['valid'] ) ) { |
|
1843 | - $vat_data['valid'] = $vat_saved['valid']; |
|
1842 | + if (!empty($vat_saved) && isset($vat_saved['valid'])) { |
|
1843 | + $vat_data['valid'] = $vat_saved['valid']; |
|
1844 | 1844 | } |
1845 | 1845 | |
1846 | - if ( $company !== null ) { |
|
1846 | + if ($company !== null) { |
|
1847 | 1847 | $vat_data['company'] = $company; |
1848 | 1848 | } |
1849 | 1849 | |
1850 | 1850 | $message = ''; |
1851 | - if ( $vat_number !== null ) { |
|
1851 | + if ($vat_number !== null) { |
|
1852 | 1852 | $vat_data['number'] = $vat_number; |
1853 | 1853 | |
1854 | - if ( !$vat_data['valid'] || ( $vat_saved['number'] !== $vat_data['number'] ) || ( $vat_saved['company'] !== $vat_data['company'] ) ) { |
|
1855 | - if ( !empty( $wpinv_options['vat_vies_check'] ) ) { |
|
1856 | - if ( empty( $wpinv_options['vat_offline_check'] ) && !self::offline_check( $vat_number ) ) { |
|
1854 | + if (!$vat_data['valid'] || ($vat_saved['number'] !== $vat_data['number']) || ($vat_saved['company'] !== $vat_data['company'])) { |
|
1855 | + if (!empty($wpinv_options['vat_vies_check'])) { |
|
1856 | + if (empty($wpinv_options['vat_offline_check']) && !self::offline_check($vat_number)) { |
|
1857 | 1857 | $vat_data['valid'] = false; |
1858 | 1858 | } |
1859 | 1859 | } else { |
1860 | - $result = self::check_vat( $vat_number ); |
|
1860 | + $result = self::check_vat($vat_number); |
|
1861 | 1861 | |
1862 | - if ( !empty( $result['valid'] ) ) { |
|
1862 | + if (!empty($result['valid'])) { |
|
1863 | 1863 | $vat_data['valid'] = true; |
1864 | - $vies_company = !empty( $result['company'] ) ? $result['company'] : ''; |
|
1865 | - $vies_company = apply_filters( 'wpinv_vies_company_name', $vies_company ); |
|
1864 | + $vies_company = !empty($result['company']) ? $result['company'] : ''; |
|
1865 | + $vies_company = apply_filters('wpinv_vies_company_name', $vies_company); |
|
1866 | 1866 | |
1867 | - $valid_company = $vies_company && $company && ( $vies_company == '---' || strcasecmp( trim( $vies_company ), trim( $company ) ) == 0 ) ? true : false; |
|
1867 | + $valid_company = $vies_company && $company && ($vies_company == '---' || strcasecmp(trim($vies_company), trim($company)) == 0) ? true : false; |
|
1868 | 1868 | |
1869 | - if ( !( !empty( $wpinv_options['vat_disable_company_name_check'] ) || $valid_company ) ) { |
|
1869 | + if (!(!empty($wpinv_options['vat_disable_company_name_check']) || $valid_company)) { |
|
1870 | 1870 | $vat_data['valid'] = false; |
1871 | 1871 | |
1872 | - $message = wp_sprintf( __( 'The company name associated with the %s number provided is not the same as the company name provided.', 'invoicing' ), $vat_name ); |
|
1872 | + $message = wp_sprintf(__('The company name associated with the %s number provided is not the same as the company name provided.', 'invoicing'), $vat_name); |
|
1873 | 1873 | } |
1874 | 1874 | } else { |
1875 | - $message = wp_sprintf( __( 'Fail to validate the %s number: EU Commission VAT server (VIES) check fails.', 'invoicing' ), $vat_name ); |
|
1875 | + $message = wp_sprintf(__('Fail to validate the %s number: EU Commission VAT server (VIES) check fails.', 'invoicing'), $vat_name); |
|
1876 | 1876 | } |
1877 | 1877 | } |
1878 | 1878 | |
1879 | - if ( !$vat_data['valid'] ) { |
|
1880 | - $error = wp_sprintf( __( 'The %s %s number %s you have entered has not been validated', 'invoicing' ), '<a href="#wpi-vat-details">', $vat_name, '</a>' ) . ( $message ? ' ( ' . $message . ' )' : '' ); |
|
1881 | - wpinv_set_error( 'vat_validation', $error ); |
|
1879 | + if (!$vat_data['valid']) { |
|
1880 | + $error = wp_sprintf(__('The %s %s number %s you have entered has not been validated', 'invoicing'), '<a href="#wpi-vat-details">', $vat_name, '</a>') . ($message ? ' ( ' . $message . ' )' : ''); |
|
1881 | + wpinv_set_error('vat_validation', $error); |
|
1882 | 1882 | } |
1883 | 1883 | } |
1884 | 1884 | } |
1885 | 1885 | |
1886 | - $wpi_session->set( 'user_vat_data', $vat_data ); |
|
1886 | + $wpi_session->set('user_vat_data', $vat_data); |
|
1887 | 1887 | } |
1888 | 1888 | |
1889 | - public static function checkout_vat_fields( $billing_details ) { |
|
1889 | + public static function checkout_vat_fields($billing_details) { |
|
1890 | 1890 | global $wpi_session, $wpinv_options, $wpi_country, $wpi_requires_vat; |
1891 | 1891 | |
1892 | 1892 | $ip_address = wpinv_get_ip(); |
1893 | 1893 | $ip_country_code = self::get_country_by_ip(); |
1894 | 1894 | |
1895 | - $tax_label = __( self::get_vat_name(), 'invoicing' ); |
|
1895 | + $tax_label = __(self::get_vat_name(), 'invoicing'); |
|
1896 | 1896 | $invoice = wpinv_get_invoice_cart(); |
1897 | - $is_digital = self::invoice_has_digital_rule( $invoice ); |
|
1897 | + $is_digital = self::invoice_has_digital_rule($invoice); |
|
1898 | 1898 | $wpi_country = $invoice->country; |
1899 | 1899 | |
1900 | - $requires_vat = !self::hide_vat_fields() && !$invoice->is_free() && self::requires_vat( 0, false, $is_digital ); |
|
1900 | + $requires_vat = !self::hide_vat_fields() && !$invoice->is_free() && self::requires_vat(0, false, $is_digital); |
|
1901 | 1901 | $wpi_requires_vat = $requires_vat; |
1902 | 1902 | |
1903 | 1903 | $company = self::get_user_company(); |
1904 | 1904 | $vat_number = self::get_user_vat_number(); |
1905 | 1905 | |
1906 | - $validated = $vat_number ? self::get_user_vat_number( '', 0, true ) : 1; |
|
1907 | - $vat_info = $wpi_session->get( 'user_vat_data' ); |
|
1906 | + $validated = $vat_number ? self::get_user_vat_number('', 0, true) : 1; |
|
1907 | + $vat_info = $wpi_session->get('user_vat_data'); |
|
1908 | 1908 | |
1909 | - if ( is_array( $vat_info ) ) { |
|
1910 | - $company = isset( $vat_info['company'] ) ? $vat_info['company'] : ''; |
|
1911 | - $vat_number = isset( $vat_info['number'] ) ? $vat_info['number'] : ''; |
|
1912 | - $validated = isset( $vat_info['valid'] ) ? $vat_info['valid'] : false; |
|
1909 | + if (is_array($vat_info)) { |
|
1910 | + $company = isset($vat_info['company']) ? $vat_info['company'] : ''; |
|
1911 | + $vat_number = isset($vat_info['number']) ? $vat_info['number'] : ''; |
|
1912 | + $validated = isset($vat_info['valid']) ? $vat_info['valid'] : false; |
|
1913 | 1913 | } |
1914 | 1914 | |
1915 | 1915 | $selected_country = $invoice->country ? $invoice->country : wpinv_default_billing_country(); |
1916 | 1916 | |
1917 | - if ( $ip_country_code == 'UK' ) { |
|
1917 | + if ($ip_country_code == 'UK') { |
|
1918 | 1918 | $ip_country_code = 'GB'; |
1919 | 1919 | } |
1920 | 1920 | |
1921 | - if ( $selected_country == 'UK' ) { |
|
1921 | + if ($selected_country == 'UK') { |
|
1922 | 1922 | $selected_country = 'GB'; |
1923 | 1923 | } |
1924 | 1924 | |
1925 | - if ( $requires_vat && ( self::same_country_rule() == 'no' && wpinv_is_base_country( $selected_country ) || !self::allow_vat_rules() ) ) { |
|
1925 | + if ($requires_vat && (self::same_country_rule() == 'no' && wpinv_is_base_country($selected_country) || !self::allow_vat_rules())) { |
|
1926 | 1926 | $requires_vat = false; |
1927 | 1927 | } |
1928 | 1928 | |
@@ -1930,52 +1930,52 @@ discard block |
||
1930 | 1930 | $display_validate_btn = 'none'; |
1931 | 1931 | $display_reset_btn = 'none'; |
1932 | 1932 | |
1933 | - if ( !empty( $vat_number ) && $validated ) { |
|
1934 | - $vat_vailidated_text = wp_sprintf( __( '%s number validated', 'invoicing' ), $tax_label ); |
|
1933 | + if (!empty($vat_number) && $validated) { |
|
1934 | + $vat_vailidated_text = wp_sprintf(__('%s number validated', 'invoicing'), $tax_label); |
|
1935 | 1935 | $vat_vailidated_class = 'wpinv-vat-stat-1'; |
1936 | 1936 | $display_reset_btn = 'block'; |
1937 | 1937 | } else { |
1938 | - $vat_vailidated_text = empty( $vat_number ) ? '' : wp_sprintf( __( '%s number not validated', 'invoicing' ), $tax_label ); |
|
1939 | - $vat_vailidated_class = empty( $vat_number ) ? '' : 'wpinv-vat-stat-0'; |
|
1938 | + $vat_vailidated_text = empty($vat_number) ? '' : wp_sprintf(__('%s number not validated', 'invoicing'), $tax_label); |
|
1939 | + $vat_vailidated_class = empty($vat_number) ? '' : 'wpinv-vat-stat-0'; |
|
1940 | 1940 | $display_validate_btn = 'block'; |
1941 | 1941 | } |
1942 | 1942 | |
1943 | - $show_ip_country = $is_digital && ( empty( $vat_number ) || !$requires_vat ) && $ip_country_code != $selected_country ? 'block' : 'none'; |
|
1943 | + $show_ip_country = $is_digital && (empty($vat_number) || !$requires_vat) && $ip_country_code != $selected_country ? 'block' : 'none'; |
|
1944 | 1944 | ?> |
1945 | 1945 | <div id="wpi-vat-details" class="wpi-vat-details clearfix" style="display:<?php echo $display_vat_details; ?>"> |
1946 | 1946 | <div id="wpi_vat_info" class="clearfix panel panel-default"> |
1947 | - <div class="panel-heading"><h3 class="panel-title"><?php echo wp_sprintf( __( '%s Details', 'invoicing' ), $tax_label );?></h3></div> |
|
1947 | + <div class="panel-heading"><h3 class="panel-title"><?php echo wp_sprintf(__('%s Details', 'invoicing'), $tax_label); ?></h3></div> |
|
1948 | 1948 | <div id="wpinv-fields-box" class="panel-body"> |
1949 | 1949 | <p id="wpi_show_vat_note"> |
1950 | - <?php echo wp_sprintf( __( 'Validate your registered %s number to exclude tax.', 'invoicing' ), $tax_label ); ?> |
|
1950 | + <?php echo wp_sprintf(__('Validate your registered %s number to exclude tax.', 'invoicing'), $tax_label); ?> |
|
1951 | 1951 | </p> |
1952 | 1952 | <div id="wpi_vat_fields" class="wpi_vat_info"> |
1953 | 1953 | <p class="wpi-cart-field wpi-col2 wpi-colf"> |
1954 | - <label for="wpinv_company" class="wpi-label"><?php _e( 'Company Name', 'invoicing' );?></label> |
|
1954 | + <label for="wpinv_company" class="wpi-label"><?php _e('Company Name', 'invoicing'); ?></label> |
|
1955 | 1955 | <?php |
1956 | - echo wpinv_html_text( array( |
|
1956 | + echo wpinv_html_text(array( |
|
1957 | 1957 | 'id' => 'wpinv_company', |
1958 | 1958 | 'name' => 'wpinv_company', |
1959 | 1959 | 'value' => $company, |
1960 | 1960 | 'class' => 'wpi-input form-control', |
1961 | - 'placeholder' => __( 'Company name', 'invoicing' ), |
|
1962 | - ) ); |
|
1961 | + 'placeholder' => __('Company name', 'invoicing'), |
|
1962 | + )); |
|
1963 | 1963 | ?> |
1964 | 1964 | </p> |
1965 | 1965 | <p class="wpi-cart-field wpi-col2 wpi-coll wpi-cart-field-vat"> |
1966 | - <label for="wpinv_vat_number" class="wpi-label"><?php echo wp_sprintf( __( '%s Number', 'invoicing' ), $tax_label );?></label> |
|
1966 | + <label for="wpinv_vat_number" class="wpi-label"><?php echo wp_sprintf(__('%s Number', 'invoicing'), $tax_label); ?></label> |
|
1967 | 1967 | <span id="wpinv_vat_number-wrap"> |
1968 | 1968 | <label for="wpinv_vat_number" class="wpinv-label"></label> |
1969 | - <input type="text" class="wpi-input form-control" placeholder="<?php echo esc_attr( wp_sprintf( __( '%s number', 'invoicing' ), $tax_label ) );?>" value="<?php esc_attr_e( $vat_number );?>" id="wpinv_vat_number" name="wpinv_vat_number"> |
|
1970 | - <span class="wpinv-vat-stat <?php echo $vat_vailidated_class;?>"><i class="fa"></i> <font><?php echo $vat_vailidated_text;?></font></span> |
|
1969 | + <input type="text" class="wpi-input form-control" placeholder="<?php echo esc_attr(wp_sprintf(__('%s number', 'invoicing'), $tax_label)); ?>" value="<?php esc_attr_e($vat_number); ?>" id="wpinv_vat_number" name="wpinv_vat_number"> |
|
1970 | + <span class="wpinv-vat-stat <?php echo $vat_vailidated_class; ?>"><i class="fa"></i> <font><?php echo $vat_vailidated_text; ?></font></span> |
|
1971 | 1971 | </span> |
1972 | 1972 | </p> |
1973 | 1973 | <p class="wpi-cart-field wpi-col wpi-colf wpi-cart-field-actions"> |
1974 | - <button class="btn btn-success btn-sm wpinv-vat-validate" type="button" id="wpinv_vat_validate" style="display:<?php echo $display_validate_btn; ?>"><?php echo wp_sprintf( __("Validate %s Number", 'invoicing'), $tax_label ); ?></button> |
|
1975 | - <button class="btn btn-danger btn-sm wpinv-vat-reset" type="button" id="wpinv_vat_reset" style="display:<?php echo $display_reset_btn; ?>"><?php echo wp_sprintf( __("Reset %s", 'invoicing'), $tax_label ); ?></button> |
|
1974 | + <button class="btn btn-success btn-sm wpinv-vat-validate" type="button" id="wpinv_vat_validate" style="display:<?php echo $display_validate_btn; ?>"><?php echo wp_sprintf(__("Validate %s Number", 'invoicing'), $tax_label); ?></button> |
|
1975 | + <button class="btn btn-danger btn-sm wpinv-vat-reset" type="button" id="wpinv_vat_reset" style="display:<?php echo $display_reset_btn; ?>"><?php echo wp_sprintf(__("Reset %s", 'invoicing'), $tax_label); ?></button> |
|
1976 | 1976 | <span class="wpi-vat-box wpi-vat-box-info"><span id="text"></span></span> |
1977 | 1977 | <span class="wpi-vat-box wpi-vat-box-error"><span id="text"></span></span> |
1978 | - <input type="hidden" name="_wpi_nonce" value="<?php echo wp_create_nonce( 'vat_validation' ) ?>" /> |
|
1978 | + <input type="hidden" name="_wpi_nonce" value="<?php echo wp_create_nonce('vat_validation') ?>" /> |
|
1979 | 1979 | </p> |
1980 | 1980 | </div> |
1981 | 1981 | </div> |
@@ -1989,32 +1989,32 @@ discard block |
||
1989 | 1989 | </span> |
1990 | 1990 | </div> |
1991 | 1991 | </div> |
1992 | - <?php if ( empty( $wpinv_options['hide_ip_address'] ) ) { |
|
1993 | - $ip_link = '<a title="' . esc_attr( __( 'View more details on map', 'invoicing' ) ) . '" target="_blank" href="' . esc_url( admin_url( 'admin-ajax.php?action=wpinv_ip_geolocation&ip=' . $ip_address ) ) . '" class="wpi-ip-address-link">' . $ip_address . ' <i class="fa fa-external-link-square" aria-hidden="true"></i></a>'; |
|
1992 | + <?php if (empty($wpinv_options['hide_ip_address'])) { |
|
1993 | + $ip_link = '<a title="' . esc_attr(__('View more details on map', 'invoicing')) . '" target="_blank" href="' . esc_url(admin_url('admin-ajax.php?action=wpinv_ip_geolocation&ip=' . $ip_address)) . '" class="wpi-ip-address-link">' . $ip_address . ' <i class="fa fa-external-link-square" aria-hidden="true"></i></a>'; |
|
1994 | 1994 | ?> |
1995 | 1995 | <div class="wpi-ip-info clearfix panel panel-info"> |
1996 | 1996 | <div id="wpinv-fields-box" class="panel-body"> |
1997 | - <span><?php echo wp_sprintf( __( "Your IP address is: %s", 'invoicing' ), $ip_link ); ?></span> |
|
1997 | + <span><?php echo wp_sprintf(__("Your IP address is: %s", 'invoicing'), $ip_link); ?></span> |
|
1998 | 1998 | </div> |
1999 | 1999 | </div> |
2000 | 2000 | <?php } |
2001 | 2001 | } |
2002 | 2002 | |
2003 | - public static function show_vat_notice( $invoice ) { |
|
2004 | - if ( empty( $invoice ) ) { |
|
2003 | + public static function show_vat_notice($invoice) { |
|
2004 | + if (empty($invoice)) { |
|
2005 | 2005 | return NULL; |
2006 | 2006 | } |
2007 | 2007 | |
2008 | - $label = wpinv_get_option( 'vat_invoice_notice_label' ); |
|
2009 | - $notice = wpinv_get_option( 'vat_invoice_notice' ); |
|
2010 | - if ( $label || $notice ) { |
|
2008 | + $label = wpinv_get_option('vat_invoice_notice_label'); |
|
2009 | + $notice = wpinv_get_option('vat_invoice_notice'); |
|
2010 | + if ($label || $notice) { |
|
2011 | 2011 | ?> |
2012 | 2012 | <div class="row wpinv-vat-notice"> |
2013 | 2013 | <div class="col-sm-12"> |
2014 | - <?php if ( $label ) { ?> |
|
2015 | - <strong><?php _e( $label, 'invoicing' ); ?></strong> |
|
2016 | - <?php } if ( $notice ) { ?> |
|
2017 | - <?php echo wpautop( wptexturize( __( $notice, 'invoicing' ) ) ) ?> |
|
2014 | + <?php if ($label) { ?> |
|
2015 | + <strong><?php _e($label, 'invoicing'); ?></strong> |
|
2016 | + <?php } if ($notice) { ?> |
|
2017 | + <?php echo wpautop(wptexturize(__($notice, 'invoicing'))) ?> |
|
2018 | 2018 | <?php } ?> |
2019 | 2019 | </div> |
2020 | 2020 | </div> |