test if response array contains contribution

This commit is contained in:
Marc Michalsky forumZFD 2021-02-23 16:17:28 +01:00
parent c20c4ab16c
commit 5e068f6d31
Signed by untrusted user who does not match committer: marc.koch
GPG key ID: 12406554CFB028B9

View file

@ -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
}
}
}
}