suretax 0.2.3 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. checksums.yaml +4 -4
  2. data/.env.example +4 -0
  3. data/.rubocop.yml +111 -0
  4. data/Gemfile +1 -1
  5. data/Gemfile.lock +9 -9
  6. data/lib/suretax.rb +0 -1
  7. data/lib/suretax/api.rb +7 -7
  8. data/lib/suretax/api/cancel_request.rb +7 -7
  9. data/lib/suretax/api/group.rb +5 -6
  10. data/lib/suretax/api/item_message.rb +3 -3
  11. data/lib/suretax/api/request.rb +37 -37
  12. data/lib/suretax/api/request_item.rb +13 -17
  13. data/lib/suretax/api/response.rb +18 -19
  14. data/lib/suretax/api/tax.rb +11 -12
  15. data/lib/suretax/api/tax_amount.rb +3 -4
  16. data/lib/suretax/concerns.rb +1 -3
  17. data/lib/suretax/concerns/validatable.rb +21 -27
  18. data/lib/suretax/configuration.rb +17 -20
  19. data/lib/suretax/connection.rb +3 -5
  20. data/lib/suretax/constants/regulatory_codes.rb +8 -8
  21. data/lib/suretax/constants/response_groups.rb +6 -6
  22. data/lib/suretax/constants/sales_type_codes.rb +5 -5
  23. data/lib/suretax/constants/tax_situs_codes.rb +10 -10
  24. data/lib/suretax/constants/transaction_type_codes.rb +2 -2
  25. data/lib/suretax/response.rb +7 -10
  26. data/lib/suretax/version.rb +1 -1
  27. data/spec/lib/suretax/api/group_spec.rb +21 -22
  28. data/spec/lib/suretax/api/request_item_spec.rb +10 -12
  29. data/spec/lib/suretax/api/request_item_validations_spec.rb +73 -76
  30. data/spec/lib/suretax/api/request_spec.rb +62 -66
  31. data/spec/lib/suretax/api/request_validations_spec.rb +141 -143
  32. data/spec/lib/suretax/api/response_spec.rb +48 -52
  33. data/spec/lib/suretax/api/tax_amount_spec.rb +12 -12
  34. data/spec/lib/suretax/api/tax_spec.rb +26 -28
  35. data/spec/lib/suretax/configuration_spec.rb +21 -24
  36. data/spec/lib/suretax/connection_spec.rb +11 -15
  37. data/spec/lib/suretax/response_spec.rb +27 -31
  38. data/spec/spec_helper.rb +16 -17
  39. data/spec/support/cancellation_helper.rb +0 -1
  40. data/spec/support/connection_shared_examples.rb +8 -10
  41. data/spec/support/request_helper.rb +13 -14
  42. data/spec/support/suretax_helper.rb +2 -4
  43. data/spec/support/validations_shared_examples.rb +12 -12
  44. data/suretax.gemspec +10 -8
  45. metadata +7 -7
  46. data/.travis.yml +0 -13
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c8eea17484cffad2ec21fedb1aaea5e82c30f11d
4
- data.tar.gz: 4b09457c6438ca37dbdbaf17ae748571e329af61
3
+ metadata.gz: 5eaeb9eb9a7c58e6f33b2d62dc8b5263dd04031d
4
+ data.tar.gz: b3999b6f2efa44afafca10ee867ec26ceb9fb3d6
5
5
  SHA512:
