summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJared Norman <jared@super.gd>2019-03-19 12:49:03 -0700
committerJared Norman <jared@super.gd>2019-03-19 12:49:03 -0700
commit0d3d8783755d18c0d6ebfc95f3109b518e7e1b07 (patch)
treea786b218ddf0b3147876c329ddb1f96f07e19254
parentf5f234e82ab8f2cc5044c9299e8894ff9dcbbf8d (diff)
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.
-rw-r--r--lib/super_good/solidus_taxjar/api_params.rb17
-rw-r--r--spec/super_good/solidus_taxjar/api_params_spec.rb13
2 files changed, 29 insertions, 1 deletions
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