Hi,
I’m trying to add redirect option where when someone makes payment and the payment is successful then it should redirect to custom thank you page.
I’ve build the code but it’s not working as required, if someone can help me know where I did wrong that would be great help.
Code I made:
import { makeDonation } from 'backend/pay';
import { makeCustomDonation } from 'backend/pay';
import wixPay from 'wix-pay';
import wixLocation from 'wix-location';
$w.onReady(function () {
$w("#selectAmount").onChange((event) => {
$w("#enterAmount").value = null;
$w("#enterAmount").placeholder = "0.00";
});
$w("#enterAmount").onKeyPress((event) => {
$w("#selectAmount").selectedIndex = null;
});
$w('#donateButton').onClick(async () => {
let checkSelect = Number($w("#selectAmount").value);
let checkEnter = Number($w("#enterAmount").value);
if (checkEnter) {
console.log("Amound being paid is " + checkEnter);
let item = {
'price': Number(checkEnter)
}
let payment = await makeCustomDonation(checkEnter)
let wixPayRes = await wixPay.startPayment(payment.id)
.then((result) =>{
if(result.status==="Successful"){
wixLocation.to("https://www.payment.tanishqsundhan.com/payment-status/successful/9f045d95-8c1e-4d16-827b-003ed0be7d8b")
} else if (result.status==="Failed") {
wixLocation.to("https://www.payment.tanishqsundhan.com/payment-status/failed/7cfe9abb-8ab1-45f4-9f9d-912c21b71572")
} else if (result.status==="Pending") {
wixLocation.to("https://www.payment.tanishqsundhan.com/payment-status/pending/8a87f195-28e3-494c-b8be-02229d744e25")
} else if (result.status==="Cancelled") {
wixLocation.to("https://www.payment.tanishqsundhan.com/payment-status/cancelled/c9873a3e-9a06-4a86-a31a-dc3559cbabbf")
}
})
} else if (checkSelect) {
console.log("Amound being paid is " + checkSelect);
let item = {
'price': Number(checkSelect)
}
let payment = await makeDonation(checkSelect)
let wixPayRes = await wixPay.startPayment(payment.id)
.then((result) =>{
if(result.status==="Sucessfull"){
wixLocation.to("https://www.payment.tanishqsundhan.com/payment-status/successful/9f045d95-8c1e-4d16-827b-003ed0be7d8b")
} else if (result.status==="Failed") {
wixLocation.to("https://www.payment.tanishqsundhan.com/payment-status/failed/7cfe9abb-8ab1-45f4-9f9d-912c21b71572")
} else if (result.status==="Pending") {
wixLocation.to("https://www.payment.tanishqsundhan.com/payment-status/pending/8a87f195-28e3-494c-b8be-02229d744e25")
} else if (result.status==="Cancelled") {
wixLocation.to("https://www.payment.tanishqsundhan.com/payment-status/cancelled/c9873a3e-9a06-4a86-a31a-dc3559cbabbf")
}
})
}
});
});