Jump to content

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
https://forums.phpfreaks.com/topic/307438-ipn-simulator-not-working-on-000webhost/
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

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.

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.