SuperGoodSoft / solidus_taxjar

Support for using TaxJar to handle tax calculations in Solidus
BSD 3-Clause "New" or "Revised" License
12 stars 13 forks source link

Don't refund orders with unaccounted for order level adjustments #180

Open Noah-Silvera opened 2 years ago

Noah-Silvera commented 2 years ago

Taken from #178

If you try to make an order level adjustment and then a new payment to process a refund for an order, the system will try to do two things

  1. Create a 'refund transaction' with the amounts of the entire order
  2. Create brand new transaction with the new order amount

However, order level adjustments are not taken into account when reporting the total order amount to Taxjar. This causes Taxjar to throw an error when trying to report the new amount.

As discussed in #178, this scenario is handled by allowing users to configure a custom discount_calculator which will let them determine how to handle splitting the discount among items for order level adjustments if desired.

However, as discovered in the testing of #139, order level adjustments will cause the creation of the "refund+new transaction" to fail silently and put your TaxJar reporting into a bad state (the order has been fully refunded, but a new transaction has not been created with the reduced amount)

To prevent this from happening, we should do the following.

  1. If an order has order level adjustments, a custom discount calculator has not been configured, and the order is about to be posted to taxjar a.) We should short circuit reporting and not post the full refund OR new reduced amount transaction (currently the full refund transaction is succeeding but the new reduced amount transaction is failing) b.) We should display an error message to the user notifying them that the order was not reported to TaxJar c.) We should add documentation describing how and why to use the discount_calculator option d.) We should display a link to the documentation so they can learn how to handle order level adjustments if desired.
Noah-Silvera commented 2 years ago

One question that still remains in this ticket is how do we determine that someone isn't already handling order level adjustments? Maybe comparing the new line item totals to the order amount and seeing if they don't match? Because that is the underlying problem which causes the TaxJar API to return an error.