Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dev/financial#69 Fix misrecording of payments against non pay_later Pending contribution. #15511

Merged
merged 1 commit into from
Oct 15, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 0 additions & 14 deletions CRM/Contribute/Form/AdditionalPayment.php
Original file line number Diff line number Diff line change
Expand Up @@ -342,20 +342,6 @@ public function submit($submittedValues) {
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
Expand Down
27 changes: 21 additions & 6 deletions CRM/Financial/BAO/Payment.php
Original file line number Diff line number Diff line change
Expand Up @@ -171,12 +171,7 @@ public static function create($params) {
}
}
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;
Expand Down Expand Up @@ -534,4 +529,24 @@ protected static function isPaymentCompletesContribution($contributionID, $payme
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,
]
);
}

}
23 changes: 22 additions & 1 deletion tests/phpunit/api/v3/PaymentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -670,7 +670,28 @@ public function testCreatePaymentPayLater() {
/**
* 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();
Expand Down