OrderCloud.Integrations.Shipping.Fedex
1.0.2-alpha
See the version list below for details.
dotnet add package OrderCloud.Integrations.Shipping.Fedex --version 1.0.2-alpha
NuGet\Install-Package OrderCloud.Integrations.Shipping.Fedex -Version 1.0.2-alpha
<PackageReference Include="OrderCloud.Integrations.Shipping.Fedex" Version="1.0.2-alpha" />
paket add OrderCloud.Integrations.Shipping.Fedex --version 1.0.2-alpha
#r "nuget: OrderCloud.Integrations.Shipping.Fedex, 1.0.2-alpha"
// Install OrderCloud.Integrations.Shipping.Fedex as a Cake Addin #addin nuget:?package=OrderCloud.Integrations.Shipping.Fedex&version=1.0.2-alpha&prerelease // Install OrderCloud.Integrations.Shipping.Fedex as a Cake Tool #tool nuget:?package=OrderCloud.Integrations.Shipping.Fedex&version=1.0.2-alpha&prerelease
OrderCloud.Integrations.Shipping.Fedex
This project brings shipping rate calculation to your ecommerce app using the Fedex API. It is published as a nuget code library and conforms to a standard shipping interface published in the base library OrderCloud.Catalyst.
Basics and Installation
- If you haven't, please review Order Checkout Integration Event focusing on the ShippingRates event. In short, a webhook from the platform makes a request to a solution-custom API route that contains logic for estimating shipping rates.
- This library can be installed in the context of a .NET API project that responds to those webhooks. If you already have a .NET API project, great. If not, you can follow this guide. After you have published your API, you will need to configure OrderCloud to point its Integration Event webhooks at your API.
- In your .NET project, add the OrderCloud.Integrations.Shipping.Fedex nuget package with either the Visual Studio UI or the dotnet CLI.
dotnet add package OrderCloud.Integrations.Shipping.Fedex
Authentication and Injection
You will need these configuration data points to authneticate to the Fedex API - BaseUrl, ClientID, ClientSecret and AccountNumber. Create an account with Fedex and get these from the admin portal.
var fedexService = new FedexService(new FedexConfig()
{
BaseUrl = "https://apis-sandbox.fedex.com", // or https://apis.fedex.com
ClientID = "...",
ClientSecret = "...",
AccountNumber = "..."
});
For efficient use of compute resources and clean code, create 1 FedexService object and make it available throughout your project using inversion of control dependency injection.
services.AddSingleton<IShippingRatesCalculator>(fedexService);
Notice that IShippingRatesCalculator is not specific to Fedex. It is general to shipping rates and comes from the upstream OrderCloud.Catalyst package.
Usage
Create routes that respond to the OrderCloud platform's Integration Event webhooks. Inject the shipping interface IShippingRatesCalculator and use it within the logic of the route. It is not recommended to rely directly on FedexService anywhere. The layer of abstraction that IShippingRatesCalculator provides decouples your code from Fedex as a specific provider and hides some internal complexity.
public class CheckoutIntegrationEventController : CatalystController
{
private readonly IShippingRatesCalculator _shipMethodCalculator;
public CheckoutIntegrationEventController(IShippingRatesCalculator shipMethodCalculator)
{
// Inject interface. Implementation will depend on how services were registered, FedexService in this case.
_shipMethodCalculator = shipMethodCalculator;
}
....
[HttpPost, Route("shippingrates")] // route and method specified by OrderCloud platform
[OrderCloudWebhookAuth] // Security feature to verifiy request came from Ordercloud.
public async Task<ShipEstimateResponse> EstimateShippingRates([FromBody] OrderCalculatePayload<CheckoutConfig> payload)
{
var response = new ShipEstimateResponse();
// containerization logic - how should lineItem quantities be boxed into a set of shipped packages?
response.ShipEstimates = new List<ShipEstimate> { ... }
var packages = response.ShipEstimates.Select(se => MapToPackages(response.ShipEstimates));
// use the interface
List<List<ShipMethod> rates = await _shipMethodCalculator.CalculateShipMethodsAsync(packages);
for (var i = 0; i<response.ShipEstimates.Count; i++)
{
response.ShipEstimates[0].ShipMethods = rates[0]
}
return response;
}
}
This library also supports more complex cases that require mulitple shipping accounts with different credentials. For example, in a franchise business model where each location is independent but all sell on one ecommerce solution. In that case, still inject one instance of FedexService exactly as above. You can provide empty strings for the fields. However, when you call methods on the interfaces, provide the optional configOverride
parameter.
FedexConfig configOverride = await FetchShippingAccountCredentials(supplierID)
var packages = new List<ShipPackage>() { ... }
List<List<ShipMethods> rates = await _shipMethodCalculator.CalculateShipMethodsAsync(packages, configOverride);
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- ordercloud-dotnet-catalyst (>= 2.0.2)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
2.3.0 | 412 | 10/31/2022 |
1.0.2-alpha | 208 | 4/21/2022 |
1.0.1-alpha | 194 | 4/21/2022 |