paymentrails 0.1
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/Balance.rb +0 -0
- data/lib/BalanceGateway.rb +13 -0
- data/lib/Batch.rb +4 -0
- data/lib/BatchGateway.rb +89 -0
- data/lib/BatchSummary.rb +4 -0
- data/lib/Client.rb +103 -0
- data/lib/Configuration.rb +30 -0
- data/lib/Exceptions.rb +17 -0
- data/lib/Gateway.rb +38 -0
- data/lib/Payment.rb +4 -0
- data/lib/PaymentGateway.rb +61 -0
- data/lib/Recipient.rb +4 -0
- data/lib/RecipientAccount.rb +4 -0
- data/lib/RecipientAccountGateway.rb +61 -0
- data/lib/RecipientGateway.rb +62 -0
- data/lib/paymentrails.rb +2 -0
- data/paymentrails.gemspec +15 -0
- data/spec/integration/BatchTest.rb +123 -0
- data/spec/integration/RecipientTest.rb +87 -0
- metadata +76 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: a8ceb73c0e1a331ed962206a781d889d8a7686aa27b1274e570f19e3aa073242
|
4
|
+
data.tar.gz: bb4dcbe84f95705a2bfee3a7307e9faad7b8c0e128709c6f861fa3938e188b13
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b160375ec38307bb976d7814f25ebe20bc436122de064574089b90e75aeb307e7e244c3dc987ffee3ef0118dcf481ab3039b67923bbff3672ad72b243a9e2c96
|
7
|
+
data.tar.gz: a3a9f4d4ff206893c29c89e6962bc09f5b420562343823ac003b23e5fdd76d8367a8155f5d8d9092316ece200a18dea43c8d4f4ca5844798faa3f197cd362005
|
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2017 Payment Rails, Inc.
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person
|
4
|
+
obtaining a copy of this software and associated documentation
|
5
|
+
files (the "Software"), to deal in the Software without
|
6
|
+
restriction, including without limitation the rights to use,
|
7
|
+
copy, modify, merge, publish, distribute, sublicense, and/or sell
|
8
|
+
copies of the Software, and to permit persons to whom the
|
9
|
+
Software is furnished to do so, subject to the following
|
10
|
+
conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be
|
13
|
+
included in all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
16
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
17
|
+
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
18
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
19
|
+
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
20
|
+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
21
|
+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
22
|
+
OTHER DEALINGS IN THE SOFTWARE.
|
data/lib/Balance.rb
ADDED
File without changes
|
data/lib/Batch.rb
ADDED
@@ -0,0 +1,4 @@
|
|
1
|
+
class Batch
|
2
|
+
attr_accessor :id, :amount, :completedAt, :createdAt, :currency, :description, :sentAt, :status, :totalPayments, :updatedAt, :quoteExpiredAt, :payments
|
3
|
+
attr_writer :id, :amount, :completedAt, :createdAt, :currency, :description, :sentAt, :status, :totalPayments, :updatedAt, :quoteExpiredAt, :payments
|
4
|
+
end
|
data/lib/BatchGateway.rb
ADDED
@@ -0,0 +1,89 @@
|
|
1
|
+
require_relative 'Client.rb'
|
2
|
+
|
3
|
+
class BatchGateway
|
4
|
+
def initialize(client)
|
5
|
+
@client = client
|
6
|
+
end
|
7
|
+
|
8
|
+
def find(batch_id)
|
9
|
+
response = @client.get('/v1/batches/' + batch_id)
|
10
|
+
batch_builder(response)
|
11
|
+
end
|
12
|
+
|
13
|
+
def all
|
14
|
+
response = @client.get('/v1/batches/')
|
15
|
+
batch_list_builder(response)
|
16
|
+
end
|
17
|
+
|
18
|
+
def create(body)
|
19
|
+
response = @client.post('/v1/batches/', body)
|
20
|
+
batch_builder(response)
|
21
|
+
end
|
22
|
+
|
23
|
+
def update(batch_id, body)
|
24
|
+
@client.patch('/v1/batches/' + batch_id, body)
|
25
|
+
true
|
26
|
+
end
|
27
|
+
|
28
|
+
def delete(batch_id)
|
29
|
+
@client.delete('/v1/batches/' + batch_id)
|
30
|
+
true
|
31
|
+
end
|
32
|
+
|
33
|
+
def generate_quote(batch_id)
|
34
|
+
response = @client.post('/v1/batches/' + batch_id + '/generate-quote', {})
|
35
|
+
batch_builder(response)
|
36
|
+
end
|
37
|
+
|
38
|
+
def start_processing(batch_id)
|
39
|
+
response = @client.post('/v1/batches/' + batch_id + '/start-processing', {})
|
40
|
+
batch_builder(response)
|
41
|
+
end
|
42
|
+
|
43
|
+
def search(page = 1, page_number = 10, term = '')
|
44
|
+
response = @client.get('/v1/batches/?search=' + term + 'page=' + page + '&pageSize=' + page_number)
|
45
|
+
batch_list_builder(response)
|
46
|
+
end
|
47
|
+
|
48
|
+
def batch_builder(response)
|
49
|
+
batch = Batch.new
|
50
|
+
data = JSON.parse(response)
|
51
|
+
data.each do |key, value|
|
52
|
+
next unless key === 'batch'
|
53
|
+
value.each do |newKey, newValue|
|
54
|
+
batch.send("#{newKey}=", newValue)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
batch
|
58
|
+
end
|
59
|
+
|
60
|
+
def summary(batch_id)
|
61
|
+
response = @client.get('/v1/batches/' + batch_id + '/summary')
|
62
|
+
summary = BatchSummary.new
|
63
|
+
data = JSON.parse(response)
|
64
|
+
data.each do |key, value|
|
65
|
+
next unless key === 'batchSummary'
|
66
|
+
value.each do |newKey, newValue|
|
67
|
+
summary.send("#{newKey}=", newValue)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
summary
|
71
|
+
end
|
72
|
+
|
73
|
+
def batch_list_builder(response)
|
74
|
+
batches = []
|
75
|
+
data = JSON.parse(response)
|
76
|
+
|
77
|
+
data.each do |key, value|
|
78
|
+
next unless key === 'batches'
|
79
|
+
value.each do |newKey, _newValue|
|
80
|
+
batch = Batch.new
|
81
|
+
newKey.each do |key1, value1|
|
82
|
+
batch.send("#{key1}=", value1)
|
83
|
+
end
|
84
|
+
batches.push(batch)
|
85
|
+
end
|
86
|
+
end
|
87
|
+
batches
|
88
|
+
end
|
89
|
+
end
|
data/lib/BatchSummary.rb
ADDED
@@ -0,0 +1,4 @@
|
|
1
|
+
class BatchSummary
|
2
|
+
attr_accessor :id, :amount, :completedAt, :createdAt, :currency, :description, :sentAt, :status, :totalPayments, :updatedAt, :methods, :detail, :total
|
3
|
+
attr_writer :id, :amount, :completedAt, :createdAt, :currency, :description, :sentAt, :status, :totalPayments, :updatedAt, :methods, :detail, :total
|
4
|
+
end
|
data/lib/Client.rb
ADDED
@@ -0,0 +1,103 @@
|
|
1
|
+
require_relative 'Exceptions.rb'
|
2
|
+
require 'digest'
|
3
|
+
require 'net/http'
|
4
|
+
require 'openssl'
|
5
|
+
require 'rest-client'
|
6
|
+
require 'uri'
|
7
|
+
require 'json'
|
8
|
+
|
9
|
+
|
10
|
+
class Client
|
11
|
+
def initialize(config)
|
12
|
+
@config = config
|
13
|
+
end
|
14
|
+
|
15
|
+
def get(endPoint)
|
16
|
+
send_request(endPoint, 'GET')
|
17
|
+
end
|
18
|
+
|
19
|
+
def post(endPoint, body)
|
20
|
+
body = body.to_json
|
21
|
+
send_request(endPoint, 'POST', body)
|
22
|
+
end
|
23
|
+
|
24
|
+
def delete(endPoint)
|
25
|
+
send_request(endPoint, 'DELETE')
|
26
|
+
end
|
27
|
+
|
28
|
+
def patch(endPoint, body)
|
29
|
+
body = body.to_json
|
30
|
+
send_request(endPoint, 'PATCH', body)
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
def send_request(endPoint, method, body = '')
|
36
|
+
uri = URI.parse(@config.apiBase + endPoint)
|
37
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
38
|
+
|
39
|
+
# for ssl use
|
40
|
+
if (@config.apiBase["https"])
|
41
|
+
http.use_ssl = true
|
42
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
43
|
+
end
|
44
|
+
|
45
|
+
time = Time.now.to_i
|
46
|
+
headers = {'X-PR-Timestamp': time.to_s,
|
47
|
+
'Authorization': generate_authorization(time, endPoint, method, body),
|
48
|
+
'Content-Type': 'application/json'}
|
49
|
+
|
50
|
+
if method === "GET"
|
51
|
+
request = Net::HTTP::Get.new(uri.request_uri, headers)
|
52
|
+
elsif method === "POST"
|
53
|
+
request = Net::HTTP::Post.new(uri.request_uri, headers)
|
54
|
+
request.body = body
|
55
|
+
elsif method === "PATCH"
|
56
|
+
request = Net::HTTP::Patch.new(uri.request_uri, headers)
|
57
|
+
request.body = body
|
58
|
+
elsif method === "DELETE"
|
59
|
+
request = Net::HTTP::Delete.new(uri.request_uri, headers)
|
60
|
+
end
|
61
|
+
|
62
|
+
response = http.request(request)
|
63
|
+
|
64
|
+
if response.code != '200' && response.code != '204'
|
65
|
+
throw_status_code_exception(response.message + ' ' + response.body , response.code)
|
66
|
+
end
|
67
|
+
response.body
|
68
|
+
end
|
69
|
+
|
70
|
+
private
|
71
|
+
def generate_authorization(time, endPoint, method, body)
|
72
|
+
message = [time.to_s, method, endPoint, body].join("\n") + "\n"
|
73
|
+
signature = OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new('sha256'), @config.privateKey, message)
|
74
|
+
'prsign ' + @config.publicKey + ':' + signature
|
75
|
+
end
|
76
|
+
|
77
|
+
private
|
78
|
+
def throw_status_code_exception(message, code)
|
79
|
+
case code
|
80
|
+
when '400'
|
81
|
+
raise MalformedException, message
|
82
|
+
when '401'
|
83
|
+
raise AuthenticationError, message
|
84
|
+
when '403'
|
85
|
+
raise AuthorizationErrormessage
|
86
|
+
when '404'
|
87
|
+
raise NotFoundError, message
|
88
|
+
when '429'
|
89
|
+
raise TooManyRequestsError message
|
90
|
+
when '500'
|
91
|
+
raise ServerError, message
|
92
|
+
when '503'
|
93
|
+
raise DownForMaintenanceErroressage, message
|
94
|
+
else
|
95
|
+
raise UnexpectedError, message
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
|
101
|
+
|
102
|
+
|
103
|
+
|
@@ -0,0 +1,30 @@
|
|
1
|
+
class Configuration
|
2
|
+
def initialize(publicKey, privateKey, enviroment)
|
3
|
+
@publicKey = publicKey
|
4
|
+
@privateKey = privateKey
|
5
|
+
@apiBase = set_enviroment(enviroment)
|
6
|
+
end
|
7
|
+
|
8
|
+
def set_enviroment(apiBase)
|
9
|
+
case apiBase
|
10
|
+
when 'production'
|
11
|
+
'https://api.paymentrails.com'
|
12
|
+
when 'development'
|
13
|
+
'http://api.railz.io'
|
14
|
+
when 'integration'
|
15
|
+
'http://api.local.dev:3000'
|
16
|
+
else
|
17
|
+
'https://api.paymentrails.com'
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
attr_reader :publicKey
|
22
|
+
|
23
|
+
attr_writer :publicKey
|
24
|
+
|
25
|
+
attr_reader :privateKey
|
26
|
+
|
27
|
+
attr_writer :privateKey
|
28
|
+
|
29
|
+
attr_reader :apiBase
|
30
|
+
end
|
data/lib/Exceptions.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
class PaymentRailsError < ::StandardError; end
|
2
|
+
|
3
|
+
class AuthenticationError < PaymentRailsError; end
|
4
|
+
|
5
|
+
class AuthorizationError < PaymentRailsError; end
|
6
|
+
|
7
|
+
class DownForMaintenanceError < PaymentRailsError; end
|
8
|
+
|
9
|
+
class NotFoundError < PaymentRailsError; end
|
10
|
+
|
11
|
+
class ServerError < PaymentRailsError; end
|
12
|
+
|
13
|
+
class TooManyRequestsError < PaymentRailsError; end
|
14
|
+
|
15
|
+
class UnexpectedError < PaymentRailsError; end
|
16
|
+
|
17
|
+
class MalformedException < PaymentRailsError; end
|
data/lib/Gateway.rb
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
require_relative 'RecipientGateway.rb'
|
2
|
+
require_relative 'RecipientAccountGateway.rb'
|
3
|
+
require_relative 'BatchGateway.rb'
|
4
|
+
require_relative 'PaymentGateway.rb'
|
5
|
+
require_relative 'BalanceGateway.rb'
|
6
|
+
|
7
|
+
class Gateway
|
8
|
+
attr_reader :config
|
9
|
+
attr_writer :config
|
10
|
+
|
11
|
+
attr_reader :client
|
12
|
+
attr_writer :client
|
13
|
+
|
14
|
+
attr_reader :recipient
|
15
|
+
attr_writer :recipient
|
16
|
+
|
17
|
+
attr_reader :recipient_account
|
18
|
+
attr_writer :recipient_account
|
19
|
+
|
20
|
+
attr_reader :batch
|
21
|
+
attr_writer :batch
|
22
|
+
|
23
|
+
attr_reader :payment
|
24
|
+
attr_writer :payment
|
25
|
+
|
26
|
+
attr_reader :balance
|
27
|
+
attr_writer :balance
|
28
|
+
|
29
|
+
def initialize(config)
|
30
|
+
@config = config
|
31
|
+
@client = Client.new(config)
|
32
|
+
@recipient = RecipientGateway.new(client)
|
33
|
+
@recipient_account = RecipientAccountGateway.new(client)
|
34
|
+
@batch = BatchGateway.new(client)
|
35
|
+
@payment = PaymentGateway.new(client)
|
36
|
+
@balance = BalanceGateway.new(client)
|
37
|
+
end
|
38
|
+
end
|
data/lib/Payment.rb
ADDED
@@ -0,0 +1,4 @@
|
|
1
|
+
class Payment
|
2
|
+
attr_reader :id, :status, :isSupplyPayment, :returnedAmount, :sourceAmount, :sourceCurrency, :targetAmount, :targetCurrency, :exchangeRate, :fees, :recipientFees, :fxRate, :memo, :externalId, :processedAt, :createdAt, :updatedAt, :merchantFees, :compliance, :payoutMethod, :recipient, :withholdingAmount, :withholdingCurrency, :equivalentWithholdingAmount, :equivalentWithholdingCurrency, :methodDisplay, :batch
|
3
|
+
attr_writer :id, :status, :isSupplyPayment, :returnedAmount, :sourceAmount, :sourceCurrency, :targetAmount, :targetCurrency, :exchangeRate, :fees, :recipientFees, :fxRate, :memo, :externalId, :processedAt, :createdAt, :updatedAt, :merchantFees, :compliance, :payoutMethod, :recipient, :withholdingAmount, :withholdingCurrency, :equivalentWithholdingAmount, :equivalentWithholdingCurrency, :methodDisplay, :batch
|
4
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
require_relative 'Client.rb'
|
2
|
+
|
3
|
+
class PaymentGateway
|
4
|
+
def initialize(client)
|
5
|
+
@client = client
|
6
|
+
end
|
7
|
+
|
8
|
+
def find(batch_id, payment_id)
|
9
|
+
response = @client.get('/v1/batches/' + batch_id + '/payments/' + payment_id)
|
10
|
+
payment_builder(response)
|
11
|
+
end
|
12
|
+
|
13
|
+
def create(batch_id, body)
|
14
|
+
response = @client.post('/v1/batches/' + batch_id + '/payments', body)
|
15
|
+
payment_builder(response)
|
16
|
+
end
|
17
|
+
|
18
|
+
def update(batch_id, payment_id, body)
|
19
|
+
@client.patch('/v1/batches/' + batch_id + '/payments/' + payment_id, body)
|
20
|
+
true
|
21
|
+
end
|
22
|
+
|
23
|
+
def delete(batch_id, payment_id)
|
24
|
+
@client.delete('/v1/batches/' + batch_id + '/payments/' + payment_id)
|
25
|
+
true
|
26
|
+
end
|
27
|
+
|
28
|
+
def search(batch_id, page = 1, page_number = 10, term = '')
|
29
|
+
response = @client.get('/v1/batches/' + batch_id.to_s + '/payments?' + 'page=' + page.to_s + '&pageSize=' + page_number.to_s + '&search=' + term)
|
30
|
+
payments_list_builder(response)
|
31
|
+
end
|
32
|
+
|
33
|
+
def payment_builder(response)
|
34
|
+
payment = Payment.new
|
35
|
+
data = JSON.parse(response)
|
36
|
+
data.each do |key, value|
|
37
|
+
next unless key === 'payment'
|
38
|
+
value.each do |recipKey, recipValue|
|
39
|
+
payment.send("#{recipKey}=", recipValue)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
payment
|
43
|
+
end
|
44
|
+
|
45
|
+
def payments_list_builder(response)
|
46
|
+
payments = []
|
47
|
+
data = JSON.parse(response)
|
48
|
+
|
49
|
+
data.each do |key, value|
|
50
|
+
next unless key === 'payments'
|
51
|
+
value.each do |newKey, _newValue|
|
52
|
+
payment = Payment.new
|
53
|
+
newKey.each do |key1, value1|
|
54
|
+
payment.send("#{key1}=", value1)
|
55
|
+
end
|
56
|
+
payments.push(payment)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
payments
|
60
|
+
end
|
61
|
+
end
|
data/lib/Recipient.rb
ADDED
@@ -0,0 +1,4 @@
|
|
1
|
+
class Recipient
|
2
|
+
attr_accessor :id, :routeType, :estimatedFees, :referenceId, :email, :name, :lastName, :firstName, :type, :taxType, :status, :language, :complianceStatus, :dob, :passport, :updatedAt, :createdAt, :gravatarUrl, :governmentId, :ssn, :primaryCurrency, :merchantId, :payout, :compliance, :accounts, :address, :taxWithholdingPercentage, :taxForm, :taxFormStatus, :inactiveReasons, :payoutMethod, :placeOfBirth, :tags, :taxDeliveryType
|
3
|
+
attr_writer :id, :routeType, :estimatedFees, :referenceId, :email, :name, :lastName, :firstName, :type, :taxType, :status, :language, :complianceStatus, :dob, :passport, :updatedAt, :createdAt, :gravatarUrl, :governmentId, :ssn, :primaryCurrency, :merchantId, :payout, :compliance, :accounts, :address, :taxWithholdingPercentage, :taxForm, :taxFormStatus, :inactiveReasons, :payoutMethod, :placeOfBirth, :tags, :taxDeliveryType
|
4
|
+
end
|
@@ -0,0 +1,4 @@
|
|
1
|
+
class RecipientAccount
|
2
|
+
attr_accessor :id, :primary, :currency, :recipientAccountId, :routeType, :recipientFees, :emailAddress, :country, :type, :iban, :accountNum, :accountHolderName, :swiftBic, :branchId, :bankId, :bankName, :bankAddress, :bankCity, :bankRegionCode, :bankPostalCode, :status, :disabledAt
|
3
|
+
attr_writer :id, :primary, :currency, :recipientAccountId, :routeType, :recipientFees, :emailAddress, :country, :type, :iban, :accountNum, :accountHolderName, :swiftBic, :branchId, :bankId, :bankName, :bankAddress, :bankCity, :bankRegionCode, :bankPostalCode, :status, :disabledAt
|
4
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
require_relative 'Client.rb'
|
2
|
+
|
3
|
+
class RecipientAccountGateway
|
4
|
+
def initialize(client)
|
5
|
+
@client = client
|
6
|
+
end
|
7
|
+
|
8
|
+
def find(recipient_id, recipient_account_id)
|
9
|
+
response = @client.get('/v1/recipients/' + recipient_id + '/accounts/' + recipient_account_id)
|
10
|
+
recipient_account_builder(response)
|
11
|
+
end
|
12
|
+
|
13
|
+
def all(recipient_id)
|
14
|
+
response = @client.get('/v1/recipients/' + recipient_id + '/accounts/')
|
15
|
+
recipient_account_list_builder(response)
|
16
|
+
end
|
17
|
+
|
18
|
+
def create(recipient_id, body)
|
19
|
+
response = @client.post('/v1/recipients/' + recipient_id + '/accounts', body)
|
20
|
+
recipient_account_builder(response)
|
21
|
+
end
|
22
|
+
|
23
|
+
def update(recipient_id, recipient_account_id, body)
|
24
|
+
response = @client.patch('/v1/recipients/' + recipient_id, + '/accounts/' + recipient_account_id, body)
|
25
|
+
recipient_account_builder(response)
|
26
|
+
end
|
27
|
+
|
28
|
+
def delete(recipient_id, recipient_account_id)
|
29
|
+
@client.delete('/v1/recipients/' + recipient_id + '/accounts/' + recipient_account_id)
|
30
|
+
true
|
31
|
+
end
|
32
|
+
|
33
|
+
def recipient_account_builder(response)
|
34
|
+
recipient_account = RecipientAccount.new
|
35
|
+
data = JSON.parse(response)
|
36
|
+
data.each do |key, value|
|
37
|
+
next unless key === 'account'
|
38
|
+
value.each do |recipKey, recipValue|
|
39
|
+
recipient_account.send("#{recipKey}=", recipValue)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
recipient_account
|
43
|
+
end
|
44
|
+
|
45
|
+
def recipient_account_list_builder(response)
|
46
|
+
recipient_accounts = []
|
47
|
+
data = JSON.parse(response)
|
48
|
+
|
49
|
+
data.each do |key, value|
|
50
|
+
next unless key === 'accounts'
|
51
|
+
value.each do |newKey, _newValue|
|
52
|
+
recipient_account = RecipientAccount.new
|
53
|
+
newKey.each do |key1, value1|
|
54
|
+
recipient_account.send("#{key1}=", value1)
|
55
|
+
end
|
56
|
+
recipient_accounts.push(recipient_account)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
recipient_accounts
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
require_relative 'Client.rb'
|
2
|
+
require_relative 'Recipient.rb'
|
3
|
+
|
4
|
+
class RecipientGateway
|
5
|
+
def initialize(client)
|
6
|
+
@client = client
|
7
|
+
end
|
8
|
+
|
9
|
+
def find(recipient_id)
|
10
|
+
response = @client.get('/v1/recipients/' + recipient_id)
|
11
|
+
recipient_builder(response)
|
12
|
+
end
|
13
|
+
|
14
|
+
def create(body)
|
15
|
+
response = @client.post('/v1/recipients/', body)
|
16
|
+
recipient_builder(response)
|
17
|
+
end
|
18
|
+
|
19
|
+
def update(recipient_id, body)
|
20
|
+
@client.patch('/v1/recipients/' + recipient_id, body)
|
21
|
+
true
|
22
|
+
end
|
23
|
+
|
24
|
+
def delete(recipient_id)
|
25
|
+
@client.delete('/v1/recipients/' + recipient_id)
|
26
|
+
true
|
27
|
+
end
|
28
|
+
|
29
|
+
def search(page = 1, page_size = 10, term = '')
|
30
|
+
response = @client.get('/v1/recipients?page=' + page.to_s + '&pageSize=' + page_size.to_s + '&search=' + term)
|
31
|
+
recipient_list_builder(response)
|
32
|
+
end
|
33
|
+
|
34
|
+
def recipient_builder(response)
|
35
|
+
recipient = Recipient.new
|
36
|
+
data = JSON.parse(response)
|
37
|
+
data.each do |key, value|
|
38
|
+
next unless key === 'recipient'
|
39
|
+
value.each do |recipKey, recipValue|
|
40
|
+
recipient.send("#{recipKey}=", recipValue)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
recipient
|
44
|
+
end
|
45
|
+
|
46
|
+
def recipient_list_builder(response)
|
47
|
+
recipients = []
|
48
|
+
data = JSON.parse(response)
|
49
|
+
|
50
|
+
data.each do |key, value|
|
51
|
+
next unless key === 'recipients'
|
52
|
+
value.each do |newKey, _newValue|
|
53
|
+
recipient = Recipient.new
|
54
|
+
newKey.each do |key1, value1|
|
55
|
+
recipient.send("#{key1}=", value1)
|
56
|
+
end
|
57
|
+
recipients.push(recipient)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
recipients
|
61
|
+
end
|
62
|
+
end
|
data/lib/paymentrails.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
$:.push File.expand_path("../lib", __FILE__)
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = "paymentrails"
|
5
|
+
s.summary = "PaymentRails Ruby SDK"
|
6
|
+
s.description = "Ruby SDK for interacting with the PaymentRails API"
|
7
|
+
s.version = '0.1'
|
8
|
+
s.homepage = 'https://www.paymentrails.com/'
|
9
|
+
s.email = 'jesse.silber@paymentrails.com'
|
10
|
+
s.license = "MIT"
|
11
|
+
s.author = "PaymentRails"
|
12
|
+
s.has_rdoc = false
|
13
|
+
s.files = Dir.glob ["README.rdoc", "LICENSE", "lib/**/*.{rb,crt}", "spec/**/*", "*.gemspec"]
|
14
|
+
s.add_dependency "rest-client", "= 2.0.2"
|
15
|
+
end
|
@@ -0,0 +1,123 @@
|
|
1
|
+
Dir['../../lib/*'].each { |file| require_relative file }
|
2
|
+
require 'test/unit'
|
3
|
+
require 'securerandom'
|
4
|
+
|
5
|
+
class BatchTest < Test::Unit::TestCase
|
6
|
+
def setup
|
7
|
+
@client = Gateway.new(Configuration.new('YOUR-API-KEY', 'YOUR-API-SECRET', 'production'))
|
8
|
+
end
|
9
|
+
|
10
|
+
def create_recipient
|
11
|
+
uuid = SecureRandom.uuid.to_s
|
12
|
+
recipient = @client.recipient.create(
|
13
|
+
type: 'individual',
|
14
|
+
firstName: 'Tom',
|
15
|
+
lastName: 'Jones',
|
16
|
+
email: 'test.batch' + uuid + '@example.com',
|
17
|
+
address: {
|
18
|
+
street1: '123 Wolfstrasse',
|
19
|
+
city: 'Berlin',
|
20
|
+
country: 'DE',
|
21
|
+
postalCode: '123123'
|
22
|
+
}
|
23
|
+
)
|
24
|
+
@client.recipient_account.create(recipient.id, type: 'bank-transfer', currency: 'EUR', country: 'DE', iban: 'DE89 3704 0044 0532 0130 00')
|
25
|
+
recipient
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_all
|
29
|
+
batch = @client.batch.all
|
30
|
+
assert_true(batch.count > 0)
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_create
|
34
|
+
batch = @client.batch.create(sourceCurrency: 'USD', description: 'Integration Test Create')
|
35
|
+
assert_not_nil(batch)
|
36
|
+
assert_not_nil(batch.id)
|
37
|
+
|
38
|
+
batch = @client.batch.all
|
39
|
+
assert_true(batch.count > 0)
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_update
|
43
|
+
batch = @client.batch.create(sourceCurrency: 'USD', description: 'Integration Test Create')
|
44
|
+
assert_not_nil(batch)
|
45
|
+
assert_not_nil(batch.id)
|
46
|
+
|
47
|
+
all = @client.batch.all
|
48
|
+
assert_true(all.count > 0)
|
49
|
+
|
50
|
+
response = @client.batch.update(batch.id, description: 'Integration Update')
|
51
|
+
assert_true(response)
|
52
|
+
findBatch = @client.batch.find(batch.id)
|
53
|
+
assert_equal('Integration Update', findBatch.description)
|
54
|
+
assert_equal('open', batch.status)
|
55
|
+
|
56
|
+
response = @client.batch.delete(batch.id)
|
57
|
+
assert_true(response)
|
58
|
+
end
|
59
|
+
|
60
|
+
def test_create_with_payments
|
61
|
+
recipientAlpha = create_recipient
|
62
|
+
recipientBeta = create_recipient
|
63
|
+
|
64
|
+
batch = @client.batch.create(
|
65
|
+
sourceCurrency: 'USD', description: 'Integration Test Payments', payments: [
|
66
|
+
{ targetAmount: '10.00', targetCurrency: 'EUR', recipient: { id: recipientAlpha.id } },
|
67
|
+
{ sourceAmount: '10.00', recipient: { id: recipientBeta.id } }
|
68
|
+
]
|
69
|
+
)
|
70
|
+
|
71
|
+
assert_not_nil(batch)
|
72
|
+
assert_not_nil(batch.id)
|
73
|
+
|
74
|
+
findBatch = @client.batch.find(batch.id)
|
75
|
+
assert_not_nil(findBatch)
|
76
|
+
assert_equal(2, findBatch.totalPayments)
|
77
|
+
|
78
|
+
payments = @client.payment.search(batch.id)
|
79
|
+
payments.each { |item| assert_equal('pending', item.status) }
|
80
|
+
end
|
81
|
+
|
82
|
+
def test_payments
|
83
|
+
batch = @client.batch.create(sourceCurrency: 'USD', description: 'Integration Test Payments')
|
84
|
+
assert_not_nil(batch)
|
85
|
+
assert_not_nil(batch.id)
|
86
|
+
|
87
|
+
recipient = create_recipient
|
88
|
+
|
89
|
+
payment = @client.payment.create(batch.id, sourceAmount: '10.00', recipient: { id: recipient.id })
|
90
|
+
|
91
|
+
assert_not_nil(payment)
|
92
|
+
assert_not_nil(payment.id)
|
93
|
+
|
94
|
+
response = @client.payment.update(batch.id, payment.id, sourceAmount: '20.00')
|
95
|
+
assert_true(response)
|
96
|
+
|
97
|
+
response = @client.payment.delete(batch.id, payment.id)
|
98
|
+
assert_true(response)
|
99
|
+
end
|
100
|
+
|
101
|
+
def test_processing
|
102
|
+
recipientAlpha = create_recipient
|
103
|
+
recipientBeta = create_recipient
|
104
|
+
|
105
|
+
batch = @client.batch.create(
|
106
|
+
sourceCurrency: 'USD', description: 'Integration Test Payments', payments: [
|
107
|
+
{ targetAmount: '10.00', targetCurrency: 'EUR', recipient: { id: recipientAlpha.id } },
|
108
|
+
{ sourceAmount: '10.00', recipient: { id: recipientBeta.id } }
|
109
|
+
]
|
110
|
+
)
|
111
|
+
assert_not_nil(batch)
|
112
|
+
assert_not_nil(batch.id)
|
113
|
+
|
114
|
+
summary = @client.batch.summary(batch.id)
|
115
|
+
assert_equal(2, summary.detail['bank-transfer']['count'])
|
116
|
+
|
117
|
+
quote = @client.batch.generate_quote(batch.id)
|
118
|
+
assert_not_nil(quote)
|
119
|
+
|
120
|
+
start = @client.batch.start_processing(batch.id)
|
121
|
+
assert_not_nil(start)
|
122
|
+
end
|
123
|
+
end
|
@@ -0,0 +1,87 @@
|
|
1
|
+
Dir['../../lib/*'].each { |file| require_relative file }
|
2
|
+
require 'test/unit'
|
3
|
+
require 'securerandom'
|
4
|
+
|
5
|
+
class RecipientTest < Test::Unit::TestCase
|
6
|
+
def setup
|
7
|
+
@client = Gateway.new(Configuration.new('YOUR-API-KEY', 'YOUR-API-SECRET', 'production'))
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_create
|
11
|
+
uuid = SecureRandom.uuid.to_s
|
12
|
+
response = @client.recipient.create(
|
13
|
+
type: 'individual',
|
14
|
+
firstName: 'Tom',
|
15
|
+
lastName: 'Jones',
|
16
|
+
email: 'test.create' + uuid + '@example.com'
|
17
|
+
)
|
18
|
+
assert_not_nil(response)
|
19
|
+
assert_equal(response.firstName, 'Tom')
|
20
|
+
assert_equal(response.lastName, 'Jones')
|
21
|
+
assert_not_nil(response.id)
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_lifecycle
|
25
|
+
uuid = SecureRandom.uuid.to_s
|
26
|
+
recipient = @client.recipient.create(
|
27
|
+
type: 'individual',
|
28
|
+
firstName: 'Tom',
|
29
|
+
lastName: 'Jones',
|
30
|
+
email: 'test.create' + uuid + '@example.com'
|
31
|
+
)
|
32
|
+
assert_not_nil(recipient)
|
33
|
+
assert_equal(recipient.firstName, 'Tom')
|
34
|
+
assert_equal(recipient.status, 'incomplete')
|
35
|
+
|
36
|
+
response = @client.recipient.update(recipient.id, firstName: 'Bob')
|
37
|
+
assert_true(response)
|
38
|
+
|
39
|
+
recipient = @client.recipient.find(recipient.id)
|
40
|
+
assert_equal(recipient.firstName, 'Bob')
|
41
|
+
|
42
|
+
response = @client.recipient.delete(recipient.id)
|
43
|
+
assert_true(response)
|
44
|
+
|
45
|
+
recipient = @client.recipient.find(recipient.id)
|
46
|
+
assert_equal(recipient.status, 'archived')
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_account
|
50
|
+
uuid = SecureRandom.uuid.to_s
|
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
|
+
|
68
|
+
account = @client.recipient_account.create(recipient.id, type: 'bank-transfer', currency: 'EUR', country: 'DE', iban: 'DE89 3704 0044 0532 0130 00')
|
69
|
+
assert_not_nil(account)
|
70
|
+
|
71
|
+
account = @client.recipient_account.create(recipient.id, type: 'bank-transfer', currency: 'EUR', country: 'FR', iban: 'FR14 2004 1010 0505 0001 3M02 606')
|
72
|
+
assert_not_nil(account)
|
73
|
+
|
74
|
+
findAccount = @client.recipient_account.find(recipient.id, account.id)
|
75
|
+
assert_equal(account.id, findAccount.id)
|
76
|
+
|
77
|
+
accountList = @client.recipient_account.all(recipient.id)
|
78
|
+
assert_equal(2, accountList.count)
|
79
|
+
assert_equal(accountList[0].currency, 'EUR')
|
80
|
+
|
81
|
+
result = @client.recipient_account.delete(recipient.id, account.id)
|
82
|
+
assert_true(result)
|
83
|
+
|
84
|
+
accountList = @client.recipient_account.all(recipient.id)
|
85
|
+
assert_equal(1, accountList.count)
|
86
|
+
end
|
87
|
+
end
|
metadata
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: paymentrails
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '0.1'
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- PaymentRails
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-05-03 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rest-client
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 2.0.2
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 2.0.2
|
27
|
+
description: Ruby SDK for interacting with the PaymentRails API
|
28
|
+
email: jesse.silber@paymentrails.com
|
29
|
+
executables: []
|
30
|
+
extensions: []
|
31
|
+
extra_rdoc_files: []
|
32
|
+
files:
|
33
|
+
- LICENSE
|
34
|
+
- lib/Balance.rb
|
35
|
+
- lib/BalanceGateway.rb
|
36
|
+
- lib/Batch.rb
|
37
|
+
- lib/BatchGateway.rb
|
38
|
+
- lib/BatchSummary.rb
|
39
|
+
- lib/Client.rb
|
40
|
+
- lib/Configuration.rb
|
41
|
+
- lib/Exceptions.rb
|
42
|
+
- lib/Gateway.rb
|
43
|
+
- lib/Payment.rb
|
44
|
+
- lib/PaymentGateway.rb
|
45
|
+
- lib/Recipient.rb
|
46
|
+
- lib/RecipientAccount.rb
|
47
|
+
- lib/RecipientAccountGateway.rb
|
48
|
+
- lib/RecipientGateway.rb
|
49
|
+
- lib/paymentrails.rb
|
50
|
+
- paymentrails.gemspec
|
51
|
+
- spec/integration/BatchTest.rb
|
52
|
+
- spec/integration/RecipientTest.rb
|
53
|
+
homepage: https://www.paymentrails.com/
|
54
|
+
licenses:
|
55
|
+
- MIT
|
56
|
+
metadata: {}
|
57
|
+
post_install_message:
|
58
|
+
rdoc_options: []
|
59
|
+
require_paths:
|
60
|
+
- lib
|
61
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
62
|
+
requirements:
|
63
|
+
- - ">="
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: '0'
|
66
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
67
|
+
requirements:
|
68
|
+
- - ">="
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: '0'
|
71
|
+
requirements: []
|
72
|
+
rubygems_version: 3.0.3
|
73
|
+
signing_key:
|
74
|
+
specification_version: 4
|
75
|
+
summary: PaymentRails Ruby SDK
|
76
|
+
test_files: []
|