paymentrails 0.1.2 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f10dfe6a1de6364a6f4cd84fcd70379e5e82fb8a9d3deee9fe8568f98f775386
4
- data.tar.gz: 05bb3e71ac29f285430f7713fb126347b1f60159eb62272ff1504dc80251155c
3
+ metadata.gz: 4baf68c202c58008adf60a8ff50d5779d188f53858d622b16c64affc145dfd29
4
+ data.tar.gz: 69662b23f889833d6517dd5154aec6b0be48022b07a2fcba8b24f9bd3faa749a
5
5
  SHA512:
6
- metadata.gz: 86e87a2dff1c9a22b00532315b6f9ab97206afb7703ae2f81d5433a5e1769e22fe03af3182575acdc34a1c2ef9128cf287ccb36a4d622d1a614bfd8513c02d10
7
- data.tar.gz: e78456012f1203d16b952307b5a32ce4e6c516c015bce003f18d922afc8c4937a2073b28ad4765de8351ee5467b9b3fd1c0fdb54d4265a1d5c6b7161334fe353
6
+ metadata.gz: c1ab530137667572959a151a4e2364dd55bcdbbdbe8d580ea50403ca3abf7a318081409ebbb5d966c070a86641c43187c991e9149a11d7b50d541a6b43ae4fb1
7
+ data.tar.gz: db934880345ba92aee92ac8b3cee97d06e0affe62b9fac5206e63dd741b89de48ccc051e5d2a4477c748372df9dbae44b4288ee1bc74734742916120fd47dafd
@@ -1,33 +1,23 @@
1
- class PaymentRails
2
- attr_reader :recipient
3
- attr_writer :recipient
4
-
5
- attr_reader :recipient_account
6
- attr_writer :recipient_account
7
-
8
- attr_reader :batch
9
- attr_writer :batch
10
-
11
- attr_reader :payment
12
- attr_writer :payment
13
-
14
- attr_reader :balance
15
- attr_writer :balance
16
-
17
- def initialize(key, secret, environment = 'production')
18
- load 'Configuration.rb'
19
- load 'Gateway.rb'
20
-
1
+ require 'paymentrails/Configuration'
2
+ require 'paymentrails/Gateway'
3
+
4
+ require 'paymentrails/gateways/BalanceGateway'
5
+ require 'paymentrails/gateways/BatchGateway'
6
+ require 'paymentrails/gateways/PaymentGateway'
7
+ require 'paymentrails/gateways/RecipientGateway'
8
+ require 'paymentrails/gateways/RecipientAccountGateway'
9
+
10
+ require 'paymentrails/Balance'
11
+ require 'paymentrails/Batch'
12
+ require 'paymentrails/BatchSummary'
13
+ require 'paymentrails/Exceptions'
14
+ require 'paymentrails/Payment'
15
+ require 'paymentrails/Recipient'
16
+ require 'paymentrails/RecipientAccount'
17
+
18
+ module PaymentRails
19
+ def self.client(key, secret, environment = 'production')
21
20
  client = Gateway.new(Configuration.new(key, secret, environment))
22
- @recipient = client.recipient
23
- @recipient_account = client.recipient_account
24
- @batch = client.batch
25
- @payment = client.payment
26
- @balance = client.balance
27
-
28
- # to avoid overriding potential global Configuration & Gateway
29
- Object.send(:remove_const, :Gateway)
30
- Object.send(:remove_const, :Configuration)
21
+ return client
31
22
  end
32
-
33
23
  end
