Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v0.11.1 -> v0.11.2: take country into account when determining state fallback rate #83

Merged
merged 1 commit into from
Jan 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

This file tracks all the changes (https://keepachangelog.com/en/1.0.0/) made to the client. This allows parsers such as Dependabot to provide a clean overview in pull requests.

## [v0.11.2] - 2025-01-16

#### Changed

- Take country code into account when determining applicable state tax rate in fallback quotation context.

## [v0.11.1] - 2024-12-05

#### Changed
Expand Down
15 changes: 5 additions & 10 deletions lib/vertex_client/responses/quotation_fallback.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,23 +29,18 @@ def product_for_line_item(product)

# see lib/vertex_client/rates.rb for hard-coded fallback rates
def tax_amount(price, country, state)
if known_us_state?(state)
if domestic?(country) && state.present? && RATES['US'].has_key?(state)
price * BigDecimal(RATES['US'][state])
elsif known_non_us_country?(country)
elsif !domestic?(country) && country.present? && RATES.has_key?(country)
price * BigDecimal(RATES[country])
else
BigDecimal('0.0')
end
end

# state is in the United States and we have an explicit fallback
def known_us_state?(state)
state.present? && RATES['US'].has_key?(state)
end

# we have an explicit fallback for the country
def known_non_us_country?(country)
country.present? && country != 'US' && RATES.has_key?(country)
def domestic?(country)
# we assume a country-less customer is from the US
country.nil? || country == 'US'
end

def tax_for_line_item(line_item)
Expand Down
2 changes: 1 addition & 1 deletion lib/vertex_client/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module VertexClient
VERSION = '0.11.1'
VERSION = '0.11.2'
end
22 changes: 22 additions & 0 deletions test/responses/quotation_fallback_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,28 @@
assert_equal 0.0, response.total_tax.to_f
end
end

describe 'for a country with a state code that collides with a US state code' do
let(:params) do
working_quote_params.tap do |wqp|
wqp[:customer][:address_1] = 'Miguel Angel Blanco 2 4C'
wqp[:customer][:city] = 'Valladolid'
wqp[:customer][:state] = 'VA'
wqp[:customer][:postal_code] = '47014'
wqp[:customer][:country] = 'ES'
wqp[:line_items][1][:customer][:address_1] = 'Miguel Angel Blanco 2 4C'
wqp[:line_items][1][:customer][:city] = 'Valladolid'
wqp[:line_items][1][:customer][:state] = 'VA'
wqp[:line_items][1][:customer][:postal_code] = '47014'
wqp[:line_items][1][:customer][:country] = 'ES'
end
end
let(:payload) { VertexClient::Payload::QuotationFallback.new(params) }

it 'does not use the US rates' do
assert_equal 0.0, response.total_tax.to_f
end
end
end

describe 'total' do
Expand Down