Paypals IPN.php Error - php

The situation:
Setting up a buy and download market on a website using paypal.
I've already set up the "buy" and "checkout" buttons using paypals button creator.
Now I need to create a IPN script to call paypal and verify purchase so the "product"
may start downloading. If there is a better direction in how to go about this, I would appreciate the suggestion.
The problem:
Paypals IPN sandbox simulator is giving me a
"We could not send an IPN due to an HTTP error: 500: Internal Server Error"
yet, I still receive an "INVALID" response.
The Question:
How do I
1) Fix Paypals IPN sandbox simulator to be able to send the message
2) and receive a "VERIFIED response.
The Scripts:
I am using the exact script from paypals github
heres the link:
paypal_ipn.php
Thanks in Advance!
p.s.
I have come across some similar situations but none have work for me.

Your IPN script must have an error in it causing it to return the 500 back to PayPal's server. Your script could be (and apparently is) handling most everything ok and saving your log file as expected, but then at the end something is causing the error so the script doesn't fully complete successfully.
The first thing I would do is solve that problem. An easy way to do this is to create your own simulator by building a basic HTML form with hidden fields that match the names of the fields you expect to get from an IPN. Set the action of the form to your IPN URL and then you can load this in a browser and submit it so that you can see the result on screen. This can help with troubleshooting and fixing any errors you have.
Once you've solved all the errors you can try the simulator again and you should get a successful result at that point. If you're still getting invalid, though, then you must have a problem with your callback to PayPal. We can figure that out once the script is completing successfully, though, and that may very well fix both problems once you figure out whatever is going on there.

If you are using an PHP framework to implement PayPal IPN listener, then don't forget to put exit; statement at the bottom of the controller. If you don't write exit statement, then the framework will try to load the view file, and in my case there is no view file. That is why I got the 500 Error message in the PayPal IPN simulator.
Here is example of code that is running fine on my machine.
public function ipnlistener2Action(){
// tell PHP to log errors to ipn_errors.log in this directory
//mail('YOUR EMAIL', 'Invalid IPN', "Exception");
ini_set('display_errors',1);
error_reporting(E_ALL);
// intantiate the IPN listener
require_once('common/ipnlistener.php');
$listener = new IpnListener();
// tell the IPN listener to use the PayPal test sandbox
$listener->use_sandbox = true;
// try to process the IPN POST
try {
$listener->requirePostMethod();
$verified = $listener->processIpn();
if ($verified) {
// TODO: Implement additional fraud checks and MySQL storage
mail('YOUR EMAIL', 'Valid IPN', $listener->getTextReport());
} else {
// manually investigate the invalid IPN
mail('amir.duran#ceit.co.uk', 'Invalid IPN', $listener->getTextReport());
}
} catch (Exception $e) {
mail('YOUR EMAIL', 'Invalid IPN', "Exception: ".$e->getMessage());
//var_dump("Exception");
exit(0);
}
exit;
// TODO: Handle IPN Response here
}

Related

Is the IPN working?, because the IPN simulator is not working and i am trying with a real transaction but i can't receive any notification

Is the IPN working?, because the IPN simulator is not working and i am trying with a real transaction but i can't receive any notification in my listener.php
I have been trying with the IPN simulator to send a notification to my listener.php but apparently it is not working, it is throwing this error "window.moment is not a function" and apparently paypal is working on it.
For the previous reason I have been trying with real transactions, but there is no response from the IPN.
I am trying to put the answer to a txt file
$raw=file_get_contents('php://input');
file_put_contents("testP.txt", $raw);
$doc = fopen(filename:"testP.txt", mode:"w");
foreach ($_POST as $key => $value) {
fwrite($doc, string:"$key => $value \r\n");
}
fclose($doc);
There is no result and I would like to know if the IPN is working or I am doing something wrong, because I only created the paypal buttons and added in the advanced variables the url of my listener.php as the paypal documentation says
It isn't working. I contacted PayPal support and got the following reply:
We have reported this problem and are already working on it.
Try again later or feel free to ask me about the status.
I will get back to this thread if it starts working again.

Paypal IPN now returns INVALID - PHP code previously working fine

