I know this kind of questions have been asked all over but I seem to have different case, and the solutions seen so far don't apply to my case. I'm doing finishing touches to integrating a payment gateway in my web app. But here on the payment verification script, if payment fails or user closes the flutterwave checkout modal, the redirection to the failure page fails and these errors are displayed:
Notice: Undefined index: status in /storage/ssd1/043/21042043/public_html/status.php on line 33
Notice: Undefined index: chargecode in /storage/ssd1/043/21042043/public_html/status.php on line 34
Notice: Undefined index: amount in /storage/ssd1/043/21042043/public_html/status.php on line 35
Notice: Undefined index: currency in /storage/ssd1/043/21042043/public_html/status.php on line 36
Warning: Cannot modify header information - headers already sent by (output started at /storage/ssd1/043/21042043/public_html/status.php:33) in /storage/ssd1/043/21042043/public_html/status.php on line 63
I've been trying different solutions as seen here on stack overflow but I'm not getting anywhere. I know there must be a simple work around but my head can't seem to figure it out at the moment. Please, any help would be appreciated.
Below is the script with the errors:
include "registerdbctrl.php";
if (isset($_GET['txref'])) {
$ref = $_GET['txref'];
$amount = $_GET['amount']; //Get the correct amount of your product
$email = $_GET['email'];
$currency = "NGN";
$registerid = $_GET['registerid']; //Correct Currency from Server
$query = array(
"SECKEY" => "FLWSECK_TEST-0498dfe49bdbd603460424be3a7b94e6-X",
"txref" => $ref
);
$data_string = json_encode($query);
$ch = curl_init('https://api.ravepay.co/flwv3-pug/getpaidx/api/v2/verify');
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
$response = curl_exec($ch);
$header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
$header = substr($response, 0, $header_size);
$body = substr($response, $header_size);
curl_close($ch);
$resp = json_decode($response, true);
$paymentStatus = $resp['data']['status']; //line 33
$chargeResponseCode = $resp['data']['chargecode'];
$chargeAmount = $resp['data']['amount'];
$chargeCurrency = $resp['data']['currency'];
if (($chargeResponseCode == "00" || $chargeResponseCode == "0") && ($chargeAmount == $amount) && ($chargeCurrency == $currency)) {
// transaction was successful...
// please check other things like whether you already gave value for this ref
// if the email matches the customer who owns the product etc
//Give Value and return to Success page
// var_dump($resp);
// Update payment status in database
$payStatus = "payment successful";
// $currency = "NGN";
$sql = "UPDATE registertbl SET paymentStatus = ? WHERE registerid = ?";
$stmt = $con->prepare($sql);
$stmt->bind_param("ss", $pstatus, $pregisterid);
$pstatus = $payStatus;
$pregisterid = $registerid;
$stmt->execute();
if(!$con->error){
$msgerr = "register_success";
}else{
$msgerr = $con->error;
}
header('location:https://bnbtechdigitalskillstraining.000webhostapp.com/success.php');
exit;
} else {
//Dont Give Value and return to Failure page
// var_dump($resp);
header('location:https://bnbtechdigitalskillstraining.000webhostapp.com/error.php');//line 63
exit;
}
// }
}
else {
die('No reference supplied');
}
?>```