You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
221 lines
7.4 KiB
C#
221 lines
7.4 KiB
C#
using Amazon.SellingPartnerApiSDK.AmazonSpApiSDK.Models.Exceptions;
|
|
using Amazon.SellingPartnerApiSDK.AmazonSpApiSDK.Models.ShippingV2;
|
|
using Newtonsoft.Json;
|
|
using Xunit.Abstractions;
|
|
|
|
namespace Amazon.SellingPartnerApi.Tests;
|
|
|
|
public class SampleShippingV2Tests : SampleTestsBase
|
|
{
|
|
private readonly ITestOutputHelper _testOutputHelper;
|
|
|
|
public SampleShippingV2Tests(ITestOutputHelper testOutputHelper)
|
|
{
|
|
this._testOutputHelper = testOutputHelper;
|
|
}
|
|
|
|
[Fact]
|
|
public async Task Should_Get_Rates()
|
|
{
|
|
var amazonConnection = CreateAmazonConnection();
|
|
|
|
var getRatesRequest = new GetRatesRequest
|
|
{
|
|
ShipTo = new Address
|
|
{
|
|
Name = "Courtesy Chakma",
|
|
AddressLine1 = "14420 97TH AVE BSMT DOOR JAMAICA",
|
|
StateOrRegion = "NY",
|
|
City = "JAMAICA",
|
|
CountryCode = "US",
|
|
PostalCode = "11435-4424",
|
|
},
|
|
ShipDate = new DateTime(2024,10,25,15,30,0),
|
|
ShipFrom = new Address
|
|
{
|
|
Name = "bosonshop",
|
|
AddressLine1 = "11190 White Birch Dr Suite 100",
|
|
StateOrRegion = "CA",
|
|
City = "RanchoCucamonga",
|
|
CountryCode = "US",
|
|
PostalCode = "91730",
|
|
},
|
|
Packages = new PackageList()
|
|
{
|
|
new Package
|
|
{
|
|
Dimensions = new Dimensions
|
|
{
|
|
Unit = DimensionsUnitEnum.INCH,
|
|
Length = 20,
|
|
Width = 20,
|
|
Height = 20
|
|
},
|
|
Weight = new Weight
|
|
{
|
|
Unit = WeightUnitEnum.POUND,
|
|
Value = 20
|
|
},
|
|
InsuredValue = new Currency
|
|
{
|
|
Value = 200,
|
|
Unit = "USD"
|
|
},
|
|
PackageClientReferenceId = "111-0844329-0DAWDAV",
|
|
IsHazmat = false,
|
|
Items = new ItemList
|
|
{
|
|
new Item
|
|
{
|
|
ItemValue = new Currency
|
|
{
|
|
Value = 200,
|
|
Unit = "USD"
|
|
},
|
|
Quantity = 1,
|
|
Weight = new Weight
|
|
{
|
|
Unit = WeightUnitEnum.POUND,
|
|
Value = 20
|
|
},
|
|
LiquidVolume = new LiquidVolume
|
|
{
|
|
Unit = LiquidVolumeUnitEnum.ML,
|
|
Value = 2000
|
|
},
|
|
}
|
|
}
|
|
}
|
|
},
|
|
ChannelDetails = new ChannelDetails()
|
|
{
|
|
ChannelType = ChannelType.EXTERNAL
|
|
},
|
|
};
|
|
|
|
try
|
|
{
|
|
var rates = await amazonConnection.ShippingV2.GetRatesAsync(getRatesRequest);
|
|
|
|
_testOutputHelper.WriteLine(JsonConvert.SerializeObject(rates));
|
|
}
|
|
catch (AmazonException e)
|
|
{
|
|
_testOutputHelper.WriteLine(JsonConvert.SerializeObject(e.Response.Content));
|
|
}
|
|
}
|
|
|
|
[Fact]
|
|
public async Task Should_Get_PurchaseShipment()
|
|
{
|
|
var amazonConnection = CreateAmazonConnection();
|
|
|
|
var purchaseShipmentRequest = new PurchaseShipmentRequest
|
|
{
|
|
RequestToken = "amzn1.rq.96860495585299.100",
|
|
RateId = "bdb4af907b215d71836ac5473581cf4094a9384c874e63c7252d6dcb8309212d1728552328767",
|
|
RequestedDocumentSpecification = new RequestedDocumentSpecification
|
|
{
|
|
Format = DocumentFormat.PDF,
|
|
Size = new DocumentSize
|
|
{
|
|
Unit = DocumentSizeUnitEnum.INCH,
|
|
Width = 4,
|
|
Length = 6
|
|
},
|
|
PageLayout = "DEFAULT",
|
|
NeedFileJoining = false,
|
|
RequestedDocumentTypes = new List<DocumentType>() { DocumentType.LABEL }
|
|
},
|
|
};
|
|
|
|
var purchaseShipment = await amazonConnection.ShippingV2.PurchaseShipmentAsync(purchaseShipmentRequest);
|
|
|
|
_testOutputHelper.WriteLine(JsonConvert.SerializeObject(purchaseShipment));
|
|
}
|
|
|
|
[Fact]
|
|
public async Task Should_Get_OneClickShipment()
|
|
{
|
|
var amazonConnection = CreateAmazonConnection();
|
|
|
|
var oneClickShipmentRequest = new OneClickShipmentRequest
|
|
{
|
|
ShipTo = new Address
|
|
{
|
|
Name = "Robert",
|
|
AddressLine1 = "E. O'Neal Jr 32 Winding Vale Rd Poplarville, MS",
|
|
StateOrRegion = "MS",
|
|
City = "Poplarville",
|
|
CountryCode = "US",
|
|
PostalCode = "39470",
|
|
},
|
|
ShipFrom = new Address
|
|
{
|
|
Name = "EDDIE",
|
|
AddressLine1 = "11190 White Birch Dr, Suite 100,CA,Rancho Cucamonga,91730",
|
|
StateOrRegion = "CA",
|
|
City = "Rancho Cucamonga",
|
|
CountryCode = "US",
|
|
PostalCode = "91730",
|
|
},
|
|
Packages = new PackageList()
|
|
{
|
|
new Package
|
|
{
|
|
Dimensions = new Dimensions
|
|
{
|
|
Unit = DimensionsUnitEnum.INCH,
|
|
Length = 20,
|
|
Width = 20,
|
|
Height = 20
|
|
},
|
|
Weight = new Weight
|
|
{
|
|
Unit = WeightUnitEnum.POUND,
|
|
Value = 20
|
|
},
|
|
InsuredValue = new Currency
|
|
{
|
|
Value = 200,
|
|
Unit = "USD"
|
|
},
|
|
PackageClientReferenceId = "111-0844329-0173888",
|
|
IsHazmat = false,
|
|
Items = new ItemList
|
|
{
|
|
new Item
|
|
{
|
|
ItemValue = new Currency
|
|
{
|
|
Value = 200,
|
|
Unit = "USD"
|
|
},
|
|
Quantity = 1,
|
|
Weight = new Weight
|
|
{
|
|
Unit = WeightUnitEnum.POUND,
|
|
Value = 20
|
|
},
|
|
LiquidVolume = new LiquidVolume
|
|
{
|
|
Unit = LiquidVolumeUnitEnum.ML,
|
|
Value = 2000
|
|
},
|
|
}
|
|
}
|
|
}
|
|
},
|
|
ValueAddedServicesDetails = null,
|
|
TaxDetails = null,
|
|
ChannelDetails = new ChannelDetails()
|
|
{
|
|
ChannelType = ChannelType.EXTERNAL
|
|
},
|
|
LabelSpecifications = null,
|
|
ServiceSelection = null,
|
|
ShipperInstruction = null,
|
|
DestinationAccessPointDetails = null
|
|
};
|
|
}
|
|
} |