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 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); } }