summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJared Norman <jared@super.gd>2019-04-11 13:57:53 +1200
committerGitHub <noreply@github.com>2019-04-11 13:57:53 +1200
commitcb5f842ac7490330c0818e4ccb1b178844bdf7a6 (patch)
tree4a19b79ebc091b26ef1a2d99506e22d12ffde899
parent0cb25e229937e705341c26961181fa26d6faa562 (diff)
parentcb740a35890e9aad7f5206f4c4759c497cbff115 (diff)
Merge pull request #10 from SuperGoodSoft/feature/empty-line-items
Don't send line items with 0 quantity
-rw-r--r--CHANGELOG.md2
-rw-r--r--lib/super_good/solidus_taxjar/api_params.rb12
-rw-r--r--spec/super_good/solidus_taxjar/api_params_spec.rb56
3 files changed, 67 insertions, 3 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 50c2d0c..7d842a3 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -2,6 +2,8 @@
## master
+- Avoid sending 0 quantity line items. TaxJar doesn't like them.
+
## v0.10.0
- Make shipping amounts configurable to make it easier to support order-level adjustments.
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
diff --git a/spec/super_good/solidus_taxjar/api_params_spec.rb b/spec/super_good/solidus_taxjar/api_params_spec.rb
index abc8a23..9c8696f 100644
--- a/spec/super_good/solidus_taxjar/api_params_spec.rb
+++ b/spec/super_good/solidus_taxjar/api_params_spec.rb
@@ -140,6 +140,32 @@ RSpec.describe SuperGood::SolidusTaxJar::APIParams do
}]
)
end
+
+ context "when the line item has zero quantity" do
+ let(:line_item) do
+ Spree::LineItem.new(
+ variant: variant,
+ price: 10,
+ quantity: 0,
+ promo_total: -2,
+ additional_tax_total: 4
+ )
+ end
+
+ it "excludes the line item" do
+ expect(subject).to eq(
+ to_country: "US",
+ to_zip: "90210",
+ to_city: "Los Angeles",
+ to_state: "CA",
+ to_street: "475 N Beverly Dr",
+
+ shipping: 3.01,
+
+ line_items: []
+ )
+ end
+ end
end
describe "#address_params" do
@@ -184,12 +210,40 @@ RSpec.describe SuperGood::SolidusTaxJar::APIParams do
}]
})
end
+
+ context "when the line item has 0 quantity" do
+ let(:line_item) do
+ Spree::LineItem.new(
+ variant: variant,
+ price: 10,
+ quantity: 0,
+ promo_total: -2,
+ additional_tax_total: 4
+ )
+ end
+
+ it "excludes the line item" do
+ expect(subject).to eq({
+ amount: BigDecimal("113.58"),
+ sales_tax: BigDecimal("9.87"),
+ shipping: BigDecimal("3.01"),
+ to_city: "Los Angeles",
+ to_country: "US",
+ to_state: "CA",
+ to_street: "475 N Beverly Dr",
+ to_zip: "90210",
+ transaction_date: "2018-03-06T12:10:33Z",
+ transaction_id: "R111222333",
+ line_items: []
+ })
+ end
+ end
end
describe "#refund_params" do
subject { described_class.refund_params(reimbursement) }
- it "returns params for creating/updatingin a refund" do
+ it "returns params for creating/updating a refund" do
expect(subject).to eq({
amount: BigDecimal("300.00"),
sales_tax: BigDecimal("33.33"),