trolley 0.2.14 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. checksums.yaml +4 -4
  2. data/lib/trolley/Balance.rb +4 -0
  3. data/lib/trolley/Batch.rb +20 -0
  4. data/lib/trolley/BatchSummary.rb +21 -0
  5. data/lib/trolley/Client.rb +117 -0
  6. data/lib/trolley/Configuration.rb +30 -0
  7. data/lib/trolley/Exceptions.rb +26 -0
  8. data/lib/trolley/Gateway.rb +18 -0
  9. data/lib/trolley/Invoice.rb +22 -0
  10. data/lib/trolley/InvoicePayment.rb +13 -0
  11. data/lib/trolley/OfflinePayment.rb +23 -0
  12. data/lib/trolley/Payment.rb +52 -0
  13. data/lib/trolley/Recipient.rb +44 -0
  14. data/lib/trolley/RecipientAccount.rb +30 -0
  15. data/lib/trolley/gateways/BalanceGateway.rb +15 -0
  16. data/lib/trolley/gateways/BatchGateway.rb +74 -0
  17. data/lib/trolley/gateways/InvoiceGateway.rb +57 -0
  18. data/lib/trolley/gateways/InvoicePaymentGateway.rb +37 -0
  19. data/lib/trolley/gateways/OfflinePaymentGateway.rb +44 -0
  20. data/lib/trolley/gateways/PaymentGateway.rb +42 -0
  21. data/lib/trolley/gateways/RecipientAccountGateway.rb +42 -0
  22. data/lib/trolley/gateways/RecipientGateway.rb +82 -0
  23. data/lib/trolley/utils/PaginatedArray.rb +25 -0
  24. data/lib/trolley/utils/ResponseMapper.rb +80 -0
  25. data/lib/trolley.rb +33 -5
  26. data/spec/integration/BatchTest.rb +126 -0
  27. data/spec/integration/InvoicePaymentTest.rb +92 -0
  28. data/spec/integration/InvoiceTest.rb +128 -0
  29. data/spec/integration/RecipientAccountTest.rb +48 -0
  30. data/spec/integration/RecipientTest.rb +159 -0
  31. data/spec/integration/helper.rb +19 -0
  32. data/spec/unit/ConfigurationTest.rb +47 -0
  33. data/spec/unit/PaginatedArrayTest.rb +23 -0
  34. data/spec/unit/ResponseMapperTest.rb +26 -0
  35. data/spec/unit/TrolleyTest.rb +15 -0
  36. data/trolley.gemspec +15 -12
  37. metadata +96 -7
