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(); $response = $event->getResponse();
// Create soft credit for contribution // Create soft credit for contribution
$contribution = $response['values']['contribution'] if (array_key_exists('contribution', $response['values'])) {
[array_key_first($response['values']['contribution'])]; $contribution = $response['values']['contribution']
if (array_key_exists('campaign_id', $contribution)) { [array_key_first($response['values']['contribution'])];
try { if (array_key_exists('campaign_id', $contribution)) {
$twingle_event = civicrm_api3( try {
'TwingleEvent', $twingle_event = civicrm_api3(
'getsingle', 'TwingleEvent',
['id' => $contribution['campaign_id']] 'getsingle',
)['values']; ['id' => $contribution['campaign_id']]
$response['values']['soft_credit'] = )['values'];
self::createSoftCredit($contribution, $twingle_event)['values']; $response['values']['soft_credit'] =
$event->setResponse($response); self::createSoftCredit($contribution, $twingle_event)['values'];
} catch (CiviCRM_API3_Exception $e) { $event->setResponse($response);
// Do nothing } catch (CiviCRM_API3_Exception $e) {
// Do nothing
}
} }
} }
} }