super_good-solidus_taxjar 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 802c6668a1ea106f680f6c0fcffa87ae3ab118c4
4
- data.tar.gz: 46c432958f8131ea6625187a645ce8e3bcf3fb5c
3
+ metadata.gz: 15e315fd76cef9f6fddba1b3202cda57b2e04d39
4
+ data.tar.gz: 64708cb635e934536fdb2dcb37cb0f60a23c8df1
5
5
  SHA512:
6
- metadata.gz: b06a684114911d7c4b166cd62790e7bc4bb0af0778252453367e90210aa9c7c84b4306c358a7fa530af88601de9ccb3a335f4502b26e16060fb26960cfe0314f
7
- data.tar.gz: 4a88564733603bc1d7d8d7e8be69f77c80bbb27e57f33ea8dca476862d3c4203020d6c24c30acae443756cbf5dc0ec6d8f95bb4d01a6d4daeae27598c16b8143
6
+ metadata.gz: 1ad10edb29f0a302a1f3e2f9d4100814bbb0573895b1ff4ca10217283f24f2c6fa835711bd691d3719861f24a3c21376870364bbf99334d661ba8af62ef15f93
7
+ data.tar.gz: 6c925bf6f337c91c294a5846a7afb7b43a17cc0c25a661e51cbdee66275de1e08cb0f9bcec772699b19676e4325d2a282ad6927716a438388cfb834cc6cc3dbf
@@ -3,6 +3,7 @@ require 'solidus_support'
3
3
  require 'taxjar'
4
4
 
5
5
  require "super_good/solidus_taxjar/version"
6
+ require "super_good/solidus_taxjar/api_params"
6
7
  require "super_good/solidus_taxjar/api"
7
8
  require "super_good/solidus_taxjar/tax_calculator"
8
9
  require "super_good/solidus_taxjar/discount_calculator"
@@ -13,50 +13,32 @@ module SuperGood
13
13
  end
14
14
 
15
15
  def tax_for(order)
16
- taxjar_client.tax_for_order order_params(order)
16
+ taxjar_client.tax_for_order APIParams.order_params(order)
17
17
  end
18
18
 
19
19
  def tax_rates_for(address)
20
- taxjar_client.rates_for_location(
21
- address.zipcode,
22
- street: address.address1,
23
- city: address.city,
24
- state: address&.state&.abbr || address.state_name,
25
- country: address.country.iso
26
- )
20
+ taxjar_client.rates_for_location(*APIParams.address_params(address))
27
21
  end
28
22
 
29
- def order_params(order)
30
- tax_address = order.tax_address
23
+ def create_transaction_for(order)
24
+ taxjar_client.create_order APIParams.transaction_params(order)
25
+ end
31
26
 
32
- {
33
- to_country: tax_address.country.iso,
34
- to_zip: tax_address.zipcode,
35
- to_city: tax_address.city,
36
- to_state: tax_address&.state&.abbr || tax_address.state_name,
37
- to_street: tax_address.address1,
27
+ def update_transaction_for(order)
28
+ taxjar_client.update_order APIParams.transaction_params(order)
29
+ end
38
30
 
39
- shipping: order.shipment_total,
31
+ def delete_transaction_for(order)
32
+ taxjar_client.delete_order order.number
33
+ end
40
34
 
41
- line_items: order.line_items.map do |line_item|
42
- {
43
- id: line_item.id,
44
- quantity: line_item.quantity,
45
- unit_price: line_item.price,
46
- discount: discount(line_item),
47
- product_tax_code: line_item.tax_category&.tax_code
48
- }
49
- end
50
- }
35
+ def create_refund_for(reimbursement)
36
+ taxjar_client.create_refund APIParams.refund_params(reimbursement)
51
37
  end
52
38
 
53
39
  private
54
40
 
55
41
  attr_reader :taxjar_client
56
-
57
- def discount(line_item)
58
- ::SuperGood::SolidusTaxJar.discount_calculator.new(line_item).discount
59
- end
60
42
  end
