Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,9 @@ Method to Update Shipment By Shipment ID

Moved Shipment Class to the common models, as it is used in multiple requests.
Updated package class to use the Shipment Package class in Rate Requests.

## 1.3.0

### Added

Create Shipments request
201 changes: 201 additions & 0 deletions ShipEngine.Tests/ShipEngineMethodTests/CreateShipmentsTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,201 @@
using Moq;
using Newtonsoft.Json;
using ShipEngineSDK;
using ShipEngineSDK.Common;
using ShipEngineSDK.Common.Enums;
using ShipEngineSDK.CreateShipments;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net.Http;
using System.Threading.Tasks;
using Xunit;

namespace ShipEngineTest
{
public class CreateShipmentsTest
{
public Params ShipmentParameters;
public TestUtils TestUtils;

public CreateShipmentsTest()
{
TestUtils = new TestUtils();
var Shipments = new List<Shipment>();
Shipment shipment = new Shipment()
{
ServiceCode = "usps_priority_mail",
ShipFrom = new Address()
{
Name = "John Doe",
AddressLine1 = "4009 Marathon Blvd",
CityLocality = "Austin",
StateProvince = "TX",
PostalCode = "78756",
CountryCode = Country.US,
Phone = "512-555-5555"
},
ShipTo = new Address()
{
Name = "Amanda Miller",
AddressLine1 = "525 S Winchester Blvd",
CityLocality = "San Jose",
StateProvince = "CA",
PostalCode = "95128",
CountryCode = Country.US,
Phone = "512-555-5555"
},
Customs = new Customs()
{
NonDelivery = NonDelivery.ReturnToSender,
Contents = PackageContents.Merchandise,
CustomsItems = new List<CustomsItem>()
{
new CustomsItem()
{
Description = "Merchandise",
CountryOfOrigin = Country.US,
Quantity = 1,
UnitOfMeasure = "each",
Value = new MonetaryValue()
{
Amount = 100D,
Currency = Currency.USD
}
}
}
},
Packages = new List<ShipmentPackage>() {
new ShipmentPackage() {
Weight = new Weight() {
Value = 17,
Unit = WeightUnit.Pound
},
Dimensions = new Dimensions() {
Length = 36,
Width = 12,
Height = 24,
Unit = DimensionUnit.Inch,
}
}
},
ValidateAddress = ValidateAddress.ValidateAndClean
};
Shipments.Add(shipment);
ShipmentParameters = new Params()
{
Shipments = Shipments,
};
}

[Fact]
public async void ValidCreateShipmentsTestTest()
{

var config = new Config("TEST_bTYAskEX6tD7vv6u/cZ/M4LaUSWBJ219+8S1jgFcnkk");
var mockShipEngineFixture = new MockShipEngineFixture(config);

string json = File.ReadAllText(Path.Combine(Directory.GetCurrentDirectory(), "../../../HttpResponseMocks/UpdateShipmentByID200Response.json"));

mockShipEngineFixture.StubRequest(HttpMethod.Put, "/v1/shipments/se-153814671", System.Net.HttpStatusCode.OK, json);

var resultCreate = await mockShipEngineFixture.ShipEngine.CreateShipments(ShipmentParameters);
var result = resultCreate.Shipments.First();
Assert.Equal("se-153814671", result.ShipmentId);
Assert.Equal("se-423888", result.CarrierId);
Assert.Equal("ups_ground", result.ServiceCode);
Assert.Null(result.ExternalShipmentId);
Assert.Equal("2021-08-27T00:00:00Z", result.ShipDate);
Assert.Equal("2021-08-27T16:29:25.257Z", result.CreatedAt);
Assert.Equal("2021-08-27T16:29:25.24Z", result.ModifiedAt);
Assert.Equal(ShipmentStatus.Pending, result.ShipmentStatus);

Assert.Equal("Amanda Miller", result.ShipTo.Name);
Assert.Null(result.ShipTo.Phone);
Assert.Null(result.ShipTo.CompanyName);
Assert.Equal("525 S Winchester Blvd", result.ShipTo.AddressLine1);
Assert.Null(result.ShipTo.AddressLine2);
Assert.Null(result.ShipTo.AddressLine3);
Assert.Equal("San Jose", result.ShipTo.CityLocality);
Assert.Equal("CA", result.ShipTo.StateProvince);
Assert.Equal("95128", result.ShipTo.PostalCode);
Assert.Equal(Country.US, result.ShipTo.CountryCode);
Assert.Equal(AddressResidentialIndicator.Unknown, result.ShipTo.AddressResidentialIndicator);

Assert.Equal("John Doe", result.ShipFrom.Name);
Assert.Equal("512-555-5555", result.ShipFrom.Phone);
Assert.Empty(result.ShipFrom.CompanyName);
Assert.Equal("4009 Marathon Blvd", result.ShipFrom.AddressLine1);
Assert.Null(result.ShipFrom.AddressLine2);
Assert.Null(result.ShipFrom.AddressLine3);
Assert.Equal("Austin", result.ShipFrom.CityLocality);
Assert.Equal("TX", result.ShipFrom.StateProvince);
Assert.Equal(AddressResidentialIndicator.Unknown, result.ShipFrom.AddressResidentialIndicator);

Assert.Null(result.WarehouseId);

Assert.Equal("John Doe", result.ReturnTo.Name);
Assert.Equal("512-555-5555", result.ReturnTo.Phone);
Assert.Empty(result.ReturnTo.CompanyName);
Assert.Equal("4009 Marathon Blvd", result.ReturnTo.AddressLine1);
Assert.Null(result.ReturnTo.AddressLine2);
Assert.Null(result.ReturnTo.AddressLine3);
Assert.Equal("Austin", result.ReturnTo.CityLocality);
Assert.Equal("TX", result.ReturnTo.StateProvince);
Assert.Equal(AddressResidentialIndicator.Unknown, result.ReturnTo.AddressResidentialIndicator);

Assert.Equal(DeliveryConfirmation.None, result.Confirmation);

Assert.Equal(PackageContents.Merchandise, result.Customs.Contents);
Assert.NotEmpty(result.Customs.CustomsItems);
Assert.Equal(100D, result.Customs.CustomsItems.First().Value.Amount);
Assert.Equal(NonDelivery.ReturnToSender, result.Customs.NonDelivery);

Assert.Null(result.ExternalOrderId);
Assert.Null(result.OrderSourceCode);

Assert.Null(result.AdvancedOptions.BillToAccount);
Assert.Null(result.AdvancedOptions.BillToCountryCode);
Assert.Null(result.AdvancedOptions.BillToParty);
Assert.Null(result.AdvancedOptions.BillToPostalCode);
Assert.False(result.AdvancedOptions.ContainsAlcohol);
Assert.False(result.AdvancedOptions.DeliveredDutyPaid);
Assert.False(result.AdvancedOptions.NonMachinable);
Assert.False(result.AdvancedOptions.SaturdayDelivery);
Assert.False(result.AdvancedOptions.DryIce);
Assert.Null(result.AdvancedOptions.DryIceWeight);
Assert.Null(result.AdvancedOptions.FedexFreight);
Assert.Null(result.AdvancedOptions.FreightClass);
Assert.Null(result.AdvancedOptions.CustomField1);
Assert.Null(result.AdvancedOptions.CustomField2);
Assert.Null(result.AdvancedOptions.CustomField3);
Assert.Null(result.AdvancedOptions.CollectOnDelivery);

Assert.Equal(InsuranceProvider.None, result.InsuranceProvider);
Assert.Empty(result.Tags);

Assert.Equal("package", result.Packages[0].PackageCode);
Assert.Equal(17.0, result.Packages[0].Weight.Value);
Assert.Equal(WeightUnit.Pound, result.Packages[0].Weight.Unit);
Assert.Equal(DimensionUnit.Inch, result.Packages[0].Dimensions.Unit);
Assert.Equal(12, result.Packages[0].Dimensions.Width);
Assert.Equal(36, result.Packages[0].Dimensions.Length);
Assert.Equal(24, result.Packages[0].Dimensions.Height);

Assert.Equal(Currency.USD, result.Packages[0].InsuredValue.Currency);
Assert.Equal(0, result.Packages[0].InsuredValue.Amount);

Assert.Null(result.Packages[0].LabelMessages.Reference1);
Assert.Null(result.Packages[0].LabelMessages.Reference2);
Assert.Null(result.Packages[0].LabelMessages.Reference3);

Assert.Null(result.Packages[0].ExternalPackageId);

Assert.Equal(17.0, result.TotalWeight.Value);
Assert.Equal(WeightUnit.Pound, result.TotalWeight.Unit);
Assert.Empty(result.Items);

}
}
}
21 changes: 21 additions & 0 deletions ShipEngine/Models/Dto/CreateShipments/Params.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@