@@ -0,0 +1,4 @@
1
+ module PaymentRails
2
+ class Balance
3
+ end
4
+ end
@@ -0,0 +1,6 @@
1
+ module PaymentRails
2
+ class Batch
3
+ attr_accessor :id, :amount, :completedAt, :createdAt, :currency, :description, :sentAt, :status, :totalPayments, :updatedAt, :quoteExpiredAt, :payments, :tags, :coverFees
4
+ attr_writer :id, :amount, :completedAt, :createdAt, :currency, :description, :sentAt, :status, :totalPayments, :updatedAt, :quoteExpiredAt, :payments, :tags, :coverFees
5
+ end
6
+ end
@@ -0,0 +1,6 @@
1
+ module PaymentRails
2
+ class BatchSummary
3
+ attr_accessor :id, :amount, :completedAt, :createdAt, :currency, :description, :sentAt, :status, :totalPayments, :updatedAt, :methods, :detail, :total
4
+ attr_writer :id, :amount, :completedAt, :createdAt, :currency, :description, :sentAt, :status, :totalPayments, :updatedAt, :methods, :detail, :total
5
+ end
6
+ end
@@ -0,0 +1,99 @@
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
+ module PaymentRails
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 DownForMaintenanceError, message
94
+ else
95
+ raise UnexpectedError, message
96
+ end
97
+ end
98
+ end
99
+ end
@@ -0,0 +1,33 @@
1
+ module PaymentRails
2
+ class Configuration
3
+
4
+ def initialize(publicKey, privateKey, environment = 'production')
5
+ @publicKey = publicKey
6
+ @privateKey = privateKey
7
+ @apiBase = set_environment(environment)
8
+ end
9
+
10
+ def set_environment(apiBase)
11
+ case apiBase
12
+ when 'production'
13
+ 'https://api.paymentrails.com'
14
+ when 'development'
15
+ 'https://api.railz.io'
16
+ when 'integration'
17
+ 'http://api.local.dev:3000'
18
+ else
19
+ 'https://api.paymentrails.com'
20
+ end
21
+ end
22
+
23
+ attr_reader :publicKey
24
+
25
+ attr_writer :publicKey
26
+
27
+ attr_reader :privateKey
28
+
29
+ attr_writer :privateKey
30
+
31
+ attr_reader :apiBase
32
+ end
33
+ end
@@ -1,17 +1,19 @@
1
+ module PaymentRails
1
2
  class PaymentRailsError < ::StandardError; end
2
-
3
+
3
4
  class AuthenticationError < PaymentRailsError; end
4
-
5
+
5
6
  class AuthorizationError < PaymentRailsError; end
6
-
7
+
7
8
  class DownForMaintenanceError < PaymentRailsError; end
8
-
9
+
9
10
  class NotFoundError < PaymentRailsError; end
10
-
11
+
11
12
  class ServerError < PaymentRailsError; end
12
-
13
+
13
14
  class TooManyRequestsError < PaymentRailsError; end
14
-
15
+
15
16
  class UnexpectedError < PaymentRailsError; end
16
17
 
