fintecture 0.2.1 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -3
  3. data/Gemfile +4 -2
  4. data/Gemfile.lock +1 -1
  5. data/README.md +328 -162
  6. data/Rakefile +5 -3
  7. data/bin/console +4 -3
  8. data/exemples/ais.rb +53 -0
  9. data/exemples/config_ais.json +8 -0
  10. data/exemples/config_pis.json +6 -0
  11. data/exemples/pis.rb +148 -0
  12. data/exemples/ressources.rb +23 -0
  13. data/fintecture.gemspec +16 -15
  14. data/lib/fintecture/ais_client.rb +94 -0
  15. data/lib/fintecture/api/ais/account_holders.rb +61 -0
  16. data/lib/fintecture/api/ais/accounts.rb +63 -0
  17. data/lib/fintecture/api/ais/authorize.rb +72 -0
  18. data/lib/fintecture/api/ais/authorize_decoupled.rb +68 -0
  19. data/lib/fintecture/api/ais/connect.rb +65 -0
  20. data/lib/fintecture/api/ais/delete_customer.rb +53 -0
  21. data/lib/fintecture/api/ais/transactions.rb +64 -0
  22. data/lib/fintecture/{authentication.rb → api/auth/authentication.rb} +25 -23
  23. data/lib/fintecture/api/pis/connect.rb +77 -0
  24. data/lib/fintecture/api/pis/initiate.rb +52 -0
  25. data/lib/fintecture/api/pis/payments.rb +48 -0
  26. data/lib/fintecture/api/pis/refund.rb +67 -0
  27. data/lib/fintecture/api/pis/request_to_pay.rb +63 -0
  28. data/lib/fintecture/api/pis/settlements.rb +48 -0
  29. data/lib/fintecture/api/ressources/applications.rb +57 -0
  30. data/lib/fintecture/api/ressources/providers.rb +61 -0
  31. data/lib/fintecture/api/ressources/test_accounts.rb +60 -0
  32. data/lib/fintecture/base_url.rb +26 -0
  33. data/lib/fintecture/endpoints/ais.rb +17 -0
  34. data/lib/fintecture/{api/endpoints → endpoints}/authentication.rb +3 -3
  35. data/lib/fintecture/endpoints/pis.rb +16 -0
  36. data/lib/fintecture/endpoints/ressources.rb +13 -0
  37. data/lib/fintecture/exceptions.rb +52 -13
  38. data/lib/fintecture/faraday/authentication/connection.rb +60 -40
  39. data/lib/fintecture/pis_client.rb +100 -0
  40. data/lib/fintecture/utils/constants.rb +5 -8
  41. data/lib/fintecture/utils/crypto.rb +15 -18
  42. data/lib/fintecture/utils/date.rb +4 -4
  43. data/lib/fintecture/utils/validation.rb +12 -6
  44. data/lib/fintecture/version.rb +3 -1
  45. data/lib/fintecture.rb +21 -38
  46. metadata +31 -8
  47. data/lib/fintecture/api/base_url.rb +0 -29
  48. data/lib/fintecture/api/endpoints/pis.rb +0 -14
  49. data/lib/fintecture/connect.rb +0 -38
  50. data/lib/fintecture/pis.rb +0 -262
