From c1bf02cf6586b537535956a98c3864d05ecdecc6 Mon Sep 17 00:00:00 2001 From: Jared Norman Date: Thu, 24 Jan 2019 18:09:32 -0800 Subject: Use DiscountCalculator and fix duplication There's no reason for both the TaxCalculator and the API to have nearly the same logic... so I unified that while was in there. --- lib/super_good/solidus_taxjar/api.rb | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'lib/super_good/solidus_taxjar/api.rb') diff --git a/lib/super_good/solidus_taxjar/api.rb b/lib/super_good/solidus_taxjar/api.rb index ffefd5f..2504216 100644 --- a/lib/super_good/solidus_taxjar/api.rb +++ b/lib/super_good/solidus_taxjar/api.rb @@ -26,10 +26,6 @@ module SuperGood ) end - private - - attr_reader :taxjar_client - def order_params(order) tax_address = order.tax_address @@ -47,12 +43,20 @@ module SuperGood id: line_item.id, quantity: line_item.quantity, unit_price: line_item.price, - discount: -line_item.promo_total, + discount: discount(line_item), product_tax_code: line_item.tax_category&.tax_code } end } end + + private + + attr_reader :taxjar_client + + def discount(line_item) + ::SuperGood::SolidusTaxJar.discount_calculator.new(line_item).discount + end end end end -- cgit v1.2.3