paymentrails-zero 0.2.13
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE +22 -0
- data/lib/paymentrails/Balance.rb +4 -0
- data/lib/paymentrails/Batch.rb +20 -0
- data/lib/paymentrails/BatchSummary.rb +21 -0
- data/lib/paymentrails/Client.rb +100 -0
- data/lib/paymentrails/Configuration.rb +48 -0
- data/lib/paymentrails/Exceptions.rb +19 -0
- data/lib/paymentrails/Gateway.rb +43 -0
- data/lib/paymentrails/Invoice.rb +22 -0
- data/lib/paymentrails/InvoicePayment.rb +13 -0
- data/lib/paymentrails/OfflinePayment.rb +23 -0
- data/lib/paymentrails/Payment.rb +52 -0
- data/lib/paymentrails/Recipient.rb +44 -0
- data/lib/paymentrails/RecipientAccount.rb +30 -0
- data/lib/paymentrails/gateways/BalanceGateway.rb +15 -0
- data/lib/paymentrails/gateways/BatchGateway.rb +88 -0
- data/lib/paymentrails/gateways/GatewayHelper.rb +16 -0
- data/lib/paymentrails/gateways/InvoiceGateway.rb +77 -0
- data/lib/paymentrails/gateways/InvoicePaymentGateway.rb +56 -0
- data/lib/paymentrails/gateways/OfflinePaymentGateway.rb +61 -0
- data/lib/paymentrails/gateways/PaymentGateway.rb +61 -0
- data/lib/paymentrails/gateways/RecipientAccountGateway.rb +61 -0
- data/lib/paymentrails/gateways/RecipientGateway.rb +68 -0
- data/lib/paymentrails.rb +28 -0
- data/paymentrails.gemspec +18 -0
- data/spec/integration/BatchTest.rb +121 -0
- data/spec/integration/InvoicePaymentTest.rb +99 -0
- data/spec/integration/InvoiceTest.rb +124 -0
- data/spec/integration/RecipientTest.rb +91 -0
- data/spec/integration/helper.rb +4 -0
- data/spec/unit/ConfigurationTest.rb +51 -0
- data/spec/unit/PaymentRailsTest.rb +15 -0
- metadata +131 -0
@@ -0,0 +1,124 @@
|
|
1
|
+
require_relative 'helper'
|
2
|
+
|
3
|
+
class InvoiceTest < Test::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
@client = PaymentRails.client(
|
6
|
+
ENV.fetch('SANDBOX_API_KEY'),
|
7
|
+
ENV.fetch('SANDBOX_SECRET_KEY'),
|
8
|
+
'production',
|
9
|
+
proxy_uri: ENV['PROXY_URI']
|
10
|
+
)
|
11
|
+
end
|
12
|
+
|
13
|
+
def create_recipient
|
14
|
+
uuid = SecureRandom.uuid.to_s
|
15
|
+
recipient = @client.recipient.create(
|
16
|
+
type: 'individual',
|
17
|
+
firstName: 'Tom',
|
18
|
+
lastName: 'Jones',
|
19
|
+
email: 'test.batch' + uuid + '@example.com',
|
20
|
+
address: {
|
21
|
+
street1: '123 Wolfstrasse',
|
22
|
+
city: 'Berlin',
|
23
|
+
country: 'DE',
|
24
|
+
postalCode: '123123'
|
25
|
+
}
|
26
|
+
)
|
27
|
+
@client.recipient_account.create(recipient.id, type: 'bank-transfer', currency: 'EUR', country: 'DE', iban: 'DE89 3704 0044 0532 0130 00')
|
28
|
+
recipient
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_create
|
32
|
+
recipient = create_recipient
|
33
|
+
invoice = @client.invoice.create(recipientId: recipient.id, description: 'Integration Test Invoice Create')
|
34
|
+
assert_not_nil(invoice)
|
35
|
+
assert_not_nil(invoice.id)
|
36
|
+
|
37
|
+
invoice = @client.invoice.search({})
|
38
|
+
assert_true(invoice.count > 0)
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_create_line
|
42
|
+
recipient = create_recipient
|
43
|
+
invoice = @client.invoice.create(recipientId: recipient.id, description: 'Integration Test Invoice Create')
|
44
|
+
assert_not_nil(invoice)
|
45
|
+
assert_not_nil(invoice.id)
|
46
|
+
assert_equal([], invoice.lines)
|
47
|
+
|
48
|
+
invoice_line = @client.invoice.create_line(invoiceId: invoice.id, lines: [{ unitAmount: { value: '2000', currency: 'USD' } }])
|
49
|
+
assert_not_nil(invoice_line.lines)
|
50
|
+
assert_not_nil(invoice_line.lines.first['id'])
|
51
|
+
|
52
|
+
findInvoice = @client.invoice.find(invoiceId: invoice.id)
|
53
|
+
assert_true(findInvoice.lines.count > 0)
|
54
|
+
end
|
55
|
+
|
56
|
+
def test_update
|
57
|
+
recipient = create_recipient
|
58
|
+
invoice = @client.invoice.create(recipientId: recipient.id, description: 'Integration Test Invoice Create')
|
59
|
+
assert_not_nil(invoice)
|
60
|
+
assert_not_nil(invoice.id)
|
61
|
+
|
62
|
+
invoices = @client.invoice.search({})
|
63
|
+
assert_true(invoices.count > 0)
|
64
|
+
|
65
|
+
response = @client.invoice.update(invoiceId: invoice.id, description: 'Integration Test Invoice Update')
|
66
|
+
assert_true(response)
|
67
|
+
findInvoice = @client.invoice.find(invoiceId: invoice.id)
|
68
|
+
assert_equal('Integration Test Invoice Update', findInvoice.description)
|
69
|
+
assert_equal('open', findInvoice.status)
|
70
|
+
end
|
71
|
+
|
72
|
+
def test_update_line
|
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
|
+
assert_equal([], invoice.lines)
|
78
|
+
|
79
|
+
invoice_line = @client.invoice.create_line(invoiceId: invoice.id, lines: [{ unitAmount: { value: '2000', currency: 'USD' } }])
|
80
|
+
assert_not_nil(invoice_line.lines)
|
81
|
+
assert_not_nil(invoice_line.lines.first['id'])
|
82
|
+
|
83
|
+
response = @client.invoice.update_line(
|
84
|
+
invoiceId: invoice.id,
|
85
|
+
lines: [{
|
86
|
+
invoiceLineId: invoice_line.lines.first['id'],
|
87
|
+
unitAmount: { value: '3000', currency: 'USD' }
|
88
|
+
}]
|
89
|
+
)
|
90
|
+
assert_true(response)
|
91
|
+
|
92
|
+
findInvoice = @client.invoice.find(invoiceId: invoice.id)
|
93
|
+
assert_equal('3000.00', findInvoice.lines.first['unitAmount']['value'])
|
94
|
+
end
|
95
|
+
|
96
|
+
def test_delete
|
97
|
+
recipient = create_recipient
|
98
|
+
invoice = @client.invoice.create(recipientId: recipient.id, description: 'Integration Test Invoice Create')
|
99
|
+
assert_not_nil(invoice)
|
100
|
+
assert_not_nil(invoice.id)
|
101
|
+
|
102
|
+
invoices = @client.invoice.search({})
|
103
|
+
assert_true(invoices.count > 0)
|
104
|
+
|
105
|
+
response = @client.invoice.delete(invoiceIds: invoices.map(&:id))
|
106
|
+
assert_true(response)
|
107
|
+
|
108
|
+
final_invoices = @client.invoice.search({})
|
109
|
+
assert_true(final_invoices.count == 0)
|
110
|
+
end
|
111
|
+
|
112
|
+
def test_delete_line
|
113
|
+
recipient = create_recipient
|
114
|
+
invoice = @client.invoice.create(recipientId: recipient.id, description: 'Integration Test Invoice Create')
|
115
|
+
assert_not_nil(invoice)
|
116
|
+
assert_not_nil(invoice.id)
|
117
|
+
assert_equal([], invoice.lines)
|
118
|
+
|
119
|
+
invoice_line = @client.invoice.create_line(invoiceId: invoice.id, lines: [{ unitAmount: { value: '2000', currency: 'USD' } }])
|
120
|
+
|
121
|
+
response = @client.invoice.delete_line(invoiceId: invoice.id, invoiceLineIds: [invoice_line.lines.first['id']])
|
122
|
+
assert_true(response)
|
123
|
+
end
|
124
|
+
end
|
@@ -0,0 +1,91 @@
|
|
1
|
+
require_relative 'helper'
|
2
|
+
|
3
|
+
class RecipientTest < Test::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
@client = PaymentRails.client(
|
6
|
+
ENV.fetch('SANDBOX_API_KEY'),
|
7
|
+
ENV.fetch('SANDBOX_SECRET_KEY'),
|
8
|
+
'production',
|
9
|
+
proxy_uri: ENV['PROXY_URI']
|
10
|
+
)
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_create
|
14
|
+
uuid = SecureRandom.uuid.to_s
|
15
|
+
response = @client.recipient.create(
|
16
|
+
type: 'individual',
|
17
|
+
firstName: 'Tom',
|
18
|
+
lastName: 'Jones',
|
19
|
+
email: 'test.create' + uuid + '@example.com'
|
20
|
+
)
|
21
|
+
assert_not_nil(response)
|
22
|
+
assert_equal(response.firstName, 'Tom')
|
23
|
+
assert_equal(response.lastName, 'Jones')
|
24
|
+
assert_not_nil(response.id)
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_lifecycle
|
28
|
+
uuid = SecureRandom.uuid.to_s
|
29
|
+
recipient = @client.recipient.create(
|
30
|
+
type: 'individual',
|
31
|
+
firstName: 'Tom',
|
32
|
+
lastName: 'Jones',
|
33
|
+
email: 'test.create' + uuid + '@example.com'
|
34
|
+
)
|
35
|
+
assert_not_nil(recipient)
|
36
|
+
assert_equal(recipient.firstName, 'Tom')
|
37
|
+
assert_equal(recipient.status, 'incomplete')
|
38
|
+
|
39
|
+
response = @client.recipient.update(recipient.id, firstName: 'Bob')
|
40
|
+
assert_true(response)
|
41
|
+
|
42
|
+
recipient = @client.recipient.find(recipient.id)
|
43
|
+
assert_equal(recipient.firstName, 'Bob')
|
44
|
+
|
45
|
+
response = @client.recipient.delete(recipient.id)
|
46
|
+
assert_true(response)
|
47
|
+
|
48
|
+
recipient = @client.recipient.find(recipient.id)
|
49
|
+
assert_equal(recipient.status, 'archived')
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_account
|
53
|
+
uuid = SecureRandom.uuid.to_s
|
54
|
+
recipient = @client.recipient.create(
|
55
|
+
type: 'individual',
|
56
|
+
firstName: 'Tom',
|
57
|
+
lastName: 'Jones',
|
58
|
+
email: 'test.create' + uuid + '@example.com',
|
59
|
+
address: {
|
60
|
+
street1: '123 Wolfstrasse',
|
61
|
+
city: 'Berlin',
|
62
|
+
country: 'DE',
|
63
|
+
postalCode: '123123'
|
64
|
+
}
|
65
|
+
)
|
66
|
+
assert_not_nil(recipient)
|
67
|
+
assert_equal(recipient.firstName, 'Tom')
|
68
|
+
assert_equal(recipient.lastName, 'Jones')
|
69
|
+
assert_not_nil(recipient.id)
|
70
|
+
assert_true(recipient.routeMinimum.to_i >= 0)
|
71
|
+
|
72
|
+
account = @client.recipient_account.create(recipient.id, type: 'bank-transfer', currency: 'EUR', country: 'DE', iban: 'DE89 3704 0044 0532 0130 00')
|
73
|
+
assert_not_nil(account)
|
74
|
+
|
75
|
+
account = @client.recipient_account.create(recipient.id, type: 'bank-transfer', currency: 'EUR', country: 'FR', iban: 'FR14 2004 1010 0505 0001 3M02 606')
|
76
|
+
assert_not_nil(account)
|
77
|
+
|
78
|
+
findAccount = @client.recipient_account.find(recipient.id, account.id)
|
79
|
+
assert_equal(account.id, findAccount.id)
|
80
|
+
|
81
|
+
accountList = @client.recipient_account.all(recipient.id)
|
82
|
+
assert_equal(2, accountList.count)
|
83
|
+
assert_equal(accountList[0].currency, 'EUR')
|
84
|
+
|
85
|
+
result = @client.recipient_account.delete(recipient.id, account.id)
|
86
|
+
assert_true(result)
|
87
|
+
|
88
|
+
accountList = @client.recipient_account.all(recipient.id)
|
89
|
+
assert_equal(1, accountList.count)
|
90
|
+
end
|
91
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require_relative '../../lib/paymentrails'
|
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
|
+
PaymentRails::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
|
+
PaymentRails::Configuration.new('', '')
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_new_nonempty_string
|
18
|
+
assert_nothing_raised do
|
19
|
+
PaymentRails::Configuration.new('key', 'secret')
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_api_base
|
24
|
+
assert_equal 'http://api.local.dev:3000', PaymentRails::Configuration.new('key', 'secret', 'integration').apiBase
|
25
|
+
assert_equal 'https://api.trolley.com', PaymentRails::Configuration.new('key', 'secret', 'production').apiBase
|
26
|
+
assert_equal 'https://api.railz.io', PaymentRails::Configuration.new('key', 'secret', 'development').apiBase
|
27
|
+
assert_equal 'https://api.trolley.com', PaymentRails::Configuration.new('key', 'secret', 'non_standard_environment').apiBase
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_use_ssl?
|
31
|
+
assert_equal false, PaymentRails::Configuration.new('key', 'secret', 'integration').useSsl?
|
32
|
+
assert_equal true, PaymentRails::Configuration.new('key', 'secret', 'production').useSsl?
|
33
|
+
assert_equal true, PaymentRails::Configuration.new('key', 'secret', 'development').useSsl?
|
34
|
+
assert_equal true, PaymentRails::Configuration.new('key', 'secret', 'non_standard_environment').useSsl?
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_invalid_proxy_uri
|
38
|
+
proxy_uri = 'not_://*a_valid_proxy'
|
39
|
+
assert_raise PaymentRails::Configuration::InvalidProxyAddress.new("Invalid proxy provided to configuration: #{proxy_uri}") do
|
40
|
+
PaymentRails::Configuration.new('k', 's', 'production', proxy_uri: proxy_uri).proxy
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_vaid_proxy_uri
|
45
|
+
config = PaymentRails::Configuration.new('k', 's', 'production', proxy_uri: 'http://user:pass@gimmeproxy.com:80')
|
46
|
+
assert_equal 'gimmeproxy.com', config.proxy.host
|
47
|
+
assert_equal 80, config.proxy.port
|
48
|
+
assert_equal 'user', config.proxy.user
|
49
|
+
assert_equal 'pass', config.proxy.password
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require_relative '../../lib/paymentrails'
|
2
|
+
require 'test/unit'
|
3
|
+
|
4
|
+
class PaymentRailsTest < Test::Unit::TestCase
|
5
|
+
def test_client
|
6
|
+
PaymentRails.client('key', 'secret', 'environment', 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 PaymentRails::Configuration::InvalidProxyAddress.new("Invalid proxy provided to configuration: #{proxy_uri}") do
|
12
|
+
PaymentRails.client('k', 's', 'production', proxy_uri: proxy_uri)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
metadata
ADDED
@@ -0,0 +1,131 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: paymentrails-zero
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.13
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- PaymentRails
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2023-09-08 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: '12'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '12'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rubocop
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 0.77.0
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 0.77.0
|
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
|
70
|
+
email:
|
71
|
+
- developer-tools@trolley.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- LICENSE
|
77
|
+
- lib/paymentrails.rb
|
78
|
+
- lib/paymentrails/Balance.rb
|
79
|
+
- lib/paymentrails/Batch.rb
|
80
|
+
- lib/paymentrails/BatchSummary.rb
|
81
|
+
- lib/paymentrails/Client.rb
|
82
|
+
- lib/paymentrails/Configuration.rb
|
83
|
+
- lib/paymentrails/Exceptions.rb
|
84
|
+
- lib/paymentrails/Gateway.rb
|
85
|
+
- lib/paymentrails/Invoice.rb
|
86
|
+
- lib/paymentrails/InvoicePayment.rb
|
87
|
+
- lib/paymentrails/OfflinePayment.rb
|
88
|
+
- lib/paymentrails/Payment.rb
|
89
|
+
- lib/paymentrails/Recipient.rb
|
90
|
+
- lib/paymentrails/RecipientAccount.rb
|
91
|
+
- lib/paymentrails/gateways/BalanceGateway.rb
|
92
|
+
- lib/paymentrails/gateways/BatchGateway.rb
|
93
|
+
- lib/paymentrails/gateways/GatewayHelper.rb
|
94
|
+
- lib/paymentrails/gateways/InvoiceGateway.rb
|
95
|
+
- lib/paymentrails/gateways/InvoicePaymentGateway.rb
|
96
|
+
- lib/paymentrails/gateways/OfflinePaymentGateway.rb
|
97
|
+
- lib/paymentrails/gateways/PaymentGateway.rb
|
98
|
+
- lib/paymentrails/gateways/RecipientAccountGateway.rb
|
99
|
+
- lib/paymentrails/gateways/RecipientGateway.rb
|
100
|
+
- paymentrails.gemspec
|
101
|
+
- spec/integration/BatchTest.rb
|
102
|
+
- spec/integration/InvoicePaymentTest.rb
|
103
|
+
- spec/integration/InvoiceTest.rb
|
104
|
+
- spec/integration/RecipientTest.rb
|
105
|
+
- spec/integration/helper.rb
|
106
|
+
- spec/unit/ConfigurationTest.rb
|
107
|
+
- spec/unit/PaymentRailsTest.rb
|
108
|
+
homepage: https://trolley.com/
|
109
|
+
licenses:
|
110
|
+
- MIT
|
111
|
+
metadata: {}
|
112
|
+
post_install_message:
|
113
|
+
rdoc_options: []
|
114
|
+
require_paths:
|
115
|
+
- lib
|
116
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
117
|
+
requirements:
|
118
|
+
- - ">="
|
119
|
+
- !ruby/object:Gem::Version
|
120
|
+
version: '2.4'
|
121
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
122
|
+
requirements:
|
123
|
+
- - ">="
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '0'
|
126
|
+
requirements: []
|
127
|
+
rubygems_version: 3.1.6
|
128
|
+
signing_key:
|
129
|
+
specification_version: 4
|
130
|
+
summary: Trolley Ruby SDK
|
131
|
+
test_files: []
|