diff options
author | Jared Norman <jared@super.gd> | 2019-01-30 13:07:40 -0800 |
---|---|---|
committer | Jared Norman <jared@super.gd> | 2019-01-30 13:07:40 -0800 |
commit | 8f3744abd7f06da848856136a7888c2b01b40ee5 (patch) | |
tree | 697c9c83e5db393f063823444282c0a32c053ae3 /lib | |
parent | 0152c8c4d62300e52e02d1d841e1d59ee36add99 (diff) |
Integrate APIParams class
This removes the logic from the API class and moves all the calls to the
order_params method to our new module.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/super_good/solidus_taxjar.rb | 1 | ||||
-rw-r--r-- | lib/super_good/solidus_taxjar/api.rb | 30 | ||||
-rw-r--r-- | lib/super_good/solidus_taxjar/tax_calculator.rb | 2 |
3 files changed, 3 insertions, 30 deletions
diff --git a/lib/super_good/solidus_taxjar.rb b/lib/super_good/solidus_taxjar.rb index 82f9500..be56453 100644 --- a/lib/super_good/solidus_taxjar.rb +++ b/lib/super_good/solidus_taxjar.rb @@ -3,6 +3,7 @@ require 'solidus_support' require 'taxjar' require "super_good/solidus_taxjar/version" +require "super_good/solidus_taxjar/api_params" require "super_good/solidus_taxjar/api" require "super_good/solidus_taxjar/tax_calculator" require "super_good/solidus_taxjar/discount_calculator" diff --git a/lib/super_good/solidus_taxjar/api.rb b/lib/super_good/solidus_taxjar/api.rb index 2504216..1392a47 100644 --- a/lib/super_good/solidus_taxjar/api.rb +++ b/lib/super_good/solidus_taxjar/api.rb @@ -13,7 +13,7 @@ module SuperGood end def tax_for(order) - taxjar_client.tax_for_order order_params(order) + taxjar_client.tax_for_order APIParams.order_params(order) end def tax_rates_for(address) @@ -26,37 +26,9 @@ module SuperGood ) end - def order_params(order) - tax_address = order.tax_address - - { - to_country: tax_address.country.iso, - to_zip: tax_address.zipcode, - to_city: tax_address.city, - to_state: tax_address&.state&.abbr || tax_address.state_name, - to_street: tax_address.address1, - - shipping: order.shipment_total, - - line_items: order.line_items.map do |line_item| - { - id: line_item.id, - quantity: line_item.quantity, - unit_price: line_item.price, - discount: discount(line_item), - product_tax_code: line_item.tax_category&.tax_code - } - end - } - end - private attr_reader :taxjar_client - - def discount(line_item) - ::SuperGood::SolidusTaxJar.discount_calculator.new(line_item).discount - end end end end diff --git a/lib/super_good/solidus_taxjar/tax_calculator.rb b/lib/super_good/solidus_taxjar/tax_calculator.rb index a521f0d..b9e6444 100644 --- a/lib/super_good/solidus_taxjar/tax_calculator.rb +++ b/lib/super_good/solidus_taxjar/tax_calculator.rb @@ -121,7 +121,7 @@ module SuperGood end def cache_key - api.order_params(order).transform_values do |value| + APIParams.order_params(order).transform_values do |value| case value when Array, Hash then value.hash else |