diff options
author | Noah Silvera <noah@super.gd> | 2021-04-30 10:51:32 -0700 |
---|---|---|
committer | Noah Silvera <noah@super.gd> | 2021-05-19 12:01:16 -0700 |
commit | 038f392070aab53512871a1208081b1122968536 (patch) | |
tree | 82e7cc65e6b7228395286398dc9fa6140ce812bd | |
parent | 676adfa988317ef15ee412f230e1431648774ff4 (diff) |
Use spree address2 if it is present
The taxjar validation API has the option to take a freeform
street input consisting of the full address. This means that if both
address1 and address2 exist, we should concatenate them and pass them
to the street parameter.
This can help with situations that involve a suite number that has a
unique ZIP+4 code that can be determined from the suite. The suite
number is usually kept in address2, so without it, there's no way to
distinguish the full address if only the 5 digit zip code is passed.
Co-authored-by: Nick Van Doorn <nick@super.gd>
-rw-r--r-- | lib/super_good/solidus_taxjar/api_params.rb | 2 | ||||
-rw-r--r-- | spec/super_good/solidus_taxjar/api_params_spec.rb | 30 |
2 files changed, 31 insertions, 1 deletions
diff --git a/lib/super_good/solidus_taxjar/api_params.rb b/lib/super_good/solidus_taxjar/api_params.rb index ef189e9..2e0e92c 100644 --- a/lib/super_good/solidus_taxjar/api_params.rb +++ b/lib/super_good/solidus_taxjar/api_params.rb @@ -72,7 +72,7 @@ module SuperGood state: spree_address.state&.abbr || spree_address.state_name, zip: spree_address.zipcode, city: spree_address.city, - street: spree_address.address1 + street: [spree_address.address1, spree_address.address2].compact.join(' ') } end diff --git a/spec/super_good/solidus_taxjar/api_params_spec.rb b/spec/super_good/solidus_taxjar/api_params_spec.rb index 1e879e7..df374d5 100644 --- a/spec/super_good/solidus_taxjar/api_params_spec.rb +++ b/spec/super_good/solidus_taxjar/api_params_spec.rb @@ -400,5 +400,35 @@ RSpec.describe SuperGood::SolidusTaxjar::ApiParams do }) end end + + context "an address with address2" do + let(:ship_address) do + Spree::Address.create!( + address1: "1 World Trade CTR", + address2: "STE 45A", + city: "New York", + country: country_us, + first_name: "Chuck", + last_name: "Schuldiner", + phone: "1-250-555-4444", + state: Spree::State.create!( + abbr: "NY", + country: country_us, + name: "New York" + ), + zipcode: "10007" + ) + end + + it "concatenates address1 and address2 into the street parameter" do + expect(subject).to eq({ + country: "US", + state: "NY", + zip: "10007", + city: "New York", + street: "1 World Trade CTR STE 45A" + }) + end + end end end |