From 5f5ed53aa6376877043633d16bc264746186a825 Mon Sep 17 00:00:00 2001 From: eileen Date: Mon, 4 Mar 2019 15:07:18 +1300 Subject: [PATCH] [REF] separate financial handling & component transitioning in Payment.create --- CRM/Financial/BAO/Payment.php | 45 +++++++++++++++++------------------ 1 file changed, 22 insertions(+), 23 deletions(-) diff --git a/CRM/Financial/BAO/Payment.php b/CRM/Financial/BAO/Payment.php index 567a27e0ee..9e68839930 100644 --- a/CRM/Financial/BAO/Payment.php +++ b/CRM/Financial/BAO/Payment.php @@ -58,30 +58,13 @@ class CRM_Financial_BAO_Payment { $isPaymentCompletesContribution = self::isPaymentCompletesContribution($params['contribution_id'], $params['total_amount']); - // Check if pending contribution - $fullyPaidPayLater = ($contributionStatus == 'Pending' && $isPaymentCompletesContribution); - if ($contributionStatus == 'Pending') { - if ($isPaymentCompletesContribution) { - civicrm_api3('Contribution', 'completetransaction', ['id' => $contribution['id']]); - // Get the trxn - $trxnId = CRM_Core_BAO_FinancialTrxn::getFinancialTrxnId($contribution['id'], 'DESC'); - $ftParams = ['id' => $trxnId['financialTrxnId']]; - $trxn = CRM_Core_BAO_FinancialTrxn::retrieve($ftParams, CRM_Core_DAO::$_nullArray); - } - else { - civicrm_api3('Contribution', 'create', - [ - 'id' => $contribution['id'], - 'contribution_status_id' => 'Partially paid', - ] - ); - } - } - if (!$fullyPaidPayLater) { + // For legacy reasons Pending payments are completed through completetransaction. + // @todo completetransaction should transition components but financial transactions + // should be handled through Payment.create. + $isSkipRecordingPaymentHereForLegacyHandlingReasons = ($contributionStatus == 'Pending' && $isPaymentCompletesContribution); + + if (!$isSkipRecordingPaymentHereForLegacyHandlingReasons) { $trxn = CRM_Contribute_BAO_Contribution::recordPartialPayment($contribution, $params); - if ($isPaymentCompletesContribution) { - civicrm_api3('Contribution', 'completetransaction', array('id' => $contribution['id'])); - } if (CRM_Utils_Array::value('line_item', $params) && !empty($trxn)) { foreach ($params['line_item'] as $values) { @@ -117,6 +100,22 @@ class CRM_Financial_BAO_Payment { } } + if ($isPaymentCompletesContribution) { + civicrm_api3('Contribution', 'completetransaction', array('id' => $contribution['id'])); + // Get the trxn + $trxnId = CRM_Core_BAO_FinancialTrxn::getFinancialTrxnId($contribution['id'], 'DESC'); + $ftParams = ['id' => $trxnId['financialTrxnId']]; + $trxn = CRM_Core_BAO_FinancialTrxn::retrieve($ftParams, CRM_Core_DAO::$_nullArray); + } + elseif ($contributionStatus === 'Pending') { + civicrm_api3('Contribution', 'create', + [ + 'id' => $contribution['id'], + 'contribution_status_id' => 'Partially paid', + ] + ); + } + return $trxn; } -- 2.25.1