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 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'lib/super_good/solidus_taxjar') 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 -- cgit v1.2.3