I'm using the following class to process the IPN data:
https://github.com/WadeShuler/PHP-PayPal-IPN (and it has been working fine for ages)
The last successfully processed payment was on September 28, the next IPN payment that came though on October 5 returned a response of INVALID, as has every payment since.
If I test in the IPN simulator, the message processes successfully.
Sandbox or Live, the response is INVALID. I would have thought the Sandbox would have a facility where I can review why a message was rejected as INVALID, but that doesn't seem to be the case? Would certainly have been the easy way to see the rejection reason, am I missing something?
The link that brings you to Paypal from my site is:
https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_ext-enter&redirect_cmd=_xclick&business=sales-facilitator#fydentry.com&item_name=QLD++%28Pacific+pines+secondary+Sat+25th+July+%29&item_number=FYD15000003&custom=0001000003&currency_code=AUD&amount=0.01&no_shipping=1&image_url=http://www.fydentry.com/img/follow-your-dreams-100.jpg&return=http://www.fydentry.com/entry-test.php&cancel_return=http://www.fydentry.com/entry-test.php&notify_url=http://www.fydentry.com/payback-test.php
The data posted back from Paypal is:
transaction_subject=0001000003&txn_type=web_accept&payment_date=07%3A05%3A07+Oct+15%2C+2015+PDT&last_name=buyer&residence_country=AU&pending_reason=multi_currency&item_name=QLD++%28Pacific+pines+secondary+Sat+25th+July+%29&payment_gross=&mc_currency=AUD&business=sales-facilitator%40fydentry.com&payment_type=instant&protection_eligibility=Ineligible&verify_sign=Acssfl2b2v1gxOK33TD2StcDhf-OAZxwix74kxFlSgpWMku6myuy.WFL&payer_status=verified&test_ipn=1&tax=0.00&payer_email=sales-buyer%40fydentry.com&txn_id=9BV63134E20871700&quantity=1&receiver_email=sales-facilitator%40fydentry.com&first_name=test&payer_id=FY3RYW98GNMXG&receiver_id=95FC3QCK53MHC&item_number=FYD15000003&handling_amount=0.00&payment_status=Pending&shipping=0.00&mc_gross=0.01&custom=0001000003&charset=windows-1252&notify_version=3.8&ipn_track_id=cfbd422d97d69
The response I send back to Paypal is:
cmd=_notify-validate&transaction_subject=0001000003&txn_type=web_accept&payment_date=07%3A05%3A07+Oct+15%2C+2015+PDT&last_name=buyer&residence_country=AU&pending_reason=multi_currency&item_name=QLD++%28Pacific+pines+secondary+Sat+25th+July+%29&payment_gross=&mc_currency=AUD&business=sales-facilitator%40fydentry.com&payment_type=instant&protection_eligibility=Ineligible&verify_sign=Acssfl2b2v1gxOK33TD2StcDhf-OAZxwix74kxFlSgpWMku6myuy.WFL&payer_status=verified&test_ipn=1&tax=0.00&payer_email=sales-buyer%40fydentry.com&txn_id=9BV63134E20871700&quantity=1&receiver_email=sales-facilitator%40fydentry.com&first_name=test&payer_id=FY3RYW98GNMXG&receiver_id=95FC3QCK53MHC&item_number=FYD15000003&handling_amount=0.00&payment_status=Pending&shipping=0.00&mc_gross=0.01&custom=0001000003&charset=windows-1252&notify_version=3.8&ipn_track_id=cfbd422d97d69
And the code in payback-test.php is:
<?php
include_once("f_common.php");
include_once("IpnListener.php");
use wadeshuler\paypalipn\IpnListener;
$listener = new IpnListener();
$listener->use_sandbox = true;
$dbh = open_db();
$res = 'UNKNOWN';
try {
$listener->requirePostMethod();
$verified = $listener->processIpn();
} catch (Exception $e) {
error_log($e->getMessage());
exit(0);
}
if ($verified) {
$res = "VERIFIED";
} else {
$res = "INVALID";
}
$stmt_debug = $dbh->prepare('INSERT INTO fyd_paypal_ipn (post_data, response_data, status, message_time) VALUES (:post_data, :response_data, :status, UTC_TIMESTAMP())');
$stmt_debug->execute(array(':post_data' => $listener->rawPostData, ':response_data' => $listener->debug_response, ':status' => $res));
?>
Note that for the purpose of this exercise, I also modified the IpnListener class so that I can get a copy of the response for debugging purposes.
At the top of the file in the variable declarations, I made $rawPostData public, and added this variable:
public $debug_response;
And store the value right before we use it:
$this->debug_response = $req;
if ($this->use_curl) {
$res = $this->curlPost($req);
} else {
$res = $this->fsockPost($req);
}
I'm assuming something has changed on the Paypal side to stop this working in the first place, but I can't see what it is, particularly as my response appears to be correct (identical), and I can't find anything in the Sandbox side that helps me identify why it is being regarded as invalid? Unfortunately the debug code at the bottom where I track the IPN post data and response is new, so I don't have an older (working!) set of messages to compare the contents to.
hummmm, since 1 october paypal change sha-1 to sha-2
https://www.paypal-knowledge.com/infocenter/index?page=content&id=FAQ1766&expand=true&locale=en_US
I've gotten to the bottom of it, it appears to be a certificate issue, combined with a script error.
My certificate file was out of date to the one currently in Wade's code. I spotted that and updated the certificate file yesterday. I've now verified that this was the root cause of my original failure.
However, while updating that, I also updated to the latest class - which was really just removing some deprecated code that I wasn't using and is no longer supported, but I missed one small change which broke things.
There's a line in the IpnListener class which sets the certificate location:
curl_setopt($ch, CURLOPT_CAINFO, dirname(dirname(__FILE__)) . '/cert/api_cert_chain.crt');
But the directory name ends up wrong on my server, and it can't find the certificate. The previous version of the class read:
curl_setopt($ch, CURLOPT_CAINFO, dirname(__FILE__) . '/cert/api_cert_chain.crt');
which worked. Now that I've changed it back, everything works again. Note that the domain I'm working from is set up in a sub-directory to my primary domain, which is possibly why the new code ends up pointing to the wrong place (one level above where I need it to be).
And I'm still confused as to why the IPN simulator worked, while the Sandbox and Live systems didn't.

