Exemple #1
0
        public SwedishPostalServiceShippingProvider(
            string apiKey,
            ShippingCostCalculator shippingCostCalculator,
            CustomsHandlingOptions customsHandlingOptions,
            InsuranceOptions insuranceOptions)
        {
            this.apiKey = apiKey;

            ShippingCostCalculator = shippingCostCalculator;
            CustomsHandlingOptions = customsHandlingOptions;
            InsuranceOptions       = insuranceOptions;
        }
        public AustraliaPostShippingProvider(
            string clientId,
            string secret,
            ShippingCostCalculator shippingCostCalculator,
            CustomsHandlingOptions customsHandlingOptions,
            InsuranceOptions insuranceOptions)
        {
            this.clientId = clientId;
            this.secret   = secret;

            ShippingCostCalculator = shippingCostCalculator;
            CustomsHandlingOptions = customsHandlingOptions;
            InsuranceOptions       = insuranceOptions;
        }
        // No state being kept, use static method
        // Reusable across all application
        // Use anywhere - call where needed
        public static ShippingProvider CreateShippingProvider(string country)
        {
            #region Create Shipping Provider
            ShippingProvider shippingProvider;

            if (country == "Australia")
            {
                #region Australia Post Shipping Provider
                var shippingCostCalculator = new ShippingCostCalculator(
                    internationalShippingFee: 250,
                    extraWeightFee: 500
                    )
                {
                    ShippingType = ShippingType.Standard
                };

                var customsHandlingOptions = new CustomsHandlingOptions
                {
                    TaxOptions = TaxOptions.PrePaid
                };

                var insuranceOptions = new InsuranceOptions
                {
                    ProviderHasInsurance            = false,
                    ProviderHasExtendedInsurance    = false,
                    ProviderRequiresReturnOnDamange = false
                };

                shippingProvider = new AustraliaPostShippingProvider("CLIENT_ID",
                                                                     "SECRET",
                                                                     shippingCostCalculator,
                                                                     customsHandlingOptions,
                                                                     insuranceOptions);
                #endregion
            }
            else if (country == "Sweden")
            {
                #region Swedish Postal Service Shipping Provider
                var shippingCostCalculator = new ShippingCostCalculator(
                    internationalShippingFee: 50,
                    extraWeightFee: 100
                    )
                {
                    ShippingType = ShippingType.Express
                };

                var customsHandlingOptions = new CustomsHandlingOptions
                {
                    TaxOptions = TaxOptions.PayOnArrival
                };

                var insuranceOptions = new InsuranceOptions
                {
                    ProviderHasInsurance            = true,
                    ProviderHasExtendedInsurance    = false,
                    ProviderRequiresReturnOnDamange = false
                };

                shippingProvider = new SwedishPostalServiceShippingProvider("API_KEY",
                                                                            shippingCostCalculator,
                                                                            customsHandlingOptions,
                                                                            insuranceOptions);
                #endregion
            }
            else
            {
                throw new NotSupportedException("No shipping provider found for origin country");
            }
            #endregion

            return(shippingProvider);
        }