trolley 1.0.3 → 1.1.0
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.
- checksums.yaml +4 -4
- data/lib/trolley/Client.rb +6 -1
- data/lib/trolley/Gateway.rb +7 -1
- data/lib/trolley/InvoicePayment.rb +6 -1
- data/lib/trolley/OfflinePayment.rb +2 -1
- data/lib/trolley/Payment.rb +4 -1
- data/lib/trolley/Recipient.rb +0 -2
- data/lib/trolley/RecipientAccount.rb +4 -1
- data/lib/trolley/RecipientLog.rb +12 -0
- data/lib/trolley/gateways/BalanceGateway.rb +18 -1
- data/lib/trolley/gateways/PaymentGateway.rb +5 -0
- data/lib/trolley/gateways/RecipientGateway.rb +5 -1
- data/lib/trolley/gateways/VerificationGateway.rb +40 -0
- data/lib/trolley/utils/PaginatedArray.rb +8 -3
- data/lib/trolley/utils/ResponseMapper.rb +1 -0
- data/lib/trolley.rb +3 -1
- data/test/fixtures/BalanceTest/test_find.yml +71 -0
- data/test/fixtures/BalanceTest/test_find_with_term.yml +71 -0
- data/test/fixtures/BatchTest/test_create.yml +150 -0
- data/test/fixtures/BatchTest/test_create_with_payments.yml +541 -0
- data/test/fixtures/BatchTest/test_delete_multiple.yml +209 -0
- data/test/fixtures/BatchTest/test_payments.yml +434 -0
- data/test/fixtures/BatchTest/test_processing.yml +578 -0
- data/test/fixtures/BatchTest/test_summary.yml +440 -0
- data/test/fixtures/BatchTest/test_update.yml +356 -0
- data/test/fixtures/InvoicePaymentTest/test_create.yml +489 -0
- data/test/fixtures/InvoicePaymentTest/test_delete.yml +634 -0
- data/test/fixtures/InvoicePaymentTest/test_find.yml +420 -0
- data/test/fixtures/InvoicePaymentTest/test_update.yml +634 -0
- data/test/fixtures/InvoiceTest/test_create.yml +293 -0
- data/test/fixtures/InvoiceTest/test_create_line.yml +353 -0
- data/test/fixtures/InvoiceTest/test_delete.yml +433 -0
- data/test/fixtures/InvoiceTest/test_delete_line.yml +353 -0
- data/test/fixtures/InvoiceTest/test_find.yml +284 -0
- data/test/fixtures/InvoiceTest/test_search.yml +293 -0
- data/test/fixtures/InvoiceTest/test_support_error_arrays.yml +71 -0
- data/test/fixtures/InvoiceTest/test_update.yml +428 -0
- data/test/fixtures/InvoiceTest/test_update_line.yml +422 -0
- data/test/fixtures/OfflinePaymentTest/test_create.yml +213 -0
- data/test/fixtures/OfflinePaymentTest/test_delete.yml +281 -0
- data/test/fixtures/OfflinePaymentTest/test_search.yml +281 -0
- data/test/fixtures/OfflinePaymentTest/test_update.yml +281 -0
- data/test/fixtures/PaymentTest/test_crud.yml +510 -0
- data/test/fixtures/PaymentTest/test_search.yml +366 -0
- data/test/fixtures/RecipientAccountTest/test_basic_crud.yml +351 -0
- data/test/fixtures/RecipientTest/test_account.yml +499 -0
- data/test/fixtures/RecipientTest/test_create.yml +72 -0
- data/test/fixtures/RecipientTest/test_delete_multiple.yml +347 -0
- data/test/fixtures/RecipientTest/test_find_logs.yml +278 -0
- data/test/fixtures/RecipientTest/test_find_payments.yml +512 -0
- data/test/fixtures/RecipientTest/test_lifecycle.yml +347 -0
- data/test/integration/BalanceTest.rb +22 -0
- data/test/integration/BatchTest.rb +157 -0
- data/test/integration/InvoicePaymentTest.rb +109 -0
- data/test/integration/InvoiceTest.rb +156 -0
- data/test/integration/OfflinePaymentTest.rb +109 -0
- data/test/integration/PaymentTest.rb +73 -0
- data/test/integration/RecipientAccountTest.rb +52 -0
- data/test/integration/RecipientTest.rb +176 -0
- data/test/test_helper.rb +45 -0
- data/test/unit/ClientRequestTest.rb +54 -0
- data/{spec → test}/unit/ConfigurationTest.rb +1 -1
- data/test/unit/GatewayParityTest.rb +184 -0
- data/{spec → test}/unit/PaginatedArrayTest.rb +3 -1
- data/{spec → test}/unit/TrolleyTest.rb +1 -1
- data/trolley.gemspec +10 -7
- metadata +101 -17
- data/spec/integration/BatchTest.rb +0 -126
- data/spec/integration/InvoicePaymentTest.rb +0 -92
- data/spec/integration/InvoiceTest.rb +0 -128
- data/spec/integration/RecipientAccountTest.rb +0 -48
- data/spec/integration/RecipientTest.rb +0 -159
- data/spec/integration/helper.rb +0 -19
- /data/{spec → test}/unit/ResponseMapperTest.rb +0 -0
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
require_relative '../test_helper'
|
|
2
|
+
|
|
3
|
+
class InvoiceTest < Test::Unit::TestCase
|
|
4
|
+
include TestHelper
|
|
5
|
+
|
|
6
|
+
def create_recipient
|
|
7
|
+
uuid = SecureRandom.uuid.to_s
|
|
8
|
+
recipient = @client.recipient.create(
|
|
9
|
+
type: 'individual',
|
|
10
|
+
firstName: 'Tom',
|
|
11
|
+
lastName: 'Jones',
|
|
12
|
+
email: "test.batch#{uuid}@example.com",
|
|
13
|
+
address: {
|
|
14
|
+
street1: '123 Wolfstrasse',
|
|
15
|
+
city: 'Berlin',
|
|
16
|
+
country: 'DE',
|
|
17
|
+
postalCode: '123123'
|
|
18
|
+
}
|
|
19
|
+
)
|
|
20
|
+
@client.recipient_account.create(recipient.id, type: 'bank-transfer', currency: 'EUR', country: 'DE', iban: 'DE89 3704 0044 0532 0130 00')
|
|
21
|
+
recipient
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def test_find
|
|
25
|
+
with_vcr do
|
|
26
|
+
recipient = create_recipient
|
|
27
|
+
invoice = @client.invoice.create(recipientId: recipient.id, description: 'Integration Test Invoice Create')
|
|
28
|
+
find = @client.invoice.find(invoiceId: invoice.id)
|
|
29
|
+
assert_not_nil(find)
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def test_search
|
|
34
|
+
with_vcr do
|
|
35
|
+
recipient = create_recipient
|
|
36
|
+
@client.invoice.create(recipientId: recipient.id, description: 'Integration Test Invoice Create')
|
|
37
|
+
search = @client.invoice.search({})
|
|
38
|
+
assert_true(search.count.positive?)
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def test_create
|
|
43
|
+
with_vcr do
|
|
44
|
+
recipient = create_recipient
|
|
45
|
+
invoice = @client.invoice.create(recipientId: recipient.id, description: 'Integration Test Invoice Create')
|
|
46
|
+
assert_not_nil(invoice)
|
|
47
|
+
assert_not_nil(invoice.id)
|
|
48
|
+
|
|
49
|
+
invoice = @client.invoice.search({})
|
|
50
|
+
assert_true(invoice.count.positive?)
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def test_create_line
|
|
55
|
+
with_vcr do
|
|
56
|
+
recipient = create_recipient
|
|
57
|
+
invoice = @client.invoice.create(recipientId: recipient.id, description: 'Integration Test Invoice Create')
|
|
58
|
+
assert_not_nil(invoice)
|
|
59
|
+
assert_not_nil(invoice.id)
|
|
60
|
+
assert_equal([], invoice.lines)
|
|
61
|
+
|
|
62
|
+
invoice_line = @client.invoice.create_line(invoiceId: invoice.id, lines: [{ unitAmount: { value: '2000', currency: 'USD' } }])
|
|
63
|
+
assert_not_nil(invoice_line.lines)
|
|
64
|
+
assert_not_nil(invoice_line.lines.first['id'])
|
|
65
|
+
|
|
66
|
+
findInvoice = @client.invoice.find(invoiceId: invoice.id)
|
|
67
|
+
assert_true(findInvoice.lines.count.positive?)
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
def test_update
|
|
72
|
+
with_vcr do
|
|
73
|
+
recipient = create_recipient
|
|
74
|
+
invoice = @client.invoice.create(recipientId: recipient.id, description: 'Integration Test Invoice Create')
|
|
75
|
+
assert_not_nil(invoice)
|
|
76
|
+
assert_not_nil(invoice.id)
|
|
77
|
+
|
|
78
|
+
invoices = @client.invoice.search({})
|
|
79
|
+
assert_true(invoices.count.positive?)
|
|
80
|
+
|
|
81
|
+
response = @client.invoice.update(invoiceId: invoice.id, description: 'Integration Test Invoice Update')
|
|
82
|
+
assert_true(response)
|
|
83
|
+
findInvoice = @client.invoice.find(invoiceId: invoice.id)
|
|
84
|
+
assert_equal('Integration Test Invoice Update', findInvoice.description)
|
|
85
|
+
assert_equal('open', findInvoice.status)
|
|
86
|
+
end
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
def test_update_line
|
|
90
|
+
with_vcr do
|
|
91
|
+
recipient = create_recipient
|
|
92
|
+
invoice = @client.invoice.create(recipientId: recipient.id, description: 'Integration Test Invoice Create')
|
|
93
|
+
assert_not_nil(invoice)
|
|
94
|
+
assert_not_nil(invoice.id)
|
|
95
|
+
assert_equal([], invoice.lines)
|
|
96
|
+
|
|
97
|
+
invoice_line = @client.invoice.create_line(invoiceId: invoice.id, lines: [{ unitAmount: { value: '2000', currency: 'USD' } }])
|
|
98
|
+
assert_not_nil(invoice_line.lines)
|
|
99
|
+
assert_not_nil(invoice_line.lines.first['id'])
|
|
100
|
+
|
|
101
|
+
response = @client.invoice.update_line(
|
|
102
|
+
invoiceId: invoice.id,
|
|
103
|
+
lines: [{
|
|
104
|
+
invoiceLineId: invoice_line.lines.first['id'],
|
|
105
|
+
unitAmount: { value: '3000', currency: 'USD' }
|
|
106
|
+
}]
|
|
107
|
+
)
|
|
108
|
+
assert_true(response)
|
|
109
|
+
|
|
110
|
+
findInvoice = @client.invoice.find(invoiceId: invoice.id)
|
|
111
|
+
assert_equal('3000.00', findInvoice.lines.first['unitAmount']['value'])
|
|
112
|
+
end
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
def test_delete
|
|
116
|
+
with_vcr do
|
|
117
|
+
recipient = create_recipient
|
|
118
|
+
invoice = @client.invoice.create(recipientId: recipient.id, description: 'Integration Test Invoice Create')
|
|
119
|
+
assert_not_nil(invoice)
|
|
120
|
+
assert_not_nil(invoice.id)
|
|
121
|
+
|
|
122
|
+
invoices = @client.invoice.search({})
|
|
123
|
+
assert_true(invoices.count.positive?)
|
|
124
|
+
|
|
125
|
+
response = @client.invoice.delete(invoiceIds: invoices.map(&:id))
|
|
126
|
+
assert_true(response)
|
|
127
|
+
end
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
def test_delete_line
|
|
131
|
+
with_vcr do
|
|
132
|
+
recipient = create_recipient
|
|
133
|
+
invoice = @client.invoice.create(recipientId: recipient.id, description: 'Integration Test Invoice Create')
|
|
134
|
+
assert_not_nil(invoice)
|
|
135
|
+
assert_not_nil(invoice.id)
|
|
136
|
+
assert_equal([], invoice.lines)
|
|
137
|
+
|
|
138
|
+
invoice_line = @client.invoice.create_line(invoiceId: invoice.id, lines: [{ unitAmount: { value: '2000', currency: 'USD' } }])
|
|
139
|
+
|
|
140
|
+
response = @client.invoice.delete_line(invoiceId: invoice.id, invoiceLineIds: [invoice_line.lines.first['id']])
|
|
141
|
+
assert_true(response)
|
|
142
|
+
end
|
|
143
|
+
end
|
|
144
|
+
|
|
145
|
+
def test_support_error_arrays
|
|
146
|
+
with_vcr do
|
|
147
|
+
@client.invoice.create(recipientId: 'invalid', description: 'Integration Test Invoice Create')
|
|
148
|
+
rescue ::Trolley::TrolleyError => e
|
|
149
|
+
assert_equal(1, e.validation_errors.count)
|
|
150
|
+
assert_equal('recipientId', e.validation_errors.first['field'])
|
|
151
|
+
assert_equal('Value is invalid', e.validation_errors.first['message'])
|
|
152
|
+
assert_equal('invalid_field', e.validation_errors.first['code'])
|
|
153
|
+
end
|
|
154
|
+
end
|
|
155
|
+
end
|
|
156
|
+
# rubocop:enable Metrics/ClassLength
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
require_relative '../test_helper'
|
|
2
|
+
|
|
3
|
+
class OfflinePaymentTest < Test::Unit::TestCase
|
|
4
|
+
include TestHelper
|
|
5
|
+
|
|
6
|
+
def create_recipient
|
|
7
|
+
uuid = SecureRandom.uuid.to_s
|
|
8
|
+
recipient = @client.recipient.create(
|
|
9
|
+
type: 'individual',
|
|
10
|
+
firstName: 'Tom',
|
|
11
|
+
lastName: 'Jones',
|
|
12
|
+
email: "test.batch#{uuid}@example.com",
|
|
13
|
+
address: {
|
|
14
|
+
street1: '123 Wolfstrasse',
|
|
15
|
+
city: 'Berlin',
|
|
16
|
+
country: 'DE',
|
|
17
|
+
postalCode: '123123'
|
|
18
|
+
}
|
|
19
|
+
)
|
|
20
|
+
@client.recipient_account.create(recipient.id, type: 'bank-transfer', currency: 'EUR', country: 'DE', iban: 'DE89 3704 0044 0532 0130 00')
|
|
21
|
+
recipient
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def test_create
|
|
25
|
+
with_vcr do
|
|
26
|
+
recipient = create_recipient
|
|
27
|
+
offline_payment = @client.offline_payment.create(
|
|
28
|
+
recipient.id,
|
|
29
|
+
{
|
|
30
|
+
amount: '10.00',
|
|
31
|
+
currency: 'EUR'
|
|
32
|
+
}
|
|
33
|
+
)
|
|
34
|
+
|
|
35
|
+
assert_not_nil(offline_payment)
|
|
36
|
+
assert_not_nil(offline_payment.id)
|
|
37
|
+
assert_equal('10.00', offline_payment.amount)
|
|
38
|
+
assert_equal('EUR', offline_payment.currency)
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def test_update
|
|
43
|
+
with_vcr do
|
|
44
|
+
recipient = create_recipient
|
|
45
|
+
offline_payment = @client.offline_payment.create(
|
|
46
|
+
recipient.id,
|
|
47
|
+
{
|
|
48
|
+
amount: '10.00',
|
|
49
|
+
currency: 'EUR',
|
|
50
|
+
category: 'services'
|
|
51
|
+
}
|
|
52
|
+
)
|
|
53
|
+
|
|
54
|
+
assert_not_nil(offline_payment)
|
|
55
|
+
|
|
56
|
+
response = @client.offline_payment.update(
|
|
57
|
+
recipient.id,
|
|
58
|
+
offline_payment.id,
|
|
59
|
+
{
|
|
60
|
+
category: 'royalties'
|
|
61
|
+
}
|
|
62
|
+
)
|
|
63
|
+
|
|
64
|
+
assert_true(response)
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def test_delete
|
|
69
|
+
with_vcr do
|
|
70
|
+
recipient = create_recipient
|
|
71
|
+
offline_payment = @client.offline_payment.create(
|
|
72
|
+
recipient.id,
|
|
73
|
+
{
|
|
74
|
+
amount: '10.00',
|
|
75
|
+
currency: 'EUR',
|
|
76
|
+
category: 'services'
|
|
77
|
+
}
|
|
78
|
+
)
|
|
79
|
+
|
|
80
|
+
assert_not_nil(offline_payment)
|
|
81
|
+
|
|
82
|
+
response = @client.offline_payment.delete(recipient.id, offline_payment.id)
|
|
83
|
+
|
|
84
|
+
assert_true(response)
|
|
85
|
+
end
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
def test_search
|
|
89
|
+
with_vcr do
|
|
90
|
+
recipient = create_recipient
|
|
91
|
+
offline_payment = @client.offline_payment.create(
|
|
92
|
+
recipient.id,
|
|
93
|
+
{
|
|
94
|
+
amount: '10.00',
|
|
95
|
+
currency: 'EUR',
|
|
96
|
+
category: 'services'
|
|
97
|
+
}
|
|
98
|
+
)
|
|
99
|
+
|
|
100
|
+
assert_not_nil(offline_payment)
|
|
101
|
+
|
|
102
|
+
offline_payments = @client.offline_payment.search(
|
|
103
|
+
recipient.id
|
|
104
|
+
)
|
|
105
|
+
|
|
106
|
+
assert_true(offline_payments.count.positive?)
|
|
107
|
+
end
|
|
108
|
+
end
|
|
109
|
+
end
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
require_relative '../test_helper'
|
|
2
|
+
|
|
3
|
+
class PaymentTest < Test::Unit::TestCase
|
|
4
|
+
include TestHelper
|
|
5
|
+
|
|
6
|
+
def recipient
|
|
7
|
+
uuid = SecureRandom.uuid.to_s
|
|
8
|
+
recipient = @client.recipient.create(
|
|
9
|
+
type: 'individual',
|
|
10
|
+
firstName: 'Tom',
|
|
11
|
+
lastName: 'Jones',
|
|
12
|
+
email: "test.batch#{uuid}@example.com",
|
|
13
|
+
address: {
|
|
14
|
+
street1: '123 Wolfstrasse',
|
|
15
|
+
city: 'Berlin',
|
|
16
|
+
country: 'DE',
|
|
17
|
+
postalCode: '123123'
|
|
18
|
+
}
|
|
19
|
+
)
|
|
20
|
+
@client.recipient_account.create(recipient.id, type: 'bank-transfer', currency: 'EUR', country: 'DE', iban: 'DE89 3704 0044 0532 0130 00')
|
|
21
|
+
recipient
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def batch
|
|
25
|
+
@batch ||= @client.batch.create(sourceCurrency: 'USD', description: 'Integration Test Create')
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def test_crud
|
|
29
|
+
with_vcr do
|
|
30
|
+
payment = @client.payment.create(
|
|
31
|
+
batch.id,
|
|
32
|
+
sourceAmount: '10.00',
|
|
33
|
+
sourceCurrency: 'USD',
|
|
34
|
+
recipient: { id: recipient.id }
|
|
35
|
+
)
|
|
36
|
+
|
|
37
|
+
assert_not_nil(payment)
|
|
38
|
+
assert_not_nil(payment.id)
|
|
39
|
+
assert_equal('10.00', payment.sourceAmount)
|
|
40
|
+
assert_equal('USD', payment.sourceCurrency)
|
|
41
|
+
|
|
42
|
+
payment = @client.payment.find(batch.id, payment.id)
|
|
43
|
+
assert_not_nil(payment)
|
|
44
|
+
|
|
45
|
+
update_response = @client.payment.update(
|
|
46
|
+
batch.id,
|
|
47
|
+
payment.id,
|
|
48
|
+
sourceAmount: '20.00',
|
|
49
|
+
sourceCurrency: 'USD'
|
|
50
|
+
)
|
|
51
|
+
|
|
52
|
+
assert_not_nil(update_response)
|
|
53
|
+
|
|
54
|
+
response = @client.payment.delete(batch.id, payment.id)
|
|
55
|
+
assert_true(response)
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def test_search
|
|
60
|
+
with_vcr do
|
|
61
|
+
@client.payment.create(
|
|
62
|
+
batch.id,
|
|
63
|
+
sourceAmount: '10.00',
|
|
64
|
+
sourceCurrency: 'USD',
|
|
65
|
+
recipient: { id: recipient.id }
|
|
66
|
+
)
|
|
67
|
+
|
|
68
|
+
result = @client.payment.search(batch.id)
|
|
69
|
+
assert_not_nil(result)
|
|
70
|
+
assert_true(result.count.positive?)
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
end
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
require_relative '../test_helper'
|
|
2
|
+
|
|
3
|
+
class RecipientAccountTest < Test::Unit::TestCase
|
|
4
|
+
include TestHelper
|
|
5
|
+
|
|
6
|
+
# rubocop:disable Metrics/MethodLength
|
|
7
|
+
# rubocop:disable Metrics/BlockLength
|
|
8
|
+
def test_basic_crud
|
|
9
|
+
with_vcr do
|
|
10
|
+
recipient = @client.recipient.create(
|
|
11
|
+
type: 'individual',
|
|
12
|
+
firstName: 'Tom',
|
|
13
|
+
lastName: 'Jones',
|
|
14
|
+
email: "test.create#{uuid}@example.com"
|
|
15
|
+
)
|
|
16
|
+
recipient_account = @client.recipient_account.create(
|
|
17
|
+
recipient.id, type: 'bank-transfer',
|
|
18
|
+
currency: 'EUR',
|
|
19
|
+
country: 'DE',
|
|
20
|
+
iban: 'DE89 3704 0044 0532 0130 00'
|
|
21
|
+
)
|
|
22
|
+
|
|
23
|
+
assert_not_nil(recipient_account)
|
|
24
|
+
assert_equal(recipient_account.type, 'bank-transfer')
|
|
25
|
+
assert_equal(recipient_account.currency, 'EUR')
|
|
26
|
+
|
|
27
|
+
recipient_account = @client.recipient_account.update(
|
|
28
|
+
recipient.id, recipient_account.id,
|
|
29
|
+
primary: true
|
|
30
|
+
)
|
|
31
|
+
|
|
32
|
+
assert_not_nil(recipient_account)
|
|
33
|
+
assert_equal(recipient_account.type, 'bank-transfer')
|
|
34
|
+
assert_equal(recipient_account.currency, 'EUR')
|
|
35
|
+
assert_equal(recipient_account.primary, true)
|
|
36
|
+
|
|
37
|
+
recipient_account = @client.recipient_account.find(
|
|
38
|
+
recipient.id, recipient_account.id
|
|
39
|
+
)
|
|
40
|
+
|
|
41
|
+
assert_not_nil(recipient_account)
|
|
42
|
+
|
|
43
|
+
response = @client.recipient_account.delete(
|
|
44
|
+
recipient.id, recipient_account.id
|
|
45
|
+
)
|
|
46
|
+
|
|
47
|
+
assert_true(response)
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
# rubocop:enable Metrics/MethodLength
|
|
51
|
+
# rubocop:enable Metrics/BlockLength
|
|
52
|
+
end
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
require_relative '../test_helper'
|
|
2
|
+
|
|
3
|
+
# rubocop:disable Metrics/MethodLength
|
|
4
|
+
# rubocop:disable Metrics/BlockLength
|
|
5
|
+
class RecipientTest < Test::Unit::TestCase
|
|
6
|
+
include TestHelper
|
|
7
|
+
|
|
8
|
+
def test_create
|
|
9
|
+
with_vcr do
|
|
10
|
+
response = @client.recipient.create(
|
|
11
|
+
type: 'individual',
|
|
12
|
+
firstName: 'Tom',
|
|
13
|
+
lastName: 'Jones',
|
|
14
|
+
email: "test.create#{uuid}@example.com"
|
|
15
|
+
)
|
|
16
|
+
assert_not_nil(response)
|
|
17
|
+
assert_equal(response.firstName, 'Tom')
|
|
18
|
+
assert_equal(response.lastName, 'Jones')
|
|
19
|
+
assert_not_nil(response.id)
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def test_lifecycle
|
|
24
|
+
with_vcr do
|
|
25
|
+
recipient = @client.recipient.create(
|
|
26
|
+
type: 'individual',
|
|
27
|
+
firstName: 'Tom',
|
|
28
|
+
lastName: 'Jones',
|
|
29
|
+
email: "test.create#{uuid}@example.com"
|
|
30
|
+
)
|
|
31
|
+
assert_not_nil(recipient)
|
|
32
|
+
assert_equal(recipient.firstName, 'Tom')
|
|
33
|
+
assert_equal(recipient.status, 'incomplete')
|
|
34
|
+
|
|
35
|
+
response = @client.recipient.update(recipient.id, firstName: 'Bob')
|
|
36
|
+
assert_true(response)
|
|
37
|
+
|
|
38
|
+
recipient = @client.recipient.find(recipient.id)
|
|
39
|
+
assert_equal(recipient.firstName, 'Bob')
|
|
40
|
+
|
|
41
|
+
response = @client.recipient.delete(recipient.id)
|
|
42
|
+
assert_true(response)
|
|
43
|
+
|
|
44
|
+
recipient = @client.recipient.find(recipient.id)
|
|
45
|
+
assert_equal(recipient.status, 'archived')
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def test_account
|
|
50
|
+
with_vcr do
|
|
51
|
+
recipient = @client.recipient.create(
|
|
52
|
+
type: 'individual',
|
|
53
|
+
firstName: 'Tom',
|
|
54
|
+
lastName: 'Jones',
|
|
55
|
+
email: "test.create#{uuid}@example.com",
|
|
56
|
+
address: {
|
|
57
|
+
street1: '123 Wolfstrasse',
|
|
58
|
+
city: 'Berlin',
|
|
59
|
+
country: 'DE',
|
|
60
|
+
postalCode: '123123'
|
|
61
|
+
}
|
|
62
|
+
)
|
|
63
|
+
assert_not_nil(recipient)
|
|
64
|
+
assert_equal(recipient.firstName, 'Tom')
|
|
65
|
+
assert_equal(recipient.lastName, 'Jones')
|
|
66
|
+
assert_not_nil(recipient.id)
|
|
67
|
+
assert_true(recipient.routeMinimum.to_i >= 0)
|
|
68
|
+
|
|
69
|
+
account = @client.recipient_account.create(recipient.id, type: 'bank-transfer', currency: 'EUR', country: 'DE', iban: 'DE89 3704 0044 0532 0130 00')
|
|
70
|
+
assert_not_nil(account)
|
|
71
|
+
|
|
72
|
+
account = @client.recipient_account.create(recipient.id, type: 'bank-transfer', currency: 'EUR', country: 'FR', iban: 'FR14 2004 1010 0505 0001 3M02 606')
|
|
73
|
+
assert_not_nil(account)
|
|
74
|
+
|
|
75
|
+
findAccount = @client.recipient_account.find(recipient.id, account.id)
|
|
76
|
+
assert_equal(account.id, findAccount.id)
|
|
77
|
+
|
|
78
|
+
accountList = @client.recipient_account.all(recipient.id)
|
|
79
|
+
assert_equal(2, accountList.count)
|
|
80
|
+
assert_equal(accountList[0].currency, 'EUR')
|
|
81
|
+
|
|
82
|
+
result = @client.recipient_account.delete(recipient.id, account.id)
|
|
83
|
+
assert_true(result)
|
|
84
|
+
|
|
85
|
+
accountList = @client.recipient_account.all(recipient.id)
|
|
86
|
+
assert_equal(1, accountList.count)
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
def test_delete_multiple
|
|
91
|
+
with_vcr do
|
|
92
|
+
recipient1 = @client.recipient.create(
|
|
93
|
+
type: 'individual',
|
|
94
|
+
firstName: 'Tom',
|
|
95
|
+
lastName: 'Jones',
|
|
96
|
+
email: "test.create#{uuid}@example.com"
|
|
97
|
+
)
|
|
98
|
+
assert_not_nil(recipient1)
|
|
99
|
+
assert_equal(recipient1.firstName, 'Tom')
|
|
100
|
+
assert_equal(recipient1.status, 'incomplete')
|
|
101
|
+
|
|
102
|
+
recipient2 = @client.recipient.create(
|
|
103
|
+
type: 'individual',
|
|
104
|
+
firstName: 'Tom',
|
|
105
|
+
lastName: 'Jones',
|
|
106
|
+
email: "test.create#{uuid}@example.com"
|
|
107
|
+
)
|
|
108
|
+
assert_not_nil(recipient2)
|
|
109
|
+
assert_equal(recipient2.firstName, 'Tom')
|
|
110
|
+
assert_equal(recipient2.status, 'incomplete')
|
|
111
|
+
|
|
112
|
+
response = @client.recipient.delete([recipient1.id, recipient2.id])
|
|
113
|
+
assert_true(response)
|
|
114
|
+
|
|
115
|
+
recipient1 = @client.recipient.find(recipient1.id)
|
|
116
|
+
assert_equal(recipient1.status, 'archived')
|
|
117
|
+
|
|
118
|
+
recipient2 = @client.recipient.find(recipient2.id)
|
|
119
|
+
assert_equal(recipient2.status, 'archived')
|
|
120
|
+
end
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
def test_find_logs
|
|
124
|
+
with_vcr do
|
|
125
|
+
recipient = @client.recipient.create(
|
|
126
|
+
type: 'individual',
|
|
127
|
+
firstName: 'Tom',
|
|
128
|
+
lastName: 'Jones',
|
|
129
|
+
email: "test.create#{uuid}@example.com"
|
|
130
|
+
)
|
|
131
|
+
assert_not_nil(recipient)
|
|
132
|
+
assert_equal(recipient.firstName, 'Tom')
|
|
133
|
+
assert_equal(recipient.status, 'incomplete')
|
|
134
|
+
|
|
135
|
+
@client.recipient.update(recipient.id, firstName: 'John')
|
|
136
|
+
logs = @client.recipient.find_logs(recipient.id)
|
|
137
|
+
|
|
138
|
+
assert_equal(Trolley::Utils::PaginatedArray, logs.class)
|
|
139
|
+
assert_equal(1, logs.page)
|
|
140
|
+
assert_equal('create', logs.first.type)
|
|
141
|
+
assert_boolean(true, @client.recipient.delete(recipient.id))
|
|
142
|
+
end
|
|
143
|
+
end
|
|
144
|
+
|
|
145
|
+
def test_find_payments
|
|
146
|
+
with_vcr do
|
|
147
|
+
recipient = @client.recipient.create(
|
|
148
|
+
type: 'individual',
|
|
149
|
+
firstName: 'Tom',
|
|
150
|
+
lastName: 'Jones',
|
|
151
|
+
email: "test.create#{uuid}@example.com"
|
|
152
|
+
)
|
|
153
|
+
recipient_account = @client.recipient_account.create(recipient.id, type: 'bank-transfer', currency: 'EUR', country: 'DE', iban: 'DE89 3704 0044 0532 0130 00')
|
|
154
|
+
|
|
155
|
+
batch = @client.batch.create(
|
|
156
|
+
sourceCurrency: 'USD', description: 'Integration Test Payments', payments: [
|
|
157
|
+
{ targetAmount: '10.00', targetCurrency: 'EUR', recipient: { id: recipient.id } },
|
|
158
|
+
{ sourceAmount: '10.00', recipient: { id: recipient.id } }
|
|
159
|
+
]
|
|
160
|
+
)
|
|
161
|
+
|
|
162
|
+
payments = @client.recipient.find_payments(recipient.id)
|
|
163
|
+
assert_equal(payments.count, 2)
|
|
164
|
+
assert_equal(payments[0].recipient['id'], recipient.id)
|
|
165
|
+
assert_equal(payments[1].recipient['id'], recipient.id)
|
|
166
|
+
assert_equal(payments.map(&:amount), ['10.00', '10.00'])
|
|
167
|
+
|
|
168
|
+
assert_boolean(true, @client.batch.delete(batch.id))
|
|
169
|
+
assert_boolean(true, @client.recipient_account.delete(recipient.id, recipient_account.id))
|
|
170
|
+
assert_boolean(true, @client.recipient.delete(recipient.id))
|
|
171
|
+
end
|
|
172
|
+
end
|
|
173
|
+
end
|
|
174
|
+
# rubocop:enable Metrics/ClassLength
|
|
175
|
+
# rubocop:enable Metrics/MethodLength
|
|
176
|
+
# rubocop:enable Metrics/BlockLength
|
data/test/test_helper.rb
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
require 'simplecov'
|
|
2
|
+
|
|
3
|
+
SimpleCov.start do
|
|
4
|
+
add_filter '/test/'
|
|
5
|
+
coverage_dir 'coverage'
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
require_relative '../lib/trolley'
|
|
9
|
+
require 'dotenv/load'
|
|
10
|
+
require 'test/unit'
|
|
11
|
+
require 'securerandom'
|
|
12
|
+
require 'webmock/test_unit'
|
|
13
|
+
require 'vcr'
|
|
14
|
+
|
|
15
|
+
module TestHelper
|
|
16
|
+
def setup
|
|
17
|
+
@fixture_test_path = "test/fixtures/#{self.class.name.split('::').last}"
|
|
18
|
+
@test_case = method_name.chomp('_')
|
|
19
|
+
|
|
20
|
+
@client = Trolley.client(
|
|
21
|
+
ENV.fetch('SANDBOX_API_KEY'),
|
|
22
|
+
ENV.fetch('SANDBOX_SECRET_KEY'),
|
|
23
|
+
api_base: ENV['API_BASE'],
|
|
24
|
+
proxy_uri: ENV['PROXY_URI']
|
|
25
|
+
)
|
|
26
|
+
|
|
27
|
+
VCR.configure do |config|
|
|
28
|
+
config.cassette_library_dir = @fixture_test_path
|
|
29
|
+
config.hook_into :webmock
|
|
30
|
+
|
|
31
|
+
config.before_record do |interaction|
|
|
32
|
+
interaction.request.headers.delete('Authorization')
|
|
33
|
+
interaction.request.headers.delete('Trolley-Source')
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def uuid
|
|
39
|
+
SecureRandom.uuid.to_s
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def with_vcr(&block)
|
|
43
|
+
VCR.use_cassette(@test_case, &block)
|
|
44
|
+
end
|
|
45
|
+
end
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
require_relative '../../lib/trolley'
|
|
2
|
+
require 'test/unit'
|
|
3
|
+
require 'webmock/test_unit'
|
|
4
|
+
|
|
5
|
+
class ClientRequestTest < Test::Unit::TestCase
|
|
6
|
+
def setup
|
|
7
|
+
@config = Trolley::Configuration.new('key', 'secret', api_base: 'http://api.local.dev:3000')
|
|
8
|
+
@client = Trolley::Client.new(@config)
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def test_request_posts_json_body_with_signed_headers
|
|
12
|
+
stub_request(:post, 'http://api.local.dev:3000/v1/recipients')
|
|
13
|
+
.with(
|
|
14
|
+
body: '{"type":"individual"}',
|
|
15
|
+
headers: {
|
|
16
|
+
'Authorization' => /^prsign key:/,
|
|
17
|
+
'Content-Type' => 'application/json',
|
|
18
|
+
'Trolley-Source' => "ruby-sdk_#{Trolley::VERSION}"
|
|
19
|
+
}
|
|
20
|
+
)
|
|
21
|
+
.to_return(status: 201, body: '{"ok":true}')
|
|
22
|
+
|
|
23
|
+
response = @client.request('POST', '/v1/recipients', type: 'individual')
|
|
24
|
+
|
|
25
|
+
assert_equal '{"ok":true}', response
|
|
26
|
+
assert_requested :post, 'http://api.local.dev:3000/v1/recipients'
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def test_request_delete_supports_json_body
|
|
30
|
+
stub_request(:delete, 'http://api.local.dev:3000/v1/recipients')
|
|
31
|
+
.with(body: '{"ids":["R-123"]}')
|
|
32
|
+
.to_return(status: 200, body: '{"ok":true}')
|
|
33
|
+
|
|
34
|
+
@client.request('DELETE', '/v1/recipients', ids: ['R-123'])
|
|
35
|
+
|
|
36
|
+
assert_requested :delete, 'http://api.local.dev:3000/v1/recipients'
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def test_request_accepts_204_response
|
|
40
|
+
stub_request(:delete, 'http://api.local.dev:3000/v1/recipients/R-123')
|
|
41
|
+
.to_return(status: 204, body: '')
|
|
42
|
+
|
|
43
|
+
assert_nil @client.request('DELETE', '/v1/recipients/R-123')
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def test_gateway_exposes_request_without_changing_existing_accessors
|
|
47
|
+
gateway = Trolley.client('key', 'secret', api_base: 'http://api.local.dev:3000')
|
|
48
|
+
|
|
49
|
+
assert_respond_to gateway, :request
|
|
50
|
+
assert_respond_to gateway, :recipient
|
|
51
|
+
assert_respond_to gateway, :batch
|
|
52
|
+
assert_respond_to gateway, :invoice
|
|
53
|
+
end
|
|
54
|
+
end
|
|
@@ -33,7 +33,7 @@ class ConfigurationTest < Test::Unit::TestCase
|
|
|
33
33
|
def test_invalid_proxy_uri
|
|
34
34
|
proxy_uri = 'not_://*a_valid_proxy'
|
|
35
35
|
assert_raise Trolley::Configuration::InvalidProxyAddress.new("Invalid proxy provided to configuration: #{proxy_uri}") do
|
|
36
|
-
Trolley::Configuration.new('k', 's', proxy_uri:
|
|
36
|
+
Trolley::Configuration.new('k', 's', proxy_uri:).proxy
|
|
37
37
|
end
|
|
38
38
|
end
|
|
39
39
|
|