From 4a174e95aeb83eb1e1056bf025e4a161c549f694 Mon Sep 17 00:00:00 2001 From: Matthew Wire Date: Mon, 23 Dec 2019 22:59:13 +0000 Subject: [PATCH] Set contribution status to refunded when it has previously been fully paid and now payments add up to 0 --- CRM/Financial/BAO/Payment.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CRM/Financial/BAO/Payment.php b/CRM/Financial/BAO/Payment.php index 7da4925b20..122f13cb91 100644 --- a/CRM/Financial/BAO/Payment.php +++ b/CRM/Financial/BAO/Payment.php @@ -149,6 +149,11 @@ class CRM_Financial_BAO_Payment { elseif ($contributionStatus === 'Pending' && $params['total_amount'] > 0) { self::updateContributionStatus($contribution['id'], 'Partially Paid'); } + elseif ($contributionStatus === 'Completed' && ((float) CRM_Core_BAO_FinancialTrxn::getTotalPayments($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. + self::updateContributionStatus($contribution['id'], 'Refunded'); + } 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; } -- 2.25.1