6
- metadata.gz: bd55c15f9346a5b0641b42de1b65fd13f2c54d0c6e1744426d15d55061ea77cd81487ccffd1e071c65cf3b40d8ebe54e46825f8b2d911d494ac5e4edb8eca193
7
- data.tar.gz: 775f5acfc58fe56cfedb10779d05c84d20dbc3a48a3404b912660ff2232812c8af843d051258f731b0c1d4f2558b3958f0d9343b1fdcf76e5f0699c34e9985bc
6
+ metadata.gz: 4f1239082346ee9d24c8c636f83af1af1393aaa0172a99ecc4dbc35618e36e5d606110f03109df212da538bfe01629df6971fdf94ce008183a2b55cbe72bf1ce
7
+ data.tar.gz: 3256264cb0c9f55c5d4cc43e2248e29adbedef90efd3514ceab70d00fc3dc48e5028ed9e2a6f84fdd6b3e0196eb85f26aa187cbdc94909b7aed8d6c0c4766e05
@@ -0,0 +1,4 @@
1
+ SURETAX_VALIDATION_KEY=885aa2c6-1a61-4ec6-9aa6-296120572b5e
2
+ SURETAX_CLIENT_NUMBER=000000123
3
+ SURETAX_BASE_URL=https://testapi.taxrating.net
4
+ SURETAX_REQUEST_VERSION=02
@@ -0,0 +1,111 @@
1
+ # This is the default configuration file. Enabling and disabling is configured
2
+ # in separate files. This file adds all other parameters apart from Enabled.
3
+
4
+ AllCops:
5
+ Include:
6
+ - "**/*.gemspec"
7
+ - "**/Rakefile"
8
+ Exclude:
9
+ - vendor/**/*
10
+ - db/**/*
11
+ TargetRubyVersion: 2.3
12
+
13
+ Rails:
14
+ Enabled: true
15
+
16
+ Style/CaseIndentation:
17
+ Enabled: false
18
+
19
+ Style/Lambda:
20
+ Enabled: false
21
+
22
+ Style/ConditionalAssignment:
23
+ Enabled: false
24
+
25
+ Performance/Casecmp:
26
+ Enabled: false
27
+
28
+ Style/GuardClause:
29
+ Enabled: false
30
+
31
+ Style/FrozenStringLiteralComment:
32
+ Enabled: false
33
+
34
+ LineLength:
35
+ Description: "Limit lines to 100 characters."
36
+ Max: 100
37
+ Enabled: true
38
+
39
+ AlignHash:
40
+ Description: Align the elements of a hash literal if they span more than one line.
41
+ EnforcedLastArgumentHashStyle: ignore_implicit
42
+ EnforcedHashRocketStyle: table
43
+ EnforcedColonStyle: table
44
+ Enabled: false
45
+
46
+ AlignParameters:
47
+ EnforcedStyle: with_first_parameter
48
+ SupportedStyles:
49
+ - with_first_parameter
50
+ - with_fixed_indentation
51
+ Enabled: false
52
+
53
+ Documentation:
54
+ Description: "Document classes and non-namespace modules."
55
+ Enabled: false
56
+
57
+ AndOr:
58
+ Description: "Use &&/|| instead of and/or."
59
+ Enabled: false
60
+
61
+ EndAlignment:
62
+ Description: "Align ends correctly."
63
+ Enabled: true
64
+
65
+ CollectionMethods:
66
+ Description: "Preferred collection methods."
67
+ Enabled: true
68
+ PreferredMethods:
69
+ collect: "map"
70
+ collect!: "map!"
71
+ reduce: "inject"
72
+ detect: "find"
73
+ find_all: "select"
74
+
75
+ AssignmentInCondition:
76
+ Description: "Don't use assignment in conditions."
77
+ Enabled: false
78
+
79
+ DoubleNegation:
80
+ Description: "Checks for uses of double negation (!!)."
81
+ Enabled: false
82
+
83
+ Style/BlockDelimiters:
84
+ Description: >-
85
+ Avoid using {...} for multi-line blocks (multiline chaining is
86
+ always ugly).
87
+ Prefer {...} over do...end for single-line blocks.
88
+ StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#single-line-blocks'
89
+ Enabled: false
90
+
91
+ SpaceBeforeFirstArg:
92
+ Description: "Checks that exactly one space is used between a method name and the first argument for method calls without parentheses."
93
+ Enabled: false
94
+
95
+ DotPosition:
96
+ Description: "Checks the position of the dot in multi-line method calls."
97
+ Enabled: false
98
+
99
+ ClassAndModuleChildren:
100
+ Description: "Checks style of children classes and modules."
101
+ Enabled: false
102
+
103
+ RescueModifier:
104
+ Description: "Avoid using rescue in modifier form"
105
+ Enabled: false
106
+
107
+ StringLiterals:
108
+ EnforcedStyle: double_quotes
109
+
110
+ StringLiteralsInInterpolation:
111
+ Enabled: false
data/Gemfile CHANGED
@@ -1,4 +1,4 @@
1
- source 'https://rubygems.org'
1
+ source "https://rubygems.org"
2
2
 
