summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorJared Norman <jared@super.gd>2019-04-11 13:49:55 +1200
committerJared Norman <jared@super.gd>2019-04-11 13:53:14 +1200
commitcb740a35890e9aad7f5206f4c4759c497cbff115 (patch)
tree4a19b79ebc091b26ef1a2d99506e22d12ffde899 /lib
parent3ad0d4d02a6a5c284c695d82e3064be33168be6e (diff)
Avoid sending 0 quantity line items
Diffstat (limited to 'lib')
-rw-r--r--lib/super_good/solidus_taxjar/api_params.rb12
1 files changed, 10 insertions, 2 deletions
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