I’m running into a problem where a custom form isn’t recording to a data collection after a customer processes a successful transaction through the Wix Pay box.
I believe the bug exists when a customer receives a Thank You! message from the pay box and then closes their browser instead of clicking the “Got It” confirmation button or the X in the top corner. If they opt to close their browser window, our page code never receives a success status to save the data to a collection or process our triggered email function.
Here is the page code for my button function; how could I optimize this to handle the edge case where a customer closes their browser after a successful payment?
export function payBoxButton_click(event) {
let paymentOptions = {
userInfo: {
firstName: $w("#firstName").value,
lastName: $w("#lastName").value,
country: null,
phone: $w("#phone").value,
email: $w("#email").value.toLowerCase()
}
}
createPayment(
'databaseCollection',
$w('#start').value,
$w('#end').value,
$w('#time').value,
$w('#date').value
)
.then((payment) => {
wixPay.startPayment(payment.id, paymentOptions)
.then((result) => {
if (result.status === "Successful") {
// send email to the user
emailUserOwy(
$w('#firstName').value,
$w('#lastName').value,
$w('#phone').value,
$w('#email').value.toLowerCase(),
$w('#time').value,
$w('#start').value,
$w('#end').value,
$w('#date').value
)
// save to db and open success window
wixData.insert("dataCollection", $w("#dataset3").getCurrentItem())
.then(() => {
wixWindow.openLightbox("Success Lightbox");
})
} else {
console.log('Payment Failed')
wixWindow.openLightbox("Failed Lightbox")
}
})
})
}