paymentrails 0.2.0 → 0.2.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/paymentrails.rb +5 -4
- data/lib/paymentrails/Batch.rb +16 -2
- data/lib/paymentrails/BatchSummary.rb +17 -3
- data/lib/paymentrails/Client.rb +7 -10
- data/lib/paymentrails/Configuration.rb +21 -6
- data/lib/paymentrails/Exceptions.rb +1 -1
- data/lib/paymentrails/Gateway.rb +4 -0
- data/lib/paymentrails/OfflinePayment.rb +23 -0
- data/lib/paymentrails/Payment.rb +47 -2
- data/lib/paymentrails/Recipient.rb +37 -2
- data/lib/paymentrails/RecipientAccount.rb +27 -3
- data/lib/paymentrails/gateways/BalanceGateway.rb +1 -1
- data/lib/paymentrails/gateways/BatchGateway.rb +9 -12
- data/lib/paymentrails/gateways/GatewayHelper.rb +15 -0
- data/lib/paymentrails/gateways/OfflinePaymentGateway.rb +61 -0
- data/lib/paymentrails/gateways/PaymentGateway.rb +6 -8
- data/lib/paymentrails/gateways/RecipientAccountGateway.rb +7 -9
- data/lib/paymentrails/gateways/RecipientGateway.rb +6 -8
- data/paymentrails.gemspec +7 -4
- data/spec/integration/BatchTest.rb +7 -4
- data/spec/integration/RecipientTest.rb +7 -4
- data/spec/integration/helper.rb +4 -0
- data/spec/unit/ConfigurationTest.rb +51 -0
- data/spec/unit/PaymentRailsTest.rb +15 -0
- metadata +57 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f075f2b06d9c9ce0d11833e11268288a727e10fb79f1ce44a070fbb5d9a55e2b
|
4
|
+
data.tar.gz: 82eed4cf841783902a59c32edc955b6ec7a0541ab679cb5193e7493c0d00d662
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7e6ee052161182aff7763683512b8bb66dc90b79394f19923fb3b53f544e0c6134cf66ab885b7905768d659918a8b812555cc2b7deef2878090434d7ff5c928c
|
7
|
+
data.tar.gz: 2fc33f250b401fb53d9a3d729798886db4a60a419750fbab5e47f57664aa2a8aa1a496a0aa77e252339abf9475cdb619ab5f961f5b9cdd8045abee49200e9c6c
|
data/lib/paymentrails.rb
CHANGED
@@ -6,6 +6,7 @@ require 'paymentrails/gateways/BatchGateway'
|
|
6
6
|
require 'paymentrails/gateways/PaymentGateway'
|
7
7
|
require 'paymentrails/gateways/RecipientGateway'
|
8
8
|
require 'paymentrails/gateways/RecipientAccountGateway'
|
9
|
+
require 'paymentrails/gateways/OfflinePaymentGateway'
|
9
10
|
|
10
11
|
require 'paymentrails/Balance'
|
11
12
|
require 'paymentrails/Batch'
|
@@ -14,10 +15,10 @@ require 'paymentrails/Exceptions'
|
|
14
15
|
require 'paymentrails/Payment'
|
15
16
|
require 'paymentrails/Recipient'
|
16
17
|
require 'paymentrails/RecipientAccount'
|
18
|
+
require 'paymentrails/OfflinePayment'
|
17
19
|
|
18
20
|
module PaymentRails
|
19
|
-
def self.client(key, secret, environment = 'production')
|
20
|
-
|
21
|
-
return client
|
21
|
+
def self.client(key, secret, environment = 'production', **optionals)
|
22
|
+
Gateway.new(Configuration.new(key, secret, environment, optionals))
|
22
23
|
end
|
23
|
-
end
|
24
|
+
end
|
data/lib/paymentrails/Batch.rb
CHANGED
@@ -1,6 +1,20 @@
|
|
1
1
|
module PaymentRails
|
2
2
|
class Batch
|
3
|
-
attr_accessor
|
4
|
-
|
3
|
+
attr_accessor(
|
4
|
+
:id,
|
5
|
+
:amount,
|
6
|
+
:completedAt,
|
7
|
+
:createdAt,
|
8
|
+
:currency,
|
9
|
+
:description,
|
10
|
+
:sentAt,
|
11
|
+
:status,
|
12
|
+
:totalPayments,
|
13
|
+
:updatedAt,
|
14
|
+
:quoteExpiredAt,
|
15
|
+
:payments,
|
16
|
+
:tags,
|
17
|
+
:coverFees
|
18
|
+
)
|
5
19
|
end
|
6
20
|
end
|
@@ -1,6 +1,20 @@
|
|
1
1
|
module PaymentRails
|
2
2
|
class BatchSummary
|
3
|
-
attr_accessor
|
4
|
-
|
3
|
+
attr_accessor(
|
4
|
+
:id,
|
5
|
+
:amount,
|
6
|
+
:completedAt,
|
7
|
+
:createdAt,
|
8
|
+
:currency,
|
9
|
+
:description,
|
10
|
+
:sentAt,
|
11
|
+
:status,
|
12
|
+
:totalPayments,
|
13
|
+
:updatedAt,
|
14
|
+
:methods,
|
15
|
+
:detail,
|
16
|
+
:total,
|
17
|
+
:balances
|
18
|
+
)
|
5
19
|
end
|
6
|
-
end
|
20
|
+
end
|
data/lib/paymentrails/Client.rb
CHANGED
@@ -2,7 +2,6 @@
|
|
2
2
|
require 'digest'
|
3
3
|
require 'net/http'
|
4
4
|
require 'openssl'
|
5
|
-
require 'rest-client'
|
6
5
|
require 'uri'
|
7
6
|
require 'json'
|
8
7
|
|
@@ -34,13 +33,11 @@ module PaymentRails
|
|
34
33
|
|
35
34
|
def send_request(endPoint, method, body = '')
|
36
35
|
uri = URI.parse(@config.apiBase + endPoint)
|
37
|
-
http = Net::HTTP.new(
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
43
|
-
end
|
36
|
+
http = Net::HTTP.new(
|
37
|
+
uri.host, uri.port,
|
38
|
+
@config.proxy&.host, @config.proxy&.port, @config.proxy&.user, @config.proxy&.password
|
39
|
+
)
|
40
|
+
http.use_ssl = @config.useSsl?
|
44
41
|
|
45
42
|
time = Time.now.to_i
|
46
43
|
headers = {'X-PR-Timestamp': time.to_s,
|
@@ -82,11 +79,11 @@ module PaymentRails
|
|
82
79
|
when '401'
|
83
80
|
raise AuthenticationError, message
|
84
81
|
when '403'
|
85
|
-
raise
|
82
|
+
raise AuthorizationError, message
|
86
83
|
when '404'
|
87
84
|
raise NotFoundError, message
|
88
85
|
when '429'
|
89
|
-
raise TooManyRequestsError message
|
86
|
+
raise TooManyRequestsError, message
|
90
87
|
when '500'
|
91
88
|
raise ServerError, message
|
92
89
|
when '503'
|
@@ -1,14 +1,23 @@
|
|
1
1
|
module PaymentRails
|
2
2
|
class Configuration
|
3
|
+
class InvalidProxyAddress < StandardError; end
|
4
|
+
|
5
|
+
def initialize(publicKey, privateKey, environment = 'production', proxy_uri: nil)
|
6
|
+
raise ArgumentError, 'Both key/secret must be a nonempty string' if publicKey.to_s&.empty? || privateKey.to_s&.empty?
|
3
7
|
|
4
|
-
def initialize(publicKey, privateKey, environment = 'production')
|
5
8
|
@publicKey = publicKey
|
6
9
|
@privateKey = privateKey
|
7
|
-
@
|
10
|
+
@environment = environment
|
11
|
+
# failfast on a bad proxy
|
12
|
+
begin
|
13
|
+
@proxy = proxy_uri.nil? ? nil : URI.parse(proxy_uri)
|
14
|
+
rescue URI::InvalidURIError
|
15
|
+
raise InvalidProxyAddress, "Invalid proxy provided to configuration: #{proxy_uri}"
|
16
|
+
end
|
8
17
|
end
|
9
18
|
|
10
|
-
def
|
11
|
-
case
|
19
|
+
def apiBase
|
20
|
+
case environment
|
12
21
|
when 'production'
|
13
22
|
'https://api.paymentrails.com'
|
14
23
|
when 'development'
|
@@ -20,6 +29,12 @@ module PaymentRails
|
|
20
29
|
end
|
21
30
|
end
|
22
31
|
|
32
|
+
def useSsl?
|
33
|
+
apiBase.start_with? 'https'
|
34
|
+
end
|
35
|
+
|
36
|
+
attr_reader :proxy
|
37
|
+
|
23
38
|
attr_reader :publicKey
|
24
39
|
|
25
40
|
attr_writer :publicKey
|
@@ -28,6 +43,6 @@ module PaymentRails
|
|
28
43
|
|
29
44
|
attr_writer :privateKey
|
30
45
|
|
31
|
-
attr_reader :
|
46
|
+
attr_reader :environment
|
32
47
|
end
|
33
|
-
end
|
48
|
+
end
|
data/lib/paymentrails/Gateway.rb
CHANGED
@@ -21,6 +21,9 @@ module PaymentRails
|
|
21
21
|
attr_reader :balance
|
22
22
|
attr_writer :balance
|
23
23
|
|
24
|
+
attr_reader :offline_payment
|
25
|
+
attr_writer :offline_payment
|
26
|
+
|
24
27
|
def initialize(config)
|
25
28
|
@config = config
|
26
29
|
@client = Client.new(config)
|
@@ -29,6 +32,7 @@ module PaymentRails
|
|
29
32
|
@batch = BatchGateway.new(client)
|
30
33
|
@payment = PaymentGateway.new(client)
|
31
34
|
@balance = BalanceGateway.new(client)
|
35
|
+
@offline_payment = OfflinePaymentGateway.new(client)
|
32
36
|
end
|
33
37
|
end
|
34
38
|
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module PaymentRails
|
2
|
+
class OfflinePayment
|
3
|
+
attr_accessor(
|
4
|
+
:id,
|
5
|
+
:recipientId,
|
6
|
+
:externalId,
|
7
|
+
:memo,
|
8
|
+
:tags,
|
9
|
+
:taxReportable,
|
10
|
+
:category,
|
11
|
+
:amount,
|
12
|
+
:currency,
|
13
|
+
:withholdingAmount,
|
14
|
+
:withholdingCurrency,
|
15
|
+
:processedAt,
|
16
|
+
:equivalentWithholdingAmount,
|
17
|
+
:equivalentWithholdingCurrency,
|
18
|
+
:updatedAt,
|
19
|
+
:createdAt,
|
20
|
+
:deletedAt
|
21
|
+
)
|
22
|
+
end
|
23
|
+
end
|
data/lib/paymentrails/Payment.rb
CHANGED
@@ -1,6 +1,51 @@
|
|
1
1
|
module PaymentRails
|
2
2
|
class Payment
|
3
|
-
|
4
|
-
|
3
|
+
attr_accessor(
|
4
|
+
:id,
|
5
|
+
:status,
|
6
|
+
:isSupplyPayment,
|
7
|
+
:returnedAmount,
|
8
|
+
:sourceAmount,
|
9
|
+
:sourceCurrency,
|
10
|
+
:targetAmount,
|
11
|
+
:targetCurrency,
|
12
|
+
:exchangeRate,
|
13
|
+
:fees,
|
14
|
+
:recipientFees,
|
15
|
+
:fxRate,
|
16
|
+
:memo,
|
17
|
+
:externalId,
|
18
|
+
:processedAt,
|
19
|
+
:createdAt,
|
20
|
+
:updatedAt,
|
21
|
+
:merchantFees,
|
22
|
+
:compliance,
|
23
|
+
:payoutMethod,
|
24
|
+
:estimatedDeliveryAt,
|
25
|
+
:recipient,
|
26
|
+
:withholdingAmount,
|
27
|
+
:withholdingCurrency,
|
28
|
+
:equivalentWithholdingAmount,
|
29
|
+
:equivalentWithholdingCurrency,
|
30
|
+
:methodDisplay,
|
31
|
+
:batch,
|
32
|
+
:coverFees,
|
33
|
+
:category,
|
34
|
+
:amount,
|
35
|
+
:currency,
|
36
|
+
:taxReportable,
|
37
|
+
:taxBasisAmount,
|
38
|
+
:taxBasisCurrency,
|
39
|
+
:tags,
|
40
|
+
:account,
|
41
|
+
:initiatedAt,
|
42
|
+
:settledAt,
|
43
|
+
:returnedAt,
|
44
|
+
:returnedNote,
|
45
|
+
:returnedReason,
|
46
|
+
:failureMessage,
|
47
|
+
:merchantId,
|
48
|
+
:checkNumber
|
49
|
+
)
|
5
50
|
end
|
6
51
|
end
|
@@ -1,6 +1,41 @@
|
|
1
1
|
module PaymentRails
|
2
2
|
class Recipient
|
3
|
-
attr_accessor
|
4
|
-
|
3
|
+
attr_accessor(
|
4
|
+
:id,
|
5
|
+
:routeType,
|
6
|
+
:estimatedFees,
|
7
|
+
:referenceId,
|
8
|
+
:email,
|
9
|
+
:name,
|
10
|
+
:lastName,
|
11
|
+
:firstName,
|
12
|
+
:type,
|
13
|
+
:taxType,
|
14
|
+
:status,
|
15
|
+
:language,
|
16
|
+
:complianceStatus,
|
17
|
+
:dob,
|
18
|
+
:passport,
|
19
|
+
:updatedAt,
|
20
|
+
:createdAt,
|
21
|
+
:gravatarUrl,
|
22
|
+
:governmentId,
|
23
|
+
:ssn,
|
24
|
+
:primaryCurrency,
|
25
|
+
:merchantId,
|
26
|
+
:payout,
|
27
|
+
:compliance,
|
28
|
+
:accounts,
|
29
|
+
:address,
|
30
|
+
:taxWithholdingPercentage,
|
31
|
+
:taxForm,
|
32
|
+
:taxFormStatus,
|
33
|
+
:inactiveReasons,
|
34
|
+
:payoutMethod,
|
35
|
+
:placeOfBirth,
|
36
|
+
:tags,
|
37
|
+
:taxDeliveryType,
|
38
|
+
:riskScore
|
39
|
+
)
|
5
40
|
end
|
6
41
|
end
|
@@ -1,6 +1,30 @@
|
|
1
1
|
module PaymentRails
|
2
2
|
class RecipientAccount
|
3
|
-
attr_accessor
|
4
|
-
|
3
|
+
attr_accessor(
|
4
|
+
:id,
|
5
|
+
:primary,
|
6
|
+
:currency,
|
7
|
+
:recipientAccountId,
|
8
|
+
:recipientId,
|
9
|
+
:recipientReferenceId,
|
10
|
+
:routeType,
|
11
|
+
:recipientFees,
|
12
|
+
:emailAddress,
|
13
|
+
:country,
|
14
|
+
:type,
|
15
|
+
:iban,
|
16
|
+
:accountNum,
|
17
|
+
:accountHolderName,
|
18
|
+
:swiftBic,
|
19
|
+
:branchId,
|
20
|
+
:bankId,
|
21
|
+
:bankName,
|
22
|
+
:bankAddress,
|
23
|
+
:bankCity,
|
24
|
+
:bankRegionCode,
|
25
|
+
:bankPostalCode,
|
26
|
+
:status,
|
27
|
+
:disabledAt
|
28
|
+
)
|
5
29
|
end
|
6
|
-
end
|
30
|
+
end
|
@@ -1,7 +1,10 @@
|
|
1
1
|
require_relative '../Client.rb'
|
2
|
+
require_relative 'GatewayHelper'
|
2
3
|
|
3
4
|
module PaymentRails
|
4
5
|
class BatchGateway
|
6
|
+
include GatewayHelper
|
7
|
+
|
5
8
|
def initialize(client)
|
6
9
|
@client = client
|
7
10
|
end
|
@@ -51,9 +54,7 @@ module PaymentRails
|
|
51
54
|
data = JSON.parse(response)
|
52
55
|
data.each do |key, value|
|
53
56
|
next unless key === 'batch'
|
54
|
-
|
55
|
-
batch.send("#{newKey}=", newValue)
|
56
|
-
end
|
57
|
+
loosely_hydrate_model(batch, value)
|
57
58
|
end
|
58
59
|
batch
|
59
60
|
end
|
@@ -64,9 +65,7 @@ module PaymentRails
|
|
64
65
|
data = JSON.parse(response)
|
65
66
|
data.each do |key, value|
|
66
67
|
next unless key === 'batchSummary'
|
67
|
-
|
68
|
-
summary.send("#{newKey}=", newValue)
|
69
|
-
end
|
68
|
+
loosely_hydrate_model(summary, value)
|
70
69
|
end
|
71
70
|
summary
|
72
71
|
end
|
@@ -78,14 +77,12 @@ module PaymentRails
|
|
78
77
|
data.each do |key, value|
|
79
78
|
next unless key === 'batches'
|
80
79
|
value.each do |newKey, _newValue|
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
end
|
85
|
-
batches.push(batch)
|
80
|
+
batches.push(
|
81
|
+
loosely_hydrate_model(Batch.new, newKey)
|
82
|
+
)
|
86
83
|
end
|
87
84
|
end
|
88
85
|
batches
|
89
86
|
end
|
90
87
|
end
|
91
|
-
end
|
88
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module PaymentRails
|
2
|
+
module GatewayHelper
|
3
|
+
def loosely_hydrate_model(klass_instance, attributes)
|
4
|
+
attributes.each do |k, v|
|
5
|
+
begin
|
6
|
+
klass_instance.send("#{k}=", v)
|
7
|
+
rescue NoMethodError
|
8
|
+
warn "[PaymentRails] Unknown attribute #{k} for class #{klass_instance.class.name}"
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
klass_instance
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
require_relative '../Client.rb'
|
2
|
+
require_relative 'GatewayHelper'
|
3
|
+
|
4
|
+
module PaymentRails
|
5
|
+
class OfflinePaymentGateway
|
6
|
+
include GatewayHelper
|
7
|
+
|
8
|
+
def initialize(client)
|
9
|
+
@client = client
|
10
|
+
end
|
11
|
+
|
12
|
+
def create(recipient_id, body)
|
13
|
+
response = @client.post('/v1/recipients/' + recipient_id + '/offlinePayments', body)
|
14
|
+
offline_payment_builder(response)
|
15
|
+
end
|
16
|
+
|
17
|
+
def update(recipient_id, offline_payment_id, body)
|
18
|
+
@client.patch('/v1/recipients/' + recipient_id + '/offlinePayments/' + offline_payment_id, body)
|
19
|
+
true
|
20
|
+
end
|
21
|
+
|
22
|
+
def delete(recipient_id, offline_payment_id)
|
23
|
+
@client.delete('/v1/recipients/' + recipient_id + '/offlinePayments/' + offline_payment_id)
|
24
|
+
true
|
25
|
+
end
|
26
|
+
|
27
|
+
def search(recipient_id = '', page = 1, page_size = 10, term = '')
|
28
|
+
if recipient_id === ''
|
29
|
+
response = @client.get('/v1/offline-payments?page=' + page.to_s + '&pageSize=' + page_size.to_s + '&search=' + term)
|
30
|
+
else
|
31
|
+
response = @client.get('/v1/recipients/' + recipient_id + '/offlinePayments?page=' + page.to_s + '&pageSize=' + page_size.to_s + '&search=' + term)
|
32
|
+
end
|
33
|
+
|
34
|
+
offline_payments_list_builder(response)
|
35
|
+
end
|
36
|
+
|
37
|
+
def offline_payment_builder(response)
|
38
|
+
offline_payment = OfflinePayment.new
|
39
|
+
data = JSON.parse(response)
|
40
|
+
data.each do |key, value|
|
41
|
+
next unless key === 'offlinePayment'
|
42
|
+
loosely_hydrate_model(offline_payment, value)
|
43
|
+
end
|
44
|
+
offline_payment
|
45
|
+
end
|
46
|
+
|
47
|
+
def offline_payments_list_builder(response)
|
48
|
+
offline_payments = []
|
49
|
+
data = JSON.parse(response)
|
50
|
+
|
51
|
+
data.each do |key, value|
|
52
|
+
next unless key === 'offlinePayments'
|
53
|
+
value.each do |newKey, _newValue|
|
54
|
+
offline_payment = loosely_hydrate_model(OfflinePayment.new, newKey)
|
55
|
+
offline_payments.push(offline_payment)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
offline_payments
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -1,7 +1,10 @@
|
|
1
1
|
require_relative '../Client.rb'
|
2
|
+
require_relative 'GatewayHelper'
|
2
3
|
|
3
4
|
module PaymentRails
|
4
5
|
class PaymentGateway
|
6
|
+
include GatewayHelper
|
7
|
+
|
5
8
|
def initialize(client)
|
6
9
|
@client = client
|
7
10
|
end
|
@@ -36,9 +39,7 @@ module PaymentRails
|
|
36
39
|
data = JSON.parse(response)
|
37
40
|
data.each do |key, value|
|
38
41
|
next unless key === 'payment'
|
39
|
-
|
40
|
-
payment.send("#{recipKey}=", recipValue)
|
41
|
-
end
|
42
|
+
loosely_hydrate_model(payment, value)
|
42
43
|
end
|
43
44
|
payment
|
44
45
|
end
|
@@ -50,14 +51,11 @@ module PaymentRails
|
|
50
51
|
data.each do |key, value|
|
51
52
|
next unless key === 'payments'
|
52
53
|
value.each do |newKey, _newValue|
|
53
|
-
payment = Payment.new
|
54
|
-
newKey.each do |key1, value1|
|
55
|
-
payment.send("#{key1}=", value1)
|
56
|
-
end
|
54
|
+
payment = loosely_hydrate_model(Payment.new, newKey)
|
57
55
|
payments.push(payment)
|
58
56
|
end
|
59
57
|
end
|
60
58
|
payments
|
61
59
|
end
|
62
60
|
end
|
63
|
-
end
|
61
|
+
end
|
@@ -1,7 +1,10 @@
|
|
1
1
|
require_relative '../Client.rb'
|
2
|
+
require_relative 'GatewayHelper'
|
2
3
|
|
3
4
|
module PaymentRails
|
4
5
|
class RecipientAccountGateway
|
6
|
+
include GatewayHelper
|
7
|
+
|
5
8
|
def initialize(client)
|
6
9
|
@client = client
|
7
10
|
end
|
@@ -22,7 +25,7 @@ module PaymentRails
|
|
22
25
|
end
|
23
26
|
|
24
27
|
def update(recipient_id, recipient_account_id, body)
|
25
|
-
response = @client.patch('/v1/recipients/' + recipient_id
|
28
|
+
response = @client.patch('/v1/recipients/' + recipient_id + '/accounts/' + recipient_account_id, body)
|
26
29
|
recipient_account_builder(response)
|
27
30
|
end
|
28
31
|
|
@@ -36,9 +39,7 @@ module PaymentRails
|
|
36
39
|
data = JSON.parse(response)
|
37
40
|
data.each do |key, value|
|
38
41
|
next unless key === 'account'
|
39
|
-
|
40
|
-
recipient_account.send("#{recipKey}=", recipValue)
|
41
|
-
end
|
42
|
+
loosely_hydrate_model(recipient_account, value)
|
42
43
|
end
|
43
44
|
recipient_account
|
44
45
|
end
|
@@ -50,14 +51,11 @@ module PaymentRails
|
|
50
51
|
data.each do |key, value|
|
51
52
|
next unless key === 'accounts'
|
52
53
|
value.each do |newKey, _newValue|
|
53
|
-
recipient_account = RecipientAccount.new
|
54
|
-
newKey.each do |key1, value1|
|
55
|
-
recipient_account.send("#{key1}=", value1)
|
56
|
-
end
|
54
|
+
recipient_account = loosely_hydrate_model(RecipientAccount.new, newKey)
|
57
55
|
recipient_accounts.push(recipient_account)
|
58
56
|
end
|
59
57
|
end
|
60
58
|
recipient_accounts
|
61
59
|
end
|
62
60
|
end
|
63
|
-
end
|
61
|
+
end
|
@@ -1,7 +1,10 @@
|
|
1
1
|
require_relative '../Client.rb'
|
2
|
+
require_relative 'GatewayHelper'
|
2
3
|
|
3
4
|
module PaymentRails
|
4
5
|
class RecipientGateway
|
6
|
+
include GatewayHelper
|
7
|
+
|
5
8
|
def initialize(client)
|
6
9
|
@client = client
|
7
10
|
end
|
@@ -36,9 +39,7 @@ module PaymentRails
|
|
36
39
|
data = JSON.parse(response)
|
37
40
|
data.each do |key, value|
|
38
41
|
next unless key === 'recipient'
|
39
|
-
|
40
|
-
recipient.send("#{recipKey}=", recipValue)
|
41
|
-
end
|
42
|
+
loosely_hydrate_model(recipient, value)
|
42
43
|
end
|
43
44
|
recipient
|
44
45
|
end
|
@@ -50,14 +51,11 @@ module PaymentRails
|
|
50
51
|
data.each do |key, value|
|
51
52
|
next unless key === 'recipients'
|
52
53
|
value.each do |newKey, _newValue|
|
53
|
-
recipient = Recipient.new
|
54
|
-
newKey.each do |key1, value1|
|
55
|
-
recipient.send("#{key1}=", value1)
|
56
|
-
end
|
54
|
+
recipient = loosely_hydrate_model(Recipient.new, newKey)
|
57
55
|
recipients.push(recipient)
|
58
56
|
end
|
59
57
|
end
|
60
58
|
recipients
|
61
59
|
end
|
62
60
|
end
|
63
|
-
end
|
61
|
+
end
|
data/paymentrails.gemspec
CHANGED
@@ -4,12 +4,15 @@ Gem::Specification.new do |s|
|
|
4
4
|
s.name = "paymentrails"
|
5
5
|
s.summary = "PaymentRails Ruby SDK"
|
6
6
|
s.description = "Ruby SDK for interacting with the PaymentRails API"
|
7
|
-
s.version = '0.2.
|
7
|
+
s.version = '0.2.6'
|
8
8
|
s.homepage = 'https://www.paymentrails.com/'
|
9
|
-
s.email = ['
|
9
|
+
s.email = ['joshua@paymentrails.com']
|
10
10
|
s.license = "MIT"
|
11
11
|
s.author = "PaymentRails"
|
12
|
-
s.has_rdoc = false
|
13
12
|
s.files = Dir.glob ["README.rdoc", "LICENSE", "lib/**/*.{rb,crt}", "spec/**/*", "*.gemspec"]
|
14
|
-
s.
|
13
|
+
s.required_ruby_version = '>= 2.4'
|
14
|
+
s.add_development_dependency 'dotenv', '~> 2'
|
15
|
+
s.add_development_dependency 'rake', '~> 12'
|
16
|
+
s.add_development_dependency "rubocop", '~> 0.77.0'
|
17
|
+
s.add_development_dependency 'test-unit', '~> 3'
|
15
18
|
end
|
@@ -1,10 +1,13 @@
|
|
1
|
-
require_relative '
|
2
|
-
require 'test/unit'
|
3
|
-
require 'securerandom'
|
1
|
+
require_relative 'helper'
|
4
2
|
|
5
3
|
class BatchTest < Test::Unit::TestCase
|
6
4
|
def setup
|
7
|
-
@client = PaymentRails
|
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
|
+
)
|
8
11
|
end
|
9
12
|
|
10
13
|
def create_recipient
|
@@ -1,10 +1,13 @@
|
|
1
|
-
require_relative '
|
2
|
-
require 'test/unit'
|
3
|
-
require 'securerandom'
|
1
|
+
require_relative 'helper'
|
4
2
|
|
5
3
|
class RecipientTest < Test::Unit::TestCase
|
6
4
|
def setup
|
7
|
-
@client = PaymentRails
|
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
|
+
)
|
8
11
|
end
|
9
12
|
|
10
13
|
def test_create
|
@@ -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.paymentrails.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.paymentrails.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
CHANGED
@@ -1,32 +1,73 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: paymentrails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- PaymentRails
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-07-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: dotenv
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 2
|
20
|
-
type: :
|
19
|
+
version: '2'
|
20
|
+
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 2
|
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'
|
27
69
|
description: Ruby SDK for interacting with the PaymentRails API
|
28
70
|
email:
|
29
|
-
- jesse.silber@paymentrails.com
|
30
71
|
- joshua@paymentrails.com
|
31
72
|
executables: []
|
32
73
|
extensions: []
|
@@ -41,17 +82,23 @@ files:
|
|
41
82
|
- lib/paymentrails/Configuration.rb
|
42
83
|
- lib/paymentrails/Exceptions.rb
|
43
84
|
- lib/paymentrails/Gateway.rb
|
85
|
+
- lib/paymentrails/OfflinePayment.rb
|
44
86
|
- lib/paymentrails/Payment.rb
|
45
87
|
- lib/paymentrails/Recipient.rb
|
46
88
|
- lib/paymentrails/RecipientAccount.rb
|
47
89
|
- lib/paymentrails/gateways/BalanceGateway.rb
|
48
90
|
- lib/paymentrails/gateways/BatchGateway.rb
|
91
|
+
- lib/paymentrails/gateways/GatewayHelper.rb
|
92
|
+
- lib/paymentrails/gateways/OfflinePaymentGateway.rb
|
49
93
|
- lib/paymentrails/gateways/PaymentGateway.rb
|
50
94
|
- lib/paymentrails/gateways/RecipientAccountGateway.rb
|
51
95
|
- lib/paymentrails/gateways/RecipientGateway.rb
|
52
96
|
- paymentrails.gemspec
|
53
97
|
- spec/integration/BatchTest.rb
|
54
98
|
- spec/integration/RecipientTest.rb
|
99
|
+
- spec/integration/helper.rb
|
100
|
+
- spec/unit/ConfigurationTest.rb
|
101
|
+
- spec/unit/PaymentRailsTest.rb
|
55
102
|
homepage: https://www.paymentrails.com/
|
56
103
|
licenses:
|
57
104
|
- MIT
|
@@ -64,7 +111,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
64
111
|
requirements:
|
65
112
|
- - ">="
|
66
113
|
- !ruby/object:Gem::Version
|
67
|
-
version: '
|
114
|
+
version: '2.4'
|
68
115
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
69
116
|
requirements:
|
70
117
|
- - ">="
|