How Do I Check Stripe Coupon Validity In Stripe Elements?

I'm trying to check coupon validity while using a stripe elements form on the client side without going to server. The idea is that I want to tell a customer if their coupon is valid or invalid before signing them up for something.

Ideally I would be able to just do something like this:> {
        }).catch((error) => {
          throwCardError("Invalid coupon, please try again.");

The issue is that is not a part of the elements API, it's only part of the server-side API.

The reason I'm hesitant to check on the server side is because I use firestore to store all my data. So that means in order to get this to work, I would have to first write the coupon to firebase, have a cloud function that calls the stripe API to check the coupon validity and then writes that to a separate part of the database just for that, and then set up a listener on the client side that listens for changes to that part of the database to check coupon validity, and all of that would be really slow.

Is there any way to check the validity of a stripe coupon client side in stripe elements?



There is no function within Elements to check the validity of a coupon (you can see all available methods for Stripe.js / Elements here).

If you're using Firebase, what you can do here is setup an endpoint using a HTTP function, in your client-side code make a request to this endpoint using fetch, passing the coupon id you wish to check.

When this request hits this endpoint you will make a call out to the Stripe API to attempt to retrieve the coupon, returning the result to the user; there's no need to store a copy of the coupon within your Firebase database.