diff options
author | Noah Silvera <noah@super.gd> | 2021-06-23 15:11:25 -0700 |
---|---|---|
committer | Nicholas Van Doorn <vandoorn.nick@gmail.com> | 2021-07-26 15:54:47 -0700 |
commit | 21c872896ef5eede969312c88e7dd63ecf17dcae (patch) | |
tree | ae5307ca4828b856012a000abc22f7cfd2219e9e | |
parent | 40d2f7ae406eb32be8b6ed07772c2e704d6ba3ec (diff) |
Create refund transaction with negative amounts
Refunds in taxjar are transactions that have a negative delta against
the original order. Our API was incorrectly using TaxJar's refund
API by calling it with positive numbers, which would represent the
customer getting paid more, not getting refunded.
-rw-r--r-- | lib/super_good/solidus_taxjar/api_params.rb | 4 | ||||
-rw-r--r-- | spec/super_good/solidus_taxjar/api_params_spec.rb | 9 |
2 files changed, 6 insertions, 7 deletions
diff --git a/lib/super_good/solidus_taxjar/api_params.rb b/lib/super_good/solidus_taxjar/api_params.rb index 2e0e92c..d9d30e5 100644 --- a/lib/super_good/solidus_taxjar/api_params.rb +++ b/lib/super_good/solidus_taxjar/api_params.rb @@ -60,9 +60,9 @@ module SuperGood transaction_id: reimbursement.number, transaction_reference_id: reimbursement.order.number, transaction_date: reimbursement.order.completed_at.to_formatted_s(:iso8601), - amount: reimbursement.total - additional_taxes, + amount: -1 * (reimbursement.total - additional_taxes), shipping: 0, - sales_tax: additional_taxes + sales_tax: -1 * additional_taxes ) end diff --git a/spec/super_good/solidus_taxjar/api_params_spec.rb b/spec/super_good/solidus_taxjar/api_params_spec.rb index 5ba565b..af8981d 100644 --- a/spec/super_good/solidus_taxjar/api_params_spec.rb +++ b/spec/super_good/solidus_taxjar/api_params_spec.rb @@ -328,17 +328,16 @@ RSpec.describe SuperGood::SolidusTaxjar::ApiParams do number: "RI123123123", order: order, return_items: [ - Spree::ReturnItem.new(additional_tax_total: 0.33), - Spree::ReturnItem.new(additional_tax_total: 33.0) + Spree::ReturnItem.new(additional_tax_total: 12, amount: 36), ], - total: 333.33 + total: 36 ) end it "returns params for creating/updating a refund" do expect(subject).to eq({ - amount: BigDecimal("300.00"), - sales_tax: BigDecimal("33.33"), + amount: BigDecimal("-24"), + sales_tax: BigDecimal("-12"), shipping: 0, to_city: "Los Angeles", to_country: "US", |