From 0d3d8783755d18c0d6ebfc95f3109b518e7e1b07 Mon Sep 17 00:00:00 2001 From: Jared Norman Date: Tue, 19 Mar 2019 12:49:03 -0700 Subject: Report full line item list for transactions This sends the full list of line items in the order with their SKUs and tax codes when creating/updating transactions in TaxJar. --- lib/super_good/solidus_taxjar/api_params.rb | 17 +++++++++++++++++ spec/super_good/solidus_taxjar/api_params_spec.rb | 13 ++++++++++++- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/lib/super_good/solidus_taxjar/api_params.rb b/lib/super_good/solidus_taxjar/api_params.rb index b848eee..cb554a8 100644 --- a/lib/super_good/solidus_taxjar/api_params.rb +++ b/lib/super_good/solidus_taxjar/api_params.rb @@ -24,6 +24,7 @@ module SuperGood def transaction_params(order) {} .merge(order_address_params(order.tax_address)) + .merge(transaction_line_items_params(order.line_items)) .merge( transaction_id: order.number, transaction_date: order.completed_at.to_formatted_s(:iso8601), @@ -74,6 +75,22 @@ module SuperGood } end + def transaction_line_items_params(line_items) + { + line_items: line_items.map do |line_item| + { + id: line_item.id, + quantity: line_item.quantity, + product_identifier: line_item.sku, + product_tax_code: line_item.tax_category&.tax_code, + unit_price: line_item.price, + discount: discount(line_item), + sales_tax: line_item.additional_tax_total + } + end + } + end + def discount(line_item) ::SuperGood::SolidusTaxJar.discount_calculator.new(line_item).discount end diff --git a/spec/super_good/solidus_taxjar/api_params_spec.rb b/spec/super_good/solidus_taxjar/api_params_spec.rb index 8b0e9d0..abc8a23 100644 --- a/spec/super_good/solidus_taxjar/api_params_spec.rb +++ b/spec/super_good/solidus_taxjar/api_params_spec.rb @@ -64,12 +64,14 @@ RSpec.describe SuperGood::SolidusTaxJar::APIParams do variant: variant, price: 10, quantity: 3, - promo_total: -2 + promo_total: -2, + additional_tax_total: 4 ) end let(:variant) do Spree::Variant.create!( + sku: "G00D-PR0DUCT", product: product, price: 10 ) @@ -171,6 +173,15 @@ RSpec.describe SuperGood::SolidusTaxJar::APIParams do 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 end -- cgit v1.2.3 From 84d0cf6c10bef0818f20e37531996a4bed29b6b2 Mon Sep 17 00:00:00 2001 From: Jared Norman Date: Tue, 19 Mar 2019 12:51:26 -0700 Subject: Bump to v0.7.0, update CHANGELOG.md --- CHANGELOG.md | 4 ++++ lib/super_good/solidus_taxjar/version.rb | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3d3d0df..c344a93 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## v0.7.0 + +- Switched to sending the full list of line items when creating/updating transactions in TaxJar. + ## v0.6.2 - Fixed issued where orders without tax address would cause errors because `Spree::Order#tax_address` will return a `Spree::Tax::TaxLocation` when called on an order without a tax address. `Spree::Tax::TaxLocation` isn't enough like a real address and this was causing exceptions. diff --git a/lib/super_good/solidus_taxjar/version.rb b/lib/super_good/solidus_taxjar/version.rb index 6ca181f..a27c342 100644 --- a/lib/super_good/solidus_taxjar/version.rb +++ b/lib/super_good/solidus_taxjar/version.rb @@ -1,5 +1,5 @@ module SuperGood module SolidusTaxJar - VERSION = "0.6.2" + VERSION = "0.7.0" end end -- cgit v1.2.3