From 937cf542c40befaa5b442bef4464cad8081c9f75 Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Sun, 26 Oct 2014 10:18:50 +1300 Subject: [PATCH] CRM-15226 move generic code out of specific class --- CRM/Core/Payment/AuthorizeNetIPN.php | 25 +++-------------------- CRM/Core/Payment/BaseIPN.php | 30 ++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 22 deletions(-) diff --git a/CRM/Core/Payment/AuthorizeNetIPN.php b/CRM/Core/Payment/AuthorizeNetIPN.php index 5597e6e04c..0679b33eff 100644 --- a/CRM/Core/Payment/AuthorizeNetIPN.php +++ b/CRM/Core/Payment/AuthorizeNetIPN.php @@ -98,6 +98,7 @@ class CRM_Core_Payment_AuthorizeNetIPN extends CRM_Core_Payment_BaseIPN { * @return bool */ function recur(&$input, &$ids, &$objects, $first) { + $this->_isRecurring = TRUE; $recur = &$objects['contributionRecur']; // do a subscription check @@ -154,14 +155,12 @@ class CRM_Core_Payment_AuthorizeNetIPN extends CRM_Core_Payment_BaseIPN { // 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) && @@ -170,8 +169,7 @@ class CRM_Core_Payment_AuthorizeNetIPN extends CRM_Core_Payment_BaseIPN { // 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); @@ -202,23 +200,6 @@ class CRM_Core_Payment_AuthorizeNetIPN extends CRM_Core_Payment_BaseIPN { } $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 - ); - } } /** diff --git a/CRM/Core/Payment/BaseIPN.php b/CRM/Core/Payment/BaseIPN.php index 6d8a807dde..40b77a3780 100644 --- a/CRM/Core/Payment/BaseIPN.php +++ b/CRM/Core/Payment/BaseIPN.php @@ -43,6 +43,9 @@ class CRM_Core_Payment_BaseIPN { */ protected $_inputParameters = array(); + protected $_isRecurring = FALSE; + + protected $_isFirstOrLastRecurringPayment = FALSE; /** * Constructor */ @@ -647,6 +650,9 @@ LIMIT 1;"; } CRM_Core_Error::debug_log_message("Success: Database updated"); + if ($this->_isRecurring) { + $this->sendRecurringStartOrEndNotification($ids, $recur); + } } /** @@ -705,6 +711,30 @@ LIMIT 1;"; 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 -- 2.25.1