Showing posts with label Open Exchange Rates. Show all posts
Showing posts with label Open Exchange Rates. Show all posts

Friday, March 27, 2015

Creating Exchange Rate Providers in Microsoft Dynamics AX 2012 for Open Exchange Rates



Microsoft Dynamics AX 2012 has the frame work for integrating currency exchange rates from exchange rate providers. Please reference Creating Exchange Rate Providers for Microsoft Dynamics AX 2012. The referenced document from Microsoft shows how to customize the frame work to work with Oanda Exchange Rates .

There are other providers, some which offer a fee based API and others which offer a free API. Doing research on these providers led me to Open Exchange Rates. They offer an API at no cost for personal use, and a fee based API for Enterprise users, which is fairly competitive with other providers.

This blog entry uses the referenced document from Microsoft as a guide to create a provider class in Dynamics AX specifically for use with the free version of Open Exchange Rates, and the fee based Open Exchange Rates API.


A challenge with using this provider is that it uses JSON instead of XML.

The provider class we will create will be the fee based provider. The fee based provider allows for selection of base currency, and specific currency pairs.

Create the class as ExchangeRateProviderOpenExchRates and have it extend the ExchangeRateProvider as shown in the class declaration below.

Note: The ExchangeRateProviderIdAttribute is a unique ID that you will need to supply. You can obtain a unique ID from http://createguid.com


Now create a method called getConfigurationDefaults. This method will provide the default URL used to make requests to the provider.


Next create the getExchangeRates method. This method is responsible for constructing the URL to request the currency information from the provider, and store the results in the currency exchange rate tables of Dynamics AX.



Next create the getName method. This method is used by Dynamics AX to populate the list of providers that Dynamics AX has been modified to support.


Once the getName method is created, create the getProviderId method. This method simply returns the unique GUID that was assigned in the class declaration.

Next create the getSupportedOptions method.


The last method that needs created is the readRate method. It is responsible for parsing the JSON response string from the provider, and storing the exchange rate and currency information in the Lists.


The version of the class that supports the free API is basically the same except for the URL request string. The free version only supports 2 options. The APPId, and the date parameter. The result is a currency list for all supported currencies but it is USD based. However the class filters to just the currency conversion needed by date. To modify the class to use the free version, simply change the getConfigurationDefaults method as follows:


Now that the class has been created, it can be used in currency configuration and setup within Dynamics AX.




currency1


currency2