EasyPost / easypost-node

EasyPost Shipping API Client Library for Node
https://easypost.com/docs/api
MIT License
139 stars 54 forks source link

[Bug]: getLowestRate() doesn't account for difference currencies #421

Closed pauldraper closed 1 week ago

pauldraper commented 9 months ago

Software Version

-

Language Version

-

Operating System

-

What happened?

getLowestRate() gives a bad result with different currencies, e.g. mixing CAD and USD sometimes chooses a numerically lower USD even if CAD quote is better.

I can't imagine any case where this is desirable behavior.

https://github.com/EasyPost/easypost-node/blob/4f75889a39cb4eb2ab69a96f908dd8924d93d86d/src/utils/util.js#L76

What was expected?

Not sure, but the existence of getLowestRate() is a footgun.

Sample Code

No response

Relevant logs

No response

nwithan8 commented 9 months ago

Hello, thank you for reaching out! We are triaging the issue currently. Do you perhaps have any logs you could share to help us reproduce the issue, specifically how you retrieved a combination of USD and non-USD rates?

Harrison-Burgess commented 9 months ago

Hey, what I did to produce this was creating a shipment const shipmentData = { to_address: toAddress, from_address: fromAddress, parcel: await easypost.Parcel.create({ weight: getLineItemWeight(productWithQty), }), options: { currency: "USD", }, mode, };

shipment = await easypost.Shipment.create(shipmentData); Where the addresses were from 2 different countries This requested rates where we preferred them in USD. Some of the carriers didn't seem to work for the currency option though and still gave us back rates in the local currency. const lowestRate = shipment.lowestRate([ "UPS", "CanadaPost", "FedExDefault", "USPSReturns", ]);

Justintime50 commented 1 week ago

Hey @Harrison-Burgess, thanks for providing additional details. This particular issue sounds like it could be better solved at the API level as this client library's function behaved correctly based on its intended use-case - it can only determine the lowest rate with good data. With that said, you can reach our support team at support@easypost.com and describe the perceived bug to them. They'll work with our internal teams if possible to correct this so the carrier (if possible) can return currencies in the requested type. I will note that per our documentation, the currency option does state that only carriers that allow conversion will respect the shipment option of defining an explicit currency, if I had to guess, I assume CanadaPost does not at present, though it's possible that could change if requested.

Screenshot 2024-08-27 at 9 51 36 AM

As this issue happens at the API level, I'm going to close this issue since we do not intend to support currency conversion directly in our client libraries.