summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJared Norman <jared@super.gd>2019-03-19 12:58:37 -0700
committerGitHub <noreply@github.com>2019-03-19 12:58:37 -0700
commit132bf515857d04f79143650a529d956e3bfb44a1 (patch)
tree229ad98b7272d97c2020d25a306089791eb3cddc
parentf5f234e82ab8f2cc5044c9299e8894ff9dcbbf8d (diff)
parent84d0cf6c10bef0818f20e37531996a4bed29b6b2 (diff)
Merge pull request #5 from SuperGoodSoft/feature/report-line-itemsv0.7.0
Send full line item list when creating/updating transactions
-rw-r--r--CHANGELOG.md4
-rw-r--r--lib/super_good/solidus_taxjar/api_params.rb17
-rw-r--r--lib/super_good/solidus_taxjar/version.rb2
-rw-r--r--spec/super_good/solidus_taxjar/api_params_spec.rb13
4 files changed, 34 insertions, 2 deletions
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/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/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
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