summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGELOG.md5
-rw-r--r--lib/super_good/solidus_taxjar.rb2
-rw-r--r--lib/super_good/solidus_taxjar/tax_calculator.rb6
-rw-r--r--spec/super_good/solidus_taxjar/tax_calculator_spec.rb33
-rw-r--r--spec/super_good/solidus_taxjar_spec.rb6
5 files changed, 51 insertions, 1 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 8471e12..1690360 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,10 @@
# Changelog
+## v0.6.0
+
+- Added `SuperGood::SolidusTaxJar.shipping_tax_label_maker` for customizing the labels on the tax adjustments on shipments.
+- Added `SuperGood::SolidusTaxJar.line_item_tax_label_maker` for customizing the labels on the line iteme tax adjustments.
+
## v0.5.0
- Moved exception handler configuration to `SuperGood::SolidusTaxJar.exception_handler` from `SuperGood::SolidusTaxJar::TaxCalculator.exception_handler`. Now all the configuration options are in the same place.
diff --git a/lib/super_good/solidus_taxjar.rb b/lib/super_good/solidus_taxjar.rb
index 9a32d9f..ef9497d 100644
--- a/lib/super_good/solidus_taxjar.rb
+++ b/lib/super_good/solidus_taxjar.rb
@@ -16,6 +16,7 @@ module SuperGood
attr_accessor :exception_handler
attr_accessor :taxable_address_check
attr_accessor :shipping_tax_label_maker
+ attr_accessor :line_item_tax_label_maker
end
self.discount_calculator = ::SuperGood::SolidusTaxJar::DiscountCalculator
@@ -25,5 +26,6 @@ module SuperGood
}
self.taxable_address_check = ->(address) { true }
self.shipping_tax_label_maker = ->(shipment, shipping_tax) { "Sales Tax" }
+ self.line_item_tax_label_maker = ->(taxjar_line_item) { "Sales Tax" }
end
end
diff --git a/lib/super_good/solidus_taxjar/tax_calculator.rb b/lib/super_good/solidus_taxjar/tax_calculator.rb
index a2eb8ca..91ff6c0 100644
--- a/lib/super_good/solidus_taxjar/tax_calculator.rb
+++ b/lib/super_good/solidus_taxjar/tax_calculator.rb
@@ -38,7 +38,7 @@ module SuperGood
taxjar_breakdown.line_items.map do |line_item|
Spree::Tax::ItemTax.new(
item_id: line_item.id.to_i,
- label: "Sales Tax",
+ label: line_item_tax_label(line_item),
tax_rate: tax_rate,
amount: line_item.tax_collectable,
included_in_price: false
@@ -140,6 +140,10 @@ module SuperGood
shipping_tax
)
end
+
+ def line_item_tax_label(taxjar_line_item)
+ SuperGood::SolidusTaxJar.line_item_tax_label_maker.(taxjar_line_item)
+ end
end
end
end
diff --git a/spec/super_good/solidus_taxjar/tax_calculator_spec.rb b/spec/super_good/solidus_taxjar/tax_calculator_spec.rb
index f7a7929..1899443 100644
--- a/spec/super_good/solidus_taxjar/tax_calculator_spec.rb
+++ b/spec/super_good/solidus_taxjar/tax_calculator_spec.rb
@@ -164,6 +164,7 @@ RSpec.describe ::SuperGood::SolidusTaxJar::TaxCalculator do
expect(subject.line_item_taxes.length).to eq 1
item_tax = subject.line_item_taxes.first
+
aggregate_failures do
expect(item_tax.item_id).to eq 33
expect(item_tax.label).to eq "Sales Tax"
@@ -173,6 +174,20 @@ RSpec.describe ::SuperGood::SolidusTaxJar::TaxCalculator do
end
end
+ context "with custom line item tax labels" do
+ before do
+ allow(SuperGood::SolidusTaxJar.line_item_tax_label_maker)
+ .to receive(:call)
+ .with(taxjar_line_item)
+ .and_return("Space Tax")
+ end
+
+ it "applies those labels" do
+ expect(subject.line_item_taxes.length).to eq 1
+ expect(subject.line_item_taxes.first.label).to eq "Space Tax"
+ end
+ end
+
context "but the taxable address check returns false" do
before do
allow(SuperGood::SolidusTaxJar.taxable_address_check)
@@ -216,6 +231,24 @@ RSpec.describe ::SuperGood::SolidusTaxJar::TaxCalculator do
expect(shipment_taxes[2].included_in_price).to eq false
end
end
+
+ context "with custom shipping tax labels" do
+ before do
+ allow(SuperGood::SolidusTaxJar.shipping_tax_label_maker).to receive(:call)
+ .and_return("Magic Tax", "Spicy Tax", "Vegetable Tax")
+ end
+
+ it "applies those labels" do
+ shipment_taxes = subject.shipment_taxes
+ expect(shipment_taxes.length).to eq 3
+
+ aggregate_failures do
+ expect(shipment_taxes[0].label).to eq "Magic Tax"
+ expect(shipment_taxes[1].label).to eq "Spicy Tax"
+ expect(shipment_taxes[2].label).to eq "Vegetable Tax"
+ end
+ end
+ end
end
context "when test_mode is set" do
diff --git a/spec/super_good/solidus_taxjar_spec.rb b/spec/super_good/solidus_taxjar_spec.rb
index 36ab3b3..957e2e3 100644
--- a/spec/super_good/solidus_taxjar_spec.rb
+++ b/spec/super_good/solidus_taxjar_spec.rb
@@ -43,5 +43,11 @@ RSpec.describe SuperGood::SolidusTaxJar do
let(:shipping_tax) { BigDecimal("3.25") }
it { is_expected.to eq "Sales Tax" }
end
+
+ describe ".line_item_tax_label_maker" do
+ subject { described_class.line_item_tax_label_maker.(taxjar_line_item) }
+ let(:taxjar_line_item) { instance_double Taxjar::BreakdownLineItem }
+ it { is_expected.to eq "Sales Tax" }
+ end
end
end