Paypal IPN receiving via simulator but not via my site

I have an odd problem, testing my IPN handler using the IPN simulator on the paypal website, it works (I've just got it emailing me the report), but when I do it through my site, I don't receive anything.
So I guess the problem must be with sending the pay request and setting the ipn url there
$payRequest = new PayRequest(new RequestEnvelope("en_US"), "PAY", $cancelURL, $currencyCode, $receiverList, $returnURL);
$payRequest->ipnNotificationUrl = $notifyURL;
$service = new AdaptivePaymentsService($config);
try {
/* wrap API method calls on the service object with a try catch */
$response = $service->Pay($payRequest);
}
I've double checked $notifyURL is the same as what i'm using in the simulator. Everything else is working, the user gets sent to the paypal website to complete the payment, it's just the IPN never gets sent afterwards.
I figured out that IPN has to be manually turned on in one of the accounts' profile.

PayPal notify_url not being called after extensive sandbox testing

I'm designing a website for a charity board game event, wherein people can watch the event live, and can donate money to a charity (Child's Play) in order to force players to play continuously for 60 hours. Because the donations are going directly to Child's Play, I need to use the notify_url setting to pass my IPN notification URL in; we've done this marathon twice before and have had no problems, but we recently ported it over to PHP.
Now, I've been testing the site extensively for the past few months using the sandbox, and everything was working perfectly. The marathon is only a couple of weeks away now, so I switched over to the actual PayPal system, fired off a test donation, and now I've got a problem: for some reason, PayPal is not hitting the notify_url at all. I've verified the URL by switching back to sandbox temporarily, and everything works fine. I've also added a few calls to error_log in the listener code to see if it's just getting caught in the code somewhere, but have found out it hasn't been hit at all.
If anyone can offer any suggestions here as to what I can do, I'd greatly appreciate it. Obviously I'm under a bit of a time crunch, so I'd really appreciate it if you could respond sooner rather than later.
EDIT: Here's the relevant code:
if (isset($_GET['paypalipn'])) {
// tell PHP to log errors to ipn_errors.log in this directory
ini_set('log_errors', true);
ini_set('error_log', dirname(__FILE__).'/ipn_errors.log');
// intantiate the IPN listener
$listener = new IpnListener();
// tell the IPN listener to use the PayPal test sandbox
$listener->use_sandbox = false;
error_log("here");
// try to process the IPN POST
try {
$listener->requirePostMethod();
$verified = $listener->processIpn();
} catch (Exception $e) {
error_log($e->getMessage());
exit(0);
}
error_log("here2");
// Process the IPN
if ($verified) {
error_log("here3");
$errmsg = ''; // stores errors from fraud checks
// Split the custom variable
$split_custom = explode("&", $_POST['custom']);
$custom_array = array();
for ($i = 0; $i<count($split_custom); $i++) {
$current_set = explode("=", $split_custom[$i]);
$custom_array[$current_set[0]] = $current_set[1];
}
error_log("here4");
if (!isset($custom_array['game'])) {
$custom_array['game'] = 0;
}
if (!isset($custom_array['player'])) {
$custom_array['player'] = 0;
}
error_log("here5");
if (!empty($errmsg)) {
// manually investigate errors from the fraud checking
$body = "IPN failed fraud checks: \n$errmsg\n\n";
$body .= $listener->getTextReport();
mail('jafawcett#gmail.com', 'IPN Fraud Warning', $body);
} else {
mail('jafawcett#gmail.com', 'Successful IPN', $listener->getTextReport());
}
error_log("donor_un: ".$custom_array['donor_un']);
process_donation($_POST['mc_gross'], $custom_array['player'], $custom_array['game'], $custom_array['donor_name'], $_POST['payer_email'], $custom_array['donor_un']);
} else {
// manually investigate the invalid IPN
mail('jafawcett#gmail.com', 'Invalid IPN', $listener->getTextReport());
}
}
For the ipn listener class I'm using the one created by Micah Carrick and available here:
https://github.com/Quixotix/PHP-PayPal-IPN
I asked my direct contact at PayPal about this and got the following response...
In regards to the IPN issue, we had an outage last night. It was fixed
at about 1-2am, the IPN’s are delayed because we had a backed up queue
of about 2.5 million IPN’s which did not send out. We are currently
working through these IPN’s. I’d expect normal functionality shortly.
You can also see plenty of people talking about this issue on Twitter.
We're having the same problem.
It worked perfectly fine for a few months now and the script remains untouched. PayPal IPN is enabled inside the PayPal account as well and our IPNs just stopped this morning.
There might be a problem over at PayPal, we're still trying to figure it out.

