[SOLVED] ERROR: "IPN was not sent, and the handshake was not verified. Review your information."

436 views
Skip to first unread message

Andrew A.

unread,
Aug 18, 2019, 5:13:39 AM8/18/19
to google-apps-sc...@googlegroups.com
I'm getting the above error in the PayPal simulator.
My setup is as follows (this is from my test script; it is not published):
  1. IPN handler URL: https://script.google.com/d/XXX/
  2. Transaction type: Express Checkout
I'm using the code is below (gleaned from various sources on the internet):
function doPost(e) {
 
var ss = SpreadsheetApp.openById("XXX");
 
var sheet = ss.getSheets()[0];
 
var data = sheet.getDataRange().getValues();
 
var uniqueId = e.parameter.txn_id;
 
var paypalURL = "https://ipnpb.sandbox.paypal.com/cgi-bin/webscr";
 
var payload = "cmd=_notify-validate&" + e.postData.contents;
  payload
= payload.replace("+", "%2B");
 
var params = {method:"post", "payload":payload};
 
var resp = UrlFetchApp.fetch(paypalURL, params);
 
if (resp == 'VERIFIED') {
 
var rowData = [];
 
for(var i = 0; i < data.length; i++) {
 
if(data[i][9] != uniqueId) {
  rowData
.push(e.parameter.payment_date);
  rowData
.push(e.parameter.payment_status);
  rowData
.push(e.parameter.mc_gross);
  rowData
.push(e.parameter.mc_currency);
  rowData
.push(e.parameter.mc_fee);
  rowData
.push(e.parameter.first_name);
  rowData
.push(e.parameter.last_name);
  rowData
.push(e.parameter.payer_email);
  rowData
.push(e.parameter.txn_type);
  rowData
.push(e.parameter.txn_id);
  rowData
.push(JSON.stringify(e));
  sheet
.appendRow(rowData);
 
}
 
}
 
}
 
return ContentService.createTextOutput("").setMimeType(ContentService.MimeType.TEXT);
};

Any ideas on what could be wrong and how to fix it? Please be as detailed as possible

Alan Wells

unread,
Aug 18, 2019, 8:33:23 AM8/18/19
to Google Apps Script Community
Your function is making a request to PayPal.  I don't think you need to do that.   If you are trying to get the payment information from PayPal after a customer made a payment, then you don't need to send a verification request back to PayPal.  The IPN will send a request to your doPost(e) function, and you can get the payment information, and then set the payment information values in the sheet, without replying back to PayPal.
In my doPost() function that get the payment information, I don't reply back to PayPal attempting to make a verification, and it works.  I know that someone else has also stated that they didn't need to make a verification to receive the IPN.

Andrew A.

unread,
Aug 18, 2019, 3:43:38 PM8/18/19
to Google Apps Script Community
Thanks for you reply.
Do you think that is the cause of the error?

Alan Wells

unread,
Aug 18, 2019, 6:04:09 PM8/18/19
to google-apps-sc...@googlegroups.com
Yes, I think that is causing the problem.

--
You received this message because you are subscribed to the Google Groups "Google Apps Script Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-c...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-script-community/b26b0853-42ed-490e-a69d-3135a6e14668%40googlegroups.com.

Andrew A.

unread,
Aug 19, 2019, 2:35:23 AM8/19/19
to Google Apps Script Community
I'm still getting the error... I even deployed as an add-on just to be sure.
Maybe the simulator is down?
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-community+unsub...@googlegroups.com.

Alan Wells

unread,
Aug 19, 2019, 9:33:34 AM8/19/19
to Google Apps Script Community
Is the script that you are using for the add-on also published as a Web App?  Did you use the url for the IPN that has "exec" on the end?
Is a payment showing up in your account?  Are you using a test PayPal account? 

Andrew A.

unread,
Aug 19, 2019, 9:54:32 AM8/19/19
to Google Apps Script Community
  • No this script is not published as a web app. It is just inside my test environment. Moreover, once I deploy it, I intend to Deploy as add-on not Deploy as web app. I hope that will not be a problem
  • The URL I used does not have an exec at the end (add-on not web app)
  • I was using the IPN simulator when that error showed up but some thing interesting happened today:
    • I setup a sandbox account for the buyer and for the seller, then I setup the IPN using my script URL. When I checked the IPN history for that sandbox account, I could see that the IPN was sent and PayPal indeed received a successful HTTP response code ("200"). However, my script so far appears to have failed to process the IPN

Alan Wells

unread,
Aug 19, 2019, 10:15:55 AM8/19/19
to Google Apps Script Community
You can publish an Apps Script file as BOTH an add-on and a Web App, as far as I know.  In order for PayPal to successfully send an IPN request to the url, the code with the doPost() function must be published as a WebApp.  You can have a separate Apps Script file from the file that is for your add-on for receiving the IPN.
When you publish a Web App, you'll be given a url that is different than the "dev" (development) version of the script.

Andrew A.

unread,
Aug 19, 2019, 10:53:21 AM8/19/19
to google-apps-sc...@googlegroups.com
I recall asking this sometime back but I was given the impression that it didn't matter (much to my confusion).
So, help me break that idea down of having another .gs file with the listener script...
Are you saying that I should publish as a web app to get that /dev or /exec URL, then deploy as a web add-on as I had earlier intended?

Alan Wells

unread,
Aug 19, 2019, 11:39:29 AM8/19/19
to Google Apps Script Community
The "gs" "file" is an internal file to the Apps Script file.  I just want to make sure what file is meant.  Each Apps Script file shows up in your Drive.  A "gs" file is internal to the Apps Script file.  I'm not talking about adding another "gs" file internally to the Apps Script file.

I'm currently using a separate Apps Script file from the add-on file to receive the IPN request.  Although, I'm starting to think about other possibilities and a different flow of events because of this discussion.  I'd need to do some experimenting to know for sure what other possibility there is and whether it would work or not.

The url that you put into the setting for the PayPal IPN needs to be the url with the "exec" on the end.  That is the published url for public use.

Whether you use a separate Apps Script file from the file that you are using for the add-on to receive the IPN request, or you use the same Apps Script file for both the add-on and the web app, either way, you need to publish the Web App to get the url to set in the PayPal settings.

Again, I'm using a totally separate Apps Script file from the add-on file for the Web App, and because I have multiple paid add-ons, it makes sense for me to have one central web app for all of them.  I've read that PayPal doesn't allow multiple IPN listeners.  If they did allow multiple different IPN listeners, then I'd probably experiment with combining the add-on and web app code into one Apps Script file.
Reply all
Reply to author
Forward
0 new messages