17
- class MalformedException < PaymentRailsError; end
18
+ class MalformedException < PaymentRailsError; end
19
+ end
@@ -0,0 +1,34 @@
1
+ module PaymentRails
2
+ class Gateway
3
+ attr_reader :config
4
+ attr_writer :config
5
+
6
+ attr_reader :client
7
+ attr_writer :client
8
+
9
+ attr_reader :recipient
10
+ attr_writer :recipient
11
+
12
+ attr_reader :recipient_account
13
+ attr_writer :recipient_account
14
+
15
+ attr_reader :batch
16
+ attr_writer :batch
17
+
18
+ attr_reader :payment
19
+ attr_writer :payment
20
+
21
+ attr_reader :balance
22
+ attr_writer :balance
23
+
24
+ def initialize(config)
25
+ @config = config
26
+ @client = Client.new(config)
27
+ @recipient = RecipientGateway.new(client)
28
+ @recipient_account = RecipientAccountGateway.new(client)
29
+ @batch = BatchGateway.new(client)
30
+ @payment = PaymentGateway.new(client)
31
+ @balance = BalanceGateway.new(client)
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,6 @@
1
+ module PaymentRails
2
+ class Payment
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, :coverFees, :category, :amount, :currency, :taxReportable, :taxBasisAmount, :taxBasisCurrency, :tags, :account, :initiatedAt, :settledAt, :returnedAt, :failureMessage, :merchantId
4
+ 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, :coverFees, :category, :amount, :currency, :taxReportable, :taxBasisAmount, :taxBasisCurrency, :tags, :account, :initiatedAt, :settledAt, :returnedAt, :failureMessage, :merchantId
5
+ end
6
+ end
@@ -0,0 +1,6 @@
1
+ module PaymentRails
2
+ class Recipient
3
+ 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
4
+ 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
5
+ end
6
+ end
@@ -0,0 +1,6 @@
1
+ module PaymentRails
2
+ class RecipientAccount
3
+ attr_accessor :id, :primary, :currency, :recipientAccountId, :recipientId, :recipientReferenceId, :routeType, :recipientFees, :emailAddress, :country, :type, :iban, :accountNum, :accountHolderName, :swiftBic, :branchId, :bankId, :bankName, :bankAddress, :bankCity, :bankRegionCode, :bankPostalCode, :status, :disabledAt
4
+ attr_writer :id, :primary, :currency, :recipientAccountId, :recipientId, :recipientReferenceId, :routeType, :recipientFees, :emailAddress, :country, :type, :iban, :accountNum, :accountHolderName, :swiftBic, :branchId, :bankId, :bankName, :bankAddress, :bankCity, :bankRegionCode, :bankPostalCode, :status, :disabledAt
5
+ end
6
+ end
@@ -0,0 +1,15 @@
1
+ require_relative '../Client.rb'
2
+
3
+ module PaymentRails
4
+ class BalanceGateway
5
+ def initialize(client)
6
+ @client = client
7
+ end
8
+
9
+ def find(term = '')
10
+ response = @client.get('/v1/balances/' + term )
11
+ JSON.parse(response, object_class: OpenStruct)
12
+ end
13
+
14
+ end
15
+ end
@@ -0,0 +1,91 @@
1
+ require_relative '../Client.rb'
2
+
3
+ module PaymentRails
4
+ class BatchGateway
5
+ def initialize(client)
6
+ @client = client
7
+ end
8
+
9
+ def find(batch_id)
10
+ response = @client.get('/v1/batches/' + batch_id)
11
+ batch_builder(response)
12
+ end
13
+
14
+ def all
15
+ response = @client.get('/v1/batches/')
16
+ batch_list_builder(response)
17
+ end
18
+
19
+ def create(body)
20
+ response = @client.post('/v1/batches/', body)
21
+ batch_builder(response)
22
+ end
23
+
24
+ def update(batch_id, body)
25
+ @client.patch('/v1/batches/' + batch_id, body)
26
+ true
27
+ end
28
+
29
+ def delete(batch_id)
30
+ @client.delete('/v1/batches/' + batch_id)
31
+ true
32
+ end
33
+
34
+ def generate_quote(batch_id)
35
+ response = @client.post('/v1/batches/' + batch_id + '/generate-quote', {})
36
+ batch_builder(response)
37
+ end
38
+
39
+ def start_processing(batch_id)
40
+ response = @client.post('/v1/batches/' + batch_id + '/start-processing', {})
41
+ batch_builder(response)
42
+ end
43
+
44
+ def search(page = 1, page_size = 10, term = '')
45
+ response = @client.get('/v1/batches?page=' + page.to_s + '&pageSize=' + page_size.to_s + '&search=' + term)
46
+ batch_list_builder(response)
47
+ end
48
+
49
+ def batch_builder(response)
50
+ batch = Batch.new
51
+ data = JSON.parse(response)
52
+ data.each do |key, value|
53
+ next unless key === 'batch'
54
+ value.each do |newKey, newValue|
55
+ batch.send("#{newKey}=", newValue)
56
+ end
57
+ end
58
+ batch
59
+ end
60
+
61
+ def summary(batch_id)
62
+ response = @client.get('/v1/batches/' + batch_id + '/summary')
63
+ summary = BatchSummary.new
64
+ data = JSON.parse(response)
65
+ data.each do |key, value|
66
+ next unless key === 'batchSummary'
67
+ value.each do |newKey, newValue|
68
+ summary.send("#{newKey}=", newValue)
69
+ end
70
+ end
71
+ summary
72
+ end
73
+
74
+ def batch_list_builder(response)
75
+ batches = []
76
+ data = JSON.parse(response)
77
+
78
+ data.each do |key, value|
79
+ next unless key === 'batches'
80
+ value.each do |newKey, _newValue|
81
+ batch = Batch.new
82
+ newKey.each do |key1, value1|
83
+ batch.send("#{key1}=", value1)
84
+ end
85
+ batches.push(batch)
86
+ end
87
+ end
88
+ batches
89
+ end
90
+ end
91
+ end
@@ -0,0 +1,63 @@
1
+ require_relative '../Client.rb'
2
+
3
+ module PaymentRails
4
+ class PaymentGateway
5
+ def initialize(client)
6
+ @client = client
7
+ end
8
+
9
+ def find(batch_id, payment_id)
10
+ response = @client.get('/v1/batches/' + batch_id + '/payments/' + payment_id)
11
+ payment_builder(response)
12
+ end
13
+
14
+ def create(batch_id, body)
15
+ response = @client.post('/v1/batches/' + batch_id + '/payments', body)
16
+ payment_builder(response)
17
+ end
18
+
19
+ def update(batch_id, payment_id, body)
20
+ @client.patch('/v1/batches/' + batch_id + '/payments/' + payment_id, body)
21
+ true
22
+ end
23
+
24
+ def delete(batch_id, payment_id)
25
+ @client.delete('/v1/batches/' + batch_id + '/payments/' + payment_id)
26
+ true
27
+ end
28
+
29
+ def search(batch_id, page = 1, page_size = 10, term = '')
30
+ response = @client.get('/v1/batches/' + batch_id.to_s + '/payments?page=' + page.to_s + '&pageSize=' + page_size.to_s + '&search=' + term)
31
+ payments_list_builder(response)
32
+ end
33
+
34
+ def payment_builder(response)
35
+ payment = Payment.new
36
+ data = JSON.parse(response)
37
+ data.each do |key, value|
38
+ next unless key === 'payment'
39
+ value.each do |recipKey, recipValue|
40
+ payment.send("#{recipKey}=", recipValue)
41
+ end
42
+ end
43
+ payment
44
+ end
45
+
46
+ def payments_list_builder(response)
47
+ payments = []
48
+ data = JSON.parse(response)
49
+
50
+ data.each do |key, value|
51
+ next unless key === 'payments'
52
+ value.each do |newKey, _newValue|
53
+ payment = Payment.new
54
+ newKey.each do |key1, value1|
55
+ payment.send("#{key1}=", value1)
56
+ end
57
+ payments.push(payment)
58
+ end
59
+ end
60
+ payments
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,63 @@
1
+ require_relative '../Client.rb'
2
+
3
+ module PaymentRails
4
+ class RecipientAccountGateway
5
+ def initialize(client)
6
+ @client = client
7
+ end
8
+
9
+ def find(recipient_id, recipient_account_id)
10
+ response = @client.get('/v1/recipients/' + recipient_id + '/accounts/' + recipient_account_id)
11
+ recipient_account_builder(response)
12
+ end
13
+
14
+ def all(recipient_id)
15
+ response = @client.get('/v1/recipients/' + recipient_id + '/accounts/')
16
+ recipient_account_list_builder(response)
17
+ end
18
+
19
+ def create(recipient_id, body)
20
+ response = @client.post('/v1/recipients/' + recipient_id + '/accounts', body)
21
+ recipient_account_builder(response)
22
+ end
23
+
24
+ def update(recipient_id, recipient_account_id, body)
25
+ response = @client.patch('/v1/recipients/' + recipient_id, + '/accounts/' + recipient_account_id, body)
26
+ recipient_account_builder(response)
27
+ end
28
+
29
+ def delete(recipient_id, recipient_account_id)
30
+ @client.delete('/v1/recipients/' + recipient_id + '/accounts/' + recipient_account_id)
31
+ true
32
+ end
33
+
34
+ def recipient_account_builder(response)
35
+ recipient_account = RecipientAccount.new
36
+ data = JSON.parse(response)
37
+ data.each do |key, value|
38
+ next unless key === 'account'
39
+ value.each do |recipKey, recipValue|
40
+ recipient_account.send("#{recipKey}=", recipValue)
41
+ end
42
+ end
43
+ recipient_account
44
+ end
45
+
46
+ def recipient_account_list_builder(response)
47
+ recipient_accounts = []
48
+ data = JSON.parse(response)
49
+
50
+ data.each do |key, value|
51
+ next unless key === 'accounts'
52
+ value.each do |newKey, _newValue|
53
+ recipient_account = RecipientAccount.new
54
+ newKey.each do |key1, value1|
55
+ recipient_account.send("#{key1}=", value1)
56
+ end
57
+ recipient_accounts.push(recipient_account)
58
+ end
59
+ end
60
+ recipient_accounts
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,63 @@
1
+ require_relative '../Client.rb'
2
+
3
+ module PaymentRails
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
63
+ end
@@ -4,7 +4,7 @@ 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.1.2'
7
+ s.version = '0.2.0'
8
8
  s.homepage = 'https://www.paymentrails.com/'
9
9
  s.email = ['jesse.silber@paymentrails.com', 'joshua@paymentrails.com']
10
10
  s.license = "MIT"
@@ -1,10 +1,10 @@
1
- Dir[File.join(__dir__, '../../lib', '*.rb')].each { |file| require file }
1
+ require_relative '../../lib/paymentrails'
2
2
  require 'test/unit'
3
3
  require 'securerandom'
4
4
 
5
5
  class BatchTest < Test::Unit::TestCase
6
6
  def setup
7
- @client = Gateway.new(Configuration.new('YOUR-API-KEY', 'YOUR-API-SECRET'))
7
+ @client = PaymentRails::Gateway.new(PaymentRails::Configuration.new('YOUR-API-KEY', 'YOUR-SECRET-KEY'))
8
8
  end
9
9
 
10
10
  def create_recipient
@@ -1,10 +1,10 @@
1
- Dir[File.join(__dir__, '../../lib', '*.rb')].each { |file| require file }
1
+ require_relative '../../lib/paymentrails'
2
2
  require 'test/unit'
3
3
  require 'securerandom'
4
4
 
5
5
  class RecipientTest < Test::Unit::TestCase
6
6
  def setup
7
- @client = Gateway.new(Configuration.new('YOUR-API-KEY', 'YOUR-API-SECRET'))
7
+ @client = PaymentRails::Gateway.new(PaymentRails::Configuration.new('YOUR-API-KEY', 'YOUR-SECRET-KEY'))
8
8
  end
