Checkout Stock Validation Webhook

I did a search around the forum and couldn't find much info on validating cart quantities on checkout. The one post I did find, said that the best way would be to use the JavaScript API to validate the quantities using JSONP and stop the checkout if there are errors. This requires that the server we connect to is using SSL. Writing out the entire solution would also be more complicated than it has to be.

I think a better solution would be to have an optional endpoint on the store server where foxycart can send a validation request. This could be as simple as a JSON list of the cart contents and a requirement that the server returns an empty array or a list of error messages for the user. If the response is empty, it means there are no errors and the checkout proceeds as normal, otherwise, the user is sent back to the checkout page where they can see the error messages that were returned from the server.

This webhook request would happen on the server side of foxycart so SSL would not be required on the store server.
Comments
  • fc_adamfc_adam FoxyCart Team
    @Raul,

    Thanks for the suggestion - we were actually just discussing a feature idea recently that is kind of inline with this. I'll add some notes to that ticket based on your thoughts here.

    The solution for now is as you described - you could hook into the checkout-submit event, and send off a request to a secure endpoint on your side with the current cart contents to validate if the user can still checkout with what they have or not. More details on the events at http://wiki.foxycart.com/static/redirect/javascript
Sign In or Register to comment.