Create an exchange rate provider class

The exchange rate provider class will contain the logic that queries the exchange rates for the specified currencies. The class must inherit the Telerik.Sitefinity.Modules.Ecommerce.ExchangeRates.Services.RateProviderBase class. Your class must expose the following method:
ExchangeRateResponse GetExchangeRates(ExchangeRateRequest request);

This method has one parameter of type ExchanageRateRequest which contains the base currency of the store, a list of currencies to get exchange rates for (SupportedCurrencies), and the user defined settings for the provider which can be used to provide basic credentials (username, password, URL) for calling an external service. The method returns an ExchangeRateResponse class, which contains the list of rates for the requested currencies and a list of any error messages.

This method will be called when the rates are requested in the Sitefinity CMS backend. For more information about using the provider, see For developers: Use the exchange rate provider.

To create the exchange rate provider class, perform the following:

  1. Create a new class file.
    In the folder for your custom provider, create a new class file.
  2. Make the class public.
    Define the class to use the public access specifier.
  3. Inherit the RateProviderBase class.
    The RateProviderBase class requires the following abstract method to be implemented:
    ExchangeRateResponse GetExchangeRates(ExchangeRateRequest request);
  4. Implement the GetExchangeRates method.
    In this method you have to do the following:
    1. Create an instance of the Telerik.Sitefinity.Modules.Ecommerce.ExchangeRates.Model.ExchangeRateResponse class.
      The method must return an instance of this type. In the next step you will populate its properties.
    2. Set the base currency of the response.
      Set the BaseCurrency property to the value of the same property of the request object.
    3. Set the request status.
      Set the RateRequestStatus property of the response instance to the desired status.
    4. Set the received date.
      Set the ReceivedDate property of the response instance to DateTime.Now.
    5. Get an instance of the settings for the provider.
      If you require them, you can get the settings for the provider by getting the value of the Settings property of the request instance.
    6. Iterate through the SupportedCurrencies collection of the request instance.
      Get the rate for each of the supported currencies. One of the ways to do this is to call an external service. In this example, hardcoded values are used. After getting the rate, you can validate the value and update the rate request status, if needed.
  5. Return the response instance.
    Return the instance of the ExchangeRateResponse class.

Use the following example of an exchange rate provider class:

Increase your Sitefinity skills by signing up for our free trainings. Get Sitefinity-certified at Progress Education Community to boost your credentials.

Web Security for Sitefinity Administrators

The free standalone Web Security lesson teaches administrators how to protect your websites and Sitefinity instance from external threats. Learn to configure HTTPS, SSL, allow lists for trusted sites, and cookie security, among others.

Foundations of Sitefinity ASP.NET Core Development

The free on-demand video course teaches developers how to use Sitefinity .NET Core and leverage its decoupled architecture and new way of coding against the platform.

Was this article helpful?