public static Batch getDefaultObject()
        {
            // Grab USPS carrier account to get the correct object ID for further testing.
            // This should be changed to be more generic in future versions of this test. In
            // other words, remove the depedence on a USPS carrier account to exist.
            ShippoCollection <CarrierAccount> carrierAccounts = getAPIResource().AllCarrierAccount();
            string defaultCarrierAccount = "";

            foreach (CarrierAccount account in carrierAccounts)
            {
                if (account.Carrier.ToString() == "usps")
                {
                    defaultCarrierAccount = account.ObjectId;
                }
            }

            Address addressFrom = Address.createForPurchase("Mr. Hippo", "965 Mission St.", "Ste 201", "SF",
                                                            "CA", "94103", "US", "4151234567", "*****@*****.**");
            Address addressTo = Address.createForPurchase("Mrs. Hippo", "965 Missions St.", "Ste 202", "SF",
                                                          "CA", "94103", "US", "4151234568", "*****@*****.**");

            Parcel[]      parcels       = { Parcel.createForShipment(5, 5, 5, "in", 2, "oz") };
            Shipment      shipment      = Shipment.createForBatch(addressFrom, addressTo, parcels);
            BatchShipment batchShipment = BatchShipment.createForBatchShipments(defaultCarrierAccount, "usps_priority", shipment);

            List <BatchShipment> batchShipments = new List <BatchShipment>();

            batchShipments.Add(batchShipment);

            Batch batch = getAPIResource().CreateBatch(defaultCarrierAccount, "usps_priority", ShippoEnums.LabelFiletypes.PDF_4x6,
                                                       "BATCH #170", batchShipments);

            Assert.AreEqual(ShippoEnums.Statuses.VALIDATING, batch.Status);
            return(batch);
        }
示例#2
0
        private static void RunBatchExample(APIResource resource)
        {
            ShippoCollection <CarrierAccount> carrierAccounts = resource.AllCarrierAccount();
            string defaultCarrierAccount = "";

            foreach (CarrierAccount account in carrierAccounts)
            {
                if (account.Carrier.ToString() == "usps")
                {
                    defaultCarrierAccount = account.ObjectId;
                }
            }

            Address addressFrom = Address.createForPurchase("Mr. Hippo", "965 Mission St.", "Ste 201", "SF",
                                                            "CA", "94103", "US", "4151234567", "*****@*****.**");
            Address addressTo = Address.createForPurchase("Mrs. Hippo", "965 Missions St.", "Ste 202", "SF",
                                                          "CA", "94103", "US", "4151234568", "*****@*****.**");

            Parcel[]      parcels       = { Parcel.createForShipment(5, 5, 5, "in", 2, "oz") };
            Shipment      shipment      = Shipment.createForBatch(addressFrom, addressTo, parcels);
            BatchShipment batchShipment = BatchShipment.createForBatchShipments(defaultCarrierAccount, "usps_priority", shipment);

            List <BatchShipment> batchShipments = new List <BatchShipment> ();

            batchShipments.Add(batchShipment);

            Batch batch = resource.CreateBatch(defaultCarrierAccount, "usps_priority", ShippoEnums.LabelFiletypes.PDF_4x6,
                                               "BATCH #170", batchShipments);

            Console.WriteLine("Batch Status = " + batch.Status);
            Console.WriteLine("Metadata = " + batch.Metadata);
        }