PHP PayPal IPN Invalid URL Error But URL Exists and File Working

I'm completely stumped as to why my PayPal IPN listeners wont work for my web payments standard buttons
I'm using Micah Carricks PayPal class,which is used widely and i've configured and appear to be working fine on my server
My problem arises when i attempt to process my IPN
The Sandbox simulator tool tells me my URL is invalid despite the fact the URL exists and when i access it directly handles and logs my errors fine
Can anyone tell me what i'm doing wrong?
Here is my listener code
<?php
ini_set('log_errors', true);
ini_set('error_log', '../car_errors.log');
// instantiate the IpnListener class
include('ipnlistener.php');
$listener = new IpnListener();
$listener->use_sandbox = true;
$account_owner = 'MY_EMAIL';
try
{
$listener->requirePostMethod();
$verified = $listener->processIpn();
}
catch (Exception $e)
{
error_log($e->getMessage());
exit(0);
}
/*
The processIpn() method returned true if the IPN was "VERIFIED" and false if it
was "INVALID".
*/
if ($verified)
{
if()//My checks on the post data to update my database
{
}
mail($account_owner, 'Verified Car IPN', $listener->getTextReport());
}
else
{
mail($account_owner, 'Invalid Car IPN', $listener->getTextReport());
}
?>
I've also tried a live transaction with use_sandbox set to false and the IPN history shows the IPN as Retrying,indicating it can't contact the URL
I'm beginning to lose all hope on getting this working. I'm concerned it may possibly be my file permissions on my server,however they are all set to 664. The reason i say this is that the listeners where working on a shared host but since upgrading to a VPS has been continually problematic
Any help would be greatly appreciated
Barry
If it was working before you changed servers then it sounds like some kind of server configuration issue. Since you can access the URL and you have the same URL in your Paypal config, then verify that your SSL is installed correctly. Maybe Paypal can't see the URL due to some cert error.

Categories