tax_cloud 0.2.2 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.rubocop.yml +29 -0
- data/.travis.yml +4 -7
- data/CHANGELOG.rdoc +6 -0
- data/Gemfile +6 -1
- data/README.rdoc +2 -2
- data/Rakefile +4 -1
- data/lib/hash.rb +2 -4
- data/lib/tax_cloud.rb +8 -12
- data/lib/tax_cloud/address.rb +3 -5
- data/lib/tax_cloud/cart_item.rb +0 -2
- data/lib/tax_cloud/client.rb +22 -21
- data/lib/tax_cloud/configuration.rb +2 -3
- data/lib/tax_cloud/errors/api_error.rb +6 -6
- data/lib/tax_cloud/errors/missing_config_error.rb +2 -2
- data/lib/tax_cloud/errors/missing_config_option_error.rb +5 -5
- data/lib/tax_cloud/errors/soap_error.rb +8 -10
- data/lib/tax_cloud/errors/tax_cloud_error.rb +45 -48
- data/lib/tax_cloud/errors/unexpected_soap_response_error.rb +7 -10
- data/lib/tax_cloud/record.rb +1 -1
- data/lib/tax_cloud/responses.rb +1 -1
- data/lib/tax_cloud/responses/authorized.rb +1 -1
- data/lib/tax_cloud/responses/authorized_with_capture.rb +1 -1
- data/lib/tax_cloud/responses/base.rb +26 -30
- data/lib/tax_cloud/responses/captured.rb +2 -3
- data/lib/tax_cloud/responses/cart_item.rb +2 -5
- data/lib/tax_cloud/responses/generic.rb +2 -6
- data/lib/tax_cloud/responses/lookup.rb +7 -10
- data/lib/tax_cloud/responses/ping.rb +2 -2
- data/lib/tax_cloud/responses/returned.rb +2 -2
- data/lib/tax_cloud/responses/tax_code_groups.rb +10 -13
- data/lib/tax_cloud/responses/tax_codes.rb +9 -12
- data/lib/tax_cloud/responses/tax_codes_by_group.rb +11 -14
- data/lib/tax_cloud/responses/verify_address.rb +6 -9
- data/lib/tax_cloud/tax_code.rb +1 -1
- data/lib/tax_cloud/tax_code_constants.rb +7 -9
- data/lib/tax_cloud/tax_code_group.rb +2 -4
- data/lib/tax_cloud/tax_code_groups.rb +2 -5
- data/lib/tax_cloud/tax_codes.rb +1 -5
- data/lib/tax_cloud/transaction.rb +6 -6
- data/lib/tax_cloud/version.rb +1 -1
- data/tax_cloud.gemspec +3 -3
- data/test/cassettes/authorized.yml +729 -2
- data/test/cassettes/authorized_with_capture.yml +729 -2
- data/test/cassettes/authorized_with_localized_time.yml +729 -2
- data/test/cassettes/captured.yml +730 -3
- data/test/cassettes/get_tic_groups.yml +154 -27
- data/test/cassettes/get_tics.yml +154 -27
- data/test/cassettes/get_tics_by_group.yml +728 -1
- data/test/cassettes/invalid_soap_call.yml +154 -27
- data/test/cassettes/lookup.yml +728 -1
- data/test/cassettes/lookup_ny.yml +728 -1
- data/test/cassettes/ping.yml +160 -31
- data/test/cassettes/ping_with_invalid_credentials.yml +154 -27
- data/test/cassettes/ping_with_invalid_response.yml +154 -27
- data/test/cassettes/returned.yml +730 -3
- data/test/cassettes/verify_bad_address.yml +680 -503
- data/test/cassettes/verify_good_address.yml +727 -0
- data/test/helper.rb +0 -4
- data/test/test_address.rb +4 -6
- data/test/test_cart_item.rb +1 -3
- data/test/test_client.rb +2 -4
- data/test/test_configuration.rb +3 -5
- data/test/test_setup.rb +0 -1
- data/test/test_soap.rb +2 -4
- data/test/test_tax_code_groups.rb +2 -4
- data/test/test_tax_codes.rb +1 -3
- data/test/test_transaction.rb +7 -9
- data/test/test_transaction_ny.rb +4 -6
- data/test/vcr_setup.rb +1 -1
- metadata +36 -41
- data/lib/savon_soap_xml.rb +0 -33
@@ -1,23 +1,20 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
module TaxCloud #:nodoc:
|
3
3
|
module Errors #:nodoc:
|
4
|
-
|
5
|
-
# This error is raised when TaxCloud returns an
|
4
|
+
# This error is raised when TaxCloud returns an
|
6
5
|
# unexpected SOAP response.
|
7
6
|
class UnexpectedSoapResponse < TaxCloudError
|
8
|
-
|
9
7
|
# === Parameters
|
10
8
|
# [raw] Raw data from the SOAP response.
|
11
9
|
# [key] Expected key in the SOAP response.
|
12
10
|
# [chain] Complete SOAP response chain in which the key could not be found.
|
13
11
|
def initialize(raw, key, chain)
|
14
|
-
super(compose_message(
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
12
|
+
super(compose_message('unexpected_soap_response',
|
13
|
+
key: key,
|
14
|
+
raw: raw,
|
15
|
+
chain: chain
|
16
|
+
))
|
19
17
|
end
|
20
|
-
|
21
18
|
end
|
22
19
|
end
|
23
|
-
end
|
20
|
+
end
|
data/lib/tax_cloud/record.rb
CHANGED
data/lib/tax_cloud/responses.rb
CHANGED
@@ -10,4 +10,4 @@ require 'tax_cloud/responses/captured'
|
|
10
10
|
require 'tax_cloud/responses/returned'
|
11
11
|
require 'tax_cloud/responses/tax_codes'
|
12
12
|
require 'tax_cloud/responses/tax_code_groups'
|
13
|
-
require 'tax_cloud/responses/tax_codes_by_group'
|
13
|
+
require 'tax_cloud/responses/tax_codes_by_group'
|
@@ -1,10 +1,8 @@
|
|
1
1
|
module TaxCloud #:nodoc:
|
2
2
|
module Responses #:nodoc:
|
3
|
-
|
4
3
|
# A base TaxCloud SOAP response.
|
5
4
|
class Base
|
6
|
-
|
7
|
-
# Raw response.
|
5
|
+
# Raw response.
|
8
6
|
attr_accessor :raw
|
9
7
|
|
10
8
|
# === Parameters
|
@@ -15,23 +13,22 @@ module TaxCloud #:nodoc:
|
|
15
13
|
end
|
16
14
|
|
17
15
|
class << self
|
18
|
-
|
19
16
|
# === Parameters
|
20
17
|
# [value] Location of the response type in the SOAP XML.
|
21
18
|
def response_type(value)
|
22
|
-
|
19
|
+
set_dsl(:response_type, value)
|
23
20
|
end
|
24
21
|
|
25
22
|
# === Parameters
|
26
23
|
# [value] Location of the error message in the SOAP XML.
|
27
24
|
def error_message(value)
|
28
|
-
|
25
|
+
set_dsl(:error_message, value)
|
29
26
|
end
|
30
27
|
|
31
28
|
# === Parameters
|
32
29
|
# [value] Location of the error number in the SOAP XML.
|
33
30
|
def error_number(value)
|
34
|
-
|
31
|
+
set_dsl(:error_number, value)
|
35
32
|
end
|
36
33
|
|
37
34
|
# Parse a SOAP response.
|
@@ -39,7 +36,7 @@ module TaxCloud #:nodoc:
|
|
39
36
|
# === Parameters
|
40
37
|
# [savon_response] SOAP response.
|
41
38
|
def parse(savon_response)
|
42
|
-
|
39
|
+
new(savon_response)
|
43
40
|
end
|
44
41
|
end
|
45
42
|
|
@@ -49,40 +46,39 @@ module TaxCloud #:nodoc:
|
|
49
46
|
# [chain] XML path to match.
|
50
47
|
def match(chain)
|
51
48
|
current_value = raw
|
52
|
-
chain.split(
|
49
|
+
chain.split('/').each do |key|
|
53
50
|
current_value = current_value[key.to_sym]
|
54
51
|
next if current_value
|
55
|
-
|
52
|
+
fail TaxCloud::Errors::UnexpectedSoapResponse.new(raw, key, chain)
|
56
53
|
end
|
57
54
|
current_value
|
58
55
|
end
|
59
56
|
|
60
57
|
private
|
61
58
|
|
62
|
-
|
59
|
+
class_attribute :dsl
|
63
60
|
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
end
|
61
|
+
class << self
|
62
|
+
def set_dsl(key, value)
|
63
|
+
self.dsl ||= {}
|
64
|
+
self.dsl[key] = value
|
65
|
+
self.dsl
|
70
66
|
end
|
67
|
+
end
|
71
68
|
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
end
|
78
|
-
elsif self.dsl[:error_number]
|
79
|
-
return true if match(self.dsl[:error_number]) == "0"
|
80
|
-
end
|
81
|
-
if self.dsl[:error_message]
|
82
|
-
raise TaxCloud::Errors::ApiError.new(match(self.dsl[:error_message]), raw)
|
69
|
+
def parse!
|
70
|
+
if self.dsl[:response_type]
|
71
|
+
case match(self.dsl[:response_type])
|
72
|
+
when 'OK', 'Informational' then
|
73
|
+
return true
|
83
74
|
end
|
75
|
+
elsif self.dsl[:error_number]
|
76
|
+
return true if match(self.dsl[:error_number]) == '0'
|
84
77
|
end
|
85
|
-
|
78
|
+
if self.dsl[:error_message]
|
79
|
+
fail TaxCloud::Errors::ApiError.new(match(self.dsl[:error_message]), raw)
|
80
|
+
end
|
81
|
+
end
|
86
82
|
end
|
87
83
|
end
|
88
|
-
end
|
84
|
+
end
|
@@ -1,11 +1,9 @@
|
|
1
1
|
module TaxCloud #:nodoc:
|
2
2
|
module Responses #:nodoc:
|
3
|
-
|
4
3
|
# A single item in the response to a TaxCloud Lookup API call.
|
5
|
-
#
|
4
|
+
#
|
6
5
|
# See https://api.taxcloud.net/1.0/TaxCloud.asmx?op=Lookup.
|
7
6
|
class CartItem
|
8
|
-
|
9
7
|
# The index of the cart item.
|
10
8
|
attr_accessor :cart_item_index
|
11
9
|
|
@@ -18,7 +16,6 @@ module TaxCloud #:nodoc:
|
|
18
16
|
self.cart_item_index = savon_response[:cart_item_index].to_i
|
19
17
|
self.tax_amount = savon_response[:tax_amount].to_f
|
20
18
|
end
|
21
|
-
|
22
19
|
end
|
23
20
|
end
|
24
|
-
end
|
21
|
+
end
|
@@ -1,14 +1,11 @@
|
|
1
1
|
module TaxCloud #:nodoc:
|
2
2
|
module Responses #:nodoc:
|
3
|
-
|
4
3
|
# A generic response to a TaxCloud API call.
|
5
4
|
class Generic < Base
|
6
|
-
|
7
5
|
# Response key.
|
8
6
|
class_attribute :key
|
9
7
|
|
10
8
|
class << self
|
11
|
-
|
12
9
|
# Set the response key.
|
13
10
|
# === Parameters
|
14
11
|
# [key] Response key.
|
@@ -25,11 +22,10 @@ module TaxCloud #:nodoc:
|
|
25
22
|
#
|
26
23
|
# Usually returns "OK" or raises an error.
|
27
24
|
def parse(savon_response)
|
28
|
-
response =
|
25
|
+
response = new(savon_response)
|
29
26
|
response.raw["#{key}_response".to_sym]["#{key}_result".to_sym][:response_type]
|
30
27
|
end
|
31
28
|
end
|
32
|
-
|
33
29
|
end
|
34
30
|
end
|
35
|
-
end
|
31
|
+
end
|
@@ -1,41 +1,38 @@
|
|
1
1
|
module TaxCloud #:nodoc:
|
2
2
|
module Responses #:nodoc:
|
3
|
-
|
4
3
|
# Response to a TaxCloud Lookup API call.
|
5
4
|
#
|
6
5
|
# See https://api.taxcloud.net/1.0/TaxCloud.asmx?op=Lookup.
|
7
6
|
class Lookup < Base
|
8
|
-
|
9
7
|
# Cart ID.
|
10
8
|
attr_accessor :cart_id
|
11
9
|
|
12
10
|
# Cart items.
|
13
11
|
attr_accessor :cart_items
|
14
12
|
|
15
|
-
response_type
|
16
|
-
error_message
|
13
|
+
response_type 'lookup_response/lookup_result/response_type'
|
14
|
+
error_message 'lookup_response/lookup_result/messages/response_message/message'
|
17
15
|
|
18
16
|
# === Parameters
|
19
17
|
# [savon_response] SOAP response.
|
20
18
|
def initialize(savon_response)
|
21
19
|
super savon_response
|
22
|
-
self.cart_id = match(
|
20
|
+
self.cart_id = match('lookup_response/lookup_result/cart_id')
|
23
21
|
# there can be on response or an array of responses
|
24
|
-
cart_item_responses = match(
|
22
|
+
cart_item_responses = match('lookup_response/lookup_result/cart_items_response/cart_item_response')
|
25
23
|
if cart_item_responses.is_a?(Array)
|
26
24
|
self.cart_items = cart_item_responses.map do |cart_item_response|
|
27
25
|
TaxCloud::Responses::CartItem.new(cart_item_response)
|
28
26
|
end
|
29
27
|
else
|
30
|
-
self.cart_items = [
|
28
|
+
self.cart_items = [TaxCloud::Responses::CartItem.new(cart_item_responses)]
|
31
29
|
end
|
32
30
|
end
|
33
31
|
|
34
32
|
# Total tax amount in this cart.
|
35
33
|
def tax_amount
|
36
|
-
cart_items.
|
34
|
+
cart_items.reduce(0) { |a, e| a + e.tax_amount }
|
37
35
|
end
|
38
|
-
|
39
36
|
end
|
40
37
|
end
|
41
|
-
end
|
38
|
+
end
|
@@ -1,33 +1,30 @@
|
|
1
1
|
module TaxCloud #:nodoc:
|
2
2
|
module Responses #:nodoc:
|
3
|
-
|
4
3
|
# Response to a TaxCloud getTICGroups API call.
|
5
4
|
#
|
6
5
|
# https://api.taxcloud.net/1.0/TaxCloud.asmx?op=GetTICGroups
|
7
6
|
class TaxCodeGroups < Base
|
8
|
-
|
9
|
-
|
10
|
-
error_message "get_tic_groups_response/get_tic_groups_result/messages/response_message/message"
|
7
|
+
response_type 'get_tic_groups_response/get_tic_groups_result/response_type'
|
8
|
+
error_message 'get_tic_groups_response/get_tic_groups_result/messages/response_message/message'
|
11
9
|
|
12
10
|
class << self
|
13
11
|
# Parse a TaxCloud response.
|
14
12
|
#
|
15
|
-
# === Parameters
|
13
|
+
# === Parameters
|
16
14
|
# [savon_response] SOAP response.
|
17
15
|
#
|
18
16
|
# Returns an array of Tax Code Groups.
|
19
17
|
def parse(savon_response)
|
20
|
-
response =
|
21
|
-
tax_code_groups = response.match(
|
18
|
+
response = new(savon_response)
|
19
|
+
tax_code_groups = response.match('get_tic_groups_response/get_tic_groups_result/tic_groups/tic_group')
|
22
20
|
tax_code_groups.map do |tax_code_group|
|
23
|
-
TaxCloud::TaxCodeGroup.new(
|
24
|
-
:
|
25
|
-
:
|
26
|
-
|
21
|
+
TaxCloud::TaxCodeGroup.new(
|
22
|
+
group_id: tax_code_group[:group_id].to_i,
|
23
|
+
description: tax_code_group[:description].strip
|
24
|
+
)
|
27
25
|
end
|
28
26
|
end
|
29
27
|
end
|
30
|
-
|
31
28
|
end
|
32
29
|
end
|
33
|
-
end
|
30
|
+
end
|
@@ -1,13 +1,11 @@
|
|
1
1
|
module TaxCloud #:nodoc:
|
2
2
|
module Responses #:nodoc:
|
3
|
-
|
4
3
|
# Response to a TaxCloud getTICs API call.
|
5
4
|
#
|
6
5
|
# See https://api.taxcloud.net/1.0/TaxCloud.asmx?op=GetTICs.
|
7
6
|
class TaxCodes < Base
|
8
|
-
|
9
|
-
|
10
|
-
error_message "get_ti_cs_response/get_ti_cs_result/messages/response_message/message"
|
7
|
+
response_type 'get_ti_cs_response/get_ti_cs_result/response_type'
|
8
|
+
error_message 'get_ti_cs_response/get_ti_cs_result/messages/response_message/message'
|
11
9
|
|
12
10
|
class << self
|
13
11
|
# Parse a TaxCloud response.
|
@@ -17,17 +15,16 @@ module TaxCloud #:nodoc:
|
|
17
15
|
#
|
18
16
|
# Returns an array of tax codes.
|
19
17
|
def parse(savon_response)
|
20
|
-
response =
|
21
|
-
tax_codes = response.match(
|
18
|
+
response = new(savon_response)
|
19
|
+
tax_codes = response.match('get_ti_cs_response/get_ti_cs_result/ti_cs/tic')
|
22
20
|
tax_codes.map do |tax_code|
|
23
|
-
TaxCloud::TaxCode.new(
|
24
|
-
:
|
25
|
-
:
|
26
|
-
|
21
|
+
TaxCloud::TaxCode.new(
|
22
|
+
ticid: tax_code[:ticid].to_i,
|
23
|
+
description: tax_code[:description].strip
|
24
|
+
)
|
27
25
|
end
|
28
26
|
end
|
29
27
|
end
|
30
|
-
|
31
28
|
end
|
32
29
|
end
|
33
|
-
end
|
30
|
+
end
|
@@ -1,33 +1,30 @@
|
|
1
1
|
module TaxCloud #:nodoc:
|
2
2
|
module Responses #:nodoc:
|
3
|
-
|
4
3
|
# Response to a TaxCloud getTICsByGroup API call.
|
5
|
-
#
|
4
|
+
#
|
6
5
|
# See https://api.taxcloud.net/1.0/TaxCloud.asmx?op=GetTICsByGroup.
|
7
6
|
class TaxCodesByGroup < Base
|
8
|
-
|
9
|
-
|
10
|
-
error_message "get_ti_cs_by_group_response/get_ti_cs_by_group_result/messages/response_message/message"
|
7
|
+
response_type 'get_ti_cs_by_group_response/get_ti_cs_by_group_result/response_type'
|
8
|
+
error_message 'get_ti_cs_by_group_response/get_ti_cs_by_group_result/messages/response_message/message'
|
11
9
|
|
12
10
|
class << self
|
13
11
|
# Parse a TaxCloud response.
|
14
12
|
#
|
15
|
-
# === Parameters
|
13
|
+
# === Parameters
|
16
14
|
# [savon_response] SOAP response.
|
17
15
|
#
|
18
16
|
# Returns an array of tax codes.
|
19
17
|
def parse(savon_response)
|
20
|
-
response =
|
21
|
-
tax_codes = response.match(
|
18
|
+
response = new(savon_response)
|
19
|
+
tax_codes = response.match('get_ti_cs_by_group_response/get_ti_cs_by_group_result/ti_cs/tic')
|
22
20
|
tax_codes.map do |tax_code|
|
23
|
-
TaxCloud::TaxCode.new(
|
24
|
-
:
|
25
|
-
:
|
26
|
-
|
21
|
+
TaxCloud::TaxCode.new(
|
22
|
+
ticid: tax_code[:ticid].to_i,
|
23
|
+
description: tax_code[:description]
|
24
|
+
)
|
27
25
|
end
|
28
26
|
end
|
29
27
|
end
|
30
|
-
|
31
28
|
end
|
32
29
|
end
|
33
|
-
end
|
30
|
+
end
|
@@ -1,14 +1,12 @@
|
|
1
1
|
module TaxCloud #:nodoc:
|
2
2
|
module Responses #:nodoc:
|
3
|
-
|
4
3
|
# Response to a TaxCloud VerifyAddress API call.
|
5
|
-
#
|
4
|
+
#
|
6
5
|
# See https://api.taxcloud.net/1.0/TaxCloud.asmx?op=VerifyAddress.
|
7
6
|
class VerifyAddress < Base
|
7
|
+
error_number 'verify_address_response/verify_address_result/err_number'
|
8
|
+
error_message 'verify_address_response/verify_address_result/err_description'
|
8
9
|
|
9
|
-
error_number "verify_address_response/verify_address_result/err_number"
|
10
|
-
error_message "verify_address_response/verify_address_result/err_description"
|
11
|
-
|
12
10
|
class << self
|
13
11
|
# Parse a TaxCloud response.
|
14
12
|
#
|
@@ -17,13 +15,12 @@ module TaxCloud #:nodoc:
|
|
17
15
|
#
|
18
16
|
# Returns a verified TaxCloud::Address.
|
19
17
|
def parse(savon_response)
|
20
|
-
response =
|
21
|
-
result = response.match(
|
18
|
+
response = new(savon_response)
|
19
|
+
result = response.match('verify_address_response/verify_address_result')
|
22
20
|
result.delete(:err_number)
|
23
21
|
TaxCloud::Address.new result
|
24
22
|
end
|
25
23
|
end
|
26
|
-
|
27
24
|
end
|
28
25
|
end
|
29
|
-
end
|
26
|
+
end
|