From eaf4f8186610b2b1042630040f5fe96e38d8252f Mon Sep 17 00:00:00 2001 From: Jared Norman Date: Mon, 13 May 2019 19:44:38 -0700 Subject: Sort some things I like sorted things. --- spec/super_good/solidus_taxjar/api_params_spec.rb | 55 +++++++++++------------ 1 file changed, 27 insertions(+), 28 deletions(-) diff --git a/spec/super_good/solidus_taxjar/api_params_spec.rb b/spec/super_good/solidus_taxjar/api_params_spec.rb index daa5b63..0311ab4 100644 --- a/spec/super_good/solidus_taxjar/api_params_spec.rb +++ b/spec/super_good/solidus_taxjar/api_params_spec.rb @@ -3,14 +3,14 @@ require 'spec_helper' RSpec.describe SuperGood::SolidusTaxJar::APIParams do let(:order) do Spree::Order.create!( - number: "R111222333", - total: order_total, - shipment_total: BigDecimal("3.01"), additional_tax_total: BigDecimal("9.87"), item_total: BigDecimal("28.00"), - store: store, + line_items: [line_item], + number: "R111222333", ship_address: ship_address, - line_items: [line_item] + shipment_total: BigDecimal("3.01"), + store: store, + total: order_total ).tap do |order| order.update! completed_at: DateTime.new(2018, 3, 6, 12, 10, 33) end @@ -19,33 +19,32 @@ RSpec.describe SuperGood::SolidusTaxJar::APIParams do let(:store) do Spree::Store.create!( - name: "Default Store", - url: "https://store.example.com", + cart_tax_country_iso: "US", code: "store", mail_from_address: "contact@example.com", - cart_tax_country_iso: "US" + name: "Default Store", + url: "https://store.example.com" ) end let(:ship_address) do Spree::Address.create!( - country: country_us, - state: state_california, - zipcode: "90210", - city: "Los Angeles", address1: "475 N Beverly Dr", - + city: "Los Angeles", + country: country_us, first_name: "Chuck", last_name: "Schuldiner", - phone: "1-250-555-4444" + phone: "1-250-555-4444", + state: state_california, + zipcode: "90210" ) end let(:country_us) do Spree::Country.create!( - iso_name: "UNITED STATES", - iso: "US", iso3: "USA", + iso: "US", + iso_name: "UNITED STATES", name: "United States", numcode: 840, states_required: true @@ -54,36 +53,36 @@ RSpec.describe SuperGood::SolidusTaxJar::APIParams do let(:state_california) do Spree::State.create!( + abbr: "CA", country: country_us, - name: "California", - abbr: "CA" + name: "California" ) end let(:line_item) do Spree::LineItem.new( - variant: variant, + additional_tax_total: 4, price: 10, - quantity: 3, promo_total: -2, - additional_tax_total: 4 + quantity: 3, + variant: variant ) end let(:variant) do Spree::Variant.create!( - sku: "G00D-PR0DUCT", + price: 10, product: product, - price: 10 + sku: "G00D-PR0DUCT" ) end let(:product) do Spree::Product.create!( + master: master_variant, name: "Product Name", shipping_category: shipping_category, tax_category: tax_category, - master: master_variant, variants: [master_variant] ) end @@ -94,8 +93,8 @@ RSpec.describe SuperGood::SolidusTaxJar::APIParams do let(:tax_category) do Spree::TaxCategory.create!( - name: "Default", is_default: true, + name: "Default", tax_code: "A_GEN_TAX" ) end @@ -109,13 +108,13 @@ RSpec.describe SuperGood::SolidusTaxJar::APIParams do let(:reimbursement) do Spree::Reimbursement.new( - order: order, - total: 333.33, number: "RI123123123", + order: order, return_items: [ Spree::ReturnItem.new(additional_tax_total: 0.33), Spree::ReturnItem.new(additional_tax_total: 33.0) - ] + ], + total: 333.33 ) end -- cgit v1.2.3 From 1015448f7dc6efa85a4b65c5417dfc870571ea73 Mon Sep 17 00:00:00 2001 From: Jared Norman Date: Mon, 13 May 2019 20:10:05 -0700 Subject: Send customer_id to TaxJar API This is required to support per-customer exemptions through the TaxJar API. --- CHANGELOG.md | 2 ++ lib/super_good/solidus_taxjar/api_params.rb | 8 ++++++++ spec/super_good/solidus_taxjar/api_params_spec.rb | 7 ++++++- 3 files changed, 16 insertions(+), 1 deletion(-) 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", -- cgit v1.2.3 From 09194d30b4e1681d1048135ab64f7ef67dd39479 Mon Sep 17 00:00:00 2001 From: Jared Norman Date: Mon, 13 May 2019 20:10:51 -0700 Subject: Fix wack indentation 1-space????? --- spec/super_good/solidus_taxjar/api_params_spec.rb | 64 +++++++++++------------ 1 file changed, 32 insertions(+), 32 deletions(-) diff --git a/spec/super_good/solidus_taxjar/api_params_spec.rb b/spec/super_good/solidus_taxjar/api_params_spec.rb index 9718b88..558379f 100644 --- a/spec/super_good/solidus_taxjar/api_params_spec.rb +++ b/spec/super_good/solidus_taxjar/api_params_spec.rb @@ -192,26 +192,26 @@ 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", - to_country: "US", - to_state: "CA", - to_street: "475 N Beverly Dr", - to_zip: "90210", - transaction_date: "2018-03-06T12:10:33Z", - transaction_id: "R111222333", - line_items: [{ - id: line_item.id, - quantity: 3, - product_identifier: "G00D-PR0DUCT", - product_tax_code: "A_GEN_TAX", - unit_price: 10, - discount: 2, - sales_tax: 4 - }] + amount: BigDecimal("113.58"), + customer_id: "12345", + sales_tax: BigDecimal("9.87"), + shipping: BigDecimal("3.01"), + to_city: "Los Angeles", + to_country: "US", + to_state: "CA", + to_street: "475 N Beverly Dr", + to_zip: "90210", + transaction_date: "2018-03-06T12:10:33Z", + transaction_id: "R111222333", + line_items: [{ + id: line_item.id, + quantity: 3, + product_identifier: "G00D-PR0DUCT", + product_tax_code: "A_GEN_TAX", + unit_price: 10, + discount: 2, + sales_tax: 4 + }] }) end @@ -252,18 +252,18 @@ 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", - to_country: "US", - to_state: "CA", - to_street: "475 N Beverly Dr", - to_zip: "90210", - transaction_date: "2018-03-06T12:10:33Z", - transaction_id: "R111222333", - line_items: [] + amount: BigDecimal("113.58"), + customer_id: "12345", + sales_tax: BigDecimal("9.87"), + shipping: BigDecimal("3.01"), + to_city: "Los Angeles", + to_country: "US", + to_state: "CA", + to_street: "475 N Beverly Dr", + to_zip: "90210", + transaction_date: "2018-03-06T12:10:33Z", + transaction_id: "R111222333", + line_items: [] }) end end -- cgit v1.2.3 From 25c28ac69ba771318382d26c3346c0d36bce8990 Mon Sep 17 00:00:00 2001 From: Jared Norman Date: Mon, 13 May 2019 20:13:12 -0700 Subject: Sort the rest of the things --- spec/super_good/solidus_taxjar/api_params_spec.rb | 68 +++++++++++------------ 1 file changed, 32 insertions(+), 36 deletions(-) diff --git a/spec/super_good/solidus_taxjar/api_params_spec.rb b/spec/super_good/solidus_taxjar/api_params_spec.rb index 558379f..3a55655 100644 --- a/spec/super_good/solidus_taxjar/api_params_spec.rb +++ b/spec/super_good/solidus_taxjar/api_params_spec.rb @@ -125,47 +125,43 @@ 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", - to_state: "CA", - to_street: "475 N Beverly Dr", - - shipping: 3.01, - line_items: [{ + discount: 2.00, id: order.line_items.first.id, + product_tax_code: "A_GEN_TAX", quantity: 3, - unit_price: 10.00, - discount: 2.00, - product_tax_code: "A_GEN_TAX" - }] + unit_price: 10.00 + }], + shipping: 3.01, + to_city: "Los Angeles", + to_country: "US", + to_state: "CA", + to_street: "475 N Beverly Dr", + to_zip: "90210" ) end context "when the line item has zero quantity" do let(:line_item) do Spree::LineItem.new( - variant: variant, + additional_tax_total: 4, price: 10, - quantity: 0, promo_total: -2, - additional_tax_total: 4 + quantity: 0, + variant: variant ) end it "excludes the line item" do expect(subject).to eq( customer_id: "12345", - to_country: "US", - to_zip: "90210", + line_items: [], + shipping: 3.01, to_city: "Los Angeles", + to_country: "US", to_state: "CA", to_street: "475 N Beverly Dr", - - shipping: 3.01, - - line_items: [] + to_zip: "90210" ) end end @@ -194,6 +190,15 @@ RSpec.describe SuperGood::SolidusTaxJar::APIParams do expect(subject).to eq({ amount: BigDecimal("113.58"), customer_id: "12345", + line_items: [{ + discount: 2, + id: line_item.id, + product_identifier: "G00D-PR0DUCT", + product_tax_code: "A_GEN_TAX", + quantity: 3, + sales_tax: 4, + unit_price: 10 + }], sales_tax: BigDecimal("9.87"), shipping: BigDecimal("3.01"), to_city: "Los Angeles", @@ -202,16 +207,7 @@ RSpec.describe SuperGood::SolidusTaxJar::APIParams do to_street: "475 N Beverly Dr", to_zip: "90210", transaction_date: "2018-03-06T12:10:33Z", - transaction_id: "R111222333", - line_items: [{ - id: line_item.id, - quantity: 3, - product_identifier: "G00D-PR0DUCT", - product_tax_code: "A_GEN_TAX", - unit_price: 10, - discount: 2, - sales_tax: 4 - }] + transaction_id: "R111222333" }) end @@ -242,11 +238,11 @@ RSpec.describe SuperGood::SolidusTaxJar::APIParams do context "when the line item has 0 quantity" do let(:line_item) do Spree::LineItem.new( - variant: variant, + additional_tax_total: 4, price: 10, - quantity: 0, promo_total: -2, - additional_tax_total: 4 + quantity: 0, + variant: variant ) end @@ -254,6 +250,7 @@ RSpec.describe SuperGood::SolidusTaxJar::APIParams do expect(subject).to eq({ amount: BigDecimal("113.58"), customer_id: "12345", + line_items: [], sales_tax: BigDecimal("9.87"), shipping: BigDecimal("3.01"), to_city: "Los Angeles", @@ -263,7 +260,6 @@ RSpec.describe SuperGood::SolidusTaxJar::APIParams do to_zip: "90210", transaction_date: "2018-03-06T12:10:33Z", transaction_id: "R111222333", - line_items: [] }) end end @@ -284,7 +280,7 @@ RSpec.describe SuperGood::SolidusTaxJar::APIParams do to_zip: "90210", transaction_date: "2018-03-06T12:10:33Z", transaction_id: "RI123123123", - transaction_reference_id: "R111222333", + transaction_reference_id: "R111222333" }) end end -- cgit v1.2.3