Skip to content

Commit

Permalink
Merge pull request #65 from customink/ak/dont-require-zip-outside-us
Browse files Browse the repository at this point in the history
Don't require postal_code for non-US locations
  • Loading branch information
Adam Kulisek authored Apr 29, 2021
2 parents ffae838 + 19f87e3 commit 5e62a54
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 30 deletions.
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.10.1] - 2021-04-29

#### Changed

- Loosen quotation validation rules to only require `postal_code` for `US` based locations.

## [v0.10.0] - 2020-09-29

#### Added
Expand Down
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,20 +95,22 @@ response.subtotal #=> Total price before tax
```

#### Location specific data (required for `:customer` and specified `:physical_origin` of `:seller` in `:line_items`)
You are required to specify a `state` or a `country`. The client will raise an error if none is specified.
You are required to specify a `state` or a `country`. The client will raise an error if none is specified.

At the moment specifying state automatically implies `country` is `US`. For `US` locations `postal_code` is also required.

##### US address example
```ruby
customer: {
...
state: "NY",
# Optional, you don't have to explicitly specify a country once state is set
country: "US",
postal_code: "10005",
country: "US", # Optional, you don't have to explicitly specify a country once state is set
...
}
```
##### Non-US address example
`state` is an optional attribute for non-US countries
`state` and `postal_code` are optional attributes for non-US countries
```ruby
customer: {
...
Expand Down
4 changes: 2 additions & 2 deletions lib/vertex_client/payloads/quotation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def sellers_physical_origin_lines(params)

# The hash argument is either customer or physical_origin object
def destination_present?(hash)
(us_location_present?(hash) || other_location_present?(hash)) && hash[:postal_code].present?
us_location_present?(hash) || other_location_present?(hash)
end

def transform_line_item(line_item, number, defaults)
Expand Down Expand Up @@ -79,7 +79,7 @@ def transform_product(line_item)
end

def us_location_present?(customer)
customer[:state].present?
customer[:state].present? && customer[:postal_code].present?
end

def other_location_present?(customer)
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.10.0'
VERSION = '0.10.1'
end
6 changes: 0 additions & 6 deletions test/payload_validator_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,7 @@

before(:each) do
payload[:customer].delete(:state)
end

it 'raises an error when missing postal code' do
payload[:customer].delete(:postal_code)
assert_raises VertexClient::ValidationError do
VertexClient::Payload::Quotation.new(payload)
end
end

it 'raises an error when missing country' do
Expand Down
20 changes: 3 additions & 17 deletions test/payloads/quotation_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,10 @@
describe 'for EU customer' do
before(:each) do
working_eu_quote_params[:customer].delete(:state)
working_eu_quote_params[:customer].delete(:postal_code)
end

it 'is happy if country and postal_code are present on customer' do
it 'is happy if country is present on customer' do
VertexClient::Payload::Quotation.new(working_eu_quote_params).validate!
end

Expand All @@ -66,13 +67,6 @@
VertexClient::Payload::Quotation.new(working_eu_quote_params).body
end
end

it 'raises if the customer is missing postal_code' do
working_eu_quote_params[:customer].delete(:postal_code)
assert_raises VertexClient::ValidationError do
VertexClient::Payload::Quotation.new(working_eu_quote_params).body
end
end
end

describe 'for seller override' do
Expand Down Expand Up @@ -117,12 +111,11 @@
working_eu_quote_params[:line_items][1][:seller][:physical_origin] = {
address_1: 'Prujezdna 320/62',
city: 'Praha',
postal_code: '100 00',
country: 'CZ'
}
end

it 'does not raise if country and postal_code are present' do
it 'does not raise if country is present' do
VertexClient::Payload::Quotation.new(working_eu_quote_params).validate!
end

Expand All @@ -132,13 +125,6 @@
VertexClient::Payload::Quotation.new(working_eu_quote_params).body
end
end

it 'raises if physical_origin is missing postal_code' do
working_eu_quote_params[:line_items][1][:seller][:physical_origin].delete(:postal_code)
assert_raises VertexClient::ValidationError do
VertexClient::Payload::Quotation.new(working_eu_quote_params).body
end
end
end
end
end
Expand Down

0 comments on commit 5e62a54

Please sign in to comment.