public static async Task <IList <HSShipEstimate> > ConvertCurrency(this IList <HSShipEstimate> shipEstimates, CurrencySymbol shipperCurrency, CurrencySymbol buyerCurrency, IExchangeRatesCommand _exchangeRates)
        {
            // If the Buyer's currency is USD, do not convert rates.
            if (buyerCurrency == CurrencySymbol.USD)
            {
                return(shipEstimates);
            }
            ;

            var rates          = (await _exchangeRates.Get(buyerCurrency)).Rates;
            var conversionRate = rates.Find(r => r.Currency == shipperCurrency).Rate;

            return(shipEstimates.Select(estimate =>
            {
                estimate.ShipMethods = estimate.ShipMethods.Select(method =>
                {
                    method.xp.OriginalCurrency = shipperCurrency;
                    method.xp.OrderCurrency = buyerCurrency;
                    method.xp.ExchangeRate = conversionRate;
                    if (conversionRate != null)
                    {
                        method.Cost /= (decimal)conversionRate;
                    }
                    return method;
                }).ToList();
                return estimate;
            }).ToList());
        }
        public async Task <List <OrderCloudIntegrationsConversionRate> > GetExchangeRatesForUser(string userToken)
        {
            var currency = await GetCurrencyForUser(userToken);

            var exchangeRates = await _exchangeRatesCommand.Get(new ListArgs <OrderCloudIntegrationsConversionRate>() { }, currency);

            return(exchangeRates.Items.ToList());
        }
Beispiel #3
0
        public async Task map_raw_api_rates_test()
        {
            var rates = await _command.Get(CurrencySymbol.EUR);

            Assert.IsTrue(rates.BaseSymbol == CurrencySymbol.EUR);
            Assert.IsTrue(rates.Rates.Count(r => r.Rate == 0) == 0); // make sure any errors in returned data (null rate for EUR) is set to 1
            Assert.IsFalse(rates.Rates.Any(r => r.Icon == null));
        }
        private async Task <List <HSShipEstimate> > ConvertShippingRatesCurrency(IList <HSShipEstimate> shipEstimates, CurrencySymbol shipperCurrency, CurrencySymbol buyerCurrency)
        {
            var rates          = (await _exchangeRates.Get(buyerCurrency)).Rates;
            var conversionRate = rates.Find(r => r.Currency == shipperCurrency).Rate;

            return(shipEstimates.Select(estimate =>
            {
                estimate.ShipMethods = estimate.ShipMethods.Select(method =>
                {
                    method.xp.OriginalCurrency = shipperCurrency;
                    method.xp.OrderCurrency = buyerCurrency;
                    method.xp.ExchangeRate = conversionRate;
                    if (conversionRate != null)
                    {
                        method.Cost /= (decimal)conversionRate;
                    }
                    return method;
                }).ToList();
                return estimate;
            }).ToList());
        }
 public async Task <ListPage <OrderCloudIntegrationsConversionRate> > Get(ListArgs <OrderCloudIntegrationsConversionRate> rateArgs, CurrencySymbol currency)
 {
     return(await _command.Get(rateArgs, currency));
 }