I'm fairly new to PHP and I'm trying to integrate it into my website. I have followed one tutorial and it uses a secured pdo statemetns, and this is my first time facing them. So I integrated paypal and the transcations goes well, I'm using sandbox for testing purposes. Now as I understand this code works with the IPN, so whenever transcation is made the informaton is being send to the page that checks if the payment is success and then store the informations in datebase.
I have activated IPN from my business sandbox account and now when I try to make a payment it all goes well, but the informations isn't being stored in my datebase. I have checked error log file and saw this:
[28-Dec-2019 04:05:36 UTC] PHP Fatal error: Uncaught Error: Call to undefined method mysqli_stmt::get_result() in /home/fm4rkhoed1b3/public_html/cutesalons.com/public/locals/include/paypal/promote/DBController.php:32
Stack trace:
#0 /home/fm4rkhoed1b3/public_html/cutesalons.com/public/locals/include/paypal/promote/notify.php(109): DBController->runQuery('SELECT * FROM p...', 's', Array)
#1 {main}
thrown in /home/fm4rkhoed1b3/public_html/cutesalons.com/public/locals/include/paypal/promote/DBController.php on line 32
Now I have read a little and saw that this can be due that I don't have a mysqli driver installed, can you please confirm?
DBController.php
<?php
class DBController
{
private $host = "localhost";
private $user = "locals";
private $password = "aleksa95";
private $database = "locals";
private $conn;
function __construct()
{
$this->conn = $this->connectDB();
}
function connectDB()
{
$conn = mysqli_connect($this->host, $this->user, $this->password, $this->database);
return $conn;
}
function runQuery($query, $param_type, $param_value_array)
{
$sql = $this->conn->prepare($query);
$this->bindQueryParams($sql, $param_type, $param_value_array);
$sql->execute();
$result = $sql->get_result();
if ($result->num_rows > 0) {
while ($row = $result->fetch_assoc()) {
$resultset[] = $row;
}
}
if (! empty($resultset)) {
return $resultset;
}
}
function bindQueryParams($sql, $param_type, $param_value_array)
{
$param_value_reference[] = & $param_type;
for ($i = 0; $i < count($param_value_array); $i ++) {
$param_value_reference[] = & $param_value_array[$i];
}
call_user_func_array(array(
$sql,
'bind_param'
), $param_value_reference);
}
function insert($query, $param_type, $param_value_array)
{
$sql = $this->conn->prepare($query);
$this->bindQueryParams($sql, $param_type, $param_value_array);
$sql->execute();
}
}
?>
And this is the code i'm using to insert the info in datebase:
// Split response headers and payload, a better way for strcmp
$tokens = explode("\r\n\r\n", trim($res));
$res = trim(end($tokens));
if (strcmp ($res, "VERIFIED") == 0) {
// assign posted variables to local variables
$item_name = $_POST['item_name'];
$item_number = $_POST['item_number'];
$payment_status = $_POST['payment_status'];
$payment_amount = $_POST['mc_gross'];
$payment_currency = $_POST['mc_currency'];
$txn_id = $_POST['txn_id'];
$receiver_email = $_POST['receiver_email'];
$payer_email = $_POST['payer_email'];
include('DBController.php');
$db = new DBController();
// check whether the payment_status is Completed
$isPaymentCompleted = false;
if($payment_status == "Completed") {
$isPaymentCompleted = true;
}
// check that txn_id has not been previously processed
$isUniqueTxnId = false;
$param_type="s";
$param_value_array = array($txn_id);
$result = $db->runQuery("SELECT * FROM payment WHERE txn_id = ?",$param_type,$param_value_array);
if(empty($result)) {
$isUniqueTxnId = true;
}
// check that receiver_email is your PayPal email
// check that payment_amount/payment_currency are correct
if($isPaymentCompleted) {
$param_type = "sssdss";
$param_value_array = array($item_number, $item_name, $payment_status, $payment_amount, $payment_currency, $txn_id);
$payment_id = $db->insert("INSERT INTO payment(item_number, item_name, payment_status, payment_amount, payment_currency, txn_id) VALUES(?, ?, ?, ?, ?, ?)", $param_type, $param_value_array);
error_log(date('[Y-m-d H:i e] '). "Vdddddddddddderified IPN: $req ". PHP_EOL, 3, LOG_FILE);
}
// process payment and mark item as paid.
if(DEBUG == true) {
error_log(date('[Y-m-d H:i e] '). "Verified IPN: $req ". PHP_EOL, 3, LOG_FILE);
}
} else if (strcmp ($res, "INVALID") == 0) {
// log for manual investigation
// Add business logic here which deals with invalid IPN messages
if(DEBUG == true) {
error_log(date('[Y-m-d H:i e] '). "Invalid IPN: $req" . PHP_EOL, 3, LOG_FILE);
}
}
Can anyone please help me debug this cause I think this is caussing also my IPN to fail at sending messages. I will be much appriciated.