public override void When(ShipmentCommands.Import c) { var shipment = new CreateShipment(); shipment.ShipmentId = c.ShipmentId; shipment.ShipmentTypeId = c.ShipmentTypeId; shipment.OriginFacilityId = c.OriginFacilityId; shipment.DestinationFacilityId = c.DestinationFacilityId; shipment.PartyIdFrom = c.PartyIdFrom; shipment.PartyIdTo = c.PartyIdTo; if (c.ShipmentTypeId == ShipmentTypeIds.PurchaseShipment || c.ShipmentTypeId == ShipmentTypeIds.IncomingShipment) { shipment.StatusId = StatusItemIds.PurchShipCreated; } else { shipment.StatusId = StatusItemIds.ShipmentInput; } //todo More properties... var shipItems = new List <ICreateShipmentItem>(); int i = 0; foreach (var d in c.ShipmentItems) { var shipItem = CreateShipmentItem(i, d); shipment.ShipmentItems.Add(shipItem); i++; } When(shipment); }
public static async Task <Shipment> GetDefaultObject() { Address addressFrom = await AddressTest.GetDefaultObject(); Address addressTo = await AddressTest.GetDefaultObject2(); Parcel parcel = await ParcelTest.GetDefaultObject(); var parameters = new CreateShipment { AddressFrom = addressFrom.ObjectId, AddressTo = addressTo.ObjectId, Async = false, Metadata = "Customer ID 123456", ShipmentDate = DateTime.Now }; parameters.AddParcel(parcel.ObjectId); parameters.CustomsDeclaration = ""; parameters.Extra = new ShipmentExtra { Insurance = new ShipmentExtraInsurance { Amount = 30, Currency = "USD" }, SignatureConfirmation = ShippoEnums.SignatureConfirmations.STANDARD }; return(await GetShippoClient().CreateShipment(parameters)); }
public static async Task <Manifest> GetDefaultObject(BaseAddress addressTo) { var parameters0 = new CreateShipment(); Address addressFrom = await AddressTest.GetDefaultObject(); Parcel parcel = await ParcelTest.GetDefaultObject(); parameters0.AddressFrom = addressFrom.ObjectId; parameters0.AddressTo = addressTo; parameters0.AddParcel(parcel.ObjectId); parameters0.ShipmentDate = DateTime.Now; parameters0.CustomsDeclaration = ""; parameters0.Extra = new ShipmentExtra { Insurance = new ShipmentExtraInsurance { Amount = 30, Currency = "USD" }, SignatureConfirmation = ShippoEnums.SignatureConfirmations.STANDARD }; parameters0.Metadata = "Customer ID 123456"; parameters0.Async = false; Shipment shipment = await GetShippoClient().CreateShipment(parameters0); ShippoCollection <Rate> rateCollection = await GetShippoClient().GetShippingRatesSync(shipment.ObjectId, "USD"); List <Rate> rateList = rateCollection.Data; Rate[] rateArray = rateList.ToArray(); var createTransaction = new CreateTransaction { Rate = rateArray[0].ObjectId, Metadata = "Customer ID 123456" }; Transaction transaction = await GetShippoClient().CreateTransactionSync(createTransaction); var parameters2 = new CreateManifest { ShipmentDate = DateTime.Now, AddressFromObjectId = addressFrom.ObjectId, Provider = "usps" }; var transactions = new List <string>(); transactions.Add(transaction.ObjectId); parameters2.TransactionsIds = transactions.ToArray(); return(await GetShippoClient().CreateManifest(parameters2)); }
public void Handle( CreateShipment c) { // example of DomainValidationException if (c.Address.StartsWith("1")) { throw new DomainValidationException($"Can't create shipment with address {c.Address}"); } _shipments.Perform( c.Id, shipment => shipment.CreateShipment(c.Id, c.Metadata, c.Address), c.Metadata); }
public async Task <Shipment> CreateShipment(CreateShipment shipment) { var content = new StringContent(JsonHelper.Serialize(shipment, "yyyy-MM-dd"), Encoding.UTF8, "application/json"); var response = await _httpClient.PostAsync($"shipment?api_token={_apiKey}", content).ConfigureAwait(false); var jsonResult = await response.Content.ReadAsStringAsync().ConfigureAwait(false); if (response.IsSuccessStatusCode) { return(JsonHelper.Deserialize <Shipment>(jsonResult)); } HandleResponseError(response); return(null); }
public void Post([FromBody] string address) { var command = new CreateShipment { Id = Guid.NewGuid().ToString(), Address = address, Metadata = new CommandMetadata { CommandId = Guid.NewGuid().ToString(), ConnectionId = Request.Headers["Connection-Id"] } }; _commandBus.Send(command); }
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 <VismaActionResult> CreateShipment(string entityNumber, CreateShipment cs) { return(await VismaNetApiHelper.Action(Authorization, ApiControllerUri, entityNumber, "createShipment", cs)); }
public async Task HandleAsync(CreateShipment command) { await Repository.SaveAsync(Shipment.Create(Guid.NewGuid(), command.CustomerId, command.ShippingItems)); }
public async Task <Shipment> CreateShipment(CreateShipment createShipment) { string ep = string.Format("{0}/shipments", apiEndpoint); return(await this.apiClient.DoRequestAsync <Shipment>(ep, HttpMethod.Post, Serialize(createShipment))); }