fmwebschool.com
Top Experts [learn more]Top 4-10
webko

9743 K
bandmandq

2458 K
Genx

1525 K
4. tcmeyers
5. kbata
6. Martie
7. Hammerton
8. rrenfrow
9. bneeman
10. plegler
Welcome, Guest. Please login or register.
October 30, 2014, 11:46:27 PM

Login with username, password and session length
Search:     Advanced search
FMWebschool releases more educational FMStudio webinars - check them out here:
http://www.fmwebschool.com/webinars.php
27809 Posts in 6154 Topics by 1525 Members
Latest Member: alkyred
* Home Help Search Calendar Login Register
+  fmwebschool.com
|-+  FMStudio
| |-+  FMStudio Pro
| | |-+  send email from paypal notify
0 Members and 1 Guest are viewing this topic. « previous next »
Pages: [1] Print
Author Topic: send email from paypal notify  (Read 579 times)
roktis
Jr. Member
**
Offline Offline

Posts: 29


« on: March 05, 2012, 01:23:04 PM »

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.
Logged
webko
Global Moderator
Hero Member
*****
Offline Offline

Posts: 2116
Kudos: 9743



WWW
Applications:
« Reply #1 on: March 05, 2012, 01:54:30 PM »

echo and print_r commands are your friends...

echo $Inv_numb;
print_r ($result);

These should output to the screen for testing and debugging
Logged

tim.webko_at_gmail.com
roktis
Jr. Member
**
Offline Offline

Posts: 29


« Reply #2 on: March 13, 2012, 09:32:35 PM »

Yes, but the problem with the paypal notify function is that it is triggered by Paypal and thus never appears on your browser.
Logged
Pages: [1] Print 
« previous next »
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!