diff options
author | Jared Norman <jared@super.gd> | 2020-07-09 12:20:23 -0700 |
---|---|---|
committer | Jared Norman <jared@super.gd> | 2020-07-14 13:07:55 -0700 |
commit | fa3abe77f2e05ccabda975c82eec73929e1b3bee (patch) | |
tree | f1df8217b05c7b97a1f23415c248a693b6b1a649 /lib/super_good | |
parent | c348c0be29f772b4a0ca32ee3061f74a602e2bd9 (diff) |
Add ability to fetch address possibilities
Diffstat (limited to 'lib/super_good')
-rw-r--r-- | lib/super_good/solidus_taxjar/addresses.rb | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/lib/super_good/solidus_taxjar/addresses.rb b/lib/super_good/solidus_taxjar/addresses.rb index 8103269..0993a03 100644 --- a/lib/super_good/solidus_taxjar/addresses.rb +++ b/lib/super_good/solidus_taxjar/addresses.rb @@ -5,6 +5,10 @@ module SuperGood def normalize(spree_address) new.normalize(spree_address) end + + def possibilities(spree_address) + new.possibilities(spree_address) + end end def initialize(api: ::SuperGood::SolidusTaxJar.api) @@ -12,7 +16,7 @@ module SuperGood end def normalize(spree_address) - taxjar_address = api.validate_spree_address(spree_address).first + taxjar_address = taxjar_addresses(spree_address).first return if taxjar_address.nil? @@ -25,10 +29,26 @@ module SuperGood }) end + def possibilities(spree_address) + taxjar_addresses(spree_address).map { |taxjar_address| + Spree::Address.immutable_merge(spree_address, { + country: us, # TaxJar only supports the US currently. + state: state(taxjar_address.state), + zipcode: taxjar_address.zip, + city: taxjar_address.city, + address1: taxjar_address.street + }) + } + end + private attr_reader :api + def taxjar_addresses(spree_address) + api.validate_spree_address(spree_address) + end + def us Spree::Country.find_by iso: "US" end |