taxamo 1.0.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (82) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +7 -0
  3. data/LICENSE +11 -0
  4. data/README.md +120 -0
  5. data/Rakefile +7 -0
  6. data/lib/monkey.rb +90 -0
  7. data/lib/swagger.rb +93 -0
  8. data/lib/swagger/configuration.rb +21 -0
  9. data/lib/swagger/request.rb +198 -0
  10. data/lib/swagger/response.rb +87 -0
  11. data/lib/taxamo.rb +999 -0
  12. data/lib/taxamo/models/additionalcurrencies.rb +62 -0
  13. data/lib/taxamo/models/additionalcurrency.rb +82 -0
  14. data/lib/taxamo/models/bycountry.rb +77 -0
  15. data/lib/taxamo/models/bystatus.rb +69 -0
  16. data/lib/taxamo/models/bytaxationtype.rb +82 -0
  17. data/lib/taxamo/models/c.rb +77 -0
  18. data/lib/taxamo/models/calculatesimpletaxout.rb +62 -0
  19. data/lib/taxamo/models/calculatetaxin.rb +62 -0
  20. data/lib/taxamo/models/calculatetaxlocationout.rb +97 -0
  21. data/lib/taxamo/models/calculatetaxout.rb +62 -0
  22. data/lib/taxamo/models/canceltransactionout.rb +62 -0
  23. data/lib/taxamo/models/capturepaymentout.rb +62 -0
  24. data/lib/taxamo/models/confirmtransactionin.rb +62 -0
  25. data/lib/taxamo/models/confirmtransactionout.rb +62 -0
  26. data/lib/taxamo/models/countries.rb +112 -0
  27. data/lib/taxamo/models/country.rb +114 -0
  28. data/lib/taxamo/models/countryschema.rb +114 -0
  29. data/lib/taxamo/models/createpaymentin.rb +72 -0
  30. data/lib/taxamo/models/createpaymentout.rb +62 -0
  31. data/lib/taxamo/models/createrefundin.rb +77 -0
  32. data/lib/taxamo/models/createrefundout.rb +77 -0
  33. data/lib/taxamo/models/createsmstokenin.rb +67 -0
  34. data/lib/taxamo/models/createsmstokenout.rb +62 -0
  35. data/lib/taxamo/models/createtransactionin.rb +67 -0
  36. data/lib/taxamo/models/createtransactionout.rb +62 -0
  37. data/lib/taxamo/models/currencyschema.rb +82 -0
  38. data/lib/taxamo/models/customfields.rb +67 -0
  39. data/lib/taxamo/models/emailinvoicein.rb +62 -0
  40. data/lib/taxamo/models/emailinvoiceout.rb +62 -0
  41. data/lib/taxamo/models/evidence.rb +112 -0
  42. data/lib/taxamo/models/evidenceschema.rb +77 -0
  43. data/lib/taxamo/models/getcountriesdictout.rb +63 -0
  44. data/lib/taxamo/models/getcurrenciesdictout.rb +63 -0
  45. data/lib/taxamo/models/getdailysettlementstatsout.rb +63 -0
  46. data/lib/taxamo/models/getproducttypesdictout.rb +63 -0
  47. data/lib/taxamo/models/getrefundsout.rb +63 -0
  48. data/lib/taxamo/models/getsettlementout.rb +83 -0
  49. data/lib/taxamo/models/getsettlementstatsbycountryout.rb +63 -0
  50. data/lib/taxamo/models/getsettlementstatsbytaxationtypeout.rb +62 -0
  51. data/lib/taxamo/models/getsettlementsummaryout.rb +62 -0
  52. data/lib/taxamo/models/gettransactionout.rb +62 -0
  53. data/lib/taxamo/models/gettransactionsstatsout.rb +62 -0
  54. data/lib/taxamo/models/inputtransaction.rb +184 -0
  55. data/lib/taxamo/models/inputtransactionline.rb +133 -0
  56. data/lib/taxamo/models/inputtransactionupdate.rb +184 -0
  57. data/lib/taxamo/models/invoiceaddress.rb +97 -0
  58. data/lib/taxamo/models/listpaymentsout.rb +63 -0
  59. data/lib/taxamo/models/listtransactionsout.rb +63 -0
  60. data/lib/taxamo/models/locategivenipout.rb +72 -0
  61. data/lib/taxamo/models/locatemyipout.rb +72 -0
  62. data/lib/taxamo/models/n.rb +77 -0
  63. data/lib/taxamo/models/payments.rb +72 -0
  64. data/lib/taxamo/models/producttypeschema.rb +62 -0
  65. data/lib/taxamo/models/report.rb +92 -0
  66. data/lib/taxamo/models/settlementdailystatsschema.rb +102 -0
  67. data/lib/taxamo/models/summary.rb +87 -0
  68. data/lib/taxamo/models/transaction.rb +279 -0
  69. data/lib/taxamo/models/transactionlines.rb +163 -0
  70. data/lib/taxamo/models/transactions.rb +279 -0
  71. data/lib/taxamo/models/unconfirmtransactionin.rb +62 -0
  72. data/lib/taxamo/models/unconfirmtransactionout.rb +62 -0
  73. data/lib/taxamo/models/updatetransactionin.rb +62 -0
  74. data/lib/taxamo/models/updatetransactionout.rb +62 -0
  75. data/lib/taxamo/models/validatetaxnumberout.rb +77 -0
  76. data/lib/taxamo/models/verifysmstokenout.rb +62 -0
  77. data/lib/taxamo/version.rb +17 -0
  78. data/taxamo.gemspec +31 -0
  79. data/test/taxamo/connectivity_test.rb +55 -0
  80. data/test/taxamo/tax_test.rb +147 -0
  81. data/test/taxamo/transactions_api_test.rb +308 -0
  82. metadata +226 -0
