* @return bool
*/
function recur(&$input, &$ids, &$objects, $first) {
+ $this->_isRecurring = TRUE;
$recur = &$objects['contributionRecur'];
// do a subscription check
// check and validate gateway MD5 response if present
$this->checkMD5($ids, $input);
- $sendNotification = FALSE;
if ($input['response_code'] == 1) {
// Approved
if ($first) {
$recur->start_date = $now;
$recur->trxn_id = $recur->processor_id;
- $sendNotification = TRUE;
- $subscriptionPaymentStatus = CRM_Core_Payment::RECURRING_PAYMENT_START;
+ $this->_isFirstOrLastRecurringPayment = CRM_Core_Payment::RECURRING_PAYMENT_START;
}
$statusName = 'In Progress';
if (($recur->installments > 0) &&
// this is the last payment
$statusName = 'Completed';
$recur->end_date = $now;
- $sendNotification = TRUE;
- $subscriptionPaymentStatus = CRM_Core_Payment::RECURRING_PAYMENT_END;
+ $this->_isFirstOrLastRecurringPayment = CRM_Core_Payment::RECURRING_PAYMENT_END;
}
$recur->modified_date = $now;
$recur->contribution_status_id = array_search($statusName, $contributionStatus);
}
$this->completeTransaction($input, $ids, $objects, $transaction, $recur);
-
- if ($sendNotification) {
- $autoRenewMembership = FALSE;
- if ($recur->id &&
- isset($ids['membership']) && $ids['membership']
- ) {
- $autoRenewMembership = TRUE;
- }
-
- //send recurring Notification email for user
- CRM_Contribute_BAO_ContributionPage::recurringNotify($subscriptionPaymentStatus,
- $ids['contact'],
- $ids['contributionPage'],
- $recur,
- $autoRenewMembership
- );
- }
}
/**
*/
protected $_inputParameters = array();
+ protected $_isRecurring = FALSE;
+
+ protected $_isFirstOrLastRecurringPayment = FALSE;
/**
* Constructor
*/
}
CRM_Core_Error::debug_log_message("Success: Database updated");
+ if ($this->_isRecurring) {
+ $this->sendRecurringStartOrEndNotification($ids, $recur);
+ }
}
/**
return $contribution->composeMessageArray($input, $ids, $values, $recur, $returnMessageText);
}
+ /**
+ * Send start or end notification for recurring payments
+ * @param $ids
+ * @param $recur
+ */
+ function sendRecurringStartOrEndNotification($ids, $recur) {
+ if ($this->_isFirstOrLastRecurringPayment) {
+ $autoRenewMembership = FALSE;
+ if ($recur->id &&
+ isset($ids['membership']) && $ids['membership']
+ ) {
+ $autoRenewMembership = TRUE;
+ }
+
+ //send recurring Notification email for user
+ CRM_Contribute_BAO_ContributionPage::recurringNotify($this->_isFirstOrLastRecurringPayment,
+ $ids['contact'],
+ $ids['contributionPage'],
+ $recur,
+ $autoRenewMembership
+ );
+ }
+ }
+
/**
* Update contribution status - this is only called from one place in the code &
* it is unclear whether it is a function on the way in or on the way out