summaryrefslogtreecommitdiff
path: root/lib/super_good/solidus_taxjar/api_params.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/super_good/solidus_taxjar/api_params.rb')
-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