Answers.Body: <pre><code>&lt;?php
  
  /**
   * Implementation of hook_civicrm_tokens
   */
  
  function callhooks_civicrm_tokens( &amp;$tokens ) {
    $tokens['contribution'] = array('contribution.last_total_amount', 'contribution.last_receive_date', 'contribution.last_financial_type', 'contribution.last_trxn_id');
  }
  
  function callhooks_civicrm_tokenValues( &amp;$values, &amp;$contactIDs, $job = null, $tokens = array(), $context = null) {
  
      // KG NOTES
      // Example from Lobo: https://civicrm.org/node/480
      if ( is_array( $contactIDs ) ) {
        $contactIDString = implode( ',', array_values( $contactIDs ) );
        $single = false;
      } else {
        $contactIDString = "( $contactIDs )";
        $single = true;
      }
  
    // Contribution tokens
    $query = "
  SELECT id, contact_id, financial_type_id, total_amount, receive_date, trxn_id
  FROM   civicrm_contribution
  WHERE  contact_id IN ( $contactIDString )
  AND    is_test = 0
  ORDER BY receive_date DESC LIMIT 1
  ";
  
    $dao = CRM_Core_DAO::executeQuery( $query );
    while ( $dao-&gt;fetch( ) ) {
      if ( $single ) {
        $value =&amp; $values;
      } else {
        if ( ! array_key_exists( $dao-&gt;contact_id, $values ) ) {
          $values[$dao-&gt;contact_id] = array( );
        }
        $value =&amp; $values[$dao-&gt;contact_id];
      }
  
      $value['contribution.last_total_amount'] = $dao-&gt;total_amount;
      $value['contribution.last_receive_date'] = $dao-&gt;receive_date;
      $value['contribution.last_financial_type'] = $dao-&gt;financial_type_id;
      $value['contribution.last_trxn_id'] = $dao-&gt;trxn_id;
  
      $test = 1;
    }
  }
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-05-12T00:25:42.430Z
Answers.LastActivityDate: 2018-05-12T00:25:42.430Z
Answers.UserDisplayName: KarinG - Semper IT
Answers.Body: <p>You could use the CiviRules extension (<a href="https://civicrm.org/extensions/civirules" rel="nofollow noreferrer">https://civicrm.org/extensions/civirules</a>) and the E-mail api extension (<a href="https://civicrm.org/extensions/e-mail-api" rel="nofollow noreferrer">https://civicrm.org/extensions/e-mail-api</a>).</p>
  
  <p>You could setup a rule which is triggered when a contribution is added and add a condition the payment instrument (and probably also the financial type). You could then add an action which is send e-mail (this action is provided by the e-mail api extension).</p>
  
  <p>Documentation of CiviRules is at: <a href="https://docs.civicrm.org/civirules/en/latest" rel="nofollow noreferrer">https://docs.civicrm.org/civirules/en/latest</a></p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-05-11T11:16:13.383Z
Answers.Text: Yes -  CiviRules works - except you do need some ‘last transaction’ tokens to generate a proper receipt; I made a tiny Drupal module for the CiviCamp Calgary event sign up to do exactly this: i.e. send out to transaction receipts with CiviRules after making a payment via a webform civicrm.
Answers.UserDisplayName: KarinG - Semper IT
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-05-11T15:00:27.030Z
Answers.Text: Yes you some tokens. Probably the token extension could help out: http://github.com/eileenmcnaughton/nz.co.fuzion.civitoken/
Answers.UserDisplayName: Jaap Jansma - CiviCooP
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-05-11T16:40:37.287Z
Answers.Text: @KarinG-SemperIT I can see this tiny Drupal module somewhere?
Answers.UserDisplayName: Francesc Bassas i Bullich
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-05-11T16:40:41.850Z
Answers.Text: That extension does not give you latest contribution details; I had to add those myself
Answers.UserDisplayName: KarinG - Semper IT
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-05-11T16:42:42.020Z
Answers.Text: I will dig it up and post it
Answers.UserDisplayName: KarinG - Semper IT
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-05-12T00:26:35.483Z
Answers.Text: Ok pasted as code into an answer; looking for the last recorded contribution. Not sure if this is to standard or not - but it works :-)
Answers.UserDisplayName: KarinG - Semper IT
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-05-10T19:09:34.267Z
Answers.LastActivityDate: 2018-05-10T19:09:34.267Z
Answers.UserDisplayName: Jaap Jansma - CiviCooP
Body: <p>We have a contribution webform that allows to choose between deferred payment and online payment processor.</p>
  
  <p>We want to send a confirmation mail depending on the payment method choosed. If deferred, mail must contain instructions to complete the payment. If online, mail must contain a thank-you message if the payment is completed satisfactorily.</p>
  
  <p>What is the best approach to achieve this? If we use email webform built in feature, the emails are sent at the time of submiting the form that is  good if deferred payment method is choosed but is wrong if online method is choosed because mail is sent before payment process starts instead of when payment is complete.</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-05-10T13:39:21.800Z
