Hello!
I need to store data into a collection whenever the paymentResult status is successful.
I have three payment methods: Wix Payments, Paypal and Offline.
With the first and the third methods, there is no problem, because their paymentResult status will be either successful, failed or cancelled.
But the doubt comes when using Paypal. I’ve understood that the paymentResult status is pending until the user finishes or cancels the payment in the paypal window, and when these happen, then the onPaymentUpdate event triggers.
Since I have to store data from a form in my page whenever the paymentResult status is successful, how can I set the onPaymentUpdate event in the backend so that when it’s successful, my data from the page gets saved?
I have thought of adding to columns to the collection (one for paymentID and one for paymentResult status ) and saving the data even if the paymentResult status is pending .
With this idea, when the onPaymentUpdate event in the backend triggers, if the new paymentResult status of the event gets is successful, then I could query the paymentID and update the paymentResult status of the row with the same paymentID to successful. If it’s failed or cancelled, then to delete that row.
My current code of the sucessful status is:
createPaymentForMatricula.then(payment=>{
wixPay.startPayment(payment.id, {
"termsAndConditionsLink": "<t&c>"});
}).then(async (result)=>{
if (result.status === "Successful") {
//Save data in the collection
.
.
.
wixWindow.openLightbox("Successful Box")
} else if (result.status === "Pending") {
wixWindow.openLightbox("Pending Box");
}
})
})
Is there an easier way? Is there a way to make the .then in the code above triggers again when the onPaymentUpdate() event is triggered? Because I can only save the data in the frontend.
Thank you!