UPS Plugin Shipping Rate Set to 0.00 for International Shipments

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
5 years ago
NopCommerce 4.0
Plugin: Shipping.UPS

When calculating shipping rate for UPS for international shipments from US, international shipping rates, such as UPS Worldwide Express or UPS Standard will be set to "0.00" (plus any Additional handling charge).

This error is caused by the UPSComputationMethod.ParseResponse function.
The reason this happens is because it loops through the XML response nodes (using XmlTextReader) looking for the XML element "TotalCharges" then gets the value for "MonetaryValue".  The element "TotalCharges" appears twice for each service and the ParseResponse function overwrites the value of the 1st instance with the 2nd instance. Normally this is fine, since the values are usually the same, however, for international service codes, the 2nd instance has a value of "0.00", which overwrites the 1st, correct value.

As noted in this document on page 34.

      <TotalCharges>
         <CurrencyCode>UKL</CurrencyCode>
         <MonetaryValue>73.65</MonetaryValue>
      </TotalCharges>
      <GuaranteedDaysToDelivery>0</GuaranteedDaysToDelivery>
      <RatedPackage>
         <TransportationCharges>
            <CurrencyCode>UKL</CurrencyCode>
            <MonetaryValue>0.00</MonetaryValue>
         </TransportationCharges>
         <ServiceOptionsCharges>
            <CurrencyCode>UKL</CurrencyCode>
            <MonetaryValue>0.00</MonetaryValue>
         </ServiceOptionsCharges>
         <TotalCharges>
            <CurrencyCode>UKL</CurrencyCode>
            <MonetaryValue>0.00</MonetaryValue>
         </TotalCharges>
         <Weight>23.0</Weight>
         <BillingWeight>
            <UnitOfMeasurement>
               <Code>KGS</Code>
            </UnitOfMeasurement>
            <Weight>0.0</Weight>
         </BillingWeight>
      </RatedPackage>
   </RatedShipment>

As you can see here, the 2nd TotalCharges (in the RatedPackage node) has a MonetaryValue of 0.00.

To test it, turn on UPS Standard service in the plugin, then estimate shipping to Canada, Ontario, Zip code  n3h5k2. The rate will be set to 0.00 (plus any Additional handling charge set in the plugin).

Aside from the bug mentioned, this parsing method should be optimized and modernized to use xpath to find the values it needs.  It does allot of heavy looping, overwrites values for elements where it shouldn't and doesn't consider the parent nodes in the XML. There is allot of opportunity here to reduce defects and improve performance here.
5 years ago
Here's a dotnetfiddle for you :)

https://dotnetfiddle.net/aWaXMv
5 years ago
Thanks for the info and contribution. We'll check it.
5 years ago
We have updated UPS shipping plugin to use the latest API version using Web Services, and thus abandoned XML parsing. You can see details in this commit
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.