3
3
  # Specify your gem's dependencies in suretax.gemspec
4
4
  gemspec
@@ -1,10 +1,10 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- suretax (0.2.1)
4
+ suretax (0.2.3)
5
5
  excon
6
6
  monetize
7
- money (~> 6.5.1)
7
+ money (~> 6.9.0)
8
8
 
9
9
  GEM
10
10
  remote: https://rubygems.org/
@@ -17,13 +17,13 @@ GEM
17
17
  diff-lcs (1.2.5)
18
18
  docile (1.1.5)
19
19
  dotenv (1.0.2)
20
- excon (0.54.0)
21
- i18n (0.7.0)
20
+ excon (0.56.0)
21
+ i18n (0.8.4)
22
22
  method_source (0.8.2)
23
- monetize (1.3.0)
24
- money (~> 6.5.0)
25
- money (6.5.1)
26
- i18n (>= 0.6.4, <= 0.7.0)
23
+ monetize (1.7.0)
24
+ money (~> 6.9)
25
+ money (6.9.0)
26
+ i18n (>= 0.6.4, < 0.9)
27
27
  multi_json (1.10.1)
28
28
  pry (0.10.1)
29
29
  coderay (~> 1.1.0)
@@ -72,4 +72,4 @@ DEPENDENCIES
72
72
  webmock
73
73
 
74
74
  BUNDLED WITH
75
- 1.13.6
75
+ 1.15.1
@@ -11,7 +11,6 @@ require "suretax/api"
11
11
  require "money"
12
12
 
13
13
  module Suretax
14
-
15
14
  class << self
16
15
  attr_accessor :configuration
17
16
 
@@ -1,7 +1,7 @@
1
- require 'suretax/api/response'
2
- require 'suretax/api/request'
3
- require 'suretax/api/request_item'
4
- require 'suretax/api/cancel_request'
5
- require 'suretax/api/group'
6
- require 'suretax/api/tax'
7
- require 'suretax/api/tax_amount'
1
+ require "suretax/api/response"
2
+ require "suretax/api/request"
3
+ require "suretax/api/request_item"
4
+ require "suretax/api/cancel_request"
5
+ require "suretax/api/group"
6
+ require "suretax/api/tax"
7
+ require "suretax/api/tax_amount"
@@ -17,7 +17,7 @@ module Suretax
17
17
  configuration.validation_key)
18
18
 
19
19
  options.each_pair do |key, value|
20
- send("#{key.to_s}=", value.to_s)
20
+ send("#{key}=", value.to_s)
21
21
  end
22
22
  end
23
23
 
@@ -31,21 +31,21 @@ module Suretax
31
31
 
32
32
  def params
33
33
  {
34
- 'ClientNumber' => client_number,
35
- 'ClientTracking' => client_tracking,
36
- 'TransId' => transaction,
37
- 'ValidationKey' => validation_key
34
+ "ClientNumber" => client_number,
35
+ "ClientTracking" => client_tracking,
36
+ "TransId" => transaction,
37
+ "ValidationKey" => validation_key
38
38
  }
39
39
  end
40
40
 
41
41
  private
42
42
 
43
43
  def log_request
44
- logger.info "\nSureTax Cancellation sent:\n#{params.inspect}" if logger
44
+ logger&.info "\nSureTax Cancellation sent:\n#{params.inspect}"
45
45
  end
46
46
 
47
47
  def log_response(response)
48
- logger.info("\nSureTax Cancellation resp:\n#{response.inspect}") if logger
48
+ logger&.info("\nSureTax Cancellation resp:\n#{response.inspect}")
49
49
  end
50
50
 
51
51
  def logger
@@ -4,13 +4,12 @@ module Suretax
4
4
  attr_reader :state, :customer, :invoice, :taxes, :line
5
5
 
6
6
  def initialize(response_params)
7
- @state = response_params.fetch('StateCode')
8
- @invoice = response_params.fetch('InvoiceNumber')
9
- @line = response_params['LineNumber']
10
- @customer = response_params.fetch('CustomerNumber')
11
- @taxes = response_params.fetch('TaxList').map { |tax| Tax.new(tax) }
7
+ @state = response_params.fetch("StateCode")
8
+ @invoice = response_params.fetch("InvoiceNumber")
9
+ @line = response_params["LineNumber"]
10
+ @customer = response_params.fetch("CustomerNumber")
11
+ @taxes = response_params.fetch("TaxList").map { |tax| Tax.new(tax) }
12
12
  end
