ipn --- pdo error handling

93 Views Asked by At

I am using ipn sandbox for checking some processes:

$business = $_POST['business'];
$receiver_email = $_POST['receiver_email'];
$receiver_id = $_POST['receiver_id'];
$txn_id = $_POST['txn_id'];
$txn_type = $_POST['txn_type'];
$verify_sign = $_POST['verify_sign'];

$stmt = $dbh->prepare("INSERT INTO transactions (business, receiver_email, receiver_id, txn_id, 
                                     txn_type, verify_sign) 
                                     VALUES (?, ? , ? , ? , ? , ?)");
$stmt->bindParam(1, $value1);
$stmt->bindParam(2, $value2);
$stmt->bindParam(3, $value3);
$stmt->bindParam(4, $value4);
$stmt->bindParam(5, $value5);
$stmt->bindParam(6, $value6);

$value1 = $business;
$value2 = $receiver_email;
$value3 = $receiver_id;
$value4 = $txn_id;
$value5 = $txn_type;
$value6 = $verify_sign;
$stmt->execute(); 

So this is part of my ipn-script, but it doesnt get processed, there is nothing in my table. I cant echo or print the error, cause its ipn..but: I could write error in this logfile:

$logfile = fopen("logfile.txt", "a"); 
$error = date("d.m.Y H:i:s")." - ".$errormsg.".\r\n"; 
fwrite($logfile, $error); 
fclose($logfile); 

But what to write there, anybody could help me? greetings

1

There are 1 best solutions below

0
On

Check the IPN history in the sandbox seller account to see what it shows. This will confirm that IPN's are (or aren't) actually getting sent. If they are getting sent then you'll probably see some sort of error code instead of 200 OK.

What I like to do when developing for IPN is build my own HTML form with a bunch of hidden fields that match what I expect to get from an actual PayPal IPN. Set the action of the form to your IPN listener, and then you can load this in a browser, submit it, and see the result on screen. This can help a lot with testing and troubleshooting. Once you get it all working that way you can go back to testing actual sandbox transactions and you should get the same result.

Keep in mind that when testing that way the data isn't actually coming from PayPal, so it won't verify. You'll need to make sure your code logic is setup to handle this accordingly.

If you're saving your own log file the best info you can get from that is exactly what fields you get in the raw IPN data. The very first thing you do in your script is dump all the $_POST values into the log file so you can see the parameters.

As for seeing errors and things, your web server is already doing that. Just look at your actual Apache (or IIS) log files and you'll be able to see what's happening any time your IPN script is hit. It will show you the error code and message there that you would normally see on screen.