From 1ba7b504afd7b0d08ab8041ed007956f729cb43b Mon Sep 17 00:00:00 2001 From: eileen Date: Wed, 21 Oct 2020 12:46:10 +1300 Subject: [PATCH] dev/core#927 preliminary cleanup This just splits out the (I believe unreachable) 'no contribution id flow' and makes it clear the mystical addRecurLineItems is part of that flow - in preparation for moving handling to the cancelcontributionactions extension --- CRM/Core/Payment/BaseIPN.php | 35 ++++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/CRM/Core/Payment/BaseIPN.php b/CRM/Core/Payment/BaseIPN.php index 7c33202a42..c20c3b4010 100644 --- a/CRM/Core/Payment/BaseIPN.php +++ b/CRM/Core/Payment/BaseIPN.php @@ -9,6 +9,8 @@ +--------------------------------------------------------------------+ */ +use Civi\Api4\Contribution; + /** * Class CRM_Core_Payment_BaseIPN. */ @@ -237,25 +239,28 @@ class CRM_Core_Payment_BaseIPN { } } - $addLineItems = FALSE; if (empty($contribution->id)) { $addLineItems = TRUE; + // CRM-15546 + $contributionStatuses = CRM_Core_PseudoConstant::get('CRM_Contribute_DAO_Contribution', 'contribution_status_id', [ + 'labelColumn' => 'name', + 'flip' => 1, + ]); + $contribution->contribution_status_id = $contributionStatuses['Cancelled']; + $contribution->cancel_date = self::$_now; + $contribution->save(); + // Add line items for recurring payments. + if (!empty($objects['contributionRecur']) && $objects['contributionRecur']->id && $addLineItems) { + CRM_Contribute_BAO_ContributionRecur::addRecurLineItems($objects['contributionRecur']->id, $contribution); + } } - $participant = &$objects['participant']; - - // CRM-15546 - $contributionStatuses = CRM_Core_PseudoConstant::get('CRM_Contribute_DAO_Contribution', 'contribution_status_id', [ - 'labelColumn' => 'name', - 'flip' => 1, - ]); - $contribution->contribution_status_id = $contributionStatuses['Cancelled']; - $contribution->cancel_date = self::$_now; - $contribution->save(); - - // Add line items for recurring payments. - if (!empty($objects['contributionRecur']) && $objects['contributionRecur']->id && $addLineItems) { - CRM_Contribute_BAO_ContributionRecur::addRecurLineItems($objects['contributionRecur']->id, $contribution); + else { + Contribution::update(FALSE)->setValues([ + 'cancel_date' => 'now', + 'contribution_status_id:name' => 'Cancelled', + ])->addWhere('id', '=', $contribution->id)->execute(); } + $participant = &$objects['participant']; if (!empty($memberships)) { foreach ($memberships as $membership) { -- 2.25.1