Commit 0bf2d9b5 authored by Jamie McClelland's avatar Jamie McClelland
Browse files

ensure things don't break with apiv4

parent c32b3d39
......@@ -28,6 +28,20 @@ class CRM_CiviMobileAPI_ApiWrapper_Contribution implements API_Wrapper {
return $result;
}
/**
* Check with API version is being called.
*
* @param $result - either apiv3 or apiv4 result
*
* @return Boolean - TRUE if the api result is from version 3.
*/
private static function isApiVersion3($result) {
if (is_array($result) && $result['version'] == 3) {
return TRUE;
}
return FALSE;
}
/**
* @param array $apiRequest
* @param array $result
......@@ -35,6 +49,10 @@ class CRM_CiviMobileAPI_ApiWrapper_Contribution implements API_Wrapper {
* @return mixed
*/
private function fillFinancialTypeName($apiRequest, $result) {
if (!self::isApiVersion3($result)) {
return $result;
}
if (empty($apiRequest['params']['return']) || stristr($apiRequest['params']['return'], 'financial_type_name') !== FALSE) {
if ($apiRequest['action'] == 'getsingle') {
$result['financial_type_name'] = $this->getFinancialTypeName($result);
......@@ -56,6 +74,10 @@ class CRM_CiviMobileAPI_ApiWrapper_Contribution implements API_Wrapper {
* @return mixed
*/
private function fillFormatTotalAmount($apiRequest, $result) {
if (!self::isApiVersion3($result)) {
return $result;
}
if (empty($apiRequest['params']['return']) || stristr($apiRequest['params']['return'], 'total_amount') !== FALSE) {
if ($apiRequest['action'] == 'getsingle') {
$result['format_total_amount'] = CRM_Utils_Money::format($result['total_amount'], $result['currency']);
......@@ -85,4 +107,4 @@ class CRM_CiviMobileAPI_ApiWrapper_Contribution implements API_Wrapper {
return CRM_Core_DAO::getFieldValue('CRM_Financial_DAO_FinancialType', $financialTypeId, 'name');
}
}
}
\ No newline at end of file
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment