So i recently created PayPal IPN script, but while I was testing it with Sandbox (test) accounts, I saw problem, everything was excellent, except it just didn’t insert any data in database, well verified part just didn’t work, neather did INVALID part, didn’t work.
You can take a look on my script here –
<?php
// PHP 4.1
// 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 ('ssl://www.paypal.com', 443, $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) {
if($receiver_email == 'test_1318600337_biz@gmail.com')
{
include('../database.php');
$result = mysql_query("SELECT * FROM `smscodes` WHERE code = '$item_number';");
$select_id = mysql_fetch_array($result);
mysql_query('UPDATE `advertisements` SET status="accepted" WHERE id = "'.$select_id['adv-id'].'"');
mysql_query("DELETE FROM `smscodes` WHERE `code` = '".$item_number."' LIMIT 1");
}
}
else if (strcmp ($res, "INVALID") == 0) {
$to = 'myemailishere@myemailishere.com';
mail($to, "Error, something is wrong with paypal script", "Error, something is wrong with paypal script");
}
}
fclose ($fp);
}
?>
And my button is –
<form name="_xclick" action="https://www.sandbox.paypal.com/cgi-bin/webscr"
method="post">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="business" value="test_1318600337_biz@gmail.com">
<input type="hidden" name="currency_code" value="EUR">
<input type="hidden" name="item_name" value="Add Advertisement">
<input type="hidden" name="amount" value="3.00">
<input type="hidden" name="item_number" value="<?php echo $_SESSION['code']; ?>">
<input type="hidden" name="return" value="http://site.com">
<input type="hidden" name="notify_url" value="mysite.com/tsatstastast/ipn.php">
<input type="image" src="http://www.paypal.com/en_US/i/btn/btn_buynow_LG.gif"
border="0" name="submit" alt="Make payments with PayPal - it's fast, free and secure!">
</form>
In PayPal IPN history it shows succeed with HTTP 200, but I don’t have any clues why it doesn’t insert anything inside database. database.php file is okay, and it got all information of database inside. Hope you can help me with this problem.
EDIT: Forgot to mention, with PayPal Test tool, where you insert IPN script code, and it verifies if it is working, everything worked great. But with button, and test account it doesn’t. Oh and smscodes table, it’s correct, I’m using same table for paypal and sms payments, so no worries about it ;)!
EDIT: Tried to change to ssl://www.sandbox.paypal.com but without chance, now ill try to debug it .
EDIT 3: So I just found the error, it was In paypal sandbox account setting, didn’t turn on notificy messages. Now i got one message that says mail($to, “Error, something is wrong with paypal script”, “Error, something is wrong with paypal script”); , so it failed. What to do, any help would be appreciated!
Best regards,
Valters
Try debugging it with the values
fsockopen()provides: