super_good-solidus_taxjar 0.2.0 → 0.3.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: 84ac328950ff3ed0fc1356c29580c91645e7df28
4
- data.tar.gz: 8147769f9ec1d1200a3ccedda9f5f8eeaa5b49d9
3
+ metadata.gz: 802c6668a1ea106f680f6c0fcffa87ae3ab118c4
4
+ data.tar.gz: 46c432958f8131ea6625187a645ce8e3bcf3fb5c
5
5
  SHA512:
6
- metadata.gz: cbb8c135412d4ecc4ff7ecfa5381db365374e0230de52e6661220ac8e61e6dd949bc66538110939eb1c8d8d01c902b1895f965f285e97bfb46fe5d5c7f0746ce
7
- data.tar.gz: fccfe6065ee953781850628dc88f6548765b599928cfe10abda480515683649b5c8b450b3fbdebcf9c4911e3c62fc24acb0c985109bdad3ded2aeee3c3980f47
6
+ metadata.gz: b06a684114911d7c4b166cd62790e7bc4bb0af0778252453367e90210aa9c7c84b4306c358a7fa530af88601de9ccb3a335f4502b26e16060fb26960cfe0314f
7
+ data.tar.gz: 4a88564733603bc1d7d8d7e8be69f77c80bbb27e57f33ea8dca476862d3c4203020d6c24c30acae443756cbf5dc0ec6d8f95bb4d01a6d4daeae27598c16b8143
@@ -26,10 +26,6 @@ module SuperGood
26
26
  )
27
27
  end
28
28
 
29
- private
30
-
31
- attr_reader :taxjar_client
32
-
33
29
  def order_params(order)
34
30
  tax_address = order.tax_address
35
31
 
@@ -47,12 +43,20 @@ module SuperGood
47
43
  id: line_item.id,
48
44
  quantity: line_item.quantity,
49
45
  unit_price: line_item.price,
50
- discount: -line_item.promo_total,
46
+ discount: discount(line_item),
51
47
  product_tax_code: line_item.tax_category&.tax_code
52
48
  }
53
49
  end
54
50
  }
55
51
  end
52
+
53
+ private
54
+
55
+ attr_reader :taxjar_client
56
+
57
+ def discount(line_item)
58
+ ::SuperGood::SolidusTaxJar.discount_calculator.new(line_item).discount
59
+ end
56
60
  end
57
61
  end
58
62
  end
@@ -0,0 +1,17 @@
1
+ module SuperGood
2
+ module SolidusTaxJar
3
+ class DiscountCalculator
4
+ def initialize(line_item)
5
+ @line_item = line_item
6
+ end
7
+
8
+ def discount
9
+ -line_item.promo_total
10
+ end
11
+
12
+ private
13
+
14
+ attr_reader :line_item
15
+ end
16
+ end
17
+ end
@@ -16,6 +16,7 @@ module SuperGood
16
16
  end
17
17
 
18
18
  def calculate
19
+ return no_tax if SuperGood::SolidusTaxJar.test_mode
19
20
  return no_tax if order.tax_address.empty? || order.line_items.none?
20
21
 
21
22
  cache do
@@ -120,27 +121,13 @@ module SuperGood
120
121
  end
121
122
 
122
123
  def cache_key
123
- tax_address = order.tax_address
124
-
125
- {
126
- to_country: tax_address.country.iso,
127
- to_zip: tax_address.zipcode,
128
- to_city: tax_address.city,
129
- to_state: tax_address&.state&.abbr || tax_address.state_name,
130
- to_street: tax_address.address1,
131
-
132
- shipping: order.shipment_total,
133
-
134
- line_items: order.line_items.map do |line_item|
135
- {
136
- id: line_item.id,
137
- quantity: line_item.quantity,
138
- unit_price: line_item.price,
139
- discount: -line_item.adjustment_total,
140
- product_tax_code: line_item.tax_category&.tax_code
141
- }
142
- end.hash
143
- }
124
+ api.order_params(order).transform_values do |value|
125
+ case value
126
+ when Array, Hash then value.hash
127
+ else
128
+ value
129
+ end
130
+ end
144
131
  end
145
132
  end
146
133
  end
@@ -1,5 +1,5 @@
1
1
  module SuperGood
2
2
  module SolidusTaxJar
3
- VERSION = "0.2.0"
3
+ VERSION = "0.3.0"
4
4
  end
5
5
  end
@@ -2,11 +2,19 @@ require 'solidus_core'
2
2
  require 'solidus_support'
3
3
  require 'taxjar'
4
4
 
5
+ require "super_good/solidus_taxjar/version"
6
+ require "super_good/solidus_taxjar/api"
7
+ require "super_good/solidus_taxjar/tax_calculator"
8
+ require "super_good/solidus_taxjar/discount_calculator"
9
+
5
10
  module SuperGood
6
11
  module SolidusTaxJar
12
+ class << self
13
+ attr_accessor :discount_calculator
14
+ attr_accessor :test_mode
15
+ end
16
+
17
+ self.discount_calculator = ::SuperGood::SolidusTaxJar::DiscountCalculator
18
+ self.test_mode = false
7
19
  end
8
20
  end
9
-
10
- require "super_good/solidus_taxjar/version"
11
- require "super_good/solidus_taxjar/api"
12
- require "super_good/solidus_taxjar/tax_calculator"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: super_good-solidus_taxjar
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jared Norman
@@ -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/discount_calculator.rb
172
173
  - lib/super_good/solidus_taxjar/tax_calculator.rb
173
174
  - lib/super_good/solidus_taxjar/version.rb
174
175
  - super_good-solidus_taxjar.gemspec