Skip to content

Commit

Permalink
Canada Post: Send package.value as dollar amount instead of cents
Browse files Browse the repository at this point in the history
  • Loading branch information
Soleone committed Feb 14, 2011
1 parent 37b4721 commit d801228
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
6 changes: 5 additions & 1 deletion lib/active_shipping/shipping/carriers/canada_post.rb
Expand Up @@ -122,7 +122,7 @@ def build_rate_request(origin, destination, line_items = [], options = {})
request << XmlNode.new('merchantCPCID', @options[:login])
request << XmlNode.new('fromPostalCode', origin.postal_code)
request << XmlNode.new('turnAroundTime', options[:turn_around_time] ? options[:turn_around_time] : DEFAULT_TURN_AROUND_TIME)
request << XmlNode.new('itemsPrice', line_items.sum(&:value))
request << XmlNode.new('itemsPrice', dollar_amount(line_items.sum(&:value)))

#line items
request << build_line_items(line_items)
Expand Down Expand Up @@ -250,6 +250,10 @@ def build_line_items(line_items)

xml_line_items
end

def dollar_amount(cents)
"%0.2f" % (cents / 100.0)
end
end
end
end
2 changes: 1 addition & 1 deletion test/fixtures/xml/canadapost/example_request.xml
@@ -1 +1 @@
<!DOCTYPE eparcel SYSTEM "http://sellonline.canadapost.ca/DevelopersResources/protocolV3/eParcel.dtd"><eparcel><language>en</language><ratesAndServicesRequest><merchantCPCID>CPC_DEMO_XML</merchantCPCID><fromPostalCode>K1N 5T2</fromPostalCode><turnAroundTime>24</turnAroundTime><itemsPrice>25</itemsPrice><lineItems><item><quantity>1</quantity><weight>0.5</weight><length>4</length><width>3</width><height>2</height><description>a box full of stuff</description><readyToShip/></item></lineItems><city>Beverly Hills</city><provOrState>CA</provOrState><country>United States</country><postalCode>90210</postalCode></ratesAndServicesRequest></eparcel>
<!DOCTYPE eparcel SYSTEM "http://sellonline.canadapost.ca/DevelopersResources/protocolV3/eParcel.dtd"><eparcel><language>en</language><ratesAndServicesRequest><merchantCPCID>CPC_DEMO_XML</merchantCPCID><fromPostalCode>K1N 5T2</fromPostalCode><turnAroundTime>24</turnAroundTime><itemsPrice>25.00</itemsPrice><lineItems><item><quantity>1</quantity><weight>0.5</weight><length>4</length><width>3</width><height>2</height><description>a box full of stuff</description><readyToShip/></item></lineItems><city>Beverly Hills</city><provOrState>CA</provOrState><country>United States</country><postalCode>90210</postalCode></ratesAndServicesRequest></eparcel>
2 changes: 1 addition & 1 deletion test/unit/carriers/canada_post_test.rb
Expand Up @@ -15,7 +15,7 @@ def setup

@origin = {:address1 => "61A York St", :city => "Ottawa", :province => "ON", :country => "Canada", :postal_code => "K1N 5T2"}
@destination = {:city => "Beverly Hills", :state => "CA", :country => "United States", :postal_code => "90210"}
@line_items = [Package.new(500, [2, 3, 4], :description => "a box full of stuff", :value => 25)]
@line_items = [Package.new(500, [2, 3, 4], :description => "a box full of stuff", :value => 2500)]
end

def test_parse_rate_response_french
Expand Down

0 comments on commit d801228

Please sign in to comment.