public async Task <Parcel <Country> > Update(CreateParcel parcel) { var wrapper = new DataWrapper { Parcel = parcel }; return(await Update <Parcel <Country> >(JsonHelper.Serialize(wrapper, DateTimeFormat))); }
public static async Task <Parcel> GetDefaultObject() { var parameters = new CreateParcel { Length = 5, Width = 5, Height = 5, DistanceUnit = DistanceUnits.cm, Weight = 2, MassUnit = MassUnits.lb, Template = null, Metadata = "Customer ID 123456" }; return(await GetShippoClient().CreateParcel(parameters)); }
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); }
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); }
public static void Main(string[] args) { // replace with your Shippo Token // don't have one? get more info here // (https://goshippo.com/docs/#overview) var client = new ShippoClient("<YourShippoToken>"); // to address var toAddressTable = new CreateAddress { Name = "Mr. Hippo", Company = "Shippo", Street1 = "215 Clayton St.", City = "San Francisco", State = "CA", PostalCode = "94117", Country = "US", Phone = "+1 555 341 9393", Email = "*****@*****.**" }; // from address var fromAddressTable = new CreateAddress { Name = "Ms Hippo", Company = "San Diego Zoo", Street1 = "2920 Zoo Drive", City = "San Diego", State = "CA", PostalCode = "92101", Country = "US", Email = "*****@*****.**", Phone = "+1 619 231 1515", Metadata = "Customer ID 123456" }; // parcel var parcelTable = new CreateParcel { Length = 5, Width = 5, Height = 5, DistanceUnit = DistanceUnits.@in, Weight = 2, MassUnit = MassUnits.lb }; // shipment var shipmentTable = new CreateShipment { AddressTo = toAddressTable, AddressFrom = fromAddressTable, Async = false }; shipmentTable.AddParcel(parcelTable); // create Shipment object Console.WriteLine("Creating Shipment object.."); Task.Run(async() => { Shipment shipment = await client.CreateShipment(shipmentTable); // select desired shipping rate according to your business logic // we simply select the first rate in this example Rate rate = shipment.Rates[0]; Console.WriteLine("Getting shipping label.."); var transactionParameters = new CreateTransaction { Rate = rate.ObjectId, Async = false }; Transaction transaction = await client.CreateTransaction(transactionParameters); if (transaction.Status == ShippoEnums.TransactionStatuses.SUCCESS) { Console.WriteLine("Label url : " + transaction.LabelURL); Console.WriteLine("Tracking number : " + transaction.TrackingNumber); } else { Console.WriteLine("An Error has occured while generating your label. Messages : " + transaction.Messages); } Console.WriteLine("\nBatch\n"); await RunBatchExample(client); Console.WriteLine("\nTrack\n"); await RunTrackingExample(client); Console.WriteLine("\nValidating International Address\n"); await RunInternationalAddressValidationExample(client); }).Wait(); }
public async Task <IActionResult> Post([FromBody] CreateParcel command) { await commandDispatcher.DispatchAsync(command); return(CreatedAtAction(nameof(Get), new { id = command.Id }, null)); }
public async Task <IActionResult> Post([FromBody] CreateParcel command) { await _parcelService.CreateAsync(command.Id, command.Name, command.SenderId, command.ReceiverId, command.ReceiverAddress); return(CreatedAtAction(nameof(Get), new { id = command.Id }, null)); }
public async Task <Parcel> CreateParcel(CreateParcel createParcel) { string ep = string.Format("{0}/parcels", apiEndpoint); return(await this.apiClient.DoRequestAsync <Parcel>(ep, HttpMethod.Post, Serialize(createParcel))); }