protected $fromEmailId = NULL;
- protected $_fromEmails = NULL;
-
protected $_view = NULL;
public $_action = NULL;
CRM_Utils_System::setTitle($title);
return;
}
- $this->_fromEmails = CRM_Core_BAO_Email::getFromEmail();
-
$entityType = 'contribution';
if ($this->_component == 'event') {
$entityType = 'participant';
$this->_contributionId = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_ParticipantPayment', $this->_id, 'contribution_id', 'participant_id');
$eventId = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Participant', $this->_id, 'event_id', 'id');
- $this->_fromEmails = CRM_Event_BAO_Event::getFromEmailIds($eventId);
}
else {
$this->_contributionId = $this->_id;
- $this->_fromEmails['from_email_id'] = CRM_Core_BAO_Email::getFromEmail();
}
$paymentInfo = CRM_Core_BAO_FinancialTrxn::getPartialPaymentWithType($this->_id, $entityType);
//add receipt for offline contribution
$this->addElement('checkbox', 'is_email_receipt', ts('Send Receipt?'));
- $this->add('select', 'from_email_address', ts('Receipt From'), $this->_fromEmails['from_email_id']);
+ if ($this->_component === 'event') {
+ $eventID = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Participant', $this->_id, 'event_id', 'id');
+ }
+
+ $this->add('select', 'from_email_address', ts('Receipt From'), CRM_Financial_BAO_Payment::getValidFromEmailsForPayment($eventID));
$this->add('textarea', 'receipt_text', ts('Confirmation Message'));
/**
* Process Payments.
+ *
* @param array $submittedValues
*
+ * @throws \CiviCRM_API3_Exception
*/
public function submit($submittedValues) {
$this->_params = $submittedValues;
$statusMsg = ts('The payment record has been processed.');
// send email
if (!empty($paymentID) && !empty($this->_params['is_email_receipt'])) {
- $sendResult = civicrm_api3('Payment', 'sendconfirmation', ['id' => $paymentID])['values'][$paymentID];
+ $sendResult = civicrm_api3('Payment', 'sendconfirmation', ['id' => $paymentID, 'from' => $submittedValues['from_email_address']])['values'][$paymentID];
if ($sendResult['is_sent']) {
$statusMsg .= ' ' . ts('A receipt has been emailed to the contributor.');
}
];
$params = array_merge($defaults, $params);
- // Core#644 - handle contact ID passed as "From".
+ // Core#644 - handle Email ID passed as "From".
if (isset($params['from'])) {
$params['from'] = CRM_Utils_Mail::formatFromAddress($params['from']);
}
'toEmail' => $entities['contact']['email'],
'tplParams' => self::getConfirmationTemplateParameters($entities),
];
+ if (!empty($params['from']) && !empty($params['check_permissions'])) {
+ // Filter from against permitted emails.
+ $validEmails = self::getValidFromEmailsForPayment($entities['event']['id'] ?? NULL);
+ if (!isset($validEmails[$params['from']])) {
+ // Ignore unpermitted parameter.
+ unset($params['from']);
+ }
+ }
+ $sendTemplateParams['from'] = $params['from'] ?? key(CRM_Core_BAO_Email::domainEmails());
return CRM_Core_BAO_MessageTemplate::sendTemplate($sendTemplateParams);
}
+ /**
+ * Get valid from emails for payment.
+ *
+ * @param int $eventID
+ *
+ * @return array
+ */
+ public static function getValidFromEmailsForPayment($eventID = NULL) {
+ if ($eventID) {
+ $emails = CRM_Event_BAO_Event::getFromEmailIds($eventID);
+ }
+ else {
+ $emails['from_email_id'] = CRM_Core_BAO_Email::getFromEmail();
+ }
+ return $emails['from_email_id'];
+ }
+
/**
* Load entities related to the current payment id.
*
*/
function civicrm_api3_payment_sendconfirmation($params) {
$allowedParams = [
- 'receipt_from_email',
- 'receipt_from_name',
- 'cc_receipt',
- 'bcc_receipt',
- 'receipt_text',
+ 'from',
'id',
+ 'check_permissions',
];
$input = array_intersect_key($params, array_flip($allowedParams));
// use either the contribution or membership receipt, based on whether it’s a membership-related contrib or not
'title' => ts('Payment ID'),
'type' => CRM_Utils_Type::T_INT,
];
+ $params['from_email_address'] = [
+ 'title' => ts('From email; an email string or the id of a valid email'),
+ 'type' => CRM_Utils_Type::T_STRING,
+ ];
}
$this->checkResults([30, 70], 2);
$mut->assertSubjects(['Payment Receipt -']);
$mut->checkMailLog([
+ 'From: site@something.com',
'Dear Anthony,',
'Payment Details',
'Total Fees: $ 100.00',
$this->callAPISuccess('Payment', 'sendconfirmation', ['id' => $payment['id']]);
$mut->assertSubjects(['Payment Receipt - Annual CiviCRM meet']);
$mut->checkMailLog([
+ 'From: "FIXME" <info@EXAMPLE.ORG>',
'Dear Anthony,',
'Total Fees: $ 300.00',
'This Payment Amount: $ 50.00',
*/
public function testPaymentEmailReceiptFullyPaid() {
$mut = new CiviMailUtils($this);
+ CRM_Core_Config::singleton()->userPermissionClass->permissions = ['access CiviContribute', 'edit contributions', 'access CiviCRM'];
list($lineItems, $contribution) = $this->createParticipantWithContribution();
$params = [
];
$payment = $this->callAPISuccess('payment', 'create', $params);
- $this->callAPISuccess('Payment', 'sendconfirmation', ['id' => $payment['id']]);
+ // Here we set the email to an invalid email & use check_permissions, domain email should be used.
+ $email = $this->callAPISuccess('Email', 'create', ['contact_id' => 1, 'email' => 'bob@example.com']);
+ $this->callAPISuccess('Payment', 'sendconfirmation', ['id' => $payment['id'], 'from' => $email['id'], 'check_permissions' => 1]);
$mut->assertSubjects(['Payment Receipt - Annual CiviCRM meet', 'Registration Confirmation - Annual CiviCRM meet']);
$mut->checkMailLog([
+ 'From: "FIXME" <info@EXAMPLE.ORG>',
'Dear Anthony,',
'A payment has been received.',
'Total Fees: $ 300.00',