File tree 2 files changed +27
-10
lines changed
lib/vertex_client/responses
2 files changed +27
-10
lines changed Original file line number Diff line number Diff line change @@ -29,23 +29,18 @@ def product_for_line_item(product)
29
29
30
30
# see lib/vertex_client/rates.rb for hard-coded fallback rates
31
31
def tax_amount ( price , country , state )
32
- if known_us_state ?( state )
32
+ if domestic? ( country ) && state . present? && RATES [ 'US' ] . has_key ?( state )
33
33
price * BigDecimal ( RATES [ 'US' ] [ state ] )
34
- elsif known_non_us_country ?( country )
34
+ elsif ! domestic? ( country ) && country . present? && RATES . has_key ?( country )
35
35
price * BigDecimal ( RATES [ country ] )
36
36
else
37
37
BigDecimal ( '0.0' )
38
38
end
39
39
end
40
40
41
- # state is in the United States and we have an explicit fallback
42
- def known_us_state? ( state )
43
- state . present? && RATES [ 'US' ] . has_key? ( state )
44
- end
45
-
46
- # we have an explicit fallback for the country
47
- def known_non_us_country? ( country )
48
- country . present? && country != 'US' && RATES . has_key? ( country )
41
+ def domestic? ( country )
42
+ # we assume a country-less customer is from the US
43
+ country . nil? || country == 'US'
49
44
end
50
45
51
46
def tax_for_line_item ( line_item )
Original file line number Diff line number Diff line change 80
80
assert_equal 0.0 , response . total_tax . to_f
81
81
end
82
82
end
83
+
84
+ describe 'for a country with a state code that collides with a US state code' do
85
+ let ( :params ) do
86
+ working_quote_params . tap do |wqp |
87
+ wqp [ :customer ] [ :address_1 ] = 'Miguel Angel Blanco 2 4C'
88
+ wqp [ :customer ] [ :city ] = 'Valladolid'
89
+ wqp [ :customer ] [ :state ] = 'VA'
90
+ wqp [ :customer ] [ :postal_code ] = '47014'
91
+ wqp [ :customer ] [ :country ] = 'ES'
92
+ wqp [ :line_items ] [ 1 ] [ :customer ] [ :address_1 ] = 'Miguel Angel Blanco 2 4C'
93
+ wqp [ :line_items ] [ 1 ] [ :customer ] [ :city ] = 'Valladolid'
94
+ wqp [ :line_items ] [ 1 ] [ :customer ] [ :state ] = 'VA'
95
+ wqp [ :line_items ] [ 1 ] [ :customer ] [ :postal_code ] = '47014'
96
+ wqp [ :line_items ] [ 1 ] [ :customer ] [ :country ] = 'ES'
97
+ end
98
+ end
99
+ let ( :payload ) { VertexClient ::Payload ::QuotationFallback . new ( params ) }
100
+
101
+ it 'does not use the US rates' do
102
+ assert_equal 0.0 , response . total_tax . to_f
103
+ end
104
+ end
83
105
end
84
106
85
107
describe 'total' do
You can’t perform that action at this time.
0 commit comments