Skip to content

Commit

Permalink
Added try-catch for api call
Browse files Browse the repository at this point in the history
  • Loading branch information
adixon committed Feb 1, 2021
1 parent 6d41cb8 commit 00f2b04
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions CRM/Iats/Transaction.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']));
}
Expand Down

0 comments on commit 00f2b04

Please sign in to comment.