[ACCEPTED]-Paypal sandbox IPN return INVALID-paypal-sandbox

Accepted answer
Score: 21

An “INVALID” message is due to the following reasons:

  • Check that your are posting your response to the correct URL, which is https://www.sandbox.paypal.com/cgi-bin/webscr or https://www.paypal.com/cgi-bin/webscr, depending on whether you are testing in the Sandbox or you are live, respectively.
  • Verify that your response to the test IPN message contains exactly the same variables and values as the test message and that they are in the same order as in the test message. Finally, verify that the original variables are preceded by a cmd=_notify-validate variable.
  • Ensure 12 that you are encoding your response string and are 11 using the same character encoding as used 10 by the test IPN message. (for example, I 9 can see that he is using letters with umlaut 8 and other symbols like “/”, etc). With regard 7 to the last point, the merchant can try 6 to change the encoding language in use in 5 his PayPal account, following the steps 4 below:

    1. Login on you PayPal account
    2. Click on Profile
    3. Click on “My Selling Preferences” tab
    4. Click on “PayPal Button Language Encoding” (at the end of the page)
    5. Click on "Other Options"
    6. Select from the drop down menu: UTF-8
    7. Choose the same charset also for the second option, which is related to IPN
    8. Click “Save”

If the issue persists, we recommend 3 to review the script in use, PayPal has 2 some IPN code samples available at: https://github.com/paypal/ipn-code-samples

For 1 additional information I include the link: https://developer.paypal.com/webapps/developer/docs/classic/ipn/integration-guide/IPNTesting/#id091GFE00WY4

Score: 9

I'm pretty sure the URL to send to is just 5 "www.sandbox.paypal.com", see 4 chapter 4 of Sandbox User Guide, and well, this 3 is what I put for my own code (incidentally, for 2 live, it is also just "www.paypal.com", for 1 their sample code)

Score: 3

Thank you guys for your reply. ohhh I solved 7 it at last.

Actually in notify URL I also 6 added a username parameter. Paypal want 5 the parameter values for IPN same as it 4 return to the servlet.(You can get it as 3 req.getParameterNames()). As I have username 2 parameter extra, which is not known to paypal. Paypal 1 was returning INVALID.

Score: 2

Remember paypal's sandbox has completely 3 different credentials. You must have development 2 account and be logged into development panel 1 to use sandbox.

Score: 2

If you're testing Paypal IPN over SSL, you 1 will have to use ssl://www.sandbox.paypal.com on the port 443

Score: 0

I ran into multiple problems layered on 42 top of each other before I could get Paypal 41 IPN working - it kept returning INVALID 40 but was not specific about which part I 39 was getting wrong, unfortunately.

Things 38 I got wrong:

Sandbox - if you use the Sandbox 37 you need to use the entire Sandbox environment. It 36 requires creating a new, separate account 35 on the Paypal Sandbox website. The Sandbox 34 API credentials it sets up under your regular 33 account are not enough. You then use that 32 separate Paypal account to file fake transactions 31 on the Paypal Sandbox website, and watch 30 them come across IPN on the Sandbox endpoint. The 29 need for this second account is not obvious 28 or clear at all in setting up API access. Also, switching 27 between Sandbox and Live requires more than 26 switching the URL, you need to switch the 25 credentials. So a simple compile flag alternating 24 a string isn't going to cut it.

Live - if 23 you use the Live environment a number of 22 things will get in your way. For us, it 21 took a long time for Paypal to open up "Business" access 20 to us. It wouldn't provide us anything over 19 the API until that was enabled. When we 18 initially applied we were flatly denied 17 with no explanation or timeline to resolve 16 it. A month later ish of taking payments 15 (with no API to keep us up to date with 14 those payments) it seemed to just magically 13 start working.

Code example - the code example 12 provided by Paypal is outdated, and has 11 some clear issues. Here's an example that 10 uses modern TPL/async:

// Send the verification back to Paypal in the format Paypal requested
var verif = (HttpWebRequest)WebRequest.Create(ipnVerifyUrl);
verif.Method = "POST";
verif.ContentType = "application/x-www-form-urlencoded";
var param = req.BinaryRead(req.TotalBytes);
var sRequest = Encoding.ASCII.GetString(param);
sRequest = "cmd=_notify-validate&" + sRequest;
verif.ContentLength = sRequest.Length;

using (var streamOut = new StreamWriter(verif.GetRequestStream(), Encoding.ASCII))
{
    await streamOut.WriteAsync(sRequest);
}

// Send it
using (var re = await verif.GetResponseAsync())
{
    var s = await HttpWebRequestAsync.GetFullResponseStringAsync((HttpWebResponse)re);
    // Log the response (s)
}

Besides this code 9 actually working (This is exactly what we 8 have in Production, with some of our logging 7 library calls stripped out), this code won't 6 freeze a thread while waiting on network. The 5 awaits allow the thread to step away while 4 the network does its thing, both in writing 3 the verification request to Paypal, and 2 in receiving the response back, both of 1 which could be a long time.

More Related questions