diff options
-rw-r--r-- | CHANGELOG.md | 2 | ||||
-rw-r--r-- | lib/super_good/solidus_taxjar/api_params.rb | 8 | ||||
-rw-r--r-- | spec/super_good/solidus_taxjar/api_params_spec.rb | 7 |
3 files changed, 16 insertions, 1 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 25648a6..2e4767e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## master +- Report order.user_id as customer_id when calculating taxes and creating transactions. This enables the use of per customer exemptions. + ## v0.12.0 - Report no tax collected on order and line items when order total zeroed out. diff --git a/lib/super_good/solidus_taxjar/api_params.rb b/lib/super_good/solidus_taxjar/api_params.rb index 53b2c81..7c6942f 100644 --- a/lib/super_good/solidus_taxjar/api_params.rb +++ b/lib/super_good/solidus_taxjar/api_params.rb @@ -4,6 +4,7 @@ module SuperGood class << self def order_params(order) {} + .merge(customer_params(order)) .merge(order_address_params(order.tax_address)) .merge(line_items_params(order.line_items)) .merge(shipping: order.shipment_total) @@ -23,6 +24,7 @@ module SuperGood def transaction_params(order) {} + .merge(customer_params(order)) .merge(order_address_params(order.tax_address)) .merge(transaction_line_items_params(order.line_items)) .merge( @@ -51,6 +53,12 @@ module SuperGood private + def customer_params(order) + return {} unless order.user_id + + { customer_id: order.user_id.to_s } + end + def order_address_params(address) { to_country: address.country.iso, diff --git a/spec/super_good/solidus_taxjar/api_params_spec.rb b/spec/super_good/solidus_taxjar/api_params_spec.rb index 0311ab4..9718b88 100644 --- a/spec/super_good/solidus_taxjar/api_params_spec.rb +++ b/spec/super_good/solidus_taxjar/api_params_spec.rb @@ -10,7 +10,8 @@ RSpec.describe SuperGood::SolidusTaxJar::APIParams do ship_address: ship_address, shipment_total: BigDecimal("3.01"), store: store, - total: order_total + total: order_total, + user_id: 12345 ).tap do |order| order.update! completed_at: DateTime.new(2018, 3, 6, 12, 10, 33) end @@ -123,6 +124,7 @@ RSpec.describe SuperGood::SolidusTaxJar::APIParams do it "returns params for fetching the tax for the order" do expect(subject).to eq( + customer_id: "12345", to_country: "US", to_zip: "90210", to_city: "Los Angeles", @@ -154,6 +156,7 @@ RSpec.describe SuperGood::SolidusTaxJar::APIParams do it "excludes the line item" do expect(subject).to eq( + customer_id: "12345", to_country: "US", to_zip: "90210", to_city: "Los Angeles", @@ -190,6 +193,7 @@ RSpec.describe SuperGood::SolidusTaxJar::APIParams do it "returns params for creating/updating an order transaction" do expect(subject).to eq({ amount: BigDecimal("113.58"), + customer_id: "12345", sales_tax: BigDecimal("9.87"), shipping: BigDecimal("3.01"), to_city: "Los Angeles", @@ -249,6 +253,7 @@ RSpec.describe SuperGood::SolidusTaxJar::APIParams do it "excludes the line item" do expect(subject).to eq({ amount: BigDecimal("113.58"), + customer_id: "12345", sales_tax: BigDecimal("9.87"), shipping: BigDecimal("3.01"), to_city: "Los Angeles", |