@@ -0,0 +1,60 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'base64'
4
+ require 'json'
5
+ require 'faraday'
6
+ require 'fintecture/utils/validation'
7
+ require 'fintecture/exceptions'
8
+ require 'fintecture/utils/date'
9
+ require 'fintecture/utils/constants'
10
+
11
+ module Fintecture
12
+ module Ressources
13
+ class TestAccounts
14
+ class << self
15
+ # ------------ PUBLIC METHOD ------------
16
+ def get(client, provider_id)
17
+ @client = client
18
+
19
+ # Do the request
20
+ _request provider_id
21
+ end
22
+
23
+ private
24
+
25
+ # ------------ REQUEST ------------
26
+ def _request(provider_id)
27
+ # Get the url request
28
+ url = _endpoint
29
+
30
+ # Build additional headers
31
+ additional_headers = {}
32
+ additional_headers['app_id'] = @client.app_id
33
+
34
+ # Build uri params
35
+ query_string = ''
36
+ query_string = "?filter[provider_id]=#{provider_id}" if provider_id
37
+ # Do connect request
38
+ Fintecture::Faraday::Authentication::Connection.get(
39
+ url: url + query_string,
40
+ client: @client,
41
+ custom_content_type: 'application/json',
42
+ secure_headers: true,
43
+ additional_headers: additional_headers
44
+ )
45
+ end
46
+
47
+ # ------------ API ENDPOINT ------------
48
+ def _endpoint
49
+ "#{_api_base_url}/#{Fintecture::Api::Endpoints::Ressources::TESTACCOUNTS}"
50
+ end
51
+
52
+ # ------------ BASE URL ------------
53
+ def _api_base_url
54
+ Fintecture::Api::BaseUrl::FINTECTURE_API_URL[@client.environment.to_sym]
55
+ end
56
+
57
+ end
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,26 @@
1
+ module Fintecture
2
+ module Api
3
+ module BaseUrl
4
+ FINTECTURE_OAUTH_URL = {
5
+ local: 'http://localhost:3030/oauth',
6
+ test: 'https://oauth-sandbox-test.fintecture.com/oauth',
7
+ sandbox: 'https://api-sandbox.fintecture.com/oauth',
8
+ production: 'https://api.fintecture.com/oauth'
9
+ }
10
+
11
+ FINTECTURE_API_URL = {
12
+ local: 'http://localhost:3030',
13
+ test: 'https://api-sandbox-test.fintecture.com',
14
+ sandbox: 'https://api-sandbox-test.fintecture.com',
15
+ production: 'https://api.fintecture.com'
16
+ }
17
+
18
+ FINTECTURE_CONNECT_URL = {
19
+ local: 'http://localhost:4201',
20
+ test: 'https://connect-test.fintecture.com',
21
+ sandbox: 'https://connect-sandbox.fintecture.com',
22
+ production: 'https://connect.fintecture.com'
23
+ }
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Fintecture
4
+ module Api
5
+ module Endpoints
6
+ module Ais
7
+ # TODO: faire plus complet, avec un mot clef a remplacer
8
+ CONNECT = 'ais/v2/connect'
9
+ ACCOUNTS = 'ais/v1/customer'
10
+ TRANSACTIONS = 'ais/v1/customer'
11
+ ACCOUNTHOLDERS = 'ais/v1/customer'
12
+ CUSTOMER = 'ais/v1/customer'
13
+ AUTHORIZE = 'ais/v1/provider'
14
+ end
15
+ end
16
+ end
17
+ end
@@ -1,13 +1,13 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Fintecture
2
4
  module Api
3
5
  module Endpoints
4
6
  module Authentication
5
-
6
7
  OAUTH_TOKEN_AUTHORIZE = '/token/authorize'
7
8
  OAUTH_ACCESS_TOKEN = '/accesstoken'
8
9
  OAUTH_REFRESH_TOKEN = '/refreshtoken'
9
-
10
10
  end
11
11
  end
12
12
  end
13
- end
13
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Fintecture
4
+ module Api
5
+ module Endpoints
6
+ module Pis
7
+ INITIATE = 'pis/v2/provider'
8
+ REFUND = 'pis/v2/refund'
9
+ REQUEST_TO_PAY = 'pis/v2/request-to-pay'
10
+ PAYMENTS = 'pis/v2/payments'
11
+ CONNECT = 'pis/v2/connect'
12
+ SETTLEMENTS = 'pis/v2/settlements'
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Fintecture
4
+ module Api
5
+ module Endpoints
6
+ module Ressources
7
+ APPLICATION = 'res/v1/applications'
8
+ PROVIDERS = 'res/v1/providers'
9
+ TESTACCOUNTS = 'res/v1/testaccounts'
10
+ end
11
+ end
12
+ end
13
+ end
@@ -1,33 +1,72 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'json'
4
+
1
5
  module Fintecture
2
- class ValidationException < Exception; end
3
- class CryptoException < Exception; end
6
+ class ValidationException < RuntimeError; end
7
+
8
+ class CryptoException < RuntimeError; end
9
+
4
10
  class ApiException
5
11
  class << self
6
-
7
12
  def error(res)
8
13
  body = JSON.parse res.body
9
-
10
- code = body['code']
11
- log_id = body['log_id']
12
- errors = body['errors']
13
14
 
14
- raise Exception.new(_construct_message(res.status, code, log_id, errors))
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
15
22
  end
16
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']
17
31
 
18
- private
19
- def _construct_message(status, code, log_id, errors_array)
20
32
  error_string = "\nFintecture server errors : "
21
33
  error_string += "\n status: #{status} "
22
34
  error_string += "\n code: #{code}"
23
35
  error_string += "\n id : #{log_id}"
36
+
24
37
  errors_array.each do |error|
25
- formated_error = error.map {|key,value| " #{key}: #{value}"}.join("\n")
38
+ formated_error = error.map { |key, value| " #{key}: #{value}" }.join("\n")
26
39
  error_string += "\n\n#{formated_error}"
27
40
  end
28
41
  error_string += "\n\n"
29
- error_string
42
+
43
+ {
44
+ type: 'Fintecture api',
45
+ status: status,
46
+ errors: errors_array,
47
+ error_string: error_string
48
+ }.to_json
49
+ end
50
+
51
+ def _construct_message_error(res, body)
52
+ status = res.status
53
+ error = body['meta']
54
+
55
+ error_string = "\nFintecture server errors : "
56
+ error_string += "\n status: #{status} "
57
+
58
+ formated_error = error.map { |key, value| " #{key}: #{value}" }.join("\n")
59
+ error_string += "\n\n#{formated_error}"
60
+
61
+ error_string += "\n\n"
62
+
63
+ {
64
+ type: 'Fintecture api',
65
+ status: status,
66
+ errors: [error],
67
+ error_string: error_string
68
+ }.to_json
30
69
  end
31
70
  end
32
71
  end
33
- end
72
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'base64'
2
4
  require 'faraday'
3
5
  require 'uri'
@@ -9,112 +11,130 @@ module Fintecture
9
11
  module Authentication
10
12
  class Connection
11
13
  class << self
12
-
13
14
  def connection(url)
14
15
  ::Faraday.new(url: url) do |faraday|
15
16
  faraday.request :url_encoded
16
- faraday.adapter ::Faraday.default_adapter
17
+ faraday.adapter ::Faraday.default_adapter
17
18
  end
18
19
  end
19
20
 
20
- def post(url:, req_body: nil, custom_content_type: nil, bearer: nil, secure_headers: false, additional_headers: nil)
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
21
23
  conn = connection(url)
22
-
23
24
  res = conn.post do |req|
24
25
  req.options.params_encoder = Faraday::DisabledEncoder
25
- req.headers = req_headers(custom_content_type, bearer, secure_headers, additional_headers, method: 'post', body: req_body, url: url)
26
+ req.headers = req_headers(custom_content_type, bearer, secure_headers, additional_headers, disableAuthorization,
27
+ method: 'post', body: req_body, url: url)
26
28
  req.body = req_body
27
29
  end
28
30
 
29
31
  !res.success? ? Fintecture::ApiException.error(res) : res
30
32
  end
31
33
 
32
- def get(url:, req_body: nil, custom_content_type: nil, bearer: nil, secure_headers: false, additional_headers: nil)
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
33
36
  conn = connection(url)
34
37
 
35
38
  res = conn.get do |req|
36
39
  req.options.params_encoder = Faraday::DisabledEncoder
37
- req.headers = req_headers(custom_content_type, bearer, secure_headers, additional_headers, method: 'get', url: url)
40
+ req.headers = req_headers(custom_content_type, bearer, secure_headers, additional_headers, disableAuthorization,
41
+ method: 'get', url: url)
38
42
  req.body = req_body
39
43
  end
40
44
 
41
45
  !res.success? ? Fintecture::ApiException.error(res) : res
42
46
  end
43
47
 
44
- def req_headers(custom_content_type, bearer, secure_headers, additional_headers, method: '', body: {}, url:)
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
45
61
 
