Ipn simulator not working with this script

Hey guys!

I have trying to follow a tutorial by passive income on how to do integrate a paypal ipn to my site but keep getting an invalid message with the following code…I have listener and set the file to test.txt but it doesn’t have any information from the ipn…

<?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);

Screenshots of the errors?

I got the following message from the ipn simulator: Should the tutorial work though? Has there been any update with the ipn simulator?

But I have this from the server:

@Infinity @teodor please check

The PayPal transaction validation always returns INVALID if the IPN comes from the IPN simulator, but I found a workaround. If the IPN will come from a real transaction, it works fine. Here is how I did.

Go to PayPal Developer and Login
Create a sandbox account (if you already have a sandbox account, ignore these 2 steps)
Now go to https://www.sandbox.paypal.com and login
Then visit button management and create a button
Don’t forget to set the IPN notification URL for your sandbox acccount
Now make a real transaction from the button you created in the sandbox account
It works flawlessly

?

1 Like

Thanks for the advice… I will give that a go! But in the tutorial that I am following by passive income, when he did it, it works…

I agree with @Infinity, Paypal ipn works when it come from real transaction with all the required parameters and arguments, it can’t be accessed directly(Yet I’m not sure), will check your posted tutorial for sure.
Even not only paypal ipn, but all the payment gateways need a “callback url” to be called from a real transaction which includes required parameters and arguments(as said above), then only it works.
@piao0011 Let us know how it went for you :slight_smile: