From 4206fa5c29952ed2d05a4f50fee49d69213437a5 Mon Sep 17 00:00:00 2001 From: eileen Date: Fri, 7 May 2021 11:34:33 +1200 Subject: [PATCH] [REF] Stop passing membership id into recur notify The membership id resolves to a boolean template parameter of whether a membership is attached to the relevant recurring record. The classes that call this function do a lot of work to determine this so it's better to calculate it in-function and simplify those classes --- CRM/Contribute/BAO/ContributionPage.php | 18 +++++++++++------- CRM/Contribute/BAO/ContributionRecur.php | 3 +-- CRM/Core/Payment/AuthorizeNetIPN.php | 3 +-- CRM/Core/Payment/PayPalIPN.php | 3 +-- CRM/Core/Payment/PayPalProIPN.php | 3 +-- 5 files changed, 15 insertions(+), 15 deletions(-) diff --git a/CRM/Contribute/BAO/ContributionPage.php b/CRM/Contribute/BAO/ContributionPage.php index c15e5c3d10..e33bbdd67a 100644 --- a/CRM/Contribute/BAO/ContributionPage.php +++ b/CRM/Contribute/BAO/ContributionPage.php @@ -16,6 +16,7 @@ */ use Civi\Api4\Contribution; +use Civi\Api4\LineItem; /** * This class contains Contribution Page related functions. @@ -286,14 +287,14 @@ class CRM_Contribute_BAO_ContributionPage extends CRM_Contribute_DAO_Contributio $template = CRM_Core_Smarty::singleton(); if (!array_key_exists('related_contact', $values)) { - list($displayName, $email) = CRM_Contact_BAO_Contact_Location::getEmailDetails($contactID, FALSE, CRM_Core_BAO_LocationType::getBilling()); + [$displayName, $email] = CRM_Contact_BAO_Contact_Location::getEmailDetails($contactID, FALSE, CRM_Core_BAO_LocationType::getBilling()); } // get primary location email if no email exist( for billing location). if (!$email) { - list($displayName, $email) = CRM_Contact_BAO_Contact_Location::getEmailDetails($contactID); + [$displayName, $email] = CRM_Contact_BAO_Contact_Location::getEmailDetails($contactID); } if (empty($displayName)) { - list($displayName, $email) = CRM_Contact_BAO_Contact_Location::getEmailDetails($contactID); + [$displayName, $email] = CRM_Contact_BAO_Contact_Location::getEmailDetails($contactID); } //for display profile need to get individual contact id, @@ -510,12 +511,10 @@ class CRM_Contribute_BAO_ContributionPage extends CRM_Contribute_DAO_Contributio * TxnType. * Contribution page id. * @param object $recur - * Object of recurring contribution table. - * @param bool|object $autoRenewMembership is it a auto renew membership. * * @throws \API_Exception */ - public static function recurringNotify($contributionID, $type, $recur, $autoRenewMembership = FALSE): void { + public static function recurringNotify($contributionID, $type, $recur): void { $contribution = Contribution::get(FALSE) ->addWhere('id', '=', $contributionID) ->setSelect([ @@ -532,6 +531,11 @@ class CRM_Contribute_BAO_ContributionPage extends CRM_Contribute_DAO_Contributio ]) ->execute()->first(); + $isMembership = !empty(LineItem::get(FALSE) + ->addWhere('contribution_id', '=', $contributionID) + ->addWhere('entity_table', '=', 'civicrm_membership') + ->addSelect('id')->execute()->first()); + if ($contribution['contribution_recur.is_email_receipt'] || $contribution['contribution_page.is_email_receipt']) { if ($contribution['contribution_page.receipt_from_email']) { $receiptFromName = $contribution['contribution_page.receipt_from_name']; @@ -558,7 +562,7 @@ class CRM_Contribute_BAO_ContributionPage extends CRM_Contribute_DAO_Contributio 'displayName' => $displayName, 'receipt_from_name' => $receiptFromName, 'receipt_from_email' => $receiptFromEmail, - 'auto_renew_membership' => $autoRenewMembership, + 'auto_renew_membership' => $isMembership, ], 'from' => $receiptFrom, 'toName' => $displayName, diff --git a/CRM/Contribute/BAO/ContributionRecur.php b/CRM/Contribute/BAO/ContributionRecur.php index 5762a2a049..0e90e0d765 100644 --- a/CRM/Contribute/BAO/ContributionRecur.php +++ b/CRM/Contribute/BAO/ContributionRecur.php @@ -562,8 +562,7 @@ INNER JOIN civicrm_contribution con ON ( con.id = mp.contribution_id ) CRM_Contribute_BAO_ContributionPage::recurringNotify( $ids['contribution'], $isFirstOrLastRecurringPayment, - $recur, - $autoRenewMembership + $recur ); } } diff --git a/CRM/Core/Payment/AuthorizeNetIPN.php b/CRM/Core/Payment/AuthorizeNetIPN.php index 70140f6c48..8514f9ce2e 100644 --- a/CRM/Core/Payment/AuthorizeNetIPN.php +++ b/CRM/Core/Payment/AuthorizeNetIPN.php @@ -89,8 +89,7 @@ class CRM_Core_Payment_AuthorizeNetIPN extends CRM_Core_Payment_BaseIPN { if ($isFirstOrLastRecurringPayment) { //send recurring Notification email for user CRM_Contribute_BAO_ContributionPage::recurringNotify($contributionID, TRUE, - $contributionRecur, - (bool) $this->getMembershipID($contributionID, $contributionRecur->id) + $contributionRecur ); } diff --git a/CRM/Core/Payment/PayPalIPN.php b/CRM/Core/Payment/PayPalIPN.php index fbcbe42e84..b08cd07781 100644 --- a/CRM/Core/Payment/PayPalIPN.php +++ b/CRM/Core/Payment/PayPalIPN.php @@ -346,8 +346,7 @@ class CRM_Core_Payment_PayPalIPN extends CRM_Core_Payment_BaseIPN { CRM_Contribute_BAO_ContributionPage::recurringNotify( $ids['contribution'], $this->getFirstOrLastInSeriesStatus(), - $contributionRecur, - !empty($ids['membership']) + $contributionRecur ); } return; diff --git a/CRM/Core/Payment/PayPalProIPN.php b/CRM/Core/Payment/PayPalProIPN.php index 0ce996e222..b11df6aa8e 100644 --- a/CRM/Core/Payment/PayPalProIPN.php +++ b/CRM/Core/Payment/PayPalProIPN.php @@ -261,8 +261,7 @@ class CRM_Core_Payment_PayPalProIPN extends CRM_Core_Payment_BaseIPN { CRM_Contribute_BAO_ContributionPage::recurringNotify( $ids['contribution'], $subscriptionPaymentStatus, - $recur, - !empty($ids['membership']) + $recur ); } -- 2.25.1