46
- client_token = Base64.strict_encode64("#{Fintecture.app_id}:#{Fintecture.app_secret}")
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
47
66
 
48
- {
49
- 'Accept' => 'application/json',
50
- 'User-Agent' => "Fintecture Ruby SDK v #{Fintecture::VERSION}",
51
- 'Authorization' => bearer ? bearer : "Basic #{client_token}",
52
- 'Content-Type' => custom_content_type ? custom_content_type : 'application/x-www-form-urlencoded',
53
- }.merge(secure_headers ? req_secure_headers(additional_headers, body: body, url: url, method: method) : {})
67
+ client_token = Base64.strict_encode64("#{@client.app_id}:#{@client.app_secret}")
54
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) : {})
55
77
  end
56
78
 
57
- def req_secure_headers(additional_headers, body: {}, url: '', method: '')
58
- raise Fintecture::ValidationException.new('additional_headers must be an object') if additional_headers != nil && !additional_headers.is_a?(Hash)
59
-
60
- payload = ( body.class.name == 'String' ? body : body.to_s )
79
+ def req_secure_headers(body: {}, url: '', method: '')
80
+ payload = (body.instance_of?(String) ? body : body.to_s)
61
81
  path_name = URI(url).path
62
82
  search_params = URI(url).query
63
83
 
64
-
65
84
  request_target = search_params ? "#{method.downcase} #{path_name}?#{search_params}" : "#{method.downcase} #{path_name}"
66
85
  date = Fintecture::Utils::Date.header_time.to_s
67
86
  digest = load_digest(payload)
68
87
  x_request_id = Fintecture::Utils::Crypto.generate_uuid
69
88
 
70
-
71
89
  headers = {
72
- 'Date' => date,
73
- 'X-Request-ID' => x_request_id
90
+ 'Date' => date,
91
+ 'X-Request-ID' => x_request_id
74
92
  }.merge(payload ? digest : {})
75
93
 
76
- # Add additional_headers if exists
77
- headers = headers.merge(additional_headers) if additional_headers != nil
78
-
79
-
80
- headers['Signature'] = Fintecture::Utils::Crypto.create_signature_header({'(request-target)' => request_target}.merge(headers))
94
+ headers['Signature'] =
95
+ Fintecture::Utils::Crypto.create_signature_header(
96
+ { '(request-target)' => request_target }.merge(headers), @client
97
+ )
81
98
  headers
82
99
  end
83
100
 
84
101
  def load_digest(payload)
85
- {'Digest' => "SHA-256=#{Fintecture::Utils::Crypto.hash_base64(payload)}"}
102
+ { 'Digest' => "SHA-256=#{Fintecture::Utils::Crypto.hash_base64(payload)}" }
86
103
  end
87
104
 
88
105
  end
89
106
  end
90
107
  end
91
108
 
92
-
93
109
  module DisabledEncoder
94
110
  class << self
95
111
  extend Forwardable
96
112
  def_delegators :'Faraday::Utils', :escape, :unescape
97
113
  end
98
-
99
114
 
100
115
  def self.encode(params)
101
116
  return nil if params.nil?
102
-
103
- query_string = "#{params.map{|key, value| "#{key}=#{value}"}.join('&')}"
104
-
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
105
130
  end
106
-
107
131
 
108
-
109
132
  class << self
110
133
  attr_accessor :sort_params
111
134
  end
112
-
135
+
113
136
  # Useful default for OAuth and caching.
114
137
  @sort_params = true
115
138
  end
116
139
  end
117
140
  end
118
-
119
-
120
-
@@ -0,0 +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)
77
+ res = Fintecture::Pis::Settlements.get self, settlement_id
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,14 +1,11 @@
1
-
2
-
1
+ # frozen_string_literal: true
3
2
 
4
3
  module Fintecture
5
4
  module Utils
6
5
  module Constants
7
-
8
- SIGNEDHEADERPARAMETERLIST = %w[(request-target) Date Digest X-Request-ID];
9
- PSU_TYPES = %w[retail corporate all]
10
- SCOPES = %w[pis ais]
11
-
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
12
9
  end
