fintecture 0.2.1 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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,6 @@
1
+ {
2
+ "environment": "test",
3
+ "app_id": "your_app_id_here",
4
+ "app_secret": "your_app_secret_here",
5
+ "private_key": "your_private_key here"
6
+ }
data/exemples/pis.rb ADDED
@@ -0,0 +1,148 @@
1
+ # frozen_string_literal: true
2
+
3
+ require './lib/fintecture'
4
+
5
+ config = JSON.parse(File.read('./exemples/config_pis.json'))
6
+
7
+ pis_client = Fintecture::PisClient.new({
8
+ environment: config['environment'],
9
+ app_id: config['app_id'],
10
+ app_secret: config['app_secret'],
11
+ private_key: config['private_key']
12
+ })
13
+
14
+ payload_connect = {
15
+ meta: {
16
+ psu_name: 'John Doe', # Mandatory
17
+ psu_email: 'John.Doe@gmail.com', # Mandatory
18
+ psu_phone: '666777888', # Mandatory
19
+ psu_phone_prefix: '', # Optionnal
20
+ psu_ip: '127.0.0.1', # Optionnal (Plante la signature)
21
+ psu_form: '', # Mandatory - if no fixed beneficiary
22
+ psu_incorporation: '', # Mandatory - if no fixed beneficiary
23
+ psu_address: {
24
+ street: 'Main St.', # Mandatory
25
+ # number: '123', # Optional
26
+ complement: '2nd floor', # Optional
27
+ city: 'Paris', # Mandatory
28
+ zip: '75000', # Mandatory
29
+ country: 'fr' # Mandatory
30
+ }
31
+ },
32
+ data: {
33
+ type: 'PIS',
34
+ attributes: {
35
+ amount: '123', # Mandatory
36
+ currency: 'EUR', # Mandatory
37
+ communication: 'Thanks Mom!' # Mandatory
38
+ # execution_date: '2021-09-31', # Optional
39
+ # beneficiary: { # Optional
40
+ # name: "Dummy SA", # Conditional
41
+ # iban: "FR1420041010050500013M02606", # Conditional
42
+ # swift_bic: "FTSBSESSXXX", # Conditional
43
+ # street: "road of somewhere", # Conditional
44
+ # number: "2", # Optional
45
+ # complement:"", # Optional
46
+ # city: "Paris", # Conditional
47
+ # zip: "93160", # Conditional
48
+ # country: "FR", # Conditional
49
+ # form: "", # Mandatory if no fixed beneficiary
50
+ # incorporation: "" # Mandatory if no fixed beneficiary
51
+ # },
52
+ # debited_account_id: 'FR1420041010050500013M02606', # Optional
53
+ # debited_account_type: 'iban', # Mandatory if debited_account_id exist
54
+ # end_to_end_id: '5f78e902907e4209aa8df63659b05d24',
55
+ # scheme: 'AUTO' # Optional
56
+ }
57
+ }
58
+ }
59
+
60
+ payload_request_to_pay = {
61
+ meta: {
62
+ psu_name: 'John Doe', # Mandatory
63
+ psu_email: 'John.Doe@gmail.com', # Mandatory
64
+ psu_phone: '666777888', # Mandatory
65
+ psu_phone_prefix: '+33', # Optionnal
66
+ psu_address: {
67
+ street: 'Main St.', # Mandatory
68
+ number: '123', # Optional
69
+ city: 'Paris', # Mandatory
70
+ zip: '75000', # Mandatory
71
+ country: 'fr' # Mandatory
72
+ },
73
+ expirary: 86_400, # Optional
74
+ cc: 'John.Doe@gmail.com', # Optional
75
+ bcc: 'John.Doe@gmail.com' # Optional
76
+ },
77
+ data: {
78
+ type: 'REQUEST_TO_PAY',
79
+ attributes: {
80
+ amount: 123, # Mandatory
81
+ currency: 'EUR', # Mandatory
82
+ communication: 'Thanks Mom!' # Mandatory
83
+ }
84
+ }
85
+ }
86
+
87
+ payload_initiate = {
88
+ "meta": {
89
+ "psu_name": 'Bob McCheese',
90
+ "psu_email": 'John.Doe@gmail.com',
91
+ "psu_phone": '09743593535',
92
+ "psu_address": {
93
+ "street": 'route de la france',
94
+ "number": '33',
95
+ "complement": '2nd floor',
96
+ "zip": '12001',
97
+ "city": 'Paris',
98
+ "country": 'FR'
99
+ }
100
+ },
101
+ "data": {
102
+ "type": 'PIS',
103
+ "attributes": {
104
+ "amount": '149.30',
105
+ "currency": 'EUR',
106
+ "communication": 'Order 6543321'
107
+ # "beneficiary": {
108
+ # "name": "Bob Smith",
109
+ # "street": "road of somewhere",
110
+ # "number": "2",
111
+ # "city": "Paris",
112
+ # "zip": "93160",
113
+ # "country": "FR",
114
+ # "iban": "FR1420041010050500013M02606",
115
+ # "swift_bic": "BANKFRXXXXX"
116
+ # }
117
+ }
118
+ }
119
+ }
120
+
121
+ paramsProviders = {
122
+ 'filter[country]': 'FR',
123
+ 'filter[pis]': 'SEPA',
124
+ 'filter[ais]': 'Accounts',
125
+ 'filter[psu_type]': 'retail',
126
+ 'filter[auth_model]': 'redirect',
127
+ 'sort[name]': 'ASC',
128
+ 'sort[full_name]': 'ASC',
129
+ 'sort[country]': 'ASC',
130
+ 'sort[provider_id]': 'ASC'
131
+ }
132
+
133
+ # ######################## PIS ########################
134
+ # ------------ Get access token ------------
135
+ pis_client.generate_token
136
+ # ------------ Connect ------------
137
+ puts pis_client.connect payload_connect, 'ok', 'https://www.google.fr'
138
+ # ------------ Request to pay ------------
139
+ puts pis_client.request_to_pay payload_request_to_pay, 'fr', 'https://www.google.fr'
140
+ # ------------ Get payments ------------
141
+ puts pis_client.payments '7f47d3675f5d4964bc416b43af63b06e'
142
+ # ------------ Initiate ------------
143
+ puts pis_client.initiate payload_initiate, 'cmcifrpp', 'https://www.google.fr', 'ok'
144
+ # ------------ Refund ------------
145
+ puts pis_client.refund '7f47d3675f5d4964bc416b43af63b06e', 1
146
+ # ------------ settlements ------------
147
+ pis_client.settlements
148
+ pis_client.settlements '127335fdeb073e0eb2313ba0bd71ad44'
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ require './lib/fintecture'
4
+
5
+ # ------------ Test class -------------
6
+ config = JSON.parse(File.read('./exemples/config_pis.json'))
7
+
8
+ pis_client = Fintecture::PisClient.new({
9
+ environment: config['environment'],
10
+ app_id: config['app_id'],
11
+ app_secret: config['app_secret'],
12
+ private_key: config['private_key']
13
+ })
14
+
15
+ # ######################## RESSOURCES ########################
16
+ # ------------ Get providers ------------
17
+ puts pis_client.providers provider_id: 'agfbfr'
18
+ puts pis_client.providers paramsProviders: paramsProviders
19
+ # ------------ Get applications ------------
20
+ puts pis_client.applications
21
+ # ------------ Get test accounts ------------
22
+ puts pis_client.test_accounts
23
+ puts pis_client.test_accounts 'bbvaes'
data/fintecture.gemspec CHANGED
@@ -1,43 +1,44 @@
1
+ # frozen_string_literal: true
1
2
 
