So I've been trying to complete a redirect in my javascript code but i need to pass the uniqid that's generated with the next page but it's not working i need to know how to pass the parameters to the script.php
document.addEventListener("DOMContentLoaded", (event) => {
// Add an event listener for when the user clicks the submit button to pay
document.getElementById("submit").addEventListener("click", (e) => {
// POST ALL PARAMETERS TO A PHP SCRIPT IN ANOTHER FILE. THAT SCRIPT WILL RECEIVE THE PARAMETERS AND INSERT INTO THE DB.
// GENERATE YOUR REF WITH JAVASCRIPT.
var generated_ref = functionToGenerateRef();
$.post('script.php', {
name: name,
email: email,
generated_ref: generated_ref,
}, function (res) {
})
e.preventDefault();
const PBFKey = ""; // paste in the public key from your dashboard here
const txRef = ''+Math.floor((Math.random() * 1000000000) + 1); //Generate a random id for the transaction reference
const email = document.getElementById('email').value;
const phone = document.getElementById('phone').value;
const amount = document.getElementById('amount').value;
console.log('loaded')
// getpaidSetup is Rave's inline script function. it holds the payment data to pass to Rave.
getpaidSetup({
PBFPubKey: PBFKey,
customer_email: email,
amount: amount,
customer_phone: phone,
currency: "NGN", // Select the currency. leaving it empty defaults to NGN
txref: txRef, // Pass your UNIQUE TRANSACTION REFERENCE HERE.
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);
console.log(response.tx.chargeResponseCode);
console.log(response.data.status);
if(response.tx.chargeResponseCode == '00' || response.tx.chargeResponse == '0') {
location.href="http://localhost/ntdc/validator/?ref=" + generated_ref;
} else {
// redirect to a failure page.
}
}
});
});
});