diff --git a/CRM/Core/BAO/FinancialTrxn.php b/CRM/Core/BAO/FinancialTrxn.php index f893a9426087..f6ec9f6c65e5 100644 --- a/CRM/Core/BAO/FinancialTrxn.php +++ b/CRM/Core/BAO/FinancialTrxn.php @@ -506,26 +506,6 @@ public static function getTotalPayments($contributionID, $includeRefund = FALSE) ]); } - /** - * Function records partial payment, complete's contribution if payment is fully paid - * and returns latest payment ie financial trxn - * - * @param array $contribution - * @param array $params - * - * @return \CRM_Financial_DAO_FinancialTrxn - */ - public static function getPartialPaymentTrxn($contribution, $params) { - $trxn = CRM_Contribute_BAO_Contribution::recordPartialPayment($contribution, $params); - $paid = CRM_Core_BAO_FinancialTrxn::getTotalPayments($params['contribution_id']); - $total = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_Contribution', $params['contribution_id'], 'total_amount'); - $cmp = bccomp($total, $paid, 5); - if ($cmp == 0 || $cmp == -1) {// If paid amount is greater or equal to total amount - civicrm_api3('Contribution', 'completetransaction', array('id' => $contribution['id'])); - } - return $trxn; - } - /** * Get revenue amount for membership. * diff --git a/CRM/Financial/BAO/Payment.php b/CRM/Financial/BAO/Payment.php index 1e3e0518aa60..a5d4ea4de340 100644 --- a/CRM/Financial/BAO/Payment.php +++ b/CRM/Financial/BAO/Payment.php @@ -79,7 +79,14 @@ public static function create($params) { } } if (!$fullyPaidPayLater) { - $trxn = CRM_Core_BAO_FinancialTrxn::getPartialPaymentTrxn($contribution, $params); + $trxn = CRM_Contribute_BAO_Contribution::recordPartialPayment($contribution, $params); + $paid = CRM_Core_BAO_FinancialTrxn::getTotalPayments($params['contribution_id']); + $total = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_Contribution', $params['contribution_id'], 'total_amount'); + $cmp = bccomp($total, $paid, 5); + if ($cmp == 0 || $cmp == -1) {// If paid amount is greater or equal to total amount + civicrm_api3('Contribution', 'completetransaction', array('id' => $contribution['id'])); + } + if (CRM_Utils_Array::value('line_item', $params) && !empty($trxn)) { foreach ($params['line_item'] as $values) { foreach ($values as $id => $amount) { diff --git a/tests/phpunit/CRM/Core/BAO/FinancialTrxnTest.php b/tests/phpunit/CRM/Core/BAO/FinancialTrxnTest.php index e09a2db940d5..94de1d4d10ef 100644 --- a/tests/phpunit/CRM/Core/BAO/FinancialTrxnTest.php +++ b/tests/phpunit/CRM/Core/BAO/FinancialTrxnTest.php @@ -106,9 +106,9 @@ public function testGetTotalPayments() { } /** - * Test getPartialPaymentTrxn function. + * Tests the lines of code that used to be in the getPartialPaymentTrxn fn. */ - public function testGetPartialPaymentTrxn() { + public function testGetExPartialPaymentTrxn() { $contributionTest = new CRM_Contribute_BAO_ContributionTest(); list($lineItems, $contribution) = $contributionTest->addParticipantWithContribution(); $contribution = (array) $contribution; @@ -116,7 +116,13 @@ public function testGetPartialPaymentTrxn() { 'contribution_id' => $contribution['id'], 'total_amount' => 100.00, ); - $trxn = CRM_Core_BAO_FinancialTrxn::getPartialPaymentTrxn($contribution, $params); + $trxn = CRM_Contribute_BAO_Contribution::recordPartialPayment($contribution, $params); + $paid = CRM_Core_BAO_FinancialTrxn::getTotalPayments($params['contribution_id']); + $total = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_Contribution', $params['contribution_id'], 'total_amount'); + $cmp = bccomp($total, $paid, 5); + if ($cmp == 0 || $cmp == -1) {// If paid amount is greater or equal to total amount + civicrm_api3('Contribution', 'completetransaction', array('id' => $contribution['id'])); + } $this->assertEquals('100.00', $trxn->total_amount, 'Amount does not match.');