All Projects → alexeybusygin → ShippingRates

alexeybusygin / ShippingRates

Licence: MIT license
.NET wrapper to UPS, FedEx, USPS and DHL shipping rates APIs

Programming Languages

C#
18002 projects

Projects that are alternatives of or similar to ShippingRates

php-tracking-urls
Converts package tracking numbers into URLs (UPS, FedEx, USPS, and more)
Stars: ✭ 47 (+104.35%)
Mutual labels:  shipping, ups, dhl, fedex, usps
shippo-csharp-client
Shipping API C# library (USPS, FedEx, UPS and more)
Stars: ✭ 52 (+126.09%)
Mutual labels:  ups, dhl, fedex, usps
tracking-number-validation
A simple way to validate tracking number for the following couriers.
Stars: ✭ 22 (-4.35%)
Mutual labels:  ups, fedex, usps
shipengine-openapi
The official OpenAPI 3.0 definitions for ShipEngine™
Stars: ✭ 13 (-43.48%)
Mutual labels:  shipping, shipping-rates
usps-api
Python Wrapper for the USPS API 🚚 📦
Stars: ✭ 52 (+126.09%)
Mutual labels:  shipping, usps
B2.NET
.NET library for Backblaze's B2 Cloud Storage
Stars: ✭ 63 (+173.91%)
Mutual labels:  dotnet-standard
RESTCountries.NET
.NET Standard wrapper library around the API provided by REST Countries https://restcountries.com. The world in .NET 🔥.
Stars: ✭ 33 (+43.48%)
Mutual labels:  dotnet-standard
DNZ.SEOChecker
SEO Checker and Recommander Plugin (like wordpress Yoast) for ASP.NET Core.
Stars: ✭ 18 (-21.74%)
Mutual labels:  dotnet-standard
Nager.Country
Worldwide Country Informations (ISO-3166-1 Alpha2, ISO-3166-1 Alpha3, ISO 639-1)
Stars: ✭ 68 (+195.65%)
Mutual labels:  dotnet-standard
covidtrackerapiwrapper
CovidSharp is a crossplatform C# API wrapper for the Coronavirus tracking API (https://github.com/ExpDev07/coronavirus-tracker-api)
Stars: ✭ 11 (-52.17%)
Mutual labels:  dotnet-standard
Pluralize.NET
📘 Pluralize or singularize any English word.
Stars: ✭ 50 (+117.39%)
Mutual labels:  dotnet-standard
Capstone.NET
.NET Core and .NET Framework binding for the Capstone Disassembly Framework
Stars: ✭ 108 (+369.57%)
Mutual labels:  dotnet-standard
Merkurius
Portable Deep Learning Library for .NET
Stars: ✭ 1 (-95.65%)
Mutual labels:  dotnet-standard
PortaCapena.OdooJsonRpcClient
Odoo Client Json Rpc
Stars: ✭ 39 (+69.57%)
Mutual labels:  dotnet-standard
ATtiny13-TinyUPS
Uninterruptible Power Supply
Stars: ✭ 92 (+300%)
Mutual labels:  ups
ILject
Provides a way which you can load a .NET dll/exe from disk, modify/inject IL, and then run the assembly all in memory without modifying the file.
Stars: ✭ 25 (+8.7%)
Mutual labels:  dotnet-standard
m2.ShippingTweaks
Magento2. Extension hides any other shipping methods if free shipping is available.
Stars: ✭ 43 (+86.96%)
Mutual labels:  shipping
NwRfcNet
An easy way of making SAP RFC calls from .NET Core
Stars: ✭ 83 (+260.87%)
Mutual labels:  dotnet-standard
python-nut2
Communicate with Network UPS Tools servers from Python.
Stars: ✭ 30 (+30.43%)
Mutual labels:  ups
purplship-dashboard
The Open Source Shipping dashboard for karrio
Stars: ✭ 57 (+147.83%)
Mutual labels:  shipping-rates

ShippingRates

Build status NuGet Version

.NET wrapper to UPS, FedEx, USPS and DHL APIs. Use it to retrieve shipping rates from these carriers.

How to Install

Available in the NuGet Gallery:

PM> Install-Package ShippingRates

Getting Started

// Create RateManager
var rateManager = new RateManager();

