From 5e068f6d31ff049c48799129f7373d2298e9279a Mon Sep 17 00:00:00 2001 From: Marc Michalsky forumZFD Date: Tue, 23 Feb 2021 16:17:28 +0100 Subject: [PATCH] test if response array contains contribution --- CRM/TwingleCampaign/Utils/APIWrapper.php | 30 +++++++++++++----------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/CRM/TwingleCampaign/Utils/APIWrapper.php b/CRM/TwingleCampaign/Utils/APIWrapper.php index c495b6f..4b59262 100644 --- a/CRM/TwingleCampaign/Utils/APIWrapper.php +++ b/CRM/TwingleCampaign/Utils/APIWrapper.php @@ -36,20 +36,22 @@ class CRM_TwingleCampaign_Utils_APIWrapper { $response = $event->getResponse(); // Create soft credit for contribution - $contribution = $response['values']['contribution'] - [array_key_first($response['values']['contribution'])]; - if (array_key_exists('campaign_id', $contribution)) { - try { - $twingle_event = civicrm_api3( - 'TwingleEvent', - 'getsingle', - ['id' => $contribution['campaign_id']] - )['values']; - $response['values']['soft_credit'] = - self::createSoftCredit($contribution, $twingle_event)['values']; - $event->setResponse($response); - } catch (CiviCRM_API3_Exception $e) { - // Do nothing + if (array_key_exists('contribution', $response['values'])) { + $contribution = $response['values']['contribution'] + [array_key_first($response['values']['contribution'])]; + if (array_key_exists('campaign_id', $contribution)) { + try { + $twingle_event = civicrm_api3( + 'TwingleEvent', + 'getsingle', + ['id' => $contribution['campaign_id']] + )['values']; + $response['values']['soft_credit'] = + self::createSoftCredit($contribution, $twingle_event)['values']; + $event->setResponse($response); + } catch (CiviCRM_API3_Exception $e) { + // Do nothing + } } } }