-
Notifications
You must be signed in to change notification settings - Fork 0
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
Initial version #1
Conversation
``` | ||
composer require :vendor_slug/:package_slug | ||
v-on:change="window.app.$emit('vat-change', $event)" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would be nice to have in the core by default
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For sure, I'm waiting for this to be approved first and then I'll make a PR to the core, checkout theme, and account. Should still have this in the readme though, so that people can easily add it to their own fields :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return $validator->validateVatNumber($request->id); | ||
}); | ||
|
||
return ['result' => $result]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we also return a 4xx response on an incorrect vat?
https://github.com/rapidez/vat-validation/pull/1/files/33022e7a5301702f72834832d9aa22d6304ce132#r1796635804
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Personally, I think returning a 4xx when the VAT is invalid seems improper, given that something being invalid is still a valid output of a check.
I would expect a true
or false
output, not a true
or ERROR 4xx
output.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could still return false on an error 4xx.
As outlined in #1 (comment)
this is inconsistent with Laravel's validator method.
We could've created a custom validation rule for a valid VAT, resulting in Laravel returning a 4xx response.
Same as how it will return a 4xx now if no vat id is provided, but a 2xx if anything is provided in the vat id field
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds fun until you end up getting a FetchError just because the status code is a 4xx 🙂 we would have to work around these pre-existing error handling routines just to get the same effect as just returning true
or false
, and I don't think I prefer that.
Again, I also don't think that returning a client or server error is the right call in this case. You also don't get an error out of the isEmailAvailable
magento rest api query when an email is not available, for example.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While it would happen more often we would be getting that without returning a 4xx ourselves as well.
Laravel returns a 4xx on validation failure too so we must account for that anyways.
I don't think we need to work around pre-existing error handling, we simply need to handle the error.
Luckily that's an easy fix already implemented here for Graphql https://github.com/rapidez/core/blob/a93fbc0de64a55559149ad0665a8d05339682c17/resources/js/components/GraphqlMutation.vue#L125
So during our catch we just need to check some additional things and change the return value:
return await window
.rapidezAPI('post', 'vat-validate', data, options)
.catch(async (error) => {
if (FetchError.prototype.isPrototypeOf(error)) {
// Now we know for sure error.response is available
if (error.response.status === 422) {
// Validation did not pass since laravel returned a 422 https://laravel.com/docs/11.x/validation#quick-xhr-requests-and-validation
return false
}
}
window.Notify(window.config.translations.errors.wrong, 'error')
return 'error'
})
Of course we can shorten it to a single if statement if we like
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've made an internal issue for this specific thing for now (key: RAP-948) 🙂
Allows a very simple VAT check on any input with:
We can add this by default into the core/checkout-theme/account inputs as well, making this package full plug and play.