Commit 808fc81a authored by mattwire's avatar mattwire
Browse files

Fix 'Refund not communicated back to CiviCRM properly'

parent df201085
......@@ -390,6 +390,24 @@ trait CRM_Core_Payment_MJWIPNTrait {
$this->checkRequiredParams('updateContributionRefund', ['contribution_id', 'total_amount'], $params);
$params['payment_processor_id'] = $this->_paymentProcessor->getID();
civicrm_api3('Mjwpayment', 'create_payment', $params);
// https://github.com/civicrm/civicrm-core/pull/18930
// Set contribution status to refunded even if cancelled_payment_id is set
if (version_compare(CRM_Utils_System::version(), '5.32', '<')) {
if ($params['total_amount'] < 0 && !empty($params['cancelled_payment_id'])) {
$contribution = civicrm_api3('Contribution', 'getsingle', ['id' => $params['contribution_id']]);
$contributionStatus = CRM_Core_PseudoConstant::getName('CRM_Contribute_BAO_Contribution', 'contribution_status_id', $contribution['contribution_status_id']);
if ($contributionStatus === 'Completed' && ((float) CRM_Core_BAO_FinancialTrxn::getTotalPayments($params['contribution_id'], TRUE) === 0.0)) {
// If the contribution has previously been completed (fully paid) and now has total payments adding up to 0
// change status to refunded.
$this->updateContribution([
'contribution_id' => $params['contribution_id'],
'contribution_status_id' => 'Refunded',
]);
}
}
}
}
/**
......
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