To manage IPN there is 4 steps :
- Receive by post request info of payment by Paypal
- Return HTTP 200 response
- Return complete unaltered message to paypal
- Receive Verified or Invalid from Paypal after 3
To do that there is an example here. I made some customization of Romain script for my own need but philosophy is the same and I know with Romain we have the same issue with IPN (I'm in contact with him).
The issue is : We can't validate the IPN Process. The HTTP response code is at status 405.
What I have found is in the romain script we do step 3 before step 2. So I made a change and now the script return an empty answer :
return ContentService.createTextOutput('');
Before sending back the complete unaltered paypal message, I setup a trigger who send message to paypal after 30s :
var params = {
method: "post"
}
var req = messge from paypal;
var resp = UrlFetchApp.fetch("https://www.paypal.com/cgi-bin/webscr?"+req,params);
This code is not the same as Romain but I well received the "VERIFIED" answer from Paypal.
So now I think issue is the HTTP 200 response send back to paypal, step 2. What I made is, check the data in content, header and response code by sending my own post request to the apps script. Here the result :
[15-03-25 22:50:29:753 CET] code : 200
[15-03-25 22:50:29:754 CET] content :
[15-03-25 22:50:29:756 CET] hearder : ({'X-XSS-Protection':"1; mode=block", Expires:"Fri, 01 Jan 1990 00:00:00 GMT", 'Alternate-Protocol':"443:quic,p=0.5", 'Set-Cookie':"NID=67=hlLDTKuNN7fjl66UwT9e2_BV0xw_dd67lZ9R337Zm2K8RYNAMzF0FjnEt0uhE0cxCzymgsH-1ehuGOgZ7pHynjWRkM1Y6n0PxXp8RAdyPKgfr-Y4cUrBqoDZdUib9zWo;Domain=.googleusercontent.com;Path=/;Expires=Thu, 24-Sep-2015 21:50:29 GMT;HttpOnly", Server:"GSE", 'Cache-Control':"no-cache, no-store, max-age=0, must-revalidate", Pragma:"no-cache", 'X-Content-Type-Options':"nosniff", 'X-Frame-Options':"SAMEORIGIN", 'Transfer-Encoding':"chunked", Date:"Wed, 25 Mar 2015 21:50:29 GMT", 'Access-Control-Allow-Origin':"*", P3P:"CP=\"This is not a P3P policy! See http://www.google.com/support/accounts/bin/answer.py?hl=en&answer=151657 for more info.\"", 'Content-Type':"text/plain; charset=utf-8"})
I have found this message on stackoverflow about http response status 405 and a test to do : (IPN delivery failed. HTTP error code 405: Method Not Allowed).
The header send back with appscript after a dopost() request does not seems to be well formated. I'm not sure about that but now I don't have other idea.
If someone have an idea ?
I thought may be send a custom answer with specific header at the end of the doPost()
with apps script but don't know how to do that ?