From 038f392070aab53512871a1208081b1122968536 Mon Sep 17 00:00:00 2001 From: Noah Silvera Date: Fri, 30 Apr 2021 10:51:32 -0700 Subject: 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 --- lib/super_good/solidus_taxjar/api_params.rb | 2 +- spec/super_good/solidus_taxjar/api_params_spec.rb | 30 +++++++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) 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 -- cgit v1.2.3