diff --git a/ShipEngine.Tests/HttpResponseMocks/CreateWarehouse200Response.json b/ShipEngine.Tests/HttpResponseMocks/CreateWarehouse200Response.json new file mode 100644 index 00000000..d2bd4c80 --- /dev/null +++ b/ShipEngine.Tests/HttpResponseMocks/CreateWarehouse200Response.json @@ -0,0 +1,27 @@ +{ + "name": "Example Corp. East Warehouse", + "origin_address": { + "company_name": "Example Corp.", + "name": "John Doe", + "phone": "111-111-1111", + "address_line1": "4009 Marathon Blvd", + "address_line2": "Suite 300", + "city_locality": "Austin", + "state_province": "TX", + "postal_code": "78756", + "country_code": "US", + "address_residential_indicator": "no" + }, + "return_address": { + "company_name": "Example Corp.", + "name": "John Doe", + "phone": "111-111-1111", + "address_line1": "4009 Marathon Blvd", + "address_line2": "Suite 300", + "city_locality": "Austin", + "state_province": "TX", + "postal_code": "78756", + "country_code": "US", + "address_residential_indicator": "no" + } +} \ No newline at end of file diff --git a/ShipEngine.Tests/ShipEngine.Tests.csproj b/ShipEngine.Tests/ShipEngine.Tests.csproj index 64e2bcfd..cdca9e4f 100644 --- a/ShipEngine.Tests/ShipEngine.Tests.csproj +++ b/ShipEngine.Tests/ShipEngine.Tests.csproj @@ -25,6 +25,6 @@ - + diff --git a/ShipEngine.Tests/ShipEngineMethodTests/CreateWarehouseTest.cs b/ShipEngine.Tests/ShipEngineMethodTests/CreateWarehouseTest.cs new file mode 100644 index 00000000..e12e9e24 --- /dev/null +++ b/ShipEngine.Tests/ShipEngineMethodTests/CreateWarehouseTest.cs @@ -0,0 +1,87 @@ +using Moq; +using Newtonsoft.Json; +using ShipEngineSDK; +using ShipEngineSDK.Common.Enums; +using ShipEngineSDK.CreateWarehouse; +using System; +using System.IO; +using System.Net.Http; +using System.Threading.Tasks; +using Xunit; + +namespace ShipEngineTest +{ + public class CreateWarehouseTest + { + + public TestUtils TestUtils; + + public Params Params; + + public CreateWarehouseTest() + { + + Params = new Params() + { + IsDefault = true, + Name = "Warehouse 1", + OriginAddress = new ShipEngineSDK.Common.Address() + { + Name = "John Doe", + AddressLine1 = "4009 Marathon Blvd", + CityLocality = "Austin", + StateProvince = "TX", + PostalCode = "78756", + CountryCode = Country.US, + Phone = "512-555-5555" + }, + ReturnAddress = new ShipEngineSDK.Common.Address() + { + Name = "John Doe", + AddressLine1 = "4009 Marathon Blvd", + CityLocality = "Austin", + StateProvince = "TX", + PostalCode = "78756", + CountryCode = Country.US, + Phone = "512-555-5555" + }, + }; + + TestUtils = new TestUtils(); + } + + [Fact] + public async void ValidCreateWarehouse() + { + var config = new Config("TEST_bTYAskEX6tD7vv6u/cZ/M4LaUSWBJ219+8S1jgFcnkk"); + var mockShipEngineFixture = new MockShipEngineFixture(config); + + string json = File.ReadAllText(Path.Combine(Directory.GetCurrentDirectory(), "../../../HttpResponseMocks/CreateWarehouse200Response.json")); + + mockShipEngineFixture.StubRequest(HttpMethod.Post, "/v1/warehouses", System.Net.HttpStatusCode.OK, json); + + var result = await mockShipEngineFixture.ShipEngine.CreateWarehouse(Params, config); + + Assert.Equal("se-277331", result.WarehouseId); + Assert.Equal("Example Corp. East Warehouse", result.Name); + Assert.Equal("2021-08-27T16:29:56.8779097Z", result.CreatedAt); + } + + [Fact] + public async void InvalidRetriesInMethodCall() + { + var apiKeyString = "TEST_bTYAskEX6tD7vv6u/cZ/M4LaUSWBJ219+8S1jgFcnkk"; + + var config = new Config(apiKey: apiKeyString); + var mockHandler = new Mock(config); + var shipEngine = mockHandler.Object; + + var ex = await Assert.ThrowsAsync(async () => await shipEngine.CreateLabelFromRate(Params, methodConfig: new Config(apiKey: "12345", retries: -1))); + Assert.Equal(ErrorSource.Shipengine, ex.ErrorSource); + Assert.Equal(ErrorType.Validation, ex.ErrorType); + Assert.Equal(ErrorCode.InvalidFieldValue, ex.ErrorCode); + Assert.Equal("Retries must be greater than zero.", ex.Message); + Assert.Null(ex.RequestId); + } + } +} \ No newline at end of file diff --git a/ShipEngine/Models/Dto/CreateWarehouse/Params.cs b/ShipEngine/Models/Dto/CreateWarehouse/Params.cs new file mode 100644 index 00000000..11a79185 --- /dev/null +++ b/ShipEngine/Models/Dto/CreateWarehouse/Params.cs @@ -0,0 +1,16 @@ +namespace ShipEngineSDK.CreateWarehouse +{ + using ShipEngineSDK.Common; + using System; + using System.Collections.Generic; + using System.Text; + + public class Params + { + public bool IsDefault { get; set; } + public string Name { get; set; } + public Address OriginAddress { get; set; } + public Address ReturnAddress { get; set; } + public string WarehouseId { get; set; } + } +} diff --git a/ShipEngine/Models/Dto/CreateWarehouse/Result.cs b/ShipEngine/Models/Dto/CreateWarehouse/Result.cs new file mode 100644 index 00000000..803999d9 --- /dev/null +++ b/ShipEngine/Models/Dto/CreateWarehouse/Result.cs @@ -0,0 +1,12 @@ +namespace ShipEngineSDK.ListWarehouse +{ + using ShipEngineSDK.Warehouse; + using System; + using System.Collections.Generic; + using System.Text; + + public class Result + { + public Warehouse.Result[] Warehouses { get; set; } + } +} diff --git a/ShipEngine/Models/Dto/ImportOrders/Params.cs b/ShipEngine/Models/Dto/ImportOrders/Params.cs new file mode 100644 index 00000000..1457384e --- /dev/null +++ b/ShipEngine/Models/Dto/ImportOrders/Params.cs @@ -0,0 +1,24 @@ +namespace ShipEngineSDK.ImportOrders +{ + using ShipEngineSDK.Common; + using System; + using System.Collections.Generic; + using System.Text; + + public class Params + { + public string OrderSourceId { get; set; } + public string OrderSourceNickname { get; set; } + public string OrderSourceCode { get; set; } + public string OrderSourceFriendlyName { get; set; } + public bool Active { get; set; } + public RefreshInfo RefreshInfo { get; set; } + } + + public class RefreshInfo + { + public string Status { get; set; } + public string LastRefreshAttempt { get; set; } + public string RefreshDate { get; set; } + } +} diff --git a/ShipEngine/Models/Dto/ListManifest/Result.cs b/ShipEngine/Models/Dto/ListManifest/Result.cs new file mode 100644 index 00000000..2a61cf2b --- /dev/null +++ b/ShipEngine/Models/Dto/ListManifest/Result.cs @@ -0,0 +1,18 @@ +#nullable disable + +using ShipEngineSDK.Manifests; +using System.Collections.Generic; + +namespace ShipEngineSDK.ListManifest +{ + /// + /// List Carrier Results + /// + public class Result + { + /// + /// List of carriers associated with the account + /// + public List Manifests { get; set; } + } +} \ No newline at end of file diff --git a/ShipEngine/Models/Dto/ListSalesOrder/Result.cs b/ShipEngine/Models/Dto/ListSalesOrder/Result.cs new file mode 100644 index 00000000..62ac57cd --- /dev/null +++ b/ShipEngine/Models/Dto/ListSalesOrder/Result.cs @@ -0,0 +1,113 @@ +#nullable disable + +using ShipEngineSDK.Common; +using ShipEngineSDK.Common.Enums; +using System; +using System.Collections.Generic; + +namespace ShipEngineSDK.ListSalesOrder +{ + /// + /// List Carrier Results + /// + public class Result + { + public List SalesOrders { get; set; } + public int Total { get; set; } + } + + public class SalesOrder + { + public string SalesOrderId { get; set; } + public string ExternalOrderId { get; set; } + public string ExternalOrderNumber { get; set; } + public OrderSource OrderSource { get; set; } + public SalesOrderStatus SalesOrderStatus { get; set; } + public DateTime? OrderDate { get; set; } + public DateTime? CreatedAt { get; set; } + public DateTime? ModifiedAt { get; set; } + public PaymentDetails PaymentDetails { get; set; } + public Customer Customer { get; set; } + public BillTo BillTo { get; set; } + public Address ShipTo { get; set; } + public SalesOrderItems SalesOrderItems { get; set; } + } + + public class SalesOrderItems + { + public string SalesOrderItemId { get; set; } + public List LineItemDetails { get; set; } + } + + public class LineItemDetails + { + public string Name { get; set; } + public string Sku { get; set; } + public Weight Weight { get; set; } + public Address ShipTo { get; set; } + public RequestedShippingOptions RequestedShippingOptions { get; set; } + public PriceSummary PriceSummary { get; set; } + public int Quantity { get; set; } + public bool IsGift { get; set; } + } + + public class PriceSummary + { + public MonetaryValue UnitPrice { get; set; } + public MonetaryValue EstimatedTax { get; set; } + public string EstimatedShipping { get; set; } + public MonetaryValue Total { get; set; } + } + + public class RequestedShippingOptions + { + public string ShippingSerive { get; set; } + public DateTime? ShipDate { get; set; } + } + + public class BillTo + { + public string Email { get; set; } + public Address Address { get; set; } + } + + public class Customer + { + public string Name { get; set; } + public string Phone { get; set; } + public string Email { get; set; } + } + + public class PaymentDetails + { + public MonetaryValue Subtotal { get; set; } + public MonetaryValue EstimatesShipping { get; set; } + public MonetaryValue EstimatesTax { get; set; } + public MonetaryValue GrandTotal { get; set; } + } + + public class SalesOrderStatus + { + public string PaymentStatus { get; set; } + public string FulfillmentStatus { get; set; } + public bool IsCancelled { get; set; } + } + + public class OrderSource + { + public string OrderSourceId { get; set; } + public string OrderSourceNickname { get; set; } + public string OrderSourceCode { get; set; } + public string OrderSourceFriendlyName { get; set; } + public RefreshInfo RefreshInfo { get; set; } + public bool Active { get; set; } + } + public class RefreshInfo + { + public string Status { get; set; } + public string LastRefreshAttempt { get; set; } + public string RefreshDate { get; set; } + } + + +} \ No newline at end of file diff --git a/ShipEngine/Models/Dto/ListWarehouse/Result.cs b/ShipEngine/Models/Dto/ListWarehouse/Result.cs new file mode 100644 index 00000000..95ae9ea6 --- /dev/null +++ b/ShipEngine/Models/Dto/ListWarehouse/Result.cs @@ -0,0 +1,17 @@ +namespace ShipEngineSDK.ListWarehouse +{ + using ShipEngineSDK.Common; + using System; + using System.Collections.Generic; + using System.Text; + + public class Params + { + public string WarehouseId { get; set; } + public bool IsDefault { get; set; } + public string Name { get; set; } + public string CreatedAt { get; set; } + public Address OriginAddress { get; set; } + public Address ReturnAddress { get; set; } + } +} diff --git a/ShipEngine/Models/Dto/Warehouse/Warehouse.cs b/ShipEngine/Models/Dto/Warehouse/Warehouse.cs new file mode 100644 index 00000000..fc3eabd1 --- /dev/null +++ b/ShipEngine/Models/Dto/Warehouse/Warehouse.cs @@ -0,0 +1,16 @@ +namespace ShipEngineSDK.Warehouse +{ + using ShipEngineSDK.Common; + using System; + using System.Collections.Generic; + using System.Text; + + public class Result + { + public string WarehouseId { get; set; } + public string Name { get; set; } + public string CreatedAt { get; set; } + public Address OriginAddress { get; set; } + public Address ReturnAddress { get; set; } + } +} diff --git a/ShipEngine/ShipEngine.cs b/ShipEngine/ShipEngine.cs index cbdcf2f8..3dc024aa 100644 --- a/ShipEngine/ShipEngine.cs +++ b/ShipEngine/ShipEngine.cs @@ -1,5 +1,6 @@ using Newtonsoft.Json; using ShipEngineSDK.Common; +using ShipEngineSDK.ListWarehouse; using System.Collections.Generic; using System.Net.Http; using System.Threading.Tasks; @@ -112,7 +113,58 @@ public ShipEngine(Config config) : base() return carriers; } + /// + /// List Manifests + /// + /// + public async Task ListManifests() + { + var path = $"/v1/manifests"; + var manifests = await SendHttpRequestAsync(HttpMethod.Get, path, null, _client, _config); + return manifests; + } + /// + /// List Manifests + /// + /// + /// + /// + public async Task ListManifests(string manifestId, Config methodConfig) + { + var client = ConfigureHttpClient(methodConfig, new HttpClient()); + + var path = $"/v1/manifests"; + var manifests = await SendHttpRequestAsync(HttpMethod.Get, path, null, client, methodConfig); + return manifests; + } + + /// + /// Get Created Manifest + /// + /// + /// + public async Task GetManifest(string manifestId) + { + var path = $"/v1/manifests/{manifestId}"; + var manifest = await SendHttpRequestAsync(HttpMethod.Get, path, null, _client, _config); + return manifest; + } + + /// + /// Get Created Manifest + /// + /// + /// + /// + public async Task GetManifest(string manifestId, Config methodConfig) + { + var client = ConfigureHttpClient(methodConfig, new HttpClient()); + + var path = $"/v1/manifests/{manifestId}"; + var manifest = await SendHttpRequestAsync(HttpMethod.Get, path, null, client, methodConfig); + return manifest; + } /// /// Create a manifest @@ -363,5 +415,137 @@ public ShipEngine(Config config) : base() return labelResult; } + + /// + /// Create a warehouse with provided details + /// + /// + /// + public async Task CreateWarehouse(ShipEngineSDK.CreateWarehouse.Params warehouseParams) + { + var path = $"/v1/warehouses"; + + string warehouseParamsString = JsonConvert.SerializeObject(warehouseParams, JsonSerializerSettings); + + var warehosueResult = await SendHttpRequestAsync(HttpMethod.Post, path, warehouseParamsString, _client, _config); + + _client.Dispose(); + + return warehosueResult; + } + /// + /// Creates a warehouse with the provided details + /// + /// + /// + /// + public async Task CreateWarehouse(ShipEngineSDK.CreateWarehouse.Params warehouseParams, Config methodConfig) + { + + var client = ConfigureHttpClient(methodConfig, new HttpClient()); + + var path = $"/v1/warehouses"; + + string warehouseParamsString = JsonConvert.SerializeObject(warehouseParams, JsonSerializerSettings); + + var warehosueResult = await SendHttpRequestAsync(HttpMethod.Post, path, warehouseParamsString, client, methodConfig); + + client.Dispose(); + + return warehosueResult; + } + + /// + /// List all warehouses + /// + /// + public async Task ListWarehouses() + { + var path = "v1/warehouses"; + + var warehouses = await SendHttpRequestAsync(HttpMethod.Get, path, null, _client, _config); + + _client.Dispose(); + return warehouses; + } + /// + /// Get a list of all warehouses + /// + /// + /// + public async Task ListWarehouses(Config methodConfig) + { + var client = ConfigureHttpClient(methodConfig, new HttpClient()); + var path = "v1/warehouses"; + + var warehouses = await SendHttpRequestAsync(HttpMethod.Get, path, null, client, methodConfig); + + client.Dispose(); + return warehouses; + } + + /// + /// Get warehouse by Id + /// + /// + /// + public async Task GetWarehouseByWarehouseId(string warehouseId) + { + var path = $"/v1/warehouse/{warehouseId}"; + + var warehouseInfo = await SendHttpRequestAsync(HttpMethod.Get, path, null, _client, _config); + + _client.Dispose(); + + return warehouseInfo; + } + + /// + /// Get warehouse by Id + /// + /// + /// + /// + public async Task GetWarehouseByWarehouseId(string warehouseId, Config methodConfig) + { + var client = ConfigureHttpClient(methodConfig, new HttpClient()); + + var path = $"/v1/warehouse/{warehouseId}"; + + var warehouseInfo = await SendHttpRequestAsync(HttpMethod.Get, path, null, client, methodConfig); + + client.Dispose(); + + return warehouseInfo; + } + + public async Task ImportOrders(ImportOrders.Params importOrderParams) + { + var path = "/v-beta/order_sources/"; + + string paramString = JsonConvert.SerializeObject(importOrderParams, JsonSerializerSettings); + + await SendHttpRequestAsync(HttpMethod.Put, path, paramString, _client, _config); + _client.Dispose(); + return; + } + public async Task ListSalesOrders(string orderSourceId) + { + try + { + var path = $"/v-beta/sales_orders{orderSourceId}"; + var result = await SendHttpRequestAsync(HttpMethod.Put, path, null, _client, _config); + + _client.Dispose(); + return result; + } + catch (System.Exception ex) + { + + throw; + } + } + + } } \ No newline at end of file