Question about the wix-pay API triggered from form submission

Hello!
I have a form that a user enters data into and upon submitting, a payment window opens. I want to hold off on submitting the form until a payment is completed.

I was looking through the API trying to figure out the best way to code this:


Should I have onWixFormSubmit() return True only if the payment == successful? If so, should I have it return false? What about with pending, etc.?

$w("#wixForms2").onWixFormSubmit((event) => {
        //grabs the index of the chosen radio button
        let selectedIndex = $w("#radioGroup3").selectedIndex;
        let customInput = $w("#input23").value; // Saves the value of the custom amount input
        let emailInput = $w("#input10").value;

    // Payment API. Opens a lightbox on success
        createPaymentForProduct(selectedIndex, customInput).then(payment => {
            wixPay.startPayment(payment.id, {"showThankYouPage": false})
            .then((result) => {
                if (result.status === "Successful") {
                
                    sendEmailToContact(emailInput);
                    
                    $w('#text262').show();
                    
                    setTimeout(function() {
                        wixWindow.openLightbox("HN-information");
                    }, 500);

                    setTimeout(function() {
                        $w('#text262').hide();
                    }, 8000);

                } else {
                    console.log(result.status)
                }
            });
        });

        /*
        if () {
            return false;
        } else {
            return true;
        }
        */
        
    });

My code above. I have a commented out if/else statement because I was reading around and thought I could stop the submission if the payment status wasn’t “successful” but I can’t figure out how to access the results.status in the above function… Any advice?

Bumping with included code