9
9
 
10
10
  def test_create
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: paymentrails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - PaymentRails
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-05-28 00:00:00.000000000 Z
11
+ date: 2019-06-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client
@@ -33,22 +33,22 @@ extensions: []
33
33
  extra_rdoc_files: []
34
34
  files:
35
35
  - LICENSE
36
- - lib/Balance.rb
37
- - lib/BalanceGateway.rb
38
- - lib/Batch.rb
39
- - lib/BatchGateway.rb
40
- - lib/BatchSummary.rb
41
- - lib/Client.rb
42
- - lib/Configuration.rb
43
- - lib/Exceptions.rb
44
- - lib/Gateway.rb
45
- - lib/Payment.rb
46
- - lib/PaymentGateway.rb
47
- - lib/Recipient.rb
48
- - lib/RecipientAccount.rb
49
- - lib/RecipientAccountGateway.rb
50
- - lib/RecipientGateway.rb
51
36
  - lib/paymentrails.rb
37
+ - lib/paymentrails/Balance.rb
38
+ - lib/paymentrails/Batch.rb
39
+ - lib/paymentrails/BatchSummary.rb
40
+ - lib/paymentrails/Client.rb
41
+ - lib/paymentrails/Configuration.rb
42
+ - lib/paymentrails/Exceptions.rb
43
+ - lib/paymentrails/Gateway.rb
44
+ - lib/paymentrails/Payment.rb
45
+ - lib/paymentrails/Recipient.rb
46
+ - lib/paymentrails/RecipientAccount.rb
47
+ - lib/paymentrails/gateways/BalanceGateway.rb
48
+ - lib/paymentrails/gateways/BatchGateway.rb
49
+ - lib/paymentrails/gateways/PaymentGateway.rb
50
+ - lib/paymentrails/gateways/RecipientAccountGateway.rb
51
+ - lib/paymentrails/gateways/RecipientGateway.rb
52
52
  - paymentrails.gemspec
