From 8581484be15ed19bbd37d861b082ba1e9b34b978 Mon Sep 17 00:00:00 2001 From: Jared Norman Date: Thu, 31 Jan 2019 09:24:44 -0800 Subject: Add ability to create refunds --- lib/super_good/solidus_taxjar/api.rb | 4 ++++ lib/super_good/solidus_taxjar/api_params.rb | 15 +++++++++++++++ 2 files changed, 19 insertions(+) (limited to 'lib/super_good/solidus_taxjar') diff --git a/lib/super_good/solidus_taxjar/api.rb b/lib/super_good/solidus_taxjar/api.rb index 61fecae..7309a64 100644 --- a/lib/super_good/solidus_taxjar/api.rb +++ b/lib/super_good/solidus_taxjar/api.rb @@ -32,6 +32,10 @@ module SuperGood taxjar_client.delete_order order.number end + def create_refund_for(reimbursement) + taxjar_client.create_refund APIParams.refund_params(reimbursement) + end + private attr_reader :taxjar_client diff --git a/lib/super_good/solidus_taxjar/api_params.rb b/lib/super_good/solidus_taxjar/api_params.rb index f75713c..b848eee 100644 --- a/lib/super_good/solidus_taxjar/api_params.rb +++ b/lib/super_good/solidus_taxjar/api_params.rb @@ -33,6 +33,21 @@ module SuperGood ) end + def refund_params(reimbursement) + additional_taxes = reimbursement.return_items.sum(&:additional_tax_total) + + {} + .merge(order_address_params(reimbursement.order.tax_address)) + .merge( + 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, + shipping: 0, + sales_tax: additional_taxes + ) + end + private def order_address_params(address) -- cgit v1.2.3