2
- lib = File.expand_path("../lib", __FILE__)
3
+ lib = File.expand_path('lib', __dir__)
3
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
5
  require 'fintecture/version'
5
6
 
6
7
  Gem::Specification.new do |spec|
7
- spec.name = "fintecture"
8
+ spec.name = 'fintecture'
8
9
  spec.version = Fintecture::VERSION
9
10
  spec.authors = ['Fintecture']
10
- spec.email = ["alvaro.fernandez@nazaries.com"]
11
+ spec.email = ['alvaro.fernandez@nazaries.com']
11
12
 
12
13
  spec.summary = 'Short summary'
13
14
  spec.description = 'Longer summary'
14
- spec.homepage = "http://fintecture.com"
15
- spec.license = "GPL-3.0"
15
+ spec.homepage = 'http://fintecture.com'
16
+ spec.license = 'GPL-3.0'
16
17
 
17
18
  # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
19
  # to allow pushing to a single host or delete this section to allow pushing to any host.
19
20
  if spec.respond_to?(:metadata)
20
21
  # spec.metadata["allowed_push_host"] = 'http://mygemserver.com'
21
22
 
22
- spec.metadata["homepage_uri"] = spec.homepage
23
- spec.metadata["source_code_uri"] = "https://github.com/Fintecture/fintecture-sdk-ruby"
23
+ spec.metadata['homepage_uri'] = spec.homepage
24
+ spec.metadata['source_code_uri'] = 'https://github.com/Fintecture/fintecture-sdk-ruby'
24
25
  # spec.metadata["changelog_uri"] = spec.homepage
