Custom wix bookings form and coupon


I have a custom booking form that contains a field to enter a coupon code. On the backend i am using the following code to retrieve coupon info and know if the user can use it so before they submit the booking form, i can display a confirmation(or not) message that the coupon has been applied and update the displayed total before paying.

When they submit the form and go to the payment window, if they have indeed already used the coupon, it won’t get applied on the total but before that, when they use my form field to apply it, it shows that the coupon is applied and they see the total with the discount applied when they shouldn’t. Basically, how can i know if a user has already used the coupon he is trying to apply so i can display a message to tell him he already used the coupon?

Also, users don’t have to be registered / logged in to book a service but they do have to fill an email field in the form.

export async function getCoupon(couponCode) {
    return wixData.query("Marketing/Coupons")
    .find({suppressAuth: true})
    .then( (results) => {
        let foundCoupon = results.items.find(item => item.code === couponCode)
        console.log("foundCoupon is:", foundCoupon);

        if (foundCoupon) {
            let canBeApplied;
                    if(foundCoupon.numberOfUsages < foundCoupon.usageLimit){
                        canBeApplied = true;
                    } else {canBeApplied = false;}
                else {canBeApplied = true;}
            else { canBeApplied = false;}

            return {
                couponExists : true,
                moneyOffAmount: foundCoupon.moneyOffAmount ? foundCoupon.moneyOffAmount : "undefined",
                percentOffRate: foundCoupon.percentOffRate ? foundCoupon.percentOffRate : "undefined",
                scope: foundCoupon.scope,
                canBeApplied : canBeApplied,
        else {
            return { couponExists : false}