Unverified Commit a1b3cb01 authored by Monish Deb's avatar Monish Deb Committed by GitHub

Merge pull request #15502 from eileenmcnaughton/payment_bug

financial#69 Fix misrecording of payments against non pay_later Pending contribution.
parents 1479f0f1 16b0233c
......@@ -342,20 +342,6 @@ class CRM_Contribute_Form_AdditionalPayment extends CRM_Contribute_Form_Abstract
if ($this->_component == 'event') {
$participantId = $this->_id;
}
$contributionStatuses = CRM_Core_PseudoConstant::get('CRM_Contribute_DAO_Contribution',
'contribution_status_id',
['labelColumn' => 'name']
);
$contributionStatusID = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_Contribution', $this->_contributionId, 'contribution_status_id');
if ($contributionStatuses[$contributionStatusID] == 'Pending') {
civicrm_api3('Contribution', 'create',
[
'id' => $this->_contributionId,
'contribution_status_id' => array_search('Partially paid', $contributionStatuses),
'is_pay_later' => 0,
]
);
}
if ($this->_mode) {
// process credit card
......
......@@ -171,12 +171,7 @@ class CRM_Financial_BAO_Payment {
}
}
elseif ($contributionStatus === 'Pending') {
civicrm_api3('Contribution', 'create',
[
'id' => $contribution['id'],
'contribution_status_id' => 'Partially paid',
]
);
self::updateContributionStatus($contribution['id'], 'Partially Paid');
}
CRM_Contribute_BAO_Contribution::recordPaymentActivity($params['contribution_id'], CRM_Utils_Array::value('participant_id', $params), $params['total_amount'], $trxn->currency, $trxn->trxn_date);
return $trxn;
......@@ -534,4 +529,24 @@ WHERE eft.financial_trxn_id IN ({$trxnId}, {$baseTrxnId['financialTrxnId']})
return ($cmp == 0 || $cmp == 1);
}
/**
* Update the status of the contribution.
*
* We pass the is_post_payment_create as we have already created the line items
*
* @param int $contributionID
* @param string $status
*
* @throws \CiviCRM_API3_Exception
*/
private static function updateContributionStatus(int $contributionID, string $status) {
civicrm_api3('Contribution', 'create',
[
'id' => $contributionID,
'is_post_payment_create' => TRUE,
'contribution_status_id' => $status,
]
);
}
}
......@@ -716,7 +716,28 @@ class api_v3_PaymentTest extends CiviUnitTestCase {
/**
* Test create payment api for pay later contribution with partial payment.
*
* @throws \Exception
* https://lab.civicrm.org/dev/financial/issues/69
*/
public function testCreatePaymentIncompletePaymentPartialPayment() {
$contributionParams = [
'total_amount' => 100,
'currency' => 'USD',
'contact_id' => $this->_individualId,
'financial_type_id' => 1,
'contribution_status_id' => 2,
];
$contribution = $this->callAPISuccess('Contribution', 'create', $contributionParams);
$this->callAPISuccess('Payment', 'create', [
'contribution_id' => $contribution['id'],
'total_amount' => 50,
'payment_instrument_id' => 'Cash',
]);
$payments = $this->callAPISuccess('Payment', 'get', ['contribution_id' => $contribution['id']])['values'];
$this->assertCount(1, $payments);
}
/**
* Test create payment api for pay later contribution with partial payment.
*/
public function testCreatePaymentPayLaterPartialPayment() {
$this->createLoggedInUser();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment