Ejemplo n.º 1
0
        public Attempt <IShipmentRateQuote> CalculatePrice(IShipment shipment, IShipMethod shipMethod, decimal totalWeight, IShipProvince province)
        {
            // First sum up the total weight for the shipment.
            // We're assumning that a custom order line property
            // was set on the order line prior when the product was added to the order line.

            var shippingPrice = 0M;

            try
            {
                var http    = new UpsHttpRequestHandler();
                var rateXml = http.Post(RateRequest(shipment, totalWeight));

                var collection = UpsParseRates(rateXml);

                var firstCarrierRate = collection.FirstOrDefault(option => option.Service == shipMethod.Name);
                if (firstCarrierRate != null)
                {
                    shippingPrice = firstCarrierRate.Rate;
                }
            }
            catch (Exception ex)
            {
                return(Attempt <IShipmentRateQuote> .Fail(
                           new Exception("An error occured during your request : " +
                                         ex.Message +
                                         " Please contact your administrator or try again.")));
            }

            return(Attempt <IShipmentRateQuote> .Succeed(new ShipmentRateQuote(shipment, shipMethod) { Rate = shippingPrice }));
        }
Ejemplo n.º 2
0
        public Attempt<IShipmentRateQuote> CalculatePrice(IShipment shipment, IShipMethod shipMethod, decimal totalWeight, int quantity, IShipProvince province)
        {
            // First sum up the total weight for the shipment.
            // We're assumning that a custom order line property 
            // was set on the order line prior when the product was added to the order line.

            var shippingPrice = 0M;
            try
            {
                var service = new RateService {Url = "https://wsbeta.fedex.com:443/web-services/rate"};
                
                var reply = service.getRates(RateRequest(shipment, totalWeight, quantity));
                                                            
                if (reply.HighestSeverity == NotificationSeverityType.SUCCESS || reply.HighestSeverity == NotificationSeverityType.NOTE || reply.HighestSeverity == NotificationSeverityType.WARNING)
                {
                    var collection = BuildDeliveryOptions(reply, shipment);

                    var firstCarrierRate = collection.FirstOrDefault(option => option.Service.Contains(shipMethod.ServiceCode.Split('-').First()));
                    if (firstCarrierRate != null)
                        shippingPrice = firstCarrierRate.Rate;
                }

            }
            catch (Exception ex)
            {
                return Attempt<IShipmentRateQuote>.Fail(
                        new Exception("An error occured during your request : " +
                                                     ex.Message +
                                                     " Please contact your administrator or try again."));
            }

            return Attempt<IShipmentRateQuote>.Succeed(new ShipmentRateQuote(shipment, shipMethod) { Rate = shippingPrice });
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="FixedRateShippingGatewayMethod"/> class.
 /// </summary>
 /// <param name="gatewayResource">
 /// The gateway resource.
 /// </param>
 /// <param name="shipMethod">
 /// The ship method.
 /// </param>
 /// <param name="shipCountry">
 /// The ship country.
 /// </param>
 /// <param name="rateTable">
 /// The rate table.
 /// </param>
 public FixedRateShippingGatewayMethod(IGatewayResource gatewayResource, IShipMethod shipMethod, IShipCountry shipCountry, IShippingFixedRateTable rateTable)
     : base(gatewayResource, shipMethod, shipCountry)
 {
     RateTable = new ShippingFixedRateTable(shipMethod.Key);
     _quoteType = GatewayResource.ServiceCode == FixedRateShippingGatewayProvider.VaryByWeightPrefix ? QuoteType.VaryByWeight : QuoteType.VaryByPrice;
     RateTable = rateTable;
 }
Ejemplo n.º 4
0
        /// <summary>
        /// Deletes a <see cref="IShipMethod"/>
        /// </summary>
        /// <param name="shipMethod">The <see cref="IShipMethod"/> to delete</param>
        /// <param name="raiseEvents">Optional boolean indicating whether or not to raise events</param>
        public void Delete(IShipMethod shipMethod, bool raiseEvents = true)
        {
            if (raiseEvents)
            {
                if (Deleting.IsRaisedEventCancelled(new DeleteEventArgs <IShipMethod>(shipMethod), this))
                {
                    ((ShipMethod)shipMethod).WasCancelled = true;
                    return;
                }
            }

            using (new WriteLock(Locker))
            {
                var uow = UowProvider.GetUnitOfWork();
                using (var repository = RepositoryFactory.CreateShipMethodRepository(uow))
                {
                    repository.Delete(shipMethod);
                    uow.Commit();
                }
            }

            if (raiseEvents)
            {
                Deleted.RaiseEvent(new DeleteEventArgs <IShipMethod>(shipMethod), this);
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Initializes a new instance of the <see cref="FoaShippingGatewayMethod"/> class.
        /// </summary>
        /// <param name="gatewayResource">
        /// The gateway resource.
        /// </param>
        /// <param name="shipMethod">
        /// The ship method.
        /// </param>
        /// <param name="shipCountry">
        /// The ship country.
        /// </param>
        /// <param name="gatewayProviderSettings">
        /// The gateway provider settings.
        /// </param>
        public FoaShippingGatewayMethod(IGatewayResource gatewayResource, IShipMethod shipMethod, IShipCountry shipCountry, IGatewayProviderSettings gatewayProviderSettings) :
            base(gatewayResource, shipMethod, shipCountry)
        {
            _processorSettings = gatewayProviderSettings.ExtendedData.GetProcessorSettings();

            _shipMethod = shipMethod;
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Value to pass to the notification monitors
        /// </summary>
        /// <param name="model">
        /// The model.
        /// </param>
        /// <param name="contacts">
        /// An additional list of contacts
        /// </param>
        protected override void Notify(IPaymentResult model, IEnumerable <string> contacts)
        {
            var         symbol     = string.Empty;
            IShipment   shipment   = null;
            IShipMethod shipMethod = null;

            if (model.Invoice != null)
            {
                if (model.Invoice.Items.Any())
                {
                    var currencyCode =
                        model.Invoice.Items.First().ExtendedData.GetValue(Core.Constants.ExtendedDataKeys.CurrencyCode);
                    var currency = _storeSettingService.GetCurrencyByCode(currencyCode);
                    symbol = currency.Symbol;
                }


                // get shipping information if any

                var shippingLineItems = model.Invoice.ShippingLineItems().ToArray();
                if (shippingLineItems.Any())
                {
                    // just use the first one
                    shipment = shippingLineItems.First().ExtendedData.GetShipment <InvoiceLineItem>();

                    // get the shipmethod information
                    if (shipment != null && shipment.ShipMethodKey.HasValue)
                    {
                        shipMethod = _shipMethodService.GetByKey(shipment.ShipMethodKey.Value);
                    }
                }
            }

            NotifyMonitors(model.ToOrderConfirmationNotification(contacts, shipment, shipMethod, symbol));
        }
Ejemplo n.º 7
0
 public FixedRateShippingGatewayMethod(IGatewayResource gatewayResource, IShipMethod shipMethod, IShipCountry shipCountry, IShippingFixedRateTable rateTable)
     : base(gatewayResource, shipMethod, shipCountry)
 {
     RateTable  = new ShippingFixedRateTable(shipMethod.Key);
     _quoteType = GatewayResource.ServiceCode == FixedRateShippingGatewayProvider.VaryByWeightPrefix ? QuoteType.VaryByWeight : QuoteType.VaryByPrice;
     RateTable  = rateTable;
 }
Ejemplo n.º 8
0
        public Attempt<IShipmentRateQuote> CalculatePrice(IShipment shipment, IShipMethod shipMethod, decimal totalWeight, IShipProvince province)
        {
            // First sum up the total weight for the shipment.
            // We're assumning that a custom order line property 
            // was set on the order line prior when the product was added to the order line.

            var shippingPrice = 0M;
            try
            {
                var http = new UpsHttpRequestHandler();
                var rateXml = http.Post(RateRequest(shipment, totalWeight));

                var collection = UpsParseRates(rateXml);

                var firstCarrierRate = collection.FirstOrDefault(option => option.Service == shipMethod.Name);
                if (firstCarrierRate != null)
                    shippingPrice = firstCarrierRate.Rate;
            }
            catch (Exception ex)
            {
                return Attempt<IShipmentRateQuote>.Fail(
                        new Exception("An error occured during your request : " +
                                                     ex.Message +
                                                     " Please contact your administrator or try again."));
            }

            return Attempt<IShipmentRateQuote>.Succeed(new ShipmentRateQuote(shipment, shipMethod) { Rate = shippingPrice });
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Initializes a new instance of the <see cref="FoaShippingGatewayMethod"/> class.
        /// </summary>
        /// <param name="gatewayResource">
        /// The gateway resource.
        /// </param>
        /// <param name="shipMethod">
        /// The ship method.
        /// </param>
        /// <param name="shipCountry">
        /// The ship country.
        /// </param>
        /// <param name="gatewayProviderSettings">
        /// The gateway provider settings.
        /// </param>
        public FoaShippingGatewayMethod(IGatewayResource gatewayResource, IShipMethod shipMethod, IShipCountry shipCountry, IGatewayProviderSettings gatewayProviderSettings) : 
            base(gatewayResource, shipMethod, shipCountry)
        {
            _processorSettings = gatewayProviderSettings.ExtendedData.GetProcessorSettings();

            _shipMethod = shipMethod;
        }
 public static IShipMethod MockSavedWithKey(this IShipMethod entity, Guid key)
 {
     entity.Key = key;
     ((Entity)entity).AddingEntity();
     entity.ResetDirtyProperties();
     return(entity);
 }
Ejemplo n.º 11
0
 public FedExShippingGatewayMethod(IGatewayResource gatewayResource, IShipMethod shipMethod, IShipCountry shipCountry, IGatewayProviderSettings gatewayProviderSettings, IRuntimeCacheProvider runtimeCacheProvider)
     : base(gatewayResource, shipMethod, shipCountry)
 {
     _processor = new FedExShippingProcessor(gatewayProviderSettings.ExtendedData.GetProcessorSettings());
     _gatewayProviderSettings = gatewayProviderSettings;
     _shipMethod   = shipMethod;
     _runtimeCache = runtimeCacheProvider;
 }
Ejemplo n.º 12
0
 public FedExShippingGatewayMethod(IGatewayResource gatewayResource, IShipMethod shipMethod, IShipCountry shipCountry, IGatewayProviderSettings gatewayProviderSettings, IRuntimeCacheProvider runtimeCacheProvider)
     : base(gatewayResource, shipMethod, shipCountry)
 {
     _processor = new FedExShippingProcessor(gatewayProviderSettings.ExtendedData.GetProcessorSettings());
     _gatewayProviderSettings = gatewayProviderSettings;
     _shipMethod = shipMethod;
     _runtimeCache = runtimeCacheProvider;
 }
Ejemplo n.º 13
0
        /// <summary>
        /// Replaces shipmethod values.
        /// </summary>
        /// <param name="shipMethod">
        /// The ship method.
        /// </param>
        /// <returns>
        /// The <see cref="IEnumerable{IReplaceablePattern}"/>.
        /// </returns>
        internal static IEnumerable <IReplaceablePattern> ReplaceablePatterns(this IShipMethod shipMethod)
        {
            var patterns = new List <IReplaceablePattern>
            {
                ReplaceablePattern.GetConfigurationReplaceablePattern("ShipMethodName", shipMethod.Name),
            };

            return(patterns);
        }
Ejemplo n.º 14
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ShippingGatewayMethodBase"/> class.
        /// </summary>
        /// <param name="gatewayResource">
        /// The gateway resource.
        /// </param>
        /// <param name="shipMethod">
        /// The ship method.
        /// </param>
        /// <param name="shipCountry">
        /// The ship country.
        /// </param>
        protected ShippingGatewayMethodBase(IGatewayResource gatewayResource, IShipMethod shipMethod, IShipCountry shipCountry)
        {
            Mandate.ParameterNotNull(gatewayResource, "gatewayResource");
            Mandate.ParameterNotNull(shipMethod, "shipMethod");
            Mandate.ParameterNotNull(shipCountry, "shipCountry");

            _gatewayResource = gatewayResource;
            _shipMethod      = shipMethod;
            _shipCountry     = shipCountry;
        }
Ejemplo n.º 15
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ShippingGatewayMethodBase"/> class.
        /// </summary>
        /// <param name="gatewayResource">
        /// The gateway resource.
        /// </param>
        /// <param name="shipMethod">
        /// The ship method.
        /// </param>
        /// <param name="shipCountry">
        /// The ship country.
        /// </param>
        protected ShippingGatewayMethodBase(IGatewayResource gatewayResource, IShipMethod shipMethod, IShipCountry shipCountry)
        {
            Mandate.ParameterNotNull(gatewayResource, "gatewayResource");
            Mandate.ParameterNotNull(shipMethod, "shipMethod");
            Mandate.ParameterNotNull(shipCountry, "shipCountry");

            _gatewayResource = gatewayResource;
            _shipMethod = shipMethod;
            _shipCountry = shipCountry;
        }
Ejemplo n.º 16
0
        public ShipmentRateQuote(IShipment shipment, IShipMethod shipMethod, ExtendedDataCollection extendedData)
        {
            Mandate.ParameterNotNull(shipment, "shipment");
            Mandate.ParameterNotNull(shipMethod, "shipMethod");
            Mandate.ParameterNotNull(extendedData, "extendedData");

            shipment.ShipMethodKey = shipMethod.Key;

            Shipment     = shipment;
            ShipMethod   = shipMethod;
            ExtendedData = extendedData;
        }
Ejemplo n.º 17
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ShipmentRateQuote"/> class.
        /// </summary>
        /// <param name="shipment">
        /// The shipment.
        /// </param>
        /// <param name="shipMethod">
        /// The ship method.
        /// </param>
        /// <param name="extendedData">
        /// The extended data.
        /// </param>
        public ShipmentRateQuote(IShipment shipment, IShipMethod shipMethod, ExtendedDataCollection extendedData)
        {
            Mandate.ParameterNotNull(shipment, "shipment");
            Mandate.ParameterNotNull(shipMethod, "shipMethod");
            Mandate.ParameterNotNull(extendedData, "extendedData");

            shipment.ShipMethodKey = shipMethod.Key;

            Shipment = shipment;
            ShipMethod = shipMethod;
            ExtendedData = extendedData;
        }
Ejemplo n.º 18
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SampleShippingGatewayMethod"/> class.
 /// </summary>
 /// <param name="gatewayResource">
 /// The gateway resource.
 /// </param>
 /// <param name="shipMethod">
 /// The <see cref="IShipMethod"/>.
 /// </param>
 /// <param name="shipCountry">
 /// The <see cref="IShipCountry"/>.
 /// </param>
 /// <remarks>
 /// IShipMethod should really be named IShipMethodSettings as it is the configuration saved to the
 /// database of for the ShippingGatewayMethod.
 /// </remarks>
 public SampleShippingGatewayMethod(IGatewayResource gatewayResource, IShipMethod shipMethod, IShipCountry shipCountry)
     : base(gatewayResource, shipMethod, shipCountry)
 {
     // this is pretty brittle as it requires the AppSetting be defined
     try
     {
         _isHeavyShippingRate = decimal.Parse(WebConfigurationManager.AppSettings["SampleShipProvider:HeavyShippingCharge"]);
     }
     catch
     {
         _isHeavyShippingRate = 30M;
     }
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="SampleShippingGatewayMethod"/> class.
 /// </summary>
 /// <param name="gatewayResource">
 /// The gateway resource.
 /// </param>
 /// <param name="shipMethod">
 /// The <see cref="IShipMethod"/>.
 /// </param>
 /// <param name="shipCountry">
 /// The <see cref="IShipCountry"/>.
 /// </param>
 /// <remarks>
 /// IShipMethod should really be named IShipMethodSettings as it is the configuration saved to the
 /// database of for the ShippingGatewayMethod.
 /// </remarks>
 public SampleShippingGatewayMethod(IGatewayResource gatewayResource, IShipMethod shipMethod, IShipCountry shipCountry)
     : base(gatewayResource, shipMethod, shipCountry)
 {
     // this is pretty brittle as it requires the AppSetting be defined
     try
     {
         _isHeavyShippingRate = decimal.Parse(WebConfigurationManager.AppSettings["SampleShipProvider:HeavyShippingCharge"]);
     }
     catch
     {
         _isHeavyShippingRate = 30M;
     }
 }
Ejemplo n.º 20
0
        public UspsShippingGatewayMethod(IGatewayResource gatewayResource, IShipMethod shipMethod, IShipCountry shipCountry, IGatewayProviderSettings gatewayProviderSettings, IRuntimeCacheProvider runtimeCache) : 
            base(gatewayResource, shipMethod, shipCountry)
        {
            _processorSettings = gatewayProviderSettings.ExtendedData.GetProcessorSettings();
            _shipMethod = shipMethod;
            _runtimeCache = runtimeCache;
            _gatewayProviderSettings = gatewayProviderSettings;

            // Express Mail Hold For Pickup
            ServiceLookup[2] = new[] { new UspsDeliveryOption(2, Decimal.MaxValue, Decimal.MaxValue, Decimal.MaxValue, 108, 70) };

            // Express Mail Flat-Rate Envelope Hold For Pickup
            ServiceLookup[27] = new[] { new UspsDeliveryOption(27, 12.5M, 9.5M, 0.75M, Decimal.MaxValue, 70) };

            // Express Mail
            ServiceLookup[3] = new[] { new UspsDeliveryOption(3, Decimal.MaxValue, Decimal.MaxValue, Decimal.MaxValue, 108, 70) };

            // Express Mail Flat-Rate Envelope
            ServiceLookup[13] = new[] { new UspsDeliveryOption(13, 12.5M, 9.5M, 0.75M, Decimal.MaxValue, 70) };

            // Priority Mail
            ServiceLookup[1] = new[] { new UspsDeliveryOption(1, Decimal.MaxValue, Decimal.MaxValue, Decimal.MaxValue, 108, 70) };

            // Priority Mail Flat-Rate Envelope
            ServiceLookup[16] = new[] { new UspsDeliveryOption(16, 12.5M, 9.5M, 0.75M, Decimal.MaxValue, 70) };

            // Priority Mail Small Flat-Rate Box
            ServiceLookup[28] = new[] { new UspsDeliveryOption(28, 5.375M, 8.625M, 1.675M, Decimal.MaxValue, 70) };

            // Priority Mail Regular/Medium Flat-Rate Boxes
            ServiceLookup[17] = new[]
                                    {
                                        new UspsDeliveryOption(17, 11.875M, 13.625M, 3.375M, Decimal.MaxValue, 70),
                                        new UspsDeliveryOption(17, 11M, 8.5M, 5.5M, Decimal.MaxValue, 70)
                                    };

            // Priority Mail Large Flat-Rate Box
            ServiceLookup[22] = new[] { new UspsDeliveryOption(22, 12, 12, 5.5M, Decimal.MaxValue, 70) };

            // Parcel Post
            ServiceLookup[4] = new[] { new UspsDeliveryOption(4, Decimal.MaxValue, Decimal.MaxValue, Decimal.MaxValue, 108, 70) };

            // Bound Printed Matter
            ServiceLookup[5] = new[] { new UspsDeliveryOption(5, Decimal.MaxValue, Decimal.MaxValue, Decimal.MaxValue, 108, 70) };

            // Media Mail
            ServiceLookup[6] = new[] { new UspsDeliveryOption(6, Decimal.MaxValue, Decimal.MaxValue, Decimal.MaxValue, 108, 70) };

            // Library Mail
            ServiceLookup[7] = new[] { new UspsDeliveryOption(7, Decimal.MaxValue, Decimal.MaxValue, Decimal.MaxValue, 108, 70) };
        }
Ejemplo n.º 21
0
        public UspsShippingGatewayMethod(IGatewayResource gatewayResource, IShipMethod shipMethod, IShipCountry shipCountry, IGatewayProviderSettings gatewayProviderSettings, IRuntimeCacheProvider runtimeCache) :
            base(gatewayResource, shipMethod, shipCountry)
        {
            _processorSettings       = gatewayProviderSettings.ExtendedData.GetProcessorSettings();
            _shipMethod              = shipMethod;
            _runtimeCache            = runtimeCache;
            _gatewayProviderSettings = gatewayProviderSettings;

            // Express Mail Hold For Pickup
            ServiceLookup[2] = new[] { new UspsDeliveryOption(2, Decimal.MaxValue, Decimal.MaxValue, Decimal.MaxValue, 108, 70) };

            // Express Mail Flat-Rate Envelope Hold For Pickup
            ServiceLookup[27] = new[] { new UspsDeliveryOption(27, 12.5M, 9.5M, 0.75M, Decimal.MaxValue, 70) };

            // Express Mail
            ServiceLookup[3] = new[] { new UspsDeliveryOption(3, Decimal.MaxValue, Decimal.MaxValue, Decimal.MaxValue, 108, 70) };

            // Express Mail Flat-Rate Envelope
            ServiceLookup[13] = new[] { new UspsDeliveryOption(13, 12.5M, 9.5M, 0.75M, Decimal.MaxValue, 70) };

            // Priority Mail
            ServiceLookup[1] = new[] { new UspsDeliveryOption(1, Decimal.MaxValue, Decimal.MaxValue, Decimal.MaxValue, 108, 70) };

            // Priority Mail Flat-Rate Envelope
            ServiceLookup[16] = new[] { new UspsDeliveryOption(16, 12.5M, 9.5M, 0.75M, Decimal.MaxValue, 70) };

            // Priority Mail Small Flat-Rate Box
            ServiceLookup[28] = new[] { new UspsDeliveryOption(28, 5.375M, 8.625M, 1.675M, Decimal.MaxValue, 70) };

            // Priority Mail Regular/Medium Flat-Rate Boxes
            ServiceLookup[17] = new[]
            {
                new UspsDeliveryOption(17, 11.875M, 13.625M, 3.375M, Decimal.MaxValue, 70),
                new UspsDeliveryOption(17, 11M, 8.5M, 5.5M, Decimal.MaxValue, 70)
            };

            // Priority Mail Large Flat-Rate Box
            ServiceLookup[22] = new[] { new UspsDeliveryOption(22, 12, 12, 5.5M, Decimal.MaxValue, 70) };

            // Parcel Post
            ServiceLookup[4] = new[] { new UspsDeliveryOption(4, Decimal.MaxValue, Decimal.MaxValue, Decimal.MaxValue, 108, 70) };

            // Bound Printed Matter
            ServiceLookup[5] = new[] { new UspsDeliveryOption(5, Decimal.MaxValue, Decimal.MaxValue, Decimal.MaxValue, 108, 70) };

            // Media Mail
            ServiceLookup[6] = new[] { new UspsDeliveryOption(6, Decimal.MaxValue, Decimal.MaxValue, Decimal.MaxValue, 108, 70) };

            // Library Mail
            ServiceLookup[7] = new[] { new UspsDeliveryOption(7, Decimal.MaxValue, Decimal.MaxValue, Decimal.MaxValue, 108, 70) };
        }
Ejemplo n.º 22
0
 /// <summary>
 /// The to order confirmation notification.
 /// </summary>
 /// <param name="paymentResult">
 /// The payment result.
 /// </param>
 /// <param name="contacts">
 /// The contacts.
 /// </param>
 /// <param name="shipment">
 /// The shipment.
 /// </param>
 /// <param name="shipMethod">
 /// The ship Method.
 /// </param>
 /// <param name="currencySymbol">
 /// The currency Symbol.
 /// </param>
 /// <returns>
 /// The <see cref="IPaymentResultMonitorModel"/>.
 /// </returns>
 public static IPaymentResultMonitorModel ToOrderConfirmationNotification(this IPaymentResult paymentResult, IEnumerable<string> contacts, IShipment shipment = null, IShipMethod shipMethod = null, string currencySymbol = "")
 {
     return new PaymentResultNotifyModel()
         {
             PaymentSuccess = paymentResult.Payment.Success,
             Payment = paymentResult.Payment.Success ? paymentResult.Payment.Result : null,
             Invoice = paymentResult.Invoice,
             Contacts = contacts.ToArray(),
             Shipment = shipment,
             ShipMethod = shipMethod,
             CurrencySymbol = currencySymbol,
             ApproveOrderCreation = paymentResult.ApproveOrderCreation
         };
 }
Ejemplo n.º 23
0
        public Attempt <IShipmentRateQuote> CalculatePrice(IShipment shipment, IShipMethod shipMethod, decimal totalWeight, int quantity, IShipProvince province)
        {
            // First sum up the total weight for the shipment.
            // We're assumning that a custom order line property
            // was set on the order line prior when the product was added to the order line.

            var shippingPrice = 0M;

            try
            {
                var service = new RateService {
                    Url = "https://wsbeta.fedex.com:443/web-services/rate"
                };

                var reply = service.getRates(RateRequest(shipment, totalWeight, quantity));

                if (reply.HighestSeverity == NotificationSeverityType.SUCCESS || reply.HighestSeverity == NotificationSeverityType.NOTE || reply.HighestSeverity == NotificationSeverityType.WARNING)
                {
                    var collection = BuildDeliveryOptions(reply, shipment);

                    var firstCarrierRate = collection.FirstOrDefault(option => option.Service.Contains(shipMethod.ServiceCode.Split('-').First()));
                    if (firstCarrierRate != null)
                    {
                        shippingPrice = firstCarrierRate.Rate;
                    }
                }
            }
            catch (Exception ex)
            {
                return(Attempt <IShipmentRateQuote> .Fail(
                           new Exception("An error occured during your request : " +
                                         ex.Message +
                                         " Please contact your administrator or try again.")));
            }

            return(Attempt <IShipmentRateQuote> .Succeed(new ShipmentRateQuote(shipment, shipMethod) { Rate = shippingPrice }));
        }
Ejemplo n.º 24
0
 /// <summary>
 /// Saves a single <see cref="IShipMethod"/>
 /// </summary>
 /// <param name="shipMethod"></param>
 public void Save(IShipMethod shipMethod)
 {
     _shipMethodService.Save(shipMethod);
 }
Ejemplo n.º 25
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ShipmentRateQuote"/> class.
 /// </summary>
 /// <param name="shipment">
 /// The shipment.
 /// </param>
 /// <param name="shipMethod">
 /// The ship method.
 /// </param>
 public ShipmentRateQuote(IShipment shipment, IShipMethod shipMethod)
     : this(shipment, shipMethod, new ExtendedDataCollection())
 {            
 }
Ejemplo n.º 26
0
 public FixedRateShippingGatewayMethod(IGatewayResource gatewayResource, IShipMethod shipMethod, IShipCountry shipCountry)
     : this(gatewayResource, shipMethod, shipCountry, new ShippingFixedRateTable(shipMethod.Key))
 {
 }
Ejemplo n.º 27
0
 /// <summary>
 /// The to order confirmation notification.
 /// </summary>
 /// <param name="paymentResult">
 /// The payment result.
 /// </param>
 /// <param name="contacts">
 /// The contacts.
 /// </param>
 /// <param name="shipment">
 /// The shipment.
 /// </param>
 /// <param name="shipMethod">
 /// The ship Method.
 /// </param>
 /// <param name="currencySymbol">
 /// The currency Symbol.
 /// </param>
 /// <returns>
 /// The <see cref="IPaymentResultMonitorModel"/>.
 /// </returns>
 public static IPaymentResultMonitorModel ToOrderConfirmationNotification(this IPaymentResult paymentResult, IEnumerable <string> contacts, IShipment shipment = null, IShipMethod shipMethod = null, string currencySymbol = "")
 {
     return(new PaymentResultNotifyModel()
     {
         PaymentSuccess = paymentResult.Payment.Success,
         Payment = paymentResult.Payment.Success ? paymentResult.Payment.Result : null,
         Invoice = paymentResult.Invoice,
         Contacts = contacts.ToArray(),
         Shipment = shipment,
         ShipMethod = shipMethod,
         CurrencySymbol = currencySymbol,
         ApproveOrderCreation = paymentResult.ApproveOrderCreation
     });
 }
 public UPSShippingGatewayMethod(IGatewayResource gatewayResource, IShipMethod shipMethod, IShipCountry shipCountry, ExtendedDataCollection providerExtendedData)
     : base(gatewayResource, shipMethod, shipCountry)
 {
     _processor  = new UpsShippingProcessor(providerExtendedData.GetProcessorSettings());
     _shipMethod = shipMethod;
 }
        internal static IShipMethod ToShipMethod(this ShipMethodDisplay shipMethodDisplay, IShipMethod destination)
        {
            if (shipMethodDisplay.Key != Guid.Empty)
            {
                destination.Key = shipMethodDisplay.Key;
            }
            destination.Name        = shipMethodDisplay.Name;
            destination.ServiceCode = shipMethodDisplay.ServiceCode;
            destination.Surcharge   = shipMethodDisplay.Surcharge;
            destination.Taxable     = shipMethodDisplay.Taxable;

            foreach (var shipProvinceDisplay in shipMethodDisplay.Provinces)
            {
                IShipProvince destinationShipProvince;

                var matchingItems = destination.Provinces.Where(x => x.Code == shipProvinceDisplay.Code);
                var shipProvinces = matchingItems as IShipProvince[] ?? matchingItems.ToArray();
                if (shipProvinces.Any())
                {
                    var existingShipProvince = shipProvinces.First();
                    if (existingShipProvince != null)
                    {
                        destinationShipProvince = existingShipProvince;

                        destinationShipProvince = shipProvinceDisplay.ToShipProvince(destinationShipProvince);
                    }
                }
            }

            return(destination);
        }
 internal static ShipMethodDisplay ToShipMethodDisplay(this IShipMethod shipMethod)
 {
     return(AutoMapper.Mapper.Map <ShipMethodDisplay>(shipMethod));
 }
Ejemplo n.º 31
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ShipmentRateQuote"/> class.
 /// </summary>
 /// <param name="shipment">
 /// The shipment.
 /// </param>
 /// <param name="shipMethod">
 /// The ship method.
 /// </param>
 public ShipmentRateQuote(IShipment shipment, IShipMethod shipMethod)
     : this(shipment, shipMethod, new ExtendedDataCollection())
 {
 }
Ejemplo n.º 32
0
 public UPSShippingGatewayMethod(IGatewayResource gatewayResource, IShipMethod shipMethod, IShipCountry shipCountry, ExtendedDataCollection providerExtendedData)
     : base(gatewayResource, shipMethod, shipCountry)
 {
     _processor = new UpsShippingProcessor(providerExtendedData.GetProcessorSettings());
     _shipMethod = shipMethod;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="FixedRateShippingGatewayMethod"/> class.
 /// </summary>
 /// <param name="gatewayResource">
 /// The gateway resource.
 /// </param>
 /// <param name="shipMethod">
 /// The ship method.
 /// </param>
 /// <param name="shipCountry">
 /// The ship country.
 /// </param>
 public FixedRateShippingGatewayMethod(IGatewayResource gatewayResource, IShipMethod shipMethod, IShipCountry shipCountry)
     : this(gatewayResource, shipMethod, shipCountry, new ShippingFixedRateTable(shipMethod.Key))
 {
 }
Ejemplo n.º 34
0
        /// <summary>
        /// Deletes a <see cref="IShipMethod"/>
        /// </summary>
        /// <param name="shipMethod">The <see cref="IShipMethod"/> to delete</param>
        /// <param name="raiseEvents">Optional boolean indicating whether or not to raise events</param>
        public void Delete(IShipMethod shipMethod, bool raiseEvents = true)
        {
            if(raiseEvents)
            if (Deleting.IsRaisedEventCancelled(new DeleteEventArgs<IShipMethod>(shipMethod), this))
            {
                ((ShipMethod) shipMethod).WasCancelled = true;
                return;
            }

            using (new WriteLock(Locker))
            {
                var uow = _uowProvider.GetUnitOfWork();
                using (var repository = _repositoryFactory.CreateShipMethodRepository(uow))
                {
                    repository.Delete(shipMethod);
                    uow.Commit();
                }
            }

            if(raiseEvents) Deleted.RaiseEvent(new DeleteEventArgs<IShipMethod>(shipMethod), this);
        }
Ejemplo n.º 35
0
 /// <summary>
 /// Deletes a <see cref="IShipMethod"/>
 /// </summary>
 /// <param name="shipMethod"></param>
 public void Delete(IShipMethod shipMethod)
 {
     _shipMethodService.Delete(shipMethod);
 }
Ejemplo n.º 36
0
 /// <summary>
 /// Saves a single <see cref="IShipMethod"/>
 /// </summary>
 /// <param name="shipMethod"></param>
 public void Save(IShipMethod shipMethod)
 {
     _shipMethodService.Save(shipMethod);
 }
        internal static IShipMethod ToShipMethod(this ShipMethodDisplay shipMethodDisplay, IShipMethod destination)
        {
            if (shipMethodDisplay.Key != Guid.Empty)
            {
                destination.Key = shipMethodDisplay.Key;
            }
            destination.Name = shipMethodDisplay.Name;
            destination.ServiceCode = shipMethodDisplay.ServiceCode;
            destination.Surcharge = shipMethodDisplay.Surcharge;
            destination.Taxable = shipMethodDisplay.Taxable;

            foreach (var shipProvinceDisplay in shipMethodDisplay.Provinces)
            {
                IShipProvince destinationShipProvince;

                var matchingItems = destination.Provinces.Where(x => x.Code == shipProvinceDisplay.Code);
                var shipProvinces = matchingItems as IShipProvince[] ?? matchingItems.ToArray();
                if (shipProvinces.Any())
                {
                    var existingShipProvince = shipProvinces.First();
                    if (existingShipProvince != null)
                    {
                        destinationShipProvince = existingShipProvince;

                        destinationShipProvince = shipProvinceDisplay.ToShipProvince(destinationShipProvince);
                    }
                }
            }

            return destination;
        }
Ejemplo n.º 38
0
 /// <summary>
 /// Deletes a <see cref="IShipMethod"/>
 /// </summary>
 /// <param name="shipMethod"></param>
 public void Delete(IShipMethod shipMethod)
 {
     _shipMethodService.Delete(shipMethod);
 }