* @copyright CiviCRM LLC https://civicrm.org/licensing
*/
+use Civi\Payment\Exception\PaymentProcessorException;
/**
* This class generates form components generic to recurring contributions.
$this->assign('editableScheduleFields', array_diff($this->editableScheduleFields, $alreadyHardCodedFields));
if ($this->_subscriptionDetails->contact_id) {
- list($this->_donorDisplayName, $this->_donorEmail) = CRM_Contact_BAO_Contact::getContactDetails($this->_subscriptionDetails->contact_id);
+ [$this->_donorDisplayName, $this->_donorEmail] = CRM_Contact_BAO_Contact::getContactDetails($this->_subscriptionDetails->contact_id);
}
- CRM_Utils_System::setTitle(ts('Update Recurring Contribution'));
+ $this->setTitle(ts('Update Recurring Contribution'));
// Handle context redirection.
CRM_Contribute_BAO_ContributionRecur::setSubscriptionContext();
/**
* 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['contributionRecurID'] = $params['id'] = $this->getContributionRecurID();
$message = '';
- $params['subscriptionId'] = $this->getSubscriptionDetails()->processor_id;
+ $params['recurProcessorID'] = $params['subscriptionId'] = $this->getSubscriptionDetails()->processor_id;
+
$updateSubscription = TRUE;
if ($this->_paymentProcessorObj->supports('changeSubscriptionAmount')) {
try {
$updateSubscription = $this->_paymentProcessorObj->changeSubscriptionAmount($message, $params);
+ if ($updateSubscription instanceof CRM_Core_Error) {
+ CRM_Core_Error::deprecatedWarning('An exception should be thrown');
+ throw new PaymentProcessorException(ts('Could not update the Recurring contribution details'));
+ }
}
- catch (\Civi\Payment\Exception\PaymentProcessorException $e) {
+ catch (PaymentProcessorException $e) {
CRM_Core_Error::statusBounce($e->getMessage());
}
}
- if (is_a($updateSubscription, 'CRM_Core_Error')) {
- CRM_Core_Error::displaySessionError($updateSubscription);
- $status = ts('Could not update the Recurring contribution details');
- $msgTitle = ts('Update Error');
- $msgType = 'error';
- }
- elseif ($updateSubscription) {
+ if ($updateSubscription) {
// Handle custom data
$params['custom'] = CRM_Core_BAO_CustomField::postProcess($params, $this->contributionRecurID, 'ContributionRecur');
// save the changes
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]>";
- }
-
- list($donorDisplayName, $donorEmail) = CRM_Contact_BAO_Contact::getContactDetails($contactID);
-
- $tplParams = [
- 'recur_frequency_interval' => $this->_subscriptionDetails->frequency_interval,
- 'recur_frequency_unit' => $this->_subscriptionDetails->frequency_unit,
- 'amount' => CRM_Utils_Money::format($params['amount']),
- 'installments' => $params['installments'],
- ];
+ $receiptFrom = CRM_Contribute_BAO_ContributionRecur::getRecurFromAddress($this->getContributionRecurID());
- $tplParams['contact'] = ['display_name' => $donorDisplayName];
- $tplParams['receipt_from_email'] = $receiptFrom;
+ [$donorDisplayName, $donorEmail] = CRM_Contact_BAO_Contact::getContactDetails($contactID);
$sendTemplateParams = [
'groupName' => 'msg_tpl_workflow_contribution',
'valueName' => 'contribution_recurring_edit',
'contactId' => $contactID,
- 'tplParams' => $tplParams,
+ 'tplParams' => ['receipt_from_email' => $receiptFrom],
'isTest' => $this->_subscriptionDetails->is_test,
'PDFFilename' => 'receipt.pdf',
'from' => $receiptFrom,
'toName' => $donorDisplayName,
'toEmail' => $donorEmail,
+ 'tokenContext' => ['contribution_recurId' => $this->getContributionRecurID()],
];
- list($sent) = CRM_Core_BAO_MessageTemplate::sendTemplate($sendTemplateParams);
+ CRM_Core_BAO_MessageTemplate::sendTemplate($sendTemplateParams);
}
}
CRM_Utils_System::setUFMessage($status);
}
// keep result as 1, since we not displaying anything on the redirected page anyway
- return CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/contribute/subscriptionstatus',
+ CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/contribute/subscriptionstatus',
"reset=1&task=update&result=1"));
}
}