diff --git a/app/models/spree/tax_rate.rb b/app/models/spree/tax_rate.rb index 868b5e3a9f7..588fe919852 100644 --- a/app/models/spree/tax_rate.rb +++ b/app/models/spree/tax_rate.rb @@ -105,6 +105,15 @@ def compute_amount(item) if default_zone_or_zone_match?(item.order) calculator.compute(item) else + # Tax refund should not be possible with the way our production server are configured + Bugsnag.notify( + "Notice: Tax refund should not be possible, please check the default zone and " \ + "the tax rate zone configuration" + ) do |payload| + payload.add_metadata :order_tax_zone, item.order.tax_zone + payload.add_metadata :tax_rate_zone, zone + payload.add_metadata :default_zone, Zone.default_tax + end # In this case, it's a refund. calculator.compute(item) * - 1 end diff --git a/spec/models/spree/tax_rate_spec.rb b/spec/models/spree/tax_rate_spec.rb index 9d58cd024bc..ae12b8109d5 100644 --- a/spec/models/spree/tax_rate_spec.rb +++ b/spec/models/spree/tax_rate_spec.rb @@ -386,6 +386,16 @@ module Spree Spree::TaxRate.adjust(order, order.line_items) expect(line_item.adjustments.credit.count).to eq 2 end + + it "notifies bugsnag" do + # there are two tax rate + expect(Bugsnag).to receive(:notify).with( + "Notice: Tax refund should not be possible, please check the default zone and " \ + "the tax rate zone configuration" + ).twice.and_call_original + + Spree::TaxRate.adjust(order, order.line_items) + end end end