Skip to content

Commit

Permalink
Merge pull request #50 from easykeys/easykeys/bug/amazon/rates
Browse files Browse the repository at this point in the history
Update shipping rate provider and version to 5.2.0
  • Loading branch information
ucrengineer authored Jan 14, 2025
2 parents 312c996 + 9f00f17 commit 82ed50d
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 17 deletions.
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 @@ public AmazonShippingRateProvider(
_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 @@ public async Task<Shipment> GetRatesAsync(Shipment shipment, CancellationToken c
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 @@ public async Task<Shipment> GetRatesAsync(Shipment shipment, CancellationToken c
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 @@ public async Task<Shipment> GetRatesAsync(Shipment shipment, CancellationToken c
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 @@ public async Task<Shipment> GetRatesAsync(Shipment shipment, CancellationToken c
{
Weight = new ()
{
Unit = WeightUnit.POUND
Unit = WeightUnit.POUND,
Value = (double)shipment.Packages.Sum(x => x.Weight)
},
LiquidVolume = new ()
{
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

0 comments on commit 82ed50d

Please sign in to comment.