/**
 * Send a contribution confirmation (receipt or invoice).
 *
 * The appropriate online template will be used (the existence of related objects
 * (e.g. memberships ) will affect this selection
 *
 * @param array $params
 *   Input parameters.
 *
 * @throws Exception
 */
function civicrm_api3_contribution_sendconfirmation($params)
{
    $contribution = new CRM_Contribute_BAO_Contribution();
    $contribution->id = $params['id'];
    if (!$contribution->find(TRUE)) {
        throw new Exception('Contribution does not exist');
    }
    $input = $ids = $cvalues = array('receipt_from_email' => $params['receipt_from_email']);
    $contribution->loadRelatedObjects($input, $ids, TRUE);
    $contribution->composeMessageArray($input, $ids, $cvalues, FALSE, FALSE);
}
Beispiel #2
0
 /**
  * Send receipt from contribution.
  *
  * Do not call this directly - it is being refactored. use contribution.sendmessage api call.
  *
  * Note that the compose message part has been moved to contribution
  * In general LoadObjects is called first to get the objects but the composeMessageArray function now calls it.
  *
  * @param array $input
  *   Incoming data from Payment processor.
  * @param array $ids
  *   Related object IDs.
  * @param CRM_Contribute_BAO_Contribution $contribution
  * @param array $values
  *   Values related to objects that have already been loaded.
  * @param bool $recur
  *   Is it part of a recurring contribution.
  * @param bool $returnMessageText
  *   Should text be returned instead of sent. This.
  *   is because the function is also used to generate pdfs
  *
  * @return array
  */
 public static function sendMail(&$input, &$ids, $contribution, &$values, $recur = FALSE, $returnMessageText = FALSE)
 {
     $input['is_recur'] = $recur;
     // set receipt from e-mail and name in value
     if (!$returnMessageText) {
         $session = CRM_Core_Session::singleton();
         $userID = $session->get('userID');
         if (!empty($userID)) {
             list($userName, $userEmail) = CRM_Contact_BAO_Contact_Location::getEmailDetails($userID);
             $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);
 }
 /**
  * Send receipt from contribution.
  *
  * Do not call this directly - it is being refactored. use contribution.sendmessage api call.
  *
  * Note that the compose message part has been moved to contribution
  * In general LoadObjects is called first to get the objects but the composeMessageArray function now calls it.
  *
  * @param array $input
  *   Incoming data from Payment processor.
  * @param array $ids
  *   Related object IDs.
  * @param CRM_Contribute_BAO_Contribution $contribution
  * @param array $values
  *   Values related to objects that have already been loaded.
  * @param bool $recur
  *   Is it part of a recurring contribution.
  * @param bool $returnMessageText
  *   Should text be returned instead of sent. This.
  *   is because the function is also used to generate pdfs
  *
  * @return array
  */
 public static function sendMail(&$input, &$ids, $contribution, &$values, $recur = FALSE, $returnMessageText = FALSE)
 {
     $input['is_recur'] = $recur;
     $input['receipt_date'] = $contribution->receipt_date;
     // set receipt from e-mail and name in value
     if (!$returnMessageText) {
         $session = CRM_Core_Session::singleton();
         $userID = $session->get('userID');
         if (!empty($userID)) {
             list($userName, $userEmail) = CRM_Contact_BAO_Contact_Location::getEmailDetails($userID);
             $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);
         }
     }
     // Contribution ID should really always be set. But ?
     if (!$returnMessageText && (!isset($input['receipt_update']) || $input['receipt_update'])) {
         civicrm_api3('Contribution', 'create', array('receipt_date' => 'now', 'id' => $contribution->id));
     }
     return $contribution->composeMessageArray($input, $ids, $values, $recur, $returnMessageText);
 }