Skip to content

Commit

Permalink
Merge pull request #49 from easykeys/bug/amazon/shipping/label-gen
Browse files Browse the repository at this point in the history
Update version to 5.1.0 and enhance shipping providers
  • Loading branch information
ucrengineer authored Dec 18, 2024
2 parents cbdece5 + 1241eba commit 312c996
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 15 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.0.0
next-version: 5.1.0
branches:
feature:
tag: preview
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public async Task<Shipment> GetRatesAsync(Shipment shipment, CancellationToken c
Value = (double)shipment.Packages.Sum(x => x.InsuredValue),
Unit = "USD"
},
PackageClientReferenceId = "packageClientReferenceId",
PackageClientReferenceId = Guid.NewGuid().ToString(),
Items = new ()
{
new ()
Expand Down Expand Up @@ -124,7 +124,7 @@ public async Task<Shipment> GetRatesAsync(Shipment shipment, CancellationToken c
{
foreach (var error in ex.Result.Errors)
{
shipment.InternalErrors.Add(error.Message);
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 130 in src/EasyKeys.Shipping.Amazon.Rates/AmazonShippingRateProvider.cs

View workflow job for this annotation

GitHub Actions / build

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public async Task<ShipmentLabel> CreateSmartShipmentAsync(
Value = (double)shipment.Packages.Sum(x => x.InsuredValue),
Unit = "USD"
},
PackageClientReferenceId = "packageClientReferenceId",
PackageClientReferenceId = shippingDetails.ReferenceId,
Items = new ()
{
new ()
Expand Down Expand Up @@ -172,15 +172,15 @@ public async Task<ShipmentLabel> CreateSmartShipmentAsync(
ProviderLabelId = shipmentResult.Payload.ShipmentId,
TrackingId = details.TrackingId,
ImageType = "PNG",
Bytes = details.PackageDocuments.Select(x => Encoding.UTF8.GetBytes(x.Contents)).ToList()
Bytes = details.PackageDocuments.Select(x => Convert.FromBase64String(x.Contents)).ToList()
});
}
}
catch (ApiException<ErrorList> ex)
{
foreach (var error in ex.Result.Errors)
{
label.InternalErrors.Add(error.Message);
label.InternalErrors.Add($"{error.Message}-{error.Details}");
}

_logger.LogError(ex, $"Error creating shipment from Amazon Shipping API: {string.Join(",", ex.Result.Errors)}");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ namespace EasyKeys.Shipping.Amazon.Shipment.Models;

public class ShippingDetails
{
public string ReferenceId { get; set; } = Guid.NewGuid().ToString();

/// <summary>
/// Sender Contact Info.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
using EasyKeys.Shipping.Amazon.Shipment;
using EasyKeys.Shipping.Amazon.Shipment.Models;
using EasyKeys.Shipping.Stamps.Abstractions.Models;
using EasyKeys.Shipping.Stamps.Rates.Models;

using EasyKeysShipping.FuncTest.TestHelpers;

Expand Down Expand Up @@ -30,19 +28,21 @@ public async Task Process_Domestic_Shipment_Successfully()
shipmentDetails.Sender = sender;
shipmentDetails.Recipient = recipient;

var rateOptions = new RateOptions()
{
Sender = sender,
Recipient = recipient,
ServiceType = StampsServiceType.Priority
};

var labels = await _shipmentProvider.CreateSmartShipmentAsync(
TestShipments.CreateDomesticShipment(),
shipmentDetails,
CancellationToken.None);

Assert.NotNull(labels);
Assert.NotNull(labels.Labels[0].Bytes[0]);

// File path where the bytes will be saved
var filePath = $"{_shipmentProvider}-{_shipmentProvider.GetType().FullName}-domestic-output.png";

// Write the byte array to a file
File.WriteAllBytes(filePath, labels.Labels.First().Bytes.First());

var result = await _shipmentProvider.CancelShipmentAsync
(labels.Labels.First().TrackingId, CancellationToken.None);
}
}

0 comments on commit 312c996

Please sign in to comment.