Comments.Text: See if the link below can solve your problem, if that solves the problem, i will put it as an answer. I haven't tested, but seems that it might be what you are looking for https://www.drupal.org/node/273806
Comments.UserDisplayName: Kboy
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-05-10T13:53:39.433Z
Comments.Text: I do not see how. I not want conditional recipients, I want conditional messages and sent mail when payment is complete.
Comments.UserDisplayName: Francesc Bassas i Bullich
Tags: <webform-civicrm>
Title: How to send conditional mail confirmation after completing payment using webform
ThreadText: # How to send conditional mail confirmation after completing payment using webform
  
  (Asked by: username_0 on 2018-05-10)
  
  We have a contribution webform that allows to choose between deferred payment and online payment processor.
  
  We want to send a confirmation mail depending on the payment method choosed. If deferred, mail must contain instructions to complete the payment. If online, mail must contain a thank-you message if the payment is completed satisfactorily.
  
  What is the best approach to achieve this? If we use email webform built in feature, the emails are sent at the time of submiting the form that is good if deferred payment method is choosed but is wrong if online method is choosed because mail is sent before payment process starts instead of when payment is complete.
  
  **Tags:** webform-civicrm
  
  > **Comments:**
  > **username_1**: See if the link below can solve your problem, if that solves the problem, i will put it as an answer. I haven't tested, but seems that it might be what you are looking for https://www.drupal.org/node/273806  
  > **username_0**: I do not see how. I not want conditional recipients, I want conditional messages and sent mail when payment is complete.  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_2 on 2018-05-12. Score: 2
  
  ```
  <?php
  
  /**
   * Implementation of hook_civicrm_tokens
   */
  
  function callhooks_civicrm_tokens( &$tokens ) {
    $tokens['contribution'] = array('contribution.last_total_amount', 'contribution.last_receive_date', 'contribution.last_financial_type', 'contribution.last_trxn_id');
  }
  
  function callhooks_civicrm_tokenValues( &$values, &$contactIDs, $job = null, $tokens = array(), $context = null) {
  
      // KG NOTES
      // Example from Lobo: https://civicrm.org/node/480
      if ( is_array( $contactIDs ) ) {
        $contactIDString = implode( ',', array_values( $contactIDs ) );
        $single = false;
      } else {
        $contactIDString = "( $contactIDs )";
        $single = true;
      }
  
    // Contribution tokens
    $query = "
  SELECT id, contact_id, financial_type_id, total_amount, receive_date, trxn_id
  FROM   civicrm_contribution
  WHERE  contact_id IN ( $contactIDString )
  AND    is_test = 0
  ORDER BY receive_date DESC LIMIT 1
  ";
  
    $dao = CRM_Core_DAO::executeQuery( $query );
    while ( $dao->fetch( ) ) {
      if ( $single ) {
        $value =& $values;
      } else {
        if ( ! array_key_exists( $dao->contact_id, $values ) ) {
          $values[$dao->contact_id] = array( );
        }
        $value =& $values[$dao->contact_id];
      }
  
      $value['contribution.last_total_amount'] = $dao->total_amount;
      $value['contribution.last_receive_date'] = $dao->receive_date;
      $value['contribution.last_financial_type'] = $dao->financial_type_id;
      $value['contribution.last_trxn_id'] = $dao->trxn_id;
  
      $test = 1;
    }
  }
  
  ```
  
  
  ---
  
  ### Answer by username_3 on 2018-05-10. Score: 2
  
  You could use the CiviRules extension (<https://civicrm.org/extensions/civirules>) and the E-mail api extension (<https://civicrm.org/extensions/e-mail-api>).
  
  You could setup a rule which is triggered when a contribution is added and add a condition the payment instrument (and probably also the financial type). You could then add an action which is send e-mail (this action is provided by the e-mail api extension).
  
  Documentation of CiviRules is at: <https://docs.civicrm.org/civirules/en/latest>
  
  > **Comments:**
  > **username_2**: Yes -  CiviRules works - except you do need some ‘last transaction’ tokens to generate a proper receipt; I made a tiny Drupal module for the CiviCamp Calgary event sign up to do exactly this: i.e. send out to transaction receipts with CiviRules after making a payment via a webform civicrm.  
  > **username_3**: Yes you some tokens. Probably the token extension could help out: http://github.com/eileenmcnaughton/nz.co.fuzion.civitoken/  
  > **username_0**: @username_2 I can see this tiny Drupal module somewhere?  
  > **username_2**: That extension does not give you latest contribution details; I had to add those myself  
  > **username_2**: I will dig it up and post it  
  > **username_2**: Ok pasted as code into an answer; looking for the last recorded contribution. Not sure if this is to standard or not - but it works :-)  
  
  ---
  
  