public async Task <Batch> AddShipmentsToBatch(string batchId, IEnumerable <string> shipmentIds)
        {
            var list = new List <CreateBatchShipment>();

            foreach (string shipmentId in shipmentIds)
            {
                var createBatchShipment = new CreateBatchShipment
                {
                    Shipment = shipmentId
                };
                list.Add(createBatchShipment);
            }
            string ep = string.Format("{0}/batches/{1}/add_shipments", apiEndpoint, System.Net.WebUtility.HtmlEncode(batchId));

            return(await this.apiClient.DoRequestAsync <Batch>(ep, HttpMethod.Post, Serialize(list)));
        }
Beispiel #2
0
        public static async Task <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 = await GetShippoClient().AllCarrierAccounts();

            string defaultCarrierAccount = "";

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

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

            CreateParcel[] parcels       = { CreateParcel.CreateForShipment(5, 5, 5, DistanceUnits.@in, 2, MassUnits.oz) };
            var            shipment      = CreateShipment.CreateForBatch(addressFrom, addressTo, parcels);
            var            batchShipment = CreateBatchShipment.CreateForBatchShipments(defaultCarrierAccount, "usps_priority", shipment);

            var batchShipments = new List <CreateBatchShipment>();

            batchShipments.Add(batchShipment);

            Batch batch = await GetShippoClient().CreateBatch(new CreateBatch
            {
                DefaultCarrierAccount    = defaultCarrierAccount,
                DefaultServicelevelToken = "usps_priority",
                LabelFiletype            = ShippoEnums.LabelFiletypes.PDF_4x6,
                Metadata       = "BATCH #170",
                BatchShipments = batchShipments
            });

            Assert.AreEqual(ShippoEnums.Statuses.VALIDATING, batch.Status);
            return(batch);
        }
Beispiel #3
0
        private static async Task RunBatchExample(ShippoClient resource)
        {
            ShippoCollection <CarrierAccount> carrierAccounts = await resource.AllCarrierAccounts();

            string defaultCarrierAccount = "";

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

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

            CreateParcel[] parcels       = { CreateParcel.CreateForShipment(5, 5, 5, DistanceUnits.@in, 2, MassUnits.oz) };
            var            shipment      = CreateShipment.CreateForBatch(addressFrom, addressTo, parcels);
            var            batchShipment = CreateBatchShipment.CreateForBatchShipments(defaultCarrierAccount, "usps_priority", shipment);

            var batchShipments = new List <CreateBatchShipment>();

            batchShipments.Add(batchShipment);

            Batch batch = await resource.CreateBatch(new CreateBatch
            {
                DefaultCarrierAccount    = defaultCarrierAccount,
                DefaultServicelevelToken = "usps_priority",
                LabelFiletype            = ShippoEnums.LabelFiletypes.PDF_4x6,
                Metadata       = "BATCH #170",
                BatchShipments = batchShipments
            });

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