Skip to content
This repository has been archived by the owner on Jun 13, 2018. It is now read-only.

Bug: Stamps.com rates are expressed in dollars in the API, ActiveShipping sometimes interprets them as cents #455

Open
dustMason opened this issue Jan 3, 2017 · 1 comment

Comments

@dustMason
Copy link
Contributor

dustMason commented Jan 3, 2017

Before I make a PR, I'd like advice on the best approach to fixing this issue.

The code in question is https://github.com/Shopify/active_shipping/blob/master/lib/active_shipping/package.rb#L117-L131

    def self.cents_from(money)
      return nil if money.nil?
      if money.respond_to?(:cents)
        return money.cents
      else
        case money
        when Float
          (money * 100).round
        when String
          money =~ /\./ ? (money.to_f * 100).round : money.to_i
        else
          money.to_i
        end
      end
    end

When querying the Stamps.com API for rates, it returns amount values that look like 10.50 representing $10.50, for example. However, when the value is an amount of whole dollars, it looks like 10 representing $10, for example. This causes the cents_from method above to assume that the 10 is a value in cents since it doesn't contain a ..

We discovered this when a customer was charged $0.57 for a shipment from California to Finland! Whoops!

Perhaps the best way would be to have the Stamps Carrier class return this value as an instance of a class that implements a cents method. What would be best practice here?

Thanks

@kmcphillips
Copy link
Member

Oh boy. This cents_from method is super painful.

I'm going to put this in the 2.0 milestone. We should replace this with proper money parsing.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants