From 00f2b048a7fe5cc6a71522a7436e23979fceb264 Mon Sep 17 00:00:00 2001 From: adixon Date: Mon, 1 Feb 2021 17:12:48 -0500 Subject: [PATCH] Added try-catch for api call --- CRM/Iats/Transaction.php | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/CRM/Iats/Transaction.php b/CRM/Iats/Transaction.php index 19f49e27..40171022 100644 --- a/CRM/Iats/Transaction.php +++ b/CRM/Iats/Transaction.php @@ -184,11 +184,18 @@ static function process_contribution_payment(&$contribution, $paymentProcessor, if (!$use_repeattransaction) { /* If I'm not using repeattransaction for any reason, I'll create the contribution manually */ // This code assumes that the contribution_status_id has been set properly above, either pending or failed. - $contributionResult = civicrm_api3('contribution', 'create', $contribution); + try { + $contributionResult = civicrm_api3('contribution', 'create', $contribution); + } + catch (Exception $e) { + // log the error and continue + CRM_Core_Error::debug_var('Unexpected Exception', $e); + $contributionResult = []; + } // Pass back the created id indirectly since I'm calling by reference. $contribution['id'] = CRM_Utils_Array::value('id', $contributionResult); // Connect to a membership if requested. - if (!empty($contribution['membership_id'])) { + if (!empty($contribution['id']) && !empty($contribution['membership_id'])) { try { civicrm_api3('MembershipPayment', 'create', array('contribution_id' => $contribution['id'], 'membership_id' => $contribution['membership_id'])); }