Esempio n. 1
0
        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 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);
        }
      }