fintecture 0.1.6 → 0.1.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +24 -28
- data/lib/fintecture.rb +2 -2
- data/lib/fintecture/api/endpoints/pis.rb +13 -0
- data/lib/fintecture/authentication.rb +3 -3
- data/lib/fintecture/connect.rb +54 -29
- data/lib/fintecture/exceptions.rb +4 -0
- data/lib/fintecture/faraday/authentication/connection.rb +39 -6
- data/lib/fintecture/pis.rb +61 -0
- data/lib/fintecture/utils/constants.rb +14 -0
- data/lib/fintecture/utils/crypto.rb +33 -6
- data/lib/fintecture/utils/date.rb +15 -0
- data/lib/fintecture/utils/validation.rb +17 -0
- data/lib/fintecture/version.rb +1 -1
- metadata +8 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 363973dcc95af085243be930db8fe736d5c4a5cc7250a0085f976305b3f70381
|
4
|
+
data.tar.gz: f02d9c62439389ef1a01332990a4a5407ffb2950007534907fdb280922551086
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dfbbdea308ceca340c632e28c88cf6b47f05507405de850c6df3201bb389630ecc6ef0a2222f5a3dba9a51d3b0e4574b5f7ad5ce2c4202a4686df72a304e0e78
|
7
|
+
data.tar.gz: c50413e95387828349f132eb83e39d9cd3ec2c5e4af333c69306bd9bbd4bb5b0efee940f82dd7f04452532b9e758aa00006f82e5624b5dcf6bb3b7e66f112bc1
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -10,11 +10,6 @@ Add this line to your application's Gemfile:
|
|
10
10
|
gem 'fintecture'
|
11
11
|
```
|
12
12
|
|
13
|
-
or install it through our github repository
|
14
|
-
|
15
|
-
```ruby
|
16
|
-
gem 'fintecture', github: 'Fintecture/fintecture-sdk-ruby'
|
17
|
-
```
|
18
13
|
|
19
14
|
And then execute:
|
20
15
|
|
@@ -33,7 +28,7 @@ Initialize your client credentials
|
|
33
28
|
```ruby
|
34
29
|
Fintecture.app_id = 'your_app_id'
|
35
30
|
Fintecture.app_secret = 'your_app_secret'
|
36
|
-
Fintecture.
|
31
|
+
Fintecture.private_key = %q(your_private_key)
|
37
32
|
```
|
38
33
|
|
39
34
|
|
@@ -56,7 +51,7 @@ You can also see the available environments
|
|
56
51
|
#### Access token
|
57
52
|
|
58
53
|
```ruby
|
59
|
-
Fintecture::
|
54
|
+
Fintecture::Pis.get_access_token
|
60
55
|
```
|
61
56
|
|
62
57
|
### Connect
|
@@ -70,41 +65,42 @@ payment_attrs = {
|
|
70
65
|
customer_full_name: 'John Doe',
|
71
66
|
customer_email: 'john.doe@email.com',
|
72
67
|
customer_ip: '127.0.0.1',
|
73
|
-
end_to_end_id: '5f78e902907e4209aa8df63659b05d24', # uuid optional
|
74
68
|
redirect_uri: 'http://example.com/callback',
|
75
|
-
origin_uri: '',
|
76
|
-
state: 'somestate'
|
69
|
+
origin_uri: 'http://example.com/checkout?session=123',
|
70
|
+
state: 'somestate',
|
71
|
+
psu_type: 'retail',
|
72
|
+
country: 'fr'
|
77
73
|
}
|
78
|
-
|
74
|
+
tokens = Fintecture::Pis.get_access_token
|
75
|
+
connect_response = Fintecture::Connect.get_pis_connect tokens['access_token'], payment_attrs
|
76
|
+
url = connect_response[:url]
|
77
|
+
|
79
78
|
```
|
80
79
|
Explanation of each field:
|
81
80
|
|
82
81
|
* amount: **[mandatory]** The amount of the payment initiation request. Min 1.00 and Max is variable based on bank's policy.
|
83
82
|
* currency: **[mandatory]** The currency of the payment initiation request. Currently, only EUR and GBP is supported.
|
84
83
|
* communication: **[optional]** A message sent to the beneficiary of the payment and visible on his bank statement. In the context of ecommerce payment collection, the order reference is inputted here (with an optional prefer ex: REF#23444)
|
85
|
-
* customer_full_name: **[mandatory]**
|
86
|
-
* customer_email: **[mandatory]**
|
87
|
-
* customer_ip: **[mandatory]**
|
88
|
-
*
|
89
|
-
*
|
90
|
-
* origin_uri: **[optional]** a URL to which the customer will be redirected if he wants to exit Fintecture Connect
|
84
|
+
* customer_full_name: **[mandatory]** The full name of the payer
|
85
|
+
* customer_email: **[mandatory]** The email of the payer
|
86
|
+
* customer_ip: **[mandatory]** The ip address of the payer
|
87
|
+
* redirect_uri: **[mandatory]** The callback URL to which the customer is redirected after authentication with his bank
|
88
|
+
* origin_uri: **[optional]** A URL to which the customer will be redirected if he wants to exit Fintecture Connect
|
91
89
|
* state: **[optional]** A state parameter which is sent back on callback
|
90
|
+
* retail: **[optional]** Possible values are **retail** and **corporate** (retail by default)
|
91
|
+
* country: **[optional]** Loads a specific collection of providers filter by country
|
92
92
|
|
93
|
-
#### Verify
|
93
|
+
#### Verify payment
|
94
94
|
|
95
95
|
```ruby
|
96
|
-
callback_params = {
|
97
|
-
session_id: 'uri_session_id',
|
98
|
-
status: 'uri_status',
|
99
|
-
customer_id: 'uri_customer_id',
|
100
|
-
provider: 'uri_provider',
|
101
|
-
state: 'uri_state',
|
102
|
-
s: 'uri_s'
|
103
|
-
}
|
104
96
|
|
105
|
-
Fintecture::
|
97
|
+
payment_response = Fintecture::Pis.get_payments tokens['access_token'], params[:session_id]
|
98
|
+
payment_response_body = JSON.parse payment_response.body
|
99
|
+
|
100
|
+
verified = (payment_response_body['meta']['status'] === 'payment_created')
|
106
101
|
```
|
107
|
-
|
102
|
+
|
103
|
+
If the payment was success, the status of the response (_payment_response_body['meta']['status']_) should be **payment_created**
|
108
104
|
|
109
105
|
## Development
|
110
106
|
|
data/lib/fintecture.rb
CHANGED
@@ -29,10 +29,10 @@ module Fintecture
|
|
29
29
|
@logger = nil
|
30
30
|
@environment = 'sandbox'
|
31
31
|
|
32
|
-
ENVIRONMENTS = %w[local sandbox production].freeze
|
32
|
+
ENVIRONMENTS = %w[local test sandbox production].freeze
|
33
33
|
|
34
34
|
class << self
|
35
|
-
attr_accessor :app_id, :app_secret, :
|
35
|
+
attr_accessor :app_id, :app_secret, :private_key
|
36
36
|
|
37
37
|
def environment=(environment)
|
38
38
|
environment = environment.downcase
|
@@ -16,10 +16,10 @@ module Fintecture
|
|
16
16
|
::Faraday.get "#{token_authorize_endpoint}#{query_string}"
|
17
17
|
end
|
18
18
|
|
19
|
-
def
|
19
|
+
def get_access_token(auth_code = nil)
|
20
20
|
body = access_token_data auth_code
|
21
21
|
|
22
|
-
Fintecture::Faraday::Authentication::Connection.post url:
|
22
|
+
Fintecture::Faraday::Authentication::Connection.post url: access_token_url, req_body: body
|
23
23
|
end
|
24
24
|
|
25
25
|
def refresh_token(refresh_token)
|
@@ -38,7 +38,7 @@ module Fintecture
|
|
38
38
|
"#{base_url}#{Fintecture::Api::Endpoints::Authentication::OAUTH_TOKEN_AUTHORIZE}"
|
39
39
|
end
|
40
40
|
|
41
|
-
def
|
41
|
+
def access_token_url
|
42
42
|
"#{base_url}#{Fintecture::Api::Endpoints::Authentication::OAUTH_ACCESS_TOKEN}"
|
43
43
|
end
|
44
44
|
|
data/lib/fintecture/connect.rb
CHANGED
@@ -1,26 +1,37 @@
|
|
1
1
|
require 'base64'
|
2
2
|
require 'json'
|
3
|
+
require 'faraday'
|
4
|
+
require 'fintecture/pis'
|
5
|
+
require 'fintecture/utils/validation'
|
6
|
+
require 'fintecture/exceptions'
|
7
|
+
require 'fintecture/utils/date'
|
8
|
+
require 'fintecture/utils/constants'
|
3
9
|
|
4
10
|
module Fintecture
|
5
11
|
class Connect
|
6
12
|
class << self
|
7
13
|
SIGNATURE_TYPE = 'rsa-sha256'.freeze
|
8
14
|
|
9
|
-
def
|
10
|
-
connect_url(
|
15
|
+
def get_pis_connect(access_token = nil, payment_attrs = nil)
|
16
|
+
connect_url(access_token, payment_attrs, type: 'pis')
|
11
17
|
end
|
12
18
|
|
13
|
-
def connect_url(payment_attrs
|
19
|
+
def connect_url(access_token = nil, payment_attrs = nil, type: nil)
|
20
|
+
@access_token = access_token
|
14
21
|
@payment_attrs = as_json payment_attrs
|
15
22
|
@type = type
|
16
23
|
|
17
24
|
validate_payment_integrity
|
18
25
|
|
19
|
-
@payment_attrs['end_to_end_id'] ||= Fintecture::Utils::Crypto.
|
26
|
+
@payment_attrs['end_to_end_id'] ||= Fintecture::Utils::Crypto.generate_uuid_only_chars
|
27
|
+
|
20
28
|
payload = build_payload
|
21
|
-
|
29
|
+
config = build_config(payload).to_json.to_s
|
22
30
|
|
23
|
-
|
31
|
+
{
|
32
|
+
url: build_url(config),
|
33
|
+
session_id: payload[:meta][:session_id]
|
34
|
+
}
|
24
35
|
end
|
25
36
|
|
26
37
|
def verify_url_parameters(parameters = nil)
|
@@ -36,37 +47,41 @@ module Fintecture
|
|
36
47
|
|
37
48
|
private
|
38
49
|
|
39
|
-
def
|
40
|
-
|
41
|
-
|
42
|
-
raise "invalid #{param_name ? param_name : 'parameter'} format, the parameter should be a #{klass} instead a #{target.class.name}"
|
50
|
+
def build_url(config)
|
51
|
+
"#{base_url}/#{@type}/#{@payment_attrs['psu_type']}/#{@payment_attrs['country']}?config=#{Base64.strict_encode64(config)}"
|
43
52
|
end
|
44
53
|
|
45
54
|
def validate_payment_integrity
|
46
|
-
raise_if_klass_mismatch @payment_attrs, Hash, 'payment_attrs'
|
55
|
+
Fintecture::Utils::Validation.raise_if_klass_mismatch @payment_attrs, Hash, 'payment_attrs'
|
56
|
+
|
57
|
+
raise Fintecture::ValidationException.new("access_token is a mandatory field") if @access_token.nil?
|
58
|
+
|
59
|
+
@payment_attrs['psu_type'] = 'retail' unless @payment_attrs['psu_type']
|
60
|
+
@payment_attrs['country'] = 'all' unless @payment_attrs['country']
|
47
61
|
|
48
62
|
error_msg = 'invalid payment payload parameter'
|
49
63
|
|
50
|
-
raise "#{error_msg} type" unless
|
64
|
+
raise Fintecture::ValidationException.new("#{error_msg} type") unless Fintecture::Utils::Constants::SCOPES.include? @type
|
65
|
+
raise Fintecture::ValidationException.new("#{@payment_attrs['psu_type']} PSU type not allowed") unless Fintecture::Utils::Constants::PSU_TYPES.include? @payment_attrs['psu_type']
|
51
66
|
|
52
|
-
raise 'end_to_end_id must be an alphanumeric string' if(@payment_attrs['end_to_end_id'] && !@payment_attrs['end_to_end_id'].match(/^[0-9a-zA-Z]*$/))
|
67
|
+
raise Fintecture::ValidationException.new('end_to_end_id must be an alphanumeric string') if(@payment_attrs['end_to_end_id'] && !@payment_attrs['end_to_end_id'].match(/^[0-9a-zA-Z]*$/))
|
53
68
|
|
54
69
|
%w[amount currency customer_full_name customer_email customer_ip redirect_uri].each do |param|
|
55
|
-
raise "#{param} is a mandatory field" if @payment_attrs[param].nil?
|
70
|
+
raise Fintecture::ValidationException.new("#{param} is a mandatory field") if @payment_attrs[param].nil?
|
56
71
|
end
|
57
72
|
|
58
73
|
# Check if string
|
59
74
|
%w[communication redirect_uri].each do |param|
|
60
|
-
raise_if_klass_mismatch(@payment_attrs[param], String, param) if(@payment_attrs[param])
|
75
|
+
Fintecture::Utils::Validation.raise_if_klass_mismatch(@payment_attrs[param], String, param) if(@payment_attrs[param])
|
61
76
|
end
|
62
77
|
|
63
78
|
end
|
64
79
|
|
65
80
|
def validate_post_payment_integrity
|
66
|
-
raise_if_klass_mismatch @post_payment_attrs, Hash, 'post_payment_attrs'
|
81
|
+
Fintecture::Utils::Validation.raise_if_klass_mismatch @post_payment_attrs, Hash, 'post_payment_attrs'
|
67
82
|
|
68
83
|
%w[s state status session_id customer_id provider].each do |param|
|
69
|
-
raise "invalid post payment parameter #{param}" if @post_payment_attrs[param].nil?
|
84
|
+
raise Fintecture::ValidationException.new("invalid post payment parameter #{param}") if @post_payment_attrs[param].nil?
|
70
85
|
end
|
71
86
|
end
|
72
87
|
|
@@ -89,29 +104,39 @@ module Fintecture
|
|
89
104
|
attributes: attributes,
|
90
105
|
}
|
91
106
|
|
107
|
+
prepare_payment_response = Fintecture::Pis.prepare_payment( @access_token, {
|
108
|
+
data: data,
|
109
|
+
meta: meta
|
110
|
+
})
|
111
|
+
prepare_payment_response_body = JSON.parse(prepare_payment_response.body)
|
92
112
|
{
|
93
|
-
|
94
|
-
|
113
|
+
meta: {session_id: prepare_payment_response_body['meta']['session_id']},
|
114
|
+
data: { attributes: {amount: @payment_attrs['amount'], currency: @payment_attrs['currency']}}
|
95
115
|
}
|
96
116
|
end
|
97
117
|
|
98
|
-
def build_signature(payload)
|
99
|
-
|
118
|
+
def build_signature(payload, date, x_request_id)
|
119
|
+
date_string = "x-date: #{date}"
|
120
|
+
digest_string = "digest: SHA-256=#{Fintecture::Utils::Crypto.hash_base64(payload.to_json)}"
|
121
|
+
x_request_id_string = "x-request-id: #{x_request_id}"
|
122
|
+
|
123
|
+
Fintecture::Utils::Crypto.sign_payload "#{digest_string}\n#{date_string}\n#{x_request_id_string}"
|
100
124
|
end
|
101
125
|
|
102
|
-
def
|
103
|
-
|
104
|
-
|
126
|
+
def build_config(payload)
|
127
|
+
header_time = Fintecture::Utils::Date.header_time
|
128
|
+
x_request_id = Fintecture::Utils::Crypto.generate_uuid
|
105
129
|
{
|
106
130
|
app_id: Fintecture.app_id,
|
107
|
-
access_token: access_token,
|
131
|
+
access_token: @access_token,
|
132
|
+
date: header_time,
|
133
|
+
request_id: x_request_id,
|
108
134
|
signature_type: SIGNATURE_TYPE,
|
109
|
-
signature: build_signature(payload),
|
135
|
+
signature: build_signature(payload, header_time, x_request_id),
|
110
136
|
redirect_uri: @payment_attrs['redirect_uri'] || '',
|
111
137
|
origin_uri: @payment_attrs['origin_uri'] || '',
|
112
138
|
state: @payment_attrs['state'],
|
113
|
-
payload: payload
|
114
|
-
version: Fintecture::VERSION,
|
139
|
+
payload: payload
|
115
140
|
}
|
116
141
|
end
|
117
142
|
|
@@ -139,7 +164,7 @@ module Fintecture
|
|
139
164
|
begin
|
140
165
|
element.as_json
|
141
166
|
rescue NoMethodError
|
142
|
-
raise "invalid parameter format, the parameter should be a Hash or an Object Model instead a #{element.class.name}"
|
167
|
+
raise Fintecture::ValidationException.new("invalid parameter format, the parameter should be a Hash or an Object Model instead a #{element.class.name}")
|
143
168
|
end
|
144
169
|
end
|
145
170
|
end
|
@@ -1,5 +1,8 @@
|
|
1
1
|
require 'base64'
|
2
2
|
require 'faraday'
|
3
|
+
require 'uri'
|
4
|
+
require 'fintecture/utils/crypto'
|
5
|
+
require 'fintecture/utils/date'
|
3
6
|
|
4
7
|
module Fintecture
|
5
8
|
module Faraday
|
@@ -14,24 +17,54 @@ module Fintecture
|
|
14
17
|
end
|
15
18
|
end
|
16
19
|
|
17
|
-
def post(url:, req_body:)
|
20
|
+
def post(url:, req_body: nil, custom_content_type: nil, bearer: nil, secure_headers: false)
|
18
21
|
conn = connection(url)
|
19
22
|
|
20
23
|
conn.post do |req|
|
21
|
-
req.headers = req_headers
|
24
|
+
req.headers = req_headers(custom_content_type, bearer, secure_headers, method: 'post', body: req_body, url: url)
|
22
25
|
req.body = req_body
|
23
26
|
end
|
24
27
|
end
|
25
28
|
|
26
|
-
def
|
29
|
+
def get(url:, req_body: nil, custom_content_type: nil, bearer: nil, secure_headers: false)
|
30
|
+
conn = connection(url)
|
31
|
+
|
32
|
+
conn.get do |req|
|
33
|
+
req.headers = req_headers(custom_content_type, bearer, secure_headers, method: 'get', url: url)
|
34
|
+
req.body = req_body
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def req_headers(custom_content_type, bearer, secure_headers, method: '', body: {}, url:)
|
27
39
|
client_token = Base64.strict_encode64("#{Fintecture.app_id}:#{Fintecture.app_secret}")
|
28
40
|
|
29
41
|
{
|
30
42
|
'Accept' => 'application/json',
|
31
43
|
'User-Agent' => "Fintecture Ruby SDK v #{Fintecture::VERSION}",
|
32
|
-
'Authorization' => "Basic #{client_token}",
|
33
|
-
'Content-Type' => 'application/x-www-form-urlencoded',
|
34
|
-
}
|
44
|
+
'Authorization' => bearer ? bearer : "Basic #{client_token}",
|
45
|
+
'Content-Type' => custom_content_type ? custom_content_type : 'application/x-www-form-urlencoded',
|
46
|
+
}.merge(secure_headers ? req_secure_headers(body: body, url: url, method: method) : {})
|
47
|
+
|
48
|
+
end
|
49
|
+
|
50
|
+
def req_secure_headers(body: {}, url: '', method: '')
|
51
|
+
payload = ( body.class.name == 'String' ? body : body.to_s )
|
52
|
+
path_name = URI(url).path
|
53
|
+
search_params = URI(url).query
|
54
|
+
|
55
|
+
headers = {
|
56
|
+
'Date' => Fintecture::Utils::Date.header_time.to_s,
|
57
|
+
'X-Request-ID' => Fintecture::Utils::Crypto.generate_uuid
|
58
|
+
}.merge(payload ? load_digest(payload) : {})
|
59
|
+
|
60
|
+
request_target = search_params ? "#{method.downcase} #{path_name}?#{search_params}" : "#{method.downcase} #{path_name}"
|
61
|
+
|
62
|
+
headers['Signature'] = Fintecture::Utils::Crypto.create_signature_header({'(request-target)' => request_target}.merge(headers))
|
63
|
+
headers
|
64
|
+
end
|
65
|
+
|
66
|
+
def load_digest(payload)
|
67
|
+
{'Digest' => "SHA-256=#{Fintecture::Utils::Crypto.hash_base64(payload)}"}
|
35
68
|
end
|
36
69
|
|
37
70
|
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'faraday'
|
3
|
+
require 'fintecture/api/endpoints/pis'
|
4
|
+
require 'fintecture/api/base_url'
|
5
|
+
|
6
|
+
module Fintecture
|
7
|
+
class Pis
|
8
|
+
class << self
|
9
|
+
|
10
|
+
# Headers
|
11
|
+
def prepare_payment(access_token, payload)
|
12
|
+
url = prepare_payment_endpoint
|
13
|
+
|
14
|
+
Fintecture::Faraday::Authentication::Connection.post(
|
15
|
+
url: url,
|
16
|
+
req_body: payload.to_json,
|
17
|
+
custom_content_type: 'application/json',
|
18
|
+
bearer: "Bearer #{access_token}",
|
19
|
+
secure_headers: true
|
20
|
+
)
|
21
|
+
end
|
22
|
+
|
23
|
+
# This needs headers
|
24
|
+
def get_payments(access_token, session_id)
|
25
|
+
url = payment_endpoint
|
26
|
+
|
27
|
+
Fintecture::Faraday::Authentication::Connection.get(
|
28
|
+
url: "#{url}/#{session_id}",
|
29
|
+
custom_content_type: 'application/json',
|
30
|
+
bearer: "Bearer #{access_token}",
|
31
|
+
secure_headers: true
|
32
|
+
)
|
33
|
+
end
|
34
|
+
|
35
|
+
def get_access_token
|
36
|
+
response = Fintecture::Authentication.get_access_token
|
37
|
+
|
38
|
+
JSON.parse response.body
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
|
43
|
+
def prepare_payment_endpoint
|
44
|
+
"#{api_base_url}/#{Fintecture::Api::Endpoints::Pis::PREPARE}"
|
45
|
+
end
|
46
|
+
|
47
|
+
def payment_endpoint
|
48
|
+
"#{api_base_url}/#{Fintecture::Api::Endpoints::Pis::PAYMENTS}"
|
49
|
+
end
|
50
|
+
|
51
|
+
def base_url
|
52
|
+
Fintecture::Api::BaseUrl::FINTECTURE_CONNECT_URL[Fintecture.environment.to_sym]
|
53
|
+
end
|
54
|
+
|
55
|
+
def api_base_url
|
56
|
+
Fintecture::Api::BaseUrl::FINTECTURE_API_URL[Fintecture.environment.to_sym]
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -2,7 +2,9 @@ require 'securerandom'
|
|
2
2
|
require 'openssl'
|
3
3
|
require 'base64'
|
4
4
|
require 'json'
|
5
|
-
|
5
|
+
require 'fintecture/exceptions'
|
6
|
+
require 'fintecture/utils/constants'
|
7
|
+
require 'uri'
|
6
8
|
|
7
9
|
module Fintecture
|
8
10
|
module Utils
|
@@ -10,31 +12,38 @@ module Fintecture
|
|
10
12
|
class << self
|
11
13
|
|
12
14
|
def generate_uuid
|
13
|
-
SecureRandom.uuid
|
15
|
+
SecureRandom.uuid
|
16
|
+
end
|
17
|
+
|
18
|
+
def generate_uuid_only_chars
|
19
|
+
generate_uuid.gsub!('-','')
|
14
20
|
end
|
15
21
|
|
16
22
|
def sign_payload(payload)
|
17
23
|
payload = payload.to_json.to_s if payload.is_a? Hash
|
18
24
|
|
19
25
|
digest = OpenSSL::Digest::SHA256.new
|
20
|
-
private_key = OpenSSL::PKey::RSA.new(Fintecture.
|
26
|
+
private_key = OpenSSL::PKey::RSA.new(Fintecture.private_key)
|
21
27
|
|
22
28
|
begin
|
23
29
|
signature = private_key.sign(digest, payload)
|
24
30
|
Base64.strict_encode64(signature)
|
25
31
|
rescue
|
26
|
-
raise 'error during signature'
|
32
|
+
raise Fintecture::CryptoException.new('error during signature')
|
27
33
|
end
|
28
34
|
end
|
29
35
|
|
30
36
|
def decrypt_private(digest)
|
37
|
+
digest = URI.unescape digest
|
31
38
|
encrypted_string = Base64.decode64(digest)
|
32
|
-
private_key = OpenSSL::PKey::RSA.new(Fintecture.
|
39
|
+
private_key = OpenSSL::PKey::RSA.new(Fintecture.private_key)
|
33
40
|
|
34
41
|
begin
|
35
42
|
private_key.private_decrypt(encrypted_string, OpenSSL::PKey::RSA::PKCS1_OAEP_PADDING)
|
43
|
+
rescue OpenSSL::PKey::RSAError => e
|
44
|
+
raise Fintecture::CryptoException.new("error while decrypt, #{e.message}")
|
36
45
|
rescue
|
37
|
-
raise 'error during decryption'
|
46
|
+
raise Fintecture::CryptoException.new('error during decryption')
|
38
47
|
end
|
39
48
|
end
|
40
49
|
|
@@ -43,6 +52,24 @@ module Fintecture
|
|
43
52
|
Base64.strict_encode64(digest)
|
44
53
|
end
|
45
54
|
|
55
|
+
def create_signature_header(headers)
|
56
|
+
signing = []
|
57
|
+
header = []
|
58
|
+
|
59
|
+
Fintecture::Utils::Constants::SIGNEDHEADERPARAMETERLIST.each do |param|
|
60
|
+
next unless headers[param]
|
61
|
+
|
62
|
+
param_low = param.downcase
|
63
|
+
signing << "#{param_low}: #{headers[param]}"
|
64
|
+
header << param_low
|
65
|
+
end
|
66
|
+
|
67
|
+
# Double quote in join needed. If not we will get two slashes \\n
|
68
|
+
signature = sign_payload signing.join("\n")
|
69
|
+
|
70
|
+
'keyId="' + Fintecture.app_id + '",algorithm="rsa-sha256",headers="' + header.join(' ') + '",signature="' + signature + '"'
|
71
|
+
end
|
72
|
+
|
46
73
|
end
|
47
74
|
end
|
48
75
|
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'fintecture/exceptions'
|
2
|
+
|
3
|
+
module Fintecture
|
4
|
+
module Utils
|
5
|
+
class Validation
|
6
|
+
class << self
|
7
|
+
|
8
|
+
def raise_if_klass_mismatch(target, klass, param_name = nil)
|
9
|
+
return if target.is_a? klass
|
10
|
+
|
11
|
+
raise Fintecture::ValidationException.new("invalid #{param_name ? param_name : 'parameter'} format, the parameter should be a #{klass} instead a #{target.class.name}")
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
data/lib/fintecture/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fintecture
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Fintecture
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-02-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -88,10 +88,16 @@ files:
|
|
88
88
|
- lib/fintecture.rb
|
89
89
|
- lib/fintecture/api/base_url.rb
|
90
90
|
- lib/fintecture/api/endpoints/authentication.rb
|
91
|
+
- lib/fintecture/api/endpoints/pis.rb
|
91
92
|
- lib/fintecture/authentication.rb
|
92
93
|
- lib/fintecture/connect.rb
|
94
|
+
- lib/fintecture/exceptions.rb
|
93
95
|
- lib/fintecture/faraday/authentication/connection.rb
|
96
|
+
- lib/fintecture/pis.rb
|
97
|
+
- lib/fintecture/utils/constants.rb
|
94
98
|
- lib/fintecture/utils/crypto.rb
|
99
|
+
- lib/fintecture/utils/date.rb
|
100
|
+
- lib/fintecture/utils/validation.rb
|
95
101
|
- lib/fintecture/version.rb
|
96
102
|
homepage: http://fintecture.com
|
97
103
|
licenses:
|