You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
573 lines
32 KiB
C#
573 lines
32 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Web.Services.Protocols;
|
|
using System.IO;
|
|
using NetLibrary.Log;
|
|
using NetLibrary.Data;
|
|
using System.Data.Common;
|
|
using System.Data;
|
|
using NetLibrary.Express;
|
|
using TradeManageNew.WebReference1;
|
|
using System.Net;
|
|
|
|
namespace TradeManageNew
|
|
{
|
|
public class FedexSmartPostNew2
|
|
{
|
|
public static string Key = "";
|
|
public static string Password = "";
|
|
public static string AccountNumber = "";
|
|
public static string MeterNumber = "";
|
|
public static string PayAccountNumber = "";
|
|
public static string PostInfo = "";
|
|
public static string HubId = "";
|
|
public static string PostName = "";
|
|
public static int IsQM = 0;
|
|
public static FedexOrder ormd = null;
|
|
public static string LBPath = "";
|
|
public FedexOrder2 GetFedex(FedexOrder md, out string Error)
|
|
{
|
|
ormd = md;
|
|
string code = "";
|
|
FedexOrder2 fmd = new FedexOrder2();
|
|
fmd.CustomerTransactionId = md.CustomerTransactionId;
|
|
|
|
ProcessShipmentRequest request = CreateShipmentRequest();
|
|
//
|
|
ShipService service = new ShipService();
|
|
service.Url = "https://ws.fedex.com:443/web-services/ship"; //"https://wsbeta.fedex.com:443/web-services";// "https://ws.fedex.com:443/web-services/ship";
|
|
if (usePropertyFile())
|
|
{
|
|
service.Url = "https://ws.fedex.com:443/web-services/ship"; // "https://wsbeta.fedex.com:443/web-services";// "https://ws.fedex.com:443/web-services/ship";// getProperty("endpoint");
|
|
}
|
|
//
|
|
|
|
try
|
|
{
|
|
// ServicePointManager.SecurityProtocol = (SecurityProtocolType)192 | (SecurityProtocolType)768 | (SecurityProtocolType)3072;
|
|
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11;
|
|
ProcessShipmentReply reply = service.processShipment(request);
|
|
if ((reply.HighestSeverity != NotificationSeverityType.ERROR) && (reply.HighestSeverity != NotificationSeverityType.FAILURE))
|
|
{
|
|
code = reply.CompletedShipmentDetail.CompletedPackageDetails[0].TrackingIds[0].TrackingNumber;
|
|
ShowShipmentReply(reply);
|
|
}
|
|
else
|
|
{
|
|
|
|
Error = ShowNotifications(reply);
|
|
ErrorFollow.TraceWrite("Fedex", "processShipment", Error);
|
|
return null;
|
|
}
|
|
}
|
|
catch (SoapException e)
|
|
{
|
|
Error = e.Detail.InnerText;
|
|
ErrorFollow.TraceWrite("Fedex", "processShipment", Error);
|
|
return null;
|
|
// Console.WriteLine(e.Detail.InnerText);
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
Error = e.Message;
|
|
ErrorFollow.TraceWrite("Fedex", "processShipment", Error);
|
|
return null;
|
|
// Console.WriteLine(e.Message);
|
|
}
|
|
// Console.WriteLine("Press any key to quit !");
|
|
// Console.ReadKey();
|
|
Error = "";
|
|
|
|
|
|
fmd.PostCode = code;
|
|
return fmd;
|
|
}
|
|
|
|
private static ProcessShipmentRequest CreateShipmentRequest()
|
|
{
|
|
// Build the ShipmentRequest
|
|
ProcessShipmentRequest request = new ProcessShipmentRequest();
|
|
//
|
|
request.WebAuthenticationDetail = new WebAuthenticationDetail();
|
|
request.WebAuthenticationDetail.UserCredential = new WebAuthenticationCredential();
|
|
request.WebAuthenticationDetail.UserCredential.Key = Key;// "ENsVAGUr9UIGx7Uj"; // Replace "XXX" with the Key
|
|
request.WebAuthenticationDetail.UserCredential.Password = Password;// "o7j1X19OxhxWqwb9gMTDEGYfE"; // Replace "XXX" with the Password
|
|
if (usePropertyFile()) //Set values from a file for testing purposes
|
|
{
|
|
request.WebAuthenticationDetail.UserCredential.Key = getProperty("key");
|
|
request.WebAuthenticationDetail.UserCredential.Password = getProperty("password");
|
|
}
|
|
//
|
|
request.ClientDetail = new ClientDetail();
|
|
request.ClientDetail.AccountNumber = AccountNumber;// "510087160"; // Replace "XXX" with the client's account number
|
|
request.ClientDetail.MeterNumber = MeterNumber;// "118810402"; // Replace "XXX" with the client's meter number
|
|
if (usePropertyFile()) //Set values from a file for testing purposes
|
|
{
|
|
request.ClientDetail.AccountNumber = getProperty("accountnumber");
|
|
request.ClientDetail.MeterNumber = getProperty("meternumber");
|
|
}
|
|
//
|
|
request.TransactionDetail = new TransactionDetail();
|
|
request.TransactionDetail.CustomerTransactionId = ormd.CustomerTransactionId;// "1245677"; // The client will get the same value back in the response
|
|
//
|
|
request.Version = new VersionId();
|
|
//
|
|
SetShipmentDetails(request);
|
|
//
|
|
SetSender(request);
|
|
//
|
|
SetRecipient(request);
|
|
//
|
|
SetPayment(request);
|
|
//
|
|
SetLabelDetails(request);
|
|
//
|
|
SetPackageLineItems(request);
|
|
|
|
if (ormd.Rever.CountryCode=="CA")
|
|
{
|
|
SetCustomsClearanceDetails(request);
|
|
}
|
|
else
|
|
SetSmartPostDetails(request);
|
|
//
|
|
return request;
|
|
}
|
|
|
|
private static void SetShipmentDetails(ProcessShipmentRequest request)
|
|
{
|
|
request.RequestedShipment = new RequestedShipment();
|
|
request.RequestedShipment.ShipTimestamp = DateTime.Now; // Ship date and time
|
|
request.RequestedShipment.DropoffType = DropoffType.REGULAR_PICKUP;
|
|
if (PostName == "GROUND_HOME_DELIVERY")
|
|
request.RequestedShipment.ServiceType = ServiceType.GROUND_HOME_DELIVERY;
|
|
else if (PostName == "SMART_POST")
|
|
request.RequestedShipment.ServiceType = ServiceType.SMART_POST;
|
|
else if (PostName == "FEDEX_GROUND")
|
|
request.RequestedShipment.ServiceType = ServiceType.FEDEX_GROUND;
|
|
else if (PostName == "FEDEX_2_DAY")
|
|
request.RequestedShipment.ServiceType = ServiceType.FEDEX_2_DAY;
|
|
request.RequestedShipment.PackagingType = PackagingType.YOUR_PACKAGING; // Packaging type YOUR_PACKAGING, ...
|
|
//
|
|
request.RequestedShipment.PackageCount = "1";
|
|
|
|
}
|
|
|
|
private static void SetSender(ProcessShipmentRequest request)
|
|
{
|
|
//request.RequestedShipment.Shipper = new Party();
|
|
//request.RequestedShipment.Shipper.Contact = new Contact();
|
|
//request.RequestedShipment.Shipper.Contact.CompanyName = "Sender Company Name";
|
|
//request.RequestedShipment.Shipper.Contact.PhoneNumber = "9012637906";
|
|
////
|
|
//request.RequestedShipment.Shipper.Address = new Address();
|
|
//request.RequestedShipment.Shipper.Address.StreetLines = new string[1] { "Address Line 1" };
|
|
//request.RequestedShipment.Shipper.Address.City = "Austin";
|
|
//request.RequestedShipment.Shipper.Address.StateOrProvinceCode = "TX";
|
|
//request.RequestedShipment.Shipper.Address.PostalCode = "73301";
|
|
//request.RequestedShipment.Shipper.Address.CountryCode = "US";
|
|
|
|
|
|
request.RequestedShipment.Shipper = new Party();
|
|
request.RequestedShipment.Shipper.Contact = new Contact();
|
|
request.RequestedShipment.Shipper.Contact.PersonName = ormd.Shiper.PersonName;//"chu";
|
|
request.RequestedShipment.Shipper.Contact.CompanyName = ormd.Shiper.CompanyName;//"chu";
|
|
request.RequestedShipment.Shipper.Contact.PhoneNumber = ormd.Shiper.PhoneNumber;//"0805522713";
|
|
request.RequestedShipment.Shipper.Address = new Address();
|
|
request.RequestedShipment.Shipper.Address.StreetLines = new string[1] { ormd.Shiper.StreetLines }; //new string[2] { "1202 Chalet Ln", "Do Not Delete - Test Account" };
|
|
request.RequestedShipment.Shipper.Address.City = ormd.Shiper.City;//"Harrison";
|
|
request.RequestedShipment.Shipper.Address.StateOrProvinceCode = ormd.Shiper.StateOrProvinceCode;//"AR";
|
|
request.RequestedShipment.Shipper.Address.PostalCode = ormd.Shiper.PostalCode;//"72601";
|
|
request.RequestedShipment.Shipper.Address.CountryCode = ormd.Shiper.CountryCode;//"US";
|
|
}
|
|
|
|
private static void SetRecipient(ProcessShipmentRequest request)
|
|
{
|
|
//request.RequestedShipment.Recipient = new Party();
|
|
//request.RequestedShipment.Recipient.Contact = new Contact();
|
|
//request.RequestedShipment.Recipient.Contact.PersonName = "Recipient Name";
|
|
//request.RequestedShipment.Recipient.Contact.PhoneNumber = "9012637906";
|
|
////
|
|
//request.RequestedShipment.Recipient.Address = new Address();
|
|
//request.RequestedShipment.Recipient.Address.StreetLines = new string[1] { "Recipient Address Line 1" };
|
|
//request.RequestedShipment.Recipient.Address.City = "Windsor";
|
|
//request.RequestedShipment.Recipient.Address.StateOrProvinceCode = "CT";
|
|
//request.RequestedShipment.Recipient.Address.PostalCode = "06006";
|
|
//request.RequestedShipment.Recipient.Address.CountryCode = "US";
|
|
|
|
request.RequestedShipment.Recipient = new Party();
|
|
|
|
//
|
|
request.RequestedShipment.Recipient.Contact = new Contact();
|
|
request.RequestedShipment.Recipient.Contact.PersonName = ormd.Rever.PersonName;//"Recipient Name";
|
|
request.RequestedShipment.Recipient.Contact.CompanyName = ormd.Rever.CompanyName;//"Recipient Company Name";
|
|
request.RequestedShipment.Recipient.Contact.PhoneNumber = ormd.Rever.PhoneNumber;//"9012637906";
|
|
//
|
|
request.RequestedShipment.Recipient.Address = new Address();
|
|
if (ormd.Rever.StreetLines.Length <= 25)
|
|
request.RequestedShipment.Recipient.Address.StreetLines = new string[1] { ormd.Rever.StreetLines };// new string[1] { "Address Line 1" };
|
|
else
|
|
{
|
|
string[] addr = ormd.Rever.StreetLines.Split(' ');
|
|
if (ormd.Rever.StreetLines.Contains(",") == true)
|
|
{
|
|
addr = ormd.Rever.StreetLines.Split(',');
|
|
}
|
|
string line1 = "";
|
|
string line2 = "";
|
|
if (addr.Length == 2)
|
|
{
|
|
line1 = addr[0];
|
|
line2 = addr[1];
|
|
|
|
}
|
|
else
|
|
{
|
|
for (int i = 0; i < addr.Length; i++)
|
|
{
|
|
if (line1.Length + addr[i].Length < 25)
|
|
line1 += addr[i] + " ";
|
|
else
|
|
line2 += addr[i] + " ";
|
|
|
|
}
|
|
}
|
|
if(line2!="")
|
|
request.RequestedShipment.Recipient.Address.StreetLines = new string[2] { line1, line2 };
|
|
else
|
|
request.RequestedShipment.Recipient.Address.StreetLines = new string[1] { line1};
|
|
|
|
}
|
|
request.RequestedShipment.Recipient.Address.City = ormd.Rever.City;//"Richmond";
|
|
request.RequestedShipment.Recipient.Address.StateOrProvinceCode = ormd.Rever.StateOrProvinceCode;//"BC";
|
|
request.RequestedShipment.Recipient.Address.PostalCode = ormd.Rever.PostalCode;// "V7C4V4";
|
|
request.RequestedShipment.Recipient.Address.CountryCode = ormd.Rever.CountryCode;
|
|
|
|
|
|
if (PostName == "GROUND_HOME_DELIVERY")
|
|
{
|
|
request.RequestedShipment.Recipient.Address.Residential = true;
|
|
request.RequestedShipment.Recipient.Address.ResidentialSpecified = true;
|
|
request.RequestedShipment.Recipient.Contact = new Contact();
|
|
|
|
if (ormd.Rever.PersonName != null && ormd.Rever.PersonName != "")
|
|
request.RequestedShipment.Recipient.Contact.PersonName = ormd.Rever.PersonName;
|
|
else
|
|
request.RequestedShipment.Recipient.Contact.PersonName = "jacky";
|
|
if (ormd.Rever.PhoneNumber != null && ormd.Rever.PhoneNumber != "")
|
|
request.RequestedShipment.Recipient.Contact.PhoneNumber = ormd.Rever.PhoneNumber;
|
|
else
|
|
request.RequestedShipment.Recipient.Contact.PhoneNumber = "2392276058";
|
|
}
|
|
|
|
}
|
|
|
|
private static void SetPayment(ProcessShipmentRequest request)
|
|
{
|
|
request.RequestedShipment.ShippingChargesPayment = new Payment();
|
|
request.RequestedShipment.ShippingChargesPayment.PaymentType = PaymentType.SENDER;
|
|
request.RequestedShipment.ShippingChargesPayment.Payor = new Payor();
|
|
request.RequestedShipment.ShippingChargesPayment.Payor.ResponsibleParty = new Party();
|
|
request.RequestedShipment.ShippingChargesPayment.Payor.ResponsibleParty.AccountNumber = AccountNumber;// "510087160"; // Replace "XXX" with client's account number
|
|
if (usePropertyFile()) //Set values from a file for testing purposes
|
|
{
|
|
request.RequestedShipment.ShippingChargesPayment.Payor.ResponsibleParty.AccountNumber = getProperty("payoraccount");
|
|
}
|
|
request.RequestedShipment.ShippingChargesPayment.Payor.ResponsibleParty.Contact = new Contact();
|
|
request.RequestedShipment.ShippingChargesPayment.Payor.ResponsibleParty.Address = new Address();
|
|
request.RequestedShipment.ShippingChargesPayment.Payor.ResponsibleParty.Address.CountryCode ="US";
|
|
}
|
|
|
|
private static void SetLabelDetails(ProcessShipmentRequest request)
|
|
{
|
|
request.RequestedShipment.LabelSpecification = new LabelSpecification();
|
|
request.RequestedShipment.LabelSpecification.ImageType = ShippingDocumentImageType.PNG; // Image types PDF, PNG, DPL, ...
|
|
request.RequestedShipment.LabelSpecification.ImageTypeSpecified = true;
|
|
request.RequestedShipment.LabelSpecification.CustomerSpecifiedDetail = new CustomerSpecifiedLabelDetail();
|
|
|
|
|
|
|
|
//request.RequestedShipment.LabelSpecification.CustomerSpecifiedDetail.CustomContent = new CustomLabelDetail();
|
|
//request.RequestedShipment.LabelSpecification.CustomerSpecifiedDetail.CustomContent.CoordinateUnits = CustomLabelCoordinateUnits.PIXELS;
|
|
//request.RequestedShipment.LabelSpecification.CustomerSpecifiedDetail.CustomContent.TextEntries = new CustomLabelTextEntry[1];
|
|
//request.RequestedShipment.LabelSpecification.CustomerSpecifiedDetail.CustomContent.TextEntries[0] = new CustomLabelTextEntry();
|
|
//request.RequestedShipment.LabelSpecification.CustomerSpecifiedDetail.CustomContent.TextEntries[0].Position = new CustomLabelPosition();
|
|
//request.RequestedShipment.LabelSpecification.CustomerSpecifiedDetail.CustomContent.TextEntries[0].Position.X = "50";
|
|
//request.RequestedShipment.LabelSpecification.CustomerSpecifiedDetail.CustomContent.TextEntries[0].Position.Y =50;
|
|
//// request.RequestedShipment.LabelSpecification.CustomerSpecifiedDetail.CustomContent.TextEntries[0].Format = "Data for text";
|
|
//request.RequestedShipment.LabelSpecification.CustomerSpecifiedDetail.CustomContent.BarcodeEntries = new CustomLabelBarcodeEntry[1];
|
|
//request.RequestedShipment.LabelSpecification.CustomerSpecifiedDetail.CustomContent.BarcodeEntries[0] = new CustomLabelBarcodeEntry();
|
|
//request.RequestedShipment.LabelSpecification.CustomerSpecifiedDetail.CustomContent.BarcodeEntries[0].DataFields = new string[1] { "1xKM0574-white" };
|
|
|
|
// create a label specification
|
|
|
|
|
|
// add a custom label text entry with a note below the single code
|
|
//CustomLabelTextEntry customLabelNote = new CustomLabelTextEntry();
|
|
|
|
//customLabelNote.DataFields = new string[1] { "1xKM0574-white" };
|
|
|
|
|
|
//// add the custom label text entry to the label specification
|
|
//request.RequestedShipment.LabelSpecification.CustomerSpecifiedDetail.CustomContent.TextEntries = new CustomLabelTextEntry[] { customLabelNote };
|
|
|
|
|
|
|
|
//request.RequestedShipment.LabelSpecification.CustomerSpecifiedDetail.CustomContent.BarcodeEntries[0].Position = new CustomLabelPosition();
|
|
//request.RequestedShipment.LabelSpecification.CustomerSpecifiedDetail.CustomContent.BarcodeEntries[0].Position.X = "50";
|
|
//request.RequestedShipment.LabelSpecification.CustomerSpecifiedDetail.CustomContent.BarcodeEntries[0].Position.Y = 50;
|
|
//request.RequestedShipment.LabelSpecification.CustomerSpecifiedDetail.CustomContent.BarcodeEntries[0].BarHeight = 100;
|
|
//request.RequestedShipment.LabelSpecification.CustomerSpecifiedDetail.CustomContent.BarcodeEntries[0].ThinBarWidth = 8;
|
|
//request.RequestedShipment.LabelSpecification.CustomerSpecifiedDetail.CustomContent.BarcodeEntries[0].Format = "%s";
|
|
//request.RequestedShipment.LabelSpecification.CustomerSpecifiedDetail.CustomContent.BarcodeEntries[0].BarcodeSymbology = BarcodeSymbologyType.CODE128C;
|
|
//request.RequestedShipment.LabelSpecification.CustomerSpecifiedDetail.MaskedData = new LabelMaskableDataType[1];
|
|
//request.RequestedShipment.LabelSpecification.CustomerSpecifiedDetail.MaskedData[0] = new LabelMaskableDataType();
|
|
//request.RequestedShipment.LabelSpecification.CustomerSpecifiedDetail.MaskedData[0] = LabelMaskableDataType.SHIPPER_ACCOUNT_NUMBER;
|
|
//request.RequestedShipment.LabelSpecification.CustomerSpecifiedDetail.CustomContentPosition = RelativeVerticalPositionType.BELOW;
|
|
//request.RequestedShipment.LabelSpecification.CustomerSpecifiedDetail.ConfigurableReferenceEntries = new ConfigurableLabelReferenceEntry[1];
|
|
//request.RequestedShipment.LabelSpecification.CustomerSpecifiedDetail.ConfigurableReferenceEntries[0] = new ConfigurableLabelReferenceEntry();
|
|
//request.RequestedShipment.LabelSpecification.CustomerSpecifiedDetail.ConfigurableReferenceEntries[0].DataField = "1xKM0574-white";
|
|
//request.RequestedShipment.LabelSpecification.CustomerSpecifiedDetail.ConfigurableReferenceEntries[0].ZoneNumber = "1";
|
|
//request.RequestedShipment.LabelSpecification.CustomerSpecifiedDetail.DocTabContent=
|
|
//
|
|
if (PostName == "SMART_POST")
|
|
request.RequestedShipment.LabelSpecification.CustomerSpecifiedDetail.SecondaryBarcode = SecondaryBarcodeType.USPS;
|
|
request.RequestedShipment.LabelSpecification.LabelFormatType = LabelFormatType.COMMON2D;
|
|
request.RequestedShipment.LabelSpecification.LabelStockType = LabelStockType.PAPER_4X6;
|
|
request.RequestedShipment.LabelSpecification.LabelStockTypeSpecified = true;
|
|
|
|
}
|
|
|
|
private static void SetPackageLineItems(ProcessShipmentRequest request)
|
|
{
|
|
request.RequestedShipment.RequestedPackageLineItems = new RequestedPackageLineItem[1];
|
|
request.RequestedShipment.RequestedPackageLineItems[0] = new RequestedPackageLineItem();
|
|
request.RequestedShipment.RequestedPackageLineItems[0].SequenceNumber = "1";
|
|
// Package weight information
|
|
request.RequestedShipment.RequestedPackageLineItems[0].Weight = new Weight();
|
|
request.RequestedShipment.RequestedPackageLineItems[0].Weight.Value = ormd.GoodsList[0].Weight;
|
|
request.RequestedShipment.RequestedPackageLineItems[0].Weight.Units = WeightUnits.LB;
|
|
//
|
|
if (IsQM == 1) //签收服务
|
|
{
|
|
request.RequestedShipment.RequestedPackageLineItems[0].SpecialServicesRequested = new PackageSpecialServicesRequested();
|
|
request.RequestedShipment.RequestedPackageLineItems[0].SpecialServicesRequested.SignatureOptionDetail = new SignatureOptionDetail();
|
|
request.RequestedShipment.RequestedPackageLineItems[0].SpecialServicesRequested.SignatureOptionDetail.OptionType = SignatureOptionType.DIRECT;
|
|
}
|
|
request.RequestedShipment.RequestedPackageLineItems[0].CustomerReferences = new CustomerReference[1];
|
|
request.RequestedShipment.RequestedPackageLineItems[0].CustomerReferences[0] = new CustomerReference();
|
|
request.RequestedShipment.RequestedPackageLineItems[0].CustomerReferences[0].CustomerReferenceType = CustomerReferenceType.CUSTOMER_REFERENCE;
|
|
request.RequestedShipment.RequestedPackageLineItems[0].CustomerReferences[0].Value = ormd.GoodsList[0].SKU;
|
|
//request.RequestedShipment.RequestedPackageLineItems[0].CustomerReferences[1] = new CustomerReference();
|
|
//request.RequestedShipment.RequestedPackageLineItems[0].CustomerReferences[1].CustomerReferenceType = CustomerReferenceType.P_O_NUMBER;
|
|
//request.RequestedShipment.RequestedPackageLineItems[0].CustomerReferences[1].Value ="1*KM0707";
|
|
|
|
request.RequestedShipment.RequestedPackageLineItems[0].Dimensions = new Dimensions();
|
|
if (ormd.GoodsList[0].Lenght != null && ormd.GoodsList[0].Lenght != "")
|
|
request.RequestedShipment.RequestedPackageLineItems[0].Dimensions.Length = ormd.GoodsList[0].Lenght;//"12";
|
|
else
|
|
request.RequestedShipment.RequestedPackageLineItems[0].Dimensions.Length = "60 ";
|
|
if (ormd.GoodsList[0].Width != null && ormd.GoodsList[0].Width != "")
|
|
request.RequestedShipment.RequestedPackageLineItems[0].Dimensions.Width = ormd.GoodsList[0].Width;//"13";
|
|
else
|
|
request.RequestedShipment.RequestedPackageLineItems[0].Dimensions.Width = "30";
|
|
if (ormd.GoodsList[0].Height != null && ormd.GoodsList[0].Height != "")
|
|
request.RequestedShipment.RequestedPackageLineItems[0].Dimensions.Height = ormd.GoodsList[0].Height;// "14";
|
|
else
|
|
request.RequestedShipment.RequestedPackageLineItems[0].Dimensions.Height = "30";
|
|
request.RequestedShipment.RequestedPackageLineItems[0].Dimensions.Units = LinearUnits.IN;
|
|
}
|
|
private static void SetCustomsClearanceDetails(ProcessShipmentRequest request)
|
|
{
|
|
request.RequestedShipment.CustomsClearanceDetail = new CustomsClearanceDetail();
|
|
request.RequestedShipment.CustomsClearanceDetail.DutiesPayment = new Payment();
|
|
request.RequestedShipment.CustomsClearanceDetail.DutiesPayment.PaymentType = PaymentType.SENDER;
|
|
request.RequestedShipment.CustomsClearanceDetail.DutiesPayment.Payor = new Payor();
|
|
request.RequestedShipment.CustomsClearanceDetail.DutiesPayment.Payor.ResponsibleParty = new Party();
|
|
request.RequestedShipment.CustomsClearanceDetail.DutiesPayment.Payor.ResponsibleParty.AccountNumber = AccountNumber; // Replace "XXX" with the payor account number
|
|
if (usePropertyFile()) //Set values from a file for testing purposes
|
|
{
|
|
request.RequestedShipment.CustomsClearanceDetail.DutiesPayment.Payor.ResponsibleParty.AccountNumber = getProperty("dutiesaccount");
|
|
}
|
|
request.RequestedShipment.CustomsClearanceDetail.DutiesPayment.Payor.ResponsibleParty.Contact = new Contact();
|
|
request.RequestedShipment.CustomsClearanceDetail.DutiesPayment.Payor.ResponsibleParty.Address = new Address();
|
|
request.RequestedShipment.CustomsClearanceDetail.DutiesPayment.Payor.ResponsibleParty.Address.CountryCode = "CA";
|
|
request.RequestedShipment.CustomsClearanceDetail.DocumentContent = InternationalDocumentContentType.NON_DOCUMENTS;
|
|
//
|
|
request.RequestedShipment.CustomsClearanceDetail.CustomsValue = new Money();
|
|
request.RequestedShipment.CustomsClearanceDetail.CustomsValue.Amount = 10.0M;
|
|
request.RequestedShipment.CustomsClearanceDetail.CustomsValue.Currency = "USD";
|
|
//
|
|
// SetCommodityDetails(request);
|
|
}
|
|
private static void SetSmartPostDetails(ProcessShipmentRequest request)
|
|
{
|
|
request.RequestedShipment.SmartPostDetail = new SmartPostShipmentDetail();
|
|
request.RequestedShipment.SmartPostDetail.Indicia = SmartPostIndiciaType.PARCEL_SELECT;
|
|
request.RequestedShipment.SmartPostDetail.IndiciaSpecified = true;
|
|
request.RequestedShipment.SmartPostDetail.AncillaryEndorsement = SmartPostAncillaryEndorsementType.ADDRESS_CORRECTION;
|
|
request.RequestedShipment.SmartPostDetail.AncillaryEndorsementSpecified = true;
|
|
|
|
request.RequestedShipment.SmartPostDetail.HubId = HubId;// "5531"; // Replace "XXX" with the hub id
|
|
if (usePropertyFile()) //Set values from a file for testing purposes
|
|
{
|
|
request.RequestedShipment.SmartPostDetail.HubId = getProperty("hubid");
|
|
}
|
|
|
|
}
|
|
private static void ShowShipmentReply(ProcessShipmentReply reply)
|
|
{
|
|
// Console.WriteLine("Shipment Reply details:");
|
|
// Console.WriteLine("\nSmartPost Reply details");
|
|
// if(reply.CompletedShipmentDetail.SmartPostDetail.PickUpCarrierSpecified) Console.WriteLine("PickupCarrier Code:" + reply.CompletedShipmentDetail.SmartPostDetail.PickUpCarrier);
|
|
// if (reply.CompletedShipmentDetail.SmartPostDetail.MachinableSpecified) Console.WriteLine("Machinable:" + reply.CompletedShipmentDetail.SmartPostDetail.Machinable);
|
|
// Console.WriteLine();
|
|
|
|
// Console.WriteLine("Package details\n");
|
|
foreach (CompletedPackageDetail packageDetail in reply.CompletedShipmentDetail.CompletedPackageDetails)
|
|
{
|
|
//ShowTrackingDetails(packageDetail.TrackingIds);
|
|
//ShowPackageRateDetails(packageDetail.PackageRating.PackageRateDetails);
|
|
// ShowBarcodeDetails(packageDetail.OperationalDetail.Barcodes);
|
|
if (null != packageDetail.Label.Parts[0].Image)
|
|
{
|
|
SaveLabel(packageDetail.TrackingIds[0].TrackingNumber, packageDetail.Label.Parts[0].Image);
|
|
}
|
|
}
|
|
}
|
|
|
|
private static void ShowTrackingDetails(TrackingId[] TrackingIds)
|
|
{
|
|
// Tracking information for each package
|
|
Console.WriteLine("Tracking details");
|
|
if (TrackingIds != null)
|
|
{
|
|
for (int i = 0; i < TrackingIds.Length; i++)
|
|
{
|
|
Console.WriteLine("Tracking # {0} Form ID {1}", TrackingIds[i].TrackingNumber, TrackingIds[i].FormId);
|
|
}
|
|
}
|
|
}
|
|
|
|
private static void ShowPackageRateDetails(PackageRateDetail[] PackageRateDetails)
|
|
{
|
|
foreach (PackageRateDetail ratedPackage in PackageRateDetails)
|
|
{
|
|
Console.WriteLine("\nRate details");
|
|
if (ratedPackage.BillingWeight != null)
|
|
Console.WriteLine("Billing weight {0} {1}", ratedPackage.BillingWeight.Value, ratedPackage.BillingWeight.Units);
|
|
if (ratedPackage.BaseCharge != null)
|
|
Console.WriteLine("Base charge {0} {1}", ratedPackage.BaseCharge.Amount, ratedPackage.BaseCharge.Currency);
|
|
if (ratedPackage.TotalSurcharges != null)
|
|
Console.WriteLine("Total surcharge {0} {1}", ratedPackage.TotalSurcharges.Amount, ratedPackage.TotalSurcharges.Currency);
|
|
if (ratedPackage.Surcharges != null)
|
|
{
|
|
// Individual surcharge for each package
|
|
foreach (Surcharge surcharge in ratedPackage.Surcharges)
|
|
Console.WriteLine(" {0} surcharge {1} {2}", surcharge.SurchargeType, surcharge.Amount.Amount, surcharge.Amount.Currency);
|
|
}
|
|
if (ratedPackage.NetCharge != null)
|
|
Console.WriteLine("Net charge {0} {1}", ratedPackage.NetCharge.Amount, ratedPackage.NetCharge.Currency);
|
|
}
|
|
}
|
|
|
|
private static void ShowBarcodeDetails(PackageBarcodes barcodes)
|
|
{
|
|
// Barcode information for each package
|
|
Console.WriteLine("\nBarcode details");
|
|
if (barcodes != null)
|
|
{
|
|
if (barcodes.StringBarcodes != null)
|
|
{
|
|
for (int i = 0; i < barcodes.StringBarcodes.Length; i++)
|
|
{
|
|
Console.WriteLine("String barcode {0} Type {1}", barcodes.StringBarcodes[i].Value, barcodes.StringBarcodes[i].Type);
|
|
}
|
|
}
|
|
|
|
if (barcodes.BinaryBarcodes != null)
|
|
{
|
|
for (int i = 0; i < barcodes.BinaryBarcodes.Length; i++)
|
|
{
|
|
Console.WriteLine("Binary barcode Type {0}", barcodes.BinaryBarcodes[i].Type);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
private static void SaveLabel(String shipLabelFileName, byte[] labelBuffer)
|
|
{
|
|
// Save shipping label to file
|
|
string LabelPath = AppDomain.CurrentDomain.BaseDirectory + "attached/fedex/";// @"F:\褚明杰\fedex\ShipService_v2014_cs\cs\ShipWebServiceClient\Express\International\ShipWebServiceClient\bin\Release\pdf\";
|
|
if (LBPath != "")
|
|
LabelPath = LBPath;
|
|
if (usePropertyFile())
|
|
{
|
|
LabelPath = getProperty("labelpath");
|
|
}
|
|
String LabelFileName = LabelPath + shipLabelFileName + ".png";
|
|
FileStream LabelFile = new FileStream(LabelFileName, FileMode.Create);
|
|
LabelFile.Write(labelBuffer, 0, labelBuffer.Length);
|
|
LabelFile.Close();
|
|
// DisplayLabel(LabelFileName);
|
|
}
|
|
|
|
private static void DisplayLabel(string labelFileName)
|
|
{
|
|
System.Diagnostics.ProcessStartInfo info = new System.Diagnostics.ProcessStartInfo(labelFileName);
|
|
info.UseShellExecute = true;
|
|
info.Verb = "open";
|
|
System.Diagnostics.Process.Start(info);
|
|
}
|
|
|
|
private static string ShowNotifications(ProcessShipmentReply reply)
|
|
{
|
|
//Console.WriteLine("Notifications");
|
|
string error = "";
|
|
for (int i = 0; i < reply.Notifications.Length; i++)
|
|
{
|
|
Notification notification = reply.Notifications[i];
|
|
error += "Code:" + notification.Code + ";Message:" + notification.Message + ";Source:" + notification.Source;
|
|
//Console.WriteLine("Notification no. {0}", i);
|
|
//Console.WriteLine(" Severity: {0}", notification.Severity);
|
|
//Console.WriteLine(" Code: {0}", notification.Code);
|
|
//Console.WriteLine(" Message: {0}", notification.Message);
|
|
//Console.WriteLine(" Source: {0}", notification.Source);
|
|
}
|
|
return error;
|
|
}
|
|
private static bool usePropertyFile() //Set to true for common properties to be set with getProperty function.
|
|
{
|
|
return getProperty("usefile").Equals("True");
|
|
}
|
|
private static String getProperty(String propertyname) //Sets common properties for testing purposes.
|
|
{
|
|
try
|
|
{
|
|
String filename = "C:\\filepath\\filename.txt";
|
|
if (System.IO.File.Exists(filename))
|
|
{
|
|
System.IO.StreamReader sr = new System.IO.StreamReader(filename);
|
|
do
|
|
{
|
|
String[] parts = sr.ReadLine().Split(',');
|
|
if (parts[0].Equals(propertyname) && parts.Length == 2)
|
|
{
|
|
return parts[1];
|
|
}
|
|
}
|
|
while (!sr.EndOfStream);
|
|
}
|
|
Console.WriteLine("Property {0} set to default 'XXX'", propertyname);
|
|
return "XXX";
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
Console.WriteLine("Property {0} set to default 'XXX'", propertyname);
|
|
return "XXX";
|
|
}
|
|
}
|
|
}
|
|
} |