From cb740a35890e9aad7f5206f4c4759c497cbff115 Mon Sep 17 00:00:00 2001 From: Jared Norman Date: Thu, 11 Apr 2019 13:49:55 +1200 Subject: Avoid sending 0 quantity line items --- lib/super_good/solidus_taxjar/api_params.rb | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'lib/super_good') diff --git a/lib/super_good/solidus_taxjar/api_params.rb b/lib/super_good/solidus_taxjar/api_params.rb index 8596856..25f8317 100644 --- a/lib/super_good/solidus_taxjar/api_params.rb +++ b/lib/super_good/solidus_taxjar/api_params.rb @@ -63,7 +63,7 @@ module SuperGood def line_items_params(line_items) { - line_items: line_items.map do |line_item| + line_items: valid_line_items(line_items).map do |line_item| { id: line_item.id, quantity: line_item.quantity, @@ -77,7 +77,7 @@ module SuperGood def transaction_line_items_params(line_items) { - line_items: line_items.map do |line_item| + line_items: valid_line_items(line_items).map do |line_item| { id: line_item.id, quantity: line_item.quantity, @@ -91,6 +91,14 @@ module SuperGood } end + def valid_line_items(line_items) + # The API appears to error when sent line items with no quantity... + # but why would you do that anyway. + line_items.reject do |line_item| + line_item.quantity.zero? + end + end + def discount(line_item) ::SuperGood::SolidusTaxJar.discount_calculator.new(line_item).discount end -- cgit v1.2.3