I am trying to get my system to send an email to a customer when paypal notifies me that the order is completed. I want to send the email to the email they input instead of their paypal email. In an earlier post,
http://fmwebschool.com/frm/index.php?topic=2514.0 Micheal said that you have to modify the paypal notify function.
"PayPal_Module/paypal.php contains a function FMStudio_PayPal_Notify. That function ends with "die("GOOD");" which just stops the code there - replace that line with "return $vars;" and the return value of that function is an array of the transaction."
Later he said that the code would be:
The return was there to separate FMStudio_PayPal_Notify from anything else, your code currently has:
FMStudio_PayPal_Notify(...some options...);
With the return line it can become:
$data = FMStudio_PayPal_Notify(....same options....);
$payer_email = $data['payer_email'];
However, no mention was made by what he meant by FMStudio_Paypal_Notify (...some options...).
Basically, I need to pull the invoice number out of the paypal notify string. With the invoice number, I can easily do a find to get the record and then get the email from that and send the email.
The following is the Paypal_Notify portion of the code.
function FMStudio_PayPal_Notify($Connection,$Layout,$business,$Invoice,$Status,$Fields,$Values,$script,$sandbox,$rootPath) {
$vars = array();
foreach($_POST as $var=>$value) {
if(get_magic_quotes_gpc()) {
$vars[$var] =stripslashes($_POST[$var]);
}else{
$vars[$var] = $_POST[$var];
}
}
if(!count($vars)) die('No post request was submitted');
file_put_contents('post.txt',serialize($vars));
// Security checks come first
if($vars['receiver_email'] != $business) {
die('SECURITY ERROR: RECEIVER EMAILS DO NOT MATCH');
}
$vars['cmd'] = '_notify-validate';
if($sandbox) {
$vars['notify-validate'] = FMStudio_PayPal_sendPOST("
https://www.sandbox.paypal.com/cgi-bin/webscr", $vars);
}else{
$vars['notify-validate'] = FMStudio_PayPal_sendPOST("
https://www.paypal.com/cgi-bin/webscr", $vars);
}
if($vars['notify-validate'] != 'VERIFIED') {
die('VALIDATION FAILED');
}
if(is_a($Connection,'FileMaker')) {
$find = $Connection->newFindCommand($Layout);
$find->addFindCriterion($Invoice, '=='.fmsEscape($vars['invoice']));
$result = $find->execute();
if(FileMaker::isError($result)) die('Failed to Find the Invoice');
$record = $result->getFirstRecord();
$edit = $Connection->newEditCommand($Layout,$record->getRecordId());
$edit->setField($Status, $vars['payment_status']);
$edit->setField($Fields, implode("\r",array_keys($vars)));
$edit->setField($Values, implode("\r",array_values($vars)));
if($script != '') $edit->setScript($script);
$result = $edit->execute();
if(FileMaker::isError($result)) {
die('FileMaker Error on Commit');
}
}else{
$find = clone($Connection);
$find->AddDBParam($Invoice, '=='.fmsEscape($vars['invoice']));
$result = $find->FMFind();
if($result['errorCode'] != 0) die('Failed to Find the Invoice');
$recid = array_shift(explode('.',key($result['data'])));
$edit = clone($Connection);
$edit->AddDBParam('-recid', $recid);
$edit->AddDBParam($Status, $vars['payment_status']);
$edit->AddDBParam($Fields, implode("\r",array_keys($vars)));
$edit->AddDBParam($Values, implode("\r",array_values($vars)));
if($script != '') $edit->PerformFMScript($script);
$result = $edit->FMEdit();
if($result['errorCode'] != 0) {
die('FileMaker Error on Commit');
}
}
die(good);
}
What do I need to change to get a value :Inv_numb to use in this find:
$found_records_find = $maincon->newFindCommand('ray_order');
$found_records_findCriterions = array('Inv_numb'=>'=='.fmsEscape($Inv_numb),);
Thanks in advance. I assume it is something like change the
die(good); to
$Inv_numb=$vars['$Invoice'];
However, since there is no real way to test this since it never shows up on the browser, I could use some help.