Forums

how to include paypal transaction id in email ?

Jefftech 23 Jul, 2009
Hi,

I'm using chronoForms with the paypal api + paypal's website payments pro. Wondering how to grab the paypal transaction id and include it in the confirmation email sent by my form.
GreyHead 23 Jul, 2009
Hi Jefftech,

I'm not to sure how the PayPal API works in practice. Where is the ID generated? Usually if you re-order the plugins so that the email is more or less the last transaction you can capture any data that has been created beforehand.

Bob
Jefftech 23 Jul, 2009
Hi Bob,

In the paypal api configuration for the form, under the useful variables tab it lists the transaction id as $MyPlugins->cf_paypal_api['transaction_id'] .

I Did set the plug-in to run before the email and the id of course shows up in debug for a successful transaction.

Just not sure how to capture the id and then take it to be include it in the email.

The email is set to disabled. Then the code i have on "On Submit code - after sending email: " is as follows.
I assume I can access the id in the "true" part of the statement but i am unsure how to add it to the email itself.

if($MyPlugins->cf_paypal_api['payment_status'] == 'SUCCESS')
  {
    echo  "Thank you for Ordering at site.com. You will be recieving a confirmation email shortly";
    $MyFormEmails =& CFEMails::getInstance($MyForm->formrow->id);
    $MyFormEmails->setEmailData(1, 'enabled', '1');
    $MyFormEmails->sendEmails($MyForm, $MyFormEmails->emails);
  }
  else
  {
      $MyForm->addErrorMsg( 'An error occured : '.$MyPlugins->cf_paypal_api['error_message'] );
    $MyForm->haltFunction["autogenerated_after_email"] = true;
  }

?>
nml375 23 Jul, 2009
Hi,
The email id is the first parameter in the setEmailData command (in your case, 1).
To add the transaction id with your current code, two ideas comes to mind:

1st one,
Add a custom field in your email template (say {transid}), and then modify your code like below to include the transaction id as if it was submitted by the user:
..
  $MyFormEmails->setEmailData(1, 'enabled', '1');
  $tmp = JRequest::get('post', JREQUEST_ALLOWRAW);
  $tmp['transid'] = $MyPlugins->cf_paypal_api['transaction_id'];
  $MyFormEmails->sendemails($MyForm, $MyFormEmails->emails, $tmp);
...


2nd one,
Add some php-code into your email template. I think you'll need to disable the template editor to accomplish this though (under setup emails). You would insert the following line wherever you wish to add the transaction id:
<? echo $MyPlugins->cf_paypal_api['transaction_id']; ?>


/Fredrik
Jefftech 23 Jul, 2009
Thanks alot! I tried both methods .

The first one worked perfectly.

The 2nd one did not work for me even with the editor disabled, it kept stripping the php tags etc.
This topic is locked and no more replies can be posted.