@@ -0,0 +1,48 @@
1
+ require_relative 'helper'
2
+
3
+ class RecipientAccountTest < Test::Unit::TestCase
4
+ include ApiClientHelper
5
+
6
+ # rubocop:disable Metrics/MethodLength
7
+ def test_basic_crud
8
+ recipient = @client.recipient.create(
9
+ type: 'individual',
10
+ firstName: 'Tom',
11
+ lastName: 'Jones',
12
+ email: "test.create#{uuid}@example.com"
13
+ )
14
+ recipient_account = @client.recipient_account.create(
15
+ recipient.id, type: 'bank-transfer',
16
+ currency: 'EUR',
17
+ country: 'DE',
18
+ iban: 'DE89 3704 0044 0532 0130 00'
19
+ )
20
+
21
+ assert_not_nil(recipient_account)
22
+ assert_equal(recipient_account.type, 'bank-transfer')
23
+ assert_equal(recipient_account.currency, 'EUR')
24
+
25
+ recipient_account = @client.recipient_account.update(
26
+ recipient.id, recipient_account.id,
27
+ primary: true
28
+ )
29
+
30
+ assert_not_nil(recipient_account)
31
+ assert_equal(recipient_account.type, 'bank-transfer')
32
+ assert_equal(recipient_account.currency, 'EUR')
33
+ assert_equal(recipient_account.primary, true)
34
+
35
+ recipient_account = @client.recipient_account.find(
36
+ recipient.id, recipient_account.id
37
+ )
38
+
39
+ assert_not_nil(recipient_account)
40
+
41
+ response = @client.recipient_account.delete(
42
+ recipient.id, recipient_account.id
43
+ )
44
+
45
+ assert_true(response)
46
+ end
47
+ # rubocop:enable Metrics/MethodLength
48
+ end
@@ -0,0 +1,159 @@
1
+ require_relative 'helper'
2
+
3
+ # rubocop:disable Metrics/ClassLength
4
+ class RecipientTest < Test::Unit::TestCase
5
+ include ApiClientHelper
6
+
7
+ def test_create
8
+ response = @client.recipient.create(
9
+ type: 'individual',
10
+ firstName: 'Tom',
11
+ lastName: 'Jones',
12
+ email: "test.create#{uuid}@example.com"
13
+ )
14
+ assert_not_nil(response)
15
+ assert_equal(response.firstName, 'Tom')
16
+ assert_equal(response.lastName, 'Jones')
17
+ assert_not_nil(response.id)
18
+ end
19
+
20
+ def test_lifecycle
21
+ recipient = @client.recipient.create(
22
+ type: 'individual',
23
+ firstName: 'Tom',
24
+ lastName: 'Jones',
25
+ email: "test.create#{uuid}@example.com"
26
+ )
27
+ assert_not_nil(recipient)
28
+ assert_equal(recipient.firstName, 'Tom')
29
+ assert_equal(recipient.status, 'incomplete')
30
+
31
+ response = @client.recipient.update(recipient.id, firstName: 'Bob')
32
+ assert_true(response)
33
+
34
+ recipient = @client.recipient.find(recipient.id)
35
+ assert_equal(recipient.firstName, 'Bob')
36
+
37
+ response = @client.recipient.delete(recipient.id)
38
+ assert_true(response)
39
+
40
+ recipient = @client.recipient.find(recipient.id)
41
+ assert_equal(recipient.status, 'archived')
42
+ end
43
+
44
+ def test_account
45
+ recipient = @client.recipient.create(
46
+ type: 'individual',
47
+ firstName: 'Tom',
48
+ lastName: 'Jones',
49
+ email: "test.create#{uuid}@example.com",
50
+ address: {
51
+ street1: '123 Wolfstrasse',
52
+ city: 'Berlin',
53
+ country: 'DE',
54
+ postalCode: '123123'
55
+ }
56
+ )
57
+ assert_not_nil(recipient)
58
+ assert_equal(recipient.firstName, 'Tom')
59
+ assert_equal(recipient.lastName, 'Jones')
60
+ assert_not_nil(recipient.id)
61
+ assert_true(recipient.routeMinimum.to_i >= 0)
62
+
63
+ account = @client.recipient_account.create(recipient.id, type: 'bank-transfer', currency: 'EUR', country: 'DE', iban: 'DE89 3704 0044 0532 0130 00')
64
+ assert_not_nil(account)
65
+
66
+ account = @client.recipient_account.create(recipient.id, type: 'bank-transfer', currency: 'EUR', country: 'FR', iban: 'FR14 2004 1010 0505 0001 3M02 606')
67
+ assert_not_nil(account)
68
+
69
+ findAccount = @client.recipient_account.find(recipient.id, account.id)
70
+ assert_equal(account.id, findAccount.id)
71
+
72
+ accountList = @client.recipient_account.all(recipient.id)
73
+ assert_equal(2, accountList.count)
74
+ assert_equal(accountList[0].currency, 'EUR')
75
+
76
+ result = @client.recipient_account.delete(recipient.id, account.id)
77
+ assert_true(result)
78
+
79
+ accountList = @client.recipient_account.all(recipient.id)
80
+ assert_equal(1, accountList.count)
81
+ end
82
+
83
+ def test_delete_multiple
84
+ recipient1 = @client.recipient.create(
85
+ type: 'individual',
86
+ firstName: 'Tom',
87
+ lastName: 'Jones',
88
+ email: "test.create#{uuid}@example.com"
89
+ )
90
+ assert_not_nil(recipient1)
91
+ assert_equal(recipient1.firstName, 'Tom')
92
+ assert_equal(recipient1.status, 'incomplete')
93
+
94
+ recipient2 = @client.recipient.create(
95
+ type: 'individual',
96
+ firstName: 'Tom',
97
+ lastName: 'Jones',
98
+ email: "test.create#{uuid}@example.com"
99
+ )
100
+ assert_not_nil(recipient2)
101
+ assert_equal(recipient2.firstName, 'Tom')
102
+ assert_equal(recipient2.status, 'incomplete')
103
+
104
+ response = @client.recipient.delete([recipient1.id, recipient2.id])
105
+ assert_true(response)
106
+
107
+ recipient1 = @client.recipient.find(recipient1.id)
108
+ assert_equal(recipient1.status, 'archived')
109
+
110
+ recipient2 = @client.recipient.find(recipient2.id)
111
+ assert_equal(recipient2.status, 'archived')
112
+ end
113
+
114
+ def test_find_logs
115
+ recipient = @client.recipient.create(
116
+ type: 'individual',
117
+ firstName: 'Tom',
118
+ lastName: 'Jones',
119
+ email: "test.create#{uuid}@example.com"
120
+ )
121
+ assert_not_nil(recipient)
122
+ assert_equal(recipient.firstName, 'Tom')
123
+ assert_equal(recipient.status, 'incomplete')
124
+
125
+ @client.recipient.update(recipient.id, firstName: 'John')
126
+ logs = @client.recipient.find_logs(recipient.id)
127
+
128
+ assert_equal(logs.class, OpenStruct)
129
+ assert_boolean(true, @client.recipient.delete(recipient.id))
130
+ end
131
+
132
+ def test_find_payments
133
+ recipient = @client.recipient.create(
134
+ type: 'individual',
135
+ firstName: 'Tom',
136
+ lastName: 'Jones',
137
+ email: "test.create#{uuid}@example.com"
138
+ )
139
+ recipient_account = @client.recipient_account.create(recipient.id, type: 'bank-transfer', currency: 'EUR', country: 'DE', iban: 'DE89 3704 0044 0532 0130 00')
140
+
141
+ batch = @client.batch.create(
142
+ sourceCurrency: 'USD', description: 'Integration Test Payments', payments: [
143
+ { targetAmount: '10.00', targetCurrency: 'EUR', recipient: { id: recipient.id } },
144
+ { sourceAmount: '10.00', recipient: { id: recipient.id } }
145
+ ]
146
+ )
147
+
148
+ payments = @client.recipient.find_payments(recipient.id)
149
+ assert_equal(payments.count, 2)
150
+ assert_equal(payments[0].recipient['id'], recipient.id)
151
+ assert_equal(payments[1].recipient['id'], recipient.id)
152
+ assert_equal(payments.map(&:amount), ['10.00', '10.00'])
153
+
154
+ assert_boolean(true, @client.batch.delete(batch.id))
155
+ assert_boolean(true, @client.recipient_account.delete(recipient.id, recipient_account.id))
156
+ assert_boolean(true, @client.recipient.delete(recipient.id))
157
+ end
158
+ end
159
+ # rubocop:enable Metrics/ClassLength
@@ -0,0 +1,19 @@
1
+ require_relative '../../lib/trolley'
2
+ require 'dotenv/load'
3
+ require 'test/unit'
4
+ require 'securerandom'
5
+
6
+ module ApiClientHelper
7
+ def setup
8
+ @client = Trolley.client(
9
+ ENV.fetch('SANDBOX_API_KEY'),
10
+ ENV.fetch('SANDBOX_SECRET_KEY'),
11
+ api_base: ENV['API_BASE'],
12
+ proxy_uri: ENV['PROXY_URI']
13
+ )
14
+ end
15
+ end
16
+
17
+ def uuid
18
+ SecureRandom.uuid.to_s
19
+ end
@@ -0,0 +1,47 @@
1
+ require_relative '../../lib/trolley'
2
+ require 'test/unit'
3
+
4
+ class ConfigurationTest < Test::Unit::TestCase
5
+ def test_new_nil
6
+ assert_raise ArgumentError.new('Both key/secret must be a nonempty string') do
7
+ Trolley::Configuration.new(nil, nil)
8
+ end
9
+ end
10
+
11
+ def test_new_empty_string
12
+ assert_raise ArgumentError.new('Both key/secret must be a nonempty string') do
13
+ Trolley::Configuration.new('', '')
14
+ end
15
+ end
16
+
17
+ def test_new_nonempty_string
18
+ assert_nothing_raised do
19
+ Trolley::Configuration.new('key', 'secret')
20
+ end
21
+ end
22
+
23
+ def test_api_base
24
+ assert_equal 'https://api.trolley.com', Trolley::Configuration.new('key', 'secret').api_base
25
+ assert_equal 'http://localhost:8080', Trolley::Configuration.new('key', 'secret', api_base: 'http://localhost:8080').api_base
26
+ end
27
+
28
+ def test_use_ssl?
29
+ assert_equal false, Trolley::Configuration.new('key', 'secret', api_base: 'http://example.com').useSsl?
30
+ assert_equal true, Trolley::Configuration.new('key', 'secret').useSsl?
31
+ end
32
+
33
+ def test_invalid_proxy_uri
34
+ proxy_uri = 'not_://*a_valid_proxy'
35
+ assert_raise Trolley::Configuration::InvalidProxyAddress.new("Invalid proxy provided to configuration: #{proxy_uri}") do
36
+ Trolley::Configuration.new('k', 's', proxy_uri: proxy_uri).proxy
37
+ end
38
+ end
39
+
40
+ def test_vaid_proxy_uri
41
+ config = Trolley::Configuration.new('k', 's', proxy_uri: 'http://user:pass@gimmeproxy.com:80')
42
+ assert_equal 'gimmeproxy.com', config.proxy.host
43
+ assert_equal 80, config.proxy.port
44
+ assert_equal 'user', config.proxy.user
45
+ assert_equal 'pass', config.proxy.password
46
+ end
47
+ end
@@ -0,0 +1,23 @@
1
+ require_relative '../../lib/trolley'
2
+ require 'test/unit'
3
+
4
+ class PaginatedArrayTest < Test::Unit::TestCase
5
+ def test_initialize
6
+ paginated_array = Trolley::Utils::PaginatedArray.new([1, 2, 3], 1, 2, 3)
7
+ assert_equal [1, 2, 3], paginated_array
8
+ assert_equal 1, paginated_array.page
9
+ assert_equal 2, paginated_array.pages
10
+ assert_equal 3, paginated_array.records
11
+ end
12
+
13
+ def test_from_response
14
+ response = '{"meta":{"page":1,"pages":2,"records":3},"batches":[{"id":1},{"id":2},{"id":3}]}'
15
+ paginated_array = Trolley::Utils::PaginatedArray.from_response(response, Trolley::Batch)
16
+ assert_equal 3, paginated_array.count
17
+ assert_equal Trolley::Batch, paginated_array.first.class
18
+
19
+ assert_equal 1, paginated_array.page
20
+ assert_equal 2, paginated_array.pages
21
+ assert_equal 3, paginated_array.records
22
+ end
23
+ end
@@ -0,0 +1,26 @@
1
+ require_relative '../../lib/trolley'
2
+ require 'test/unit'
3
+
4
+ class ResponseMapperTest < Test::Unit::TestCase
5
+ def test_build_resource
6
+ response = '{"batch": {"id": 1}}'
7
+ mapper = Trolley::Utils::ResponseMapper.new(response, Trolley::Batch)
8
+ result = mapper.build
9
+
10
+ assert_instance_of Trolley::Batch, result
11
+ assert_equal 1, result.id
12
+ end
13
+
14
+ def test_build_collection
15
+ response = '{"batches": [{"id": 1}, {"id": 2}]}'
16
+ mapper = Trolley::Utils::ResponseMapper.new(response, Trolley::Batch)
17
+ result = mapper.build
18
+
19
+ assert_instance_of Array, result
20
+ assert_equal 2, result.length
21
+ assert_instance_of Trolley::Batch, result[0]
22
+ assert_equal 1, result[0].id
23
+ assert_instance_of Trolley::Batch, result[1]
24
+ assert_equal 2, result[1].id
25
+ end
26
+ end
@@ -0,0 +1,15 @@
1
+ require_relative '../../lib/trolley'
2
+ require 'test/unit'
3
+
4
+ class PaymentRailsTest < Test::Unit::TestCase
5
+ def test_client
6
+ Trolley.client('key', 'secret', proxy_uri: 'http://user:pass@gimmeproxy.com:80')
7
+ end
8
+
9
+ def test_client_invalid_proxy_uri
10
+ proxy_uri = 'not_://*a_valid_proxy'
11
+ assert_raise Trolley::Configuration::InvalidProxyAddress.new("Invalid proxy provided to configuration: #{proxy_uri}") do
12
+ Trolley.client('k', 's', proxy_uri: proxy_uri)
13
+ end
14
+ end
15
+ end
data/trolley.gemspec CHANGED
@@ -1,15 +1,18 @@
1
- $:.push File.expand_path("../lib", __FILE__)
1
+ $:.push File.expand_path('lib', __dir__)
2
2
 
