From a64d61277545d035e7f41e99df9d9bd23c8dd0d9 Mon Sep 17 00:00:00 2001 From: eileen Date: Tue, 10 Nov 2020 16:06:04 +1300 Subject: [PATCH] Standardise more params in completeOrder This moves the loading of the following params from the first contribution from Authorize.net to completeOrder - amount_level - address_id In addition campaign_id is moved, however, this is only in it is not an input param or derived from the recur record --- CRM/Contribute/BAO/Contribution.php | 20 ++++++++++++------- CRM/Core/Payment/AuthorizeNetIPN.php | 11 ++-------- .../CRM/Core/Payment/AuthorizeNetIPNTest.php | 11 ++++++---- tests/phpunit/CiviTest/CiviUnitTestCase.php | 3 +++ 4 files changed, 25 insertions(+), 20 deletions(-) diff --git a/CRM/Contribute/BAO/Contribution.php b/CRM/Contribute/BAO/Contribution.php index 2f5c8769d8..fbbe9f1bff 100644 --- a/CRM/Contribute/BAO/Contribution.php +++ b/CRM/Contribute/BAO/Contribution.php @@ -2626,10 +2626,6 @@ LEFT JOIN civicrm_contribution contribution ON ( componentPayment.contribution_ $recurringContribution = civicrm_api3('ContributionRecur', 'getsingle', [ 'id' => $contributionParams['contribution_recur_id'], ]); - if (!empty($recurringContribution['campaign_id'])) { - // CRM-17718 the campaign id on the contribution recur record should get precedence. - $contributionParams['campaign_id'] = $recurringContribution['campaign_id']; - } if (!empty($recurringContribution['financial_type_id'])) { // CRM-17718 the campaign id on the contribution recur record should get precedence. $contributionParams['financial_type_id'] = $recurringContribution['financial_type_id']; @@ -2652,10 +2648,20 @@ LEFT JOIN civicrm_contribution contribution ON ( componentPayment.contribution_ else { $contributionParams['financial_type_id'] = $templateContribution['financial_type_id']; } - foreach (['contact_id', 'currency', 'source'] as $fieldName) { - $contributionParams[$fieldName] = $templateContribution[$fieldName]; + foreach (['contact_id', 'currency', 'source', 'amount_level', 'address_id'] as $fieldName) { + if (isset($templateContribution[$fieldName])) { + $contributionParams[$fieldName] = $templateContribution[$fieldName]; + } + } + if (!empty($recurringContribution['campaign_id'])) { + // CRM-17718 the campaign id on the contribution recur record should get precedence. + $contributionParams['campaign_id'] = $recurringContribution['campaign_id']; + } + if (!isset($contributionParams['campaign_id']) && isset($templateContribution['campaign_id'])) { + // Fall back on value from the previous contribution if not passed in as input + // or loadable from the recurring contribution. + $contributionParams['campaign_id'] = $templateContribution['campaign_id']; } - $contributionParams['source'] = $contributionParams['source'] ?: ts('Recurring contribution'); //CRM-18805 -- Contribution page not recorded on recurring transactions, Recurring contribution payments diff --git a/CRM/Core/Payment/AuthorizeNetIPN.php b/CRM/Core/Payment/AuthorizeNetIPN.php index 04042b587a..607fcc1fec 100644 --- a/CRM/Core/Payment/AuthorizeNetIPN.php +++ b/CRM/Core/Payment/AuthorizeNetIPN.php @@ -96,23 +96,16 @@ class CRM_Core_Payment_AuthorizeNetIPN extends CRM_Core_Payment_BaseIPN { // create a contribution and then get it processed $contribution = new CRM_Contribute_BAO_Contribution(); $contribution->contact_id = $ids['contact']; - $contribution->financial_type_id = $objects['contributionType']->id; $contribution->contribution_page_id = $ids['contributionPage']; $contribution->contribution_recur_id = $ids['contributionRecur']; $contribution->receive_date = $input['receive_date']; - $contribution->currency = $objects['contribution']->currency; - $contribution->amount_level = $objects['contribution']->amount_level; - $contribution->address_id = $objects['contribution']->address_id; - $contribution->campaign_id = $objects['contribution']->campaign_id; - - $objects['contribution'] = &$contribution; } $input['payment_processor_id'] = $paymentProcessorID; $isFirstOrLastRecurringPayment = $this->recur($input, [ 'related_contact' => $ids['related_contact'] ?? NULL, - 'participant' => !empty($objects['participant']) ? $objects['participant']->id : NULL, + 'participant' => NULL, 'contributionRecur' => $contributionRecur->id, - ], $contributionRecur, $objects['contribution'], $first); + ], $contributionRecur, $contribution, $first); if ($isFirstOrLastRecurringPayment) { //send recurring Notification email for user diff --git a/tests/phpunit/CRM/Core/Payment/AuthorizeNetIPNTest.php b/tests/phpunit/CRM/Core/Payment/AuthorizeNetIPNTest.php index 2b04f7a484..5953eb796c 100644 --- a/tests/phpunit/CRM/Core/Payment/AuthorizeNetIPNTest.php +++ b/tests/phpunit/CRM/Core/Payment/AuthorizeNetIPNTest.php @@ -164,10 +164,13 @@ class CRM_Core_Payment_AuthorizeNetIPNTest extends CiviUnitTestCase { $contribution = $this->callAPISuccess('contribution', 'get', [ 'contribution_recur_id' => $this->_contributionRecurID, 'sequential' => 1, - ]); - $this->assertEquals(2, $contribution['count']); - $this->assertEquals('second_one', $contribution['values'][1]['trxn_id']); - $this->assertEquals(date('Y-m-d'), date('Y-m-d', strtotime($contribution['values'][1]['receive_date']))); + ])['values']; + $this->assertCount(2, $contribution); + $secondContribution = $contribution[1]; + $this->assertEquals('second_one', $secondContribution['trxn_id']); + $this->assertEquals(date('Y-m-d'), date('Y-m-d', strtotime($secondContribution['receive_date']))); + $this->assertEquals('expensive', $secondContribution['amount_level']); + $this->assertEquals($this->ids['campaign'][0], $secondContribution['campaign_id']); } /** diff --git a/tests/phpunit/CiviTest/CiviUnitTestCase.php b/tests/phpunit/CiviTest/CiviUnitTestCase.php index 429249e2bd..8d540ed055 100644 --- a/tests/phpunit/CiviTest/CiviUnitTestCase.php +++ b/tests/phpunit/CiviTest/CiviUnitTestCase.php @@ -2504,6 +2504,7 @@ VALUES * @throws \CRM_Core_Exception */ public function setupRecurringPaymentProcessorTransaction($recurParams = [], $contributionParams = []) { + $this->ids['campaign'][0] = $this->callAPISuccess('Campaign', 'create', ['title' => 'get the money'])['id']; $contributionParams = array_merge([ 'total_amount' => '200', 'invoice_id' => $this->_invoiceID, @@ -2515,6 +2516,8 @@ VALUES 'is_test' => 0, 'receive_date' => '2019-07-25 07:34:23', 'skipCleanMoney' => TRUE, + 'amount_level' => 'expensive', + 'campaign_id' => $this->ids['campaign'][0], ], $contributionParams); $contributionRecur = $this->callAPISuccess('contribution_recur', 'create', array_merge([ 'contact_id' => $this->_contactID, -- 2.25.1