Skip to content
Snippets Groups Projects
Commit b34a817a authored by mattwire's avatar mattwire
Browse files

Record a full refund correctly

parent 63c0bbaf
No related branches found
No related tags found
No related merge requests found
......@@ -95,22 +95,23 @@ trait CRM_Core_Payment_MJWIPNTrait {
/**
* Record a refunded contribution
* This function ONLY supports full refunds
*
* @param array $params
*
* @throws \CiviCRM_API3_Exception
*/
protected function updateContributionRefund($params) {
$this->checkRequiredParams('updateContributionRefund', ['id', 'total_amount'], $params);
if ($params['total_amount'] > 0) {
$params['total_amount'] = -$params['total_amount'];
}
$this->checkRequiredParams('updateContributionRefund', ['id', 'payment_trxn_id'], $params);
if (empty($params['cancel_date'])) {
$params['cancel_date'] = date('YmdHis');
}
$params['contribution_status_id'] = CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'contribution_status_id', 'Refunded');
civicrm_api3('Contribution', 'create', $params);
$this->updatePaymentTrxnID($params['id'], $params['payment_trxn_id']);
}
/**
......@@ -251,12 +252,17 @@ trait CRM_Core_Payment_MJWIPNTrait {
// @fixme: There needs to be a better way to do this!!
// Contribution trxn_id = invoice_id, payment trxn_id = charge_id
// but calling completetransaction does not allow us to do that.
// @fixme: 2! Payment.get does not support the sort option so we can't do limit=1,sort=id DESC
$payment = civicrm_api3('Payment', 'get', [
'contribution_id' => $contributionID,
'options' => ['limit' => 1, 'sort' => "id DESC"],
]);
if (empty($payment['count'])) {
$this->exception('No payments found for contribution ID: ' . $contributionID);
}
krsort($payment['values']);
$paymentID = CRM_Utils_Array::first($payment['values'])['id'];
civicrm_api3('FinancialTrxn', 'create', [
'id' => $payment['id'],
'id' => $paymentID,
'trxn_id' => $trxnID,
]);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment