From: Pradeep Nayak Date: Wed, 20 Jan 2016 11:12:37 +0000 (+0530) Subject: CRM-16259, ignore foreach iteration when financial trxn id is null in api result X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=2ff2ff26e7fef0437a9c90b8933d1959016ea3bd;p=civicrm-core.git CRM-16259, ignore foreach iteration when financial trxn id is null in api result ---------------------------------------- * CRM-16259: Create Payment API https://issues.civicrm.org/jira/browse/CRM-16259 --- diff --git a/api/v3/Payment.php b/api/v3/Payment.php index 709a57bdd1..4de7545221 100644 --- a/api/v3/Payment.php +++ b/api/v3/Payment.php @@ -49,23 +49,29 @@ function civicrm_api3_payment_get($params) { $params['options']['limit'] = 0; $eft = civicrm_api3('EntityFinancialTrxn', 'get', $params); if (!empty($eft['values'])) { + $eftIds = array(); foreach ($eft['values'] as $efts) { + if (empty($efts['financial_trxn_id'])) { + continue; + } $eftIds[] = $efts['financial_trxn_id']; $map[$efts['financial_trxn_id']] = $efts['entity_id']; } - $ftParams = array( - 'id' => array('IN' => $eftIds), - 'is_payment' => 1, - ); - if ($limit) { - $ftParams['options']['limit'] = $limit; - } - $financialTrxn = civicrm_api3('FinancialTrxn', 'get', $ftParams); - foreach ($financialTrxn['values'] as &$values) { - $values['contribution_id'] = $map[$values['id']]; + if (!empty($eftIds)) { + $ftParams = array( + 'id' => array('IN' => $eftIds), + 'is_payment' => 1, + ); + if ($limit) { + $ftParams['options']['limit'] = $limit; + } + $financialTrxn = civicrm_api3('FinancialTrxn', 'get', $ftParams); + foreach ($financialTrxn['values'] as &$values) { + $values['contribution_id'] = $map[$values['id']]; + } } } - return civicrm_api3_create_success(CRM_Utils_Array::value('values', $financialTrxn), $params, 'Payment', 'get'); + return civicrm_api3_create_success(CRM_Utils_Array::value('values', $financialTrxn, array()), $params, 'Payment', 'get'); } /**