// Add desired shipping providers
// You will need a license #, userid and password to utilize the UPS provider.
rateManager.AddProvider(new UPSProvider(upsLicenseNumber, upsUserId, upsPassword));
// You will need an account # and meter # to utilize the FedEx provider.
rateManager.AddProvider(new FedExProvider(fedexKey, fedexPassword, fedexAccountNumber, fedexMeterNumber));
// You will need a userId to use the USPS provider. Your account will also need access to the production servers.
rateManager.AddProvider(new USPSProvider(uspsUserId));
// You will need a Site ID and Password to use DHL provider.
rateManager.AddProvider(new DHLProvider(dhlSiteId, dhlPassword, useProduction: false));

// (Optional) Add RateAdjusters
rateManager.AddRateAdjuster(new PercentageRateAdjuster(.9M));

// Setup package and destination/origin addresses
var packages = new List<Package>();
packages.Add(new Package(12, 12, 12, 35, 150));
packages.Add(new Package(4, 4, 6, 15, 250));

var origin = new Address("", "", "06405", "US");
var destination = new Address("", "", "20852", "US"); // US Address

// Call GetRates()
Shipment shipment = await rateManager.GetRatesAsync(origin, destination, packages);

// Iterate through the rates returned
foreach (Rate rate in shipment.Rates)
{
    Console.WriteLine(rate);
}

ShippingRates supports requesting a single rate from UPS and USPS. To do so, include the rate description as a parameter of the provider constructor.

rateManager.AddProvider(new USPSProvider(uspsUserId, "Priority Mail"));
rateManager.AddProvider(new UPSProvider(upsLicenseNumber, upsUserId, upsPassword, "UPS Ground"));

A list of valid shipping methods can be found in the documentation links below.

See the sample app in this repository for a working example.

More information can be found in Wiki.

International Rates

USPS requires a separate API call for retrieving rates international services.

The call works the same but use the USPSInternationalProvider instead. Your current USPS credentials will work with this and will return the available services between the origin and destination addresses.

Shipping Options

Shipping options can be passed to the GetRates function as ShipmentOptions object.

var shipment = await rateManager.GetRatesAsync(origin, destination, packages,
    new ShipmentOptions() {
        SaturdayDelivery = true,
        ShippingDate = new DateTime(2020, 7, 15),
        PreferredCurrencyCode = "EUR",  // For FedEx only
        FedExOneRate = true             // For FedEx only
    });

The following options are available:

Name Default Value Meaning
SaturdayDelivery False Enable Saturday Delivery option for shipping rates.
ShippingDate null Pickup date. Current date and time is used if not specified.
PreferredCurrencyCode USD Preferred rates currency code in the ISO format. Applies to FedEx only.
FedExOneRate False Use FedEx One Rate pricing option. Applies to FedEx only.

Saturday Delivery

If ShipmentOptions.SaturdayDelivery is set, then you can expect to receive some Saturday Delivery methods. You can check it with Rate.Options.SaturdayDelivery property:

var anySaturdayDeliveryMethods = shipment.Rates.Any(r => r.Options.SaturdayDelivery);

Error Handling

Normally RateManager.GetRates wouldn't throw any exceptions. All errors are caught and reported in two properties: Errors and InternalErrors. Errors are for errors coming from APIs (incorrect address etc.) It should be quite safe to show them to the end-user. InternalErrors are errors happened during API calls processing (SOAP, HTTP requests) and errors from inside the ShippingRates. They can be used for debugging and internal reporting. Iterating through Errors and InternalErrors:

var shipment = rateManager.GetRates(origin, destination, packages);

foreach (var error in shipment.Errors)
{
    Console.WriteLine(error.Number);
    Console.WriteLine(error.Source);
    Console.WriteLine(error.Description);
}

foreach (var error in shipment.InternalErrors)
{
    Console.WriteLine(error);
}

FedEx and 556 There are no valid services available

This one can be tricky to debug. Start with setting at least $1 insurance for your shipment. For some reason, FedEx would not report errors like wrong ZIP code for origin address if there is no insurance set.

3rd Party Docs

Developer documentation is often hard to find. The links below are provided as reference.

Credits

Originally forked from DotNetShipping by @kylewest.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].