From fedc226fd832ceb9d5d026364de3d35dcc4e18fb Mon Sep 17 00:00:00 2001 From: eileen Date: Sun, 11 Oct 2020 08:53:45 +1300 Subject: [PATCH] dev/financial#152 Pass contribution directly to completeOrder We have done quite a a bit of cleanup on this and the only value in objects now used is contribution - this is really explict in the code as we actually unset objects after extracting contribution. This alters the function signature such that it receives contribution directly rather than in an array --- CRM/Contribute/BAO/Contribution.php | 7 ++----- CRM/Core/Payment/AuthorizeNetIPN.php | 2 +- CRM/Core/Payment/BaseIPN.php | 2 +- CRM/Core/Payment/PayPalIPN.php | 2 +- CRM/Core/Payment/PayPalProIPN.php | 2 +- CRM/Event/Form/Task/Batch.php | 2 +- api/v3/Contribution.php | 2 +- 7 files changed, 8 insertions(+), 11 deletions(-) diff --git a/CRM/Contribute/BAO/Contribution.php b/CRM/Contribute/BAO/Contribution.php index e931c645dd..5423b6efd3 100644 --- a/CRM/Contribute/BAO/Contribution.php +++ b/CRM/Contribute/BAO/Contribution.php @@ -4363,7 +4363,7 @@ INNER JOIN civicrm_activity ON civicrm_activity_contact.activity_id = civicrm_ac * * @param array $input * @param array $ids - * @param array $objects + * @param \CRM_Contribute_BAO_Contribution $contribution * @param bool $isPostPaymentCreate * Is this being called from the payment.create api. If so the api has taken care of financial entities. * Note that our goal is that this would only ever be called from payment.create and never handle financials (only @@ -4373,11 +4373,8 @@ INNER JOIN civicrm_activity ON civicrm_activity_contact.activity_id = civicrm_ac * @throws \CRM_Core_Exception * @throws \CiviCRM_API3_Exception */ - public static function completeOrder($input, $ids, $objects, $isPostPaymentCreate = FALSE) { + public static function completeOrder($input, $ids, $contribution, $isPostPaymentCreate = FALSE) { $transaction = new CRM_Core_Transaction(); - $contribution = $objects['contribution']; - // Unset objects just to make it clear it's not used again. - unset($objects); // @todo see if we even need this - it's used further down to create an activity // but the BAO layer should create that - we just need to add a test to cover it & can // maybe remove $ids altogether. diff --git a/CRM/Core/Payment/AuthorizeNetIPN.php b/CRM/Core/Payment/AuthorizeNetIPN.php index bcf56e15af..1598041210 100644 --- a/CRM/Core/Payment/AuthorizeNetIPN.php +++ b/CRM/Core/Payment/AuthorizeNetIPN.php @@ -229,7 +229,7 @@ class CRM_Core_Payment_AuthorizeNetIPN extends CRM_Core_Payment_BaseIPN { return TRUE; } - CRM_Contribute_BAO_Contribution::completeOrder($input, $ids, ['contribution' => $objects['contribution']]); + CRM_Contribute_BAO_Contribution::completeOrder($input, $ids, $objects['contribution']); // 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 diff --git a/CRM/Core/Payment/BaseIPN.php b/CRM/Core/Payment/BaseIPN.php index e1fa68af31..bf340e7221 100644 --- a/CRM/Core/Payment/BaseIPN.php +++ b/CRM/Core/Payment/BaseIPN.php @@ -427,7 +427,7 @@ class CRM_Core_Payment_BaseIPN { 'related_contact' => $ids['related_contact'] ?? NULL, 'participant' => !empty($objects['participant']) ? $objects['participant']->id : NULL, 'contributionRecur' => !empty($objects['contributionRecur']) ? $objects['contributionRecur']->id : NULL, - ], $objects); + ], $objects['contribution']); } /** diff --git a/CRM/Core/Payment/PayPalIPN.php b/CRM/Core/Payment/PayPalIPN.php index c9e35fae42..6f600ccd1d 100644 --- a/CRM/Core/Payment/PayPalIPN.php +++ b/CRM/Core/Payment/PayPalIPN.php @@ -252,7 +252,7 @@ class CRM_Core_Payment_PayPalIPN extends CRM_Core_Payment_BaseIPN { return; } - CRM_Contribute_BAO_Contribution::completeOrder($input, $ids, $objects); + CRM_Contribute_BAO_Contribution::completeOrder($input, $ids, $objects['contribution']); } /** diff --git a/CRM/Core/Payment/PayPalProIPN.php b/CRM/Core/Payment/PayPalProIPN.php index 613186cfae..10dcbd9ac7 100644 --- a/CRM/Core/Payment/PayPalProIPN.php +++ b/CRM/Core/Payment/PayPalProIPN.php @@ -368,7 +368,7 @@ class CRM_Core_Payment_PayPalProIPN extends CRM_Core_Payment_BaseIPN { return; } - CRM_Contribute_BAO_Contribution::completeOrder($input, $ids, $objects); + CRM_Contribute_BAO_Contribution::completeOrder($input, $ids, $objects['contribution']); } /** diff --git a/CRM/Event/Form/Task/Batch.php b/CRM/Event/Form/Task/Batch.php index 395feda865..c20505cc94 100644 --- a/CRM/Event/Form/Task/Batch.php +++ b/CRM/Event/Form/Task/Batch.php @@ -362,7 +362,7 @@ class CRM_Event_Form_Task_Batch extends CRM_Event_Form_Task { 'related_contact' => NULL, 'participant' => $params['component_id'], 'contributionRecur' => NULL, - ], ['contribution' => $contribution]); + ], $contribution); // reset template values before processing next transactions $template->clearTemplateVars(); diff --git a/api/v3/Contribution.php b/api/v3/Contribution.php index 7a4da8e57a..de6bf1b062 100644 --- a/api/v3/Contribution.php +++ b/api/v3/Contribution.php @@ -679,7 +679,7 @@ function _ipn_process_transaction($params, $contribution, $input, $ids) { 'related_contact' => $ids['related_contact'] ?? NULL, 'participant' => !empty($objects['participant']) ? $objects['participant']->id : NULL, 'contributionRecur' => !empty($objects['contributionRecur']) ? $objects['contributionRecur']->id : NULL, - ], $objects, + ], $objects['contribution'], $params['is_post_payment_create'] ?? NULL); } -- 2.25.1