diff options
author | Jared Norman <jared@super.gd> | 2019-04-11 13:57:53 +1200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-04-11 13:57:53 +1200 |
commit | cb5f842ac7490330c0818e4ccb1b178844bdf7a6 (patch) | |
tree | 4a19b79ebc091b26ef1a2d99506e22d12ffde899 /lib/super_good/solidus_taxjar | |
parent | 0cb25e229937e705341c26961181fa26d6faa562 (diff) | |
parent | cb740a35890e9aad7f5206f4c4759c497cbff115 (diff) |
Merge pull request #10 from SuperGoodSoft/feature/empty-line-items
Don't send line items with 0 quantity
Diffstat (limited to 'lib/super_good/solidus_taxjar')
-rw-r--r-- | lib/super_good/solidus_taxjar/api_params.rb | 12 |
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 |