summaryrefslogtreecommitdiff
path: root/lib/super_good/solidus_taxjar
diff options
context:
space:
mode:
authorJared Norman <jared@super.gd>2019-01-30 17:15:37 -0800
committerJared Norman <jared@super.gd>2019-01-30 17:15:37 -0800
commit1fdfaff9bef12831cace3f0661c2bb3209500220 (patch)
treef22b78268d69d2b0cee538a6d05dfdcd3025dc4e /lib/super_good/solidus_taxjar
parent054a25e9da909242fef25770c31678c251621573 (diff)
Add ability to create order transactions
Diffstat (limited to 'lib/super_good/solidus_taxjar')
-rw-r--r--lib/super_good/solidus_taxjar/api.rb4
-rw-r--r--lib/super_good/solidus_taxjar/api_params.rb12
2 files changed, 16 insertions, 0 deletions
diff --git a/lib/super_good/solidus_taxjar/api.rb b/lib/super_good/solidus_taxjar/api.rb
index d52a4a4..301fba4 100644
--- a/lib/super_good/solidus_taxjar/api.rb
+++ b/lib/super_good/solidus_taxjar/api.rb
@@ -20,6 +20,10 @@ module SuperGood
taxjar_client.rates_for_location(*APIParams.address_params(address))
end
+ def create_transaction_for(order)
+ taxjar_client.create_order APIParams.transaction_params(order)
+ 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 4e61253..f75713c 100644
--- a/lib/super_good/solidus_taxjar/api_params.rb
+++ b/lib/super_good/solidus_taxjar/api_params.rb
@@ -21,6 +21,18 @@ module SuperGood
]
end
+ def transaction_params(order)
+ {}
+ .merge(order_address_params(order.tax_address))
+ .merge(
+ transaction_id: order.number,
+ transaction_date: order.completed_at.to_formatted_s(:iso8601),
+ amount: order.total - order.additional_tax_total,
+ shipping: order.shipment_total,
+ sales_tax: order.additional_tax_total
+ )
+ end
+
private
def order_address_params(address)