$values['amount'] = $recurContrib->amount;
$values['financial_type_id'] = $objects['contributionType']->id;
$values['title'] = $source = ts('Offline Recurring Contribution');
- $domainValues = CRM_Core_BAO_Domain::getNameAndEmail();
- $values['receipt_from_name'] = $domainValues[0];
- $values['receipt_from_email'] = $domainValues[1];
}
if ($recurContrib && $recurContrib->id && !isset($input['is_email_receipt'])) {
if (!array_key_exists('is_email_receipt', $values) ||
$values['is_email_receipt'] == 1
) {
- self::sendMail($input, $ids, $objects['contribution'], $values, $recur, FALSE);
+ civicrm_api3('Contribution', 'sendconfirmation', array(
+ 'id' => $contribution->id,
+ 'payment_processor_id' => $paymentProcessorId,
+ ));
CRM_Core_Error::debug_log_message("Receipt sent");
}
* Incoming data from Payment processor.
* @param array $ids
* Related object IDs.
- * @param CRM_Contribute_BAO_Contribution $contribution
+ * @param int $contributionID
* @param array $values
* Values related to objects that have already been loaded.
* @param bool $recur
* is because the function is also used to generate pdfs
*
* @return array
+ * @throws \CRM_Core_Exception
+ * @throws \CiviCRM_API3_Exception
*/
- public static function sendMail(&$input, &$ids, $contribution, &$values, $recur = FALSE, $returnMessageText = FALSE) {
+ public static function sendMail(&$input, &$ids, $contributionID, &$values, $recur = FALSE,
+ $returnMessageText = FALSE) {
$input['is_recur'] = $recur;
- $input['receipt_date'] = $contribution->receipt_date;
+
+ $contribution = new CRM_Contribute_BAO_Contribution();
+ $contribution->id = $contributionID;
+ if (!$contribution->find(TRUE)) {
+ throw new CRM_Core_Exception('Contribution does not exist');
+ }
+ $contribution->loadRelatedObjects($input, $ids, TRUE);
// set receipt from e-mail and name in value
if (!$returnMessageText) {
$session = CRM_Core_Session::singleton();
// 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));
+ $values['receipt_date'] = date('Y-m-d H:i:s');
}
return $contribution->composeMessageArray($input, $ids, $values, $recur, $returnMessageText);
}
'useForMember' => $values['useForMember'],
'membership_assign' => $values['membership_assign'],
'amount' => $values['amount'],
+ 'receipt_date' => !$values['receipt_date'] ?: date('YmdHis', strtotime($values['receipt_date'])),
);
if ($contributionTypeId = CRM_Utils_Array::value('financial_type_id', $values)) {
);
}
+ if (empty($values['receipt_from_name']) && empty($values['receipt_from_name'])) {
+ list($values['receipt_from_name'], $values['receipt_from_email']) = CRM_Core_BAO_Domain::getNameAndEmail();
+ }
+
if ($values['is_email_receipt']) {
$sendTemplateParams['from'] = CRM_Utils_Array::value('receipt_from_name', $values) . ' <' . $values['receipt_from_email'] . '>';
$sendTemplateParams['toName'] = $displayName;
* @param array $result
* @param int $contributionID
*
- * @throws \CRM_Core_Exception
+ * @throws \CiviCRM_API3_Exception
+ * @throws \Exception
*/
protected function completeTransaction($result, $contributionID) {
if (CRM_Utils_Array::value('payment_status_id', $result) == 1) {
$objects['contribution']->receive_date = CRM_Utils_Date::isoToMysql($objects['contribution']->receive_date);
$values = array();
- $mail = CRM_Contribute_BAO_Contribution::sendMail($input, $ids, $objects['contribution'], $values, FALSE,
+ $mail = CRM_Contribute_BAO_Contribution::sendMail($input, $ids, $objects['contribution']->id, $values, FALSE,
$elements['createPdf']);
if ($mail['html']) {
* @return array
*/
public function sendMail(&$input, &$ids, &$objects, &$values, $recur = FALSE, $returnMessageText = FALSE) {
- return CRM_Contribute_BAO_Contribution::sendMail($input, $ids, $objects['contribution'], $values, $recur,
+ return CRM_Contribute_BAO_Contribution::sendMail($input, $ids, $objects['contribution']->id, $values, $recur,
$returnMessageText);
}
* @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 = $values = array();
+ $passThroughParams = array(
+ 'receipt_from_email',
+ 'receipt_from_name',
+ 'receipt_update',
+ 'cc_receipt',
+ 'bcc_receipt',
+ 'receipt_text',
+ 'payment_processor_id',
+ );
+ foreach ($passThroughParams as $key) {
+ if (isset($params[$key])) {
+ $input[$key] = $params[$key];
+ }
}
- $input = $ids = $cvalues = array('receipt_from_email' => $params['receipt_from_email']);
- $contribution->loadRelatedObjects($input, $ids, TRUE);
- $contribution->composeMessageArray($input, $ids, $cvalues, FALSE, FALSE);
+ CRM_Contribute_BAO_Contribution::sendMail($input, $ids, $params['id'], $values);
}
/**
function _civicrm_api3_contribution_sendconfirmation_spec(&$params) {
$params['id'] = array(
'api.required' => 1,
- 'title' => 'Contribution ID',
+ 'title' => ts('Contribution ID'),
'type' => CRM_Utils_Type::T_INT,
);
$params['receipt_from_email'] = array(
- 'api.required' => 1,
- 'title' => 'From Email address (string) required until someone provides a patch :-)',
+ 'title' => ts('From Email address (string)'),
'type' => CRM_Utils_Type::T_STRING,
);
$params['receipt_from_name'] = array(
- 'title' => 'From Name (string)',
+ 'title' => ts('From Name (string)'),
'type' => CRM_Utils_Type::T_STRING,
);
$params['cc_receipt'] = array(
- 'title' => 'CC Email address (string)',
+ 'title' => ts('CC Email address (string)'),
'type' => CRM_Utils_Type::T_STRING,
);
$params['bcc_receipt'] = array(
- 'title' => 'BCC Email address (string)',
+ 'title' => ts('BCC Email address (string)'),
'type' => CRM_Utils_Type::T_STRING,
);
$params['receipt_text'] = array(
- 'title' => 'Message (string)',
+ 'title' => ts('Message (string)'),
'type' => CRM_Utils_Type::T_STRING,
);
+ $params['receipt_update'] = array(
+ 'title' => ts('Update the Receipt Date'),
+ 'type' => CRM_Utils_Type::T_BOOLEAN,
+ 'api.default' => TRUE,
+ );
+ $params['payment_processor_id'] = array(
+ 'title' => ts('Payment processor Id (avoids mis-guesses)'),
+ 'type' => CRM_Utils_Type::T_INT,
+ );
}
/**
*/
protected $_eventID;
+ /**
+ * @var CiviMailUtils
+ */
+ protected $mut;
+
/**
* Setup function.
*/
*/
public function testCompleteTransaction() {
$mut = new CiviMailUtils($this, TRUE);
+ $this->swapMessageTemplateForTestTemplate();
$this->createLoggedInUser();
$params = array_merge($this->_params, array('contribution_status_id' => 2));
$contribution = $this->callAPISuccess('contribution', 'create', $params);
$this->assertEquals('Completed', $contribution['contribution_status']);
$this->assertEquals(date('Y-m-d'), date('Y-m-d', strtotime($contribution['receipt_date'])));
$mut->checkMailLog(array(
- 'Receipt - Contribution',
- 'Please print this confirmation for your records.',
- 'May 11th, 2012',
+ 'email:::anthony_anderson@civicrm.org',
+ 'is_monetary:::1',
+ 'amount:::100.00',
+ 'currency:::USD',
+ 'receive_date:::' . date('Ymd', strtotime($contribution['receive_date'])),
+ 'receipt_date:::' . date('Ymd'),
+ 'contributeMode:::notify',
+ 'title:::Contribution',
+ 'displayName:::Mr. Anthony Anderson II',
));
$mut->stop();
+ $this->revertTemplateToReservedTemplate();
}
/**
*/
public function testCompleteTransactionWithTestTemplate() {
$this->swapMessageTemplateForTestTemplate();
- $mut = new CiviMailUtils($this, TRUE);
- $this->createLoggedInUser();
- $params = array_merge($this->_params, array('contribution_status_id' => 2, 'receipt_date' => 'now'));
- $contribution = $this->callAPISuccess('contribution', 'create', $params);
+ $contribution = $this->setUpForCompleteTransaction();
$this->callAPISuccess('contribution', 'completetransaction', array(
'id' => $contribution['id'],
'trxn_date' => date('2011-04-09'),
'trxn_id' => 'kazam',
));
$receive_date = $this->callAPISuccess('Contribution', 'getvalue', array('id' => $contribution['id'], 'return' => 'receive_date'));
- $mut->checkMailLog(array(
+ $this->mut->checkMailLog(array(
'email:::anthony_anderson@civicrm.org',
'is_monetary:::1',
'amount:::100.00',
'title:::Contribution',
'displayName:::Mr. Anthony Anderson II',
'trxn_id:::kazam',
- 'contactID:::' . $params['contact_id'],
+ 'contactID:::' . $this->_params['contact_id'],
'contributionID:::' . $contribution['id'],
'financialTypeId:::1',
'financialTypeName:::Donation',
));
- $mut->stop();
+ $this->mut->stop();
$this->revertTemplateToReservedTemplate();
}
+ /**
+ * Complete the transaction using the template with all the possible.
+ */
+ public function testCompleteTransactionContributionPageFromAddress() {
+ $contributionPage = $this->callAPISuccess('ContributionPage', 'create', array(
+ 'receipt_from_name' => 'Mickey Mouse',
+ 'receipt_from_email' => 'mickey@mouse.com',
+ 'title' => "Test Contribution Page",
+ 'financial_type_id' => 1,
+ 'currency' => 'NZD',
+ 'goal_amount' => 50,
+ 'is_pay_later' => 1,
+ 'is_monetary' => TRUE,
+ 'is_email_receipt' => TRUE,
+ ));
+ $this->_params['contribution_page_id'] = $contributionPage['id'];
+ $contribution = $this->setUpForCompleteTransaction();
+ $this->callAPISuccess('contribution', 'completetransaction', array('id' => $contribution['id']));
+ $this->mut->checkMailLog(array(
+ 'mickey@mouse.com',
+ 'Mickey Mouse <',
+ ));
+ $this->mut->stop();
+ }
+
/**
* Test completing first transaction in a recurring series.
*
return $originalContribution;
}
+ /**
+ * Common set up routine.
+ *
+ * @return array
+ */
+ protected function setUpForCompleteTransaction() {
+ $this->mut = new CiviMailUtils($this, TRUE);
+ $this->createLoggedInUser();
+ $params = array_merge($this->_params, array('contribution_status_id' => 2, 'receipt_date' => 'now'));
+ $contribution = $this->callAPISuccess('contribution', 'create', $params);
+ return $contribution;
+ }
+
}