3
3
  Gem::Specification.new do |s|
4
- s.name = "trolley"
5
- s.summary = "Future home of Trolley Ruby SDK"
6
- s.description = "Future home of Trolley Ruby SDK"
7
- s.version = '0.2.14'
8
- s.homepage = 'https://trolley.com/'
9
- s.email = ['developer-tools@trolley.com']
10
- s.homepage = "https://www.trolley.com"
11
- s.license = "MIT"
12
- s.author = "Trolley"
13
- s.files = Dir.glob ["README.rdoc", "LICENSE", "lib/**/*.{rb,crt}", "spec/**/*", "*.gemspec"]
14
- s.required_ruby_version = '>= 2.4'
4
+ s.name = 'trolley'
5
+ s.summary = 'Trolley Ruby SDK'
6
+ s.description = 'Ruby SDK for interacting with the Trolley API'
7
+ s.version = '1.0.1'
8
+ s.homepage = 'https://trolley.com/'
9
+ s.email = ['developer-tools@trolley.com']
10
+ s.license = 'MIT'
11
+ s.author = 'Trolley'
12
+ s.files = Dir.glob ['README.rdoc', 'LICENSE', 'lib/**/*.{rb,crt}', 'spec/**/*', '*.gemspec']
13
+ s.required_ruby_version = '>= 2.7'
14
+ s.add_development_dependency 'dotenv', '~> 2'
15
+ s.add_development_dependency 'rake', '~> 13'
16
+ s.add_development_dependency 'rubocop', '~> 1'
17
+ s.add_development_dependency 'test-unit', '~> 3'
15
18
  end
