public void Initialize() { Client.apiKey = "WzJHJ6SoPnBVYu0ae4aIHA"; address = new Address() { company = "Simpler Postage Inc", street1 = "164 Townsend Street", street2 = "Unit 1", city = "San Francisco", state = "CA", country = "US", zip = "94107", phone = "1234567890" }; toAddress = new Dictionary<string, object>() { {"company", "Simpler Postage Inc"}, {"street1", "164 Townsend Street"}, {"street2", "Unit 1"}, {"city", "San Francisco"}, {"state", "CA"}, {"country", "US"}, {"zip", "94107"}, }; fromAddress = new Dictionary<string, object>() { {"name", "Andrew Tribone"}, {"street1", "480 Fell St"}, {"street2", "#3"}, {"city", "San Francisco"}, {"state", "CA"}, {"country", "US"}, {"zip", "94102"} }; shipment = Shipment.Create(new Dictionary<string, object>() { {"parcel", new Dictionary<string, object>() {{"length", 8}, {"width", 6}, {"height", 5}, {"weight", 10}}}, {"to_address", toAddress}, {"from_address", fromAddress}, {"reference", "ShipmentRef"} }); shipment.Buy(shipment.LowestRate()); parameters = new Dictionary<string, object>() { {"is_account_address", false}, {"address", address}, {"shipment", shipment}, {"min_datetime", DateTime.Now}, {"max_datetime", DateTime.Now} }; }
public void TestPredefinedPackage() { Parcel parcel = new Parcel() { weight = 1.8, predefined_package = "SMALLFLATRATEBOX" }; Shipment shipment = new Shipment() { parcel = parcel }; shipment.Create(); Assert.AreEqual(null, shipment.parcel.height); Assert.AreEqual("SMALLFLATRATEBOX", shipment.parcel.predefined_package); }
public void TestCarrierAccounts() { Address to = Address.Create(toAddress); Address from = Address.Create(fromAddress); Parcel parcel = Parcel.Create(new Dictionary<string, object>() { {"length", 8}, {"width", 6}, {"height", 5}, {"weight", 10} }); CustomsItem item = new CustomsItem() { description = "description" }; CustomsInfo info = new CustomsInfo() { customs_certify = "TRUE", eel_pfc = "NOEEI 30.37(a)", customs_items = new List<CustomsItem>() { item } }; Shipment shipment = new Shipment(); shipment.to_address = to; shipment.from_address = from; shipment.parcel = parcel; shipment.carrier_accounts = new List<CarrierAccount> { new CarrierAccount { id = "ca_qn6QC6fd" } }; shipment.Create(); if (shipment.rates.Count > 0) Assert.IsTrue(shipment.rates.TrueForAll(r => r.carrier_account_id == "ca_qn6QC6fd")); }
public void TestLowestRate() { Rate lowestUSPS = new Rate() { rate = "1.0", carrier = "USPS", service = "ParcelSelect" }; Rate highestUSPS = new Rate() { rate = "10.0", carrier = "USPS", service = "Priority" }; Rate lowestUPS = new Rate() { rate = "2.0", carrier = "UPS", service = "ParcelSelect" }; Rate highestUPS = new Rate() { rate = "20.0", carrier = "UPS", service = "Priority" }; Shipment shipment = new Shipment() { rates = new List<Rate>() { highestUSPS, lowestUSPS, highestUPS, lowestUPS } }; Rate rate = shipment.LowestRate(); Assert.AreEqual(rate, lowestUSPS); rate = shipment.LowestRate(includeCarriers: new List<string>() { "UPS" }); Assert.AreEqual(rate, lowestUPS); rate = shipment.LowestRate(includeServices: new List<string>() { "Priority" }); Assert.AreEqual(rate, highestUSPS); rate = shipment.LowestRate(excludeCarriers: new List<string>() { "USPS" }); Assert.AreEqual(rate, lowestUPS); rate = shipment.LowestRate(excludeServices: new List<string>() { "ParcelSelect" }); Assert.AreEqual(rate, highestUSPS); rate = shipment.LowestRate(includeCarriers: new List<string>() { "FedEx" }); Assert.IsNull(rate); }
public void TestCreateWithId() { Shipment shipment = new Shipment() { id = "shp_asdlf" }; shipment.Create(); }
/// <summary> /// Creates a new Shipment /// </summary> /// <param name="model">The Shipment to be created on the server</param> /// <returns>A fully populated Shipment, included the new Id</returns> /// <seealso cref="http://www.easypost.com/docs#shipments"/> public Shipment CreateShipment(Shipment model) { return(Execute <Shipment>(model, EasyPostUrls.SHIPMENTS)); }
public override void ShipBox(BusinessObjects.Order order, Box box) { if (ShipStatusUpdate != null) { ShipStatusUpdate("Setting Client API"); } ConfigurationValue oConVal = Configuration.GetValue(new string[] { "EasyPost", "APIKey" }); if (oConVal != null) { // Test API: HR89ARS1oymZV0qh3Kdg2g Client.apiKey = (string)oConVal.Value; } if (ShipStatusUpdate != null) { ShipStatusUpdate("Validating address"); } Address address = Address.CreateAndVerify(new Dictionary<string, object>() { {"company", "EasyPost"}, {"street1", "118 2nd Street"}, {"street2", "4th Floor"}, {"city", "San Francisco"}, {"state", "CA"}, {"country", "US"}, {"zip", "94105"} }); address.Verify(); if (ShipStatusUpdate != null) { ShipStatusUpdate("Creating from address"); } Address fromAddress = new Address() { name = "Andrew Tribone", street1 = "480 Fell St", street2 = "#3", city = "San Francisco", state = "CA", country = "US", zip = "94102" }; if (ShipStatusUpdate != null) { ShipStatusUpdate("Creating to address"); } Address toAddress = new Address() { company = "Simpler Postage Inc", street1 = "164 Townsend Street", street2 = "Unit 1", city = "San Francisco", state = "CA", country = "US", zip = "94107" }; if (ShipStatusUpdate != null) { ShipStatusUpdate("Creating parcel"); } Parcel parcel = new Parcel() { length = 8, width = 6, height = 5, weight = 10 }; if (ShipStatusUpdate != null) { ShipStatusUpdate("Shipping parcel"); } Shipment shipment = new Shipment() { to_address = toAddress, from_address = fromAddress, parcel = parcel }; shipment.Buy(shipment.LowestRate(includeServices: new List<string>() { "Priority" }, excludeCarriers: new List<string>() { "FedEx" })); if (ShipStatusUpdate != null) { ShipStatusUpdate("Generating parcel label"); } string sLabelFormat = ""; oConVal = Configuration.GetValue(new string[] { "EasyPost", "LabelFormat" }); if (oConVal != null) { // Test API: HR89ARS1oymZV0qh3Kdg2g sLabelFormat = (string)oConVal.Value; } shipment.GenerateLabel(sLabelFormat); if (sLabelFormat.ToUpper() == "PDF") { System.Diagnostics.Process.Start(shipment.postage_label.label_pdf_url); } else if (sLabelFormat.ToUpper() == "ZPL") { System.Diagnostics.Process.Start(shipment.postage_label.label_url); } }