Giter Club home page Giter Club logo

shippingrates's Introduction

ShippingRates

Build status NuGet Version

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

UPS Breaking Changes

UPS has deprecated access key authentication in favor of an OAuth 2.0 security model for all APIs. Beginning June 3, 2024, access keys will no longer be supported. More details at the UPS site: https://developer.ups.com/oauth-developer-guide?loc=en_US

The new authentication model is implemented in the package version 2.0, right now in Beta: https://www.nuget.org/packages/ShippingRates/2.0.215-beta

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 an OAuth Client ID, Client Secret, and Account Number to use the UPS provider.
rateManager.AddProvider(new UPSProvider(new UPSProviderConfiguration()
{
    ClientId = upsClientId,
    ClientSecret = upsClientSecret,
    AccountNumber = upsAccountNumber
}));
// 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 the 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 to retrieve rates for 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 a 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
        FedExOneRatePackageOverride = "FEDEX_ENVELOPE"  // For FedEx only
    });

The following options are available:

Name Default Value Meaning
SaturdayDelivery False Enable the Saturday Delivery option for shipping rates.
ShippingDate null Pickup date. The current date and time are used if not specified.
PreferredCurrencyCode USD Preferred rates currency code in the ISO format. Applies to FedEx only.
FedExOneRate False Use the FedEx One Rate pricing option. Applies to FedEx only.
FedExOneRatePackageOverride FEDEX_MEDIUM_BOX Packing option when using FedEx OneRate.

Saturday Delivery

If ShipmentOptions.SaturdayDelivery is set, you can expect to receive some Saturday Delivery methods. You can check it with the 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 that occur 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 by setting at least $1 insurance for your shipment. For some reason, FedEx will not report errors like the wrong ZIP code for the origin address if no insurance is 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. Package icon by Fredy Sujono.

shippingrates's People

Contributors

alexeybusygin avatar creinker avatar dependabot[bot] avatar khnbb avatar oztrkkaan avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

shippingrates's Issues

Errors: 250003 Invalid Access License number

Thank you for keeping up with this API!
I'm trying to use the UPS side but I'm getting a
Errors: 250003 Invalid Access License number
I double checked and it works in the UPS API C# examples.
I have the proper access key, username and password.

Exception in DotNetShipping .Net 4.6

Hi. I was hoping I could get a bit of help. I can't install ShippingRates since my OLD program is targeting .NET 4.6. The DotNetShipping code to retrieve UPS rates is working fine (and has been for a long time) on my production system (Azure), but on my development machine, I'm getting an exception:

System.Net.WebException: 'The operation has timed out'

Any ideas would be much appreciated!
Ron

Missing option to request quote in some currency

Hey, there is an option in fedex api, to return the quote in currency that we want to have, also there is additional field which is saying which currency is it. Can you add this please? It would be very helpful. Or I can create PR, but please accept this :)

FedEx One Rate

Hello - Can you include FedEx One Rate services and pricing? The information is provided directly from FedEx web service online documentation. Thanks!

How to Specify One Rate Pricing
To specify FedEx One Rate Pricing Option in the Web Service Transaction, do the following:

  1. Specify FEDEX_ONE_RATE Shipment Special Service.
    
  2. Specify one of the following Packaging Types:
    

Packaging Type | Max Weight (lbs) | Max Weight (kg)
FEDEX_SMALL_BOX | 50 | 22.68
FEDEX_MEDIUM_BOX | 50 | 22.68
FEDEX_LARGE_BOX | 50 | 22.68
FEDEX_EXTRA_LARGE_BOX | 50 | 22.68
FEDEX_PAK | 50 | 22.68
FEDEX_TUBE | 50 | 22.68
FEDEX_ENVELOPE | 10 | 4.5

Originally posted by @joekrauss in #5 (comment)

UPS ServiceDescription Bug

There appears to be a bug in the way the ServiceDescription is used in the UPSProvider class. Service description is used to determine the value of the RequestOption in the following code:
writer.WriteElementString("RequestOption", string.IsNullOrWhiteSpace(_serviceDescription) ? "Shop" : _serviceDescription);
The values for this field should either be "Shop" or "Rate" as far as I know.

However, the ServiceDescription is also used to determine the ServiceCode if you're specifying a shipping method:
writer.WriteElementString("Code", _serviceDescription.ToUpsShipCode());

"Rate" is not a valid entry for the ToUpsShipCode() function, and any ship method (i.e. "UPS Sure Post") is not a valid entry for RequestOption. This needs to be fixed.

DotNetShipping: The request was aborted: Could not create SSL/TLS secure channel. Canada orders yield errors

Hi community,
I've been trying to resolve this issue by reading the UPS docs and looking over the code in this repository but to no avail. Has anyone else had issues getting back rates for Canadian orders? This issue is an extremely interesting one because US orders work just fine but as soon as I put in a Canadian address, BAM. Errors. Please refer to my stackoverflow post: https://stackoverflow.com/questions/75584440/dotnetshipping-the-request-was-aborted-could-not-create-ssl-tls-secure-channel

