Commit fa7576f0 authored by mattwire's avatar mattwire
Browse files

Don't exit when a contribution cannot be found

parent 1481dc6a
......@@ -94,13 +94,14 @@ class CRM_Core_Payment_AuthNetIPN {
// Notifies you that an authorization and capture transaction was created.
$contribution = $this->getContributionFromTrxnInfo($this->getParamFromResponse($response, 'invoice_id'));
$pendingStatusId = CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'contribution_status_id', 'Pending');
if (!empty($contribution['id']) && $contribution['contribution_status_id'] == $pendingStatusId) {
if ($contribution && ($contribution['contribution_status_id'] == $pendingStatusId)) {
$params = [
'contribution_id' => $contribution['id'],
'trxn_id' => $this->getParamFromResponse($response, 'transaction_id'),
'order_reference' => $this->getParamFromResponse($response, 'invoice_id'),
'trxn_date' => $this->event_date,
'total_amount' => $this->getParamFromResponse($response, 'total_amount'),
'contribution_status_id' => $contribution['contribution_status_id']
];
$this->updateContributionCompleted($params);
}
......@@ -120,8 +121,12 @@ class CRM_Core_Payment_AuthNetIPN {
case 'net.authorize.payment.refund.created':
// Notifies you that a successfully settled transaction was refunded.
$contribution = $this->getContributionFromTrxnInfo($this->getParamFromResponse($response, 'invoice_id'));
if (!$contribution) {
return FALSE;
}
$params = [
'contribution_id' => $this->getContributionFromTrxnInfo($this->getParamFromResponse($response, 'invoice_id'))['id'],
'contribution_id' => $contribution['id'],
'total_amount' => $this->getParamFromResponse($response, 'refund_amount'),
];
$this->updateContributionRefund($params);
......@@ -129,8 +134,12 @@ class CRM_Core_Payment_AuthNetIPN {
case 'net.authorize.payment.void.created':
// Notifies you that an unsettled transaction was voided.
$contribution = $this->getContributionFromTrxnInfo($this->getParamFromResponse($response, 'invoice_id'));
if (!$contribution) {
return FALSE;
}
$params = [
'contribution_id' => $this->getContributionFromTrxnInfo($this->getParamFromResponse($response, 'invoice_id'))['id'],
'contribution_id' => $contribution['id'],
'order_reference' => $this->getParamFromResponse($response, 'invoice_id'),
'trxn_date' => $this->event_date,
];
......@@ -143,19 +152,28 @@ class CRM_Core_Payment_AuthNetIPN {
case 'net.authorize.payment.fraud.approved':
// Notifies you that a previously held transaction was approved.
$contribution = $this->getContributionFromTrxnInfo($this->getParamFromResponse($response, 'invoice_id'));
if (!$contribution) {
return FALSE;
}
$params = [
'contribution_id' => $this->getContributionFromTrxnInfo($this->getParamFromResponse($response, 'invoice_id'))['id'],
'contribution_id' => $contribution['id'],
'trxn_id' => $this->getParamFromResponse($response, 'transaction_id'),
'order_reference' => $this->getParamFromResponse($response, 'invoice_id'),
'trxn_date' => $this->event_date,
'contribution_status_id' => $contribution['contribution_status_id']
];
$this->updateContributionCompleted($params);
break;
case 'net.authorize.payment.fraud.declined':
// Notifies you that a previously held transaction was declined.
$contribution = $this->getContributionFromTrxnInfo($this->getParamFromResponse($response, 'invoice_id'));
if (!$contribution) {
return FALSE;
}
$params = [
'contribution_id' => $this->getContributionFromTrxnInfo($this->getParamFromResponse($response, 'invoice_id'))['id'],
'contribution_id' => $contribution['id'],
'order_reference' => $this->getParamFromResponse($response, 'invoice_id'),
'trxn_date' => $this->event_date,
];
......@@ -223,7 +241,7 @@ class CRM_Core_Payment_AuthNetIPN {
*
* @param string $invoiceID
*
* @return array
* @return array|NULL
* @throws \CiviCRM_API3_Exception
*/
protected function getContributionFromTrxnInfo($invoiceID) {
......@@ -249,7 +267,7 @@ class CRM_Core_Payment_AuthNetIPN {
// We can't do anything without a matching contribution!
if (empty($contribution['id'])) {
$this->exception("Could not find matching contribution for trxn_id: {$this->trxnId} or invoice ID: {$invoiceID}");
return NULL;
}
return reset($contribution['values']);
......
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