diff options
author | Jared Norman <jared@super.gd> | 2019-01-20 16:10:35 -0800 |
---|---|---|
committer | Jared Norman <jared@super.gd> | 2019-01-20 16:10:35 -0800 |
commit | 3a1aea93e236ec0a52fae0ef4ab949acccd2088f (patch) | |
tree | 9bcf1596ea1f0cb8d69358b7f64b129e46f3ca35 /lib | |
parent | 4ddde7d3b241cd57f935bb74750d1ed574dd90c4 (diff) |
Use correctly value for shipping tax
Oops, was grabbing the total shipping tax for the order and using that
as the tax, instead of grabbing the collectable tax from the breakdown.
That makes more sense.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/super_good/solidus_taxjar/tax_calculator.rb | 25 |
1 files changed, 12 insertions, 13 deletions
diff --git a/lib/super_good/solidus_taxjar/tax_calculator.rb b/lib/super_good/solidus_taxjar/tax_calculator.rb index 4efa367..445087a 100644 --- a/lib/super_good/solidus_taxjar/tax_calculator.rb +++ b/lib/super_good/solidus_taxjar/tax_calculator.rb @@ -12,6 +12,7 @@ module SuperGood def calculate return no_tax if order.tax_address.empty? + return no_tax unless taxjar_breakdown Spree::Tax::OrderTax.new( order_id: order.id, @@ -26,24 +27,22 @@ module SuperGood def line_item_taxes @line_item_taxes ||= - if taxjar_breakdown - taxjar_breakdown.line_items.map do |line_item| - Spree::Tax::ItemTax.new( - item_id: line_item.id.to_i, - label: "Sales Tax", - tax_rate: tax_rate, - amount: line_item.tax_collectable, - included_in_price: false - ) - end - else - [] + taxjar_breakdown.line_items.map do |line_item| + Spree::Tax::ItemTax.new( + item_id: line_item.id.to_i, + label: "Sales Tax", + tax_rate: tax_rate, + amount: line_item.tax_collectable, + included_in_price: false + ) end end def shipment_taxes @shipment_taxes ||= - if (total_shipping_tax = taxjar_tax.shipping) != 0 + if taxjar_breakdown.shipping? && + (total_shipping_tax = taxjar_breakdown.shipping.tax_collectable) != 0 + # Distribute shipping tax across shipments: # TaxJar does not provide a breakdown of shipping taxes, so we have # to proportionally distribute the tax across the shipments, |