13
-
14
13
  end
15
14
  end
16
15
  end
@@ -4,9 +4,9 @@ module Suretax
4
4
  attr_reader :line_number, :response_code, :message
5
5
 
6
6
  def initialize(response_params)
7
- @line_number = response_params.fetch('LineNumber')
8
- @response_code = response_params.fetch('ResponseCode')
9
- @message = response_params.fetch('Message')
7
+ @line_number = response_params.fetch("LineNumber")
8
+ @response_code = response_params.fetch("ResponseCode")
9
+ @message = response_params.fetch("Message")
10
10
  end
11
11
  end
12
12
  end
@@ -34,14 +34,14 @@ module Suretax
34
34
  :items
35
35
 
36
36
  def initialize(options = {})
37
- self.return_file_code = '0'
37
+ self.return_file_code = "0"
38
38
  self.client_number = options.delete(:client_number) || configuration.client_number
39
39
  self.validation_key = options.delete(:validation_key) || configuration.validation_key
40
40
 
41
41
  default_data_date(options)
42
42
 
43
- options.each_pair do |key,value|
44
- self.send("#{key.to_s}=", value.to_s)
43
+ options.each_pair do |key, value|
44
+ send("#{key}=", value.to_s)
45
45
  end
46
46
 
47
47
  initialize_items(options)
@@ -60,12 +60,12 @@ module Suretax
60
60
  end
61
61
 
62
62
  def valid?
63
- !errors.any?
63
+ errors.none?
64
64
  end
65
65
 
66
66
  def rollback
67
67
  if response