@@ -0,0 +1,62 @@
1
+ # Copyright 2014-2015 Taxamo, Ltd.
2
+
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at [apache.org/licenses/LICENSE-2.0](http://www.apache.org/licenses/LICENSE-2.0)
6
+ #
7
+ # Unless required by applicable law or agreed to in writing, software
8
+ # distributed under the License is distributed on an "AS IS" BASIS,
9
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10
+ # See the License for the specific language governing permissions and
11
+ # limitations under the License.
12
+
13
+ class UpdateTransactionOut
14
+ attr_accessor :transaction
15
+
16
+ # :internal => :external
17
+ def self.attribute_map
18
+ {
19
+ :transaction => :transaction
20
+
21
+ }
22
+ end
23
+
24
+ def initialize(attributes = {})
25
+ return if attributes.empty?
26
+ # Morph attribute keys into undescored rubyish style
27
+ if attributes["transaction"]
28
+ @transaction = Transaction.new(attributes["transaction"])
29
+
30
+ end
31
+
32
+
33
+ end
34
+
35
+ def to_body
36
+ body = {}
37
+ self.class.attribute_map.each_pair do |key, value|
38
+ v = self.send(key)
39
+ unless v.nil?
40
+ if v.is_a?(Array)
41
+ array = Array.new
42
+ v.each do |item|
43
+ if item.respond_to?("to_body".to_sym)
44
+ array.push item.to_body
45
+ else
46
+ array.push item
47
+ end
48
+ end
49
+ body[value] = array
50
+ else
51
+ if v.respond_to?("to_body".to_sym)
52
+ body[value] = v.to_body
53
+ else
54
+ body[value] = v
55
+ end
56
+ end
57
+ end
58
+ end
59
+ body
60
+ end
61
+ end
62
+
@@ -0,0 +1,77 @@
1
+ # Copyright 2014-2015 Taxamo, Ltd.
2
+
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at [apache.org/licenses/LICENSE-2.0](http://www.apache.org/licenses/LICENSE-2.0)
6
+ #
7
+ # Unless required by applicable law or agreed to in writing, software
8
+ # distributed under the License is distributed on an "AS IS" BASIS,
9
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10
+ # See the License for the specific language governing permissions and
11
+ # limitations under the License.
12
+
13
+ class ValidateTaxNumberOut
14
+ attr_accessor :tax_deducted, :buyer_tax_number, :buyer_tax_number_valid, :billing_country_code
15
+
16
+ # :internal => :external
17
+ def self.attribute_map
18
+ {
19
+ :tax_deducted => :tax_deducted,
20
+ :buyer_tax_number => :buyer_tax_number,
21
+ :buyer_tax_number_valid => :buyer_tax_number_valid,
22
+ :billing_country_code => :billing_country_code
23
+
24
+ }
25
+ end
26
+
27
+ def initialize(attributes = {})
28
+ return if attributes.empty?
29
+ # Morph attribute keys into undescored rubyish style
30
+ if attributes["tax_deducted"]
31
+ @tax_deducted = attributes["tax_deducted"]
32
+
33
+ end
34
+ if attributes["buyer_tax_number"]
35
+ @buyer_tax_number = attributes["buyer_tax_number"]
36
+
37
+ end
38
+ if attributes["buyer_tax_number_valid"]
39
+ @buyer_tax_number_valid = attributes["buyer_tax_number_valid"]
40
+
41
+ end
42
+ if attributes["billing_country_code"]
43
+ @billing_country_code = attributes["billing_country_code"]
44
+
45
+ end
46
+
47
+
48
+ end
49
+
50
+ def to_body
51
+ body = {}
52
+ self.class.attribute_map.each_pair do |key, value|
53
+ v = self.send(key)
54
+ unless v.nil?
55
+ if v.is_a?(Array)
56
+ array = Array.new
57
+ v.each do |item|
58
+ if item.respond_to?("to_body".to_sym)
59
+ array.push item.to_body
60
+ else
61
+ array.push item
62
+ end
63
+ end
64
+ body[value] = array
65
+ else
66
+ if v.respond_to?("to_body".to_sym)
67
+ body[value] = v.to_body
68
+ else
69
+ body[value] = v
70
+ end
71
+ end
72
+ end
73
+ end
74
+ body
75
+ end
76
+ end
77
+
@@ -0,0 +1,62 @@
1
+ # Copyright 2014-2015 Taxamo, Ltd.
2
+
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at [apache.org/licenses/LICENSE-2.0](http://www.apache.org/licenses/LICENSE-2.0)
6
+ #
7
+ # Unless required by applicable law or agreed to in writing, software
8
+ # distributed under the License is distributed on an "AS IS" BASIS,
9
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10
+ # See the License for the specific language governing permissions and
11
+ # limitations under the License.
12
+
13
+ class VerifySMSTokenOut
14
+ attr_accessor :country_code
15
+
16
+ # :internal => :external
17
+ def self.attribute_map
18
+ {
19
+ :country_code => :country_code
20
+
21
+ }
22
+ end
23
+
24
+ def initialize(attributes = {})
25
+ return if attributes.empty?
26
+ # Morph attribute keys into undescored rubyish style
27
+ if attributes["country_code"]
28
+ @country_code = attributes["country_code"]
29
+
30
+ end
31
+
32
+
33
+ end
34
+
35
+ def to_body
36
+ body = {}
37
+ self.class.attribute_map.each_pair do |key, value|
38
+ v = self.send(key)
39
+ unless v.nil?
40
+ if v.is_a?(Array)
41
+ array = Array.new
42
+ v.each do |item|
43
+ if item.respond_to?("to_body".to_sym)
44
+ array.push item.to_body
45
+ else
46
+ array.push item
47
+ end
48
+ end
49
+ body[value] = array
50
+ else
51
+ if v.respond_to?("to_body".to_sym)
52
+ body[value] = v.to_body
53
+ else
54
+ body[value] = v
55
+ end
56
+ end
57
+ end
58
+ end
59
+ body
60
+ end
61
+ end
62
+
@@ -0,0 +1,17 @@
1
+ # Copyright 2014-2015 Taxamo, Ltd.
2
+
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at [apache.org/licenses/LICENSE-2.0](http://www.apache.org/licenses/LICENSE-2.0)
6
+ #
7
+ # Unless required by applicable law or agreed to in writing, software
8
+ # distributed under the License is distributed on an "AS IS" BASIS,
9
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10
+ # See the License for the specific language governing permissions and
11
+ # limitations under the License.
12
+
13
+ module Taxamo
14
+ VERSION = "1.0.5"
15
+ end
16
+
17
+
@@ -0,0 +1,31 @@
1
+ $:.unshift(File.join(File.dirname(__FILE__), 'lib'))
2
+
3
+ require 'taxamo/version'
4
+
5
+ spec = Gem::Specification.new do |s|
6
+ s.name = 'taxamo'
7
+ s.version = Taxamo::VERSION
8
+ s.summary = 'Ruby bindings for the Taxamo API'
9
+ s.description = 'Taxamo provides a real-time Software as a Service (SaaS) solution for compliance with the new 2015 EU VAT rules on the sale of e-services. http://www.taxamo.com'
10
+ s.authors = ['Tomek Lipski']
11
+ s.email = ['tom@taxamo.com']
12
+ s.homepage = 'https://www.taxamo.com/apidocs/index.html'
13
+ s.license = 'Apache'
14
+
15
+ #s.add_dependency('rest-client', '~> 1.4')
16
+ #s.add_dependency('mime-types', '>= 1.25', '< 3.0')
17
+ #s.add_dependency('json', '~> 1.8.1')
18
+ s.add_dependency('addressable', '~> 2')
19
+ s.add_dependency('typhoeus', '~> 0.6.0')
20
+ s.add_dependency('require_all', '~> 1.3.2')
21
+
22
+ s.add_development_dependency('mocha', '~> 0.13.2')
23
+ s.add_development_dependency('shoulda', '~> 3.4.0')
24
+ s.add_development_dependency('test-unit')
25
+ s.add_development_dependency('rake')
26
+
27
+ s.files = `git ls-files`.split("\n")
28
+ s.test_files = `git ls-files -- test/*`.split("\n")
29
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
30
+ s.require_paths = ['lib']
31
+ end
@@ -0,0 +1,55 @@
1
+ # Copyright 2014-2015 Taxamo, Ltd.
2
+
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at [apache.org/licenses/LICENSE-2.0](http://www.apache.org/licenses/LICENSE-2.0)
6
+ #
7
+ # Unless required by applicable law or agreed to in writing, software
8
+ # distributed under the License is distributed on an "AS IS" BASIS,
9
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10
+ # See the License for the specific language governing permissions and
11
+ # limitations under the License.
12
+
13
+ require 'test/unit'
14
+ require 'shoulda'
15
+ require 'taxamo'
16
+
17
+ class ConnectivityTest < Test::Unit::TestCase
18
+
19
+ should 'test_validate' do
20
+ Swagger.configure do |config|
21
+ config.api_key = 'SamplePrivateTestKey1'
22
+ end
23
+
24
+ assert_raise(ValidationError) {
25
+ Taxamo.calculate_tax ({'__transaction' => {
26
+ 'currency_code' => 'USD',
27
+ 'buyer_ip' => '127.0.0.1',
28
+ 'billing_country_code' => 'IE',
29
+ 'force_country_code' => 'FR',
30
+ 'transaction_lines' => [{'amount' => 200,
31
+ 'custom_id' => 'line1'},
32
+ {'amount' => 100,
33
+ 'product_type' => 'e-book',
34
+ 'custom_id' => 'line2'}]}}) }
35
+ end
36
+
37
+ should 'test_auth' do
38
+ Swagger.configure do |config|
39
+ config.api_key = 'SamplePrivateTestKey1!'
40
+ end
41
+ assert_raise(AuthenticationError) {
42
+ Taxamo.calculate_tax ({'__transaction' => {
43
+ 'currency_code' => 'USD',
44
+ 'buyer_ip' => '127.0.0.1',
45
+ 'billing_country_code' => 'IE',
46
+ 'force_country_code' => 'FR',
47
+ 'transaction_lines' => [{'amount' => 200,
48
+ 'custom_id' => 'line1'},
49
+ {'amount' => 100,
50
+ 'product_type' => 'e-book',
51
+ 'custom_id' => 'line2'}]}})}
52
+
53
+
54
+ end
55
+ end
@@ -0,0 +1,147 @@
1
+ # Copyright 2014-2015 Taxamo, Ltd.
2
+
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at [apache.org/licenses/LICENSE-2.0](http://www.apache.org/licenses/LICENSE-2.0)
6
+ #
7
+ # Unless required by applicable law or agreed to in writing, software
8
+ # distributed under the License is distributed on an "AS IS" BASIS,
9
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10
+ # See the License for the specific language governing permissions and
11
+ # limitations under the License.
12
+
13
+ require 'test/unit'
14
+ require 'shoulda'
15
+ require 'taxamo'
16
+
17
+
18
+ class TaxTest < Test::Unit::TestCase
19
+
20
+ should 'basic tax calculation works' do
21
+
22
+ Swagger.configure do |config|
23
+ config.api_key = 'SamplePrivateTestKey1'
24
+ end
25
+ resp = Taxamo.calculate_tax(
26
+ {'transaction' => {
27
+ 'currency_code' => 'USD',
28
+ 'buyer_ip' => '127.0.0.1',
29
+ 'billing_country_code' => 'IE',
30
+ 'force_country_code' => 'FR',
31
+ 'transaction_lines' => [{'amount' => 200,
32
+ 'custom_id' => 'line1'},
33
+ {'amount' => 100,
34
+ 'product_type' => 'e-book',
35
+ 'custom_id' => 'line2'}]}})
36
+
37
+ assert_equal resp.transaction.countries.detected.code, 'IE'
38
+ assert_equal resp.transaction.amount, 300
39
+ assert_equal resp.transaction.tax_amount, 45.5
40
+ assert_equal resp.transaction.total_amount, 345.5
41
+
42
+ assert_equal resp.transaction.transaction_lines[0].custom_id, 'line1'
43
+ assert_equal resp.transaction.transaction_lines[0].tax_rate, 20
44
+ assert_equal resp.transaction.transaction_lines[0].tax_amount, 40
45
+ assert_equal resp.transaction.transaction_lines[1].custom_id, 'line2'
46
+ assert_equal resp.transaction.transaction_lines[1].tax_rate, 5.5
47
+ assert_equal resp.transaction.transaction_lines[1].tax_amount, 5.5
48
+ end
49
+
50
+
51
+ should 'data model works' do
52
+
53
+ Swagger.configure do |config|
54
+ config.api_key = 'SamplePrivateTestKey1'
55
+ end
56
+
57
+ taxIn = CalculateTaxIn.new
58
+ taxIn.transaction = InputTransaction.new
59
+ taxIn.transaction.currency_code = 'USD'
60
+ taxIn.transaction.buyer_ip = '127.0.0.1'
61
+ taxIn.transaction.billing_country_code = 'IE'
62
+ taxIn.transaction.force_country_code = 'FR'
63
+ taxIn.transaction.transaction_lines = [InputTransactionLine.new, InputTransactionLine.new]
64
+ taxIn.transaction.transaction_lines[0].amount = 200
65
+ taxIn.transaction.transaction_lines[0].custom_id = 'line1'
66
+ taxIn.transaction.transaction_lines[1].amount = 100
67
+ taxIn.transaction.transaction_lines[1].custom_id = 'line2'
68
+ taxIn.transaction.transaction_lines[1].product_type = 'e-book'
69
+
70
+ resp = Taxamo.calculate_tax(taxIn)
71
+
72
+ assert_equal resp.transaction.countries.detected.code, 'IE'
73
+ assert_equal resp.transaction.amount, 300
74
+ assert_equal resp.transaction.tax_amount, 45.5
75
+ assert_equal resp.transaction.total_amount, 345.5
76
+
77
+ assert_equal resp.transaction.transaction_lines[0].custom_id, 'line1'
78
+ assert_equal resp.transaction.transaction_lines[0].tax_rate, 20
79
+ assert_equal resp.transaction.transaction_lines[0].tax_amount, 40
80
+ assert_equal resp.transaction.transaction_lines[1].custom_id, 'line2'
81
+ assert_equal resp.transaction.transaction_lines[1].tax_rate, 5.5
82
+ assert_equal resp.transaction.transaction_lines[1].tax_amount, 5.5
83
+ end
84
+
85
+ should 'test simple calculate' do
86
+
87
+ Swagger.configure do |config|
88
+ config.api_key = 'SamplePrivateTestKey1'
89
+ end
90
+ resp = Taxamo.calculate_simple_tax(nil,
91
+ nil,
92
+ 'e-book', #product_type
93
+ 'FR', #force_country_code
94
+ nil,
95
+ nil,
96
+ nil,
97
+ nil,
98
+ 100, #amount
99
+ 'IE', #billing_country_code
100
+ 'USD', #currency_code
101
+ nil)
102
+
103
+ assert_equal resp.transaction.tax_country_code, 'FR'
104
+ assert_equal resp.transaction.amount, 100
105
+ assert_equal resp.transaction.tax_amount, 5.5
106
+ assert_equal resp.transaction.total_amount, 105.5
107
+
108
+ assert_equal resp.transaction.transaction_lines[0].tax_rate, 5.5
109
+ assert_equal resp.transaction.transaction_lines[0].tax_rate, 5.5
110
+ assert_equal resp.transaction.transaction_lines[0].total_amount, 105.5
111
+
112
+ end
113
+
114
+ should 'test validate tax number' do
115
+
116
+ Swagger.configure do |config|
117
+ config.api_key = 'SamplePrivateTestKey1'
118
+ end
119
+ resp = Taxamo.validate_tax_number(nil, 'IE6388047V')
120
+ assert_equal resp.tax_deducted, true
121
+ assert_equal resp.billing_country_code, 'IE'
122
+
123
+ resp = Taxamo.validate_tax_number('IE', '6388047V')
124
+ assert_equal resp.tax_deducted, true
125
+ assert_equal resp.billing_country_code, 'IE'
126
+
127
+ resp = Taxamo.validate_tax_number('IE', '6388047V12121')
128
+
129
+ assert_equal resp.tax_deducted, nil
130
+ end
131
+
132
+
133
+ should 'test_location_calculate' do
134
+
135
+ Swagger.configure do |config|
136
+ config.api_key = 'SamplePrivateTestKey1'
137
+ end
138
+
139
+ resp = Taxamo.calculate_tax_location('BE', '424242')
140
+ assert_equal resp.tax_country_code, 'BE'
141
+ assert_equal resp.tax_supported, true
142
+ assert_equal resp.countries.detected.code, 'BE'
143
+ assert_equal resp.countries.by_billing.code, 'BE'
144
+ assert_equal resp.countries.by_cc.code, 'BE'
145
+
146
+ end
147
+ end