metadata CHANGED
@@ -1,16 +1,72 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: trolley
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.14
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Trolley
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-03-14 00:00:00.000000000 Z
12
- dependencies: []
13
- description: Future home of Trolley Ruby SDK
11
+ date: 2023-05-01 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: dotenv
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '13'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '13'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rubocop
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1'
55
+ - !ruby/object:Gem::Dependency
56
+ name: test-unit
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3'
69
+ description: Ruby SDK for interacting with the Trolley API
14
70
  email:
15
71
  - developer-tools@trolley.com
16
72
  executables: []
@@ -19,8 +75,41 @@ extra_rdoc_files: []
19
75
  files:
20
76
  - LICENSE
21
77
  - lib/trolley.rb
78
+ - lib/trolley/Balance.rb
79
+ - lib/trolley/Batch.rb
80
+ - lib/trolley/BatchSummary.rb
81
+ - lib/trolley/Client.rb
82
+ - lib/trolley/Configuration.rb
83
+ - lib/trolley/Exceptions.rb
84
+ - lib/trolley/Gateway.rb
85
+ - lib/trolley/Invoice.rb
86
+ - lib/trolley/InvoicePayment.rb
87
+ - lib/trolley/OfflinePayment.rb
88
+ - lib/trolley/Payment.rb
89
+ - lib/trolley/Recipient.rb
90
+ - lib/trolley/RecipientAccount.rb
91
+ - lib/trolley/gateways/BalanceGateway.rb
92
+ - lib/trolley/gateways/BatchGateway.rb
93
+ - lib/trolley/gateways/InvoiceGateway.rb
94
+ - lib/trolley/gateways/InvoicePaymentGateway.rb
95
+ - lib/trolley/gateways/OfflinePaymentGateway.rb
96
+ - lib/trolley/gateways/PaymentGateway.rb
97
+ - lib/trolley/gateways/RecipientAccountGateway.rb
98
+ - lib/trolley/gateways/RecipientGateway.rb
99
+ - lib/trolley/utils/PaginatedArray.rb
100
+ - lib/trolley/utils/ResponseMapper.rb
101
+ - spec/integration/BatchTest.rb
102
+ - spec/integration/InvoicePaymentTest.rb
103
+ - spec/integration/InvoiceTest.rb
104
+ - spec/integration/RecipientAccountTest.rb
105
+ - spec/integration/RecipientTest.rb
106
+ - spec/integration/helper.rb
107
+ - spec/unit/ConfigurationTest.rb
108
+ - spec/unit/PaginatedArrayTest.rb
109
+ - spec/unit/ResponseMapperTest.rb
110
+ - spec/unit/TrolleyTest.rb
22
111
  - trolley.gemspec
23
- homepage: https://www.trolley.com
112
+ homepage: https://trolley.com/
24
113
  licenses:
25
114
  - MIT
26
115
  metadata: {}
@@ -32,7 +121,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
32
121
  requirements:
33
122
  - - ">="
34
123
  - !ruby/object:Gem::Version
35
- version: '2.4'
124
+ version: '2.7'
36
125
  required_rubygems_version: !ruby/object:Gem::Requirement
37
126
  requirements:
38
127
  - - ">="
@@ -42,5 +131,5 @@ requirements: []
42
131
  rubygems_version: 3.2.3
43
132
  signing_key:
44
133
  specification_version: 4
45
- summary: Future home of Trolley Ruby SDK
134
+ summary: Trolley Ruby SDK
46
135
  test_files: []