Support for UK shipping

Seems the code only works for US or Canada shipments. Please include domestic shipments in UK.

No saturday delivery option

Hi! I am trying to find a way to specify the option Saturday delivery. Any sugestions?
I will extend the package class to allow the boolean and add the code to GetRates.
Thanks a lot for maintaining this package!

Will it support create label?

I am using UPS with negotiate rates, its online website do not support print two labels on a letter page, so I want to print lable by my own way, thanks.

Add optional USPS special services

I'm not seeing a way to include USPS special services. More specifically I need to add Registered Mail Restricted Delivery. Any plans to make this available?

https://www.usps.com/business/web-tools-apis/rate-calculator-api.pdf - page 8

Special Service Name | ServiceID
Insurance | 100
Insurance –Priority Mail Express | 101
Return Receipt | 102
Collect on Delivery | 103
Certificate of Mailing (Form 3665) | 104
Certified Mail | 105
USPS Tracking | 106
Signature Confirmation | 108
Registered Mail | 109
Return Receipt Electronic | 110
Registered mail COD collection Charge | 112
Return Receipt –Priority Mail Express | 118
Adult Signature Required | 119
Adult Signature Restricted Delivery | 120
Insurance –Priority Mail | 125
USPS Tracking Electronic | 155
Signature Confirmation Electronic | 156
Certificate of Mailing (Form 3817) | 160
Certified Mail Restricted Delivery | 170
Certified Mail Adult Signature Required | 171
Certified Mail Adult Signature Restricted Delivery | 172
Signature Confirm. Restrict. Delivery | 173
Signature Confirmation Electronic Restricted Delivery | 174
Collect on Delivery Restricted Delivery | 175
Registered Mail Restricted Delivery | 176
Insurance Restricted Delivery | 177
Insurance Restrict. Delivery –Priority Mail | 179
Insurance Restrict. Delivery –Priority Mail Express | 178
Insurance Restrict. Delivery (Bulk Only) | 180
Scan Retention | 181
Scan + Signature Retention | 182
Special Handling -Fragile | 190

Negotiated Rates and Freight

Здравствуйте, Алексей!

I am trying to use your solution for getting negotiated rates:

        rateManager.AddProvider(new UPSProvider(upsLicenseNumber, upsUsername, upsPassword) { UseNegotiatedRates = true, UseProduction = false });

But the rate I get back is the same, whether UseNegotiatedRates is true or false. I guess, ShipperNumber should be required, but if so, where can I provide it? Or anything else I may be missing?

Also, I see your package deals with UPS packages, but how about freight?

Thank you very much!

Another carrier.

Are you interested in implementing support for other carriers? and accepting PR's for this.

  • thanks for maintaining this repo.

UPS deprecating xml API on June 5,2024

Got this email from UPS today:

Upgrades to the UPS API Security Model

Thank you for being a UPS API user! At UPS, we continue to improve our technology offerings and work to provide better security for our valued customers.

UPS has implemented an OAuth 2.0 security model for all APIs to enhance the overall security for our customers to reduce fraud and provide enhanced API capabilities. This change impacts your current API integration and requires you to make updates to your existing application interface.

How will this impact my API integration?

• Beginning June 5, 2023, UPS will no longer issue API access keys

• On June 3, 2024, access keys will no longer be supported for authentication to UPS APIs

• You will need to obtain OAuth API credentials from the new UPS Developer Portal and update your security protocols to OAuth 2.0 prior to June 3, 2024 to continue transacting with UPS APIs

• Any legacy UPS API integrations using XML, SOAP, or legacy JSON payloads will also be required to convert to the RESTful APIs

We have created an API access key migration guide to assist with your migration from access keys to OAuth 2.0. If you obtained an access key to provide to a 3rd party please notify them of these changes immediately.

So this means this package will need to implement the Rest api or it will no longer work on June 5, 2023.

FedEx provider exception on .NET Framework 4.8

Thanks for maintaining this fork! I'm using version 1.1.0.96 on .NET Framework 4.8. UPS rates come back fine, but Fedex rates come back empty with the following InternalError:

FedEx provider exception: Error in line 1 position 169. Expecting element 'ExceptionDetail' from namespace
'http://schemas.datacontract.org/2004/07/System.ServiceModel'.. Encountered 'Element'  with name 'cause', namespace ''.

This issue does not occur on .NET Core.
It also does not occur with DotNetShipping on .NET Framework 4.8.

Negotiated Rates

Hello, I am having a hard time finding how to retrieve negotiated rates using ShippingRates.
Could you provide some info on how to retrieve it?

Thank you in advance! :)

Incorrect shipping rates for FedEx Japan to Singapore

FedEx International Economy rate seems to be too high:

FedEx
        INTERNATIONAL_PRIORITY
        FedEx International Priority
        188.01
        9/18/2020 9:00:00 PM
FedEx
        INTERNATIONAL_ECONOMY
        FedEx International Economy
        14283.00
        9/21/2020 9:00:00 PM

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.