Requires Craft 2.5+, running php 5.5.9+
If you're using coupons with your payments you can optionally include pre-validation on coupons seperate to the regular full validation.
Note: this validation is additional to the native coupon validation. Coupons are always validated when they are applied to a payment, regardless of this setup.
When a coupon field is passed as part of a payment attempt it is validated. If valid the payment attempt will continue, but if not, the submission will return with an error attached to the coupon field, with a message similar to 'Sorry, this coupon code is invalid'.
Optionally you can use the extra AJAX endpoint of :
charge/coupon/validate to check the validity of a coupon prior to form submission, and return a valid/invalid message early.
This endpoint always return a JSON response.
Success State :
messageString 'This coupon is valid'
paymentTypeString 'One-off' or 'Recurring'
couponArray of the associated coupon
Failure State :
messageString similar to : 'Sorry, this coupon is invalid' etc..
Note: Just because a coupon returns as valid doesn't guarantee it will be accepted for the payment. Further restrictions may apply when the coupon is applied such as paymentType mismatch, limits on usages, etc... Always include coupon validation error message output in your templates.