@@ -101,7 +101,7 @@ discard block |
||
| 101 | 101 | * @param string $card_num The credit card number |
| 102 | 102 | * @param string $exp_date CC expiration date |
| 103 | 103 | * |
| 104 | - * @return AuthorizeNetAIM_Response |
|
| 104 | + * @return AuthorizeNetARB_Response |
|
| 105 | 105 | */ |
| 106 | 106 | public function authorizeAndCapture($amount = false, $card_num = false, $exp_date = false) |
| 107 | 107 | { |
@@ -122,7 +122,7 @@ discard block |
||
| 122 | 122 | * @param string $trans_id Transaction id to charge |
| 123 | 123 | * @param string $amount Dollar amount to charge if lesser than auth |
| 124 | 124 | * |
| 125 | - * @return AuthorizeNetAIM_Response |
|
| 125 | + * @return AuthorizeNetARB_Response |
|
| 126 | 126 | */ |
| 127 | 127 | public function priorAuthCapture($trans_id = false, $amount = false) |
| 128 | 128 | { |
@@ -141,7 +141,7 @@ discard block |
||
| 141 | 141 | * @param string $card_num The credit card number |
| 142 | 142 | * @param string $exp_date CC expiration date |
| 143 | 143 | * |
| 144 | - * @return AuthorizeNetAIM_Response |
|
| 144 | + * @return AuthorizeNetARB_Response |
|
| 145 | 145 | */ |
| 146 | 146 | public function authorizeOnly($amount = false, $card_num = false, $exp_date = false) |
| 147 | 147 | { |
@@ -160,7 +160,7 @@ discard block |
||
| 160 | 160 | * |
| 161 | 161 | * @param string $trans_id Transaction id to void |
| 162 | 162 | * |
| 163 | - * @return AuthorizeNetAIM_Response |
|
| 163 | + * @return AuthorizeNetARB_Response |
|
| 164 | 164 | */ |
| 165 | 165 | public function void($trans_id = false) |
| 166 | 166 | { |
@@ -179,7 +179,7 @@ discard block |
||
| 179 | 179 | * @param string $card_num The last 4 of credit card number |
| 180 | 180 | * @param string $exp_date CC expiration date |
| 181 | 181 | * |
| 182 | - * @return AuthorizeNetAIM_Response |
|
| 182 | + * @return AuthorizeNetARB_Response |
|
| 183 | 183 | */ |
| 184 | 184 | public function captureOnly($auth_code = false, $amount = false, $card_num = false, $exp_date = false) |
| 185 | 185 | { |
@@ -200,7 +200,7 @@ discard block |
||
| 200 | 200 | * @param string $amount The dollar amount to credit |
| 201 | 201 | * @param string $card_num The last 4 of credit card number |
| 202 | 202 | * |
| 203 | - * @return AuthorizeNetAIM_Response |
|
| 203 | + * @return AuthorizeNetARB_Response |
|
| 204 | 204 | */ |
| 205 | 205 | public function credit($trans_id = false, $amount = false, $card_num = false) |
| 206 | 206 | { |
@@ -77,19 +77,19 @@ discard block |
||
| 77 | 77 | * A list of all fields in the AIM API. |
| 78 | 78 | * Used to warn user if they try to set a field not offered in the API. |
| 79 | 79 | */ |
| 80 | - private $_all_aim_fields = array("address","allow_partial_auth","amount", |
|
| 81 | - "auth_code","authentication_indicator", "bank_aba_code","bank_acct_name", |
|
| 82 | - "bank_acct_num","bank_acct_type","bank_check_number","bank_name", |
|
| 83 | - "card_code","card_num","cardholder_authentication_value","city","company", |
|
| 84 | - "country","cust_id","customer_ip","delim_char","delim_data","description", |
|
| 85 | - "duplicate_window","duty","echeck_type","email","email_customer", |
|
| 86 | - "encap_char","exp_date","fax","first_name","footer_email_receipt", |
|
| 87 | - "freight","header_email_receipt","invoice_num","last_name","line_item", |
|
| 88 | - "login","method","phone","po_num","recurring_billing","relay_response", |
|
| 89 | - "ship_to_address","ship_to_city","ship_to_company","ship_to_country", |
|
| 90 | - "ship_to_first_name","ship_to_last_name","ship_to_state","ship_to_zip", |
|
| 91 | - "split_tender_id","state","tax","tax_exempt","test_request","tran_key", |
|
| 92 | - "trans_id","type","version","zip" |
|
| 80 | + private $_all_aim_fields = array("address", "allow_partial_auth", "amount", |
|
| 81 | + "auth_code", "authentication_indicator", "bank_aba_code", "bank_acct_name", |
|
| 82 | + "bank_acct_num", "bank_acct_type", "bank_check_number", "bank_name", |
|
| 83 | + "card_code", "card_num", "cardholder_authentication_value", "city", "company", |
|
| 84 | + "country", "cust_id", "customer_ip", "delim_char", "delim_data", "description", |
|
| 85 | + "duplicate_window", "duty", "echeck_type", "email", "email_customer", |
|
| 86 | + "encap_char", "exp_date", "fax", "first_name", "footer_email_receipt", |
|
| 87 | + "freight", "header_email_receipt", "invoice_num", "last_name", "line_item", |
|
| 88 | + "login", "method", "phone", "po_num", "recurring_billing", "relay_response", |
|
| 89 | + "ship_to_address", "ship_to_city", "ship_to_company", "ship_to_country", |
|
| 90 | + "ship_to_first_name", "ship_to_last_name", "ship_to_state", "ship_to_zip", |
|
| 91 | + "split_tender_id", "state", "tax", "tax_exempt", "test_request", "tran_key", |
|
| 92 | + "trans_id", "type", "version", "zip" |
|
| 93 | 93 | ); |
| 94 | 94 | |
| 95 | 95 | /** |
@@ -403,7 +403,7 @@ discard block |
||
| 403 | 403 | // Split Array |
| 404 | 404 | $this->response = $response; |
| 405 | 405 | if ($encap_char) { |
| 406 | - $this->_response_array = explode($encap_char.$delimiter.$encap_char, substr($response, 1, -1)); |
|
| 406 | + $this->_response_array = explode($encap_char . $delimiter . $encap_char, substr($response, 1, -1)); |
|
| 407 | 407 | } else { |
| 408 | 408 | $this->_response_array = explode($delimiter, $response); |
| 409 | 409 | } |
@@ -457,7 +457,7 @@ discard block |
||
| 457 | 457 | $this->duty = $this->_response_array[33]; |
| 458 | 458 | $this->freight = $this->_response_array[34]; |
| 459 | 459 | $this->tax_exempt = $this->_response_array[35]; |
| 460 | - $this->purchase_order_number= $this->_response_array[36]; |
|
| 460 | + $this->purchase_order_number = $this->_response_array[36]; |
|
| 461 | 461 | $this->md5_hash = $this->_response_array[37]; |
| 462 | 462 | $this->card_code_response = $this->_response_array[38]; |
| 463 | 463 | $this->cavv_response = $this->_response_array[39]; |
@@ -484,10 +484,10 @@ discard block |
||
| 484 | 484 | |
| 485 | 485 | if ($this->error) { |
| 486 | 486 | $this->error_message = "AuthorizeNet Error: |
| 487 | - Response Code: ".$this->response_code." |
|
| 488 | - Response Subcode: ".$this->response_subcode." |
|
| 489 | - Response Reason Code: ".$this->response_reason_code." |
|
| 490 | - Response Reason Text: ".$this->response_reason_text." |
|
| 487 | + Response Code: ".$this->response_code . " |
|
| 488 | + Response Subcode: ".$this->response_subcode . " |
|
| 489 | + Response Reason Code: ".$this->response_reason_code . " |
|
| 490 | + Response Reason Text: ".$this->response_reason_text . " |
|
| 491 | 491 | "; |
| 492 | 492 | } |
| 493 | 493 | } else { |
@@ -51,7 +51,7 @@ discard block |
||
| 51 | 51 | * @param AuthorizeNetCustomer $customerProfile |
| 52 | 52 | * @param string $validationMode |
| 53 | 53 | * |
| 54 | - * @return AuthorizeNetCIM_Response |
|
| 54 | + * @return AuthorizeNetARB_Response |
|
| 55 | 55 | */ |
| 56 | 56 | public function createCustomerProfile($customerProfile, $validationMode = "none") |
| 57 | 57 | { |
@@ -69,7 +69,7 @@ discard block |
||
| 69 | 69 | * @param AuthorizeNetPaymentProfile $paymentProfile |
| 70 | 70 | * @param string $validationMode |
| 71 | 71 | * |
| 72 | - * @return AuthorizeNetCIM_Response |
|
| 72 | + * @return AuthorizeNetARB_Response |
|
| 73 | 73 | */ |
| 74 | 74 | public function createCustomerPaymentProfile($customerProfileId, $paymentProfile, $validationMode = "none") |
| 75 | 75 | { |
@@ -87,7 +87,7 @@ discard block |
||
| 87 | 87 | * @param int $customerProfileId |
| 88 | 88 | * @param AuthorizeNetAddress $shippingAddress |
| 89 | 89 | * |
| 90 | - * @return AuthorizeNetCIM_Response |
|
| 90 | + * @return AuthorizeNetARB_Response |
|
| 91 | 91 | */ |
| 92 | 92 | public function createCustomerShippingAddress($customerProfileId, $shippingAddress) |
| 93 | 93 | { |
@@ -105,7 +105,7 @@ discard block |
||
| 105 | 105 | * @param AuthorizeNetTransaction $transaction |
| 106 | 106 | * @param string $extraOptionsString |
| 107 | 107 | * |
| 108 | - * @return AuthorizeNetCIM_Response |
|
| 108 | + * @return AuthorizeNetARB_Response |
|
| 109 | 109 | */ |
| 110 | 110 | public function createCustomerProfileTransaction($transactionType, $transaction, $extraOptionsString = "") |
| 111 | 111 | { |
@@ -122,7 +122,7 @@ discard block |
||
| 122 | 122 | * |
| 123 | 123 | * @param int $customerProfileId |
| 124 | 124 | * |
| 125 | - * @return AuthorizeNetCIM_Response |
|
| 125 | + * @return AuthorizeNetARB_Response |
|
| 126 | 126 | */ |
| 127 | 127 | public function deleteCustomerProfile($customerProfileId) |
| 128 | 128 | { |
@@ -137,7 +137,7 @@ discard block |
||
| 137 | 137 | * @param int $customerProfileId |
| 138 | 138 | * @param int $customerPaymentProfileId |
| 139 | 139 | * |
| 140 | - * @return AuthorizeNetCIM_Response |
|
| 140 | + * @return AuthorizeNetARB_Response |
|
| 141 | 141 | */ |
| 142 | 142 | public function deleteCustomerPaymentProfile($customerProfileId, $customerPaymentProfileId) |
| 143 | 143 | { |
@@ -153,7 +153,7 @@ discard block |
||
| 153 | 153 | * @param int $customerProfileId |
| 154 | 154 | * @param int $customerAddressId |
| 155 | 155 | * |
| 156 | - * @return AuthorizeNetCIM_Response |
|
| 156 | + * @return AuthorizeNetARB_Response |
|
| 157 | 157 | */ |
| 158 | 158 | public function deleteCustomerShippingAddress($customerProfileId, $customerAddressId) |
| 159 | 159 | { |
@@ -166,7 +166,7 @@ discard block |
||
| 166 | 166 | /** |
| 167 | 167 | * Get all customer profile ids. |
| 168 | 168 | * |
| 169 | - * @return AuthorizeNetCIM_Response |
|
| 169 | + * @return AuthorizeNetARB_Response |
|
| 170 | 170 | */ |
| 171 | 171 | public function getCustomerProfileIds() |
| 172 | 172 | { |
@@ -179,7 +179,7 @@ discard block |
||
| 179 | 179 | * |
| 180 | 180 | * @param int $customerProfileId |
| 181 | 181 | * |
| 182 | - * @return AuthorizeNetCIM_Response |
|
| 182 | + * @return AuthorizeNetARB_Response |
|
| 183 | 183 | */ |
| 184 | 184 | public function getCustomerProfile($customerProfileId) |
| 185 | 185 | { |
@@ -194,7 +194,7 @@ discard block |
||
| 194 | 194 | * @param int $customerProfileId |
| 195 | 195 | * @param int $customerPaymentProfileId |
| 196 | 196 | * |
| 197 | - * @return AuthorizeNetCIM_Response |
|
| 197 | + * @return AuthorizeNetARB_Response |
|
| 198 | 198 | */ |
| 199 | 199 | public function getCustomerPaymentProfile($customerProfileId, $customerPaymentProfileId) |
| 200 | 200 | { |
@@ -210,7 +210,7 @@ discard block |
||
| 210 | 210 | * @param int $customerProfileId |
| 211 | 211 | * @param int $customerAddressId |
| 212 | 212 | * |
| 213 | - * @return AuthorizeNetCIM_Response |
|
| 213 | + * @return AuthorizeNetARB_Response |
|
| 214 | 214 | */ |
| 215 | 215 | public function getCustomerShippingAddress($customerProfileId, $customerAddressId) |
| 216 | 216 | { |
@@ -226,7 +226,7 @@ discard block |
||
| 226 | 226 | * @param int $customerProfileId |
| 227 | 227 | * @param AuthorizeNetCustomer $customerProfile |
| 228 | 228 | * |
| 229 | - * @return AuthorizeNetCIM_Response |
|
| 229 | + * @return AuthorizeNetARB_Response |
|
| 230 | 230 | */ |
| 231 | 231 | public function updateCustomerProfile($customerProfileId, $customerProfile) |
| 232 | 232 | { |
@@ -245,7 +245,7 @@ discard block |
||
| 245 | 245 | * @param AuthorizeNetPaymentProfile $paymentProfile |
| 246 | 246 | * @param string $validationMode |
| 247 | 247 | * |
| 248 | - * @return AuthorizeNetCIM_Response |
|
| 248 | + * @return AuthorizeNetARB_Response |
|
| 249 | 249 | */ |
| 250 | 250 | public function updateCustomerPaymentProfile($customerProfileId, $customerPaymentProfileId, $paymentProfile, $validationMode = "none") |
| 251 | 251 | { |
@@ -265,7 +265,7 @@ discard block |
||
| 265 | 265 | * @param int $customerShippingAddressId |
| 266 | 266 | * @param AuthorizeNetAddress $shippingAddress |
| 267 | 267 | * |
| 268 | - * @return AuthorizeNetCIM_Response |
|
| 268 | + * @return AuthorizeNetARB_Response |
|
| 269 | 269 | */ |
| 270 | 270 | public function updateCustomerShippingAddress($customerProfileId, $customerShippingAddressId, $shippingAddress) |
| 271 | 271 | { |
@@ -284,7 +284,7 @@ discard block |
||
| 284 | 284 | * @param int $splitTenderId |
| 285 | 285 | * @param string $splitTenderStatus |
| 286 | 286 | * |
| 287 | - * @return AuthorizeNetCIM_Response |
|
| 287 | + * @return AuthorizeNetARB_Response |
|
| 288 | 288 | */ |
| 289 | 289 | public function updateSplitTenderGroup($splitTenderId, $splitTenderStatus) |
| 290 | 290 | { |
@@ -303,7 +303,7 @@ discard block |
||
| 303 | 303 | * @param int $cardCode |
| 304 | 304 | * @param string $validationMode |
| 305 | 305 | * |
| 306 | - * @return AuthorizeNetCIM_Response |
|
| 306 | + * @return AuthorizeNetARB_Response |
|
| 307 | 307 | */ |
| 308 | 308 | public function validateCustomerPaymentProfile($customerProfileId, $customerPaymentProfileId, $customerShippingAddressId, $cardCode, $validationMode = "testMode") |
| 309 | 309 | { |
@@ -316,9 +316,9 @@ |
||
| 316 | 316 | return $this->_sendRequest(); |
| 317 | 317 | } |
| 318 | 318 | |
| 319 | - /** |
|
| 320 | - * @return string |
|
| 321 | - */ |
|
| 319 | + /** |
|
| 320 | + * @return string |
|
| 321 | + */ |
|
| 322 | 322 | protected function _getPostUrl() |
| 323 | 323 | { |
| 324 | 324 | return ($this->_sandbox ? self::SANDBOX_URL : self::LIVE_URL); |
@@ -309,10 +309,10 @@ discard block |
||
| 309 | 309 | { |
| 310 | 310 | $this->_validationMode = $validationMode; |
| 311 | 311 | $this->_constructXml("validateCustomerPaymentProfileRequest"); |
| 312 | - $this->_xml->addChild("customerProfileId",$customerProfileId); |
|
| 313 | - $this->_xml->addChild("customerPaymentProfileId",$customerPaymentProfileId); |
|
| 314 | - $this->_xml->addChild("customerShippingAddressId",$customerShippingAddressId); |
|
| 315 | - $this->_xml->addChild("cardCode",$cardCode); |
|
| 312 | + $this->_xml->addChild("customerProfileId", $customerProfileId); |
|
| 313 | + $this->_xml->addChild("customerPaymentProfileId", $customerPaymentProfileId); |
|
| 314 | + $this->_xml->addChild("customerShippingAddressId", $customerShippingAddressId); |
|
| 315 | + $this->_xml->addChild("cardCode", $cardCode); |
|
| 316 | 316 | return $this->_sendRequest(); |
| 317 | 317 | } |
| 318 | 318 | |
@@ -341,13 +341,13 @@ discard block |
||
| 341 | 341 | */ |
| 342 | 342 | protected function _setPostString() |
| 343 | 343 | { |
| 344 | - ($this->_validationMode != "none" ? $this->_xml->addChild('validationMode',$this->_validationMode) : ""); |
|
| 344 | + ($this->_validationMode != "none" ? $this->_xml->addChild('validationMode', $this->_validationMode) : ""); |
|
| 345 | 345 | $this->_post_string = $this->_xml->asXML(); |
| 346 | 346 | |
| 347 | 347 | // Add extraOptions CDATA |
| 348 | 348 | if ($this->_extraOptions) { |
| 349 | 349 | $this->_xml->addChild("extraOptions"); |
| 350 | - $this->_post_string = str_replace("<extraOptions></extraOptions>",'<extraOptions><![CDATA[' . $this->_extraOptions . ']]></extraOptions>', $this->_xml->asXML()); |
|
| 350 | + $this->_post_string = str_replace("<extraOptions></extraOptions>", '<extraOptions><![CDATA[' . $this->_extraOptions . ']]></extraOptions>', $this->_xml->asXML()); |
|
| 351 | 351 | $this->_extraOptions = false; |
| 352 | 352 | } |
| 353 | 353 | // Blank out our validation mode, so that we don't include it in calls that |
@@ -362,12 +362,12 @@ discard block |
||
| 362 | 362 | */ |
| 363 | 363 | private function _constructXml($request_type) |
| 364 | 364 | { |
| 365 | - $string = '<?xml version="1.0" encoding="utf-8"?><'.$request_type.' xmlns="AnetApi/xml/v1/schema/AnetApiSchema.xsd"></'.$request_type.'>'; |
|
| 365 | + $string = '<?xml version="1.0" encoding="utf-8"?><' . $request_type . ' xmlns="AnetApi/xml/v1/schema/AnetApiSchema.xsd"></' . $request_type . '>'; |
|
| 366 | 366 | $this->_xml = @new SimpleXMLElement($string); |
| 367 | 367 | $merchant = $this->_xml->addChild('merchantAuthentication'); |
| 368 | - $merchant->addChild('name',$this->_api_login); |
|
| 369 | - $merchant->addChild('transactionKey',$this->_transaction_key); |
|
| 370 | - ($this->_refId ? $this->_xml->addChild('refId',$this->_refId) : ""); |
|
| 368 | + $merchant->addChild('name', $this->_api_login); |
|
| 369 | + $merchant->addChild('transactionKey', $this->_transaction_key); |
|
| 370 | + ($this->_refId ? $this->_xml->addChild('refId', $this->_refId) : ""); |
|
| 371 | 371 | } |
| 372 | 372 | |
| 373 | 373 | /** |
@@ -387,7 +387,7 @@ discard block |
||
| 387 | 387 | $this->_addObject($items, $item); |
| 388 | 388 | } |
| 389 | 389 | } else { |
| 390 | - $destination->addChild($key,$value); |
|
| 390 | + $destination->addChild($key, $value); |
|
| 391 | 391 | } |
| 392 | 392 | } elseif (is_object($value) && self::_notEmpty($value)) { |
| 393 | 393 | $dest = $destination->addChild($key); |
@@ -79,7 +79,7 @@ |
||
| 79 | 79 | * |
| 80 | 80 | * @param string $response |
| 81 | 81 | * |
| 82 | - * @return AuthorizeNetAIM_Response |
|
| 82 | + * @return AuthorizeNetCP_Response |
|
| 83 | 83 | */ |
| 84 | 84 | protected function _handleResponse($response) |
| 85 | 85 | { |
@@ -116,7 +116,7 @@ discard block |
||
| 116 | 116 | |
| 117 | 117 | $this->xml = @simplexml_load_string($response); |
| 118 | 118 | // Set all fields |
| 119 | - $this->version = array_pop(array_slice(explode('"', $response), 1,1)); |
|
| 119 | + $this->version = array_pop(array_slice(explode('"', $response), 1, 1)); |
|
| 120 | 120 | $this->response_code = (string)$this->xml->ResponseCode; |
| 121 | 121 | |
| 122 | 122 | if ($this->response_code == 1) { |
@@ -144,7 +144,7 @@ discard block |
||
| 144 | 144 | // Split Array |
| 145 | 145 | $this->response = $response; |
| 146 | 146 | if ($encap_char) { |
| 147 | - $this->_response_array = explode($encap_char.$delimiter.$encap_char, substr($response, 1, -1)); |
|
| 147 | + $this->_response_array = explode($encap_char . $delimiter . $encap_char, substr($response, 1, -1)); |
|
| 148 | 148 | } else { |
| 149 | 149 | $this->_response_array = explode($delimiter, $response); |
| 150 | 150 | } |
@@ -190,9 +190,9 @@ discard block |
||
| 190 | 190 | |
| 191 | 191 | if ($this->error) { |
| 192 | 192 | $this->error_message = "AuthorizeNet Error: |
| 193 | - Response Code: ".$this->response_code." |
|
| 194 | - Response Reason Code: ".$this->response_reason_code." |
|
| 195 | - Response Reason Text: ".$this->response_reason_text." |
|
| 193 | + Response Code: ".$this->response_code . " |
|
| 194 | + Response Reason Code: ".$this->response_reason_code . " |
|
| 195 | + Response Reason Text: ".$this->response_reason_text . " |
|
| 196 | 196 | "; |
| 197 | 197 | } |
| 198 | 198 | |
@@ -28,6 +28,7 @@ |
||
| 28 | 28 | /** |
| 29 | 29 | * Get the post url. We need this because until 5.3 you |
| 30 | 30 | * you could not access child constants in a parent class. |
| 31 | + * @return string|null |
|
| 31 | 32 | */ |
| 32 | 33 | abstract protected function _getPostUrl(); |
| 33 | 34 | |
@@ -96,7 +96,7 @@ |
||
| 96 | 96 | curl_setopt($curl_request, CURLOPT_SSL_VERIFYPEER, false); |
| 97 | 97 | } |
| 98 | 98 | |
| 99 | - if (preg_match('/xml/',$post_url)) { |
|
| 99 | + if (preg_match('/xml/', $post_url)) { |
|
| 100 | 100 | curl_setopt($curl_request, CURLOPT_HTTPHEADER, Array("Content-Type: text/xml")); |
| 101 | 101 | } |
| 102 | 102 | |
@@ -110,6 +110,7 @@ |
||
| 110 | 110 | * Grabs the contents of a unique element. |
| 111 | 111 | * |
| 112 | 112 | * @param string |
| 113 | + * @param string $elementName |
|
| 113 | 114 | * @return string |
| 114 | 115 | */ |
| 115 | 116 | protected function _getElementContents($elementName) |
@@ -29,7 +29,7 @@ discard block |
||
| 29 | 29 | $this->xml = @simplexml_load_string($response); |
| 30 | 30 | |
| 31 | 31 | // Remove namespaces for use with XPath. |
| 32 | - $this->xpath_xml = @simplexml_load_string(preg_replace('/ xmlns:xsi[^>]+/','',$response)); |
|
| 32 | + $this->xpath_xml = @simplexml_load_string(preg_replace('/ xmlns:xsi[^>]+/', '', $response)); |
|
| 33 | 33 | } |
| 34 | 34 | } |
| 35 | 35 | |
@@ -116,12 +116,12 @@ discard block |
||
| 116 | 116 | { |
| 117 | 117 | $start = "<$elementName>"; |
| 118 | 118 | $end = "</$elementName>"; |
| 119 | - if (strpos($this->response,$start) === false || strpos($this->response,$end) === false) { |
|
| 119 | + if (strpos($this->response, $start) === false || strpos($this->response, $end) === false) { |
|
| 120 | 120 | return false; |
| 121 | 121 | } else { |
| 122 | - $start_position = strpos($this->response, $start)+strlen($start); |
|
| 122 | + $start_position = strpos($this->response, $start) + strlen($start); |
|
| 123 | 123 | $end_position = strpos($this->response, $end); |
| 124 | - return substr($this->response, $start_position, $end_position-$start_position); |
|
| 124 | + return substr($this->response, $start_position, $end_position - $start_position); |
|
| 125 | 125 | } |
| 126 | 126 | } |
| 127 | 127 | |
@@ -69,6 +69,7 @@ discard block |
||
| 69 | 69 | * remove XML response namespaces |
| 70 | 70 | * without this php will spit out warinings |
| 71 | 71 | * @see http://community.developer.authorize.net/t5/Integration-and-Testing/ARB-with-SimpleXML-PHP-Issue/m-p/7128#M5139 |
| 72 | + * @return string |
|
| 72 | 73 | */ |
| 73 | 74 | private function removeResponseXMLNS($input) |
| 74 | 75 | { |
@@ -150,6 +151,9 @@ discard block |
||
| 150 | 151 | $this->process(); |
| 151 | 152 | } |
| 152 | 153 | |
| 154 | + /** |
|
| 155 | + * @param SimpleXMLElement $xml |
|
| 156 | + */ |
|
| 153 | 157 | private function setParameters($xml, $array) |
| 154 | 158 | { |
| 155 | 159 | if (is_array($array)) |
@@ -40,7 +40,7 @@ discard block |
||
| 40 | 40 | const EXCEPTION_CURL = 10; |
| 41 | 41 | |
| 42 | 42 | private $ch; |
| 43 | - private $login; |
|
| 43 | + private $login; |
|
| 44 | 44 | private $response; |
| 45 | 45 | private $response_xml; |
| 46 | 46 | private $results; |
@@ -48,9 +48,9 @@ discard block |
||
| 48 | 48 | private $url; |
| 49 | 49 | private $xml; |
| 50 | 50 | |
| 51 | - public function __construct($login, $transkey, $test = self::USE_PRODUCTION_SERVER) |
|
| 52 | - { |
|
| 53 | - $login = trim($login); |
|
| 51 | + public function __construct($login, $transkey, $test = self::USE_PRODUCTION_SERVER) |
|
| 52 | + { |
|
| 53 | + $login = trim($login); |
|
| 54 | 54 | $transkey = trim($transkey); |
| 55 | 55 | if (empty($login) || empty($transkey)) |
| 56 | 56 | { |
@@ -63,7 +63,7 @@ discard block |
||
| 63 | 63 | |
| 64 | 64 | $subdomain = ($test) ? 'apitest' : 'api'; |
| 65 | 65 | $this->url = 'https://' . $subdomain . '.authorize.net/xml/v1/request.api'; |
| 66 | - } |
|
| 66 | + } |
|
| 67 | 67 | |
| 68 | 68 | /** |
| 69 | 69 | * remove XML response namespaces |
@@ -78,9 +78,9 @@ discard block |
||
| 78 | 78 | return str_replace(' xmlns:xsd="http://www.w3.org/2001/XMLSchema"','',$input); |
| 79 | 79 | } |
| 80 | 80 | |
| 81 | - public function __toString() |
|
| 82 | - { |
|
| 83 | - $output = ''; |
|
| 81 | + public function __toString() |
|
| 82 | + { |
|
| 83 | + $output = ''; |
|
| 84 | 84 | $output .= '<table summary="Authorize.Net Results" id="authnet">' . "\n"; |
| 85 | 85 | $output .= '<tr>' . "\n\t\t" . '<th colspan="2"><b>Class Parameters</b></th>' . "\n" . '</tr>' . "\n"; |
| 86 | 86 | $output .= '<tr>' . "\n\t\t" . '<td><b>API Login ID</b></td><td>' . $this->login . '</td>' . "\n" . '</tr>' . "\n"; |
@@ -117,9 +117,9 @@ discard block |
||
| 117 | 117 | $output .= '</table>'; |
| 118 | 118 | |
| 119 | 119 | return $output; |
| 120 | - } |
|
| 120 | + } |
|
| 121 | 121 | |
| 122 | - public function __destruct() |
|
| 122 | + public function __destruct() |
|
| 123 | 123 | { |
| 124 | 124 | if (isset($this->ch)) |
| 125 | 125 | { |
@@ -128,31 +128,31 @@ discard block |
||
| 128 | 128 | } |
| 129 | 129 | |
| 130 | 130 | public function __get($var) |
| 131 | - { |
|
| 132 | - return $this->response_xml->$var; |
|
| 133 | - } |
|
| 134 | - |
|
| 135 | - public function __set($key, $value) |
|
| 136 | - { |
|
| 137 | - trigger_error('You cannot set parameters directly in ' . __CLASS__ . '.', E_USER_WARNING); |
|
| 138 | - return false; |
|
| 139 | - } |
|
| 140 | - |
|
| 141 | - public function __call($api_call, $args) |
|
| 142 | - { |
|
| 143 | - $this->xml = new SimpleXMLElement('<' . $api_call . '></' . $api_call . '>'); |
|
| 131 | + { |
|
| 132 | + return $this->response_xml->$var; |
|
| 133 | + } |
|
| 134 | + |
|
| 135 | + public function __set($key, $value) |
|
| 136 | + { |
|
| 137 | + trigger_error('You cannot set parameters directly in ' . __CLASS__ . '.', E_USER_WARNING); |
|
| 138 | + return false; |
|
| 139 | + } |
|
| 140 | + |
|
| 141 | + public function __call($api_call, $args) |
|
| 142 | + { |
|
| 143 | + $this->xml = new SimpleXMLElement('<' . $api_call . '></' . $api_call . '>'); |
|
| 144 | 144 | $this->xml->addAttribute('xmlns', 'AnetApi/xml/v1/schema/AnetApiSchema.xsd'); |
| 145 | - $merch_auth = $this->xml->addChild('merchantAuthentication'); |
|
| 145 | + $merch_auth = $this->xml->addChild('merchantAuthentication'); |
|
| 146 | 146 | $merch_auth->addChild('name', $this->login); |
| 147 | - $merch_auth->addChild('transactionKey', $this->transkey); |
|
| 147 | + $merch_auth->addChild('transactionKey', $this->transkey); |
|
| 148 | 148 | |
| 149 | - $this->setParameters($this->xml, $args[0]); |
|
| 150 | - $this->process(); |
|
| 151 | - } |
|
| 149 | + $this->setParameters($this->xml, $args[0]); |
|
| 150 | + $this->process(); |
|
| 151 | + } |
|
| 152 | 152 | |
| 153 | - private function setParameters($xml, $array) |
|
| 154 | - { |
|
| 155 | - if (is_array($array)) |
|
| 153 | + private function setParameters($xml, $array) |
|
| 154 | + { |
|
| 155 | + if (is_array($array)) |
|
| 156 | 156 | { |
| 157 | 157 | $first = true; |
| 158 | 158 | foreach ($array as $key => $value) |
@@ -184,34 +184,34 @@ discard block |
||
| 184 | 184 | } |
| 185 | 185 | } |
| 186 | 186 | } |
| 187 | - } |
|
| 187 | + } |
|
| 188 | 188 | |
| 189 | - private function process() |
|
| 190 | - { |
|
| 191 | - $this->xml = $this->xml->asXML(); |
|
| 189 | + private function process() |
|
| 190 | + { |
|
| 191 | + $this->xml = $this->xml->asXML(); |
|
| 192 | 192 | |
| 193 | - $this->ch = curl_init(); |
|
| 193 | + $this->ch = curl_init(); |
|
| 194 | 194 | curl_setopt($this->ch, CURLOPT_URL, $this->url); |
| 195 | - curl_setopt($this->ch, CURLOPT_RETURNTRANSFER, 1); |
|
| 196 | - curl_setopt($this->ch, CURLOPT_HTTPHEADER, Array("Content-Type: text/xml")); |
|
| 197 | - curl_setopt($this->ch, CURLOPT_HEADER, 0); |
|
| 198 | - curl_setopt($this->ch, CURLOPT_POSTFIELDS, $this->xml); |
|
| 199 | - curl_setopt($this->ch, CURLOPT_POST, 1); |
|
| 200 | - curl_setopt($this->ch, CURLOPT_SSL_VERIFYHOST, 2); |
|
| 201 | - curl_setopt($this->ch, CURLOPT_CAINFO, dirname(__FILE__) . '/ssl/cert.pem'); |
|
| 195 | + curl_setopt($this->ch, CURLOPT_RETURNTRANSFER, 1); |
|
| 196 | + curl_setopt($this->ch, CURLOPT_HTTPHEADER, Array("Content-Type: text/xml")); |
|
| 197 | + curl_setopt($this->ch, CURLOPT_HEADER, 0); |
|
| 198 | + curl_setopt($this->ch, CURLOPT_POSTFIELDS, $this->xml); |
|
| 199 | + curl_setopt($this->ch, CURLOPT_POST, 1); |
|
| 200 | + curl_setopt($this->ch, CURLOPT_SSL_VERIFYHOST, 2); |
|
| 201 | + curl_setopt($this->ch, CURLOPT_CAINFO, dirname(__FILE__) . '/ssl/cert.pem'); |
|
| 202 | 202 | |
| 203 | 203 | if(($this->response = curl_exec($this->ch)) !== false) |
| 204 | 204 | { |
| 205 | 205 | $this->response_xml = @new SimpleXMLElement($this->response); |
| 206 | 206 | |
| 207 | - curl_close($this->ch); |
|
| 207 | + curl_close($this->ch); |
|
| 208 | 208 | unset($this->ch); |
| 209 | 209 | return; |
| 210 | - } |
|
| 210 | + } |
|
| 211 | 211 | throw new AuthnetXMLException('Connection error: ' . curl_error($this->ch) . ' (' . curl_errno($this->ch) . ')', self::EXCEPTION_CURL); |
| 212 | - } |
|
| 212 | + } |
|
| 213 | 213 | |
| 214 | - public function isSuccessful() |
|
| 214 | + public function isSuccessful() |
|
| 215 | 215 | { |
| 216 | 216 | return $this->response_xml->messages->resultCode == 'Ok'; |
| 217 | 217 | } |
@@ -50,7 +50,7 @@ discard block |
||
| 50 | 50 | |
| 51 | 51 | public function __construct($login, $transkey, $test = self::USE_PRODUCTION_SERVER) |
| 52 | 52 | { |
| 53 | - $login = trim($login); |
|
| 53 | + $login = trim($login); |
|
| 54 | 54 | $transkey = trim($transkey); |
| 55 | 55 | if (empty($login) || empty($transkey)) |
| 56 | 56 | { |
@@ -59,7 +59,7 @@ discard block |
||
| 59 | 59 | |
| 60 | 60 | $this->login = trim($login); |
| 61 | 61 | $this->transkey = trim($transkey); |
| 62 | - $test = (bool) $test; |
|
| 62 | + $test = (bool)$test; |
|
| 63 | 63 | |
| 64 | 64 | $subdomain = ($test) ? 'apitest' : 'api'; |
| 65 | 65 | $this->url = 'https://' . $subdomain . '.authorize.net/xml/v1/request.api'; |
@@ -73,14 +73,14 @@ discard block |
||
| 73 | 73 | private function removeResponseXMLNS($input) |
| 74 | 74 | { |
| 75 | 75 | // why remove them one at a time? all three aren't consistantly used in the response |
| 76 | - $input = str_replace(' xmlns="AnetApi/xml/v1/schema/AnetApiSchema.xsd"','',$input); |
|
| 77 | - $input = str_replace(' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"','',$input); |
|
| 78 | - return str_replace(' xmlns:xsd="http://www.w3.org/2001/XMLSchema"','',$input); |
|
| 76 | + $input = str_replace(' xmlns="AnetApi/xml/v1/schema/AnetApiSchema.xsd"', '', $input); |
|
| 77 | + $input = str_replace(' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"', '', $input); |
|
| 78 | + return str_replace(' xmlns:xsd="http://www.w3.org/2001/XMLSchema"', '', $input); |
|
| 79 | 79 | } |
| 80 | 80 | |
| 81 | 81 | public function __toString() |
| 82 | 82 | { |
| 83 | - $output = ''; |
|
| 83 | + $output = ''; |
|
| 84 | 84 | $output .= '<table summary="Authorize.Net Results" id="authnet">' . "\n"; |
| 85 | 85 | $output .= '<tr>' . "\n\t\t" . '<th colspan="2"><b>Class Parameters</b></th>' . "\n" . '</tr>' . "\n"; |
| 86 | 86 | $output .= '<tr>' . "\n\t\t" . '<td><b>API Login ID</b></td><td>' . $this->login . '</td>' . "\n" . '</tr>' . "\n"; |
@@ -159,9 +159,9 @@ discard block |
||
| 159 | 159 | { |
| 160 | 160 | if (is_array($value)) |
| 161 | 161 | { |
| 162 | - if(is_numeric($key)) |
|
| 162 | + if (is_numeric($key)) |
|
| 163 | 163 | { |
| 164 | - if($first === true) |
|
| 164 | + if ($first === true) |
|
| 165 | 165 | { |
| 166 | 166 | $xmlx = $xml; |
| 167 | 167 | $first = false; |
@@ -200,7 +200,7 @@ discard block |
||
| 200 | 200 | curl_setopt($this->ch, CURLOPT_SSL_VERIFYHOST, 2); |
| 201 | 201 | curl_setopt($this->ch, CURLOPT_CAINFO, dirname(__FILE__) . '/ssl/cert.pem'); |
| 202 | 202 | |
| 203 | - if(($this->response = curl_exec($this->ch)) !== false) |
|
| 203 | + if (($this->response = curl_exec($this->ch)) !== false) |
|
| 204 | 204 | { |
| 205 | 205 | $this->response_xml = @new SimpleXMLElement($this->response); |
| 206 | 206 | |
@@ -165,20 +165,17 @@ |
||
| 165 | 165 | { |
| 166 | 166 | $xmlx = $xml; |
| 167 | 167 | $first = false; |
| 168 | - } |
|
| 169 | - else |
|
| 168 | + } else |
|
| 170 | 169 | { |
| 171 | 170 | $parent = $xml->xpath('parent::*'); |
| 172 | 171 | $xmlx = $parent[0]->addChild($xml->getName()); |
| 173 | 172 | } |
| 174 | - } |
|
| 175 | - else |
|
| 173 | + } else |
|
| 176 | 174 | { |
| 177 | 175 | $xmlx = $xml->addChild($key); |
| 178 | 176 | } |
| 179 | 177 | $this->setParameters($xmlx, $value); |
| 180 | - } |
|
| 181 | - else |
|
| 178 | + } else |
|
| 182 | 179 | { |
| 183 | 180 | $xml->$key = $value; |
| 184 | 181 | } |
@@ -189,6 +189,11 @@ |
||
| 189 | 189 | return $this->responseFor('insights', 'Insights', $ipAddress); |
| 190 | 190 | } |
| 191 | 191 | |
| 192 | + /** |
|
| 193 | + * @param string $endpoint |
|
| 194 | + * @param string $class |
|
| 195 | + * @param string $ipAddress |
|
| 196 | + */ |
|
| 192 | 197 | private function responseFor($endpoint, $class, $ipAddress) |
| 193 | 198 | { |
| 194 | 199 | $path = implode('/', array(self::$basePath, $endpoint, $ipAddress)); |
@@ -9,7 +9,6 @@ |
||
| 9 | 9 | use GeoIp2\Exception\InvalidRequestException; |
| 10 | 10 | use GeoIp2\Exception\OutOfQueriesException; |
| 11 | 11 | use GeoIp2\ProviderInterface; |
| 12 | -use MaxMind\Exception\InvalidInputException; |
|
| 13 | 12 | use MaxMind\WebService\Client as WsClient; |
| 14 | 13 | |
| 15 | 14 | /** |
@@ -76,7 +76,7 @@ |
||
| 76 | 76 | // This is for backwards compatibility. Do not remove except for a |
| 77 | 77 | // major version bump. |
| 78 | 78 | if (is_string($options)) { |
| 79 | - $options = array( 'host' => $options ); |
|
| 79 | + $options = array('host' => $options); |
|
| 80 | 80 | } |
| 81 | 81 | |
| 82 | 82 | if (!isset($options['host'])) { |
@@ -115,6 +115,9 @@ discard block |
||
| 115 | 115 | return $this->resolveDataPointer($pointer); |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | + /** |
|
| 119 | + * @param string $ipAddress |
|
| 120 | + */ |
|
| 118 | 121 | private function findAddressInTree($ipAddress) |
| 119 | 122 | { |
| 120 | 123 | // XXX - could simplify. Done as a byte array to ease porting |
@@ -146,6 +149,9 @@ discard block |
||
| 146 | 149 | } |
| 147 | 150 | |
| 148 | 151 | |
| 152 | + /** |
|
| 153 | + * @param integer $length |
|
| 154 | + */ |
|
| 149 | 155 | private function startNode($length) |
| 150 | 156 | { |
| 151 | 157 | // Check if we are looking up an IPv4 address in an IPv6 tree. If this |
@@ -178,6 +184,9 @@ discard block |
||
| 178 | 184 | return $node; |
| 179 | 185 | } |
| 180 | 186 | |
| 187 | + /** |
|
| 188 | + * @param integer $index |
|
| 189 | + */ |
|
| 181 | 190 | private function readNode($nodeNumber, $index) |
| 182 | 191 | { |
| 183 | 192 | $baseOffset = $nodeNumber * $this->metadata->nodeByteSize; |
@@ -230,6 +239,10 @@ discard block |
||
| 230 | 239 | * are much faster algorithms (e.g., Boyer-Moore) for this if speed is ever |
| 231 | 240 | * an issue, but I suspect it won't be. |
| 232 | 241 | */ |
| 242 | + |
|
| 243 | + /** |
|
| 244 | + * @param string $filename |
|
| 245 | + */ |
|
| 233 | 246 | private function findMetadataStart($filename) |
| 234 | 247 | { |
| 235 | 248 | $handle = $this->fileHandle; |
@@ -407,6 +407,10 @@ discard block |
||
| 407 | 407 | exit; |
| 408 | 408 | } |
| 409 | 409 | |
| 410 | + /** |
|
| 411 | + * @param string $source_url |
|
| 412 | + * @param string $destination_file |
|
| 413 | + */ |
|
| 410 | 414 | public static function geoip2_download_file( $source_url, $destination_file ) { |
| 411 | 415 | $success = false; |
| 412 | 416 | $message = ''; |
@@ -1192,6 +1196,9 @@ discard block |
||
| 1192 | 1196 | return apply_filters( 'wpinv_response_euvatrates', $response, $group ); |
| 1193 | 1197 | } |
| 1194 | 1198 | |
| 1199 | + /** |
|
| 1200 | + * @param boolean $is_digital |
|
| 1201 | + */ |
|
| 1195 | 1202 | public static function requires_vat( $requires_vat = false, $user_id = 0, $is_digital = null ) { |
| 1196 | 1203 | global $wpi_item_id, $wpi_country; |
| 1197 | 1204 | |
@@ -1412,6 +1419,9 @@ discard block |
||
| 1412 | 1419 | return apply_filters( 'wpinv_item_is_taxable', $is_taxable, $item_id, $country , $state ); |
| 1413 | 1420 | } |
| 1414 | 1421 | |
| 1422 | + /** |
|
| 1423 | + * @param string|null $state |
|
| 1424 | + */ |
|
| 1415 | 1425 | public static function find_rate( $country, $state, $rate, $class ) { |
| 1416 | 1426 | global $wpi_zero_tax; |
| 1417 | 1427 | |
@@ -1,6 +1,8 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | // Exit if accessed directly. |
| 3 | -if (!defined( 'ABSPATH' ) ) exit; |
|
| 3 | +if (!defined( 'ABSPATH' ) ) { |
|
| 4 | + exit; |
|
| 5 | +} |
|
| 4 | 6 | |
| 5 | 7 | class WPInv_EUVat { |
| 6 | 8 | private static $is_ajax = false; |
@@ -1445,16 +1447,18 @@ discard block |
||
| 1445 | 1447 | |
| 1446 | 1448 | if ( !empty( $tax_rates ) ) { |
| 1447 | 1449 | foreach ( $tax_rates as $key => $tax_rate ) { |
| 1448 | - if ( $country != $tax_rate['country'] ) |
|
| 1449 | - continue; |
|
| 1450 | + if ( $country != $tax_rate['country'] ) { |
|
| 1451 | + continue; |
|
| 1452 | + } |
|
| 1450 | 1453 | |
| 1451 | 1454 | if ( !empty( $tax_rate['global'] ) ) { |
| 1452 | 1455 | if ( 0 !== $tax_rate['rate'] || !empty( $tax_rate['rate'] ) ) { |
| 1453 | 1456 | $rate = number_format( $tax_rate['rate'], 4 ); |
| 1454 | 1457 | } |
| 1455 | 1458 | } else { |
| 1456 | - if ( empty( $tax_rate['state'] ) || strtolower( $state ) != strtolower( $tax_rate['state'] ) ) |
|
| 1457 | - continue; |
|
| 1459 | + if ( empty( $tax_rate['state'] ) || strtolower( $state ) != strtolower( $tax_rate['state'] ) ) { |
|
| 1460 | + continue; |
|
| 1461 | + } |
|
| 1458 | 1462 | |
| 1459 | 1463 | $state_rate = $tax_rate['rate']; |
| 1460 | 1464 | if ( 0 !== $state_rate || !empty( $state_rate ) ) { |
@@ -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,137 +17,137 @@ 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 | - if( wpinv_use_taxes() && wpinv_get_option( 'apply_vat_rules' ) ) { |
|
| 90 | + if (wpinv_use_taxes() && wpinv_get_option('apply_vat_rules')) { |
|
| 91 | 91 | self::load_vat_scripts(); |
| 92 | 92 | } |
| 93 | 93 | } |
| 94 | 94 | |
| 95 | - public static function load_vat_scripts(){ |
|
| 96 | - $suffix = '';//defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
| 95 | + public static function load_vat_scripts() { |
|
| 96 | + $suffix = ''; //defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
| 97 | 97 | |
| 98 | - wp_register_script( 'wpinv-vat-validation-script', WPINV_PLUGIN_URL . 'assets/js/jsvat' . $suffix . '.js', array( 'jquery' ), WPINV_VERSION ); |
|
| 99 | - wp_register_script( 'wpinv-vat-script', WPINV_PLUGIN_URL . 'assets/js/euvat' . $suffix . '.js', array( 'jquery' ), WPINV_VERSION ); |
|
| 98 | + wp_register_script('wpinv-vat-validation-script', WPINV_PLUGIN_URL . 'assets/js/jsvat' . $suffix . '.js', array('jquery'), WPINV_VERSION); |
|
| 99 | + wp_register_script('wpinv-vat-script', WPINV_PLUGIN_URL . 'assets/js/euvat' . $suffix . '.js', array('jquery'), WPINV_VERSION); |
|
| 100 | 100 | |
| 101 | - $vat_name = self::get_vat_name(); |
|
| 101 | + $vat_name = self::get_vat_name(); |
|
| 102 | 102 | |
| 103 | 103 | $vars = array(); |
| 104 | 104 | $vars['UseTaxes'] = wpinv_use_taxes(); |
| 105 | 105 | $vars['EUStates'] = self::get_eu_states(); |
| 106 | - $vars['NoRateSet'] = __( 'You have not set a rate. Do you want to continue?', 'invoicing' ); |
|
| 107 | - $vars['EmptyCompany'] = __( 'Please enter your registered company name!', 'invoicing' ); |
|
| 108 | - $vars['EmptyVAT'] = wp_sprintf( __( 'Please enter your %s number!', 'invoicing' ), $vat_name ); |
|
| 109 | - $vars['TotalsRefreshed'] = wp_sprintf( __( 'The invoice totals will be refreshed to update the %s.', 'invoicing' ), $vat_name ); |
|
| 110 | - $vars['ErrValidateVAT'] = wp_sprintf( __( 'Fail to validate the %s number!', 'invoicing' ), $vat_name ); |
|
| 111 | - $vars['ErrResetVAT'] = wp_sprintf( __( 'Fail to reset the %s number!', 'invoicing' ), $vat_name ); |
|
| 112 | - $vars['ErrInvalidVat'] = wp_sprintf( __( 'The %s number supplied does not have a valid format!', 'invoicing' ), $vat_name ); |
|
| 113 | - $vars['ErrInvalidResponse'] = __( 'An invalid response has been received from the server!', 'invoicing' ); |
|
| 106 | + $vars['NoRateSet'] = __('You have not set a rate. Do you want to continue?', 'invoicing'); |
|
| 107 | + $vars['EmptyCompany'] = __('Please enter your registered company name!', 'invoicing'); |
|
| 108 | + $vars['EmptyVAT'] = wp_sprintf(__('Please enter your %s number!', 'invoicing'), $vat_name); |
|
| 109 | + $vars['TotalsRefreshed'] = wp_sprintf(__('The invoice totals will be refreshed to update the %s.', 'invoicing'), $vat_name); |
|
| 110 | + $vars['ErrValidateVAT'] = wp_sprintf(__('Fail to validate the %s number!', 'invoicing'), $vat_name); |
|
| 111 | + $vars['ErrResetVAT'] = wp_sprintf(__('Fail to reset the %s number!', 'invoicing'), $vat_name); |
|
| 112 | + $vars['ErrInvalidVat'] = wp_sprintf(__('The %s number supplied does not have a valid format!', 'invoicing'), $vat_name); |
|
| 113 | + $vars['ErrInvalidResponse'] = __('An invalid response has been received from the server!', 'invoicing'); |
|
| 114 | 114 | $vars['ApplyVATRules'] = $vars['UseTaxes'] ? self::allow_vat_rules() : false; |
| 115 | 115 | $vars['HideVatFields'] = $vars['ApplyVATRules'] ? self::hide_vat_fields() : true; |
| 116 | - $vars['ErrResponse'] = __( 'The request response is invalid!', 'invoicing' ); |
|
| 117 | - $vars['ErrRateResponse'] = __( 'The get rate request response is invalid', 'invoicing' ); |
|
| 118 | - $vars['PageRefresh'] = __( 'The page will be refreshed in 10 seconds to show the new options.', 'invoicing' ); |
|
| 119 | - $vars['RequestResponseNotValidJSON'] = __( 'The get rate request response is not valid JSON', 'invoicing' ); |
|
| 120 | - $vars['GetRateRequestFailed'] = __( 'The get rate request failed: ', 'invoicing' ); |
|
| 121 | - $vars['NoRateInformationInResponse'] = __( 'The get rate request response does not contain any rate information', 'invoicing' ); |
|
| 122 | - $vars['RatesUpdated'] = __( 'The rates have been updated. Press the save button to record these new rates.', 'invoicing' ); |
|
| 123 | - $vars['IPAddressInformation'] = __( 'IP Address Information', 'invoicing' ); |
|
| 124 | - $vars['VatValidating'] = wp_sprintf( __( 'Validating %s number...', 'invoicing' ), $vat_name ); |
|
| 125 | - $vars['VatReseting'] = __( 'Reseting...', 'invoicing' ); |
|
| 126 | - $vars['VatValidated'] = wp_sprintf( __( '%s number validated', 'invoicing' ), $vat_name ); |
|
| 127 | - $vars['VatNotValidated'] = wp_sprintf( __( '%s number not validated', 'invoicing' ), $vat_name ); |
|
| 128 | - $vars['ConfirmDeleteClass'] = __( 'Are you sure you wish to delete this rates class?', 'invoicing' ); |
|
| 116 | + $vars['ErrResponse'] = __('The request response is invalid!', 'invoicing'); |
|
| 117 | + $vars['ErrRateResponse'] = __('The get rate request response is invalid', 'invoicing'); |
|
| 118 | + $vars['PageRefresh'] = __('The page will be refreshed in 10 seconds to show the new options.', 'invoicing'); |
|
| 119 | + $vars['RequestResponseNotValidJSON'] = __('The get rate request response is not valid JSON', 'invoicing'); |
|
| 120 | + $vars['GetRateRequestFailed'] = __('The get rate request failed: ', 'invoicing'); |
|
| 121 | + $vars['NoRateInformationInResponse'] = __('The get rate request response does not contain any rate information', 'invoicing'); |
|
| 122 | + $vars['RatesUpdated'] = __('The rates have been updated. Press the save button to record these new rates.', 'invoicing'); |
|
| 123 | + $vars['IPAddressInformation'] = __('IP Address Information', 'invoicing'); |
|
| 124 | + $vars['VatValidating'] = wp_sprintf(__('Validating %s number...', 'invoicing'), $vat_name); |
|
| 125 | + $vars['VatReseting'] = __('Reseting...', 'invoicing'); |
|
| 126 | + $vars['VatValidated'] = wp_sprintf(__('%s number validated', 'invoicing'), $vat_name); |
|
| 127 | + $vars['VatNotValidated'] = wp_sprintf(__('%s number not validated', 'invoicing'), $vat_name); |
|
| 128 | + $vars['ConfirmDeleteClass'] = __('Are you sure you wish to delete this rates class?', 'invoicing'); |
|
| 129 | 129 | $vars['isFront'] = is_admin() ? false : true; |
| 130 | 130 | $vars['baseCountry'] = wpinv_get_default_country(); |
| 131 | - $vars['disableVATSameCountry'] = ( self::same_country_rule() == 'no' ? true : false ); |
|
| 132 | - $vars['disableVATSimpleCheck'] = wpinv_get_option( 'vat_offline_check' ) ? true : false; |
|
| 131 | + $vars['disableVATSameCountry'] = (self::same_country_rule() == 'no' ? true : false); |
|
| 132 | + $vars['disableVATSimpleCheck'] = wpinv_get_option('vat_offline_check') ? true : false; |
|
| 133 | 133 | |
| 134 | - wp_enqueue_script( 'wpinv-vat-validation-script' ); |
|
| 135 | - wp_enqueue_script( 'wpinv-vat-script' ); |
|
| 136 | - wp_localize_script( 'wpinv-vat-script', 'WPInv_VAT_Vars', $vars ); |
|
| 134 | + wp_enqueue_script('wpinv-vat-validation-script'); |
|
| 135 | + wp_enqueue_script('wpinv-vat-script'); |
|
| 136 | + wp_localize_script('wpinv-vat-script', 'WPInv_VAT_Vars', $vars); |
|
| 137 | 137 | } |
| 138 | 138 | |
| 139 | 139 | public static function enqueue_admin_scripts() { |
| 140 | - if( isset( $_GET['page'] ) && 'wpinv-settings' == $_GET['page'] ) { |
|
| 140 | + if (isset($_GET['page']) && 'wpinv-settings' == $_GET['page']) { |
|
| 141 | 141 | self::load_vat_scripts(); |
| 142 | 142 | } |
| 143 | 143 | } |
| 144 | 144 | |
| 145 | - public static function section_vat_settings( $sections ) { |
|
| 146 | - if ( !empty( $sections ) ) { |
|
| 147 | - $sections['vat'] = __( 'EU VAT Settings', 'invoicing' ); |
|
| 145 | + public static function section_vat_settings($sections) { |
|
| 146 | + if (!empty($sections)) { |
|
| 147 | + $sections['vat'] = __('EU VAT Settings', 'invoicing'); |
|
| 148 | 148 | |
| 149 | - if ( self::allow_vat_classes() ) { |
|
| 150 | - $sections['vat_rates'] = __( 'EU VAT Rates', 'invoicing' ); |
|
| 149 | + if (self::allow_vat_classes()) { |
|
| 150 | + $sections['vat_rates'] = __('EU VAT Rates', 'invoicing'); |
|
| 151 | 151 | } |
| 152 | 152 | } |
| 153 | 153 | return $sections; |
@@ -156,52 +156,52 @@ discard block |
||
| 156 | 156 | public static function vat_rates_settings() { |
| 157 | 157 | $vat_classes = self::get_rate_classes(); |
| 158 | 158 | $vat_rates = array(); |
| 159 | - $vat_class = isset( $_REQUEST['wpi_sub'] ) && $_REQUEST['wpi_sub'] !== '' && isset( $vat_classes[$_REQUEST['wpi_sub']] )? sanitize_text_field( $_REQUEST['wpi_sub'] ) : '_new'; |
|
| 160 | - $current_url = remove_query_arg( 'wpi_sub' ); |
|
| 159 | + $vat_class = isset($_REQUEST['wpi_sub']) && $_REQUEST['wpi_sub'] !== '' && isset($vat_classes[$_REQUEST['wpi_sub']]) ? sanitize_text_field($_REQUEST['wpi_sub']) : '_new'; |
|
| 160 | + $current_url = remove_query_arg('wpi_sub'); |
|
| 161 | 161 | |
| 162 | 162 | $vat_rates['vat_rates_header'] = array( |
| 163 | 163 | 'id' => 'vat_rates_header', |
| 164 | - 'name' => '<h3>' . __( 'Manage VAT Rates', 'invoicing' ) . '</h3>', |
|
| 164 | + 'name' => '<h3>' . __('Manage VAT Rates', 'invoicing') . '</h3>', |
|
| 165 | 165 | 'desc' => '', |
| 166 | 166 | 'type' => 'header', |
| 167 | 167 | 'size' => 'regular' |
| 168 | 168 | ); |
| 169 | 169 | $vat_rates['vat_rates_class'] = array( |
| 170 | 170 | 'id' => 'vat_rates_class', |
| 171 | - 'name' => __( 'Edit VAT Rates', 'invoicing' ), |
|
| 172 | - 'desc' => __( 'The standard rate will apply where no explicit rate is provided.', 'invoicing' ), |
|
| 171 | + 'name' => __('Edit VAT Rates', 'invoicing'), |
|
| 172 | + 'desc' => __('The standard rate will apply where no explicit rate is provided.', 'invoicing'), |
|
| 173 | 173 | 'type' => 'select', |
| 174 | - 'options' => array_merge( $vat_classes, array( '_new' => __( 'Add New Rate Class', 'invoicing' ) ) ), |
|
| 175 | - 'placeholder' => __( 'Select a VAT Rate', 'invoicing' ), |
|
| 174 | + 'options' => array_merge($vat_classes, array('_new' => __('Add New Rate Class', 'invoicing'))), |
|
| 175 | + 'placeholder' => __('Select a VAT Rate', 'invoicing'), |
|
| 176 | 176 | 'selected' => $vat_class, |
| 177 | 177 | 'class' => 'wpi_select2', |
| 178 | 178 | 'onchange' => 'document.location.href="' . $current_url . '&wpi_sub=" + this.value;', |
| 179 | 179 | ); |
| 180 | 180 | |
| 181 | - if ( $vat_class != '_standard' && $vat_class != '_new' ) { |
|
| 181 | + if ($vat_class != '_standard' && $vat_class != '_new') { |
|
| 182 | 182 | $vat_rates['vat_rate_delete'] = array( |
| 183 | 183 | 'id' => 'vat_rate_delete', |
| 184 | 184 | 'type' => 'vat_rate_delete', |
| 185 | 185 | ); |
| 186 | 186 | } |
| 187 | 187 | |
| 188 | - if ( $vat_class == '_new' ) { |
|
| 188 | + if ($vat_class == '_new') { |
|
| 189 | 189 | $vat_rates['vat_rates_settings'] = array( |
| 190 | 190 | 'id' => 'vat_rates_settings', |
| 191 | - 'name' => '<h3>' . __( 'Add New Rate Class', 'invoicing' ) . '</h3>', |
|
| 191 | + 'name' => '<h3>' . __('Add New Rate Class', 'invoicing') . '</h3>', |
|
| 192 | 192 | 'type' => 'header', |
| 193 | 193 | ); |
| 194 | 194 | $vat_rates['vat_rate_name'] = array( |
| 195 | 195 | 'id' => 'vat_rate_name', |
| 196 | - 'name' => __( 'Name', 'invoicing' ), |
|
| 197 | - 'desc' => __( 'A short name for the new VAT Rate class', 'invoicing' ), |
|
| 196 | + 'name' => __('Name', 'invoicing'), |
|
| 197 | + 'desc' => __('A short name for the new VAT Rate class', 'invoicing'), |
|
| 198 | 198 | 'type' => 'text', |
| 199 | 199 | 'size' => 'regular', |
| 200 | 200 | ); |
| 201 | 201 | $vat_rates['vat_rate_desc'] = array( |
| 202 | 202 | 'id' => 'vat_rate_desc', |
| 203 | - 'name' => __( 'Description', 'invoicing' ), |
|
| 204 | - 'desc' => __( 'Manage VAT Rate class', 'invoicing' ), |
|
| 203 | + 'name' => __('Description', 'invoicing'), |
|
| 204 | + 'desc' => __('Manage VAT Rate class', 'invoicing'), |
|
| 205 | 205 | 'type' => 'text', |
| 206 | 206 | 'size' => 'regular', |
| 207 | 207 | ); |
@@ -213,7 +213,7 @@ discard block |
||
| 213 | 213 | $vat_rates['vat_rates'] = array( |
| 214 | 214 | 'id' => 'vat_rates', |
| 215 | 215 | 'name' => '<h3>' . $vat_classes[$vat_class] . '</h3>', |
| 216 | - 'desc' => self::get_class_desc( $vat_class ), |
|
| 216 | + 'desc' => self::get_class_desc($vat_class), |
|
| 217 | 217 | 'type' => 'vat_rates', |
| 218 | 218 | ); |
| 219 | 219 | } |
@@ -221,12 +221,12 @@ discard block |
||
| 221 | 221 | return $vat_rates; |
| 222 | 222 | } |
| 223 | 223 | |
| 224 | - public static function vat_settings( $settings ) { |
|
| 225 | - if ( !empty( $settings ) ) { |
|
| 224 | + public static function vat_settings($settings) { |
|
| 225 | + if (!empty($settings)) { |
|
| 226 | 226 | $vat_settings = array(); |
| 227 | 227 | $vat_settings['vat_company_title'] = array( |
| 228 | 228 | 'id' => 'vat_company_title', |
| 229 | - 'name' => '<h3>' . __( 'Your Company Details', 'invoicing' ) . '</h3>', |
|
| 229 | + 'name' => '<h3>' . __('Your Company Details', 'invoicing') . '</h3>', |
|
| 230 | 230 | 'desc' => '', |
| 231 | 231 | 'type' => 'header', |
| 232 | 232 | 'size' => 'regular' |
@@ -234,22 +234,22 @@ discard block |
||
| 234 | 234 | |
| 235 | 235 | $vat_settings['vat_company_name'] = array( |
| 236 | 236 | 'id' => 'vat_company_name', |
| 237 | - 'name' => __( 'Your Company Name', 'invoicing' ), |
|
| 238 | - '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>' ), |
|
| 237 | + 'name' => __('Your Company Name', 'invoicing'), |
|
| 238 | + '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>'), |
|
| 239 | 239 | 'type' => 'text', |
| 240 | 240 | 'size' => 'regular', |
| 241 | 241 | ); |
| 242 | 242 | |
| 243 | 243 | $vat_settings['vat_number'] = array( |
| 244 | 244 | 'id' => 'vat_number', |
| 245 | - 'name' => __( 'Your VAT Number', 'invoicing' ), |
|
| 245 | + 'name' => __('Your VAT Number', 'invoicing'), |
|
| 246 | 246 | 'type' => 'vat_number', |
| 247 | 247 | 'size' => 'regular', |
| 248 | 248 | ); |
| 249 | 249 | |
| 250 | 250 | $vat_settings['vat_settings_title'] = array( |
| 251 | 251 | 'id' => 'vat_settings_title', |
| 252 | - 'name' => '<h3>' . __( 'Apply VAT Settings', 'invoicing' ) . '</h3>', |
|
| 252 | + 'name' => '<h3>' . __('Apply VAT Settings', 'invoicing') . '</h3>', |
|
| 253 | 253 | 'desc' => '', |
| 254 | 254 | 'type' => 'header', |
| 255 | 255 | 'size' => 'regular' |
@@ -257,8 +257,8 @@ discard block |
||
| 257 | 257 | |
| 258 | 258 | $vat_settings['apply_vat_rules'] = array( |
| 259 | 259 | 'id' => 'apply_vat_rules', |
| 260 | - 'name' => __( 'Enable VAT Rules', 'invoicing' ), |
|
| 261 | - '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>', |
|
| 260 | + 'name' => __('Enable VAT Rules', 'invoicing'), |
|
| 261 | + '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>', |
|
| 262 | 262 | 'type' => 'checkbox', |
| 263 | 263 | 'std' => '1' |
| 264 | 264 | ); |
@@ -274,8 +274,8 @@ discard block |
||
| 274 | 274 | |
| 275 | 275 | $vat_settings['vat_prevent_b2c_purchase'] = array( |
| 276 | 276 | 'id' => 'vat_prevent_b2c_purchase', |
| 277 | - 'name' => __( 'Prevent EU B2C Sales', 'invoicing' ), |
|
| 278 | - 'desc' => __( 'Enable this option if you are not registered for VAT in the EU.', 'invoicing' ), |
|
| 277 | + 'name' => __('Prevent EU B2C Sales', 'invoicing'), |
|
| 278 | + 'desc' => __('Enable this option if you are not registered for VAT in the EU.', 'invoicing'), |
|
| 279 | 279 | 'type' => 'checkbox' |
| 280 | 280 | ); |
| 281 | 281 | |
@@ -283,22 +283,22 @@ discard block |
||
| 283 | 283 | |
| 284 | 284 | $vat_settings['vat_same_country_rule'] = array( |
| 285 | 285 | 'id' => 'vat_same_country_rule', |
| 286 | - 'name' => __( 'Same Country Rule', 'invoicing' ), |
|
| 287 | - 'desc' => __( 'Select how you want to handle VAT charge if sales are in the same country as the base country.', 'invoicing' ), |
|
| 286 | + 'name' => __('Same Country Rule', 'invoicing'), |
|
| 287 | + 'desc' => __('Select how you want to handle VAT charge if sales are in the same country as the base country.', 'invoicing'), |
|
| 288 | 288 | 'type' => 'select', |
| 289 | 289 | 'options' => array( |
| 290 | - '' => __( 'Normal', 'invoicing' ), |
|
| 291 | - 'no' => __( 'No VAT', 'invoicing' ), |
|
| 292 | - 'always' => __( 'Always apply VAT', 'invoicing' ), |
|
| 290 | + '' => __('Normal', 'invoicing'), |
|
| 291 | + 'no' => __('No VAT', 'invoicing'), |
|
| 292 | + 'always' => __('Always apply VAT', 'invoicing'), |
|
| 293 | 293 | ), |
| 294 | - 'placeholder' => __( 'Select an option', 'invoicing' ), |
|
| 294 | + 'placeholder' => __('Select an option', 'invoicing'), |
|
| 295 | 295 | 'std' => '', |
| 296 | 296 | 'class' => 'wpi_select2', |
| 297 | 297 | ); |
| 298 | 298 | |
| 299 | 299 | $vat_settings['vat_checkout_title'] = array( |
| 300 | 300 | 'id' => 'vat_checkout_title', |
| 301 | - 'name' => '<h3>' . __( 'Checkout Fields', 'invoicing' ) . '</h3>', |
|
| 301 | + 'name' => '<h3>' . __('Checkout Fields', 'invoicing') . '</h3>', |
|
| 302 | 302 | 'desc' => '', |
| 303 | 303 | 'type' => 'header', |
| 304 | 304 | 'size' => 'regular' |
@@ -306,14 +306,14 @@ discard block |
||
| 306 | 306 | |
| 307 | 307 | $vat_settings['vat_disable_fields'] = array( |
| 308 | 308 | 'id' => 'vat_disable_fields', |
| 309 | - 'name' => __( 'Disable VAT Fields', 'invoicing' ), |
|
| 310 | - '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>', |
|
| 309 | + 'name' => __('Disable VAT Fields', 'invoicing'), |
|
| 310 | + '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>', |
|
| 311 | 311 | 'type' => 'checkbox' |
| 312 | 312 | ); |
| 313 | 313 | |
| 314 | 314 | $vat_settings['vat_ip_lookup'] = array( |
| 315 | 315 | 'id' => 'vat_ip_lookup', |
| 316 | - 'name' => __( 'IP Country Look-up', 'invoicing' ), |
|
| 316 | + 'name' => __('IP Country Look-up', 'invoicing'), |
|
| 317 | 317 | 'type' => 'vat_ip_lookup', |
| 318 | 318 | 'size' => 'regular', |
| 319 | 319 | 'std' => 'default', |
@@ -322,21 +322,21 @@ discard block |
||
| 322 | 322 | |
| 323 | 323 | $vat_settings['hide_ip_address'] = array( |
| 324 | 324 | 'id' => 'hide_ip_address', |
| 325 | - 'name' => __( 'Hide IP Info at Checkout', 'invoicing' ), |
|
| 326 | - 'desc' => __( 'Hide the user IP info at checkout.', 'invoicing' ), |
|
| 325 | + 'name' => __('Hide IP Info at Checkout', 'invoicing'), |
|
| 326 | + 'desc' => __('Hide the user IP info at checkout.', 'invoicing'), |
|
| 327 | 327 | 'type' => 'checkbox' |
| 328 | 328 | ); |
| 329 | 329 | |
| 330 | 330 | $vat_settings['vat_ip_country_default'] = array( |
| 331 | 331 | 'id' => 'vat_ip_country_default', |
| 332 | - 'name' => __( 'Enable IP Country as Default', 'invoicing' ), |
|
| 333 | - 'desc' => __( 'Show the country of the users IP as the default country, otherwise the site default country will be used.', 'invoicing' ), |
|
| 332 | + 'name' => __('Enable IP Country as Default', 'invoicing'), |
|
| 333 | + 'desc' => __('Show the country of the users IP as the default country, otherwise the site default country will be used.', 'invoicing'), |
|
| 334 | 334 | 'type' => 'checkbox' |
| 335 | 335 | ); |
| 336 | 336 | |
| 337 | 337 | $vat_settings['vies_validation_title'] = array( |
| 338 | 338 | 'id' => 'vies_validation_title', |
| 339 | - 'name' => '<h3>' . __( 'VIES Validation', 'invoicing' ) . '</h3>', |
|
| 339 | + 'name' => '<h3>' . __('VIES Validation', 'invoicing') . '</h3>', |
|
| 340 | 340 | 'desc' => '', |
| 341 | 341 | 'type' => 'header', |
| 342 | 342 | 'size' => 'regular' |
@@ -344,37 +344,37 @@ discard block |
||
| 344 | 344 | |
| 345 | 345 | $vat_settings['vat_vies_check'] = array( |
| 346 | 346 | 'id' => 'vat_vies_check', |
| 347 | - 'name' => __( 'Disable VIES VAT ID Check', 'invoicing' ), |
|
| 348 | - '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>' ), |
|
| 347 | + 'name' => __('Disable VIES VAT ID Check', 'invoicing'), |
|
| 348 | + '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>'), |
|
| 349 | 349 | 'type' => 'checkbox' |
| 350 | 350 | ); |
| 351 | 351 | |
| 352 | 352 | $vat_settings['vat_disable_company_name_check'] = array( |
| 353 | 353 | 'id' => 'vat_disable_company_name_check', |
| 354 | - 'name' => __( 'Disable VIES Name Check', 'invoicing' ), |
|
| 355 | - '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>' ), |
|
| 354 | + 'name' => __('Disable VIES Name Check', 'invoicing'), |
|
| 355 | + '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>'), |
|
| 356 | 356 | 'type' => 'checkbox' |
| 357 | 357 | ); |
| 358 | 358 | |
| 359 | 359 | $vat_settings['vat_offline_check'] = array( |
| 360 | 360 | 'id' => 'vat_offline_check', |
| 361 | - 'name' => __( 'Disable Basic Checks', 'invoicing' ), |
|
| 362 | - 'desc' => __( 'Disable basic JS checks for correct format of VAT number. (Not Recommended)', 'invoicing' ), |
|
| 361 | + 'name' => __('Disable Basic Checks', 'invoicing'), |
|
| 362 | + 'desc' => __('Disable basic JS checks for correct format of VAT number. (Not Recommended)', 'invoicing'), |
|
| 363 | 363 | 'type' => 'checkbox' |
| 364 | 364 | ); |
| 365 | 365 | |
| 366 | 366 | |
| 367 | 367 | $settings['vat'] = $vat_settings; |
| 368 | 368 | |
| 369 | - if ( self::allow_vat_classes() ) { |
|
| 369 | + if (self::allow_vat_classes()) { |
|
| 370 | 370 | $settings['vat_rates'] = self::vat_rates_settings(); |
| 371 | 371 | } |
| 372 | 372 | |
| 373 | 373 | $eu_fallback_rate = array( |
| 374 | 374 | 'id' => 'eu_fallback_rate', |
| 375 | - 'name' => '<h3>' . __( 'VAT rate for EU member states', 'invoicing' ) . '</h3>', |
|
| 375 | + 'name' => '<h3>' . __('VAT rate for EU member states', 'invoicing') . '</h3>', |
|
| 376 | 376 | 'type' => 'eu_fallback_rate', |
| 377 | - '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' ), |
|
| 377 | + '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'), |
|
| 378 | 378 | 'std' => '20', |
| 379 | 379 | 'size' => 'small' |
| 380 | 380 | ); |
@@ -390,11 +390,11 @@ discard block |
||
| 390 | 390 | $database_url = 'http' . (isset($_SERVER["HTTPS"]) && $_SERVER["HTTPS"] === 'on' ? 's' : '') . '://geolite.maxmind.com/download/geoip/database/'; |
| 391 | 391 | $destination_dir = $upload_dir['basedir'] . '/invoicing'; |
| 392 | 392 | |
| 393 | - if ( !is_dir( $destination_dir ) ) { |
|
| 394 | - mkdir( $destination_dir ); |
|
| 393 | + if (!is_dir($destination_dir)) { |
|
| 394 | + mkdir($destination_dir); |
|
| 395 | 395 | } |
| 396 | 396 | |
| 397 | - $database_files = array( |
|
| 397 | + $database_files = array( |
|
| 398 | 398 | 'country' => array( |
| 399 | 399 | 'source' => $database_url . 'GeoLite2-Country.mmdb.gz', |
| 400 | 400 | 'destination' => $destination_dir . '/GeoLite2-Country.mmdb', |
@@ -405,57 +405,57 @@ discard block |
||
| 405 | 405 | ) |
| 406 | 406 | ); |
| 407 | 407 | |
| 408 | - foreach( $database_files as $database => $files ) { |
|
| 409 | - $result = self::geoip2_download_file( $files['source'], $files['destination'] ); |
|
| 408 | + foreach ($database_files as $database => $files) { |
|
| 409 | + $result = self::geoip2_download_file($files['source'], $files['destination']); |
|
| 410 | 410 | |
| 411 | - if ( empty( $result['success'] ) ) { |
|
| 411 | + if (empty($result['success'])) { |
|
| 412 | 412 | echo $result['message']; |
| 413 | 413 | exit; |
| 414 | 414 | } |
| 415 | 415 | |
| 416 | - wpinv_update_option( 'wpinv_geoip2_date_updated', current_time( 'timestamp' ) ); |
|
| 417 | - echo sprintf(__( 'GeoIP2 %s database updated successfully.', 'invoicing' ), $database ) . ' '; |
|
| 416 | + wpinv_update_option('wpinv_geoip2_date_updated', current_time('timestamp')); |
|
| 417 | + echo sprintf(__('GeoIP2 %s database updated successfully.', 'invoicing'), $database) . ' '; |
|
| 418 | 418 | } |
| 419 | 419 | |
| 420 | 420 | exit; |
| 421 | 421 | } |
| 422 | 422 | |
| 423 | - public static function geoip2_download_file( $source_url, $destination_file ) { |
|
| 423 | + public static function geoip2_download_file($source_url, $destination_file) { |
|
| 424 | 424 | $success = false; |
| 425 | 425 | $message = ''; |
| 426 | 426 | |
| 427 | - if ( !function_exists( 'download_url' ) ) { |
|
| 428 | - require_once( ABSPATH . 'wp-admin/includes/file.php' ); |
|
| 427 | + if (!function_exists('download_url')) { |
|
| 428 | + require_once(ABSPATH . 'wp-admin/includes/file.php'); |
|
| 429 | 429 | } |
| 430 | 430 | |
| 431 | - $temp_file = download_url( $source_url ); |
|
| 431 | + $temp_file = download_url($source_url); |
|
| 432 | 432 | |
| 433 | - if ( is_wp_error( $temp_file ) ) { |
|
| 434 | - $message = sprintf( __( 'Error while downloading GeoIp2 database( %s ): %s', 'invoicing' ), $source_url, $temp_file->get_error_message() ); |
|
| 433 | + if (is_wp_error($temp_file)) { |
|
| 434 | + $message = sprintf(__('Error while downloading GeoIp2 database( %s ): %s', 'invoicing'), $source_url, $temp_file->get_error_message()); |
|
| 435 | 435 | } else { |
| 436 | - $handle = gzopen( $temp_file, 'rb' ); |
|
| 436 | + $handle = gzopen($temp_file, 'rb'); |
|
| 437 | 437 | |
| 438 | - if ( $handle ) { |
|
| 439 | - $fopen = fopen( $destination_file, 'wb' ); |
|
| 440 | - if ( $fopen ) { |
|
| 441 | - while ( ( $data = gzread( $handle, 4096 ) ) != false ) { |
|
| 442 | - fwrite( $fopen, $data ); |
|
| 438 | + if ($handle) { |
|
| 439 | + $fopen = fopen($destination_file, 'wb'); |
|
| 440 | + if ($fopen) { |
|
| 441 | + while (($data = gzread($handle, 4096)) != false) { |
|
| 442 | + fwrite($fopen, $data); |
|
| 443 | 443 | } |
| 444 | 444 | |
| 445 | - gzclose( $handle ); |
|
| 446 | - fclose( $fopen ); |
|
| 445 | + gzclose($handle); |
|
| 446 | + fclose($fopen); |
|
| 447 | 447 | |
| 448 | 448 | $success = true; |
| 449 | 449 | } else { |
| 450 | - gzclose( $handle ); |
|
| 451 | - $message = sprintf( __( 'Error could not open destination GeoIp2 database file for writing: %s', 'invoicing' ), $destination_file ); |
|
| 450 | + gzclose($handle); |
|
| 451 | + $message = sprintf(__('Error could not open destination GeoIp2 database file for writing: %s', 'invoicing'), $destination_file); |
|
| 452 | 452 | } |
| 453 | 453 | } else { |
| 454 | - $message = sprintf( __( 'Error could not open GeoIp2 database file for reading: %s', 'invoicing' ), $temp_file ); |
|
| 454 | + $message = sprintf(__('Error could not open GeoIp2 database file for reading: %s', 'invoicing'), $temp_file); |
|
| 455 | 455 | } |
| 456 | 456 | |
| 457 | - if ( file_exists( $temp_file ) ) { |
|
| 458 | - unlink( $temp_file ); |
|
| 457 | + if (file_exists($temp_file)) { |
|
| 458 | + unlink($temp_file); |
|
| 459 | 459 | } |
| 460 | 460 | } |
| 461 | 461 | |
@@ -467,11 +467,11 @@ discard block |
||
| 467 | 467 | } |
| 468 | 468 | |
| 469 | 469 | public static function load_geoip2() { |
| 470 | - if ( defined( 'WPINV_GEOIP2_LODDED' ) ) { |
|
| 470 | + if (defined('WPINV_GEOIP2_LODDED')) { |
|
| 471 | 471 | return; |
| 472 | 472 | } |
| 473 | 473 | |
| 474 | - if ( !class_exists( '\MaxMind\Db\Reader' ) ) { |
|
| 474 | + if (!class_exists('\MaxMind\Db\Reader')) { |
|
| 475 | 475 | $maxmind_db_files = array( |
| 476 | 476 | 'Reader/Decoder.php', |
| 477 | 477 | 'Reader/InvalidDatabaseException.php', |
@@ -480,12 +480,12 @@ discard block |
||
| 480 | 480 | 'Reader.php', |
| 481 | 481 | ); |
| 482 | 482 | |
| 483 | - foreach ( $maxmind_db_files as $key => $file ) { |
|
| 484 | - require_once( WPINV_PLUGIN_DIR . 'includes/libraries/MaxMind/Db/' . $file ); |
|
| 483 | + foreach ($maxmind_db_files as $key => $file) { |
|
| 484 | + require_once(WPINV_PLUGIN_DIR . 'includes/libraries/MaxMind/Db/' . $file); |
|
| 485 | 485 | } |
| 486 | 486 | } |
| 487 | 487 | |
| 488 | - if ( !class_exists( '\GeoIp2\Database\Reader' ) ) { |
|
| 488 | + if (!class_exists('\GeoIp2\Database\Reader')) { |
|
| 489 | 489 | $geoip2_files = array( |
| 490 | 490 | 'ProviderInterface.php', |
| 491 | 491 | 'Compat/JsonSerializable.php', |
@@ -519,23 +519,23 @@ discard block |
||
| 519 | 519 | 'WebService/Client.php', |
| 520 | 520 | ); |
| 521 | 521 | |
| 522 | - foreach ( $geoip2_files as $key => $file ) { |
|
| 523 | - require_once( WPINV_PLUGIN_DIR . 'includes/libraries/GeoIp2/' . $file ); |
|
| 522 | + foreach ($geoip2_files as $key => $file) { |
|
| 523 | + require_once(WPINV_PLUGIN_DIR . 'includes/libraries/GeoIp2/' . $file); |
|
| 524 | 524 | } |
| 525 | 525 | } |
| 526 | 526 | |
| 527 | - define( 'WPINV_GEOIP2_LODDED', true ); |
|
| 527 | + define('WPINV_GEOIP2_LODDED', true); |
|
| 528 | 528 | } |
| 529 | 529 | |
| 530 | 530 | public static function geoip2_country_dbfile() { |
| 531 | 531 | $upload_dir = wp_upload_dir(); |
| 532 | 532 | |
| 533 | - if ( !isset( $upload_dir['basedir'] ) ) { |
|
| 533 | + if (!isset($upload_dir['basedir'])) { |
|
| 534 | 534 | return false; |
| 535 | 535 | } |
| 536 | 536 | |
| 537 | 537 | $filename = $upload_dir['basedir'] . '/invoicing/GeoLite2-Country.mmdb'; |
| 538 | - if ( !file_exists( $filename ) ) { |
|
| 538 | + if (!file_exists($filename)) { |
|
| 539 | 539 | return false; |
| 540 | 540 | } |
| 541 | 541 | |
@@ -545,12 +545,12 @@ discard block |
||
| 545 | 545 | public static function geoip2_city_dbfile() { |
| 546 | 546 | $upload_dir = wp_upload_dir(); |
| 547 | 547 | |
| 548 | - if ( !isset( $upload_dir['basedir'] ) ) { |
|
| 548 | + if (!isset($upload_dir['basedir'])) { |
|
| 549 | 549 | return false; |
| 550 | 550 | } |
| 551 | 551 | |
| 552 | 552 | $filename = $upload_dir['basedir'] . '/invoicing/GeoLite2-City.mmdb'; |
| 553 | - if ( !file_exists( $filename ) ) { |
|
| 553 | + if (!file_exists($filename)) { |
|
| 554 | 554 | return false; |
| 555 | 555 | } |
| 556 | 556 | |
@@ -561,10 +561,10 @@ discard block |
||
| 561 | 561 | try { |
| 562 | 562 | self::load_geoip2(); |
| 563 | 563 | |
| 564 | - if ( $filename = self::geoip2_country_dbfile() ) { |
|
| 565 | - return new \GeoIp2\Database\Reader( $filename ); |
|
| 564 | + if ($filename = self::geoip2_country_dbfile()) { |
|
| 565 | + return new \GeoIp2\Database\Reader($filename); |
|
| 566 | 566 | } |
| 567 | - } catch( Exception $e ) { |
|
| 567 | + } catch (Exception $e) { |
|
| 568 | 568 | return false; |
| 569 | 569 | } |
| 570 | 570 | |
@@ -575,173 +575,173 @@ discard block |
||
| 575 | 575 | try { |
| 576 | 576 | self::load_geoip2(); |
| 577 | 577 | |
| 578 | - if ( $filename = self::geoip2_city_dbfile() ) { |
|
| 579 | - return new \GeoIp2\Database\Reader( $filename ); |
|
| 578 | + if ($filename = self::geoip2_city_dbfile()) { |
|
| 579 | + return new \GeoIp2\Database\Reader($filename); |
|
| 580 | 580 | } |
| 581 | - } catch( Exception $e ) { |
|
| 581 | + } catch (Exception $e) { |
|
| 582 | 582 | return false; |
| 583 | 583 | } |
| 584 | 584 | |
| 585 | 585 | return false; |
| 586 | 586 | } |
| 587 | 587 | |
| 588 | - public static function geoip2_country_record( $ip_address ) { |
|
| 588 | + public static function geoip2_country_record($ip_address) { |
|
| 589 | 589 | try { |
| 590 | 590 | $reader = self::geoip2_country_reader(); |
| 591 | 591 | |
| 592 | - if ( $reader ) { |
|
| 593 | - $record = $reader->country( $ip_address ); |
|
| 592 | + if ($reader) { |
|
| 593 | + $record = $reader->country($ip_address); |
|
| 594 | 594 | |
| 595 | - if ( !empty( $record->country->isoCode ) ) { |
|
| 595 | + if (!empty($record->country->isoCode)) { |
|
| 596 | 596 | return $record; |
| 597 | 597 | } |
| 598 | 598 | } |
| 599 | - } catch(\InvalidArgumentException $e) { |
|
| 600 | - wpinv_error_log( $e->getMessage(), 'GeoIp2 Lookup( ' . $ip_address . ' )' ); |
|
| 599 | + } catch (\InvalidArgumentException $e) { |
|
| 600 | + wpinv_error_log($e->getMessage(), 'GeoIp2 Lookup( ' . $ip_address . ' )'); |
|
| 601 | 601 | |
| 602 | 602 | return false; |
| 603 | - } catch(\GeoIp2\Exception\AddressNotFoundException $e) { |
|
| 604 | - wpinv_error_log( $e->getMessage(), 'GeoIp2 Lookup( ' . $ip_address . ' )' ); |
|
| 603 | + } catch (\GeoIp2\Exception\AddressNotFoundException $e) { |
|
| 604 | + wpinv_error_log($e->getMessage(), 'GeoIp2 Lookup( ' . $ip_address . ' )'); |
|
| 605 | 605 | |
| 606 | 606 | return false; |
| 607 | - } catch( Exception $e ) { |
|
| 607 | + } catch (Exception $e) { |
|
| 608 | 608 | return false; |
| 609 | 609 | } |
| 610 | 610 | |
| 611 | 611 | return false; |
| 612 | 612 | } |
| 613 | 613 | |
| 614 | - public static function geoip2_city_record( $ip_address ) { |
|
| 614 | + public static function geoip2_city_record($ip_address) { |
|
| 615 | 615 | try { |
| 616 | 616 | $reader = self::geoip2_city_reader(); |
| 617 | 617 | |
| 618 | - if ( $reader ) { |
|
| 619 | - $record = $reader->city( $ip_address ); |
|
| 618 | + if ($reader) { |
|
| 619 | + $record = $reader->city($ip_address); |
|
| 620 | 620 | |
| 621 | - if ( !empty( $record->country->isoCode ) ) { |
|
| 621 | + if (!empty($record->country->isoCode)) { |
|
| 622 | 622 | return $record; |
| 623 | 623 | } |
| 624 | 624 | } |
| 625 | - } catch(\InvalidArgumentException $e) { |
|
| 626 | - wpinv_error_log( $e->getMessage(), 'GeoIp2 Lookup( ' . $ip_address . ' )' ); |
|
| 625 | + } catch (\InvalidArgumentException $e) { |
|
| 626 | + wpinv_error_log($e->getMessage(), 'GeoIp2 Lookup( ' . $ip_address . ' )'); |
|
| 627 | 627 | |
| 628 | 628 | return false; |
| 629 | - } catch(\GeoIp2\Exception\AddressNotFoundException $e) { |
|
| 630 | - wpinv_error_log( $e->getMessage(), 'GeoIp2 Lookup( ' . $ip_address . ' )' ); |
|
| 629 | + } catch (\GeoIp2\Exception\AddressNotFoundException $e) { |
|
| 630 | + wpinv_error_log($e->getMessage(), 'GeoIp2 Lookup( ' . $ip_address . ' )'); |
|
| 631 | 631 | |
| 632 | 632 | return false; |
| 633 | - } catch( Exception $e ) { |
|
| 633 | + } catch (Exception $e) { |
|
| 634 | 634 | return false; |
| 635 | 635 | } |
| 636 | 636 | |
| 637 | 637 | return false; |
| 638 | 638 | } |
| 639 | 639 | |
| 640 | - public static function geoip2_country_code( $ip_address ) { |
|
| 641 | - $record = self::geoip2_country_record( $ip_address ); |
|
| 642 | - return !empty( $record->country->isoCode ) ? $record->country->isoCode : wpinv_get_default_country(); |
|
| 640 | + public static function geoip2_country_code($ip_address) { |
|
| 641 | + $record = self::geoip2_country_record($ip_address); |
|
| 642 | + return !empty($record->country->isoCode) ? $record->country->isoCode : wpinv_get_default_country(); |
|
| 643 | 643 | } |
| 644 | 644 | |
| 645 | 645 | // Find country by IP address. |
| 646 | - public static function get_country_by_ip( $ip = '' ) { |
|
| 646 | + public static function get_country_by_ip($ip = '') { |
|
| 647 | 647 | global $wpinv_ip_address_country; |
| 648 | 648 | |
| 649 | - if ( !empty( $wpinv_ip_address_country ) ) { |
|
| 649 | + if (!empty($wpinv_ip_address_country)) { |
|
| 650 | 650 | return $wpinv_ip_address_country; |
| 651 | 651 | } |
| 652 | 652 | |
| 653 | - if ( empty( $ip ) ) { |
|
| 653 | + if (empty($ip)) { |
|
| 654 | 654 | $ip = wpinv_get_ip(); |
| 655 | 655 | } |
| 656 | 656 | |
| 657 | - $ip_country_service = wpinv_get_option( 'vat_ip_lookup' ); |
|
| 658 | - $is_default = empty( $ip_country_service ) || $ip_country_service === 'default' ? true : false; |
|
| 657 | + $ip_country_service = wpinv_get_option('vat_ip_lookup'); |
|
| 658 | + $is_default = empty($ip_country_service) || $ip_country_service === 'default' ? true : false; |
|
| 659 | 659 | |
| 660 | - if ( !empty( $ip ) && $ip !== '127.0.0.1' ) { // For 127.0.0.1(localhost) use default country. |
|
| 661 | - if ( function_exists( 'geoip_country_code_by_name') && ( $ip_country_service === 'geoip' || $is_default ) ) { |
|
| 660 | + if (!empty($ip) && $ip !== '127.0.0.1') { // For 127.0.0.1(localhost) use default country. |
|
| 661 | + if (function_exists('geoip_country_code_by_name') && ($ip_country_service === 'geoip' || $is_default)) { |
|
| 662 | 662 | try { |
| 663 | - $wpinv_ip_address_country = geoip_country_code_by_name( $ip ); |
|
| 664 | - } catch( Exception $e ) { |
|
| 665 | - wpinv_error_log( $e->getMessage(), 'GeoIP Lookup( ' . $ip . ' )' ); |
|
| 663 | + $wpinv_ip_address_country = geoip_country_code_by_name($ip); |
|
| 664 | + } catch (Exception $e) { |
|
| 665 | + wpinv_error_log($e->getMessage(), 'GeoIP Lookup( ' . $ip . ' )'); |
|
| 666 | 666 | } |
| 667 | - } else if ( self::geoip2_country_dbfile() && ( $ip_country_service === 'geoip2' || $is_default ) ) { |
|
| 668 | - $wpinv_ip_address_country = self::geoip2_country_code( $ip ); |
|
| 669 | - } else if ( function_exists( 'simplexml_load_file' ) && ( $ip_country_service === 'geoplugin' || $is_default ) ) { |
|
| 670 | - $load_xml = simplexml_load_file( 'http://www.geoplugin.net/xml.gp?ip=' . $ip ); |
|
| 667 | + } else if (self::geoip2_country_dbfile() && ($ip_country_service === 'geoip2' || $is_default)) { |
|
| 668 | + $wpinv_ip_address_country = self::geoip2_country_code($ip); |
|
| 669 | + } else if (function_exists('simplexml_load_file') && ($ip_country_service === 'geoplugin' || $is_default)) { |
|
| 670 | + $load_xml = simplexml_load_file('http://www.geoplugin.net/xml.gp?ip=' . $ip); |
|
| 671 | 671 | |
| 672 | - if ( !empty( $load_xml ) && !empty( $load_xml->geoplugin_countryCode ) ) { |
|
| 672 | + if (!empty($load_xml) && !empty($load_xml->geoplugin_countryCode)) { |
|
| 673 | 673 | $wpinv_ip_address_country = (string)$load_xml->geoplugin_countryCode; |
| 674 | 674 | } |
| 675 | 675 | } |
| 676 | 676 | } |
| 677 | 677 | |
| 678 | - if ( empty( $wpinv_ip_address_country ) ) { |
|
| 678 | + if (empty($wpinv_ip_address_country)) { |
|
| 679 | 679 | $wpinv_ip_address_country = wpinv_get_default_country(); |
| 680 | 680 | } |
| 681 | 681 | |
| 682 | 682 | return $wpinv_ip_address_country; |
| 683 | 683 | } |
| 684 | 684 | |
| 685 | - public static function sanitize_vat_settings( $input ) { |
|
| 685 | + public static function sanitize_vat_settings($input) { |
|
| 686 | 686 | global $wpinv_options; |
| 687 | 687 | |
| 688 | 688 | $valid = false; |
| 689 | 689 | $message = ''; |
| 690 | 690 | |
| 691 | - if ( !empty( $wpinv_options['vat_vies_check'] ) ) { |
|
| 692 | - if ( empty( $wpinv_options['vat_offline_check'] ) ) { |
|
| 693 | - $valid = self::offline_check( $input['vat_number'] ); |
|
| 691 | + if (!empty($wpinv_options['vat_vies_check'])) { |
|
| 692 | + if (empty($wpinv_options['vat_offline_check'])) { |
|
| 693 | + $valid = self::offline_check($input['vat_number']); |
|
| 694 | 694 | } else { |
| 695 | 695 | $valid = true; |
| 696 | 696 | } |
| 697 | 697 | |
| 698 | - $message = $valid ? '' : __( 'VAT number not validated', 'invoicing' ); |
|
| 698 | + $message = $valid ? '' : __('VAT number not validated', 'invoicing'); |
|
| 699 | 699 | } else { |
| 700 | - $result = self::check_vat( $input['vat_number'] ); |
|
| 700 | + $result = self::check_vat($input['vat_number']); |
|
| 701 | 701 | |
| 702 | - if ( empty( $result['valid'] ) ) { |
|
| 702 | + if (empty($result['valid'])) { |
|
| 703 | 703 | $valid = false; |
| 704 | 704 | $message = $result['message']; |
| 705 | 705 | } else { |
| 706 | - $valid = ( isset( $result['company'] ) && ( $result['company'] == '---' || ( strcasecmp( trim( $result['company'] ), trim( $input['vat_company_name'] ) ) == 0 ) ) ) || !empty( $wpinv_options['vat_disable_company_name_check'] ); |
|
| 707 | - $message = $valid ? '' : __( 'The company name associated with the VAT number provided is not the same as the company name provided.', 'invoicing' ); |
|
| 706 | + $valid = (isset($result['company']) && ($result['company'] == '---' || (strcasecmp(trim($result['company']), trim($input['vat_company_name'])) == 0))) || !empty($wpinv_options['vat_disable_company_name_check']); |
|
| 707 | + $message = $valid ? '' : __('The company name associated with the VAT number provided is not the same as the company name provided.', 'invoicing'); |
|
| 708 | 708 | } |
| 709 | 709 | } |
| 710 | 710 | |
| 711 | - if ( $message && self::is_vat_validated() != $valid ) { |
|
| 712 | - add_settings_error( 'wpinv-notices', '', $message, ( $valid ? 'updated' : 'error' ) ); |
|
| 711 | + if ($message && self::is_vat_validated() != $valid) { |
|
| 712 | + add_settings_error('wpinv-notices', '', $message, ($valid ? 'updated' : 'error')); |
|
| 713 | 713 | } |
| 714 | 714 | |
| 715 | 715 | $input['vat_valid'] = $valid; |
| 716 | 716 | return $input; |
| 717 | 717 | } |
| 718 | 718 | |
| 719 | - public static function sanitize_vat_rates( $input ) { |
|
| 720 | - if( !current_user_can( 'manage_options' ) ) { |
|
| 721 | - add_settings_error( 'wpinv-notices', '', __( 'Your account does not have permission to add rate classes.', 'invoicing' ), 'error' ); |
|
| 719 | + public static function sanitize_vat_rates($input) { |
|
| 720 | + if (!current_user_can('manage_options')) { |
|
| 721 | + add_settings_error('wpinv-notices', '', __('Your account does not have permission to add rate classes.', 'invoicing'), 'error'); |
|
| 722 | 722 | return $input; |
| 723 | 723 | } |
| 724 | 724 | |
| 725 | 725 | $vat_classes = self::get_rate_classes(); |
| 726 | - $vat_class = !empty( $_REQUEST['wpi_vat_class'] ) && isset( $vat_classes[$_REQUEST['wpi_vat_class']] )? sanitize_text_field( $_REQUEST['wpi_vat_class'] ) : ''; |
|
| 726 | + $vat_class = !empty($_REQUEST['wpi_vat_class']) && isset($vat_classes[$_REQUEST['wpi_vat_class']]) ? sanitize_text_field($_REQUEST['wpi_vat_class']) : ''; |
|
| 727 | 727 | |
| 728 | - if ( empty( $vat_class ) ) { |
|
| 729 | - add_settings_error( 'wpinv-notices', '', __( 'No valid VAT rates class contained in the request to save rates.', 'invoicing' ), 'error' ); |
|
| 728 | + if (empty($vat_class)) { |
|
| 729 | + add_settings_error('wpinv-notices', '', __('No valid VAT rates class contained in the request to save rates.', 'invoicing'), 'error'); |
|
| 730 | 730 | |
| 731 | 731 | return $input; |
| 732 | 732 | } |
| 733 | 733 | |
| 734 | - $new_rates = ! empty( $_POST['vat_rates'] ) ? array_values( $_POST['vat_rates'] ) : array(); |
|
| 734 | + $new_rates = !empty($_POST['vat_rates']) ? array_values($_POST['vat_rates']) : array(); |
|
| 735 | 735 | |
| 736 | - if ( $vat_class === '_standard' ) { |
|
| 736 | + if ($vat_class === '_standard') { |
|
| 737 | 737 | // Save the active rates in the invoice settings |
| 738 | - update_option( 'wpinv_tax_rates', $new_rates ); |
|
| 738 | + update_option('wpinv_tax_rates', $new_rates); |
|
| 739 | 739 | } else { |
| 740 | 740 | // Get the existing set of rates |
| 741 | 741 | $rates = self::get_non_standard_rates(); |
| 742 | 742 | $rates[$vat_class] = $new_rates; |
| 743 | 743 | |
| 744 | - update_option( 'wpinv_vat_rates', $rates ); |
|
| 744 | + update_option('wpinv_vat_rates', $rates); |
|
| 745 | 745 | } |
| 746 | 746 | |
| 747 | 747 | return $input; |
@@ -751,71 +751,71 @@ discard block |
||
| 751 | 751 | $response = array(); |
| 752 | 752 | $response['success'] = false; |
| 753 | 753 | |
| 754 | - if ( !current_user_can( 'manage_options' ) ) { |
|
| 755 | - $response['error'] = __( 'Invalid access!', 'invoicing' ); |
|
| 756 | - wp_send_json( $response ); |
|
| 754 | + if (!current_user_can('manage_options')) { |
|
| 755 | + $response['error'] = __('Invalid access!', 'invoicing'); |
|
| 756 | + wp_send_json($response); |
|
| 757 | 757 | } |
| 758 | 758 | |
| 759 | - $vat_class_name = !empty( $_POST['name'] ) ? sanitize_text_field( $_POST['name'] ) : false; |
|
| 760 | - $vat_class_desc = !empty( $_POST['desc'] ) ? sanitize_text_field( $_POST['desc'] ) : false; |
|
| 759 | + $vat_class_name = !empty($_POST['name']) ? sanitize_text_field($_POST['name']) : false; |
|
| 760 | + $vat_class_desc = !empty($_POST['desc']) ? sanitize_text_field($_POST['desc']) : false; |
|
| 761 | 761 | |
| 762 | - if ( empty( $vat_class_name ) ) { |
|
| 763 | - $response['error'] = __( 'Select the VAT rate name', 'invoicing' ); |
|
| 764 | - wp_send_json( $response ); |
|
| 762 | + if (empty($vat_class_name)) { |
|
| 763 | + $response['error'] = __('Select the VAT rate name', 'invoicing'); |
|
| 764 | + wp_send_json($response); |
|
| 765 | 765 | } |
| 766 | 766 | |
| 767 | 767 | $vat_classes = (array)self::get_rate_classes(); |
| 768 | 768 | |
| 769 | - if ( !empty( $vat_classes ) && in_array( strtolower( $vat_class_name ), array_map( 'strtolower', array_values( $vat_classes ) ) ) ) { |
|
| 770 | - $response['error'] = wp_sprintf( __( 'A VAT Rate name "%s" already exists', 'invoicing' ), $vat_class_name ); |
|
| 771 | - wp_send_json( $response ); |
|
| 769 | + if (!empty($vat_classes) && in_array(strtolower($vat_class_name), array_map('strtolower', array_values($vat_classes)))) { |
|
| 770 | + $response['error'] = wp_sprintf(__('A VAT Rate name "%s" already exists', 'invoicing'), $vat_class_name); |
|
| 771 | + wp_send_json($response); |
|
| 772 | 772 | } |
| 773 | 773 | |
| 774 | - $rate_class_key = normalize_whitespace( 'wpi-' . $vat_class_name ); |
|
| 775 | - $rate_class_key = sanitize_key( str_replace( " ", "-", $rate_class_key ) ); |
|
| 774 | + $rate_class_key = normalize_whitespace('wpi-' . $vat_class_name); |
|
| 775 | + $rate_class_key = sanitize_key(str_replace(" ", "-", $rate_class_key)); |
|
| 776 | 776 | |
| 777 | - $vat_classes = (array)self::get_rate_classes( true ); |
|
| 778 | - $vat_classes[$rate_class_key] = array( 'name' => $vat_class_name, 'desc' => $vat_class_desc ); |
|
| 777 | + $vat_classes = (array)self::get_rate_classes(true); |
|
| 778 | + $vat_classes[$rate_class_key] = array('name' => $vat_class_name, 'desc' => $vat_class_desc); |
|
| 779 | 779 | |
| 780 | - update_option( '_wpinv_vat_rate_classes', $vat_classes ); |
|
| 780 | + update_option('_wpinv_vat_rate_classes', $vat_classes); |
|
| 781 | 781 | |
| 782 | 782 | $response['success'] = true; |
| 783 | - $response['redirect'] = admin_url( 'admin.php?page=wpinv-settings&tab=taxes§ion=vat_rates&wpi_sub=' . $rate_class_key ); |
|
| 783 | + $response['redirect'] = admin_url('admin.php?page=wpinv-settings&tab=taxes§ion=vat_rates&wpi_sub=' . $rate_class_key); |
|
| 784 | 784 | |
| 785 | - wp_send_json( $response ); |
|
| 785 | + wp_send_json($response); |
|
| 786 | 786 | } |
| 787 | 787 | |
| 788 | 788 | public static function delete_class() { |
| 789 | 789 | $response = array(); |
| 790 | 790 | $response['success'] = false; |
| 791 | 791 | |
| 792 | - if ( !current_user_can( 'manage_options' ) || !isset( $_POST['class'] ) ) { |
|
| 793 | - $response['error'] = __( 'Invalid access!', 'invoicing' ); |
|
| 794 | - wp_send_json( $response ); |
|
| 792 | + if (!current_user_can('manage_options') || !isset($_POST['class'])) { |
|
| 793 | + $response['error'] = __('Invalid access!', 'invoicing'); |
|
| 794 | + wp_send_json($response); |
|
| 795 | 795 | } |
| 796 | 796 | |
| 797 | - $vat_class = isset( $_POST['class'] ) && $_POST['class'] !== '' ? sanitize_text_field( $_POST['class'] ) : false; |
|
| 797 | + $vat_class = isset($_POST['class']) && $_POST['class'] !== '' ? sanitize_text_field($_POST['class']) : false; |
|
| 798 | 798 | $vat_classes = (array)self::get_rate_classes(); |
| 799 | 799 | |
| 800 | - if ( !isset( $vat_classes[$vat_class] ) ) { |
|
| 801 | - $response['error'] = __( 'Requested class does not exists', 'invoicing' ); |
|
| 802 | - wp_send_json( $response ); |
|
| 800 | + if (!isset($vat_classes[$vat_class])) { |
|
| 801 | + $response['error'] = __('Requested class does not exists', 'invoicing'); |
|
| 802 | + wp_send_json($response); |
|
| 803 | 803 | } |
| 804 | 804 | |
| 805 | - if ( $vat_class == '_new' || $vat_class == '_standard' ) { |
|
| 806 | - $response['error'] = __( 'You can not delete standard rates class', 'invoicing' ); |
|
| 807 | - wp_send_json( $response ); |
|
| 805 | + if ($vat_class == '_new' || $vat_class == '_standard') { |
|
| 806 | + $response['error'] = __('You can not delete standard rates class', 'invoicing'); |
|
| 807 | + wp_send_json($response); |
|
| 808 | 808 | } |
| 809 | 809 | |
| 810 | - $vat_classes = (array)self::get_rate_classes( true ); |
|
| 811 | - unset( $vat_classes[$vat_class] ); |
|
| 810 | + $vat_classes = (array)self::get_rate_classes(true); |
|
| 811 | + unset($vat_classes[$vat_class]); |
|
| 812 | 812 | |
| 813 | - update_option( '_wpinv_vat_rate_classes', $vat_classes ); |
|
| 813 | + update_option('_wpinv_vat_rate_classes', $vat_classes); |
|
| 814 | 814 | |
| 815 | 815 | $response['success'] = true; |
| 816 | - $response['redirect'] = admin_url( 'admin.php?page=wpinv-settings&tab=taxes§ion=vat_rates&wpi_sub=_new' ); |
|
| 816 | + $response['redirect'] = admin_url('admin.php?page=wpinv-settings&tab=taxes§ion=vat_rates&wpi_sub=_new'); |
|
| 817 | 817 | |
| 818 | - wp_send_json( $response ); |
|
| 818 | + wp_send_json($response); |
|
| 819 | 819 | } |
| 820 | 820 | |
| 821 | 821 | public static function update_eu_rates() { |
@@ -824,72 +824,72 @@ discard block |
||
| 824 | 824 | $response['error'] = null; |
| 825 | 825 | $response['data'] = null; |
| 826 | 826 | |
| 827 | - if ( !current_user_can( 'manage_options' ) ) { |
|
| 828 | - $response['error'] = __( 'Invalid access!', 'invoicing' ); |
|
| 829 | - wp_send_json( $response ); |
|
| 827 | + if (!current_user_can('manage_options')) { |
|
| 828 | + $response['error'] = __('Invalid access!', 'invoicing'); |
|
| 829 | + wp_send_json($response); |
|
| 830 | 830 | } |
| 831 | 831 | |
| 832 | - $group = !empty( $_POST['group'] ) ? sanitize_text_field( $_POST['group'] ) : ''; |
|
| 833 | - $euvatrates = self::request_euvatrates( $group ); |
|
| 832 | + $group = !empty($_POST['group']) ? sanitize_text_field($_POST['group']) : ''; |
|
| 833 | + $euvatrates = self::request_euvatrates($group); |
|
| 834 | 834 | |
| 835 | - if ( !empty( $euvatrates ) ) { |
|
| 836 | - if ( !empty( $euvatrates['success'] ) && !empty( $euvatrates['rates'] ) ) { |
|
| 835 | + if (!empty($euvatrates)) { |
|
| 836 | + if (!empty($euvatrates['success']) && !empty($euvatrates['rates'])) { |
|
| 837 | 837 | $response['success'] = true; |
| 838 | 838 | $response['data']['rates'] = $euvatrates['rates']; |
| 839 | - } else if ( !empty( $euvatrates['error'] ) ) { |
|
| 839 | + } else if (!empty($euvatrates['error'])) { |
|
| 840 | 840 | $response['error'] = $euvatrates['error']; |
| 841 | 841 | } |
| 842 | 842 | } |
| 843 | 843 | |
| 844 | - wp_send_json( $response ); |
|
| 844 | + wp_send_json($response); |
|
| 845 | 845 | } |
| 846 | 846 | |
| 847 | 847 | public static function hide_vat_fields() { |
| 848 | - $hide = wpinv_get_option( 'vat_disable_fields' ); |
|
| 848 | + $hide = wpinv_get_option('vat_disable_fields'); |
|
| 849 | 849 | |
| 850 | - return apply_filters( 'wpinv_hide_vat_fields', $hide ); |
|
| 850 | + return apply_filters('wpinv_hide_vat_fields', $hide); |
|
| 851 | 851 | } |
| 852 | 852 | |
| 853 | 853 | public static function same_country_rule() { |
| 854 | - $same_country_rule = wpinv_get_option( 'vat_same_country_rule' ); |
|
| 854 | + $same_country_rule = wpinv_get_option('vat_same_country_rule'); |
|
| 855 | 855 | |
| 856 | - return apply_filters( 'wpinv_vat_same_country_rule', $same_country_rule ); |
|
| 856 | + return apply_filters('wpinv_vat_same_country_rule', $same_country_rule); |
|
| 857 | 857 | } |
| 858 | 858 | |
| 859 | 859 | public static function get_vat_name() { |
| 860 | - $vat_name = wpinv_get_option( 'vat_name' ); |
|
| 861 | - $vat_name = !empty( $vat_name ) ? $vat_name : 'VAT'; |
|
| 860 | + $vat_name = wpinv_get_option('vat_name'); |
|
| 861 | + $vat_name = !empty($vat_name) ? $vat_name : 'VAT'; |
|
| 862 | 862 | |
| 863 | - return apply_filters( 'wpinv_get_owner_vat_name', $vat_name ); |
|
| 863 | + return apply_filters('wpinv_get_owner_vat_name', $vat_name); |
|
| 864 | 864 | } |
| 865 | 865 | |
| 866 | 866 | public static function get_company_name() { |
| 867 | - $company_name = wpinv_get_option( 'vat_company_name' ); |
|
| 867 | + $company_name = wpinv_get_option('vat_company_name'); |
|
| 868 | 868 | |
| 869 | - return apply_filters( 'wpinv_get_owner_company_name', $company_name ); |
|
| 869 | + return apply_filters('wpinv_get_owner_company_name', $company_name); |
|
| 870 | 870 | } |
| 871 | 871 | |
| 872 | 872 | public static function get_vat_number() { |
| 873 | - $vat_number = wpinv_get_option( 'vat_number' ); |
|
| 873 | + $vat_number = wpinv_get_option('vat_number'); |
|
| 874 | 874 | |
| 875 | - return apply_filters( 'wpinv_get_owner_vat_number', $vat_number ); |
|
| 875 | + return apply_filters('wpinv_get_owner_vat_number', $vat_number); |
|
| 876 | 876 | } |
| 877 | 877 | |
| 878 | 878 | public static function is_vat_validated() { |
| 879 | - $validated = self::get_vat_number() && wpinv_get_option( 'vat_valid' ); |
|
| 879 | + $validated = self::get_vat_number() && wpinv_get_option('vat_valid'); |
|
| 880 | 880 | |
| 881 | - return apply_filters( 'wpinv_is_owner_vat_validated', $validated ); |
|
| 881 | + return apply_filters('wpinv_is_owner_vat_validated', $validated); |
|
| 882 | 882 | } |
| 883 | 883 | |
| 884 | - public static function sanitize_vat( $vat_number, $country_code = '' ) { |
|
| 885 | - $vat_number = str_replace( array(' ', '.', '-', '_', ',' ), '', strtoupper( trim( $vat_number ) ) ); |
|
| 884 | + public static function sanitize_vat($vat_number, $country_code = '') { |
|
| 885 | + $vat_number = str_replace(array(' ', '.', '-', '_', ','), '', strtoupper(trim($vat_number))); |
|
| 886 | 886 | |
| 887 | - if ( empty( $country_code ) ) { |
|
| 888 | - $country_code = substr( $vat_number, 0, 2 ); |
|
| 887 | + if (empty($country_code)) { |
|
| 888 | + $country_code = substr($vat_number, 0, 2); |
|
| 889 | 889 | } |
| 890 | 890 | |
| 891 | - if ( strpos( $vat_number , $country_code ) === 0 ) { |
|
| 892 | - $vat = str_replace( $country_code, '', $vat_number ); |
|
| 891 | + if (strpos($vat_number, $country_code) === 0) { |
|
| 892 | + $vat = str_replace($country_code, '', $vat_number); |
|
| 893 | 893 | } else { |
| 894 | 894 | $vat = $country_code . $vat_number; |
| 895 | 895 | } |
@@ -902,140 +902,140 @@ discard block |
||
| 902 | 902 | return $return; |
| 903 | 903 | } |
| 904 | 904 | |
| 905 | - public static function offline_check( $vat_number, $country_code = '', $formatted = false ) { |
|
| 906 | - $vat = self::sanitize_vat( $vat_number, $country_code ); |
|
| 905 | + public static function offline_check($vat_number, $country_code = '', $formatted = false) { |
|
| 906 | + $vat = self::sanitize_vat($vat_number, $country_code); |
|
| 907 | 907 | $vat_number = $vat['vat_number']; |
| 908 | 908 | $country_code = $vat['iso']; |
| 909 | 909 | $regex = array(); |
| 910 | 910 | |
| 911 | - switch ( $country_code ) { |
|
| 911 | + switch ($country_code) { |
|
| 912 | 912 | case 'AT': |
| 913 | - $regex[] = '/^(AT)U(\d{8})$/'; // Austria |
|
| 913 | + $regex[] = '/^(AT)U(\d{8})$/'; // Austria |
|
| 914 | 914 | break; |
| 915 | 915 | case 'BE': |
| 916 | - $regex[] = '/^(BE)(0?\d{9})$/'; // Belgium |
|
| 916 | + $regex[] = '/^(BE)(0?\d{9})$/'; // Belgium |
|
| 917 | 917 | break; |
| 918 | 918 | case 'BG': |
| 919 | - $regex[] = '/^(BG)(\d{9,10})$/'; // Bulgaria |
|
| 919 | + $regex[] = '/^(BG)(\d{9,10})$/'; // Bulgaria |
|
| 920 | 920 | break; |
| 921 | 921 | case 'CH': |
| 922 | 922 | case 'CHE': |
| 923 | - $regex[] = '/^(CHE)(\d{9})MWST$/'; // Switzerland (Not EU) |
|
| 923 | + $regex[] = '/^(CHE)(\d{9})MWST$/'; // Switzerland (Not EU) |
|
| 924 | 924 | break; |
| 925 | 925 | case 'CY': |
| 926 | - $regex[] = '/^(CY)([0-5|9]\d{7}[A-Z])$/'; // Cyprus |
|
| 926 | + $regex[] = '/^(CY)([0-5|9]\d{7}[A-Z])$/'; // Cyprus |
|
| 927 | 927 | break; |
| 928 | 928 | case 'CZ': |
| 929 | - $regex[] = '/^(CZ)(\d{8,13})$/'; // Czech Republic |
|
| 929 | + $regex[] = '/^(CZ)(\d{8,13})$/'; // Czech Republic |
|
| 930 | 930 | break; |
| 931 | 931 | case 'DE': |
| 932 | - $regex[] = '/^(DE)([1-9]\d{8})$/'; // Germany |
|
| 932 | + $regex[] = '/^(DE)([1-9]\d{8})$/'; // Germany |
|
| 933 | 933 | break; |
| 934 | 934 | case 'DK': |
| 935 | - $regex[] = '/^(DK)(\d{8})$/'; // Denmark |
|
| 935 | + $regex[] = '/^(DK)(\d{8})$/'; // Denmark |
|
| 936 | 936 | break; |
| 937 | 937 | case 'EE': |
| 938 | - $regex[] = '/^(EE)(10\d{7})$/'; // Estonia |
|
| 938 | + $regex[] = '/^(EE)(10\d{7})$/'; // Estonia |
|
| 939 | 939 | break; |
| 940 | 940 | case 'EL': |
| 941 | - $regex[] = '/^(EL)(\d{9})$/'; // Greece |
|
| 941 | + $regex[] = '/^(EL)(\d{9})$/'; // Greece |
|
| 942 | 942 | break; |
| 943 | 943 | case 'ES': |
| 944 | - $regex[] = '/^(ES)([A-Z]\d{8})$/'; // Spain (National juridical entities) |
|
| 945 | - $regex[] = '/^(ES)([A-H|N-S|W]\d{7}[A-J])$/'; // Spain (Other juridical entities) |
|
| 946 | - $regex[] = '/^(ES)([0-9|Y|Z]\d{7}[A-Z])$/'; // Spain (Personal entities type 1) |
|
| 947 | - $regex[] = '/^(ES)([K|L|M|X]\d{7}[A-Z])$/'; // Spain (Personal entities type 2) |
|
| 944 | + $regex[] = '/^(ES)([A-Z]\d{8})$/'; // Spain (National juridical entities) |
|
| 945 | + $regex[] = '/^(ES)([A-H|N-S|W]\d{7}[A-J])$/'; // Spain (Other juridical entities) |
|
| 946 | + $regex[] = '/^(ES)([0-9|Y|Z]\d{7}[A-Z])$/'; // Spain (Personal entities type 1) |
|
| 947 | + $regex[] = '/^(ES)([K|L|M|X]\d{7}[A-Z])$/'; // Spain (Personal entities type 2) |
|
| 948 | 948 | break; |
| 949 | 949 | case 'EU': |
| 950 | - $regex[] = '/^(EU)(\d{9})$/'; // EU-type |
|
| 950 | + $regex[] = '/^(EU)(\d{9})$/'; // EU-type |
|
| 951 | 951 | break; |
| 952 | 952 | case 'FI': |
| 953 | - $regex[] = '/^(FI)(\d{8})$/'; // Finland |
|
| 953 | + $regex[] = '/^(FI)(\d{8})$/'; // Finland |
|
| 954 | 954 | break; |
| 955 | 955 | case 'FR': |
| 956 | - $regex[] = '/^(FR)(\d{11})$/'; // France (1) |
|
| 957 | - $regex[] = '/^(FR)[(A-H)|(J-N)|(P-Z)](\d{10})$/'; // France (2) |
|
| 958 | - $regex[] = '/^(FR)\d[(A-H)|(J-N)|(P-Z)](\d{9})$/'; // France (3) |
|
| 959 | - $regex[] = '/^(FR)[(A-H)|(J-N)|(P-Z)]{2}(\d{9})$/'; // France (4) |
|
| 956 | + $regex[] = '/^(FR)(\d{11})$/'; // France (1) |
|
| 957 | + $regex[] = '/^(FR)[(A-H)|(J-N)|(P-Z)](\d{10})$/'; // France (2) |
|
| 958 | + $regex[] = '/^(FR)\d[(A-H)|(J-N)|(P-Z)](\d{9})$/'; // France (3) |
|
| 959 | + $regex[] = '/^(FR)[(A-H)|(J-N)|(P-Z)]{2}(\d{9})$/'; // France (4) |
|
| 960 | 960 | break; |
| 961 | 961 | case 'GB': |
| 962 | - $regex[] = '/^(GB)?(\d{9})$/'; // UK (Standard) |
|
| 963 | - $regex[] = '/^(GB)?(\d{12})$/'; // UK (Branches) |
|
| 964 | - $regex[] = '/^(GB)?(GD\d{3})$/'; // UK (Government) |
|
| 965 | - $regex[] = '/^(GB)?(HA\d{3})$/'; // UK (Health authority) |
|
| 962 | + $regex[] = '/^(GB)?(\d{9})$/'; // UK (Standard) |
|
| 963 | + $regex[] = '/^(GB)?(\d{12})$/'; // UK (Branches) |
|
| 964 | + $regex[] = '/^(GB)?(GD\d{3})$/'; // UK (Government) |
|
| 965 | + $regex[] = '/^(GB)?(HA\d{3})$/'; // UK (Health authority) |
|
| 966 | 966 | break; |
| 967 | 967 | case 'GR': |
| 968 | - $regex[] = '/^(GR)(\d{8,9})$/'; // Greece |
|
| 968 | + $regex[] = '/^(GR)(\d{8,9})$/'; // Greece |
|
| 969 | 969 | break; |
| 970 | 970 | case 'HR': |
| 971 | - $regex[] = '/^(HR)(\d{11})$/'; // Croatia |
|
| 971 | + $regex[] = '/^(HR)(\d{11})$/'; // Croatia |
|
| 972 | 972 | break; |
| 973 | 973 | case 'HU': |
| 974 | - $regex[] = '/^(HU)(\d{8})$/'; // Hungary |
|
| 974 | + $regex[] = '/^(HU)(\d{8})$/'; // Hungary |
|
| 975 | 975 | break; |
| 976 | 976 | case 'IE': |
| 977 | - $regex[] = '/^(IE)(\d{7}[A-W])$/'; // Ireland (1) |
|
| 978 | - $regex[] = '/^(IE)([7-9][A-Z\*\+)]\d{5}[A-W])$/'; // Ireland (2) |
|
| 979 | - $regex[] = '/^(IE)(\d{7}[A-Z][AH])$/'; // Ireland (3) (new format from 1 Jan 2013) |
|
| 977 | + $regex[] = '/^(IE)(\d{7}[A-W])$/'; // Ireland (1) |
|
| 978 | + $regex[] = '/^(IE)([7-9][A-Z\*\+)]\d{5}[A-W])$/'; // Ireland (2) |
|
| 979 | + $regex[] = '/^(IE)(\d{7}[A-Z][AH])$/'; // Ireland (3) (new format from 1 Jan 2013) |
|
| 980 | 980 | break; |
| 981 | 981 | case 'IT': |
| 982 | - $regex[] = '/^(IT)(\d{11})$/'; // Italy |
|
| 982 | + $regex[] = '/^(IT)(\d{11})$/'; // Italy |
|
| 983 | 983 | break; |
| 984 | 984 | case 'LV': |
| 985 | - $regex[] = '/^(LV)(\d{11})$/'; // Latvia |
|
| 985 | + $regex[] = '/^(LV)(\d{11})$/'; // Latvia |
|
| 986 | 986 | break; |
| 987 | 987 | case 'LT': |
| 988 | - $regex[] = '/^(LT)(\d{9}|\d{12})$/'; // Lithuania |
|
| 988 | + $regex[] = '/^(LT)(\d{9}|\d{12})$/'; // Lithuania |
|
| 989 | 989 | break; |
| 990 | 990 | case 'LU': |
| 991 | - $regex[] = '/^(LU)(\d{8})$/'; // Luxembourg |
|
| 991 | + $regex[] = '/^(LU)(\d{8})$/'; // Luxembourg |
|
| 992 | 992 | break; |
| 993 | 993 | case 'MT': |
| 994 | - $regex[] = '/^(MT)([1-9]\d{7})$/'; // Malta |
|
| 994 | + $regex[] = '/^(MT)([1-9]\d{7})$/'; // Malta |
|
| 995 | 995 | break; |
| 996 | 996 | case 'NL': |
| 997 | - $regex[] = '/^(NL)(\d{9})B\d{2}$/'; // Netherlands |
|
| 997 | + $regex[] = '/^(NL)(\d{9})B\d{2}$/'; // Netherlands |
|
| 998 | 998 | break; |
| 999 | 999 | case 'NO': |
| 1000 | - $regex[] = '/^(NO)(\d{9})$/'; // Norway (Not EU) |
|
| 1000 | + $regex[] = '/^(NO)(\d{9})$/'; // Norway (Not EU) |
|
| 1001 | 1001 | break; |
| 1002 | 1002 | case 'PL': |
| 1003 | - $regex[] = '/^(PL)(\d{10})$/'; // Poland |
|
| 1003 | + $regex[] = '/^(PL)(\d{10})$/'; // Poland |
|
| 1004 | 1004 | break; |
| 1005 | 1005 | case 'PT': |
| 1006 | - $regex[] = '/^(PT)(\d{9})$/'; // Portugal |
|
| 1006 | + $regex[] = '/^(PT)(\d{9})$/'; // Portugal |
|
| 1007 | 1007 | break; |
| 1008 | 1008 | case 'RO': |
| 1009 | - $regex[] = '/^(RO)([1-9]\d{1,9})$/'; // Romania |
|
| 1009 | + $regex[] = '/^(RO)([1-9]\d{1,9})$/'; // Romania |
|
| 1010 | 1010 | break; |
| 1011 | 1011 | case 'RS': |
| 1012 | - $regex[] = '/^(RS)(\d{9})$/'; // Serbia (Not EU) |
|
| 1012 | + $regex[] = '/^(RS)(\d{9})$/'; // Serbia (Not EU) |
|
| 1013 | 1013 | break; |
| 1014 | 1014 | case 'SI': |
| 1015 | - $regex[] = '/^(SI)([1-9]\d{7})$/'; // Slovenia |
|
| 1015 | + $regex[] = '/^(SI)([1-9]\d{7})$/'; // Slovenia |
|
| 1016 | 1016 | break; |
| 1017 | 1017 | case 'SK': |
| 1018 | - $regex[] = '/^(SK)([1-9]\d[(2-4)|(6-9)]\d{7})$/'; // Slovakia Republic |
|
| 1018 | + $regex[] = '/^(SK)([1-9]\d[(2-4)|(6-9)]\d{7})$/'; // Slovakia Republic |
|
| 1019 | 1019 | break; |
| 1020 | 1020 | case 'SE': |
| 1021 | - $regex[] = '/^(SE)(\d{10}01)$/'; // Sweden |
|
| 1021 | + $regex[] = '/^(SE)(\d{10}01)$/'; // Sweden |
|
| 1022 | 1022 | break; |
| 1023 | 1023 | default: |
| 1024 | 1024 | $regex = array(); |
| 1025 | 1025 | break; |
| 1026 | 1026 | } |
| 1027 | 1027 | |
| 1028 | - if ( empty( $regex ) ) { |
|
| 1028 | + if (empty($regex)) { |
|
| 1029 | 1029 | return false; |
| 1030 | 1030 | } |
| 1031 | 1031 | |
| 1032 | - foreach ( $regex as $pattern ) { |
|
| 1032 | + foreach ($regex as $pattern) { |
|
| 1033 | 1033 | $matches = null; |
| 1034 | - preg_match_all( $pattern, $vat_number, $matches ); |
|
| 1034 | + preg_match_all($pattern, $vat_number, $matches); |
|
| 1035 | 1035 | |
| 1036 | - if ( !empty( $matches[1][0] ) && !empty( $matches[2][0] ) ) { |
|
| 1037 | - if ( $formatted ) { |
|
| 1038 | - return array( 'code' => $matches[1][0], 'number' => $matches[2][0] ); |
|
| 1036 | + if (!empty($matches[1][0]) && !empty($matches[2][0])) { |
|
| 1037 | + if ($formatted) { |
|
| 1038 | + return array('code' => $matches[1][0], 'number' => $matches[2][0]); |
|
| 1039 | 1039 | } else { |
| 1040 | 1040 | return true; |
| 1041 | 1041 | } |
@@ -1045,75 +1045,75 @@ discard block |
||
| 1045 | 1045 | return false; |
| 1046 | 1046 | } |
| 1047 | 1047 | |
| 1048 | - public static function vies_check( $vat_number, $country_code = '', $result = false ) { |
|
| 1049 | - $vat = self::sanitize_vat( $vat_number, $country_code ); |
|
| 1048 | + public static function vies_check($vat_number, $country_code = '', $result = false) { |
|
| 1049 | + $vat = self::sanitize_vat($vat_number, $country_code); |
|
| 1050 | 1050 | $vat_number = $vat['vat']; |
| 1051 | 1051 | $iso = $vat['iso']; |
| 1052 | 1052 | |
| 1053 | - $url = 'http://ec.europa.eu/taxation_customs/vies/viesquer.do?ms=' . urlencode( $iso ) . '&iso=' . urlencode( $iso ) . '&vat=' . urlencode( $vat_number ); |
|
| 1053 | + $url = 'http://ec.europa.eu/taxation_customs/vies/viesquer.do?ms=' . urlencode($iso) . '&iso=' . urlencode($iso) . '&vat=' . urlencode($vat_number); |
|
| 1054 | 1054 | |
| 1055 | - if ( ini_get( 'allow_url_fopen' ) ) { |
|
| 1056 | - $response = file_get_contents( $url ); |
|
| 1057 | - } else if ( function_exists( 'curl_init' ) ) { |
|
| 1055 | + if (ini_get('allow_url_fopen')) { |
|
| 1056 | + $response = file_get_contents($url); |
|
| 1057 | + } else if (function_exists('curl_init')) { |
|
| 1058 | 1058 | $ch = curl_init(); |
| 1059 | 1059 | |
| 1060 | - curl_setopt( $ch, CURLOPT_URL, $url ); |
|
| 1061 | - curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT, 30 ); |
|
| 1062 | - curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true ); |
|
| 1063 | - curl_setopt( $ch, CURLOPT_SSL_VERIFYHOST, 0 ); |
|
| 1064 | - curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, 0 ); |
|
| 1060 | + curl_setopt($ch, CURLOPT_URL, $url); |
|
| 1061 | + curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30); |
|
| 1062 | + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
|
| 1063 | + curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); |
|
| 1064 | + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); |
|
| 1065 | 1065 | |
| 1066 | - $response = curl_exec( $ch ); |
|
| 1066 | + $response = curl_exec($ch); |
|
| 1067 | 1067 | |
| 1068 | - if ( curl_errno( $ch ) ) { |
|
| 1069 | - wpinv_error_log( curl_error( $ch ), 'VIES CHECK ERROR' ); |
|
| 1068 | + if (curl_errno($ch)) { |
|
| 1069 | + wpinv_error_log(curl_error($ch), 'VIES CHECK ERROR'); |
|
| 1070 | 1070 | $response = ''; |
| 1071 | 1071 | } |
| 1072 | 1072 | |
| 1073 | - curl_close( $ch ); |
|
| 1073 | + curl_close($ch); |
|
| 1074 | 1074 | } else { |
| 1075 | - 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' ); |
|
| 1075 | + 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'); |
|
| 1076 | 1076 | } |
| 1077 | 1077 | |
| 1078 | - if ( empty( $response ) ) { |
|
| 1078 | + if (empty($response)) { |
|
| 1079 | 1079 | return $result; |
| 1080 | 1080 | } |
| 1081 | 1081 | |
| 1082 | - if ( preg_match( '/invalid VAT number/i', $response ) ) { |
|
| 1082 | + if (preg_match('/invalid VAT number/i', $response)) { |
|
| 1083 | 1083 | return false; |
| 1084 | - } else if ( preg_match( '/valid VAT number/i', $response, $matches ) ) { |
|
| 1085 | - $content = explode( "valid VAT number", htmlentities( $response ) ); |
|
| 1084 | + } else if (preg_match('/valid VAT number/i', $response, $matches)) { |
|
| 1085 | + $content = explode("valid VAT number", htmlentities($response)); |
|
| 1086 | 1086 | |
| 1087 | - if ( !empty( $content[1] ) ) { |
|
| 1088 | - preg_match_all( '/<tr>(.*?)<td.*?>(.*?)<\/td>(.*?)<\/tr>/si', html_entity_decode( $content[1] ), $matches ); |
|
| 1087 | + if (!empty($content[1])) { |
|
| 1088 | + preg_match_all('/<tr>(.*?)<td.*?>(.*?)<\/td>(.*?)<\/tr>/si', html_entity_decode($content[1]), $matches); |
|
| 1089 | 1089 | |
| 1090 | - if ( !empty( $matches[2] ) && $matches[3] ) { |
|
| 1090 | + if (!empty($matches[2]) && $matches[3]) { |
|
| 1091 | 1091 | $return = array(); |
| 1092 | 1092 | |
| 1093 | - foreach ( $matches[2] as $key => $label ) { |
|
| 1094 | - $label = trim( $label ); |
|
| 1093 | + foreach ($matches[2] as $key => $label) { |
|
| 1094 | + $label = trim($label); |
|
| 1095 | 1095 | |
| 1096 | - switch ( strtolower( $label ) ) { |
|
| 1096 | + switch (strtolower($label)) { |
|
| 1097 | 1097 | case 'member state': |
| 1098 | - $return['state'] = trim( strip_tags( $matches[3][$key] ) ); |
|
| 1098 | + $return['state'] = trim(strip_tags($matches[3][$key])); |
|
| 1099 | 1099 | break; |
| 1100 | 1100 | case 'vat number': |
| 1101 | - $return['number'] = trim( strip_tags( $matches[3][$key] ) ); |
|
| 1101 | + $return['number'] = trim(strip_tags($matches[3][$key])); |
|
| 1102 | 1102 | break; |
| 1103 | 1103 | case 'name': |
| 1104 | - $return['company'] = trim( strip_tags( $matches[3][$key] ) ); |
|
| 1104 | + $return['company'] = trim(strip_tags($matches[3][$key])); |
|
| 1105 | 1105 | break; |
| 1106 | 1106 | case 'address': |
| 1107 | - $address = str_replace( array( "<br><br>", "<br /><br />", "<br/><br/>" ), "<br>", html_entity_decode( trim( $matches[3][$key] ) ) ); |
|
| 1108 | - $return['address'] = trim( strip_tags( $address, '<br>' ) ); |
|
| 1107 | + $address = str_replace(array("<br><br>", "<br /><br />", "<br/><br/>"), "<br>", html_entity_decode(trim($matches[3][$key]))); |
|
| 1108 | + $return['address'] = trim(strip_tags($address, '<br>')); |
|
| 1109 | 1109 | break; |
| 1110 | 1110 | case 'consultation number': |
| 1111 | - $return['consultation'] = trim( strip_tags( $matches[3][$key] ) ); |
|
| 1111 | + $return['consultation'] = trim(strip_tags($matches[3][$key])); |
|
| 1112 | 1112 | break; |
| 1113 | 1113 | } |
| 1114 | 1114 | } |
| 1115 | 1115 | |
| 1116 | - if ( !empty( $return ) ) { |
|
| 1116 | + if (!empty($return)) { |
|
| 1117 | 1117 | return $return; |
| 1118 | 1118 | } |
| 1119 | 1119 | } |
@@ -1125,55 +1125,55 @@ discard block |
||
| 1125 | 1125 | } |
| 1126 | 1126 | } |
| 1127 | 1127 | |
| 1128 | - public static function check_vat( $vat_number, $country_code = '' ) { |
|
| 1128 | + public static function check_vat($vat_number, $country_code = '') { |
|
| 1129 | 1129 | $vat_name = self::get_vat_name(); |
| 1130 | 1130 | |
| 1131 | 1131 | $return = array(); |
| 1132 | 1132 | $return['valid'] = false; |
| 1133 | - $return['message'] = wp_sprintf( __( '%s number not validated', 'invoicing' ), $vat_name ); |
|
| 1133 | + $return['message'] = wp_sprintf(__('%s number not validated', 'invoicing'), $vat_name); |
|
| 1134 | 1134 | |
| 1135 | - if ( !wpinv_get_option( 'vat_offline_check' ) && !self::offline_check( $vat_number, $country_code ) ) { |
|
| 1135 | + if (!wpinv_get_option('vat_offline_check') && !self::offline_check($vat_number, $country_code)) { |
|
| 1136 | 1136 | return $return; |
| 1137 | 1137 | } |
| 1138 | 1138 | |
| 1139 | - $response = self::vies_check( $vat_number, $country_code ); |
|
| 1139 | + $response = self::vies_check($vat_number, $country_code); |
|
| 1140 | 1140 | |
| 1141 | - if ( $response ) { |
|
| 1142 | - $return['valid'] = true; |
|
| 1141 | + if ($response) { |
|
| 1142 | + $return['valid'] = true; |
|
| 1143 | 1143 | |
| 1144 | - if ( is_array( $response ) ) { |
|
| 1145 | - $return['company'] = isset( $response['company'] ) ? $response['company'] : ''; |
|
| 1146 | - $return['address'] = isset( $response['address'] ) ? $response['address'] : ''; |
|
| 1144 | + if (is_array($response)) { |
|
| 1145 | + $return['company'] = isset($response['company']) ? $response['company'] : ''; |
|
| 1146 | + $return['address'] = isset($response['address']) ? $response['address'] : ''; |
|
| 1147 | 1147 | $return['message'] = $return['company'] . '<br/>' . $return['address']; |
| 1148 | 1148 | } |
| 1149 | 1149 | } else { |
| 1150 | 1150 | $return['valid'] = false; |
| 1151 | - $return['message'] = wp_sprintf( __( 'Fail to validate the %s number: EU Commission VAT server (VIES) check fails.', 'invoicing' ), $vat_name ); |
|
| 1151 | + $return['message'] = wp_sprintf(__('Fail to validate the %s number: EU Commission VAT server (VIES) check fails.', 'invoicing'), $vat_name); |
|
| 1152 | 1152 | } |
| 1153 | 1153 | |
| 1154 | 1154 | return $return; |
| 1155 | 1155 | } |
| 1156 | 1156 | |
| 1157 | - public static function request_euvatrates( $group ) { |
|
| 1157 | + public static function request_euvatrates($group) { |
|
| 1158 | 1158 | $response = array(); |
| 1159 | 1159 | $response['success'] = false; |
| 1160 | 1160 | $response['error'] = null; |
| 1161 | 1161 | $response['eurates'] = null; |
| 1162 | 1162 | |
| 1163 | 1163 | $euvatrates_url = 'https://euvatrates.com/rates.json'; |
| 1164 | - $euvatrates_url = apply_filters( 'wpinv_euvatrates_url', $euvatrates_url ); |
|
| 1165 | - $api_response = wp_remote_get( $euvatrates_url ); |
|
| 1164 | + $euvatrates_url = apply_filters('wpinv_euvatrates_url', $euvatrates_url); |
|
| 1165 | + $api_response = wp_remote_get($euvatrates_url); |
|
| 1166 | 1166 | |
| 1167 | 1167 | try { |
| 1168 | - if ( is_wp_error( $api_response ) ) { |
|
| 1169 | - $response['error'] = __( $api_response->get_error_message(), 'invoicing' ); |
|
| 1168 | + if (is_wp_error($api_response)) { |
|
| 1169 | + $response['error'] = __($api_response->get_error_message(), 'invoicing'); |
|
| 1170 | 1170 | } else { |
| 1171 | - $body = json_decode( $api_response['body'] ); |
|
| 1171 | + $body = json_decode($api_response['body']); |
|
| 1172 | 1172 | |
| 1173 | - if ( isset( $body->rates ) ) { |
|
| 1173 | + if (isset($body->rates)) { |
|
| 1174 | 1174 | $rates = array(); |
| 1175 | 1175 | |
| 1176 | - foreach ( $body->rates as $country_code => $rate ) { |
|
| 1176 | + foreach ($body->rates as $country_code => $rate) { |
|
| 1177 | 1177 | $vat_rate = array(); |
| 1178 | 1178 | $vat_rate['country'] = $rate->country; |
| 1179 | 1179 | $vat_rate['standard'] = (float)$rate->standard_rate; |
@@ -1181,7 +1181,7 @@ discard block |
||
| 1181 | 1181 | $vat_rate['superreduced'] = (float)$rate->super_reduced_rate; |
| 1182 | 1182 | $vat_rate['parking'] = (float)$rate->parking_rate; |
| 1183 | 1183 | |
| 1184 | - if ( $group !== '' && in_array( $group, array( 'standard', 'reduced', 'superreduced', 'parking' ) ) ) { |
|
| 1184 | + if ($group !== '' && in_array($group, array('standard', 'reduced', 'superreduced', 'parking'))) { |
|
| 1185 | 1185 | $vat_rate_group = array(); |
| 1186 | 1186 | $vat_rate_group['country'] = $rate->country; |
| 1187 | 1187 | $vat_rate_group[$group] = $vat_rate[$group]; |
@@ -1193,79 +1193,79 @@ discard block |
||
| 1193 | 1193 | } |
| 1194 | 1194 | |
| 1195 | 1195 | $response['success'] = true; |
| 1196 | - $response['rates'] = apply_filters( 'wpinv_process_euvatrates', $rates, $api_response, $group ); |
|
| 1196 | + $response['rates'] = apply_filters('wpinv_process_euvatrates', $rates, $api_response, $group); |
|
| 1197 | 1197 | } else { |
| 1198 | - $response['error'] = __( 'No EU rates found!', 'invoicing' ); |
|
| 1198 | + $response['error'] = __('No EU rates found!', 'invoicing'); |
|
| 1199 | 1199 | } |
| 1200 | 1200 | } |
| 1201 | - } catch ( Exception $e ) { |
|
| 1202 | - $response['error'] = __( $e->getMessage(), 'invoicing' ); |
|
| 1201 | + } catch (Exception $e) { |
|
| 1202 | + $response['error'] = __($e->getMessage(), 'invoicing'); |
|
| 1203 | 1203 | } |
| 1204 | 1204 | |
| 1205 | - return apply_filters( 'wpinv_response_euvatrates', $response, $group ); |
|
| 1205 | + return apply_filters('wpinv_response_euvatrates', $response, $group); |
|
| 1206 | 1206 | } |
| 1207 | 1207 | |
| 1208 | - public static function requires_vat( $requires_vat = false, $user_id = 0, $is_digital = null ) { |
|
| 1208 | + public static function requires_vat($requires_vat = false, $user_id = 0, $is_digital = null) { |
|
| 1209 | 1209 | global $wpi_item_id, $wpi_country; |
| 1210 | 1210 | |
| 1211 | - if ( !empty( $_POST['wpinv_country'] ) ) { |
|
| 1212 | - $country_code = trim( $_POST['wpinv_country'] ); |
|
| 1213 | - } else if ( !empty( $_POST['country'] ) ) { |
|
| 1214 | - $country_code = trim( $_POST['country'] ); |
|
| 1215 | - } else if ( !empty( $wpi_country ) ) { |
|
| 1211 | + if (!empty($_POST['wpinv_country'])) { |
|
| 1212 | + $country_code = trim($_POST['wpinv_country']); |
|
| 1213 | + } else if (!empty($_POST['country'])) { |
|
| 1214 | + $country_code = trim($_POST['country']); |
|
| 1215 | + } else if (!empty($wpi_country)) { |
|
| 1216 | 1216 | $country_code = $wpi_country; |
| 1217 | 1217 | } else { |
| 1218 | - $country_code = self::get_user_country( '', $user_id ); |
|
| 1218 | + $country_code = self::get_user_country('', $user_id); |
|
| 1219 | 1219 | } |
| 1220 | 1220 | |
| 1221 | - if ( $is_digital === null && $wpi_item_id ) { |
|
| 1222 | - $is_digital = $wpi_item_id ? self::item_has_digital_rule( $wpi_item_id ) : self::allow_vat_rules(); |
|
| 1221 | + if ($is_digital === null && $wpi_item_id) { |
|
| 1222 | + $is_digital = $wpi_item_id ? self::item_has_digital_rule($wpi_item_id) : self::allow_vat_rules(); |
|
| 1223 | 1223 | } |
| 1224 | 1224 | |
| 1225 | - if ( !empty( $country_code ) ) { |
|
| 1226 | - $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 ) ); |
|
| 1225 | + if (!empty($country_code)) { |
|
| 1226 | + $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)); |
|
| 1227 | 1227 | } |
| 1228 | 1228 | |
| 1229 | - return apply_filters( 'wpinv_requires_vat', $requires_vat, $user_id ); |
|
| 1229 | + return apply_filters('wpinv_requires_vat', $requires_vat, $user_id); |
|
| 1230 | 1230 | } |
| 1231 | 1231 | |
| 1232 | - public static function tax_label( $label = '' ) { |
|
| 1232 | + public static function tax_label($label = '') { |
|
| 1233 | 1233 | global $wpi_requires_vat; |
| 1234 | 1234 | |
| 1235 | - if ( !( $wpi_requires_vat !== 0 && $wpi_requires_vat ) ) { |
|
| 1236 | - $wpi_requires_vat = self::requires_vat( 0, false ); |
|
| 1235 | + if (!($wpi_requires_vat !== 0 && $wpi_requires_vat)) { |
|
| 1236 | + $wpi_requires_vat = self::requires_vat(0, false); |
|
| 1237 | 1237 | } |
| 1238 | 1238 | |
| 1239 | - return $wpi_requires_vat ? __( self::get_vat_name(), 'invoicing' ) : ( $label ? $label : __( 'Tax', 'invoicing' ) ); |
|
| 1239 | + return $wpi_requires_vat ? __(self::get_vat_name(), 'invoicing') : ($label ? $label : __('Tax', 'invoicing')); |
|
| 1240 | 1240 | } |
| 1241 | 1241 | |
| 1242 | 1242 | public static function standard_rates_label() { |
| 1243 | - return __( 'Standard Rates', 'invoicing' ); |
|
| 1243 | + return __('Standard Rates', 'invoicing'); |
|
| 1244 | 1244 | } |
| 1245 | 1245 | |
| 1246 | - public static function get_rate_classes( $with_desc = false ) { |
|
| 1247 | - $rate_classes_option = get_option( '_wpinv_vat_rate_classes', true ); |
|
| 1248 | - $classes = maybe_unserialize( $rate_classes_option ); |
|
| 1246 | + public static function get_rate_classes($with_desc = false) { |
|
| 1247 | + $rate_classes_option = get_option('_wpinv_vat_rate_classes', true); |
|
| 1248 | + $classes = maybe_unserialize($rate_classes_option); |
|
| 1249 | 1249 | |
| 1250 | - if ( empty( $classes ) || !is_array( $classes ) ) { |
|
| 1250 | + if (empty($classes) || !is_array($classes)) { |
|
| 1251 | 1251 | $classes = array(); |
| 1252 | 1252 | } |
| 1253 | 1253 | |
| 1254 | 1254 | $rate_classes = array(); |
| 1255 | - if ( !array_key_exists( '_standard', $classes ) ) { |
|
| 1256 | - if ( $with_desc ) { |
|
| 1257 | - $rate_classes['_standard'] = array( 'name' => self::standard_rates_label(), 'desc' => __( 'EU member states standard VAT rates', 'invoicing' ) ); |
|
| 1255 | + if (!array_key_exists('_standard', $classes)) { |
|
| 1256 | + if ($with_desc) { |
|
| 1257 | + $rate_classes['_standard'] = array('name' => self::standard_rates_label(), 'desc' => __('EU member states standard VAT rates', 'invoicing')); |
|
| 1258 | 1258 | } else { |
| 1259 | 1259 | $rate_classes['_standard'] = self::standard_rates_label(); |
| 1260 | 1260 | } |
| 1261 | 1261 | } |
| 1262 | 1262 | |
| 1263 | - foreach ( $classes as $key => $class ) { |
|
| 1264 | - $name = !empty( $class['name'] ) ? __( $class['name'], 'invoicing' ) : $key; |
|
| 1265 | - $desc = !empty( $class['desc'] ) ? __( $class['desc'], 'invoicing' ) : ''; |
|
| 1263 | + foreach ($classes as $key => $class) { |
|
| 1264 | + $name = !empty($class['name']) ? __($class['name'], 'invoicing') : $key; |
|
| 1265 | + $desc = !empty($class['desc']) ? __($class['desc'], 'invoicing') : ''; |
|
| 1266 | 1266 | |
| 1267 | - if ( $with_desc ) { |
|
| 1268 | - $rate_classes[$key] = array( 'name' => $name, 'desc' => $desc ); |
|
| 1267 | + if ($with_desc) { |
|
| 1268 | + $rate_classes[$key] = array('name' => $name, 'desc' => $desc); |
|
| 1269 | 1269 | } else { |
| 1270 | 1270 | $rate_classes[$key] = $name; |
| 1271 | 1271 | } |
@@ -1276,15 +1276,15 @@ discard block |
||
| 1276 | 1276 | |
| 1277 | 1277 | public static function get_all_classes() { |
| 1278 | 1278 | $classes = self::get_rate_classes(); |
| 1279 | - $classes['_exempt'] = __( 'Exempt (0%)', 'invoicing' ); |
|
| 1279 | + $classes['_exempt'] = __('Exempt (0%)', 'invoicing'); |
|
| 1280 | 1280 | |
| 1281 | - return apply_filters( 'wpinv_vat_get_all_classes', $classes ); |
|
| 1281 | + return apply_filters('wpinv_vat_get_all_classes', $classes); |
|
| 1282 | 1282 | } |
| 1283 | 1283 | |
| 1284 | - public static function get_class_desc( $rate_class ) { |
|
| 1285 | - $rate_classes = self::get_rate_classes( true ); |
|
| 1284 | + public static function get_class_desc($rate_class) { |
|
| 1285 | + $rate_classes = self::get_rate_classes(true); |
|
| 1286 | 1286 | |
| 1287 | - if ( !empty( $rate_classes ) && isset( $rate_classes[$rate_class] ) && isset( $rate_classes[$rate_class]['desc'] ) ) { |
|
| 1287 | + if (!empty($rate_classes) && isset($rate_classes[$rate_class]) && isset($rate_classes[$rate_class]['desc'])) { |
|
| 1288 | 1288 | return $rate_classes[$rate_class]['desc']; |
| 1289 | 1289 | } |
| 1290 | 1290 | |
@@ -1300,106 +1300,106 @@ discard block |
||
| 1300 | 1300 | 'increased' => 'Increased' |
| 1301 | 1301 | ); |
| 1302 | 1302 | |
| 1303 | - return apply_filters( 'wpinv_get_vat_groups', $vat_groups ); |
|
| 1303 | + return apply_filters('wpinv_get_vat_groups', $vat_groups); |
|
| 1304 | 1304 | } |
| 1305 | 1305 | |
| 1306 | 1306 | public static function get_rules() { |
| 1307 | 1307 | $vat_rules = array( |
| 1308 | - 'digital' => __( 'Digital Product', 'invoicing' ), |
|
| 1309 | - 'physical' => __( 'Physical Product', 'invoicing' ) |
|
| 1308 | + 'digital' => __('Digital Product', 'invoicing'), |
|
| 1309 | + 'physical' => __('Physical Product', 'invoicing') |
|
| 1310 | 1310 | ); |
| 1311 | - return apply_filters( 'wpinv_get_vat_rules', $vat_rules ); |
|
| 1311 | + return apply_filters('wpinv_get_vat_rules', $vat_rules); |
|
| 1312 | 1312 | } |
| 1313 | 1313 | |
| 1314 | - public static function get_vat_rates( $class ) { |
|
| 1315 | - if ( $class === '_standard' ) { |
|
| 1314 | + public static function get_vat_rates($class) { |
|
| 1315 | + if ($class === '_standard') { |
|
| 1316 | 1316 | return wpinv_get_tax_rates(); |
| 1317 | 1317 | } |
| 1318 | 1318 | |
| 1319 | 1319 | $rates = self::get_non_standard_rates(); |
| 1320 | 1320 | |
| 1321 | - return array_key_exists( $class, $rates ) ? $rates[$class] : array(); |
|
| 1321 | + return array_key_exists($class, $rates) ? $rates[$class] : array(); |
|
| 1322 | 1322 | } |
| 1323 | 1323 | |
| 1324 | 1324 | public static function get_non_standard_rates() { |
| 1325 | - $option = get_option( 'wpinv_vat_rates', array()); |
|
| 1326 | - return is_array( $option ) ? $option : array(); |
|
| 1325 | + $option = get_option('wpinv_vat_rates', array()); |
|
| 1326 | + return is_array($option) ? $option : array(); |
|
| 1327 | 1327 | } |
| 1328 | 1328 | |
| 1329 | 1329 | public static function allow_vat_rules() { |
| 1330 | - return ( wpinv_use_taxes() && wpinv_get_option( 'apply_vat_rules' ) ? true : false ); |
|
| 1330 | + return (wpinv_use_taxes() && wpinv_get_option('apply_vat_rules') ? true : false); |
|
| 1331 | 1331 | } |
| 1332 | 1332 | |
| 1333 | 1333 | public static function allow_vat_classes() { |
| 1334 | 1334 | return false; // TODO |
| 1335 | - return ( wpinv_get_option( 'vat_allow_classes' ) ? true : false ); |
|
| 1335 | + return (wpinv_get_option('vat_allow_classes') ? true : false); |
|
| 1336 | 1336 | } |
| 1337 | 1337 | |
| 1338 | - public static function get_item_class( $postID ) { |
|
| 1339 | - $class = get_post_meta( $postID, '_wpinv_vat_class', true ); |
|
| 1338 | + public static function get_item_class($postID) { |
|
| 1339 | + $class = get_post_meta($postID, '_wpinv_vat_class', true); |
|
| 1340 | 1340 | |
| 1341 | - if ( empty( $class ) ) { |
|
| 1341 | + if (empty($class)) { |
|
| 1342 | 1342 | $class = '_standard'; |
| 1343 | 1343 | } |
| 1344 | 1344 | |
| 1345 | - return apply_filters( 'wpinv_get_item_vat_class', $class, $postID ); |
|
| 1345 | + return apply_filters('wpinv_get_item_vat_class', $class, $postID); |
|
| 1346 | 1346 | } |
| 1347 | 1347 | |
| 1348 | - public static function item_class_label( $postID ) { |
|
| 1348 | + public static function item_class_label($postID) { |
|
| 1349 | 1349 | $vat_classes = self::get_all_classes(); |
| 1350 | 1350 | |
| 1351 | - $class = self::get_item_class( $postID ); |
|
| 1352 | - $class = isset( $vat_classes[$class] ) ? $vat_classes[$class] : __( $class, 'invoicing' ); |
|
| 1351 | + $class = self::get_item_class($postID); |
|
| 1352 | + $class = isset($vat_classes[$class]) ? $vat_classes[$class] : __($class, 'invoicing'); |
|
| 1353 | 1353 | |
| 1354 | - return apply_filters( 'wpinv_item_class_label', $class, $postID ); |
|
| 1354 | + return apply_filters('wpinv_item_class_label', $class, $postID); |
|
| 1355 | 1355 | } |
| 1356 | 1356 | |
| 1357 | - public static function get_item_rule( $postID ) { |
|
| 1358 | - $rule_type = get_post_meta( $postID, '_wpinv_vat_rule', true ); |
|
| 1357 | + public static function get_item_rule($postID) { |
|
| 1358 | + $rule_type = get_post_meta($postID, '_wpinv_vat_rule', true); |
|
| 1359 | 1359 | |
| 1360 | - if ( empty( $rule_type ) ) { |
|
| 1360 | + if (empty($rule_type)) { |
|
| 1361 | 1361 | $rule_type = self::allow_vat_rules() ? 'digital' : 'physical'; |
| 1362 | 1362 | } |
| 1363 | 1363 | |
| 1364 | - return apply_filters( 'wpinv_item_get_vat_rule', $rule_type, $postID ); |
|
| 1364 | + return apply_filters('wpinv_item_get_vat_rule', $rule_type, $postID); |
|
| 1365 | 1365 | } |
| 1366 | 1366 | |
| 1367 | - public static function item_rule_label( $postID ) { |
|
| 1367 | + public static function item_rule_label($postID) { |
|
| 1368 | 1368 | $vat_rules = self::get_rules(); |
| 1369 | - $vat_rule = self::get_item_rule( $postID ); |
|
| 1370 | - $vat_rule = isset( $vat_rules[$vat_rule] ) ? $vat_rules[$vat_rule] : $vat_rule; |
|
| 1369 | + $vat_rule = self::get_item_rule($postID); |
|
| 1370 | + $vat_rule = isset($vat_rules[$vat_rule]) ? $vat_rules[$vat_rule] : $vat_rule; |
|
| 1371 | 1371 | |
| 1372 | - return apply_filters( 'wpinv_item_rule_label', $vat_rule, $postID ); |
|
| 1372 | + return apply_filters('wpinv_item_rule_label', $vat_rule, $postID); |
|
| 1373 | 1373 | } |
| 1374 | 1374 | |
| 1375 | - public static function item_has_digital_rule( $item_id = 0 ) { |
|
| 1376 | - return self::get_item_rule( $item_id ) == 'digital' ? true : false; |
|
| 1375 | + public static function item_has_digital_rule($item_id = 0) { |
|
| 1376 | + return self::get_item_rule($item_id) == 'digital' ? true : false; |
|
| 1377 | 1377 | } |
| 1378 | 1378 | |
| 1379 | - public static function invoice_has_digital_rule( $invoice = 0 ) { |
|
| 1380 | - if ( !self::allow_vat_rules() ) { |
|
| 1379 | + public static function invoice_has_digital_rule($invoice = 0) { |
|
| 1380 | + if (!self::allow_vat_rules()) { |
|
| 1381 | 1381 | return false; |
| 1382 | 1382 | } |
| 1383 | 1383 | |
| 1384 | - if ( empty( $invoice ) ) { |
|
| 1384 | + if (empty($invoice)) { |
|
| 1385 | 1385 | return true; |
| 1386 | 1386 | } |
| 1387 | 1387 | |
| 1388 | - if ( is_int( $invoice ) ) { |
|
| 1389 | - $invoice = new WPInv_Invoice( $invoice ); |
|
| 1388 | + if (is_int($invoice)) { |
|
| 1389 | + $invoice = new WPInv_Invoice($invoice); |
|
| 1390 | 1390 | } |
| 1391 | 1391 | |
| 1392 | - if ( !( is_object( $invoice ) && is_a( $invoice, 'WPInv_Invoice' ) ) ) { |
|
| 1392 | + if (!(is_object($invoice) && is_a($invoice, 'WPInv_Invoice'))) { |
|
| 1393 | 1393 | return true; |
| 1394 | 1394 | } |
| 1395 | 1395 | |
| 1396 | - $cart_items = $invoice->get_cart_details(); |
|
| 1396 | + $cart_items = $invoice->get_cart_details(); |
|
| 1397 | 1397 | |
| 1398 | - if ( !empty( $cart_items ) ) { |
|
| 1398 | + if (!empty($cart_items)) { |
|
| 1399 | 1399 | $has_digital_rule = false; |
| 1400 | 1400 | |
| 1401 | - foreach ( $cart_items as $key => $item ) { |
|
| 1402 | - if ( self::item_has_digital_rule( $item['id'] ) ) { |
|
| 1401 | + foreach ($cart_items as $key => $item) { |
|
| 1402 | + if (self::item_has_digital_rule($item['id'])) { |
|
| 1403 | 1403 | $has_digital_rule = true; |
| 1404 | 1404 | break; |
| 1405 | 1405 | } |
@@ -1411,67 +1411,67 @@ discard block |
||
| 1411 | 1411 | return $has_digital_rule; |
| 1412 | 1412 | } |
| 1413 | 1413 | |
| 1414 | - public static function item_is_taxable( $item_id = 0, $country = false, $state = false ) { |
|
| 1415 | - if ( !wpinv_use_taxes() ) { |
|
| 1414 | + public static function item_is_taxable($item_id = 0, $country = false, $state = false) { |
|
| 1415 | + if (!wpinv_use_taxes()) { |
|
| 1416 | 1416 | return false; |
| 1417 | 1417 | } |
| 1418 | 1418 | |
| 1419 | 1419 | $is_taxable = true; |
| 1420 | 1420 | |
| 1421 | - if ( !empty( $item_id ) && self::get_item_class( $item_id ) == '_exempt' ) { |
|
| 1421 | + if (!empty($item_id) && self::get_item_class($item_id) == '_exempt') { |
|
| 1422 | 1422 | $is_taxable = false; |
| 1423 | 1423 | } |
| 1424 | 1424 | |
| 1425 | - return apply_filters( 'wpinv_item_is_taxable', $is_taxable, $item_id, $country , $state ); |
|
| 1425 | + return apply_filters('wpinv_item_is_taxable', $is_taxable, $item_id, $country, $state); |
|
| 1426 | 1426 | } |
| 1427 | 1427 | |
| 1428 | - public static function find_rate( $country, $state, $rate, $class ) { |
|
| 1428 | + public static function find_rate($country, $state, $rate, $class) { |
|
| 1429 | 1429 | global $wpi_zero_tax; |
| 1430 | 1430 | |
| 1431 | - if ( $class === '_exempt' || $wpi_zero_tax ) { |
|
| 1431 | + if ($class === '_exempt' || $wpi_zero_tax) { |
|
| 1432 | 1432 | return 0; |
| 1433 | 1433 | } |
| 1434 | 1434 | |
| 1435 | - $tax_rates = wpinv_get_tax_rates(); |
|
| 1435 | + $tax_rates = wpinv_get_tax_rates(); |
|
| 1436 | 1436 | |
| 1437 | - if ( $class !== '_standard' ) { |
|
| 1438 | - $class_rates = self::get_vat_rates( $class ); |
|
| 1437 | + if ($class !== '_standard') { |
|
| 1438 | + $class_rates = self::get_vat_rates($class); |
|
| 1439 | 1439 | |
| 1440 | - if ( is_array( $class_rates ) ) { |
|
| 1440 | + if (is_array($class_rates)) { |
|
| 1441 | 1441 | $indexed_class_rates = array(); |
| 1442 | 1442 | |
| 1443 | - foreach ( $class_rates as $key => $cr ) { |
|
| 1443 | + foreach ($class_rates as $key => $cr) { |
|
| 1444 | 1444 | $indexed_class_rates[$cr['country']] = $cr; |
| 1445 | 1445 | } |
| 1446 | 1446 | |
| 1447 | - $tax_rates = array_map( function( $tr ) use( $indexed_class_rates ) { |
|
| 1447 | + $tax_rates = array_map(function($tr) use($indexed_class_rates) { |
|
| 1448 | 1448 | $tr_country = $tr['country']; |
| 1449 | - if ( !isset( $indexed_class_rates[$tr_country] ) ) { |
|
| 1449 | + if (!isset($indexed_class_rates[$tr_country])) { |
|
| 1450 | 1450 | return $tr; |
| 1451 | 1451 | } |
| 1452 | 1452 | $icr = $indexed_class_rates[$tr_country]; |
| 1453 | - return ( empty( $icr['rate'] ) && $icr['rate'] !== '0' ) ? $tr : $icr; |
|
| 1453 | + return (empty($icr['rate']) && $icr['rate'] !== '0') ? $tr : $icr; |
|
| 1454 | 1454 | |
| 1455 | - }, $tax_rates, $class_rates ); |
|
| 1455 | + }, $tax_rates, $class_rates); |
|
| 1456 | 1456 | } |
| 1457 | 1457 | } |
| 1458 | 1458 | |
| 1459 | - if ( !empty( $tax_rates ) ) { |
|
| 1460 | - foreach ( $tax_rates as $key => $tax_rate ) { |
|
| 1461 | - if ( $country != $tax_rate['country'] ) |
|
| 1459 | + if (!empty($tax_rates)) { |
|
| 1460 | + foreach ($tax_rates as $key => $tax_rate) { |
|
| 1461 | + if ($country != $tax_rate['country']) |
|
| 1462 | 1462 | continue; |
| 1463 | 1463 | |
| 1464 | - if ( !empty( $tax_rate['global'] ) ) { |
|
| 1465 | - if ( 0 !== $tax_rate['rate'] || !empty( $tax_rate['rate'] ) ) { |
|
| 1466 | - $rate = number_format( $tax_rate['rate'], 4 ); |
|
| 1464 | + if (!empty($tax_rate['global'])) { |
|
| 1465 | + if (0 !== $tax_rate['rate'] || !empty($tax_rate['rate'])) { |
|
| 1466 | + $rate = number_format($tax_rate['rate'], 4); |
|
| 1467 | 1467 | } |
| 1468 | 1468 | } else { |
| 1469 | - if ( empty( $tax_rate['state'] ) || strtolower( $state ) != strtolower( $tax_rate['state'] ) ) |
|
| 1469 | + if (empty($tax_rate['state']) || strtolower($state) != strtolower($tax_rate['state'])) |
|
| 1470 | 1470 | continue; |
| 1471 | 1471 | |
| 1472 | 1472 | $state_rate = $tax_rate['rate']; |
| 1473 | - if ( 0 !== $state_rate || !empty( $state_rate ) ) { |
|
| 1474 | - $rate = number_format( $state_rate, 4 ); |
|
| 1473 | + if (0 !== $state_rate || !empty($state_rate)) { |
|
| 1474 | + $rate = number_format($state_rate, 4); |
|
| 1475 | 1475 | } |
| 1476 | 1476 | } |
| 1477 | 1477 | } |
@@ -1480,84 +1480,84 @@ discard block |
||
| 1480 | 1480 | return $rate; |
| 1481 | 1481 | } |
| 1482 | 1482 | |
| 1483 | - public static function get_rate( $rate = 1, $country = '', $state = '', $item_id = 0 ) { |
|
| 1483 | + public static function get_rate($rate = 1, $country = '', $state = '', $item_id = 0) { |
|
| 1484 | 1484 | global $wpinv_options, $wpi_session, $wpi_item_id, $wpi_zero_tax; |
| 1485 | 1485 | |
| 1486 | 1486 | $item_id = $item_id > 0 ? $item_id : $wpi_item_id; |
| 1487 | 1487 | $allow_vat_classes = self::allow_vat_classes(); |
| 1488 | - $class = $item_id ? self::get_item_class( $item_id ) : '_standard'; |
|
| 1488 | + $class = $item_id ? self::get_item_class($item_id) : '_standard'; |
|
| 1489 | 1489 | |
| 1490 | - if ( $class === '_exempt' || $wpi_zero_tax ) { |
|
| 1490 | + if ($class === '_exempt' || $wpi_zero_tax) { |
|
| 1491 | 1491 | return 0; |
| 1492 | - } else if ( !$allow_vat_classes ) { |
|
| 1492 | + } else if (!$allow_vat_classes) { |
|
| 1493 | 1493 | $class = '_standard'; |
| 1494 | 1494 | } |
| 1495 | 1495 | |
| 1496 | - if( !empty( $_POST['wpinv_country'] ) ) { |
|
| 1496 | + if (!empty($_POST['wpinv_country'])) { |
|
| 1497 | 1497 | $post_country = $_POST['wpinv_country']; |
| 1498 | - } elseif( !empty( $_POST['wpinv_country'] ) ) { |
|
| 1498 | + } elseif (!empty($_POST['wpinv_country'])) { |
|
| 1499 | 1499 | $post_country = $_POST['wpinv_country']; |
| 1500 | - } elseif( !empty( $_POST['country'] ) ) { |
|
| 1500 | + } elseif (!empty($_POST['country'])) { |
|
| 1501 | 1501 | $post_country = $_POST['country']; |
| 1502 | 1502 | } else { |
| 1503 | 1503 | $post_country = ''; |
| 1504 | 1504 | } |
| 1505 | 1505 | |
| 1506 | - $country = !empty( $post_country ) ? $post_country : wpinv_default_billing_country( $country ); |
|
| 1507 | - $base_country = wpinv_is_base_country( $country ); |
|
| 1506 | + $country = !empty($post_country) ? $post_country : wpinv_default_billing_country($country); |
|
| 1507 | + $base_country = wpinv_is_base_country($country); |
|
| 1508 | 1508 | |
| 1509 | - $requires_vat = self::requires_vat( 0, false ); |
|
| 1510 | - $is_digital = self::get_item_rule( $item_id ) == 'digital' ; |
|
| 1511 | - $rate = $requires_vat && isset( $wpinv_options['eu_fallback_rate'] ) ? $wpinv_options['eu_fallback_rate'] : $rate; |
|
| 1509 | + $requires_vat = self::requires_vat(0, false); |
|
| 1510 | + $is_digital = self::get_item_rule($item_id) == 'digital'; |
|
| 1511 | + $rate = $requires_vat && isset($wpinv_options['eu_fallback_rate']) ? $wpinv_options['eu_fallback_rate'] : $rate; |
|
| 1512 | 1512 | |
| 1513 | - if ( self::same_country_rule() == 'no' && $base_country ) { // Disable VAT to same country |
|
| 1513 | + if (self::same_country_rule() == 'no' && $base_country) { // Disable VAT to same country |
|
| 1514 | 1514 | $rate = 0; |
| 1515 | - } else if ( $requires_vat ) { |
|
| 1516 | - $vat_number = self::get_user_vat_number( '', 0, true ); |
|
| 1515 | + } else if ($requires_vat) { |
|
| 1516 | + $vat_number = self::get_user_vat_number('', 0, true); |
|
| 1517 | 1517 | $vat_info = self::current_vat_data(); |
| 1518 | 1518 | |
| 1519 | - if ( is_array( $vat_info ) ) { |
|
| 1520 | - $vat_number = isset( $vat_info['number'] ) && !empty( $vat_info['valid'] ) ? $vat_info['number'] : ""; |
|
| 1519 | + if (is_array($vat_info)) { |
|
| 1520 | + $vat_number = isset($vat_info['number']) && !empty($vat_info['valid']) ? $vat_info['number'] : ""; |
|
| 1521 | 1521 | } |
| 1522 | 1522 | |
| 1523 | - if ( $country == 'UK' ) { |
|
| 1523 | + if ($country == 'UK') { |
|
| 1524 | 1524 | $country = 'GB'; |
| 1525 | 1525 | } |
| 1526 | 1526 | |
| 1527 | - if ( !empty( $vat_number ) ) { |
|
| 1527 | + if (!empty($vat_number)) { |
|
| 1528 | 1528 | $rate = 0; |
| 1529 | 1529 | } else { |
| 1530 | - $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 |
|
| 1530 | + $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 |
|
| 1531 | 1531 | } |
| 1532 | 1532 | |
| 1533 | - if ( empty( $vat_number ) && !$is_digital ) { |
|
| 1534 | - if ( $base_country ) { |
|
| 1535 | - $rate = self::find_rate( $country, null, $rate, $class ); |
|
| 1533 | + if (empty($vat_number) && !$is_digital) { |
|
| 1534 | + if ($base_country) { |
|
| 1535 | + $rate = self::find_rate($country, null, $rate, $class); |
|
| 1536 | 1536 | } else { |
| 1537 | - if ( empty( $country ) && isset( $wpinv_options['eu_fallback_rate'] ) ) { |
|
| 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 | - } else if ( empty( $vat_number ) || ( self::same_country_rule() == 'always' && $base_country ) ) { |
|
| 1544 | - if ( empty( $country ) && isset( $wpinv_options['eu_fallback_rate'] ) ) { |
|
| 1543 | + } else if (empty($vat_number) || (self::same_country_rule() == 'always' && $base_country)) { |
|
| 1544 | + if (empty($country) && isset($wpinv_options['eu_fallback_rate'])) { |
|
| 1545 | 1545 | $rate = $wpinv_options['eu_fallback_rate']; |
| 1546 | - } else if( !empty( $country ) ) { |
|
| 1547 | - $rate = self::find_rate( $country, $state, $rate, $class ); |
|
| 1546 | + } else if (!empty($country)) { |
|
| 1547 | + $rate = self::find_rate($country, $state, $rate, $class); |
|
| 1548 | 1548 | } |
| 1549 | 1549 | } |
| 1550 | 1550 | } else { |
| 1551 | - if ( $is_digital ) { |
|
| 1551 | + if ($is_digital) { |
|
| 1552 | 1552 | $ip_country_code = self::get_country_by_ip(); |
| 1553 | 1553 | |
| 1554 | - if ( $ip_country_code && self::is_eu_state( $ip_country_code ) ) { |
|
| 1555 | - $rate = self::find_rate( $ip_country_code, '', 0, $class ); |
|
| 1554 | + if ($ip_country_code && self::is_eu_state($ip_country_code)) { |
|
| 1555 | + $rate = self::find_rate($ip_country_code, '', 0, $class); |
|
| 1556 | 1556 | } else { |
| 1557 | - $rate = self::find_rate( $country, $state, $rate, $class ); |
|
| 1557 | + $rate = self::find_rate($country, $state, $rate, $class); |
|
| 1558 | 1558 | } |
| 1559 | 1559 | } else { |
| 1560 | - $rate = self::find_rate( $country, $state, $rate, $class ); |
|
| 1560 | + $rate = self::find_rate($country, $state, $rate, $class); |
|
| 1561 | 1561 | } |
| 1562 | 1562 | } |
| 1563 | 1563 | |
@@ -1567,48 +1567,48 @@ discard block |
||
| 1567 | 1567 | public static function current_vat_data() { |
| 1568 | 1568 | global $wpi_session; |
| 1569 | 1569 | |
| 1570 | - return $wpi_session->get( 'user_vat_data' ); |
|
| 1570 | + return $wpi_session->get('user_vat_data'); |
|
| 1571 | 1571 | } |
| 1572 | 1572 | |
| 1573 | - public static function get_user_country( $country = '', $user_id = 0 ) { |
|
| 1574 | - $user_address = wpinv_get_user_address( $user_id, false ); |
|
| 1573 | + public static function get_user_country($country = '', $user_id = 0) { |
|
| 1574 | + $user_address = wpinv_get_user_address($user_id, false); |
|
| 1575 | 1575 | |
| 1576 | - if ( wpinv_get_option( 'vat_ip_country_default' ) ) { |
|
| 1576 | + if (wpinv_get_option('vat_ip_country_default')) { |
|
| 1577 | 1577 | $country = ''; |
| 1578 | 1578 | } |
| 1579 | 1579 | |
| 1580 | - $country = empty( $user_address ) || !isset( $user_address['country'] ) || empty( $user_address['country'] ) ? $country : $user_address['country']; |
|
| 1581 | - $result = apply_filters( 'wpinv_get_user_country', $country, $user_id ); |
|
| 1580 | + $country = empty($user_address) || !isset($user_address['country']) || empty($user_address['country']) ? $country : $user_address['country']; |
|
| 1581 | + $result = apply_filters('wpinv_get_user_country', $country, $user_id); |
|
| 1582 | 1582 | |
| 1583 | - if ( empty( $result ) ) { |
|
| 1583 | + if (empty($result)) { |
|
| 1584 | 1584 | $result = self::get_country_by_ip(); |
| 1585 | 1585 | } |
| 1586 | 1586 | |
| 1587 | 1587 | return $result; |
| 1588 | 1588 | } |
| 1589 | 1589 | |
| 1590 | - public static function set_user_country( $country = '', $user_id = 0 ) { |
|
| 1590 | + public static function set_user_country($country = '', $user_id = 0) { |
|
| 1591 | 1591 | global $wpi_userID; |
| 1592 | 1592 | |
| 1593 | - if ( empty($country) && !empty($wpi_userID) && get_current_user_id() != $wpi_userID ) { |
|
| 1593 | + if (empty($country) && !empty($wpi_userID) && get_current_user_id() != $wpi_userID) { |
|
| 1594 | 1594 | $country = wpinv_get_default_country(); |
| 1595 | 1595 | } |
| 1596 | 1596 | |
| 1597 | 1597 | return $country; |
| 1598 | 1598 | } |
| 1599 | 1599 | |
| 1600 | - public static function get_user_vat_number( $vat_number = '', $user_id = 0, $is_valid = false ) { |
|
| 1600 | + public static function get_user_vat_number($vat_number = '', $user_id = 0, $is_valid = false) { |
|
| 1601 | 1601 | global $wpi_current_id, $wpi_userID; |
| 1602 | 1602 | |
| 1603 | - if ( !empty( $_POST['new_user'] ) ) { |
|
| 1603 | + if (!empty($_POST['new_user'])) { |
|
| 1604 | 1604 | return ''; |
| 1605 | 1605 | } |
| 1606 | 1606 | |
| 1607 | - if ( empty( $user_id ) ) { |
|
| 1608 | - $user_id = !empty( $wpi_userID ) ? $wpi_userID : ( $wpi_current_id ? wpinv_get_user_id( $wpi_current_id ) : get_current_user_id() ); |
|
| 1607 | + if (empty($user_id)) { |
|
| 1608 | + $user_id = !empty($wpi_userID) ? $wpi_userID : ($wpi_current_id ? wpinv_get_user_id($wpi_current_id) : get_current_user_id()); |
|
| 1609 | 1609 | } |
| 1610 | 1610 | |
| 1611 | - $vat_number = empty( $user_id ) ? '' : get_user_meta( $user_id, '_wpinv_vat_number', true ); |
|
| 1611 | + $vat_number = empty($user_id) ? '' : get_user_meta($user_id, '_wpinv_vat_number', true); |
|
| 1612 | 1612 | |
| 1613 | 1613 | /* TODO |
| 1614 | 1614 | if ( $is_valid && $vat_number ) { |
@@ -1619,38 +1619,38 @@ discard block |
||
| 1619 | 1619 | } |
| 1620 | 1620 | */ |
| 1621 | 1621 | |
| 1622 | - return apply_filters('wpinv_get_user_vat_number', $vat_number, $user_id, $is_valid ); |
|
| 1622 | + return apply_filters('wpinv_get_user_vat_number', $vat_number, $user_id, $is_valid); |
|
| 1623 | 1623 | } |
| 1624 | 1624 | |
| 1625 | - public static function get_user_company( $company = '', $user_id = 0 ) { |
|
| 1625 | + public static function get_user_company($company = '', $user_id = 0) { |
|
| 1626 | 1626 | global $wpi_current_id, $wpi_userID; |
| 1627 | 1627 | |
| 1628 | - if ( empty( $user_id ) ) { |
|
| 1629 | - $user_id = !empty( $wpi_userID ) ? $wpi_userID : ( $wpi_current_id ? wpinv_get_user_id( $wpi_current_id ) : get_current_user_id() ); |
|
| 1628 | + if (empty($user_id)) { |
|
| 1629 | + $user_id = !empty($wpi_userID) ? $wpi_userID : ($wpi_current_id ? wpinv_get_user_id($wpi_current_id) : get_current_user_id()); |
|
| 1630 | 1630 | } |
| 1631 | 1631 | |
| 1632 | - $company = empty( $user_id ) ? "" : get_user_meta( $user_id, '_wpinv_company', true ); |
|
| 1632 | + $company = empty($user_id) ? "" : get_user_meta($user_id, '_wpinv_company', true); |
|
| 1633 | 1633 | |
| 1634 | - return apply_filters( 'wpinv_user_company', $company, $user_id ); |
|
| 1634 | + return apply_filters('wpinv_user_company', $company, $user_id); |
|
| 1635 | 1635 | } |
| 1636 | 1636 | |
| 1637 | - public static function save_user_vat_details( $company = '', $vat_number = '' ) { |
|
| 1638 | - $save = apply_filters( 'wpinv_allow_save_user_vat_details', true ); |
|
| 1637 | + public static function save_user_vat_details($company = '', $vat_number = '') { |
|
| 1638 | + $save = apply_filters('wpinv_allow_save_user_vat_details', true); |
|
| 1639 | 1639 | |
| 1640 | - if ( is_user_logged_in() && $save ) { |
|
| 1640 | + if (is_user_logged_in() && $save) { |
|
| 1641 | 1641 | $user_id = get_current_user_id(); |
| 1642 | 1642 | |
| 1643 | - if ( !empty( $vat_number ) ) { |
|
| 1644 | - update_user_meta( $user_id, '_wpinv_vat_number', $vat_number ); |
|
| 1643 | + if (!empty($vat_number)) { |
|
| 1644 | + update_user_meta($user_id, '_wpinv_vat_number', $vat_number); |
|
| 1645 | 1645 | } else { |
| 1646 | - delete_user_meta( $user_id, '_wpinv_vat_number'); |
|
| 1646 | + delete_user_meta($user_id, '_wpinv_vat_number'); |
|
| 1647 | 1647 | } |
| 1648 | 1648 | |
| 1649 | - if ( !empty( $company ) ) { |
|
| 1650 | - update_user_meta( $user_id, '_wpinv_company', $company ); |
|
| 1649 | + if (!empty($company)) { |
|
| 1650 | + update_user_meta($user_id, '_wpinv_company', $company); |
|
| 1651 | 1651 | } else { |
| 1652 | - delete_user_meta( $user_id, '_wpinv_company'); |
|
| 1653 | - delete_user_meta( $user_id, '_wpinv_vat_number'); |
|
| 1652 | + delete_user_meta($user_id, '_wpinv_company'); |
|
| 1653 | + delete_user_meta($user_id, '_wpinv_vat_number'); |
|
| 1654 | 1654 | } |
| 1655 | 1655 | } |
| 1656 | 1656 | |
@@ -1660,113 +1660,113 @@ discard block |
||
| 1660 | 1660 | public static function ajax_vat_validate() { |
| 1661 | 1661 | global $wpinv_options, $wpi_session; |
| 1662 | 1662 | |
| 1663 | - $is_checkout = ( !empty( $_POST['source'] ) && $_POST['source'] == 'checkout' ) ? true : false; |
|
| 1663 | + $is_checkout = (!empty($_POST['source']) && $_POST['source'] == 'checkout') ? true : false; |
|
| 1664 | 1664 | $response = array(); |
| 1665 | 1665 | $response['success'] = false; |
| 1666 | 1666 | |
| 1667 | - if ( empty( $_REQUEST['_wpi_nonce'] ) || ( !empty( $_REQUEST['_wpi_nonce'] ) && !wp_verify_nonce( $_REQUEST['_wpi_nonce'], 'vat_validation' ) ) ) { |
|
| 1668 | - $response['error'] = __( 'Invalid security nonce', 'invoicing' ); |
|
| 1669 | - wp_send_json( $response ); |
|
| 1667 | + if (empty($_REQUEST['_wpi_nonce']) || (!empty($_REQUEST['_wpi_nonce']) && !wp_verify_nonce($_REQUEST['_wpi_nonce'], 'vat_validation'))) { |
|
| 1668 | + $response['error'] = __('Invalid security nonce', 'invoicing'); |
|
| 1669 | + wp_send_json($response); |
|
| 1670 | 1670 | } |
| 1671 | 1671 | |
| 1672 | - $vat_name = self::get_vat_name(); |
|
| 1672 | + $vat_name = self::get_vat_name(); |
|
| 1673 | 1673 | |
| 1674 | - if ( $is_checkout ) { |
|
| 1674 | + if ($is_checkout) { |
|
| 1675 | 1675 | $invoice = wpinv_get_invoice_cart(); |
| 1676 | 1676 | |
| 1677 | - if ( !self::requires_vat( false, 0, self::invoice_has_digital_rule( $invoice ) ) ) { |
|
| 1677 | + if (!self::requires_vat(false, 0, self::invoice_has_digital_rule($invoice))) { |
|
| 1678 | 1678 | $vat_info = array(); |
| 1679 | - $wpi_session->set( 'user_vat_data', $vat_info ); |
|
| 1679 | + $wpi_session->set('user_vat_data', $vat_info); |
|
| 1680 | 1680 | |
| 1681 | 1681 | self::save_user_vat_details(); |
| 1682 | 1682 | |
| 1683 | 1683 | $response['success'] = true; |
| 1684 | - $response['message'] = wp_sprintf( __( 'Ignore %s', 'invoicing' ), $vat_name ); |
|
| 1685 | - wp_send_json( $response ); |
|
| 1684 | + $response['message'] = wp_sprintf(__('Ignore %s', 'invoicing'), $vat_name); |
|
| 1685 | + wp_send_json($response); |
|
| 1686 | 1686 | } |
| 1687 | 1687 | } |
| 1688 | 1688 | |
| 1689 | - $company = !empty( $_POST['company'] ) ? sanitize_text_field( $_POST['company'] ) : ''; |
|
| 1690 | - $vat_number = !empty( $_POST['number'] ) ? sanitize_text_field( $_POST['number'] ) : ''; |
|
| 1689 | + $company = !empty($_POST['company']) ? sanitize_text_field($_POST['company']) : ''; |
|
| 1690 | + $vat_number = !empty($_POST['number']) ? sanitize_text_field($_POST['number']) : ''; |
|
| 1691 | 1691 | |
| 1692 | - $vat_info = $wpi_session->get( 'user_vat_data' ); |
|
| 1693 | - if ( !is_array( $vat_info ) || empty( $vat_info ) ) { |
|
| 1694 | - $vat_info = array( 'company'=> $company, 'number' => '', 'valid' => true ); |
|
| 1692 | + $vat_info = $wpi_session->get('user_vat_data'); |
|
| 1693 | + if (!is_array($vat_info) || empty($vat_info)) { |
|
| 1694 | + $vat_info = array('company'=> $company, 'number' => '', 'valid' => true); |
|
| 1695 | 1695 | } |
| 1696 | 1696 | |
| 1697 | - if ( empty( $vat_number ) ) { |
|
| 1698 | - if ( $is_checkout ) { |
|
| 1697 | + if (empty($vat_number)) { |
|
| 1698 | + if ($is_checkout) { |
|
| 1699 | 1699 | $response['success'] = true; |
| 1700 | - $response['message'] = wp_sprintf( __( 'No %s number has been applied. %s will be added to invoice totals', 'invoicing' ), $vat_name, $vat_name ); |
|
| 1700 | + $response['message'] = wp_sprintf(__('No %s number has been applied. %s will be added to invoice totals', 'invoicing'), $vat_name, $vat_name); |
|
| 1701 | 1701 | |
| 1702 | - $vat_info = $wpi_session->get( 'user_vat_data' ); |
|
| 1702 | + $vat_info = $wpi_session->get('user_vat_data'); |
|
| 1703 | 1703 | $vat_info['number'] = ""; |
| 1704 | 1704 | $vat_info['valid'] = true; |
| 1705 | 1705 | |
| 1706 | - self::save_user_vat_details( $company ); |
|
| 1706 | + self::save_user_vat_details($company); |
|
| 1707 | 1707 | } else { |
| 1708 | - $response['error'] = wp_sprintf( __( 'Please enter your %s number!', 'invoicing' ), $vat_name ); |
|
| 1708 | + $response['error'] = wp_sprintf(__('Please enter your %s number!', 'invoicing'), $vat_name); |
|
| 1709 | 1709 | |
| 1710 | 1710 | $vat_info['valid'] = false; |
| 1711 | 1711 | } |
| 1712 | 1712 | |
| 1713 | - $wpi_session->set( 'user_vat_data', $vat_info ); |
|
| 1714 | - wp_send_json( $response ); |
|
| 1713 | + $wpi_session->set('user_vat_data', $vat_info); |
|
| 1714 | + wp_send_json($response); |
|
| 1715 | 1715 | } |
| 1716 | 1716 | |
| 1717 | - if ( empty( $company ) ) { |
|
| 1717 | + if (empty($company)) { |
|
| 1718 | 1718 | $vat_info['valid'] = false; |
| 1719 | - $wpi_session->set( 'user_vat_data', $vat_info ); |
|
| 1719 | + $wpi_session->set('user_vat_data', $vat_info); |
|
| 1720 | 1720 | |
| 1721 | - $response['error'] = __( 'Please enter your registered company name!', 'invoicing' ); |
|
| 1722 | - wp_send_json( $response ); |
|
| 1721 | + $response['error'] = __('Please enter your registered company name!', 'invoicing'); |
|
| 1722 | + wp_send_json($response); |
|
| 1723 | 1723 | } |
| 1724 | 1724 | |
| 1725 | - if ( !empty( $wpinv_options['vat_vies_check'] ) ) { |
|
| 1726 | - if ( empty( $wpinv_options['vat_offline_check'] ) && !self::offline_check( $vat_number ) ) { |
|
| 1725 | + if (!empty($wpinv_options['vat_vies_check'])) { |
|
| 1726 | + if (empty($wpinv_options['vat_offline_check']) && !self::offline_check($vat_number)) { |
|
| 1727 | 1727 | $vat_info['valid'] = false; |
| 1728 | - $wpi_session->set( 'user_vat_data', $vat_info ); |
|
| 1728 | + $wpi_session->set('user_vat_data', $vat_info); |
|
| 1729 | 1729 | |
| 1730 | - $response['error'] = wp_sprintf( __( '%s number not validated', 'invoicing' ), $vat_name ); |
|
| 1731 | - wp_send_json( $response ); |
|
| 1730 | + $response['error'] = wp_sprintf(__('%s number not validated', 'invoicing'), $vat_name); |
|
| 1731 | + wp_send_json($response); |
|
| 1732 | 1732 | } |
| 1733 | 1733 | |
| 1734 | 1734 | $response['success'] = true; |
| 1735 | - $response['message'] = wp_sprintf( __( '%s number validated', 'invoicing' ), $vat_name ); |
|
| 1735 | + $response['message'] = wp_sprintf(__('%s number validated', 'invoicing'), $vat_name); |
|
| 1736 | 1736 | } else { |
| 1737 | - $result = self::check_vat( $vat_number ); |
|
| 1737 | + $result = self::check_vat($vat_number); |
|
| 1738 | 1738 | |
| 1739 | - if ( empty( $result['valid'] ) ) { |
|
| 1739 | + if (empty($result['valid'])) { |
|
| 1740 | 1740 | $response['error'] = $result['message']; |
| 1741 | - wp_send_json( $response ); |
|
| 1741 | + wp_send_json($response); |
|
| 1742 | 1742 | } |
| 1743 | 1743 | |
| 1744 | - $vies_company = !empty( $result['company'] ) ? $result['company'] : ''; |
|
| 1745 | - $vies_company = apply_filters( 'wpinv_vies_company_name', $vies_company ); |
|
| 1744 | + $vies_company = !empty($result['company']) ? $result['company'] : ''; |
|
| 1745 | + $vies_company = apply_filters('wpinv_vies_company_name', $vies_company); |
|
| 1746 | 1746 | |
| 1747 | - $valid_company = $vies_company && $company && ( $vies_company == '---' || strcasecmp( trim( $vies_company ), trim( $company ) ) == 0 ) ? true : false; |
|
| 1747 | + $valid_company = $vies_company && $company && ($vies_company == '---' || strcasecmp(trim($vies_company), trim($company)) == 0) ? true : false; |
|
| 1748 | 1748 | |
| 1749 | - if ( !empty( $wpinv_options['vat_disable_company_name_check'] ) || $valid_company ) { |
|
| 1749 | + if (!empty($wpinv_options['vat_disable_company_name_check']) || $valid_company) { |
|
| 1750 | 1750 | $response['success'] = true; |
| 1751 | - $response['message'] = wp_sprintf( __( '%s number validated', 'invoicing' ), $vat_name ); |
|
| 1751 | + $response['message'] = wp_sprintf(__('%s number validated', 'invoicing'), $vat_name); |
|
| 1752 | 1752 | } else { |
| 1753 | 1753 | $vat_info['valid'] = false; |
| 1754 | - $wpi_session->set( 'user_vat_data', $vat_info ); |
|
| 1754 | + $wpi_session->set('user_vat_data', $vat_info); |
|
| 1755 | 1755 | |
| 1756 | 1756 | $response['success'] = false; |
| 1757 | - $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 ); |
|
| 1758 | - wp_send_json( $response ); |
|
| 1757 | + $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); |
|
| 1758 | + wp_send_json($response); |
|
| 1759 | 1759 | } |
| 1760 | 1760 | } |
| 1761 | 1761 | |
| 1762 | - if ( $is_checkout ) { |
|
| 1763 | - self::save_user_vat_details( $company, $vat_number ); |
|
| 1762 | + if ($is_checkout) { |
|
| 1763 | + self::save_user_vat_details($company, $vat_number); |
|
| 1764 | 1764 | |
| 1765 | - $vat_info = array('company' => $company, 'number' => $vat_number, 'valid' => true ); |
|
| 1766 | - $wpi_session->set( 'user_vat_data', $vat_info ); |
|
| 1765 | + $vat_info = array('company' => $company, 'number' => $vat_number, 'valid' => true); |
|
| 1766 | + $wpi_session->set('user_vat_data', $vat_info); |
|
| 1767 | 1767 | } |
| 1768 | 1768 | |
| 1769 | - wp_send_json( $response ); |
|
| 1769 | + wp_send_json($response); |
|
| 1770 | 1770 | } |
| 1771 | 1771 | |
| 1772 | 1772 | public static function ajax_vat_reset() { |
@@ -1775,161 +1775,161 @@ discard block |
||
| 1775 | 1775 | $company = is_user_logged_in() ? self::get_user_company() : ''; |
| 1776 | 1776 | $vat_number = self::get_user_vat_number(); |
| 1777 | 1777 | |
| 1778 | - $vat_info = array('company' => $company, 'number' => $vat_number, 'valid' => false ); |
|
| 1779 | - $wpi_session->set( 'user_vat_data', $vat_info ); |
|
| 1778 | + $vat_info = array('company' => $company, 'number' => $vat_number, 'valid' => false); |
|
| 1779 | + $wpi_session->set('user_vat_data', $vat_info); |
|
| 1780 | 1780 | |
| 1781 | 1781 | $response = array(); |
| 1782 | 1782 | $response['success'] = true; |
| 1783 | 1783 | $response['data']['company'] = $company; |
| 1784 | 1784 | $response['data']['number'] = $vat_number; |
| 1785 | 1785 | |
| 1786 | - wp_send_json( $response ); |
|
| 1786 | + wp_send_json($response); |
|
| 1787 | 1787 | } |
| 1788 | 1788 | |
| 1789 | - public static function checkout_vat_validate( $valid_data, $post ) { |
|
| 1789 | + public static function checkout_vat_validate($valid_data, $post) { |
|
| 1790 | 1790 | global $wpinv_options, $wpi_session; |
| 1791 | 1791 | |
| 1792 | - $vat_name = __( self::get_vat_name(), 'invoicing' ); |
|
| 1792 | + $vat_name = __(self::get_vat_name(), 'invoicing'); |
|
| 1793 | 1793 | |
| 1794 | - if ( !isset( $_POST['_wpi_nonce'] ) || !wp_verify_nonce( $_POST['_wpi_nonce'], 'vat_validation' ) ) { |
|
| 1795 | - wpinv_set_error( 'vat_validation', wp_sprintf( __( "Invalid %s validation request.", 'invoicing' ), $vat_name ) ); |
|
| 1794 | + if (!isset($_POST['_wpi_nonce']) || !wp_verify_nonce($_POST['_wpi_nonce'], 'vat_validation')) { |
|
| 1795 | + wpinv_set_error('vat_validation', wp_sprintf(__("Invalid %s validation request.", 'invoicing'), $vat_name)); |
|
| 1796 | 1796 | return; |
| 1797 | 1797 | } |
| 1798 | 1798 | |
| 1799 | - $vat_saved = $wpi_session->get( 'user_vat_data' ); |
|
| 1800 | - $wpi_session->set( 'user_vat_data', null ); |
|
| 1799 | + $vat_saved = $wpi_session->get('user_vat_data'); |
|
| 1800 | + $wpi_session->set('user_vat_data', null); |
|
| 1801 | 1801 | |
| 1802 | 1802 | $invoice = wpinv_get_invoice_cart(); |
| 1803 | 1803 | $amount = $invoice->get_total(); |
| 1804 | - $is_digital = self::invoice_has_digital_rule( $invoice ); |
|
| 1805 | - $no_vat = !self::requires_vat( 0, false, $is_digital ); |
|
| 1804 | + $is_digital = self::invoice_has_digital_rule($invoice); |
|
| 1805 | + $no_vat = !self::requires_vat(0, false, $is_digital); |
|
| 1806 | 1806 | |
| 1807 | - $company = !empty( $_POST['wpinv_company'] ) ? $_POST['wpinv_company'] : null; |
|
| 1808 | - $vat_number = !empty( $_POST['wpinv_vat_number'] ) ? $_POST['wpinv_vat_number'] : null; |
|
| 1809 | - $country = !empty( $_POST['wpinv_country'] ) ? $_POST['wpinv_country'] : $invoice->country; |
|
| 1810 | - if ( empty( $country ) ) { |
|
| 1807 | + $company = !empty($_POST['wpinv_company']) ? $_POST['wpinv_company'] : null; |
|
| 1808 | + $vat_number = !empty($_POST['wpinv_vat_number']) ? $_POST['wpinv_vat_number'] : null; |
|
| 1809 | + $country = !empty($_POST['wpinv_country']) ? $_POST['wpinv_country'] : $invoice->country; |
|
| 1810 | + if (empty($country)) { |
|
| 1811 | 1811 | $country = wpinv_default_billing_country(); |
| 1812 | 1812 | } |
| 1813 | 1813 | |
| 1814 | - if ( !$is_digital && $no_vat ) { |
|
| 1814 | + if (!$is_digital && $no_vat) { |
|
| 1815 | 1815 | return; |
| 1816 | 1816 | } |
| 1817 | 1817 | |
| 1818 | - $vat_data = array( 'company' => '', 'number' => '', 'valid' => false ); |
|
| 1818 | + $vat_data = array('company' => '', 'number' => '', 'valid' => false); |
|
| 1819 | 1819 | |
| 1820 | 1820 | $ip_country_code = self::get_country_by_ip(); |
| 1821 | - $is_eu_state = self::is_eu_state( $country ); |
|
| 1822 | - $is_eu_state_ip = self::is_eu_state( $ip_country_code ); |
|
| 1821 | + $is_eu_state = self::is_eu_state($country); |
|
| 1822 | + $is_eu_state_ip = self::is_eu_state($ip_country_code); |
|
| 1823 | 1823 | $is_non_eu_user = !$is_eu_state && !$is_eu_state_ip; |
| 1824 | 1824 | |
| 1825 | - if ( $is_digital && !$is_non_eu_user && empty( $vat_number ) && apply_filters( 'wpinv_checkout_requires_country', true, $amount ) ) { |
|
| 1825 | + if ($is_digital && !$is_non_eu_user && empty($vat_number) && apply_filters('wpinv_checkout_requires_country', true, $amount)) { |
|
| 1826 | 1826 | $vat_data['adddress_confirmed'] = false; |
| 1827 | 1827 | |
| 1828 | - if ( !isset( $_POST['wpinv_adddress_confirmed'] ) ) { |
|
| 1829 | - if ( $ip_country_code != $country ) { |
|
| 1830 | - 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>' ) ); |
|
| 1828 | + if (!isset($_POST['wpinv_adddress_confirmed'])) { |
|
| 1829 | + if ($ip_country_code != $country) { |
|
| 1830 | + 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>')); |
|
| 1831 | 1831 | } |
| 1832 | 1832 | } else { |
| 1833 | 1833 | $vat_data['adddress_confirmed'] = true; |
| 1834 | 1834 | } |
| 1835 | 1835 | } |
| 1836 | 1836 | |
| 1837 | - if ( !empty( $wpinv_options['vat_prevent_b2c_purchase'] ) && !$is_non_eu_user && ( empty( $vat_number ) || $no_vat ) ) { |
|
| 1838 | - if ( $is_eu_state ) { |
|
| 1839 | - 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 ) ); |
|
| 1840 | - } else if ( $is_digital && $is_eu_state_ip ) { |
|
| 1841 | - wpinv_set_error( 'vat_validation', wp_sprintf( __( 'Sales to non-EU countries cannot be completed because %s must be applied.', 'invoicing' ), $vat_name ) ); |
|
| 1837 | + if (!empty($wpinv_options['vat_prevent_b2c_purchase']) && !$is_non_eu_user && (empty($vat_number) || $no_vat)) { |
|
| 1838 | + if ($is_eu_state) { |
|
| 1839 | + 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)); |
|
| 1840 | + } else if ($is_digital && $is_eu_state_ip) { |
|
| 1841 | + wpinv_set_error('vat_validation', wp_sprintf(__('Sales to non-EU countries cannot be completed because %s must be applied.', 'invoicing'), $vat_name)); |
|
| 1842 | 1842 | } |
| 1843 | 1843 | } |
| 1844 | 1844 | |
| 1845 | - if ( !$is_eu_state || $no_vat || empty( $vat_number ) ) { |
|
| 1845 | + if (!$is_eu_state || $no_vat || empty($vat_number)) { |
|
| 1846 | 1846 | return; |
| 1847 | 1847 | } |
| 1848 | 1848 | |
| 1849 | - if ( !empty( $vat_saved ) && isset( $vat_saved['valid'] ) ) { |
|
| 1850 | - $vat_data['valid'] = $vat_saved['valid']; |
|
| 1849 | + if (!empty($vat_saved) && isset($vat_saved['valid'])) { |
|
| 1850 | + $vat_data['valid'] = $vat_saved['valid']; |
|
| 1851 | 1851 | } |
| 1852 | 1852 | |
| 1853 | - if ( $company !== null ) { |
|
| 1853 | + if ($company !== null) { |
|
| 1854 | 1854 | $vat_data['company'] = $company; |
| 1855 | 1855 | } |
| 1856 | 1856 | |
| 1857 | 1857 | $message = ''; |
| 1858 | - if ( $vat_number !== null ) { |
|
| 1858 | + if ($vat_number !== null) { |
|
| 1859 | 1859 | $vat_data['number'] = $vat_number; |
| 1860 | 1860 | |
| 1861 | - if ( !$vat_data['valid'] || ( $vat_saved['number'] !== $vat_data['number'] ) || ( $vat_saved['company'] !== $vat_data['company'] ) ) { |
|
| 1862 | - if ( !empty( $wpinv_options['vat_vies_check'] ) ) { |
|
| 1863 | - if ( empty( $wpinv_options['vat_offline_check'] ) && !self::offline_check( $vat_number ) ) { |
|
| 1861 | + if (!$vat_data['valid'] || ($vat_saved['number'] !== $vat_data['number']) || ($vat_saved['company'] !== $vat_data['company'])) { |
|
| 1862 | + if (!empty($wpinv_options['vat_vies_check'])) { |
|
| 1863 | + if (empty($wpinv_options['vat_offline_check']) && !self::offline_check($vat_number)) { |
|
| 1864 | 1864 | $vat_data['valid'] = false; |
| 1865 | 1865 | } |
| 1866 | 1866 | } else { |
| 1867 | - $result = self::check_vat( $vat_number ); |
|
| 1867 | + $result = self::check_vat($vat_number); |
|
| 1868 | 1868 | |
| 1869 | - if ( !empty( $result['valid'] ) ) { |
|
| 1869 | + if (!empty($result['valid'])) { |
|
| 1870 | 1870 | $vat_data['valid'] = true; |
| 1871 | - $vies_company = !empty( $result['company'] ) ? $result['company'] : ''; |
|
| 1872 | - $vies_company = apply_filters( 'wpinv_vies_company_name', $vies_company ); |
|
| 1871 | + $vies_company = !empty($result['company']) ? $result['company'] : ''; |
|
| 1872 | + $vies_company = apply_filters('wpinv_vies_company_name', $vies_company); |
|
| 1873 | 1873 | |
| 1874 | - $valid_company = $vies_company && $company && ( $vies_company == '---' || strcasecmp( trim( $vies_company ), trim( $company ) ) == 0 ) ? true : false; |
|
| 1874 | + $valid_company = $vies_company && $company && ($vies_company == '---' || strcasecmp(trim($vies_company), trim($company)) == 0) ? true : false; |
|
| 1875 | 1875 | |
| 1876 | - if ( !( !empty( $wpinv_options['vat_disable_company_name_check'] ) || $valid_company ) ) { |
|
| 1876 | + if (!(!empty($wpinv_options['vat_disable_company_name_check']) || $valid_company)) { |
|
| 1877 | 1877 | $vat_data['valid'] = false; |
| 1878 | 1878 | |
| 1879 | - $message = wp_sprintf( __( 'The company name associated with the %s number provided is not the same as the company name provided.', 'invoicing' ), $vat_name ); |
|
| 1879 | + $message = wp_sprintf(__('The company name associated with the %s number provided is not the same as the company name provided.', 'invoicing'), $vat_name); |
|
| 1880 | 1880 | } |
| 1881 | 1881 | } else { |
| 1882 | - $message = wp_sprintf( __( 'Fail to validate the %s number: EU Commission VAT server (VIES) check fails.', 'invoicing' ), $vat_name ); |
|
| 1882 | + $message = wp_sprintf(__('Fail to validate the %s number: EU Commission VAT server (VIES) check fails.', 'invoicing'), $vat_name); |
|
| 1883 | 1883 | } |
| 1884 | 1884 | } |
| 1885 | 1885 | |
| 1886 | - if ( !$vat_data['valid'] ) { |
|
| 1887 | - $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 . ' )' : '' ); |
|
| 1888 | - wpinv_set_error( 'vat_validation', $error ); |
|
| 1886 | + if (!$vat_data['valid']) { |
|
| 1887 | + $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 . ' )' : ''); |
|
| 1888 | + wpinv_set_error('vat_validation', $error); |
|
| 1889 | 1889 | } |
| 1890 | 1890 | } |
| 1891 | 1891 | } |
| 1892 | 1892 | |
| 1893 | - $wpi_session->set( 'user_vat_data', $vat_data ); |
|
| 1893 | + $wpi_session->set('user_vat_data', $vat_data); |
|
| 1894 | 1894 | } |
| 1895 | 1895 | |
| 1896 | - public static function checkout_vat_fields( $billing_details ) { |
|
| 1896 | + public static function checkout_vat_fields($billing_details) { |
|
| 1897 | 1897 | global $wpi_session, $wpinv_options, $wpi_country, $wpi_requires_vat; |
| 1898 | 1898 | |
| 1899 | 1899 | $ip_address = wpinv_get_ip(); |
| 1900 | 1900 | $ip_country_code = self::get_country_by_ip(); |
| 1901 | 1901 | |
| 1902 | - $tax_label = __( self::get_vat_name(), 'invoicing' ); |
|
| 1902 | + $tax_label = __(self::get_vat_name(), 'invoicing'); |
|
| 1903 | 1903 | $invoice = wpinv_get_invoice_cart(); |
| 1904 | - $is_digital = self::invoice_has_digital_rule( $invoice ); |
|
| 1904 | + $is_digital = self::invoice_has_digital_rule($invoice); |
|
| 1905 | 1905 | $wpi_country = $invoice->country; |
| 1906 | 1906 | |
| 1907 | - $requires_vat = !self::hide_vat_fields() && !$invoice->is_free() && self::requires_vat( 0, false, $is_digital ); |
|
| 1907 | + $requires_vat = !self::hide_vat_fields() && !$invoice->is_free() && self::requires_vat(0, false, $is_digital); |
|
| 1908 | 1908 | $wpi_requires_vat = $requires_vat; |
| 1909 | 1909 | |
| 1910 | 1910 | $company = self::get_user_company(); |
| 1911 | 1911 | $vat_number = self::get_user_vat_number(); |
| 1912 | 1912 | |
| 1913 | - $validated = $vat_number ? self::get_user_vat_number( '', 0, true ) : 1; |
|
| 1914 | - $vat_info = $wpi_session->get( 'user_vat_data' ); |
|
| 1913 | + $validated = $vat_number ? self::get_user_vat_number('', 0, true) : 1; |
|
| 1914 | + $vat_info = $wpi_session->get('user_vat_data'); |
|
| 1915 | 1915 | |
| 1916 | - if ( is_array( $vat_info ) ) { |
|
| 1917 | - $company = isset( $vat_info['company'] ) ? $vat_info['company'] : ''; |
|
| 1918 | - $vat_number = isset( $vat_info['number'] ) ? $vat_info['number'] : ''; |
|
| 1919 | - $validated = isset( $vat_info['valid'] ) ? $vat_info['valid'] : false; |
|
| 1916 | + if (is_array($vat_info)) { |
|
| 1917 | + $company = isset($vat_info['company']) ? $vat_info['company'] : ''; |
|
| 1918 | + $vat_number = isset($vat_info['number']) ? $vat_info['number'] : ''; |
|
| 1919 | + $validated = isset($vat_info['valid']) ? $vat_info['valid'] : false; |
|
| 1920 | 1920 | } |
| 1921 | 1921 | |
| 1922 | 1922 | $selected_country = $invoice->country ? $invoice->country : wpinv_default_billing_country(); |
| 1923 | 1923 | |
| 1924 | - if ( $ip_country_code == 'UK' ) { |
|
| 1924 | + if ($ip_country_code == 'UK') { |
|
| 1925 | 1925 | $ip_country_code = 'GB'; |
| 1926 | 1926 | } |
| 1927 | 1927 | |
| 1928 | - if ( $selected_country == 'UK' ) { |
|
| 1928 | + if ($selected_country == 'UK') { |
|
| 1929 | 1929 | $selected_country = 'GB'; |
| 1930 | 1930 | } |
| 1931 | 1931 | |
| 1932 | - if ( $requires_vat && ( self::same_country_rule() == 'no' && wpinv_is_base_country( $selected_country ) || !self::allow_vat_rules() ) ) { |
|
| 1932 | + if ($requires_vat && (self::same_country_rule() == 'no' && wpinv_is_base_country($selected_country) || !self::allow_vat_rules())) { |
|
| 1933 | 1933 | $requires_vat = false; |
| 1934 | 1934 | } |
| 1935 | 1935 | |
@@ -1937,52 +1937,52 @@ discard block |
||
| 1937 | 1937 | $display_validate_btn = 'none'; |
| 1938 | 1938 | $display_reset_btn = 'none'; |
| 1939 | 1939 | |
| 1940 | - if ( !empty( $vat_number ) && $validated ) { |
|
| 1941 | - $vat_vailidated_text = wp_sprintf( __( '%s number validated', 'invoicing' ), $tax_label ); |
|
| 1940 | + if (!empty($vat_number) && $validated) { |
|
| 1941 | + $vat_vailidated_text = wp_sprintf(__('%s number validated', 'invoicing'), $tax_label); |
|
| 1942 | 1942 | $vat_vailidated_class = 'wpinv-vat-stat-1'; |
| 1943 | 1943 | $display_reset_btn = 'block'; |
| 1944 | 1944 | } else { |
| 1945 | - $vat_vailidated_text = empty( $vat_number ) ? '' : wp_sprintf( __( '%s number not validated', 'invoicing' ), $tax_label ); |
|
| 1946 | - $vat_vailidated_class = empty( $vat_number ) ? '' : 'wpinv-vat-stat-0'; |
|
| 1945 | + $vat_vailidated_text = empty($vat_number) ? '' : wp_sprintf(__('%s number not validated', 'invoicing'), $tax_label); |
|
| 1946 | + $vat_vailidated_class = empty($vat_number) ? '' : 'wpinv-vat-stat-0'; |
|
| 1947 | 1947 | $display_validate_btn = 'block'; |
| 1948 | 1948 | } |
| 1949 | 1949 | |
| 1950 | - $show_ip_country = $is_digital && ( empty( $vat_number ) || !$requires_vat ) && $ip_country_code != $selected_country ? 'block' : 'none'; |
|
| 1950 | + $show_ip_country = $is_digital && (empty($vat_number) || !$requires_vat) && $ip_country_code != $selected_country ? 'block' : 'none'; |
|
| 1951 | 1951 | ?> |
| 1952 | 1952 | <div id="wpi-vat-details" class="wpi-vat-details clearfix" style="display:<?php echo $display_vat_details; ?>"> |
| 1953 | 1953 | <div id="wpi_vat_info" class="clearfix panel panel-default"> |
| 1954 | - <div class="panel-heading"><h3 class="panel-title"><?php echo wp_sprintf( __( '%s Details', 'invoicing' ), $tax_label );?></h3></div> |
|
| 1954 | + <div class="panel-heading"><h3 class="panel-title"><?php echo wp_sprintf(__('%s Details', 'invoicing'), $tax_label); ?></h3></div> |
|
| 1955 | 1955 | <div id="wpinv-fields-box" class="panel-body"> |
| 1956 | 1956 | <p id="wpi_show_vat_note"> |
| 1957 | - <?php echo wp_sprintf( __( 'Validate your registered %s number to exclude tax.', 'invoicing' ), $tax_label ); ?> |
|
| 1957 | + <?php echo wp_sprintf(__('Validate your registered %s number to exclude tax.', 'invoicing'), $tax_label); ?> |
|
| 1958 | 1958 | </p> |
| 1959 | 1959 | <div id="wpi_vat_fields" class="wpi_vat_info"> |
| 1960 | 1960 | <p class="wpi-cart-field wpi-col2 wpi-colf"> |
| 1961 | - <label for="wpinv_company" class="wpi-label"><?php _e( 'Company Name', 'invoicing' );?></label> |
|
| 1961 | + <label for="wpinv_company" class="wpi-label"><?php _e('Company Name', 'invoicing'); ?></label> |
|
| 1962 | 1962 | <?php |
| 1963 | - echo wpinv_html_text( array( |
|
| 1963 | + echo wpinv_html_text(array( |
|
| 1964 | 1964 | 'id' => 'wpinv_company', |
| 1965 | 1965 | 'name' => 'wpinv_company', |
| 1966 | 1966 | 'value' => $company, |
| 1967 | 1967 | 'class' => 'wpi-input form-control', |
| 1968 | - 'placeholder' => __( 'Company name', 'invoicing' ), |
|
| 1969 | - ) ); |
|
| 1968 | + 'placeholder' => __('Company name', 'invoicing'), |
|
| 1969 | + )); |
|
| 1970 | 1970 | ?> |
| 1971 | 1971 | </p> |
| 1972 | 1972 | <p class="wpi-cart-field wpi-col2 wpi-coll wpi-cart-field-vat"> |
| 1973 | - <label for="wpinv_vat_number" class="wpi-label"><?php echo wp_sprintf( __( '%s Number', 'invoicing' ), $tax_label );?></label> |
|
| 1973 | + <label for="wpinv_vat_number" class="wpi-label"><?php echo wp_sprintf(__('%s Number', 'invoicing'), $tax_label); ?></label> |
|
| 1974 | 1974 | <span id="wpinv_vat_number-wrap"> |
| 1975 | 1975 | <label for="wpinv_vat_number" class="wpinv-label"></label> |
| 1976 | - <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"> |
|
| 1977 | - <span class="wpinv-vat-stat <?php echo $vat_vailidated_class;?>"><i class="fa"></i> <font><?php echo $vat_vailidated_text;?></font></span> |
|
| 1976 | + <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"> |
|
| 1977 | + <span class="wpinv-vat-stat <?php echo $vat_vailidated_class; ?>"><i class="fa"></i> <font><?php echo $vat_vailidated_text; ?></font></span> |
|
| 1978 | 1978 | </span> |
| 1979 | 1979 | </p> |
| 1980 | 1980 | <p class="wpi-cart-field wpi-col wpi-colf wpi-cart-field-actions"> |
| 1981 | - <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> |
|
| 1982 | - <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> |
|
| 1981 | + <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> |
|
| 1982 | + <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> |
|
| 1983 | 1983 | <span class="wpi-vat-box wpi-vat-box-info"><span id="text"></span></span> |
| 1984 | 1984 | <span class="wpi-vat-box wpi-vat-box-error"><span id="text"></span></span> |
| 1985 | - <input type="hidden" name="_wpi_nonce" value="<?php echo wp_create_nonce( 'vat_validation' ) ?>" /> |
|
| 1985 | + <input type="hidden" name="_wpi_nonce" value="<?php echo wp_create_nonce('vat_validation') ?>" /> |
|
| 1986 | 1986 | </p> |
| 1987 | 1987 | </div> |
| 1988 | 1988 | </div> |
@@ -1996,32 +1996,32 @@ discard block |
||
| 1996 | 1996 | </span> |
| 1997 | 1997 | </div> |
| 1998 | 1998 | </div> |
| 1999 | - <?php if ( empty( $wpinv_options['hide_ip_address'] ) ) { |
|
| 2000 | - $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>'; |
|
| 1999 | + <?php if (empty($wpinv_options['hide_ip_address'])) { |
|
| 2000 | + $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>'; |
|
| 2001 | 2001 | ?> |
| 2002 | 2002 | <div class="wpi-ip-info clearfix panel panel-info"> |
| 2003 | 2003 | <div id="wpinv-fields-box" class="panel-body"> |
| 2004 | - <span><?php echo wp_sprintf( __( "Your IP address is: %s", 'invoicing' ), $ip_link ); ?></span> |
|
| 2004 | + <span><?php echo wp_sprintf(__("Your IP address is: %s", 'invoicing'), $ip_link); ?></span> |
|
| 2005 | 2005 | </div> |
| 2006 | 2006 | </div> |
| 2007 | 2007 | <?php } |
| 2008 | 2008 | } |
| 2009 | 2009 | |
| 2010 | - public static function show_vat_notice( $invoice ) { |
|
| 2011 | - if ( empty( $invoice ) ) { |
|
| 2010 | + public static function show_vat_notice($invoice) { |
|
| 2011 | + if (empty($invoice)) { |
|
| 2012 | 2012 | return NULL; |
| 2013 | 2013 | } |
| 2014 | 2014 | |
| 2015 | - $label = wpinv_get_option( 'vat_invoice_notice_label' ); |
|
| 2016 | - $notice = wpinv_get_option( 'vat_invoice_notice' ); |
|
| 2017 | - if ( $label || $notice ) { |
|
| 2015 | + $label = wpinv_get_option('vat_invoice_notice_label'); |
|
| 2016 | + $notice = wpinv_get_option('vat_invoice_notice'); |
|
| 2017 | + if ($label || $notice) { |
|
| 2018 | 2018 | ?> |
| 2019 | 2019 | <div class="row wpinv-vat-notice"> |
| 2020 | 2020 | <div class="col-sm-12"> |
| 2021 | - <?php if ( $label ) { ?> |
|
| 2022 | - <strong><?php _e( $label, 'invoicing' ); ?></strong> |
|
| 2023 | - <?php } if ( $notice ) { ?> |
|
| 2024 | - <?php echo wpautop( wptexturize( __( $notice, 'invoicing' ) ) ) ?> |
|
| 2021 | + <?php if ($label) { ?> |
|
| 2022 | + <strong><?php _e($label, 'invoicing'); ?></strong> |
|
| 2023 | + <?php } if ($notice) { ?> |
|
| 2024 | + <?php echo wpautop(wptexturize(__($notice, 'invoicing'))) ?> |
|
| 2025 | 2025 | <?php } ?> |
| 2026 | 2026 | </div> |
| 2027 | 2027 | </div> |