53
53
  - spec/integration/BatchTest.rb
54
54
  - spec/integration/RecipientTest.rb
File without changes
@@ -1,13 +0,0 @@
1
- require_relative 'Client.rb'
2
-
3
- class BalanceGateway
4
- def initialize(client)
5
- @client = client
6
- end
7
-
8
- def find(term = '')
9
- response = @client.get('/v1/balances/' + term )
10
- JSON.parse(response, object_class: OpenStruct)
11
- end
12
-
13
- end
@@ -1,4 +0,0 @@
1
- class Batch
2
- attr_accessor :id, :amount, :completedAt, :createdAt, :currency, :description, :sentAt, :status, :totalPayments, :updatedAt, :quoteExpiredAt, :payments, :tags, :coverFees
3
- attr_writer :id, :amount, :completedAt, :createdAt, :currency, :description, :sentAt, :status, :totalPayments, :updatedAt, :quoteExpiredAt, :payments, :tags, :coverFees
4
- end
@@ -1,89 +0,0 @@
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
@@ -1,4 +0,0 @@
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
@@ -1,103 +0,0 @@
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 DownForMaintenanceError, message
94
- else
95
- raise UnexpectedError, message
96
- end
97
- end
98
- end
99
-
100
-
101
-
102
-
103
-
@@ -1,31 +0,0 @@
1
- class Configuration
2
-
3
- def initialize(publicKey, privateKey, environment = 'production')
4
- @publicKey = publicKey
5
- @privateKey = privateKey
6
- @apiBase = set_environment(environment)
7
- end
8
-
9
- def set_environment(apiBase)
10
- case apiBase
11
- when 'production'
12
- 'https://api.paymentrails.com'
13
- when 'development'
14
- 'https://api.railz.io'
15
- when 'integration'
16
- 'http://api.local.dev:3000'
17
- else
18
- 'https://api.paymentrails.com'
19
- end
20
- end
21
-
22
- attr_reader :publicKey
23
-
24
- attr_writer :publicKey
25
-
26
- attr_reader :privateKey
27
-
28
- attr_writer :privateKey
29
-
30
- attr_reader :apiBase
31
- end
@@ -1,38 +0,0 @@
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
@@ -1,4 +0,0 @@
1
- class Payment
2
- 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, :coverFees, :category, :amount, :currency, :taxReportable, :taxBasisAmount, :taxBasisCurrency, :tags, :account, :initiatedAt, :settledAt, :returnedAt, :failureMessage, :merchantId
3
- 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, :coverFees, :category, :amount, :currency, :taxReportable, :taxBasisAmount, :taxBasisCurrency, :tags, :account, :initiatedAt, :settledAt, :returnedAt, :failureMessage, :merchantId
4
- end
@@ -1,61 +0,0 @@
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
@@ -1,4 +0,0 @@
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
@@ -1,4 +0,0 @@
1
- class RecipientAccount
2
- attr_accessor :id, :primary, :currency, :recipientAccountId, :recipientId, :recipientReferenceId, :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, :recipientId, :recipientReferenceId, :routeType, :recipientFees, :emailAddress, :country, :type, :iban, :accountNum, :accountHolderName, :swiftBic, :branchId, :bankId, :bankName, :bankAddress, :bankCity, :bankRegionCode, :bankPostalCode, :status, :disabledAt
4
- end
@@ -1,61 +0,0 @@
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
@@ -1,62 +0,0 @@
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