2

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.

  • 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 drupal.org/node/273806 – Kboy May 10 '18 at 13:39
  • I do not see how. I not want conditional recipients, I want conditional messages and sent mail when payment is complete. – Francesc Bassas i Bullich May 10 '18 at 13:53
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

  • 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. – KarinG - Semper IT May 11 '18 at 11:16
  • Yes you some tokens. Probably the token extension could help out: github.com/eileenmcnaughton/nz.co.fuzion.civitoken – Jaap Jansma - CiviCooP May 11 '18 at 15:00
  • @KarinG-SemperIT I can see this tiny Drupal module somewhere? – Francesc Bassas i Bullich May 11 '18 at 16:40
  • That extension does not give you latest contribution details; I had to add those myself – KarinG - Semper IT May 11 '18 at 16:40
  • 1
    I will dig it up and post it – KarinG - Semper IT May 11 '18 at 16:42
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;
  }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.