Skip to content

Commit

Permalink
Merge pull request #13718 from eileenmcnaughton/payment_ref
Browse files Browse the repository at this point in the history
Decommision getPartialPaymentTrxn function
  • Loading branch information
monishdeb authored Mar 1, 2019
2 parents fa7827a + 74e4c3c commit 2169e99
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 24 deletions.
20 changes: 0 additions & 20 deletions CRM/Core/BAO/FinancialTrxn.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
9 changes: 8 additions & 1 deletion CRM/Financial/BAO/Payment.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
12 changes: 9 additions & 3 deletions tests/phpunit/CRM/Core/BAO/FinancialTrxnTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,17 +106,23 @@ 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;
$params = array(
'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.');

Expand Down

0 comments on commit 2169e99

Please sign in to comment.