This makes the retrieval generally available, since is it part of the data model,
rather than tied to the form. It could possibly be a token, or at least retrievable on
the recurring edit workflow template - but that is beyond the scope of this
return CRM_Core_PseudoConstant::get(__CLASS__, $fieldName, $params, $context);
}
+ /**
+ * Get the from address to use for the recurring contribution.
+ *
+ * This uses the contribution page id, if there is one, or the default domain one.
+ *
+ * @param int $id
+ * Recurring contribution ID.
+ *
+ * @internal
+ *
+ * @return string
+ * @throws \API_Exception
+ * @throws \CRM_Core_Exception
+ */
+ public static function getRecurFromAddress(int $id): string {
+ $details = Contribution::get(FALSE)
+ ->addWhere('contribution_recur_id', '=', $id)
+ ->addWhere('contribution_page_id', 'IS NOT NULL')
+ ->addSelect('contribution_page_id.receipt_from_name', 'contribution_page_id.receipt_from_email')
+ ->addOrderBy('receive_date', 'DESC')
+ ->execute()->first();
+ if (empty($details['contribution_page_id.receipt_from_email'])) {
+ $domainValues = CRM_Core_BAO_Domain::getNameAndEmail();
+ return "$domainValues[0] <$domainValues[1]>";
+ }
+ return '"' . $details['contribution_page_id.receipt_from_name'] . '" <' . $details['contribution_page_id.receipt_from_email'] . '>';
+ }
+
}
/**
* Called after the user submits the form.
+ *
+ * @throws \API_Exception
+ * @throws \CRM_Core_Exception
*/
public function postProcess() {
// store the submitted values in an array
}
// if this is an update of an existing recurring contribution, pass the ID
- $params['id'] = $this->_subscriptionDetails->recur_id;
+ $params['id'] = $this->getContributionRecurID();
$message = '';
$params['subscriptionId'] = $this->getSubscriptionDetails()->processor_id;
CRM_Activity_BAO_Activity::create($activityParams);
if (!empty($params['is_notify'])) {
- // send notification
- if ($this->_subscriptionDetails->contribution_page_id) {
- CRM_Core_DAO::commonRetrieveAll('CRM_Contribute_DAO_ContributionPage', 'id',
- $this->_subscriptionDetails->contribution_page_id, $value, [
- 'title',
- 'receipt_from_name',
- 'receipt_from_email',
- ]
- );
- $receiptFrom = '"' . CRM_Utils_Array::value('receipt_from_name', $value[$this->_subscriptionDetails->contribution_page_id]) . '" <' . $value[$this->_subscriptionDetails->contribution_page_id]['receipt_from_email'] . '>';
- }
- else {
- $domainValues = CRM_Core_BAO_Domain::getNameAndEmail();
- $receiptFrom = "$domainValues[0] <$domainValues[1]>";
- }
+ $receiptFrom = CRM_Contribute_BAO_ContributionRecur::getRecurFromAddress($this->getContributionRecurID());
[$donorDisplayName, $donorEmail] = CRM_Contact_BAO_Contact::getContactDetails($contactID);
}
}
+ /**
+ * Get the recurring contribution ID.
+ *
+ * @return int
+ */
+ protected function getContributionRecurID(): int {
+ return $this->_subscriptionDetails->recur_id;
+ }
+
}
/**
* Test the mail sent on update.
*
- * @throws \CRM_Core_Exception
+ * @throws \CRM_Core_Exception|\API_Exception
*/
public function testMail(): void {
$mut = new CiviMailUtils($this, TRUE);
public function getExpectedMailStrings(): array {
return [
'MIME-Version: 1.0',
- 'From: FIXME <info@EXAMPLE.ORG>',
+ 'From: "Bob" <bob@example.org>',
'To: Anthony Anderson <anthony_anderson@civicrm.org>',
'Subject: Recurring Contribution Update Notification - Mr. Anthony Anderson II',
- 'Return-Path: info@EXAMPLE.ORG',
+ 'Return-Path: bob@example.org',
'Dear Anthony,',
'Your recurring contribution has been updated as requested:',
'Recurring contribution is for $ 10.00, every 1 month(s) for 12 installments.',
- 'If you have questions please contact us at FIXME <info@EXAMPLE.ORG>.',
+ 'If you have questions please contact us at "Bob" <bob@example.org>.',
];
}
'contribution_recur_id' => $this->getContributionRecurID(),
'financial_type_id' => 'Donation',
'total_amount' => 10,
- 'api.Payment.create' => ['total_amount' => 10, 'payment_processor_id' => $this->paymentProcessorId],
+ 'contribution_page_id' => $this->getContributionPageID(),
+ 'api.Payment.create' => [
+ 'total_amount' => 10,
+ 'payment_processor_id' => $this->paymentProcessorId,
+ 'is_send_contribution_notification' => FALSE,
+ ],
]);
}
return $this->ids['ContributionRecur'][0];
}
+ /**
+ * Get a contribution page id.
+ *
+ * @return int
+ */
+ public function getContributionPageID(): int {
+ if (!isset($this->ids['ContributionPage'][0])) {
+ $this->ids['ContributionPage'][0] = $this->callAPISuccess('ContributionPage', 'create', [
+ 'receipt_from_name' => 'Bob',
+ 'receipt_from_email' => 'bob@example.org',
+ 'financial_type_id' => 'Donation',
+ ])['id'];
+ }
+ return $this->ids['ContributionPage'][0];
+ }
+
}