I don't know if any of you have used PayPal's Instant Payment Notification... I'm having a hard time getting it to work, thought I'd post here and see if anyone could help...
I'm new to the whole IPN thing... I used PayPal's example code, but I can't make it populate my database with anything. I've included the code below... any help is appreciated.
<?php
// read the post from PayPal system and add 'cmd'
$req = 'cmd=_notify-validate';
foreach ($_POST as $key => $value) {
$value = urlencode(stripslashes($value));
$req .= "&$key=$value";
}
// post back to PayPal system to validate
$header .= "POST /cgi-bin/webscr HTTP/1.0\r\n";
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Content-Length: " . strlen($req) . "\r\n\r\n";
$fp = fsockopen ('https://www.paypal.com/cgi-bin/webscr', 0, $errno, $errstr, 30);
// 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'];
if (!$fp) {
// HTTP ERROR
} else {
fputs ($fp, $header . $req);
while (!feof($fp)) {
$res = fgets ($fp, 1024);
if (strcmp ($res, "VERIFIED") == 0) {
include('global/dbconnect.php');
if(date('m') == "12"){
$month = "01";
$year = date('Y') + 1;
}else{
$month = date('m') + 1;
$year = date('Y');
}
$day = date('d');
$expiration = $year . $month . $day;
$query = "INSERT INTO payment VALUES('', '$txn_id', '$txn_type', '$payment_type', '$payment_status', '$pending_reason', '$tax', , '$item_name', '$item_number', '$amount3', '$payer_email', '$payer_status', '$payer_id', '$payment_date', NOW(), '$subscriber_id', $expiration', '$mc_gross', '$mc_fee', '$mc_currency', '$settle_amount', '$settle_currency', '$exchange_rate')";
$result = msql_query($query);
}
else if (strcmp ($res, "INVALID") == 0) {
// log for manual investigation
}
}
fclose ($fp);
}
?>