Skip to content

Commit

Permalink
Merge pull request #12921 from rioug/12908-error-when-tax-refund
Browse files Browse the repository at this point in the history
Add Bugsnag notification if we reach tax rate refund code
  • Loading branch information
dacook authored Oct 30, 2024
2 parents 54acc97 + 3f22e8c commit 3756e36
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
9 changes: 9 additions & 0 deletions app/models/spree/tax_rate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions spec/models/spree/tax_rate_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 3756e36

Please sign in to comment.