コード例 #1
0
ファイル: Fedex.cs プロジェクト: janiukjf/API
        private static RateRequest CreateRateRequest(FedExAuthentication auth)
        {
            // Build a RateRequest
            RateRequest req = new RateRequest();

            req.WebAuthenticationDetail = new WebAuthenticationDetail();
            req.WebAuthenticationDetail.UserCredential = new WebAuthenticationCredential();
            req.WebAuthenticationDetail.UserCredential.Key = auth.Key;
            req.WebAuthenticationDetail.UserCredential.Password = auth.Password;

            req.ClientDetail = new ClientDetail();
            req.ClientDetail.AccountNumber = auth.AccountNumber.ToString();
            req.ClientDetail.MeterNumber = auth.MeterNumber.ToString();

            req.TransactionDetail = new TransactionDetail();
            req.TransactionDetail.CustomerTransactionId = (auth.CustomerTransactionId != null) ? auth.CustomerTransactionId : "***Rate v10 Request using VC#***";

            req.Version = new VersionId();

            req.ReturnTransitAndCommit = true;
            req.ReturnTransitAndCommitSpecified = true;

            SetShipmentDetails(req);

            return req;
        }
コード例 #2
0
ファイル: Fedex.cs プロジェクト: janiukjf/API
        private static void ValidateXML()
        {
            try {
                string origin = HttpContext.Current.Request.Form["origin"];
                string destination = HttpContext.Current.Request.Form["destination"];
                string parts = HttpContext.Current.Request.Form["parts"];
                string auth = HttpContext.Current.Request.Form["auth"];
                string environment = HttpContext.Current.Request.Form["environment"];

                // Validate required fields
                if (origin == null || destination == null || parts == null || auth == null) {
                    throw new Exception();
                }
                if (environment != null) {
                    try {
                        _environment = environment;
                    } catch {  }
                }
                try {
                    XmlSerializer addressSerializer = new XmlSerializer(typeof(Address));
                    XmlSerializer partsSerializer = new XmlSerializer(typeof(List<int>));
                    XmlSerializer authSerializer = new XmlSerializer(typeof(FedExAuthentication));
                    _origin = (Address)addressSerializer.Deserialize(new StringReader(origin));
                    _destination = (Address)addressSerializer.Deserialize(new StringReader(destination));
                    _parts = (List<int>)partsSerializer.Deserialize(new StringReader(parts));
                    _auth = (FedExAuthentication)authSerializer.Deserialize(new StringReader(auth));
                } catch (Exception) { throw new Exception(); }

                // Parse out optional fields, hopefully without breaking anything
                try {
                    _customer = Convert.ToInt32(HttpContext.Current.Request.Form["customer"]);
                } catch (Exception) { }
                try {
                    _shipType = HttpContext.Current.Request.Form["shipment-type"];
                } catch (Exception) { }
                try {
                    _packageType = HttpContext.Current.Request.Form["package-type"];
                } catch (Exception) { }
                try {
                    _insure = Convert.ToBoolean(HttpContext.Current.Request.Form["insure"]);
                } catch (Exception) { }
                try {
                    _insureAmount = Convert.ToDecimal(HttpContext.Current.Request.Form["insure-amount"]);
                } catch (Exception) { }
                try {
                    _packageCount = Convert.ToInt32(HttpContext.Current.Request.Form["package-count"]);
                } catch (Exception) { }
            } catch (Exception) {
                throw new Exception("INVALID_REQUEST");
            }
        }
コード例 #3
0
ファイル: OrderingController.cs プロジェクト: janiukjf/API
 public void GenerateXMLAuth()
 {
     XmlSerializer ser = new XmlSerializer(typeof(FedExAuthentication));
     FedExAuthentication auth = new FedExAuthentication();
     StringWriter xml = new StringWriter();
     ser.Serialize(xml, auth);
     Response.ContentType = "text/xml";
     Response.Write(xml);
     Response.End();
 }