13
10
  end
14
- end
11
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'securerandom'
2
4
  require 'openssl'
3
5
  require 'base64'
@@ -10,39 +12,38 @@ module Fintecture
10
12
  module Utils
11
13
  class Crypto
12
14
  class << self
13
-
14
15
  def generate_uuid
15
16
  SecureRandom.uuid
16
17
  end
17
18
 
18
19
  def generate_uuid_only_chars
19
- generate_uuid.gsub!('-','')
20
+ generate_uuid.gsub!('-', '')
20
21
  end
21
22
 
22
23
  def sign_payload(payload)
23
24
  payload = payload.to_json.to_s if payload.is_a? Hash
24
- digest = OpenSSL::Digest::SHA256.new
25
- private_key = OpenSSL::PKey::RSA.new(Fintecture.private_key)
25
+ digest = OpenSSL::Digest.new('SHA256')
26
+ private_key = OpenSSL::PKey::RSA.new(@client.private_key)
26
27
 
27
28
  begin
28
29
  signature = private_key.sign(digest, payload)
29
30
  Base64.strict_encode64(signature)
30
- rescue
31
- raise Fintecture::CryptoException.new('error during signature')
31
+ rescue StandardError
32
+ raise Fintecture::CryptoException, 'error during signature'
32
33
  end
33
34
  end
34
35
 
35
36
  def decrypt_private(digest)
36
37
  digest = URI.unescape digest
37
38
  encrypted_string = Base64.decode64(digest)
38
- private_key = OpenSSL::PKey::RSA.new(Fintecture.private_key)
39
+ private_key = OpenSSL::PKey::RSA.new(@client.private_key)
39
40
 
40
41
  begin
41
42
  private_key.private_decrypt(encrypted_string, OpenSSL::PKey::RSA::PKCS1_OAEP_PADDING)
42
43
  rescue OpenSSL::PKey::RSAError => e
43
- raise Fintecture::CryptoException.new("error while decrypt, #{e.message}")
44
- rescue
45
- raise Fintecture::CryptoException.new('error during decryption')
44
+ raise Fintecture::CryptoException, "error while decrypt, #{e.message}"
45
+ rescue StandardError
46
+ raise Fintecture::CryptoException, 'error during decryption'
46
47
  end
47
48
  end
48
49
 
@@ -51,12 +52,11 @@ module Fintecture
51
52
  Base64.strict_encode64(digest)
52
53
  end
53
54
 
54
- def create_signature_header(headers)
55
+ def create_signature_header(headers, client)
56
+ @client = client
55
57
  signing = []
56
58
  header = []
57
59
 
58
-
59
-
60
60
  Fintecture::Utils::Constants::SIGNEDHEADERPARAMETERLIST.each do |param|
61
61
  next unless headers[param]
62
62
 
@@ -64,15 +64,12 @@ module Fintecture
64
64
  signing << "#{param_low}: #{headers[param]}"
65
65
  header << param_low
66
66
  end
67
-
68
67
 
69
68
  # Double quote in join needed. If not we will get two slashes \\n
70
69
  signature = sign_payload signing.join("\n")
71
- 'keyId="' + Fintecture.app_id + '",algorithm="rsa-sha256",headers="' + header.join(' ') + '",signature="' + signature + '"'
72
-
70
+ "keyId=\"#{@client.app_id}\",algorithm=\"rsa-sha256\",headers=\"#{header.join(' ')}\",signature=\"#{signature}\""
73
71
  end
74
-
75
72
  end
76
73
  end
77
74
  end
78
- end
75
+ end
@@ -1,15 +1,15 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'time'
2
4
 
3
5
  module Fintecture
4
6
  module Utils
5
7
  class Date
6
8
  class << self
7
-
8
9
  def header_time
9
- Time.now.utc.strftime("%a, %d %b %Y %H:%M:%S GMT")
10
+ Time.now.utc.strftime('%a, %d %b %Y %H:%M:%S GMT')
10
11
  end
11
-
12
12
  end
13
13
  end
14
14
  end
15
- end
15
+ end