/// <summary> /// The get taxation by product method. /// </summary> /// <returns> /// The <see cref="ITaxationByProductMethod"/>. /// </returns> /// <exception cref="NullReferenceException"> /// Throws a null reference exception if a provider cannot be resolved /// </exception> private ITaxationByProductMethod GetTaxationByProductMethod() { var taxMethod = GatewayProviderService.GetTaxMethodForProductPricing(); if (taxMethod == null) { LogHelper.Debug <TaxationContext>("Product based pricing is set in settings, but a TaxMethod has not been assigned."); this._taxMethodNotQueried = true; return(null); } var provider = GatewayProviderResolver.GetProviderByKey <TaxationGatewayProviderBase>(taxMethod.ProviderKey); if (provider == null) { var error = new NullReferenceException("Could not reTaxationGatewayProvider for CalculateTaxForProduct could not be resolved"); LogHelper.Error <TaxationContext>("Resolution failure", error); throw error; } var productProvider = provider as ITaxationByProductProvider; if (productProvider != null) { this._taxMethodNotQueried = false; return(productProvider.GetTaxationByProductMethod(taxMethod.Key)); } LogHelper.Debug <TaxationContext>("Resolved provider did not Implement ITaxationByProductProvider returning no tax"); return(null); }
/// <summary> /// Resolves all active shipping gateway providers for a given <see cref="IShipCountry"/> /// </summary> /// <param name="shipCountry"> /// The ship Country. /// </param> /// <returns> /// A collection of all active shipping gateway providers /// </returns> public IEnumerable <ShippingGatewayProviderBase> GetGatewayProvidersByShipCountry(IShipCountry shipCountry) { var gatewayProviders = GatewayProviderService.GetGatewayProvidersByShipCountry(shipCountry); return (gatewayProviders.Select( provider => GatewayProviderResolver.GetProviderByKey <ShippingGatewayProviderBase>(provider.Key))); }
public void Can_Activate_A_PaymentGatewayProvider() { //// Arrange var resolver = new GatewayProviderResolver(MerchelloContext.Current.Services.GatewayProviderService, MerchelloContext.Current.Cache.RuntimeCache); //// Act var provider = resolver.GetAllProviders<PaymentGatewayProviderBase>().FirstOrDefault(x => !x.Activated); Assert.NotNull(provider); MerchelloContext.Current.Gateways.Payment.ActivateProvider(provider); //// Assert Assert.IsTrue(provider.Activated); }
/// <summary> /// Returns a collection of all <see cref="IShipmentRateQuote"/> that are available for the <see cref="IShipment"/> /// </summary> /// <param name="shipment">The <see cref="IShipment"/> to quote</param> /// <returns>A collection of <see cref="IShipmentRateQuote"/></returns> public IEnumerable <IShipmentRateQuote> GetShipRateQuotesForShipment(IShipment shipment) { var providers = GatewayProviderResolver.GetActivatedProviders <ShippingGatewayProviderBase>() as IEnumerable <ShippingGatewayProviderBase>; var quotes = new List <IShipmentRateQuote>(); if (providers == null) { return(quotes); } foreach (var provider in providers) { quotes.AddRange(provider.QuoteShippingGatewayMethodsForShipment(shipment)); } return(quotes.OrderBy(x => x.Rate)); }
/// <summary> /// Calculates taxes for the <see cref="IInvoice"/> /// </summary> /// <param name="invoice"> /// The <see cref="IInvoice"/> to tax /// </param> /// <param name="taxAddress"> /// The address to base the taxation calculation /// </param> /// <param name="quoteOnly"> /// An optional parameter indicating that the tax calculation should be an estimate. /// This is useful for some 3rd party tax APIs /// </param> /// <returns> /// The <see cref="ITaxCalculationResult"/> /// </returns> public ITaxCalculationResult CalculateTaxesForInvoice(IInvoice invoice, IAddress taxAddress, bool quoteOnly = false) { var providersKey = GatewayProviderService.GetTaxMethodsByCountryCode(taxAddress.CountryCode) .Select(x => x.ProviderKey).FirstOrDefault(); if (Guid.Empty.Equals(providersKey)) { return(new TaxCalculationResult(0, 0)); } var provider = GatewayProviderResolver.GetProviderByKey <TaxationGatewayProviderBase>(providersKey); var gatewayTaxMethod = provider.GetGatewayTaxMethodByCountryCode(taxAddress.CountryCode); return(gatewayTaxMethod.CalculateTaxForInvoice(invoice, taxAddress)); }
/// <summary> /// Gets a list of all possible Payment Methods /// </summary> /// <returns>A collection of <see cref="IPaymentGatewayMethod"/>s</returns> public IEnumerable <IPaymentGatewayMethod> GetPaymentGatewayMethods() { var paymentProviders = GatewayProviderResolver.GetActivatedProviders <PaymentGatewayProviderBase>() as IEnumerable <PaymentGatewayProviderBase>; var methods = new List <IPaymentGatewayMethod>(); if (paymentProviders == null) { return(methods); } foreach (var provider in paymentProviders) { methods.AddRange(provider.PaymentMethods.Select(x => provider.GetPaymentGatewayMethodByKey(x.Key))); } return(methods); }
public void Can_Retrieve_A_List_Of_AllTaxationProviders() { //// Arrange var resolver = new GatewayProviderResolver(MerchelloContext.Current.Services.GatewayProviderService, MerchelloContext.Current.Cache.RuntimeCache); //// Act var providers = resolver.GetAllProviders<TaxationGatewayProviderBase>().ToArray(); //// Assert Assert.IsTrue(providers.Any()); Assert.IsTrue(providers.Any(x => x.Activated)); Assert.IsTrue(providers.Any(x => !x.Activated)); }