I'm trying to integrate the flutterwave payment gateway in my registration website. I'm using localhost for my hosting and testing and I'm having issues with redirecting to a success page after successful payment but it only keeps redirecting to a failure page even after a successful payment.
This is the code I used:
getpaidSetup({
PBFPubKey: PBFKey,
customer_email: email,
customer_fullname: name,
amount: amount,
customer_phone: phone,
custom_logo: "https://localhost/bnbtechonlinetrainingregistration/user/img/bnbtech.jpg",
custom_title: "Payment for Online Digital Skills Training - Course selected: " + courseselected,
custom_description: courseselected,
redirect_url: "https://localhost/bnbtechonlinetrainingregistration/user/success.php",
// custom_narration:
currency: "NGN",
txref: txRef,
onclose: function () { },
callback: function (response) {
flw_ref = response.tx.flwRef;// collect flwRef returned and pass to a server page to complete status check.
console.log("This is the response returned after a charge", response);
if (response.tx.chargeResponse !== '00' || response.tx.chargeResponse !== '0') {
// redirect to a success page
window.location = "success.php";
} else {
// redirect to a failure page.
window.location = "failed.php";
}
x.close();
}
});
So, I checked the response I logged in the console. I noticed word/variable mismatch in this line of code: if (response.tx.chargeResponse == '00' || response.tx.chargeResponse == '0')
It is response.tx.chargeResponseCode instead of response.tx.chargeResponse, contrary to what I obtained from flutterwave documentation.
Problem is now solved.