< Day Day Up > |
Effectively diagnose processing problems and overcome some of IPN's stumbling blocks . The IPN system is one of the most powerful features of the PayPal system. Deploying it requires a certain level of programming skill, but even with perfect programming, there can be issues that arise in deploying any new system for the first time. In the case of implementing IPN, there are several things you can do to help diagnose any issues that arise. The first step in testing your IPN system is to make a live purchase on the system so that the script gets called by PayPal [Hack #65] . 7.6.1 Adding Email to IPNA good way to help diagnose problems is to have your IPN processing page send you all the variables and their values as they were posted to the PayPal site. You can do this by inserting a server mail component function that emails you the complete form post from PayPal when your IPN page is called. You can add the code to send an email and also to include a switch to turn this function on and off with the following code, written in VBScript for Active Server Pages: Dim vTesting vTesting = 1 'Uncomment for test mode on 'vTesting = 0 'Uncomment for test mode off If vTesting = 1 Then 'Send test email Dim TestCDO Set TestCDO = Server.CreateObject("CDONTS.NewMail") TestCDO.From = "youremail@yourisp.com" TestCDO.To = "youremail@yourisp.com" TestCDO.Subject = "IPN Variables" TestCDO.Body = Request.Form( ) TestCDO.Send( ) Set TestCDO = Nothing End If With this code added to the basic IPN processing code [Hack #65] , the IPN page sends you an email with all the transaction data as posted by PayPal. This can help you determine whether the problems are with the data being passed back. 7.6.2 Using a Return URLThe next way to test your IPN script is to check to see if your IPN page is throwing any errors. You can do this easily by redirecting to your IPN page after payment (using the return variable) and having the IPN information sent when you hit the page. This provides the same functionality that normally occurs behind the scenes, except you are able to see it firsthand. You need to add the following code to your test purchase button to accomplish this: <input type="hidden" name="rm" value="2"> <input type="hidden" name="return" value="http://yoursite.com/ipn.asp"> When this code is added to your purchase button, PayPal redirects you back to your IPN script after payment and a form post is sent that allows you to see if the page has an error on it.
7.6.3 Capturing ErrorsOne way to find out if your IPN script is causing an error is to insert error-capturing code within your IPN page. When a page error occurs, you can get an email letting you know that an error has occurred and what the error was. This example uses ASP written in VBScript. First, you have to add the following piece of code to the top of your IPN page: <% On Error Resume Next %> That line makes sure that the page continues to process if an error is detected . Then, at the bottom of your IPN page, insert the following: <% ErrorCheck( ) Function ErrorCheck( ) If Err.Number <> 0 then 'if there is an error then the html table will be written out Dim ErrorCDO Set ErrorCDO = Server.CreateObject("CDONTS.NewMail") ErrorCDO.From = "youremail@yourisp.com" ErrorCDO.To = "youremail@yourisp.com" ErrorCDO.Subject = "IPN Error" ErrorCDO.Body = "Error: " & Err.Number & " " & VbCrLf & "Description: " & Err.Description & "" ErrorCDO.Send( ) Set ErrorCDO = Nothing End If End Function %> Once you add this code to your IPN script, you'll be notified via email when an error has occurred.
7.6.4 Using a Third-Party Testing ScriptAnother easy way to test your IPN page is to use a third-party testing script that simulates a PayPal purchase to your IPN script without having to make an actual purchase. The best third-party testing script is located at http://www.eliteweaver.co.uk/testing/ipntest.php. Test your script by simply entering your IPN page's web address. You also have to change the following line in your IPN page (the postback line) so your script does not try to send the posted data back to PayPal as it causes an Invalid response from their system: objHttp.open "POST", "https://www.paypal.com/cgi-bin/webscr", false Change it like so: objHttp.open "POST", "http://www.eliteweaver.co.uk/cgi-bin/webscr", false Then, you can fill in the script form with any information you like and submit it to simulate the post to your IPN script. You can find a list of all available testing scripts at http://www.paypal.com/cgi-bin/webscr?cmd=p/pdn/3p-solutions-ipntools-outside. |
< Day Day Up > |