25
26
  else
26
- raise "RubyGems 2.0 or newer is required to protect against " \
27
- "public gem pushes."
27
+ raise 'RubyGems 2.0 or newer is required to protect against ' \
28
+ 'public gem pushes.'
28
29
  end
29
30
 
30
31
  # Specify which files should be added to the gem when it is released.
31
32
  # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
32
- spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
33
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
33
34
  `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
34
35
  end
35
- spec.bindir = "exe"
36
+ spec.bindir = 'exe'
36
37
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
37
- spec.require_paths = ["lib"]
38
+ spec.require_paths = ['lib']
38
39
 
39
- spec.add_development_dependency "bundler", "~> 2.0"
40
- spec.add_development_dependency "rake", "~> 10.0"
41
- spec.add_development_dependency "rspec", "~> 3.0"
40
+ spec.add_development_dependency 'bundler', '~> 2.0'
41
+ spec.add_development_dependency 'rake', '~> 10.0'
42
+ spec.add_development_dependency 'rspec', '~> 3.0'
42
43
  spec.add_dependency 'faraday'
43
44
  end
@@ -0,0 +1,94 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'fintecture/api/ais/connect'
4
+ require 'fintecture/api/ais/accounts'
5
+ require 'fintecture/api/ais/transactions'
6
+ require 'fintecture/api/ais/account_holders'
7
+ require 'fintecture/api/ais/delete_customer'
8
+ require 'fintecture/api/ais/authorize'
9
+ require 'fintecture/api/ais/authorize_decoupled'
10
+
11
+ module Fintecture
12
+ class AisClient
13
+ @environment = 'sandbox'
14
+ @environments = %w[local sandbox production].freeze
15
+
16
+ def initialize(config)
17
+ @app_id = config[:app_id]
18
+ @app_secret = config[:app_secret]
19
+ @private_key = config[:private_key]
20
+
21
+ environment = config[:environment].downcase
22
+ unless environment.include?(environment)
23
+ raise "#{environment} not a valid environment, options are [#{environment.join(', ')}]"
24
+ end
25
+
26
+ @environment = environment
27
+ end
28
+
29
+ # Getters
30
+ attr_reader :app_id, :app_secret, :private_key, :environment, :token, :token_expires_in, :refresh_token
31
+
32
+ # Methodes
33
+ def connect(state, redirect_uri, scope = nil)
34
+ res = Fintecture::Ais::Connect.generate self, state, redirect_uri, scope
35
+
36
+ JSON.parse res.body
37
+ end
38
+
39
+ def generate_token(auth_code)
40
+ res = Fintecture::Authentication.get_access_token self, auth_code
41
+ body = JSON.parse res.body
42
+ @token = body['access_token']
43
+ @token_expires_in = body['expires_in']
44
+ @refresh_token = body['refresh_token']
45
+
46
+ body
47
+ end
48
+
49
+ def generate_refresh_token(refresh_token = nil)
50
+ res = Fintecture::Authentication.refresh_token self, (refresh_token || @refresh_token)
51
+ body = JSON.parse res.body
52
+ @token = body['access_token']
53
+
54
+ body
55
+ end
56
+
57
+ def accounts(customer_id:, account_id: nil, remove_nulls: nil, withBalances: nil)
58
+ res = Fintecture::Ais::Accounts.get self, customer_id, account_id, remove_nulls, withBalances
59
+
60
+ JSON.parse res.body
61
+ end
62
+
63
+ def transactions(customer_id:, account_id:, remove_nulls: nil, convert_dates: nil, filters: nil)
64
+ res = Fintecture::Ais::Transactions.get self, customer_id, account_id, remove_nulls, convert_dates, filters
65
+
66
+ JSON.parse res.body
67
+ end
68
+
69
+ def account_holders(customer_id:, remove_nulls: nil)
70
+ res = Fintecture::Ais::AccountHolders.get self, customer_id, remove_nulls
71
+
72
+ JSON.parse res.body
73
+ end
74
+
75
+ def delete_customer(customer_id:)
76
+ res = Fintecture::Ais::DeleteCustomer.delete self, customer_id
77
+
78
+ JSON.parse res.body
79
+ end
80
+
81
+ def authorize(provider_id:, redirect_uri:, app_id_auth: false, state: nil, x_psu_id: nil, x_psu_ip_address: nil)
82
+ res = Fintecture::Ais::Authorize.get self, app_id_auth, provider_id, redirect_uri, state, x_psu_id,
83
+ x_psu_ip_address
84
+
85
+ JSON.parse res.body
86
+ end
87
+
88
+ def authorize_decoupled(provider_id:, polling_id:, app_id_auth: false)
89
+ res = Fintecture::Ais::AuthorizeDecoupled.get self, app_id_auth, provider_id, polling_id
90
+
91
+ JSON.parse res.body
92
+ end
93
+ end
94
+ end
@@ -0,0 +1,61 @@
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 Ais
13
+ class AccountHolders
14
+ class << self
15
+ # ------------ PUBLIC METHOD ------------
16
+ def get(client, customer_id, remove_nulls)
17
+ @client = client
18
+
19
+ # Do the request
20
+ _request customer_id, remove_nulls
21
+ end
22
+
23
+ private
24
+
25
+ # ------------ REQUEST ------------
26
+ def _request(customer_id, remove_nulls)
27
+ # Get the url request
28
+ url = _endpoint customer_id
29
+
30
+ # Build uri params
31
+ query_string = ''
32
+ if remove_nulls
33
+ params = {}
34
+ params['remove_nulls'] = remove_nulls if remove_nulls
35
+ query_string = "?#{params.map { |key, value| "#{key}=#{value}" }.join('&')}"
36
+ end
37
+
38
+ # Do connect request
39
+ Fintecture::Faraday::Authentication::Connection.get(
40
+ url: url + query_string,
41
+ client: @client,
42
+ custom_content_type: 'application/json',
43
+ bearer: "Bearer #{@client.token}",
44
+ secure_headers: true
45
+ )
46
+ end
47
+
48
+ # ------------ API ENDPOINT ------------
49
+ def _endpoint(customer_id)
50
+ "#{_api_base_url}/#{Fintecture::Api::Endpoints::Ais::ACCOUNTHOLDERS}/#{customer_id}/accountholders"
51
+ end
52
+
53
+ # ------------ BASE URL ------------
54
+ def _api_base_url
55
+ Fintecture::Api::BaseUrl::FINTECTURE_API_URL[@client.environment.to_sym]
56
+ end
57
+
58
+ end
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,63 @@
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 Ais
13
+ class Accounts
14
+ class << self
15
+ # ------------ PUBLIC METHOD ------------
16
+ def get(client, customer_id, account_id, remove_nulls, withBalances)
17
+ @client = client
18
+
19
+ # Do the request
20
+ _request customer_id, account_id, remove_nulls, withBalances
21
+ end
22
+
23
+ private
24
+
25
+ # ------------ REQUEST ------------
26
+ def _request(customer_id, account_id, remove_nulls, withBalances)
27
+ # Get the url request
28
+ url = _endpoint customer_id, account_id
29
+
30
+ # Build uri params
31
+ query_string = ''
32
+ if remove_nulls || withBalances
33
+ params = {}
34
+ params['remove_nulls'] = remove_nulls if remove_nulls
35
+ params['withBalances'] = withBalances if withBalances
36
+
37
+ query_string = "?#{params.map { |key, value| "#{key}=#{value}" }.join('&')}"
38
+ end
39
+
40
+ # Do connect request
41
+ Fintecture::Faraday::Authentication::Connection.get(
42
+ url: url + query_string,
43
+ client: @client,
44
+ custom_content_type: 'application/json',
45
+ bearer: "Bearer #{@client.token}",
46
+ secure_headers: true
47
+ )
48
+ end
49
+
50
+ # ------------ API ENDPOINT ------------
51
+ def _endpoint(customer_id, account_id)
52
+ "#{_api_base_url}/#{Fintecture::Api::Endpoints::Ais::ACCOUNTS}/#{customer_id}/accounts/#{account_id || ''}"
53
+ end
54
+
55
+ # ------------ BASE URL ------------
56
+ def _api_base_url
57
+ Fintecture::Api::BaseUrl::FINTECTURE_API_URL[@client.environment.to_sym]
58
+ end
59
+
60
+ end
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,72 @@
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 Ais
13
+ class Authorize
14
+ class << self
15
+ # ------------ PUBLIC METHOD ------------
16
+ def get(client, app_id_auth, provider_id, redirect_uri, state, x_psu_id, x_psu_ip_address)
17
+ @client = client
18
+
19
+ # Do the request
20
+ _request app_id_auth, provider_id, redirect_uri, state, x_psu_id, x_psu_ip_address
21
+ end
22
+
23
+ private
24
+
25
+ # ------------ REQUEST ------------
26
+ def _request(app_id_auth, provider_id, redirect_uri, state, x_psu_id, x_psu_ip_address)
27
+ # Get the url request
28
+ url = _endpoint provider_id
29
+
30
+ # Build uri params
31
+ query_string = ''
32
+
33
+ params = {}
34
+ params['response_type'] = 'code' if app_id_auth
35
+ params['redirect_uri'] = redirect_uri if redirect_uri
36
+ params['state'] = state if state
37
+ params['model'] = 'redirect'
38
+
39
+ query_string = "?#{params.map { |key, value| "#{key}=#{value}" }.join('&')}"
40
+
41
+ # Build additional headers
42
+ additional_headers = {}
43
+ additional_headers['app_id'] = @client.app_id if app_id_auth
44
+ additional_headers['x-psu-id'] = x_psu_id if x_psu_id
45
+ additional_headers['x-psu-ip-address'] = x_psu_ip_address if x_psu_ip_address
46
+
47
+ # Do connect request
48
+ Fintecture::Faraday::Authentication::Connection.get(
49
+ url: url + query_string,
50
+ client: @client,
51
+ custom_content_type: 'application/json',
52
+ bearer: "Bearer #{@client.token}",
53
+ secure_headers: true,
54
+ additional_headers: additional_headers,
55
+ disableAuthorization: app_id_auth ? true : false
56
+ )
57
+ end
58
+
59
+ # ------------ API ENDPOINT ------------
60
+ def _endpoint(provider_id)
61
+ "#{_api_base_url}/#{Fintecture::Api::Endpoints::Ais::AUTHORIZE}/#{provider_id}/authorize"
62
+ end
63
+
64
+ # ------------ BASE URL ------------
65
+ def _api_base_url
66
+ Fintecture::Api::BaseUrl::FINTECTURE_API_URL[@client.environment.to_sym]
67
+ end
68
+
69
+ end
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,68 @@
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 Ais
13
+ class AuthorizeDecoupled
14
+ class << self
15
+ # ------------ PUBLIC METHOD ------------
16
+ def get(client, app_id_auth, provider_id, polling_id)
17
+ @client = client
18
+
19
+ # Do the request
20
+ _request app_id_auth, provider_id, polling_id
21
+ end
22
+
23
+ private
24
+
25
+ # ------------ REQUEST ------------
26
+ def _request(app_id_auth, provider_id, polling_id)
27
+ # Get the url request
28
+ url = _endpoint provider_id, polling_id
29
+
30
+ # Build uri params
31
+ query_string = ''
32
+
33
+ params = {}
34
+ params['response_type'] = 'code' if app_id_auth
35
+ params['model'] = 'decoupled'
36
+
37
+ query_string = "?#{params.map { |key, value| "#{key}=#{value}" }.join('&')}"
38
+
39
+ # Build additional headers
40
+ additional_headers = {}
41
+ additional_headers['app_id'] = @client.app_id if app_id_auth
42
+
43
+ # Do connect request
44
+ Fintecture::Faraday::Authentication::Connection.get(
45
+ url: url + query_string,
46
+ client: @client,
47
+ custom_content_type: 'application/json',
48
+ bearer: "Bearer #{@client.token}",
49
+ secure_headers: true,
50
+ additional_headers: additional_headers,
51
+ disableAuthorization: app_id_auth ? true : false
52
+ )
53
+ end
54
+
55
+ # ------------ API ENDPOINT ------------
56
+ def _endpoint(provider_id, polling_id)
57
+ "#{_api_base_url}/#{Fintecture::Api::Endpoints::Ais::AUTHORIZE}/#{provider_id}/authorize/decoupled/#{polling_id}"
58
+ end
59
+
60
+ # ------------ BASE URL ------------
61
+ def _api_base_url
62
+ Fintecture::Api::BaseUrl::FINTECTURE_API_URL[@client.environment.to_sym]
63
+ end
64
+
65
+ end
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,65 @@
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 Ais
13
+ class Connect
14
+ class << self
15
+ # ------------ PUBLIC METHOD ------------
16
+ def generate(client, state, redirect_uri, scope)
17
+ @client = client
18
+
19
+ # Do the request
20
+ _request state, redirect_uri, scope
21
+ end
22
+
23
+ private
24
+
25
+ # ------------ REQUEST ------------
26
+ def _request(state, redirect_uri, scope)
27
+ # Get the url request
28
+ url = _endpoint
29
+
30
+ # Build uri params
31
+ params = {}
32
+ params['state'] = state
33
+ params['redirect_uri'] = redirect_uri
34
+ params['scope'] = scope if scope
35
+
36
+ query_string = "?#{params.map { |key, value| "#{key}=#{value}" }.join('&')}"
37
+
38
+ # Build additional headers
39
+ additional_headers = {}
40
+ additional_headers['app_id'] = @client.app_id
41
+
42
+ # Do connect request
43
+ Fintecture::Faraday::Authentication::Connection.get(
44
+ url: url + query_string,
45
+ client: @client,
46
+ custom_content_type: 'application/json',
47
+ secure_headers: true,
48
+ additional_headers: additional_headers
49
+ )
50
+ end
51
+
52
+ # ------------ API ENDPOINT ------------
53
+ def _endpoint
54
+ "#{_api_base_url}/#{Fintecture::Api::Endpoints::Ais::CONNECT}"
55
+ end
56
+
57
+ # ------------ BASE URL ------------
58
+ def _api_base_url
59
+ Fintecture::Api::BaseUrl::FINTECTURE_API_URL[@client.environment.to_sym]
60
+ end
61
+
62
+ end
63
+ end
64
+ end
65
+ end