-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #22 from SuperGoodSoft/address-validation
Support for TaxJar Address Validation API
- Loading branch information
Showing
18 changed files
with
470 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,16 @@ | ||
#!/usr/bin/env ruby | ||
|
||
app_root = 'sandbox' | ||
app_root = "sandbox" | ||
|
||
unless File.exist? "#{app_root}/bin/rails" | ||
warn 'Creating the sandbox app...' | ||
warn "Creating the sandbox app..." | ||
Dir.chdir "#{__dir__}/.." do | ||
system "#{__dir__}/sandbox" or begin # rubocop:disable Style/AndOr | ||
warn 'Automatic creation of the sandbox app failed' | ||
warn "Automatic creation of the sandbox app failed" | ||
exit 1 | ||
end | ||
end | ||
end | ||
|
||
Dir.chdir app_root | ||
exec 'bin/rails', *ARGV | ||
exec "bin/rails", *ARGV |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
require 'super_good/solidus_taxjar' | ||
require "super_good/solidus_taxjar" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
module SuperGood | ||
module SolidusTaxJar | ||
class Addresses | ||
class << self | ||
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) | ||
@api = api | ||
end | ||
|
||
def normalize(spree_address) | ||
taxjar_address = taxjar_addresses(spree_address).first | ||
|
||
return if taxjar_address.nil? | ||
|
||
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 | ||
|
||
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 | ||
|
||
def state(abbr) | ||
us.states.find_by_abbr abbr | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.