Submitting form only if payment is completed

Hi all,

I currently have this piece of code that is designed to open up the wixPay API when a form is submitted (I initially had it run on the button click but have changed it to this). I’m wondering if there is a way to delay the submission so that it only sends if the user completes the payment. Currently, the form submits and an email is sent immediately after the form is submitted BUT the user can close out of the payment pop-up and the form still submits.

Should I trigger the email in code rather than wix automations? If so, how so?

I figured out some code to make this work referencing this article:

I just need to include it in the “successful” statement and I think I’m good

wixCrm . createContact ({
“emails” : [ $w ( “#input10” ). value ]
. then (( contactId ) => {
wixCrm . emailContact ( “SnlrNsP” , contactId ,)

Final code:

By the way, if anyone more experienced than me wants to audit this and let me know if I did anything wrong that would be awesome :slight_smile:

[edit] Just kidding. This doesn’t appear to work with new contacts/emails and I have no idea why. I also tested it in private mode and it appears that the createContact function was triggering off of my member account instead of off of the email.

Thoughts on a work around?

I’m starting to think it might be easier to do some sort of Async Await function to force the form to wait for a payment to be made before submitting the data

Hi all…

any thoughts? Im hoping for a solution by this weekend for my client