-
-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
erroneous response handling -- uncaught exception #1
Comments
Thanks for the feedback @sargac @gonz For the moment, you can handle the exception from your side when using the library. use PH7\Eu\Vat\Exception as EuVatExcept;
use PH7\Eu\Vat\Validator;
use PH7\Eu\Vat\Provider\Europa;
try {
$oVatValidator = new Validator(new Europa, '0472429986', 'BE');
if ($oVatValidator->check()) {
$sRequestDate = $oVatValidator->getRequestDate();
// Optional, format the date
$sFormattedRequestDate = (new DateTime)->format('d-m-Y');
echo 'Business Name: ' . $oVatValidator->getName() . '<br />';
echo 'Address: ' . $oVatValidator->getAddress() . '<br />';
echo 'Request Date: ' . $sFormattedRequestDate . '<br />';
echo 'Member State: ' . $oVatValidator->getCountryCode() . '<br />';
echo 'VAT Number: ' . $oVatValidator->getVatNumber() . '<br />';
} else {
echo 'Invalid VAT number';
}
} catch(EuVatExcept $oExcept) {
echo 'Member State service unavailable. Please re-submit your request later.';
} Hopefully, this helps 🎉 |
@GonzaloTorreras for you as well ^^ 😃 |
From the outer code, it is important to be able to recognise at least a few reasons for problems. Currently, it throws one Exception regarding the reason. @pH-7, in your example above, the whole line which creates the Provider (new Europa) and the validator (new Validator) is in one try-catch block, so the application has no chance to recognise the reason. I agree with @sargac that we should be able to know what exactly the problem is. What's the point of trying later if our IP address is blocked. Also, it would be worth to know that the reason of the problem is an invalid input. But I do not agree that library should produce user-friendly errors as it is not its responsibility. @sargac Who are these errors for ? a developer or the end-user? The app code which uses the validator should the look more like below, in terms of dealing with exceptions.
Of course die function here is just an example. In the first catch the exception is only of one kind, so we do not need to recognise what exactly is wrong, just service in unavailalbe. The Error message factory would look as follows:
Of course in real app it would take into account localisation settings. |
That's a good suggestion @hkwak! 👍 I agree with you. |
Hello, There is any way with wordpress plugin to exclude Vat validating only for Italy? I need to validate all vat except Italy. Thanks |
Excellent question @emidev9191. Not at the moment, but you can filter only the ones starting by "IT" prefix (which is the Italian VAT, e.g. |
Thanks @pH-7 for suggest. could you give me a practical example with code? |
hi ph-7, i'm new with scrips. but what must i copy to my site to implement this? Witch file's and where manual old skoal. I did understand your tool. Because i'm looking for this what you did write. and integrate this in prestashop 1.7.8.8. because no body in at presta shop want to help. The have a VAT number input place in costumer registration. and a (siret) frans voor kvk. NL ( Chamber of Commit number.) at registration costumers. But not for back-end store and on webpage shop front end by store information. This is in Europa mandatory almost al parts are setting up mandatory.You as owner must prove you are legit business . I have got found the form placement and edit it. it works. But do not have the validator. just made it Text. 8 for NL and 10 BE. but yours is much better. Can you help me? Maybe they will take your input faster ? Ore i can write it in the write place? |
@emidev9191 For instance, you could loop with a foreach ($aCountries as $sCountryCode => $sCountryName) {
if ($sCountryCode === 'IT') {
// Skip Italy
continue;
}
// your logic here for the rest...
} Further generic examples here. Hope it helps! 🙂 |
Hello,
I've notice the (1) Validator throws a Uncaught Exception PHP Error below, when Member State Service is not available, while (2) Service page at http://ec.europa.eu/taxation_customs/vies/vatRequest.html returns a user-friendly error: Member State service unavailable. Please re-submit your request later.
There are some more cases listed in the WSDL at http://ec.europa.eu/taxation_customs/vies/checkVatTestService.wsdl -- possibly not handled by the Validator. At the time of writing, these are:
It would be brilliant, If you could add these to your Validator, so it would return (1) a user-friendly error with a customizable message, or (2) a response, based on which would be possible to manualy write the right message.
If of some help, I've noticed the Service returns (1) an Object, whenever the number is validated (valid or invalid) and (2) a String for all other cases. I didn't test many cases, so it may not hold true for all cases. Specifically I couldn't test these Numbers (100, 200, 201, etc.) mentioned in WSDL.
Best!
The text was updated successfully, but these errors were encountered: