Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update shipping rate provider and version to 5.2.0 #50

Merged
merged 2 commits into from
Jan 14, 2025
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
2 changes: 1 addition & 1 deletion GitVersion.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
mode: Mainline
next-version: 5.1.0
next-version: 5.2.0
branches:
feature:
tag: preview
Expand Down
22 changes: 13 additions & 9 deletions src/EasyKeys.Shipping.Amazon.Rates/AmazonShippingRateProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using EasyKeys.Shipping.Amazon.Abstractions.OpenApis.V2.Shipping;
using EasyKeys.Shipping.Amazon.Abstractions.Options;
using EasyKeys.Shipping.Amazon.Abstractions.Services;
using EasyKeys.Shipping.Amazon.Rates.Models;

using Microsoft.Extensions.Logging;

Expand All @@ -27,7 +28,7 @@
_shippingApi.BaseUrl = _options.IsDevelopment ? _shippingApi.BaseUrl : "https://sellingpartnerapi-na.amazon.com";
}

public async Task<Shipment> GetRatesAsync(Shipment shipment, CancellationToken cancellationToken = default)
public async Task<Shipment> GetRatesAsync(Shipment shipment,RateContactInfo rateContactInfo, CancellationToken cancellationToken = default)

Check warning on line 31 in src/EasyKeys.Shipping.Amazon.Rates/AmazonShippingRateProvider.cs

View workflow job for this annotation

GitHub Actions / build

{
try
{
Expand All @@ -36,14 +37,16 @@
ShipDate = shipment.Options.ShippingDate.ToString("yyyy-MM-dd'T'HH:mm:ss'Z'"),
ShipTo = new Abstractions.OpenApis.V2.Shipping.Address()
{
Name = "unknown name",
AddressLine1 = shipment.DestinationAddress.StreetLine,
AddressLine2 = shipment.DestinationAddress.StreetLine2,
StateOrRegion = shipment.DestinationAddress.StateOrProvince,
City = shipment.DestinationAddress.City,
CountryCode = shipment.DestinationAddress.CountryCode,
PostalCode = shipment.DestinationAddress.PostalCode,
PhoneNumber = "unknown phone number"
Name = rateContactInfo.RecipientContact.FullName,
Email = rateContactInfo.RecipientContact.Email,
CompanyName = rateContactInfo.RecipientContact.Company,
PhoneNumber = rateContactInfo.RecipientContact.PhoneNumber
},
ShipFrom = new Abstractions.OpenApis.V2.Shipping.Address()
{
Expand All @@ -53,10 +56,10 @@
City = shipment.OriginAddress.City,
CountryCode = shipment.OriginAddress.CountryCode,
PostalCode = shipment.OriginAddress.PostalCode,
Name = "Easykeys fullfuilment team",
Email = "[email protected]",
CompanyName = "EasyKeys",
PhoneNumber = "unknown phone number"
Name = rateContactInfo.SenderContact.FullName,
Email = rateContactInfo.SenderContact.Email,
CompanyName = rateContactInfo.SenderContact.Company,
PhoneNumber = rateContactInfo.SenderContact.PhoneNumber
},
Packages = new ()
{
Expand All @@ -72,7 +75,7 @@
Weight = new ()
{
Unit = WeightUnit.POUND,
Value = (double)shipment.Packages.Sum(x => x.RoundedWeight)
Value = (double)shipment.Packages.Sum(x => x.Weight)
},
InsuredValue = new ()
{
Expand All @@ -86,7 +89,8 @@
{
Weight = new ()
{
Unit = WeightUnit.POUND
Unit = WeightUnit.POUND,
Value = (double)shipment.Packages.Sum(x => x.Weight)
},
LiquidVolume = new ()
{
Expand Down Expand Up @@ -127,7 +131,7 @@
shipment.InternalErrors.Add($"{error.Message}-{error.Details}");
}

_logger.LogError(ex, $"Error getting rates from Amazon Shipping API: {string.Join(",",ex.Result.Errors)}");

Check warning on line 134 in src/EasyKeys.Shipping.Amazon.Rates/AmazonShippingRateProvider.cs

View workflow job for this annotation

GitHub Actions / build

}
catch (ApiException ex)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
using EasyKeys.Shipping.Abstractions.Models;
using EasyKeys.Shipping.Amazon.Rates.Models;

namespace EasyKeys.Shipping.Amazon.Rates;

public interface IAmazonShippingRateProvider
{
Task<Shipment> GetRatesAsync(Shipment shipment, CancellationToken cancellationToken = default);
Task<Shipment> GetRatesAsync(Shipment shipment, RateContactInfo rateContactInfo, CancellationToken cancellationToken = default);
}
16 changes: 16 additions & 0 deletions src/EasyKeys.Shipping.Amazon.Rates/Models/RateContactInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using EasyKeys.Shipping.Abstractions.Models;

namespace EasyKeys.Shipping.Amazon.Rates.Models;

public class RateContactInfo
{
public ContactInfo SenderContact { get; set; } = new ();

public ContactInfo RecipientContact { get; set; } = new ();
}
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public async Task<ShipmentLabel> CreateSmartShipmentAsync(
Weight = new ()
{
Unit = WeightUnit.POUND,
Value = (double)shipment.Packages.Sum(x => x.RoundedWeight)
Value = (double)shipment.Packages.Sum(x => x.Weight)
},
InsuredValue = new ()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ public AmazonShippingRateProviderTests(ITestOutputHelper output)
public async Task Return_Shipment_With_Rates_Successfully()
{
var shipment = TestShipments.CreateDomesticShipment();

var result = await _rateProvider.GetRatesAsync(shipment, CancellationToken.None);
var (sender, recipient) = TestShipments.CreateContactInfo();
var result = await _rateProvider.GetRatesAsync(shipment, new () { SenderContact = sender, RecipientContact = recipient }, CancellationToken.None);

Assert.NotNull(result);

Expand Down
6 changes: 3 additions & 3 deletions test/EasyKeys.Shipping.FuncTest/TestHelpers/TestShipments.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ public static Shipment CreateDomesticShipment()
new Package(
new Dimensions()
{
Height = 20.00M,
Width = 15.00M,
Length = 12.00M
Height = 9.00M,
Width = 6.00M,
Length = 1.00M
},
.0625M),
};
Expand Down
Loading