本文介绍了如何从UPS Rate API获取费率?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用nopcommerce 3.5.我添加了TransitInTime和Rate API的UPS插件.我想通过调用UPS Rate API来获得费率.我希望页面加载下拉列表中的所有费率.

I am using nopcommerce 3.5. I have added plugin of UPS of TransitInTime and Rate API. I want to get rates by calling UPS Rate API. I want all Rates in dropdown on page load.

因此,我首先使用的是使用RateWebReference的Web服务的测试应用程序,在该应用程序中,我仅获得一个Rate,但我希望所有运输方式都可以使用Rates.

So for the first I am using test application using webservices of RateWebReference and in which I get only one Rate but I want Rates for all shipping option.

这是我的RateWSClient.cs代码

Here is my code of RateWSClient.cs

  RateService rate = new RateService();
                RateRequest rateRequest = new RateRequest();
                UPSSecurity upss = new UPSSecurity();
                UPSSecurityServiceAccessToken upssSvcAccessToken = new UPSSecurityServiceAccessToken();
                upssSvcAccessToken.AccessLicenseNumber = "CC....";
                upss.ServiceAccessToken = upssSvcAccessToken;
                UPSSecurityUsernameToken upssUsrNameToken = new UPSSecurityUsernameToken();
                upssUsrNameToken.Username = "gi..";
                upssUsrNameToken.Password = "Ch..";
                upss.UsernameToken = upssUsrNameToken;
                rate.UPSSecurityValue = upss;
                RequestType request = new RequestType();
                String[] requestOption = { "Rate" };
                request.RequestOption = requestOption;

                rateRequest.Request = request;
                ShipmentType shipment = new ShipmentType();
                ShipperType shipper = new ShipperType();

                shipper.ShipperNumber = "A65V88";
                RateWSSample.RateWebReference1.AddressType shipperAddress = new RateWSSample.RateWebReference1.AddressType();
                String[] addressLine = { "", "", "" };
                shipperAddress.AddressLine = addressLine;
                shipperAddress.City = "";
                shipperAddress.PostalCode = "30076";
                shipperAddress.StateProvinceCode = "GA";
                shipperAddress.CountryCode = "US";
                shipperAddress.AddressLine = addressLine;
                shipper.Address = shipperAddress;
                shipment.Shipper = shipper;
                ShipFromType shipFrom = new ShipFromType();
                RateWSSample.RateWebReference1.AddressType shipFromAddress = new RateWSSample.RateWebReference1.AddressType();
                shipFromAddress.AddressLine = addressLine;
                shipFromAddress.City = "";
                shipFromAddress.PostalCode = "30076";
                shipFromAddress.StateProvinceCode = "GA";
                shipFromAddress.CountryCode = "US";
                shipFrom.Address = shipFromAddress;
                shipment.ShipFrom = shipFrom;
                ShipToType shipTo = new ShipToType();
                ShipToAddressType shipToAddress = new ShipToAddressType();
                String[] addressLine1 = { "", "", "" };
                shipToAddress.AddressLine = addressLine1;
                shipToAddress.City = "";
                shipToAddress.PostalCode = "92262";
                shipToAddress.StateProvinceCode = "";
                shipToAddress.CountryCode = "US";
                shipTo.Address = shipToAddress;
                shipment.ShipTo = shipTo;
                CodeDescriptionType service = new CodeDescriptionType();

                //Below code uses dummy date for reference. Please udpate as required.
                service.Code = "02";
                shipment.Service = service;
                PackageType package = new PackageType();
                PackageWeightType packageWeight = new PackageWeightType();
                packageWeight.Weight = "125";
                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;
                PackageType[] pkgArray = { package };
                shipment.Package = pkgArray;

               //Shipping Rate Chart

               // ShipmentRatingOptionsType SRO = new ShipmentRatingOptionsType();
                //SRO.RateChartIndicator = "";
                //shipment.ShipmentRatingOptions= SRO;

                //rateRequest.Shipment = shipment;


                ShipmentRatingOptionsType SRO = new ShipmentRatingOptionsType();
                SRO.NegotiatedRatesIndicator = "";
                shipment.ShipmentRatingOptions = SRO;

                rateRequest.Shipment = shipment;

                System.Net.ServicePointManager.CertificatePolicy = new TrustAllCertificatePolicy();
                Console.WriteLine(rateRequest);
                RateResponse rateResponse = rate.ProcessRate(rateRequest);
                Console.WriteLine("The transaction was a " + rateResponse.Response.ResponseStatus.Description);
                Console.WriteLine("Total Shipment Charges " + rateResponse.RatedShipment[0].TotalCharges.MonetaryValue + rateResponse.RatedShipment[0].TotalCharges.CurrencyCode);
                Console.ReadKey();

推荐答案

我已经解决了这个问题.因此,如果您遇到此类问题,请别忘了使用

I have resolved this questions. So If you face this kind of problem don't forget to use

String[] requestOption = { "Shop" };

代替

String[] requestOption = { "Rate" };

然后,您将获得所有运输方式的费率.

Then you will get rates for all shipping options.

这篇关于如何从UPS Rate API获取费率?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 23:58