Jump to content

ipn simulator not working on 000webhost...


piano0011

Recommended Posts

Hey guys!

I have been following a video by passive code income on how to implement ipn simulator but I keep getting the message invalid from 000webhost.. Here is my code:

 

<?php

 if ($_SERVER['REQUEST_METHOD'] != 'POST') {
     header("Location: index.php");
     exit();
 }

 $ch = curl_init();
 curl_setopt($ch, CURLOPT_URL, 'https://ipnpb.sandbox.paypal.com/cgi-bin/webscr');
 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
 curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
 curl_setopt($ch, CURLOPT_POST, 1);
 curl_setopt($ch, CURLOPT_POSTFIELDS, "cmd=_notify-validate&" . http_build_query($_POST));
 $response = curl_exec($ch);
 curl_close($ch);

file_put_contents("test.txt", $response);
 

Link to comment
Share on other sites

this is likely due to a + near the end of the payment date for the time zone, and when you use http_build_query() on the data, this gets treated as is (a space), rather than a literal + , which should end up being a %2B urlencoded value.

you should log the received $_POST data so that you can see what it is. if the payment date looks like - Wed+Jul+4+2018+10%3A15%3A11+GMT+0000, you will need to handle the last + differently in the code.

next, either use or examine the 'official' php paypal listener code, to see how the + near the end of the payment date gets treated - https://github.com/paypal/ipn-code-samples/tree/master/php

Link to comment
Share on other sites

Everything I remember about IPN says just to send them back the data verbatim. As in

"cmd=_notify-validate&" . file_get_contents("php://input")

I assume their code is so complicated (note that it urldecodes in one loop then urlencodes in the next) because it's trying to handle magic_quotes. Which doesn't exist anymore. Plus I can count at least four significant problems with it.

Link to comment
Share on other sites

7 hours ago, piano0011 said:

Thanks for the reply. So, do you think that the code does not work? Maybe, I should try using a sandbox account instead?

You aren't already? Your code says you should be using the sandbox. The very fact that you're testing this means you should be using the sandbox.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.