68
- CancelRequest.new(transaction: response.transaction,
68
+ CancelRequest.new(transaction: response.transaction,
69
69
  client_number: client_number, validation_key: validation_key,
70
70
  client_tracking: client_tracking).submit
71
71
  end
@@ -74,62 +74,62 @@ module Suretax
74
74
  def params
75
75
  {
76
76
  "ClientNumber" => client_number,
77
- "BusinessUnit" => business_unit || '',
77
+ "BusinessUnit" => business_unit || "",
78
78
  "ValidationKey" => validation_key,
79
79
  "DataYear" => data_year,
80
80
  "DataMonth" => data_month,
81
81
  "TotalRevenue" => total_revenue.to_f,
82
82
  "ReturnFileCode" => return_file_code,
83
- "ClientTracking" => client_tracking || '',
83
+ "ClientTracking" => client_tracking || "",
84
84
  "IndustryExemption" => industry_exemption,
85
85
  "ResponseType" => response_type,
86
86
  "ResponseGroup" => response_group,
87
87
  "STAN" => stan || "",
88
- "ItemList" => items.map { |item| item.params }
88
+ "ItemList" => items.map(&:params)
89
89
  }
90
90
  end
91
91
 
92
92
  private
93
93
 
94
- def default_data_date(options)
95
- max_date = configuration.test? ? Date.today.prev_month : Date.today
94
+ def default_data_date(options)
95
+ max_date = configuration.test? ? Date.today.prev_month : Date.today
96
96
 
97
- requested_date = begin
98
- Date.new(options.delete(:data_year).to_i, options.delete(:data_month).to_i, 1)
99
- rescue
100
- max_date
101
- end
97
+ requested_date = begin
98
+ Date.new(options.delete(:data_year).to_i, options.delete(:data_month).to_i, 1)
99
+ rescue
100
+ max_date
101
+ end
102
102
 
103
- data_date = [requested_date, max_date].min
103
+ data_date = [requested_date, max_date].min
104
104
 
105
- self.data_month = data_date.strftime('%m')
106
- self.data_year = data_date.strftime('%Y')
107
- end
105
+ self.data_month = data_date.strftime("%m")
106
+ self.data_year = data_date.strftime("%Y")
107
+ end
108
108
 
109
- def initialize_items(options)
110
- self.items = []
111
- if options[:items].respond_to?(:each)
112
- options[:items].each do |item_args|
113
- self.items << RequestItem.new(item_args)
114
- end
109
+ def initialize_items(options)
110
+ self.items = []
111
+ if options[:items].respond_to?(:each)
112
+ options[:items].each do |item_args|
113
+ items << RequestItem.new(item_args)
115
114
  end
116
115
  end
116
+ end
117
117
 
118
- def log_request
119
- logger.info "\nSureTax Request sent:\n#{params.inspect}" if logger
120
- end
118
+ def log_request
119
+ logger&.info "\nSureTax Request sent:\n#{params.inspect}"
120
+ end
121
121
 
122
- def logger
123
- configuration.logger
124
- end
122
+ def logger
123
+ configuration.logger
124
+ end
125
125
 
126
- def configuration
127
- Suretax.configuration
128
- end
126
+ def configuration
127
+ Suretax.configuration
128
+ end
129
129
 
130
- def connection
131
- @connection ||= Connection.new
132
- end
130
+ def connection
131
+ @connection ||= Connection.new
132
+ end
133
133
  end
134
134
  end
135
135
  end
@@ -1,8 +1,6 @@
1
1
  module Suretax
2
2
  module Api
3
-
4
3
  class RequestItem
5
-
6
4
  include Suretax::Concerns::Validatable
7
5
 
8
6
  attr_accessor :bill_to_number,
@@ -56,15 +54,13 @@ module Suretax
56
54
  :tax_exemption_codes
57
55
 
58
56
  def initialize(args = {})
59
- args.each_pair do |key,value|
60
- self.send("#{key.to_s}=",value.to_s)
57
+ args.each_pair do |key, value|
58
+ send("#{key}=", value.to_s)
61
59
  end
62
60
 
63
61
  @tax_exemption_codes = []
64
- unless args[:tax_exemption_codes].nil?
65
- args[:tax_exemption_codes].each do |code|
66
- @tax_exemption_codes << code.to_s
67
- end
62
+ args[:tax_exemption_codes]&.each do |code|
63
+ @tax_exemption_codes << code.to_s
68
64
  end
69
65
 
70
66
  validate!
@@ -75,17 +71,17 @@ module Suretax
75
71
  "LineNumber" => line_number,
76
72
  "InvoiceNumber" => invoice_number,
77
73
  "CustomerNumber" => customer_number,
78
- "OrigNumber" => orig_number || '',
79
- "TermNumber" => term_number || '',
80
- "BillToNumber" => bill_to_number || '',
74
+ "OrigNumber" => orig_number || "",
75
+ "TermNumber" => term_number || "",
76
+ "BillToNumber" => bill_to_number || "",
81
77
  "Zipcode" => zipcode,
82
78
  "Plus4" => plus_four,
83
- "P2PZipcode" => p_to_p_zipcode || '',
84
- "P2PPlus4" => p_to_p_plus_four || '',
85
- "TransDate" => trans_date || Date.today.strftime('%m-%d-%Y'),
79
+ "P2PZipcode" => p_to_p_zipcode || "",
80
+ "P2PPlus4" => p_to_p_plus_four || "",
81
+ "TransDate" => trans_date || Date.today.strftime("%m-%d-%Y"),
86
82
  "Revenue" => revenue.to_f,
87
83
  "Units" => units.to_i,
88
- "UnitType" => presence(unit_type) || '00',
84
+ "UnitType" => presence(unit_type) || "00",
89
85
  "Seconds" => seconds.to_i,
90
86
  "TaxIncludedCode" => tax_included_code,
91
87
  "TaxSitusRule" => tax_situs_rule,
@@ -93,7 +89,7 @@ module Suretax
93
89
  "SalesTypeCode" => sales_type_code,
94
90
  "RegulatoryCode" => regulatory_code,
95
91
  "TaxExemptionCodeList" => tax_exemption_codes,
96
- "UDF" => user_defined_field || '',
92
+ "UDF" => user_defined_field || "",
97
93
  "ShipFromZipCode" => ship_from_zipcode || "",
98
94
  "ShipFromPlus4" => ship_from_plus_four || "",
99
95
  "OrderPlacementZipcode" => order_placement_zipcode || "",
@@ -113,7 +109,7 @@ module Suretax
113
109
  end
114
110
 
115
111
  def presence(value)
116
- value if !blank(value)
112
+ value unless blank(value)
117
113
  end
118
114
 
119
115
  def blank(value)