From 4086637add93f5d37f6491d5a216136825cbaff7 Mon Sep 17 00:00:00 2001 From: eileen Date: Wed, 12 Apr 2017 14:11:18 +1200 Subject: [PATCH] CRM-19597 move function only used by Authorize.net to a.net for clarity. We could do with a better solution around this, but it needs to be around the completetransaction api --- CRM/Contribute/BAO/Contribution.php | 10 +--------- CRM/Core/Payment/AuthorizeNetIPN.php | 15 +++++++++++++-- CRM/Core/Payment/BaseIPN.php | 5 +---- api/v3/Contribution.php | 3 +-- 4 files changed, 16 insertions(+), 17 deletions(-) diff --git a/CRM/Contribute/BAO/Contribution.php b/CRM/Contribute/BAO/Contribution.php index ce1770cf0d..ff718d3c51 100644 --- a/CRM/Contribute/BAO/Contribution.php +++ b/CRM/Contribute/BAO/Contribution.php @@ -4439,14 +4439,10 @@ WHERE eft.financial_trxn_id IN ({$trxnId}, {$baseTrxnId['financialTrxnId']}) * @param CRM_Core_Transaction $transaction * @param int $recur * @param CRM_Contribute_BAO_Contribution $contribution - * @param bool $isRecurring - * Duplication of param needs review. Only used by AuthorizeNetIPN - * @param int $isFirstOrLastRecurringPayment - * Deprecated param only used by AuthorizeNetIPN. * * @return array */ - public static function completeOrder(&$input, &$ids, $objects, $transaction, $recur, $contribution, $isRecurring, $isFirstOrLastRecurringPayment) { + public static function completeOrder(&$input, &$ids, $objects, $transaction, $recur, $contribution) { $primaryContributionID = isset($contribution->id) ? $contribution->id : $objects['first_contribution']->id; // The previous details are used when calculating line items so keep it before any code that 'does something' if (!empty($contribution->id)) { @@ -4700,10 +4696,6 @@ LIMIT 1;"; } CRM_Core_Error::debug_log_message("Success: Database updated"); - if ($isRecurring) { - CRM_Contribute_BAO_ContributionRecur::sendRecurringStartOrEndNotification($ids, $recur, - $isFirstOrLastRecurringPayment); - } return $contributionResult; } diff --git a/CRM/Core/Payment/AuthorizeNetIPN.php b/CRM/Core/Payment/AuthorizeNetIPN.php index 5e0a373bdc..2b87415b19 100644 --- a/CRM/Core/Payment/AuthorizeNetIPN.php +++ b/CRM/Core/Payment/AuthorizeNetIPN.php @@ -163,12 +163,13 @@ class CRM_Core_Payment_AuthorizeNetIPN extends CRM_Core_Payment_BaseIPN { $this->checkMD5($paymentProcessorObject, $input); + $isFirstOrLastRecurringPayment = FALSE; if ($input['response_code'] == 1) { // Approved if ($first) { $recur->start_date = $now; $recur->trxn_id = $recur->processor_id; - $this->_isFirstOrLastRecurringPayment = CRM_Core_Payment::RECURRING_PAYMENT_START; + $isFirstOrLastRecurringPayment = CRM_Core_Payment::RECURRING_PAYMENT_START; } $statusName = 'In Progress'; if (($recur->installments > 0) && @@ -177,7 +178,7 @@ class CRM_Core_Payment_AuthorizeNetIPN extends CRM_Core_Payment_BaseIPN { // this is the last payment $statusName = 'Completed'; $recur->end_date = $now; - $this->_isFirstOrLastRecurringPayment = CRM_Core_Payment::RECURRING_PAYMENT_END; + $isFirstOrLastRecurringPayment = CRM_Core_Payment::RECURRING_PAYMENT_END; } $recur->modified_date = $now; $recur->contribution_status_id = array_search($statusName, $contributionStatus); @@ -209,6 +210,16 @@ class CRM_Core_Payment_AuthorizeNetIPN extends CRM_Core_Payment_BaseIPN { } $this->completeTransaction($input, $ids, $objects, $transaction, $recur); + + // Only Authorize.net does this so it is on the a.net class. If there is a need for other processors + // to do this we should make it available via the api, e.g as a parameter, changing the nuance + // from isSentReceipt to an array of which receipts to send. + // Note that there is site-by-site opinions on which notifications are good to send. + if ($isFirstOrLastRecurringPayment) { + CRM_Contribute_BAO_ContributionRecur::sendRecurringStartOrEndNotification($ids, $recur, + $isFirstOrLastRecurringPayment); + } + } /** diff --git a/CRM/Core/Payment/BaseIPN.php b/CRM/Core/Payment/BaseIPN.php index 875f2b0a3f..c4a1af336c 100644 --- a/CRM/Core/Payment/BaseIPN.php +++ b/CRM/Core/Payment/BaseIPN.php @@ -447,12 +447,9 @@ class CRM_Core_Payment_BaseIPN { * @param bool $recur */ public function completeTransaction(&$input, &$ids, &$objects, &$transaction, $recur = FALSE) { - $isRecurring = $this->_isRecurring; - $isFirstOrLastRecurringPayment = $this->_isFirstOrLastRecurringPayment; $contribution = &$objects['contribution']; - CRM_Contribute_BAO_Contribution::completeOrder($input, $ids, $objects, $transaction, $recur, $contribution, - $isRecurring, $isFirstOrLastRecurringPayment); + CRM_Contribute_BAO_Contribution::completeOrder($input, $ids, $objects, $transaction, $recur, $contribution); } /** diff --git a/api/v3/Contribution.php b/api/v3/Contribution.php index 2fa6ba7205..4148ca54c8 100644 --- a/api/v3/Contribution.php +++ b/api/v3/Contribution.php @@ -695,8 +695,7 @@ function _ipn_process_transaction(&$params, $contribution, $input, $ids, $firstC } $transaction = new CRM_Core_Transaction(); return CRM_Contribute_BAO_Contribution::completeOrder($input, $ids, $objects, $transaction, !empty - ($contribution->contribution_recur_id), $contribution, - FALSE, FALSE); + ($contribution->contribution_recur_id), $contribution); } /** -- 2.25.1