I am using a script I found on paypals site, but I am having some problems with it. I have tried contacting paypal about this but they were less then helpful.
I have tried several different scripts from several different sites and run into the same problem with all of them. They aren't posting back to paypals site, and all I get is a blank page. I have been at this for several days and would love any help you could offer.
Thanks,
Here is the script:
I<?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 ('www.paypal.com', 80, $errno, $errstr, 30);
// assign variables
$receiver_email = $POST['receiver_email'];
$item_name = $POST['item_name'];
$item_number = $POST['item_number'];
$quantity = $POST['quantity'];
$invoice = $POST['invoice'];
$custom = $POST['custom'];
$payment_status = $POST['payment_status'];
$pending_reason = $POST['pending_reason'];
$payment_date = $POST['payment_date'];
$exchange_rate = $POST['exchange_rate'];
$payment_gross = $POST['payment_gross'];
$payment_fee = $POST['payment_fee'];
$txn_id = $POST['txn_id'];
$txn_type = $POST['txn_type'];
$first_name = $POST['first_name'];
$last_name = $POST['last_name'];
$address_street = $POST['address_street'];
$address_city = $POST['address_city'];
$address_state = $POST['address_state'];
$address_zip = $POST['address_zip'];
$address_country = $POST['address_country'];
$address_status = $POST['address_status'];
$payer_email = $POST['payer_email'];
$payer_id = $POST['payer_id'];
$payer_status = $POST['payer_status'];
$payment_type = $POST['payment_type'];
$verify_sign = $POST['verify_sign'];
$subscr_date = $POST['subscr_date'];
$subscr_effective = $POST['subscr_effective'];
$period1 = $POST['period1'];
$period2 = $POST['period2'];
$period3 = $POST['period3'];
$amount1 = $POST['amount1'];
$amount2 = $POST['amount2'];
$amount3 = $POST['amount3'];
$recurring = $POST['recurring'];
$reattempt = $POST['reattempt'];
$retry_at = $POST['retry_at'];
$recur_times = $POST['recur_times'];
$username = $POST['username'];
$password = $POST['password'];
$subscr_id = $POST['subscr_id'];
if (!$fp) {
// HTTP ERROR
echo "http error";
} else {
fputs ($fp, $header . $req);
while (!feof($fp)) {
$res = fgets ($fp, 1024);
if (strcmp ($res, "VERIFIED") == 0) {
if (strcmp ($payment_status, "Completed") == 0) {
$qry = "SELECT password FROM paypal WHERE item_number = \"$item_number\" ";
$result = mysql_query($qry,$db);
while ($myrow = mysql_fetch_row($result)) { $passwd = $myrow[0]; }
$message .= "Dear Customer,\n Thankyou for your order.\n\nThe password for the item you ordered is: $row[0]\n\nIf you have any problems, please contact us: \n\nholla@hiphopg.com";
mail($payer_email, "Your Book Password...", $message, "From: holla@hiphopg.com\nReply-To: holla@hiphopg.com");
echo "It worked.";
// check the payment_status is Completed
// check that txn_id has not been previously processed
// check that receiver_email is your Primary PayPal email
// process payment
//Write the data to my own database
$db = mysql_connect('localhost','user','pass');
mysql_select_db('db');
$resultat_sql = mysql_query("INSERT INTO paypal(receiver_email,item_name,item_number,quantity,invoice,custom,payment_status,pending_reason,payment_date,payment_gross,payment_fee,txn_id,txn_type,first_name,last_name,address_street,address_city,address_state,address_zip,address_country,address_status,payer_email,payer_status,payment_type,verify_sign,subscr_date,period1,period2,period3,amount1,amount2,amount3,recurring,reattempt,retry_at,recur_times,username,password,subscr_id )
VALUES ('$invoice', '$receiver_email', '$item_name', '$item_number', '$quantity', '$payment_status', '$pending_reason', '$payment_date', '$payment_gross', '$payment_fee', '$txn_id', '$txn_type', '$first_name', '$last_name', '$address_street', '$address_city', '$address_state', '$address_zip', '$address_country', '$address_status', '$payer_email', '$payer_status', '$payment_type', '$custom', '$verify_sign', '$subscr_date','$period1', '$period2','$period3','$amount1','$amount2','$amount3','$recurring','$reattempt','$retry_at','$recure_times','$username','$password','$subscr_id' ) ",$db);
}
else if (strcmp ($res, "INVALID") == 0) {
echo "invalid";
// log for manual investigation
}
}
fclose ($fp);
}
?>