kylewest / DotNetShipping

UPS, FedEx, USPS shipping rate calculators for .NET
MIT License
78 stars 66 forks source link

UPS - UseNegotiatedRates not working because of StateProvinceCode #80

Open elcapitanandres opened 6 years ago

elcapitanandres commented 6 years ago

When use UPS and UseNegotiatedRates = true with valid account and ShipperNumber, the server response doesn't contains the "NegotiatedRates" node. In the response details there is a Warning node "RatedShipmentWarning" = Invalid Origin State/Province. Current code is not setting the Shipper province as you can see:

writer.WriteStartElement("Address");
writer.WriteElementString("PostalCode", Shipment.OriginAddress.PostalCode);
writer.WriteElementString("CountryCode", Shipment.OriginAddress.CountryCode);
writer.WriteEndElement(); // </Address>

Seems UPS needs the StateProvinceCode node in the Shipper Address if UseNegotiatedRates=true If change code to:

writer.WriteStartElement("Address");
writer.WriteElementString("PostalCode", Shipment.OriginAddress.PostalCode);
writer.WriteElementString("CountryCode", Shipment.OriginAddress.CountryCode);
if (!string.IsNullOrWhiteSpace(Shipment.OriginAddress.State))//<RatedShipmentWarning>Invalid Origin State/Province</RatedShipmentWarning>
{
    writer.WriteElementString("StateProvinceCode", Shipment.OriginAddress.State);
}
writer.WriteEndElement(); // </Address>

I receive the NegotiatedRates node completed. There is any reason why the origin "StateProvinceCode" is not set? Thank you.