'source_contact_id' => CRM_Core_Session::getLoggedInContactID() ? CRM_Core_Session::getLoggedInContactID() :
$contactID,
));
+
+ // CRM-20336 Make sure that the contribution status is Failed, not Pending.
+ civicrm_api3('contribution', 'create', array(
+ 'id' => $contributionID,
+ 'contribution_status_id' => 'Failed',
+ ));
}
/**
$ids['contributionType'] = $this->financial_type_id;
$ids['financialType'] = $this->financial_type_id;
-
- $entities = array(
- 'contact' => 'CRM_Contact_BAO_Contact',
- 'contributionRecur' => 'CRM_Contribute_BAO_ContributionRecur',
- 'contributionType' => 'CRM_Financial_BAO_FinancialType',
- 'financialType' => 'CRM_Financial_BAO_FinancialType',
- );
- foreach ($entities as $entity => $bao) {
- if (!empty($ids[$entity])) {
- $this->_relatedObjects[$entity] = new $bao();
- $this->_relatedObjects[$entity]->id = $ids[$entity];
- if (!$this->_relatedObjects[$entity]->find(TRUE)) {
- throw new CRM_Core_Exception($entity . ' could not be loaded');
- }
- }
+ if ($this->contribution_page_id) {
+ $ids['contributionPage'] = $this->contribution_page_id;
}
+ $this->loadRelatedEntitiesByID($ids);
+
if (!empty($ids['contributionRecur']) && !$paymentProcessorID) {
$paymentProcessorID = $this->_relatedObjects['contributionRecur']->payment_processor_id;
}
* @param array $values
* Any values that may have already been compiled by calling process.
* This is augmented by values 'gathered' by gatherMessageValues
- * @param bool $recur
* @param bool $returnMessageText
* Distinguishes between whether to send message or return.
* message text. We are working towards this function ALWAYS returning message text & calling
* messages
* @throws Exception
*/
- public function composeMessageArray(&$input, &$ids, &$values, $recur = FALSE, $returnMessageText = TRUE) {
+ public function composeMessageArray(&$input, &$ids, &$values, $returnMessageText = TRUE) {
$this->loadRelatedObjects($input, $ids);
if (empty($this->_component)) {
//not really sure what params might be passed in but lets merge em into values
$values = array_merge($this->_gatherMessageValues($input, $values, $ids), $values);
+ $values['is_email_receipt'] = $this->isEmailReceipt($input, $values);
if (!empty($input['receipt_date'])) {
$values['receipt_date'] = $input['receipt_date'];
}
- $template = CRM_Core_Smarty::singleton();
- $this->_assignMessageVariablesToTemplate($values, $input, $template, $recur, $returnMessageText);
+ $template = $this->_assignMessageVariablesToTemplate($values, $input, $returnMessageText);
//what does recur 'mean here - to do with payment processor return functionality but
// what is the importance
- if ($recur && !empty($this->_relatedObjects['paymentProcessor'])) {
+ if (!empty($this->contribution_recur_id) && !empty($this->_relatedObjects['paymentProcessor'])) {
$paymentObject = Civi\Payment\System::singleton()->getByProcessor($this->_relatedObjects['paymentProcessor']);
$entityID = $entity = NULL;
if (!empty($input['amount'])) {
$values['totalAmount'] = $input['amount'];
}
-
+ // @todo set this in is_email_receipt, based on $this->_relatedObjects.
if ($values['event']['is_email_confirm']) {
$values['is_email_receipt'] = 1;
}
$values['is_pay_later'] = 1;
}
- if ($recur && $paymentObject) {
+ if (!empty($this->contribution_recur_id) && $paymentObject) {
$url = $paymentObject->subscriptionURL($membership->id, 'membership', 'cancel');
$template->assign('cancelSubscriptionUrl', $url);
$url = $paymentObject->subscriptionURL($membership->id, 'membership', 'billing');
$values['softContributions'] = $softContributions['soft_credit'];
}
if (isset($this->contribution_page_id)) {
+ // This is a call we want to use less, in favour of loading related objects.
$values = $this->addContributionPageValuesToValuesHeavyHandedly($values);
if ($this->contribution_page_id) {
+ // This is precautionary as there are some legacy flows, but it should really be
+ // loaded by now.
+ if (!isset($this->_relatedObjects['contributionPage'])) {
+ $this->loadRelatedEntitiesByID(array('contributionPage' => $this->contribution_page_id));
+ }
// CRM-8254 - override default currency if applicable
$config = CRM_Core_Config::singleton();
$config->defaultCurrency = CRM_Utils_Array::value(
// no contribution page -probably back office
else {
// Handle re-print receipt for offline contributions (call from PDF.php - no contribution_page_id)
- $values['is_email_receipt'] = 1;
$values['title'] = 'Contribution';
}
// set lineItem for contribution
*
* @param $values
* @param $input
- * @param CRM_Core_SMARTY $template
- * @param bool $recur
* @param bool $returnMessageText
*
* @return mixed
*/
- public function _assignMessageVariablesToTemplate(&$values, $input, &$template, $recur = FALSE, $returnMessageText = TRUE) {
+ public function _assignMessageVariablesToTemplate(&$values, $input, $returnMessageText = TRUE) {
+ $template = CRM_Core_Smarty::singleton();
$template->assign('first_name', $this->_relatedObjects['contact']->first_name);
$template->assign('last_name', $this->_relatedObjects['contact']->last_name);
$template->assign('displayName', $this->_relatedObjects['contact']->display_name);
)
);
$template->assign('is_monetary', 1);
- $template->assign('is_recur', (bool) $recur);
+ $template->assign('is_recur', !empty($this->contribution_recur_id));
$template->assign('currency', $this->currency);
$template->assign('address', CRM_Utils_Address::format($input));
if (!empty($values['customGroup'])) {
// CRM-8141 update the membership type with the value recorded in log when membership created/renewed
// this picks up membership type changes during renewals
+ // @todo this is almost certainly an obsolete sql call, the pre-change
+ // membership is accessible via $this->_relatedObjects
$sql = "
SELECT membership_type_id
FROM civicrm_membership_log
* @param int $contributionID
* @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
* @throws \CRM_Core_Exception
* @throws \CiviCRM_API3_Exception
*/
- public static function sendMail(&$input, &$ids, $contributionID, &$values, $recur = FALSE,
+ public static function sendMail(&$input, &$ids, $contributionID, &$values,
$returnMessageText = FALSE) {
- $input['is_recur'] = $recur;
$contribution = new CRM_Contribute_BAO_Contribution();
$contribution->id = $contributionID;
if (!$returnMessageText) {
list($values['receipt_from_name'], $values['receipt_from_email']) = self::generateFromEmailAndName($input, $contribution);
}
- $return = $contribution->composeMessageArray($input, $ids, $values, $recur, $returnMessageText);
+ $return = $contribution->composeMessageArray($input, $ids, $values, $returnMessageText);
// Contribution ID should really always be set. But ?
if (!$returnMessageText && (!isset($input['receipt_update']) || $input['receipt_update']) && empty($contribution->receipt_date)) {
civicrm_api3('Contribution', 'create', array('receipt_date' => 'now', 'id' => $contribution->id));
// These are the values that I believe to be useful.
'id',
'title',
- 'is_email_receipt',
'pay_later_receipt',
'pay_later_text',
'receipt_from_email',
}
}
+ /**
+ * Load entities related to the contribution into $this->_relatedObjects.
+ *
+ * @param array $ids
+ *
+ * @throws \CRM_Core_Exception
+ */
+ protected function loadRelatedEntitiesByID($ids) {
+ $entities = array(
+ 'contact' => 'CRM_Contact_BAO_Contact',
+ 'contributionRecur' => 'CRM_Contribute_BAO_ContributionRecur',
+ 'contributionType' => 'CRM_Financial_BAO_FinancialType',
+ 'financialType' => 'CRM_Financial_BAO_FinancialType',
+ 'contributionPage' => 'CRM_Contribute_BAO_ContributionPage',
+ );
+ foreach ($entities as $entity => $bao) {
+ if (!empty($ids[$entity])) {
+ $this->_relatedObjects[$entity] = new $bao();
+ $this->_relatedObjects[$entity]->id = $ids[$entity];
+ if (!$this->_relatedObjects[$entity]->find(TRUE)) {
+ throw new CRM_Core_Exception($entity . ' could not be loaded');
+ }
+ }
+ }
+ }
+
+ /**
+ * Should an email receipt be sent for this contribution when complete.
+ *
+ * @param array $input
+ *
+ * @return mixed
+ */
+ protected function isEmailReceipt($input) {
+ if (isset($input['is_email_receipt'])) {
+ return $input['is_email_receipt'];
+ }
+ if (!empty($this->_relatedObjects['contribution_page_id'])) {
+ return $this->_relatedObjects['contribution_page_id']->is_email_receipt;
+ }
+ return TRUE;
+ }
+
}