I've been successful getting the paypal ipn data to my google sheets using a variation of a script i found online.
function doPost(e) {
var rowData = [];
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getActiveSheet()
rowData.push(new Date(e.parameter.payment_date));
rowData.push(e.parameter.payment_type);
rowData.push(e.parameter.payment_status);
rowData.push(e.parameter.payer_email);
rowData.push(e.parameter.item_name1);
rowData.push(e.parameter.item_number1);
rowData.push(e.parameter.quantity);
rowData.push(e.parameter.first_name);
rowData.push(e.parameter.last_name);
rowData.push(e.parameter.address_street);
rowData.push(e.parameter.address_city);
rowData.push(e.parameter.address_state);
rowData.push(e.parameter.address_zip);
sheet.appendRow(rowData);
}
The above seems to work great and what the next step and I'm trying to do is take the data from a few of the cells in my google sheet where this script is working and use that in another script where an email with a link or attachment to the digital download images they purchased. I need to extract the first name, last name, payer email, and a variation of the itemname1 from above function and send the email automatically. I've set up the google sheet with the IPN information above and have added a last column 'P' where the link to the image will be located online using data from itemname1 as mentioned. The next step would be to use something like the function below using my data, but I'm having a super difficult time. I need to tweak the below function to work with my data. Is that possible? I'm not having any luck and it's all so close at this point. Anyone out there now how to do this? Can you point me in the right direction?
Something like this is what I was thinking would work for me, but I'm not sure how to tweak it to do the job I need:
// This constant is written in column C for rows for which an email // has been sent successfully.
var EMAIL_SENT = 'EMAIL_SENT';
/**
* Sends non-duplicate emails with data from the current spreadsheet.
*/
function sendEmails2() {
var sheet = SpreadsheetApp.getActiveSheet();
var startRow = 2; // First row of data to process
var numRows = 2; // Number of rows to process
// Fetch the range of cells A2:B3
var dataRange = sheet.getRange(startRow, 1, numRows, 3);
// Fetch values for each row in the Range.
var data = dataRange.getValues();
for (var i = 0; i < data.length; ++i) {
var row = data[i];
var emailAddress = row[0]; // First column
var message = row[1]; // Second column
var emailSent = row[2]; // Third column
if (emailSent !== EMAIL_SENT) { // Prevents sending duplicates
var subject = 'Sending emails from a Spreadsheet';
MailApp.sendEmail(emailAddress, subject, message);
sheet.getRange(startRow + i, 3).setValue(EMAIL_SENT);
// Make sure the cell is updated right away in case the script is interrupted
SpreadsheetApp.flush();
}
}
}
My problem is that I haven't been able to put all the data together and make it work yet. Any help?