This is very important for me to get this done but I have managed to get the listener.php to work with a subscription button but not for a paypal donate button. I just changed the settings in the paypal developer tool but I couldn't get a handshake for the donate button..... I have set the notify_url though....
I have tried to use the same code that I got working for my subscription button but I can only get the verified message for my donation button. That's as far as I can get.... I can't get all the information to be retrieved....
<?php
ob_start();
include_once __DIR__.'/header2.php';
if (!$_SESSION['u_uid']) {
echo "<meta http-equiv='refresh' content='0;url=index.php?donation=notlogin'>";
exit();
} else {
include_once __DIR__.'/includes/dbh.php';
if ($_SERVER['REQUEST_METHOD'] != 'POST') {
header("Location: index.php");
exit();
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1_2);
curl_setopt($ch, CURLOPT_URL, 'https://ipnpb.sandbox.paypal.com/cgi-bin/webscr');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "cmd=_notify-validate&" . http_build_query($_POST));
$response = curl_exec($ch);
curl_close($ch);
if ($response == "VERIFIED" && $_POST['receiver_email'] === "admin@pianocourse101.com") {
$cEmail = strip_tags($_POST['payer_email']);
$firstname = strip_tags($_POST['first_name']);
$lastname = strip_tags($_POST['last_name']);
$price = strip_tags($_POST['mc_gross']);
$currency = strip_tags($_POST['mc_currency']);
$item = strip_tags($_POST['item_number']);
$paymentStatus = strip_tags($_POST['payment_status']);
if ($item == "Donation" && $currency == "USD" && $paymentStatus == "Completed" && $price == 100) {
$sql = "INSERT INTO donation (user_email, firstname, lastname, amount) VALUES (?,?,?,?);";
$stmt = mysqli_stmt_init($conn);
if(!mysqli_stmt_prepare($stmt, $sql)) {
echo "SQL error";
} else {
mysqli_stmt_bind_param($stmt, "sssi", $cEmail, $firstname, $lastname, $price);
mysqli_stmt_execute($stmt);
}
}
}
}
?>