Implementing an IPN Listener

You can write your IPN listener in the scripting or programming language of your choice and host it on your web server.

If you are using the PayPal SDKs, you can utilize the IPN code samples.

Listener specifications

  • Your listener should listen for HTTP POST IPN messages from PayPal, which are sent instantaneously with each event.
  • After receiving the IPN message from PayPal, your listener should return an empty HTTP 200 response to PayPal. PayPal will resend the IPN if you do not send an empty HTTP 200 response. Send response messages back to PayPal to https://www.sandbox.paypal.com/cgi-bin/webscr (for Sandbox IPNs) or https://www.paypal.com/cgi-bin/webscr (for live IPNs).
  • Your listener should then HTTP POST the complete, unaltered message back to PayPal; the message must contain the same fields (in the same order) as the original message and be character encoded in the same way as the original message. However, be sure to precede the existing variables with a cmd=_notify-validate variable.
  • Subsequently, your listener should expect a single word sent back from PayPal - either VERIFIED (if the message matches the original) or INVALID (if the message does not match the original).

For an example of an IPN message, you can use a sample IPN message as a starting point.

A list of IPN variables can be found in the IPN Variables reference; however, some of these variables may not be returned to you, depending on the type of transactions and events processed.

For information on how to test and troubleshoot your listener, see IPN Testing.

As a good programming practice, as well as to keep things simple, your IPN listener should listen for a post from PayPal and dispatch it immediately to another routine or process that handles the business logic associated with the message. If your listener is structured in this way, it will be a simple and tight loop that listens for a message and dispatches it for processing by your application logic.

When you have completed your listener, push it to your site and specify the listener URL or notification URL in your account settings. See IPN Setup for more information.