CRM-16125 more sensible default for completetransaction api email from address
authorEileen McNaughton <eileen@fuzion.co.nz>
Tue, 17 Mar 2015 04:14:17 +0000 (17:14 +1300)
committerEileen McNaughton <eileen@fuzion.co.nz>
Tue, 17 Mar 2015 04:32:59 +0000 (17:32 +1300)
CRM/Core/Payment/BaseIPN.php
api/v3/Contribution.php

index 4cfe9ab88dc6e64640a2171cb7266b7a75ed5cad..c64a8bfb1da13200cb1c0aa888eb43f7b09ea3bb 100644 (file)
@@ -832,8 +832,8 @@ LIMIT 1;";
       $userID = $session->get('userID');
       if (!empty($userID)) {
         list($userName, $userEmail) = CRM_Contact_BAO_Contact_Location::getEmailDetails($userID);
-        $values['receipt_from_email'] = $userEmail;
-        $values['receipt_from_name'] = $userName;
+        $values['receipt_from_email'] = CRM_Utils_Array::value('receipt_from_email', $input, $userEmail);
+        $values['receipt_from_name'] = CRM_Utils_Array::value('receipt_from_name', $input, $userName);
       }
     }
     return $contribution->composeMessageArray($input, $ids, $values, $recur, $returnMessageText);
index 9d340142fcd46a2746d5dc40985e2b6b6c42cb76..cf6c5f0b6b5fdebe1f2335d5be1fa81c0af6de2e 100644 (file)
@@ -440,6 +440,16 @@ function _civicrm_api3_contribution_completetransaction_spec(&$params) {
     'title' => 'Send email Receipt?',
     'type' => CRM_Utils_Type::T_BOOLEAN,
   );
+  $params['receipt_from_email'] = array(
+    'title' => 'Email to send receipt from.',
+    'description' => 'If not provided this will default to being based on domain mail or contribution page',
+    'type' => CRM_Utils_Type::T_EMAIL,
+  );
+  $params['receipt_from_name'] = array(
+    'title' => 'Name to send receipt from',
+    'description' => '. If not provided this will default to domain mail or contribution page',
+    'type' => CRM_Utils_Type::T_STRING,
+  );
 }
 
 /**
@@ -513,6 +523,15 @@ function _ipn_process_transaction(&$params, $contribution, $input, $ids, $firstC
   if (isset($params['is_email_receipt'])) {
     $input['is_email_receipt'] = $params['is_email_receipt'];
   }
+  if (empty($contribution->contribution_page_id)) {
+    static $domainFromName;
+    static $domainFromEmail;
+    if (empty($domainFromEmail) && (empty($params['receipt_from_name']) || empty($params['receipt_from_email']))) {
+      list($domainFromName, $domainFromEmail) =  CRM_Core_BAO_Domain::getNameAndEmail(TRUE);
+    }
+    $input['receipt_from_name'] = CRM_Utils_Array::value('receipt_from_name', $params, $domainFromName);
+    $input['receipt_from_email'] = CRM_Utils_Array::value('receipt_from_email', $params, $domainFromEmail);
+  }
   // @todo required for base ipn but problematic as api layer handles this
   $transaction = new CRM_Core_Transaction();
   $ipn = new CRM_Core_Payment_BaseIPN();