Example #1
0
        public List <ShippingOption> GetShippingOptions()
        {
            try
            {
                _weight = MeasureUnits.ConvertWeight(ShoppingCart.TotalShippingWeight, MeasureUnits.WeightUnit.Kilogramm, MeasureUnits.WeightUnit.Pound);

                _isDomenic = CountryToIso2.ToUpper().Trim() == "US";
                return(GetShippingOption());
            }
            catch (Exception ex)
            {
                Debug.LogError(ex);
                return(new List <ShippingOption>());
            }
        }
Example #2
0
 public decimal GetRate(decimal weight, MeasureUnits.WeightUnit unit)
 {
     return(GetRate(MeasureUnits.ConvertWeight(weight, unit, MeasureUnits.WeightUnit.Kilogramm)));
 }
Example #3
0
        private RateRequest CreateRateRequest(RateService rate)
        {
            RateRequest rateRequest = new RateRequest();
            UPSSecurity upss        = new UPSSecurity();
            UPSSecurityServiceAccessToken upssSvcAccessToken = new UPSSecurityServiceAccessToken();

            upssSvcAccessToken.AccessLicenseNumber = AccessKey;
            upss.ServiceAccessToken = upssSvcAccessToken;

            UPSSecurityUsernameToken upssUsrNameToken = new UPSSecurityUsernameToken();

            upssUsrNameToken.Username = UserName;
            upssUsrNameToken.Password = Password;
            upss.UsernameToken        = upssUsrNameToken;
            rate.UPSSecurityValue     = upss;

            RequestType request = new RequestType();

            String[] requestOption = { "Shop" };
            request.RequestOption = requestOption;
            rateRequest.Request   = request;

            ShipmentType shipment = new ShipmentType();

            ShipperType shipper = new ShipperType();
            //shipper.ShipperNumber = "ISUS01";
            AddressType shipperAddress = new AddressType();

            String[] addressLine = { "Shipper\'s address line" };
            shipperAddress.AddressLine = addressLine;
            shipperAddress.City        = "Shipper\'s city";
            shipperAddress.PostalCode  = PostalCodeFrom;
            //shipperAddress.StateProvinceCode = UpsItem.CountryCode;
            shipperAddress.CountryCode = CountryCodeFrom;
            shipperAddress.AddressLine = addressLine;
            shipper.Address            = shipperAddress;
            shipment.Shipper           = shipper;

            ShipFromType shipFrom        = new ShipFromType();
            AddressType  shipFromAddress = new AddressType();

            shipFromAddress.AddressLine = addressLine;
            shipFromAddress.City        = "ShipFrom city";
            shipFromAddress.PostalCode  = PostalCodeFrom;
            //shipFromAddress.StateProvinceCode = "GA";
            shipFromAddress.CountryCode = CountryCodeFrom;
            shipFrom.Address            = shipFromAddress;
            shipment.ShipFrom           = shipFrom;

            ShipToType        shipTo        = new ShipToType();
            ShipToAddressType shipToAddress = new ShipToAddressType();

            String[] addressLine1 = { AddressTo };
            shipToAddress.AddressLine       = addressLine1;
            shipToAddress.City              = CityTo;
            shipToAddress.PostalCode        = PostalCodeTo;
            shipToAddress.StateProvinceCode = StateTo;
            shipToAddress.CountryCode       = CountryCodeTo;
            shipTo.Address  = shipToAddress;
            shipment.ShipTo = shipTo;

            //CodeDescriptionType service = new CodeDescriptionType();
            //service.Code = "02";
            //shipment.Service = service;
            float weight = MeasureUnits.ConvertWeight(ShoppingCart.TotalShippingWeight, MeasureUnits.WeightUnit.Kilogramm, MeasureUnits.WeightUnit.Pound);

            var data = new List <PackageType>();

            if (!IsPackageTooHeavy(weight))
            {
                PackageType       package       = new PackageType();
                PackageWeightType packageWeight = new PackageWeightType();
                packageWeight.Weight = weight.ToString("F3").Replace(',', '.');

                CodeDescriptionType uom = new CodeDescriptionType();
                uom.Code        = "LBS";
                uom.Description = "Pounds";
                packageWeight.UnitOfMeasurement = uom;
                package.PackageWeight           = packageWeight;

                CodeDescriptionType packType = new CodeDescriptionType();
                packType.Code         = "02";
                package.PackagingType = packType;
                data.Add(package);
            }
            else
            {
                int totalPackages        = 1;
                int totalPackagesWeights = 1;
                if (IsPackageTooHeavy(weight))
                {
                    totalPackagesWeights = SQLDataHelper.GetInt(Math.Ceiling(weight / MaxPackageWeight));
                }

                totalPackages = totalPackagesWeights;
                if (totalPackages == 0)
                {
                    totalPackages = 1;
                }

                float weight2 = weight / totalPackages;

                if (weight2 < 1)
                {
                    weight2 = 1;
                }
                for (int i = 0; i < totalPackages; i++)
                {
                    PackageType       package       = new PackageType();
                    PackageWeightType packageWeight = new PackageWeightType();
                    packageWeight.Weight = weight2.ToString("F3");

                    CodeDescriptionType uom = new CodeDescriptionType();
                    uom.Code        = "LBS";
                    uom.Description = "Pounds";
                    packageWeight.UnitOfMeasurement = uom;
                    package.PackageWeight           = packageWeight;

                    CodeDescriptionType packType = new CodeDescriptionType();
                    packType.Code         = GetPackagingTypeCode(PackagingType);
                    package.PackagingType = packType;
                    data.Add(package);
                }
            }

            PackageType[] pkgArray = data.ToArray();
            shipment.Package     = pkgArray;
            rateRequest.Shipment = shipment;

            CodeDescriptionType pckup = new CodeDescriptionType()
            {
                Code = GetPickupTypeCode(PickupType)
            };

            rateRequest.PickupType = pckup;

            CodeDescriptionType ccustomer = new CodeDescriptionType()
            {
                Code = GetCustomerClassificationCode(CustomerType)
            };

            rateRequest.CustomerClassification = ccustomer;

            System.Net.ServicePointManager.CertificatePolicy = new TrustAllCertificatePolicy();

            return(rateRequest);
        }
Example #4
0
 public float GetRate(float weight, MeasureUnits.WeightUnit unit)
 {
     return(GetRate(MeasureUnits.ConvertWeight(weight, unit, MeasureUnits.WeightUnit.Kilogramm)));
 }