#nullable disable

using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using ShipEngineSDK.Common;
using ShipEngineSDK.Common.Enums;
using System.Collections.Generic;

namespace ShipEngineSDK.CreateShipments
{


public class Params
{
/// <summary>
/// An array of shipments to be created
/// </summary>
public List<Shipment> Shipments { get; set; }
}
}
151 changes: 151 additions & 0 deletions ShipEngine/Models/Dto/CreateShipments/Result.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
using ShipEngineSDK.Common;
using ShipEngineSDK.Common.Enums;
using System;
using System.Collections.Generic;

namespace ShipEngineSDK.CreateShipments
{

public class Result
{
/// <summary>
/// Indicates if errors occured while creating the shipments
/// </summary>
public Boolean? HasErrors { get; set; }

/// <summary>
/// An array of shipments that were created
/// </summary>
public List<ShipmentResult> Shipments { get; set; }
}

public class ShipmentResult
{
/// <summary>
/// A string that uniquely identifies the shipment
/// </summary>
public string? ShipmentId { get; set; }

/// <summary>
/// The carrier account that is billed for the shipping charges
/// </summary>
public string? CarrierId { get; set; }

/// <summary>
/// The carrier service used to ship the package
/// </summary>
public string? ServiceCode { get; set; }

/// <summary>
/// ID that the Order Source assigned
/// </summary>
public string? ExternalOrderId { get; set; }

/// <summary>
/// Describe the packages included in this shipment as related to potential metadata that was imported from external order sources
/// </summary>
public List<ShipmentItem> Items { get; set; }

/// <summary>
/// Tax identifiers
/// </summary>
public List<TaxIdentifier> TaxIdentifiers { get; set; }

/// <summary>
/// You can optionally use this field to store your own identifier for this shipment.
/// </summary>
public string? ExternalShipmentId { get; set; }

/// <summary>
/// The date that the shipment was (or will be) shippped. ShipEngine will take the day of week into consideration.
/// For example, if the carrier does not operate on Sundays, then a package that would have shipped on Sunday will ship on Monday instead.
/// </summary>
public string? ShipDate { get; set; }

/// <summary>
/// The date and time that the shipment was created in ShipEngine.
/// </summary>
public string? CreatedAt { get; set; }
/// <summary>
/// The date and time that the shipment was created or last modified.
/// </summary>
public string? ModifiedAt { get; set; }

/// <summary>
/// The current status of the shipment
/// </summary>
public ShipmentStatus ShipmentStatus { get; set; }

/// <summary>
/// The recipient's mailing address
/// </summary>
public Address ShipTo { get; set; }

/// <summary>
/// The shipment's origin address. If you frequently ship from the same location, consider creating a warehouse.
/// Then you can simply specify the warehouse_id rather than the complete address each time.
/// </summary>
public Address ShipFrom { get; set; }

/// <summary>
/// The warehouse that the shipment is being shipped from. Either warehouse_id or ship_from must be specified.
/// </summary>
public string? WarehouseId { get; set; }

/// <summary>
/// The return address for this shipment. Defaults to the ship_from address.
/// </summary>
public Address ReturnTo { get; set; }

/// <summary>
/// The type of delivery confirmation that is required for this shipment.
/// </summary>
public DeliveryConfirmation Confirmation { get; set; }

/// <summary>
/// Customs information. This is usually only needed for international shipments.
/// </summary>
public Customs Customs { get; set; }

/// <summary>
/// Advanced shipment options. These are entirely optional.
/// </summary>
public AdvancedShipmentOptions AdvancedOptions { get; set; }

/// <summary>
/// Indicates if the package will be picked up or dropped off by the carrier
/// </summary>
public OriginType OriginType { get; set; }

/// <summary>
/// The insurance provider to use for any insured packages in the shipment.
/// </summary>
public InsuranceProvider InsuranceProvider { get; set; }

/// <summary>
/// Arbitrary tags associated with this shipment. Tags can be used to categorize shipments, and shipments can be queried by their tags.
/// </summary>
public List<string> Tags { get; set; }


/// <summary>
/// Total Weight of the Shipment
/// </summary>
public Weight TotalWeight { get; set; }

/// <summary>
/// The order sources that are supported by ShipEngine
/// </summary>
public OrderSourceCode? OrderSourceCode { get; set; }

/// <summary>
/// The packages in the shipment.
/// </summary>
public List<ShipmentPackage> Packages { get; set; }

/// <summary>
/// The address validation.
/// </summary>
public ValidateAddresses.Result AddressValidation { get; set; }
}
}
1 change: 1 addition & 0 deletions ShipEngine/Properties/PublishProfiles/Release.pubxml
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ https://go.microsoft.com/fwlink/?LinkID=208121.
<Platform>Any CPU</Platform>
<PublishDir>bin\Release\netstandard2.0\publish\</PublishDir>
<PublishProtocol>FileSystem</PublishProtocol>
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>
</Project>
Loading