fintecture 0.4.0 → 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +17 -17
- data/.rspec +3 -3
- data/.travis.yml +7 -7
- data/CODE_OF_CONDUCT.md +74 -74
- data/Gemfile +8 -8
- data/Gemfile.lock +59 -59
- data/LICENSE.txt +674 -674
- data/README.md +407 -407
- data/Rakefile +8 -8
- data/bin/console +15 -15
- data/bin/setup +8 -8
- data/exemples/ais.rb +53 -53
- data/exemples/config_ais.json +7 -7
- data/exemples/config_pis.json +5 -5
- data/exemples/pis.rb +148 -148
- data/exemples/ressources.rb +23 -23
- data/fintecture.gemspec +44 -44
- data/lib/fintecture/ais_client.rb +94 -94
- data/lib/fintecture/api/ais/account_holders.rb +61 -61
- data/lib/fintecture/api/ais/accounts.rb +63 -63
- data/lib/fintecture/api/ais/authorize.rb +72 -72
- data/lib/fintecture/api/ais/authorize_decoupled.rb +68 -68
- data/lib/fintecture/api/ais/connect.rb +65 -65
- data/lib/fintecture/api/ais/delete_customer.rb +53 -53
- data/lib/fintecture/api/ais/transactions.rb +64 -64
- data/lib/fintecture/api/auth/authentication.rb +78 -78
- data/lib/fintecture/api/pis/connect.rb +77 -77
- data/lib/fintecture/api/pis/initiate.rb +52 -52
- data/lib/fintecture/api/pis/payments.rb +48 -48
- data/lib/fintecture/api/pis/refund.rb +67 -67
- data/lib/fintecture/api/pis/request_to_pay.rb +63 -63
- data/lib/fintecture/api/pis/settlements.rb +50 -50
- data/lib/fintecture/api/ressources/applications.rb +57 -57
- data/lib/fintecture/api/ressources/providers.rb +61 -61
- data/lib/fintecture/api/ressources/test_accounts.rb +60 -60
- data/lib/fintecture/base_url.rb +26 -26
- data/lib/fintecture/endpoints/ais.rb +17 -17
- data/lib/fintecture/endpoints/authentication.rb +13 -13
- data/lib/fintecture/endpoints/pis.rb +16 -16
- data/lib/fintecture/endpoints/ressources.rb +13 -13
- data/lib/fintecture/exceptions.rb +75 -72
- data/lib/fintecture/faraday/authentication/connection.rb +140 -140
- data/lib/fintecture/pis_client.rb +100 -100
- data/lib/fintecture/utils/constants.rb +11 -11
- data/lib/fintecture/utils/crypto.rb +75 -75
- data/lib/fintecture/utils/date.rb +15 -15
- data/lib/fintecture/utils/validation.rb +32 -32
- data/lib/fintecture/version.rb +5 -5
- data/lib/fintecture.rb +65 -65
- metadata +8 -8
@@ -1,72 +1,75 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'json'
|
4
|
-
|
5
|
-
module Fintecture
|
6
|
-
class ValidationException < RuntimeError; end
|
7
|
-
|
8
|
-
class CryptoException < RuntimeError; end
|
9
|
-
|
10
|
-
class ApiException
|
11
|
-
class << self
|
12
|
-
def error(res)
|
13
|
-
body = JSON.parse res.body
|
14
|
-
|
15
|
-
# Errors array
|
16
|
-
if body['code'] && body['log_id'] && body['errors']
|
17
|
-
raise _construct_message_errors(res, body)
|
18
|
-
# Single error
|
19
|
-
else
|
20
|
-
raise _construct_message_error(res, body)
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
private
|
25
|
-
|
26
|
-
def _construct_message_errors(res, body)
|
27
|
-
status = res.status
|
28
|
-
code = body['code']
|
29
|
-
log_id = body['log_id']
|
30
|
-
errors_array = body['errors']
|
31
|
-
|
32
|
-
error_string = "\nFintecture server errors : "
|
33
|
-
error_string += "\n status: #{status} "
|
34
|
-
error_string += "\n code: #{code}"
|
35
|
-
error_string += "\n id : #{log_id}"
|
36
|
-
|
37
|
-
errors_array.each do |error|
|
38
|
-
formated_error = error
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
error_string
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
end
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'json'
|
4
|
+
|
5
|
+
module Fintecture
|
6
|
+
class ValidationException < RuntimeError; end
|
7
|
+
|
8
|
+
class CryptoException < RuntimeError; end
|
9
|
+
|
10
|
+
class ApiException
|
11
|
+
class << self
|
12
|
+
def error(res)
|
13
|
+
body = JSON.parse res.body
|
14
|
+
|
15
|
+
# Errors array
|
16
|
+
if body['code'] && body['log_id'] && body['errors']
|
17
|
+
raise _construct_message_errors(res, body)
|
18
|
+
# Single error
|
19
|
+
else
|
20
|
+
raise _construct_message_error(res, body)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def _construct_message_errors(res, body)
|
27
|
+
status = res.status
|
28
|
+
code = body['code']
|
29
|
+
log_id = body['log_id']
|
30
|
+
errors_array = body['errors']
|
31
|
+
|
32
|
+
error_string = "\nFintecture server errors : "
|
33
|
+
error_string += "\n status: #{status} "
|
34
|
+
error_string += "\n code: #{code}"
|
35
|
+
error_string += "\n id : #{log_id}"
|
36
|
+
|
37
|
+
errors_array.compact.each do |error|
|
38
|
+
formated_error = error
|
39
|
+
formated_error = error.map { |key, value| " #{key}: #{value}" }.join("\n") if error.is_a?(Hash)
|
40
|
+
error_string += "\n\n#{formated_error}"
|
41
|
+
end
|
42
|
+
error_string += "\n\n"
|
43
|
+
|
44
|
+
{
|
45
|
+
type: 'Fintecture api',
|
46
|
+
status: status,
|
47
|
+
errors: errors_array,
|
48
|
+
error_string: error_string
|
49
|
+
}.to_json
|
50
|
+
end
|
51
|
+
|
52
|
+
def _construct_message_error(res, body)
|
53
|
+
status = res.status
|
54
|
+
error = body['meta']
|
55
|
+
|
56
|
+
error_string = "\nFintecture server errors : "
|
57
|
+
error_string += "\n status: #{status} "
|
58
|
+
|
59
|
+
formated_error = error
|
60
|
+
formated_error = error.map { |key, value| " #{key}: #{value}" }.join("\n") if error.is_a?(Hash)
|
61
|
+
|
62
|
+
error_string += "\n\n#{formated_error}"
|
63
|
+
|
64
|
+
error_string += "\n\n"
|
65
|
+
|
66
|
+
{
|
67
|
+
type: 'Fintecture api',
|
68
|
+
status: status,
|
69
|
+
errors: [error],
|
70
|
+
error_string: error_string
|
71
|
+
}.to_json
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
@@ -1,140 +1,140 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'base64'
|
4
|
-
require 'faraday'
|
5
|
-
require 'uri'
|
6
|
-
require 'fintecture/utils/crypto'
|
7
|
-
require 'fintecture/utils/date'
|
8
|
-
|
9
|
-
module Fintecture
|
10
|
-
module Faraday
|
11
|
-
module Authentication
|
12
|
-
class Connection
|
13
|
-
class << self
|
14
|
-
def connection(url)
|
15
|
-
::Faraday.new(url: url) do |faraday|
|
16
|
-
faraday.request :url_encoded
|
17
|
-
faraday.adapter ::Faraday.default_adapter
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
def post(url:, req_body: nil, client: nil, custom_content_type: nil, bearer: nil, secure_headers: false, additional_headers: nil, disableAuthorization: nil)
|
22
|
-
@client = client
|
23
|
-
conn = connection(url)
|
24
|
-
res = conn.post do |req|
|
25
|
-
req.options.params_encoder = Faraday::DisabledEncoder
|
26
|
-
req.headers = req_headers(custom_content_type, bearer, secure_headers, additional_headers, disableAuthorization,
|
27
|
-
method: 'post', body: req_body, url: url)
|
28
|
-
req.body = req_body
|
29
|
-
end
|
30
|
-
|
31
|
-
!res.success? ? Fintecture::ApiException.error(res) : res
|
32
|
-
end
|
33
|
-
|
34
|
-
def get(url:, req_body: nil, client: nil, custom_content_type: nil, bearer: nil, secure_headers: false, additional_headers: nil, disableAuthorization: nil)
|
35
|
-
@client = client
|
36
|
-
conn = connection(url)
|
37
|
-
|
38
|
-
res = conn.get do |req|
|
39
|
-
req.options.params_encoder = Faraday::DisabledEncoder
|
40
|
-
req.headers = req_headers(custom_content_type, bearer, secure_headers, additional_headers, disableAuthorization,
|
41
|
-
method: 'get', url: url)
|
42
|
-
req.body = req_body
|
43
|
-
end
|
44
|
-
|
45
|
-
!res.success? ? Fintecture::ApiException.error(res) : res
|
46
|
-
end
|
47
|
-
|
48
|
-
def delete(url:, req_body: nil, client: nil, custom_content_type: nil, bearer: nil, secure_headers: false, additional_headers: nil, disableAuthorization: nil)
|
49
|
-
@client = client
|
50
|
-
conn = connection(url)
|
51
|
-
|
52
|
-
res = conn.delete do |req|
|
53
|
-
req.options.params_encoder = Faraday::DisabledEncoder
|
54
|
-
req.headers = req_headers(custom_content_type, bearer, secure_headers, additional_headers, disableAuthorization,
|
55
|
-
method: 'delete', body: req_body, url: url)
|
56
|
-
req.body = req_body
|
57
|
-
end
|
58
|
-
|
59
|
-
!res.success? ? Fintecture::ApiException.error(res) : res
|
60
|
-
end
|
61
|
-
|
62
|
-
def req_headers(custom_content_type, bearer, secure_headers, additional_headers, disableAuthorization, url:, method: '', body: {})
|
63
|
-
if !additional_headers.nil? && !additional_headers.is_a?(Hash)
|
64
|
-
raise Fintecture::ValidationException, 'additional_headers must be an object'
|
65
|
-
end
|
66
|
-
|
67
|
-
client_token = Base64.strict_encode64("#{@client.app_id}:#{@client.app_secret}")
|
68
|
-
|
69
|
-
headers = {
|
70
|
-
'Accept' => 'application/json',
|
71
|
-
'User-Agent' => "Fintecture Ruby SDK v #{Fintecture::VERSION}",
|
72
|
-
'Content-Type' => custom_content_type || 'application/x-www-form-urlencoded'
|
73
|
-
}
|
74
|
-
headers['Authorization'] = bearer || "Basic #{client_token}" unless disableAuthorization
|
75
|
-
headers = headers.merge(additional_headers) unless additional_headers.nil?
|
76
|
-
headers.merge(secure_headers ? req_secure_headers(body: body, url: url, method: method) : {})
|
77
|
-
end
|
78
|
-
|
79
|
-
def req_secure_headers(body: {}, url: '', method: '')
|
80
|
-
payload = (body.instance_of?(String) ? body : body.to_s)
|
81
|
-
path_name = URI(url).path
|
82
|
-
search_params = URI(url).query
|
83
|
-
|
84
|
-
request_target = search_params ? "#{method.downcase} #{path_name}?#{search_params}" : "#{method.downcase} #{path_name}"
|
85
|
-
date = Fintecture::Utils::Date.header_time.to_s
|
86
|
-
digest = load_digest(payload)
|
87
|
-
x_request_id = Fintecture::Utils::Crypto.generate_uuid
|
88
|
-
|
89
|
-
headers = {
|
90
|
-
'Date' => date,
|
91
|
-
'X-Request-ID' => x_request_id
|
92
|
-
}.merge(payload ? digest : {})
|
93
|
-
|
94
|
-
headers['Signature'] =
|
95
|
-
Fintecture::Utils::Crypto.create_signature_header(
|
96
|
-
{ '(request-target)' => request_target }.merge(headers), @client
|
97
|
-
)
|
98
|
-
headers
|
99
|
-
end
|
100
|
-
|
101
|
-
def load_digest(payload)
|
102
|
-
{ 'Digest' => "SHA-256=#{Fintecture::Utils::Crypto.hash_base64(payload)}" }
|
103
|
-
end
|
104
|
-
|
105
|
-
end
|
106
|
-
end
|
107
|
-
end
|
108
|
-
|
109
|
-
module DisabledEncoder
|
110
|
-
class << self
|
111
|
-
extend Forwardable
|
112
|
-
def_delegators :'Faraday::Utils', :escape, :unescape
|
113
|
-
end
|
114
|
-
|
115
|
-
def self.encode(params)
|
116
|
-
return nil if params.nil?
|
117
|
-
|
118
|
-
newParams = {}
|
119
|
-
params.each do |key, value|
|
120
|
-
if value.instance_of?(Hash)
|
121
|
-
value.each do |subkey, subvalue|
|
122
|
-
newParams["#{key}[#{subkey}]"] = subvalue
|
123
|
-
end
|
124
|
-
else
|
125
|
-
newParams[key] = value
|
126
|
-
end
|
127
|
-
end
|
128
|
-
|
129
|
-
newParams.map { |key, value| "#{key}=#{value}" }.join('&').to_s
|
130
|
-
end
|
131
|
-
|
132
|
-
class << self
|
133
|
-
attr_accessor :sort_params
|
134
|
-
end
|
135
|
-
|
136
|
-
# Useful default for OAuth and caching.
|
137
|
-
@sort_params = true
|
138
|
-
end
|
139
|
-
end
|
140
|
-
end
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'base64'
|
4
|
+
require 'faraday'
|
5
|
+
require 'uri'
|
6
|
+
require 'fintecture/utils/crypto'
|
7
|
+
require 'fintecture/utils/date'
|
8
|
+
|
9
|
+
module Fintecture
|
10
|
+
module Faraday
|
11
|
+
module Authentication
|
12
|
+
class Connection
|
13
|
+
class << self
|
14
|
+
def connection(url)
|
15
|
+
::Faraday.new(url: url) do |faraday|
|
16
|
+
faraday.request :url_encoded
|
17
|
+
faraday.adapter ::Faraday.default_adapter
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def post(url:, req_body: nil, client: nil, custom_content_type: nil, bearer: nil, secure_headers: false, additional_headers: nil, disableAuthorization: nil)
|
22
|
+
@client = client
|
23
|
+
conn = connection(url)
|
24
|
+
res = conn.post do |req|
|
25
|
+
req.options.params_encoder = Faraday::DisabledEncoder
|
26
|
+
req.headers = req_headers(custom_content_type, bearer, secure_headers, additional_headers, disableAuthorization,
|
27
|
+
method: 'post', body: req_body, url: url)
|
28
|
+
req.body = req_body
|
29
|
+
end
|
30
|
+
|
31
|
+
!res.success? ? Fintecture::ApiException.error(res) : res
|
32
|
+
end
|
33
|
+
|
34
|
+
def get(url:, req_body: nil, client: nil, custom_content_type: nil, bearer: nil, secure_headers: false, additional_headers: nil, disableAuthorization: nil)
|
35
|
+
@client = client
|
36
|
+
conn = connection(url)
|
37
|
+
|
38
|
+
res = conn.get do |req|
|
39
|
+
req.options.params_encoder = Faraday::DisabledEncoder
|
40
|
+
req.headers = req_headers(custom_content_type, bearer, secure_headers, additional_headers, disableAuthorization,
|
41
|
+
method: 'get', url: url)
|
42
|
+
req.body = req_body
|
43
|
+
end
|
44
|
+
|
45
|
+
!res.success? ? Fintecture::ApiException.error(res) : res
|
46
|
+
end
|
47
|
+
|
48
|
+
def delete(url:, req_body: nil, client: nil, custom_content_type: nil, bearer: nil, secure_headers: false, additional_headers: nil, disableAuthorization: nil)
|
49
|
+
@client = client
|
50
|
+
conn = connection(url)
|
51
|
+
|
52
|
+
res = conn.delete do |req|
|
53
|
+
req.options.params_encoder = Faraday::DisabledEncoder
|
54
|
+
req.headers = req_headers(custom_content_type, bearer, secure_headers, additional_headers, disableAuthorization,
|
55
|
+
method: 'delete', body: req_body, url: url)
|
56
|
+
req.body = req_body
|
57
|
+
end
|
58
|
+
|
59
|
+
!res.success? ? Fintecture::ApiException.error(res) : res
|
60
|
+
end
|
61
|
+
|
62
|
+
def req_headers(custom_content_type, bearer, secure_headers, additional_headers, disableAuthorization, url:, method: '', body: {})
|
63
|
+
if !additional_headers.nil? && !additional_headers.is_a?(Hash)
|
64
|
+
raise Fintecture::ValidationException, 'additional_headers must be an object'
|
65
|
+
end
|
66
|
+
|
67
|
+
client_token = Base64.strict_encode64("#{@client.app_id}:#{@client.app_secret}")
|
68
|
+
|
69
|
+
headers = {
|
70
|
+
'Accept' => 'application/json',
|
71
|
+
'User-Agent' => "Fintecture Ruby SDK v #{Fintecture::VERSION}",
|
72
|
+
'Content-Type' => custom_content_type || 'application/x-www-form-urlencoded'
|
73
|
+
}
|
74
|
+
headers['Authorization'] = bearer || "Basic #{client_token}" unless disableAuthorization
|
75
|
+
headers = headers.merge(additional_headers) unless additional_headers.nil?
|
76
|
+
headers.merge(secure_headers ? req_secure_headers(body: body, url: url, method: method) : {})
|
77
|
+
end
|
78
|
+
|
79
|
+
def req_secure_headers(body: {}, url: '', method: '')
|
80
|
+
payload = (body.instance_of?(String) ? body : body.to_s)
|
81
|
+
path_name = URI(url).path
|
82
|
+
search_params = URI(url).query
|
83
|
+
|
84
|
+
request_target = search_params ? "#{method.downcase} #{path_name}?#{search_params}" : "#{method.downcase} #{path_name}"
|
85
|
+
date = Fintecture::Utils::Date.header_time.to_s
|
86
|
+
digest = load_digest(payload)
|
87
|
+
x_request_id = Fintecture::Utils::Crypto.generate_uuid
|
88
|
+
|
89
|
+
headers = {
|
90
|
+
'Date' => date,
|
91
|
+
'X-Request-ID' => x_request_id
|
92
|
+
}.merge(payload ? digest : {})
|
93
|
+
|
94
|
+
headers['Signature'] =
|
95
|
+
Fintecture::Utils::Crypto.create_signature_header(
|
96
|
+
{ '(request-target)' => request_target }.merge(headers), @client
|
97
|
+
)
|
98
|
+
headers
|
99
|
+
end
|
100
|
+
|
101
|
+
def load_digest(payload)
|
102
|
+
{ 'Digest' => "SHA-256=#{Fintecture::Utils::Crypto.hash_base64(payload)}" }
|
103
|
+
end
|
104
|
+
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
module DisabledEncoder
|
110
|
+
class << self
|
111
|
+
extend Forwardable
|
112
|
+
def_delegators :'Faraday::Utils', :escape, :unescape
|
113
|
+
end
|
114
|
+
|
115
|
+
def self.encode(params)
|
116
|
+
return nil if params.nil?
|
117
|
+
|
118
|
+
newParams = {}
|
119
|
+
params.each do |key, value|
|
120
|
+
if value.instance_of?(Hash)
|
121
|
+
value.each do |subkey, subvalue|
|
122
|
+
newParams["#{key}[#{subkey}]"] = subvalue
|
123
|
+
end
|
124
|
+
else
|
125
|
+
newParams[key] = value
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
newParams.map { |key, value| "#{key}=#{value}" }.join('&').to_s
|
130
|
+
end
|
131
|
+
|
132
|
+
class << self
|
133
|
+
attr_accessor :sort_params
|
134
|
+
end
|
135
|
+
|
136
|
+
# Useful default for OAuth and caching.
|
137
|
+
@sort_params = true
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end
|
@@ -1,100 +1,100 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'fintecture/api/pis/connect'
|
4
|
-
require 'fintecture/api/pis/request_to_pay'
|
5
|
-
require 'fintecture/api/pis/payments'
|
6
|
-
require 'fintecture/api/pis/initiate'
|
7
|
-
require 'fintecture/api/pis/refund'
|
8
|
-
require 'fintecture/api/pis/settlements'
|
9
|
-
|
10
|
-
require 'fintecture/api/ressources/providers'
|
11
|
-
require 'fintecture/api/ressources/applications'
|
12
|
-
require 'fintecture/api/ressources/test_accounts'
|
13
|
-
|
14
|
-
module Fintecture
|
15
|
-
class PisClient
|
16
|
-
@environment = %w[local test sandbox production].freeze
|
17
|
-
|
18
|
-
def initialize(config)
|
19
|
-
@app_id = config[:app_id]
|
20
|
-
@app_secret = config[:app_secret]
|
21
|
-
@private_key = config[:private_key]
|
22
|
-
|
23
|
-
environment = config[:environment].downcase
|
24
|
-
unless environment.include?(environment)
|
25
|
-
raise "#{environment} not a valid environment, options are [#{environment.join(', ')}]"
|
26
|
-
end
|
27
|
-
|
28
|
-
@environment = config[:environment]
|
29
|
-
end
|
30
|
-
|
31
|
-
# Getters
|
32
|
-
attr_reader :app_id, :app_secret, :private_key, :environment, :token, :token_expires_in
|
33
|
-
|
34
|
-
# Methodes
|
35
|
-
def generate_token
|
36
|
-
res = Fintecture::Authentication.get_access_token self
|
37
|
-
body = JSON.parse res.body
|
38
|
-
|
39
|
-
@token = body['access_token']
|
40
|
-
@token_expires_in = body['expires_in']
|
41
|
-
|
42
|
-
body
|
43
|
-
end
|
44
|
-
|
45
|
-
def connect(payload, state, redirect_uri = nil, origin_uri = nil)
|
46
|
-
res = Fintecture::Pis::Connect.generate self, Marshal.load(Marshal.dump(payload)), state, redirect_uri, origin_uri
|
47
|
-
|
48
|
-
JSON.parse res.body
|
49
|
-
end
|
50
|
-
|
51
|
-
def request_to_pay(payload, x_language, redirect_uri = nil)
|
52
|
-
res = Fintecture::Pis::RequestToPay.generate self, Marshal.load(Marshal.dump(payload)), x_language, redirect_uri
|
53
|
-
|
54
|
-
JSON.parse res.body
|
55
|
-
end
|
56
|
-
|
57
|
-
def initiate(payload, provider_id, redirect_uri, state = nil)
|
58
|
-
res = Fintecture::Pis::Initiate.generate self, Marshal.load(Marshal.dump(payload)), provider_id, redirect_uri,
|
59
|
-
state
|
60
|
-
|
61
|
-
JSON.parse res.body
|
62
|
-
end
|
63
|
-
|
64
|
-
def payments(session_id = nil)
|
65
|
-
res = Fintecture::Pis::Payments.get self, session_id
|
66
|
-
|
67
|
-
JSON.parse res.body
|
68
|
-
end
|
69
|
-
|
70
|
-
def refund(session_id, amount = nil)
|
71
|
-
res = Fintecture::Pis::Refund.generate self, session_id, amount
|
72
|
-
|
73
|
-
JSON.parse res.body
|
74
|
-
end
|
75
|
-
|
76
|
-
def settlements(settlement_id = nil, include_payments = false)
|
77
|
-
res = Fintecture::Pis::Settlements.get self, settlement_id, include_payments
|
78
|
-
|
79
|
-
JSON.parse res.body
|
80
|
-
end
|
81
|
-
|
82
|
-
def providers(provider_id: nil, paramsProviders: nil)
|
83
|
-
res = Fintecture::Ressources::Providers.get self, provider_id, paramsProviders
|
84
|
-
|
85
|
-
JSON.parse res.body
|
86
|
-
end
|
87
|
-
|
88
|
-
def applications
|
89
|
-
res = Fintecture::Ressources::Applications.get self
|
90
|
-
|
91
|
-
JSON.parse res.body
|
92
|
-
end
|
93
|
-
|
94
|
-
def test_accounts(provider_id = nil)
|
95
|
-
res = Fintecture::Ressources::TestAccounts.get self, provider_id
|
96
|
-
|
97
|
-
JSON.parse res.body
|
98
|
-
end
|
99
|
-
end
|
100
|
-
end
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'fintecture/api/pis/connect'
|
4
|
+
require 'fintecture/api/pis/request_to_pay'
|
5
|
+
require 'fintecture/api/pis/payments'
|
6
|
+
require 'fintecture/api/pis/initiate'
|
7
|
+
require 'fintecture/api/pis/refund'
|
8
|
+
require 'fintecture/api/pis/settlements'
|
9
|
+
|
10
|
+
require 'fintecture/api/ressources/providers'
|
11
|
+
require 'fintecture/api/ressources/applications'
|
12
|
+
require 'fintecture/api/ressources/test_accounts'
|
13
|
+
|
14
|
+
module Fintecture
|
15
|
+
class PisClient
|
16
|
+
@environment = %w[local test sandbox production].freeze
|
17
|
+
|
18
|
+
def initialize(config)
|
19
|
+
@app_id = config[:app_id]
|
20
|
+
@app_secret = config[:app_secret]
|
21
|
+
@private_key = config[:private_key]
|
22
|
+
|
23
|
+
environment = config[:environment].downcase
|
24
|
+
unless environment.include?(environment)
|
25
|
+
raise "#{environment} not a valid environment, options are [#{environment.join(', ')}]"
|
26
|
+
end
|
27
|
+
|
28
|
+
@environment = config[:environment]
|
29
|
+
end
|
30
|
+
|
31
|
+
# Getters
|
32
|
+
attr_reader :app_id, :app_secret, :private_key, :environment, :token, :token_expires_in
|
33
|
+
|
34
|
+
# Methodes
|
35
|
+
def generate_token
|
36
|
+
res = Fintecture::Authentication.get_access_token self
|
37
|
+
body = JSON.parse res.body
|
38
|
+
|
39
|
+
@token = body['access_token']
|
40
|
+
@token_expires_in = body['expires_in']
|
41
|
+
|
42
|
+
body
|
43
|
+
end
|
44
|
+
|
45
|
+
def connect(payload, state, redirect_uri = nil, origin_uri = nil)
|
46
|
+
res = Fintecture::Pis::Connect.generate self, Marshal.load(Marshal.dump(payload)), state, redirect_uri, origin_uri
|
47
|
+
|
48
|
+
JSON.parse res.body
|
49
|
+
end
|
50
|
+
|
51
|
+
def request_to_pay(payload, x_language, redirect_uri = nil)
|
52
|
+
res = Fintecture::Pis::RequestToPay.generate self, Marshal.load(Marshal.dump(payload)), x_language, redirect_uri
|
53
|
+
|
54
|
+
JSON.parse res.body
|
55
|
+
end
|
56
|
+
|
57
|
+
def initiate(payload, provider_id, redirect_uri, state = nil)
|
58
|
+
res = Fintecture::Pis::Initiate.generate self, Marshal.load(Marshal.dump(payload)), provider_id, redirect_uri,
|
59
|
+
state
|
60
|
+
|
61
|
+
JSON.parse res.body
|
62
|
+
end
|
63
|
+
|
64
|
+
def payments(session_id = nil)
|
65
|
+
res = Fintecture::Pis::Payments.get self, session_id
|
66
|
+
|
67
|
+
JSON.parse res.body
|
68
|
+
end
|
69
|
+
|
70
|
+
def refund(session_id, amount = nil)
|
71
|
+
res = Fintecture::Pis::Refund.generate self, session_id, amount
|
72
|
+
|
73
|
+
JSON.parse res.body
|
74
|
+
end
|
75
|
+
|
76
|
+
def settlements(settlement_id = nil, include_payments = false)
|
77
|
+
res = Fintecture::Pis::Settlements.get self, settlement_id, include_payments
|
78
|
+
|
79
|
+
JSON.parse res.body
|
80
|
+
end
|
81
|
+
|
82
|
+
def providers(provider_id: nil, paramsProviders: nil)
|
83
|
+
res = Fintecture::Ressources::Providers.get self, provider_id, paramsProviders
|
84
|
+
|
85
|
+
JSON.parse res.body
|
86
|
+
end
|
87
|
+
|
88
|
+
def applications
|
89
|
+
res = Fintecture::Ressources::Applications.get self
|
90
|
+
|
91
|
+
JSON.parse res.body
|
92
|
+
end
|
93
|
+
|
94
|
+
def test_accounts(provider_id = nil)
|
95
|
+
res = Fintecture::Ressources::TestAccounts.get self, provider_id
|
96
|
+
|
97
|
+
JSON.parse res.body
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
@@ -1,11 +1,11 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Fintecture
|
4
|
-
module Utils
|
5
|
-
module Constants
|
6
|
-
SIGNEDHEADERPARAMETERLIST = %w[(request-target) Date Digest X-Request-ID].freeze
|
7
|
-
PSU_TYPES = %w[retail corporate all].freeze
|
8
|
-
SCOPES = %w[pis ais].freeze
|
9
|
-
end
|
10
|
-
end
|
11
|
-
end
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Fintecture
|
4
|
+
module Utils
|
5
|
+
module Constants
|
6
|
+
SIGNEDHEADERPARAMETERLIST = %w[(request-target) Date Digest X-Request-ID].freeze
|
7
|
+
PSU_TYPES = %w[retail corporate all].freeze
|
8
|
+
SCOPES = %w[pis ais].freeze
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|