From 2ff2ff26e7fef0437a9c90b8933d1959016ea3bd Mon Sep 17 00:00:00 2001 From: Pradeep Nayak Date: Wed, 20 Jan 2016 16:42:37 +0530 Subject: [PATCH] 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 --- api/v3/Payment.php | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) 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'); } /** -- 2.25.1