summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJared Norman <jared@super.gd>2019-04-11 15:13:39 +1200
committerGitHub <noreply@github.com>2019-04-11 15:13:39 +1200
commitb4bd6e1bf62afea276d77a5d4163efb836937ee4 (patch)
tree66498f2adbf66565def092c9dc9c041e38442500
parentfbd8c7c044803843deae20045dd7972f1e6c34ac (diff)
parent0c7fb7e0e6d4c8a16c0454fedb60f1ae5d9690d3 (diff)
Merge pull request #11 from SuperGoodSoft/additional-order-level-adjustment-handling
Avoid sending negative order totals
-rw-r--r--CHANGELOG.md2
-rw-r--r--lib/super_good/solidus_taxjar/api_params.rb2
-rw-r--r--spec/super_good/solidus_taxjar/api_params_spec.rb11
3 files changed, 13 insertions, 2 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 525591d..86af1d2 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -2,6 +2,8 @@
## master
+- Avoid sending negative amounts for order totals.
+
## v0.11.0
- Avoid sending 0 quantity line items. TaxJar doesn't like them.
diff --git a/lib/super_good/solidus_taxjar/api_params.rb b/lib/super_good/solidus_taxjar/api_params.rb
index 25f8317..3d898c3 100644
--- a/lib/super_good/solidus_taxjar/api_params.rb
+++ b/lib/super_good/solidus_taxjar/api_params.rb
@@ -28,7 +28,7 @@ module SuperGood
.merge(
transaction_id: order.number,
transaction_date: order.completed_at.to_formatted_s(:iso8601),
- amount: order.total - order.additional_tax_total,
+ amount: [order.total - order.additional_tax_total, 0].max,
shipping: shipping(order),
sales_tax: order.additional_tax_total
)
diff --git a/spec/super_good/solidus_taxjar/api_params_spec.rb b/spec/super_good/solidus_taxjar/api_params_spec.rb
index 9c8696f..2e9e289 100644
--- a/spec/super_good/solidus_taxjar/api_params_spec.rb
+++ b/spec/super_good/solidus_taxjar/api_params_spec.rb
@@ -4,7 +4,7 @@ RSpec.describe SuperGood::SolidusTaxJar::APIParams do
let(:order) do
Spree::Order.create!(
number: "R111222333",
- total: BigDecimal("123.45"),
+ total: order_total,
shipment_total: BigDecimal("3.01"),
additional_tax_total: BigDecimal("9.87"),
item_total: BigDecimal("28.00"),
@@ -15,6 +15,7 @@ RSpec.describe SuperGood::SolidusTaxJar::APIParams do
order.update! completed_at: DateTime.new(2018, 3, 6, 12, 10, 33)
end
end
+ let(:order_total) { BigDecimal("123.45") }
let(:store) do
Spree::Store.create!(
@@ -211,6 +212,14 @@ RSpec.describe SuperGood::SolidusTaxJar::APIParams do
})
end
+ context "when the order is adjusted to 0" do
+ let(:order_total) { BigDecimal("0") }
+
+ it "sends the order total as zero" do
+ expect(subject[:amount]).to be_zero
+ end
+ end
+
context "when the line item has 0 quantity" do
let(:line_item) do
Spree::LineItem.new(