Skip to content

Commit

Permalink
Merged in GUARD-702-Split-Orders-Feature-Overwrites-Order (pull request
Browse files Browse the repository at this point in the history
#4)

2020-07-22 GUARD-673 GUARD-702 Split-Orders-Feature-Overwrites-Order

Approved-by: Maxim Strelsov
  • Loading branch information
fabulaspb committed Aug 14, 2020
2 parents 4797432 + 1783aac commit c4bc73b
Show file tree
Hide file tree
Showing 12 changed files with 271 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/Global/GlobalAssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@
// [assembly: AssemblyVersion("1.0.*")]

// Keep in track with CA API version
[ assembly : AssemblyVersion( "1.3.84.0" ) ]
[ assembly : AssemblyVersion( "1.4.1.0" ) ]
2 changes: 2 additions & 0 deletions src/ShipStationAccess/ShipStationAccess.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,11 @@
<Compile Include="V2\Models\Order\ShipStationCustomItems.cs" />
<Compile Include="V2\Models\Order\ShipStationOrderAdvancedOptions.cs" />
<Compile Include="V2\Models\Order\ShipStationOrderDimensions.cs" />
<Compile Include="V2\Models\Order\ShipStationOrderFulfillment.cs" />
<Compile Include="V2\Models\Order\ShipStationOrderInsuranceOptions.cs" />
<Compile Include="V2\Models\Order\ShipStationOrderInternationalOptions.cs" />
<Compile Include="V2\Models\Order\ShipStationOrders.cs" />
<Compile Include="V2\Models\Order\ShipStationOrderShipment.cs" />
<Compile Include="V2\Models\Register\ShipStationRegister.cs" />
<Compile Include="V2\Models\Register\ShipStationRegisterResponse.cs" />
<Compile Include="V2\Models\ShippingLabel\ShipStationShippingLabel.cs" />
Expand Down
2 changes: 2 additions & 0 deletions src/ShipStationAccess/V2/IShipStationService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ public interface IShipStationService

ShipStationOrder GetOrderById( string orderId );
Task< ShipStationOrder > GetOrderByIdAsync( string orderId );
Task< IEnumerable< ShipStationOrderShipment > > GetOrderShipmentsByIdAsync( string orderId );
Task< IEnumerable< ShipStationOrderFulfillment > > GetOrderFulfillmentsByIdAsync( string orderId );

void UpdateOrder( ShipStationOrder order );
Task UpdateOrderAsync( ShipStationOrder order );
Expand Down
3 changes: 3 additions & 0 deletions src/ShipStationAccess/V2/Models/Command/ShipStationCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ internal sealed class ShipStationCommand
public static readonly ShipStationCommand GetStores = new ShipStationCommand( "/Stores" );
public static readonly ShipStationCommand GetShippingLabel = new ShipStationCommand( "/Orders/CreateLabelForOrder" );
public static readonly ShipStationCommand Register = new ShipStationCommand( "/Integratedapp/Register" );
public static readonly ShipStationCommand GetOrderShipments = new ShipStationCommand( "/Shipments" );
public static readonly ShipStationCommand GetOrderFulfillments = new ShipStationCommand( "/Fulfillments" );

private ShipStationCommand( string command )
{
this.Command = command;
Expand Down
3 changes: 2 additions & 1 deletion src/ShipStationAccess/V2/Models/Command/ShipStationParam.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ internal sealed class ShipStationParam
public static readonly ShipStationParam ServiceCode = new ShipStationParam( "serviceCode" );
public static readonly ShipStationParam Confirmation = new ShipStationParam( "confirmation" );
public static readonly ShipStationParam ShipDate = new ShipStationParam( "shipDate" );

public static readonly ShipStationParam OrderId = new ShipStationParam( "orderId" );
public static readonly ShipStationParam IncludeShipmentItems = new ShipStationParam( "includeShipmentItems" );

private ShipStationParam( string name )
{
Expand Down
4 changes: 4 additions & 0 deletions src/ShipStationAccess/V2/Models/Order/ShipStationOrder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@ [ DataMember( Name = "advancedOptions" ) ]
[ DataMember( Name = "tagIds" ) ]
public IList< long > TagsIds { get; set; }

public IEnumerable< ShipStationOrderShipment > Shipments { get; set; }

public IEnumerable< ShipStationOrderFulfillment > Fulfillments { get; set; }

public int MarketplaceId{ get; set; }

public string MarketplaceName{ get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ [ DataMember( Name = "mergedOrSplit" ) ]
[ DataMember( Name = "mergedIds" ) ]
public IList< long > MergedIds{ get; set; }

[ DataMember( Name = "parentId" ) ]
public long? ParentId { get; set; }

[ DataMember( Name = "billToParty" ) ]
public string BillToParty{ get; set; }

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
using System;
using System.Collections.Generic;
using System.Runtime.Serialization;

namespace ShipStationAccess.V2.Models.Order
{
[ DataContract ]
public sealed class ShipStationOrderFulfillments
{
[ DataMember( Name = "fulfillments" ) ]
public IEnumerable< ShipStationOrderFulfillment > Fulfillments { get; set; }

[ DataMember( Name = "total" ) ]
public int Total { get; set; }

[ DataMember( Name = "page" ) ]
public int Page { get; set; }

[ DataMember( Name = "pages" ) ]
public int Pages { get; set; }
}

[ DataContract ]
public sealed class ShipStationOrderFulfillment
{
[ DataMember( Name = "fulfillmentId" ) ]
public long Id { get; set; }

[ DataMember( Name = "orderId" ) ]
public long OrderId { get; set; }

[ DataMember( Name = "trackingNumber" ) ]
public string TrackingNumber { get; set; }

[ DataMember( Name = "createDate" ) ]
public DateTime CreateDate { get; set; }

[ DataMember( Name = "shipDate" ) ]
public DateTime ShipDate { get; set; }

[ DataMember( Name = "deliveryDate" ) ]
public DateTime? DeliveryDate { get; set; }

[ DataMember( Name = "carrierCode" ) ]
public string CarrierCode { get; set; }

[ DataMember( Name = "voided" ) ]
public bool Voided { get; set; }
}
}
104 changes: 104 additions & 0 deletions src/ShipStationAccess/V2/Models/Order/ShipStationOrderShipment.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
using System;
using System.Collections.Generic;
using System.Runtime.Serialization;

namespace ShipStationAccess.V2.Models.Order
{
[ DataContract ]
public sealed class ShipStationOrderShipments
{
[ DataMember( Name = "shipments" ) ]
public IEnumerable< ShipStationOrderShipment > Shipments { get; set; }

[ DataMember( Name = "total" ) ]
public int Total { get; set; }

[ DataMember( Name = "page" ) ]
public int Page { get; set; }

[ DataMember( Name = "pages" ) ]
public int Pages { get; set; }
}

[ DataContract ]
public sealed class ShipStationOrderShipment
{
[ DataMember( Name = "shipmentId" ) ]
public long Id { get; set; }

[ DataMember( Name = "orderId" ) ]
public long OrderId { get; set; }

[ DataMember( Name = "createDate" ) ]
public DateTime CreateDate { get; set; }

[ DataMember( Name = "shipDate" ) ]
public DateTime? ShipDate { get; set; }

[ DataMember( Name = "shipmentCost" ) ]
public decimal Cost { get; set; }

[ DataMember( Name = "insuranceCost" ) ]
public decimal InsuranceCost { get; set; }

[ DataMember( Name = "trackingNumber" ) ]
public string TrackingNumber { get; set; }

[ DataMember( Name = "carrierCode" ) ]
public string CarrierCode { get; set; }

[ DataMember( Name = "serviceCode" ) ]
public string ServiceCode { get; set; }

[ DataMember( Name = "confirmation" ) ]
public string Confirmation { get; set; }

[ DataMember( Name = "voided" ) ]
public bool Voided { get; set; }

[ DataMember( Name = "weight" ) ]
public ShipmentWeight Weight { get; set; }

[ DataMember( Name = "dimensions" ) ]
public ShipmentDimensions Dimensions { get; set; }

[ DataMember( Name = "shipmentItems" ) ]
public IEnumerable< ShipmentItem > Items { get; set; }
}

[ DataContract ]
public sealed class ShipmentWeight
{
[ DataMember( Name = "value" ) ]
public decimal Value { get; set; }

[ DataMember( Name = "units" ) ]
public string Units { get; set; }
}

[ DataContract ]
public sealed class ShipmentDimensions
{
[ DataMember( Name = "units" ) ]
public string Units { get; set; }

[ DataMember( Name = "length" ) ]
public decimal Length { get; set; }

[ DataMember( Name = "width" ) ]
public decimal Width { get; set; }

[ DataMember( Name = "height" ) ]
public decimal Height { get; set; }
}

[ DataContract ]
public sealed class ShipmentItem
{
[ DataMember( Name = "sku" ) ]
public string Sku { get; set; }

[ DataMember( Name = "quantity" ) ]
public int Quantity { get; set; }
}
}
13 changes: 13 additions & 0 deletions src/ShipStationAccess/V2/Services/ParamsBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,19 @@ public static string CreateStoreIdOrderNumberParams( string storeId, string orde
return endpoint;
}

public static string CreateOrderShipmentsParams( string orderId, bool includeShipmentItems = true )
{
var endpoint = string.Format( "?{0}={1}&{2}={3}",
ShipStationParam.OrderId.Name, orderId,
ShipStationParam.IncludeShipmentItems.Name, includeShipmentItems );
return endpoint;
}

public static string CreateOrderFulfillmentsParams( string orderId )
{
return string.Format( "?{0}={1}", ShipStationParam.OrderId.Name, orderId );
}

public static string CreateGetNextPageParams( ShipStationCommandConfig config )
{
var endpoint = string.Format( "?{0}={1}&{2}={3}",
Expand Down
67 changes: 67 additions & 0 deletions src/ShipStationAccess/V2/ShipStationService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,9 @@ public async Task< IEnumerable< ShipStationOrder > > GetOrdersAsync( DateTime da

foreach( var order in processedOrders )
{
order.Shipments = await GetOrderShipmentsByIdAsync( order.OrderId.ToString() ).ConfigureAwait( false );
order.Fulfillments = await GetOrderFulfillmentsByIdAsync( order.OrderId.ToString() ).ConfigureAwait( false );

orders.Add( order );
processedOrderIds.Add( order.OrderId );
}
Expand Down Expand Up @@ -300,6 +303,70 @@ await ActionPolicies.GetAsync.Do( async () =>

return order;
}

public async Task< IEnumerable< ShipStationOrderShipment > > GetOrderShipmentsByIdAsync( string orderId )
{
var orderShipments = new List< ShipStationOrderShipment >();

var currentPage = 1;
var pagesCount = int.MaxValue;

do
{
var getOrderShipmentsEndpoint = ParamsBuilder.CreateOrderShipmentsParams( orderId );
var nextPageParams = ParamsBuilder.CreateGetNextPageParams( new ShipStationCommandConfig( currentPage, RequestMaxLimit ) );
var orderShipmentsByPageEndPoint = getOrderShipmentsEndpoint.ConcatParams( nextPageParams );

await ActionPolicies.GetAsync.Do( async () =>
{
var orderShipmentsPage = await this._webRequestServices.GetResponseAsync< ShipStationOrderShipments >( ShipStationCommand.GetOrderShipments, orderShipmentsByPageEndPoint );

++currentPage;
if ( pagesCount == int.MaxValue )
{
pagesCount = orderShipmentsPage.Pages + 1;
}

orderShipments.AddRange( orderShipmentsPage.Shipments );

} );
}
while( currentPage <= pagesCount );

return orderShipments;
}

public async Task< IEnumerable< ShipStationOrderFulfillment > > GetOrderFulfillmentsByIdAsync( string orderId )
{
var orderFulfillments = new List< ShipStationOrderFulfillment >();

var currentPage = 1;
var pagesCount = int.MaxValue;

do
{
var getOrderFulfillmentsEndpoint = ParamsBuilder.CreateOrderFulfillmentsParams( orderId );
var nextPageParams = ParamsBuilder.CreateGetNextPageParams( new ShipStationCommandConfig( currentPage, RequestMaxLimit ) );
var orderFulfillmentsByPageEndPoint = getOrderFulfillmentsEndpoint.ConcatParams( nextPageParams );

await ActionPolicies.GetAsync.Do( async () =>
{
var orderFulfillmentsPage = await this._webRequestServices.GetResponseAsync< ShipStationOrderFulfillments >( ShipStationCommand.GetOrderFulfillments, orderFulfillmentsByPageEndPoint );

++currentPage;
if ( pagesCount == int.MaxValue )
{
pagesCount = orderFulfillmentsPage.Pages + 1;
}

orderFulfillments.AddRange( orderFulfillmentsPage.Fulfillments );

} );
}
while( currentPage <= pagesCount );

return orderFulfillments;
}
#endregion

#region Update Orders
Expand Down
20 changes: 20 additions & 0 deletions src/ShipStationAccessTests/Orders/OrderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ public class OrderTests
{
private readonly IShipStationFactory ShipStationFactory = new ShipStationFactory();
private ShipStationCredentials _credentials;
private string _testOrderWithShipments = "564221696";
private string _testOrderWithFulfillments = "576752152";

[ SetUp ]
public void Init()
Expand Down Expand Up @@ -56,6 +58,24 @@ public async Task GetOrdersAsync()
orders.Count().Should().BeGreaterThan( 0 );
}

[ Test ]
public async Task GetOrderShipmentsAsync()
{
var service = this.ShipStationFactory.CreateServiceV2( this._credentials );
var orderShipments = await service.GetOrderShipmentsByIdAsync( this._testOrderWithShipments );

orderShipments.Count().Should().BeGreaterThan( 0 );
}

[ Test ]
public async Task GetOrderFulfillmentsAsync()
{
var service = this.ShipStationFactory.CreateServiceV2( this._credentials );
var orderFulfillments = await service.GetOrderFulfillmentsByIdAsync( this._testOrderWithFulfillments );

orderFulfillments.Count().Should().BeGreaterThan( 0 );
}

[ Test ]
public void GetTags()
{
Expand Down

0 comments on commit c4bc73b

Please sign in to comment.