61
43
  end
62
44
  end
@@ -0,0 +1,83 @@
1
+ module SuperGood
2
+ module SolidusTaxJar
3
+ module APIParams
4
+ class << self
5
+ def order_params(order)
6
+ {}
7
+ .merge(order_address_params(order.tax_address))
8
+ .merge(line_items_params(order.line_items))
9
+ .merge(shipping: order.shipment_total)
10
+ end
11
+
12
+ def address_params(address)
13
+ [
14
+ address.zipcode,
15
+ {
16
+ street: address.address1,
17
+ city: address.city,
18
+ state: address&.state&.abbr || address.state_name,
19
+ country: address.country.iso
20
+ }
21
+ ]
22
+ end
23
+
24
+ def transaction_params(order)
25
+ {}
26
+ .merge(order_address_params(order.tax_address))
27
+ .merge(
28
+ transaction_id: order.number,
29
+ transaction_date: order.completed_at.to_formatted_s(:iso8601),
30
+ amount: order.total - order.additional_tax_total,
31
+ shipping: order.shipment_total,
32
+ sales_tax: order.additional_tax_total
33
+ )
34
+ end
35
+
36
+ def refund_params(reimbursement)
37
+ additional_taxes = reimbursement.return_items.sum(&:additional_tax_total)
38
+
39
+ {}
40
+ .merge(order_address_params(reimbursement.order.tax_address))
41
+ .merge(
42
+ transaction_id: reimbursement.number,
43
+ transaction_reference_id: reimbursement.order.number,
44
+ transaction_date: reimbursement.order.completed_at.to_formatted_s(:iso8601),
45
+ amount: reimbursement.total - additional_taxes,
46
+ shipping: 0,
47
+ sales_tax: additional_taxes
48
+ )
49
+ end
50
+
51
+ private
52
+
53
+ def order_address_params(address)
54
+ {
55
+ to_country: address.country.iso,
56
+ to_zip: address.zipcode,
57
+ to_city: address.city,
58
+ to_state: address&.state&.abbr || address.state_name,
59
+ to_street: address.address1,
60
+ }
61
+ end
62
+
63
+ def line_items_params(line_items)
64
+ {
65
+ line_items: line_items.map do |line_item|
66
+ {
67
+ id: line_item.id,
68
+ quantity: line_item.quantity,
69
+ unit_price: line_item.price,
70
+ discount: discount(line_item),
71
+ product_tax_code: line_item.tax_category&.tax_code
72
+ }
73
+ end
74
+ }
75
+ end
76
+
77
+ def discount(line_item)
78
+ ::SuperGood::SolidusTaxJar.discount_calculator.new(line_item).discount
79
+ end
80
+ end
81
+ end
82
+ end
83
+ end
@@ -121,7 +121,7 @@ module SuperGood
121
121
  end
122
122
 
123
123
  def cache_key
124
- api.order_params(order).transform_values do |value|
124
+ APIParams.order_params(order).transform_values do |value|
125
125
  case value
126
126
  when Array, Hash then value.hash
127
127
  else
@@ -1,5 +1,5 @@
1
1
  module SuperGood
2
2
  module SolidusTaxJar
3
- VERSION = "0.3.0"
3
+ VERSION = "0.4.0"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: super_good-solidus_taxjar
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jared Norman
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-01-28 00:00:00.000000000 Z
11
+ date: 2019-02-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: solidus_core
@@ -169,6 +169,7 @@ files:
169
169
  - bin/setup
170
170
  - lib/super_good/solidus_taxjar.rb
171
171
  - lib/super_good/solidus_taxjar/api.rb
172
+ - lib/super_good/solidus_taxjar/api_params.rb
172
173
  - lib/super_good/solidus_taxjar/discount_calculator.rb
173
174
  - lib/super_good/solidus_taxjar/tax_calculator.rb
174
175
  - lib/super_good/solidus_taxjar/version.rb