fintecture 0.3.1 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (51) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +17 -17
  3. data/.rspec +3 -3
  4. data/.travis.yml +7 -7
  5. data/CODE_OF_CONDUCT.md +74 -74
  6. data/Gemfile +8 -8
  7. data/Gemfile.lock +1 -1
  8. data/LICENSE.txt +674 -674
  9. data/README.md +407 -404
  10. data/Rakefile +8 -8
  11. data/bin/console +15 -15
  12. data/bin/setup +8 -8
  13. data/exemples/ais.rb +53 -53
  14. data/exemples/config_ais.json +7 -7
  15. data/exemples/config_pis.json +5 -5
  16. data/exemples/pis.rb +148 -148
  17. data/exemples/ressources.rb +23 -23
  18. data/fintecture.gemspec +44 -44
  19. data/lib/fintecture/ais_client.rb +94 -94
  20. data/lib/fintecture/api/ais/account_holders.rb +61 -61
  21. data/lib/fintecture/api/ais/accounts.rb +63 -63
  22. data/lib/fintecture/api/ais/authorize.rb +72 -72
  23. data/lib/fintecture/api/ais/authorize_decoupled.rb +68 -68
  24. data/lib/fintecture/api/ais/connect.rb +65 -65
  25. data/lib/fintecture/api/ais/delete_customer.rb +53 -53
  26. data/lib/fintecture/api/ais/transactions.rb +64 -64
  27. data/lib/fintecture/api/auth/authentication.rb +78 -78
  28. data/lib/fintecture/api/pis/connect.rb +77 -77
  29. data/lib/fintecture/api/pis/initiate.rb +52 -52
  30. data/lib/fintecture/api/pis/payments.rb +48 -48
  31. data/lib/fintecture/api/pis/refund.rb +67 -67
  32. data/lib/fintecture/api/pis/request_to_pay.rb +63 -63
  33. data/lib/fintecture/api/pis/settlements.rb +50 -48
  34. data/lib/fintecture/api/ressources/applications.rb +57 -57
  35. data/lib/fintecture/api/ressources/providers.rb +61 -61
  36. data/lib/fintecture/api/ressources/test_accounts.rb +60 -60
  37. data/lib/fintecture/base_url.rb +26 -26
  38. data/lib/fintecture/endpoints/ais.rb +17 -17
  39. data/lib/fintecture/endpoints/authentication.rb +13 -13
  40. data/lib/fintecture/endpoints/pis.rb +16 -16
  41. data/lib/fintecture/endpoints/ressources.rb +13 -13
  42. data/lib/fintecture/exceptions.rb +72 -72
  43. data/lib/fintecture/faraday/authentication/connection.rb +140 -140
  44. data/lib/fintecture/pis_client.rb +100 -100
  45. data/lib/fintecture/utils/constants.rb +11 -11
  46. data/lib/fintecture/utils/crypto.rb +75 -75
  47. data/lib/fintecture/utils/date.rb +15 -15
  48. data/lib/fintecture/utils/validation.rb +32 -32
  49. data/lib/fintecture/version.rb +5 -5
  50. data/lib/fintecture.rb +65 -65
  51. metadata +6 -6
@@ -1,68 +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
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
@@ -1,65 +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
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
@@ -1,53 +1,53 @@
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 DeleteCustomer
14
- class << self
15
- # ------------ PUBLIC METHOD ------------
16
- def delete(client, customer_id)
17
- @client = client
18
-
19
- # Do the request
20
- _request customer_id
21
- end
22
-
23
- private
24
-
25
- # ------------ REQUEST ------------
26
- def _request(customer_id)
27
- # Get the url request
28
- url = _endpoint customer_id
29
-
30
- # Do connect request
31
- Fintecture::Faraday::Authentication::Connection.delete(
32
- url: url,
33
- client: @client,
34
- custom_content_type: 'application/json',
35
- bearer: "Bearer #{@client.token}",
36
- secure_headers: true
37
- )
38
- end
39
-
40
- # ------------ API ENDPOINT ------------
41
- def _endpoint(customer_id)
42
- "#{_api_base_url}/#{Fintecture::Api::Endpoints::Ais::CUSTOMER}/#{customer_id}"
43
- end
44
-
45
- # ------------ BASE URL ------------
46
- def _api_base_url
47
- Fintecture::Api::BaseUrl::FINTECTURE_API_URL[@client.environment.to_sym]
48
- end
49
-
50
- end
51
- end
52
- end
53
- end
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 DeleteCustomer
14
+ class << self
15
+ # ------------ PUBLIC METHOD ------------
16
+ def delete(client, customer_id)
17
+ @client = client
18
+
19
+ # Do the request
20
+ _request customer_id
21
+ end
22
+
23
+ private
24
+
25
+ # ------------ REQUEST ------------
26
+ def _request(customer_id)
27
+ # Get the url request
28
+ url = _endpoint customer_id
29
+
30
+ # Do connect request
31
+ Fintecture::Faraday::Authentication::Connection.delete(
32
+ url: url,
33
+ client: @client,
34
+ custom_content_type: 'application/json',
35
+ bearer: "Bearer #{@client.token}",
36
+ secure_headers: true
37
+ )
38
+ end
39
+
40
+ # ------------ API ENDPOINT ------------
41
+ def _endpoint(customer_id)
42
+ "#{_api_base_url}/#{Fintecture::Api::Endpoints::Ais::CUSTOMER}/#{customer_id}"
43
+ end
44
+
45
+ # ------------ BASE URL ------------
46
+ def _api_base_url
47
+ Fintecture::Api::BaseUrl::FINTECTURE_API_URL[@client.environment.to_sym]
48
+ end
49
+
50
+ end
51
+ end
52
+ end
53
+ end
@@ -1,64 +1,64 @@
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 Transactions
14
- class << self
15
- # ------------ PUBLIC METHOD ------------
16
- def get(client, customer_id, account_id, remove_nulls, convert_dates, filters)
17
- @client = client
18
-
19
- # Do the request
20
- _request customer_id, account_id, remove_nulls, convert_dates, filters
21
- end
22
-
23
- private
24
-
25
- # ------------ REQUEST ------------
26
- def _request(customer_id, account_id, remove_nulls, convert_dates, filters)
27
- # Get the url request
28
- url = _endpoint customer_id, account_id
29
-
30
- # Build uri params
31
- query_string = ''
32
- if remove_nulls || convert_dates || filters
33
- params = {}
34
- params['remove_nulls'] = remove_nulls if remove_nulls
35
- params['convert_dates'] = convert_dates if convert_dates
36
- filters.each { |key, value| params[key] = value } if filters
37
-
38
- query_string = "?#{params.map { |key, value| "#{key}=#{value}" }.join('&')}"
39
- end
40
-
41
- # Do connect request
42
- Fintecture::Faraday::Authentication::Connection.get(
43
- url: url + query_string,
44
- client: @client,
45
- custom_content_type: 'application/json',
46
- bearer: "Bearer #{@client.token}",
47
- secure_headers: true
48
- )
49
- end
50
-
51
- # ------------ API ENDPOINT ------------
52
- def _endpoint(customer_id, account_id)
53
- "#{_api_base_url}/#{Fintecture::Api::Endpoints::Ais::TRANSACTIONS}/#{customer_id}/accounts/#{account_id}/transactions"
54
- end
55
-
56
- # ------------ BASE URL ------------
57
- def _api_base_url
58
- Fintecture::Api::BaseUrl::FINTECTURE_API_URL[@client.environment.to_sym]
59
- end
60
-
61
- end
62
- end
63
- end
64
- end
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 Transactions
14
+ class << self
15
+ # ------------ PUBLIC METHOD ------------
16
+ def get(client, customer_id, account_id, remove_nulls, convert_dates, filters)
17
+ @client = client
18
+
19
+ # Do the request
20
+ _request customer_id, account_id, remove_nulls, convert_dates, filters
21
+ end
22
+
23
+ private
24
+
25
+ # ------------ REQUEST ------------
26
+ def _request(customer_id, account_id, remove_nulls, convert_dates, filters)
27
+ # Get the url request
28
+ url = _endpoint customer_id, account_id
29
+
30
+ # Build uri params
31
+ query_string = ''
32
+ if remove_nulls || convert_dates || filters
33
+ params = {}
34
+ params['remove_nulls'] = remove_nulls if remove_nulls
35
+ params['convert_dates'] = convert_dates if convert_dates
36
+ filters.each { |key, value| params[key] = value } if filters
37
+
38
+ query_string = "?#{params.map { |key, value| "#{key}=#{value}" }.join('&')}"
39
+ end
40
+
41
+ # Do connect request
42
+ Fintecture::Faraday::Authentication::Connection.get(
43
+ url: url + query_string,
44
+ client: @client,
45
+ custom_content_type: 'application/json',
46
+ bearer: "Bearer #{@client.token}",
47
+ secure_headers: true
48
+ )
49
+ end
50
+
51
+ # ------------ API ENDPOINT ------------
52
+ def _endpoint(customer_id, account_id)
53
+ "#{_api_base_url}/#{Fintecture::Api::Endpoints::Ais::TRANSACTIONS}/#{customer_id}/accounts/#{account_id}/transactions"
54
+ end
55
+
56
+ # ------------ BASE URL ------------
57
+ def _api_base_url
58
+ Fintecture::Api::BaseUrl::FINTECTURE_API_URL[@client.environment.to_sym]
59
+ end
60
+
61
+ end
62
+ end
63
+ end
64
+ end
@@ -1,78 +1,78 @@
1
- # frozen_string_literal: true
2
-
3
- require 'json'
4
- require 'faraday'
5
-
6
- module Fintecture
7
- class Authentication
8
- class << self
9
- def authorize(redirect_uri, state = nil)
10
- query_string = "?#{{
11
- response_type: 'code',
12
- app_id: Fintecture.app_id,
13
- redirect_uri: redirect_uri,
14
- state: state
15
- }.map { |key, value| "#{key}=#{value}" }.join('&')}"
16
-
17
- ::Faraday.get "#{token_authorize_endpoint}#{query_string}"
18
- end
19
-
20
- def get_access_token(client, auth_code = nil)
21
- @client = client
22
- body = access_token_data auth_code
23
-
24
- Fintecture::Faraday::Authentication::Connection.post url: access_token_url, req_body: body, client: client
25
- end
26
-
27
- def refresh_token(client, refresh_token)
28
- @client = client
29
- body = refresh_token_data refresh_token
30
-
31
- Fintecture::Faraday::Authentication::Connection.post url: refresh_token_url, req_body: body, client: client
32
- end
33
-
34
- private
35
-
36
- def base_url
37
- Fintecture::Api::BaseUrl::FINTECTURE_OAUTH_URL[@client.environment.to_sym]
38
- end
39
-
40
- def token_authorize_endpoint
41
- "#{base_url}#{Fintecture::Api::Endpoints::Authentication::OAUTH_TOKEN_AUTHORIZE}"
42
- end
43
-
44
- def access_token_url
45
- "#{base_url}#{Fintecture::Api::Endpoints::Authentication::OAUTH_ACCESS_TOKEN}"
46
- end
47
-
48
- def refresh_token_url
49
- "#{base_url}#{Fintecture::Api::Endpoints::Authentication::OAUTH_REFRESH_TOKEN}"
50
- end
51
-
52
- def access_token_data(auth_code)
53
- data = {
54
- scope: 'PIS',
55
- app_id: @client.app_id,
56
- grant_type: 'client_credentials'
57
- }
58
-
59
- if auth_code
60
- data = {
61
- scope: 'AIS',
62
- code: auth_code,
63
- grant_type: 'authorization_code'
64
- }
65
- end
66
-
67
- data
68
- end
69
-
70
- def refresh_token_data(refresh_token)
71
- {
72
- grant_type: 'refresh_token',
73
- refresh_token: refresh_token
74
- }
75
- end
76
- end
77
- end
78
- end
1
+ # frozen_string_literal: true
2
+
3
+ require 'json'
4
+ require 'faraday'
5
+
6
+ module Fintecture
7
+ class Authentication
8
+ class << self
9
+ def authorize(redirect_uri, state = nil)
10
+ query_string = "?#{{
11
+ response_type: 'code',
12
+ app_id: Fintecture.app_id,
13
+ redirect_uri: redirect_uri,
14
+ state: state
15
+ }.map { |key, value| "#{key}=#{value}" }.join('&')}"
16
+
17
+ ::Faraday.get "#{token_authorize_endpoint}#{query_string}"
18
+ end
19
+
20
+ def get_access_token(client, auth_code = nil)
21
+ @client = client
22
+ body = access_token_data auth_code
23
+
24
+ Fintecture::Faraday::Authentication::Connection.post url: access_token_url, req_body: body, client: client
25
+ end
26
+
27
+ def refresh_token(client, refresh_token)
28
+ @client = client
29
+ body = refresh_token_data refresh_token
30
+
31
+ Fintecture::Faraday::Authentication::Connection.post url: refresh_token_url, req_body: body, client: client
32
+ end
33
+
34
+ private
35
+
36
+ def base_url
37
+ Fintecture::Api::BaseUrl::FINTECTURE_OAUTH_URL[@client.environment.to_sym]
38
+ end
39
+
40
+ def token_authorize_endpoint
41
+ "#{base_url}#{Fintecture::Api::Endpoints::Authentication::OAUTH_TOKEN_AUTHORIZE}"
42
+ end
43
+
44
+ def access_token_url
45
+ "#{base_url}#{Fintecture::Api::Endpoints::Authentication::OAUTH_ACCESS_TOKEN}"
46
+ end
47
+
48
+ def refresh_token_url
49
+ "#{base_url}#{Fintecture::Api::Endpoints::Authentication::OAUTH_REFRESH_TOKEN}"
50
+ end
51
+
52
+ def access_token_data(auth_code)
53
+ data = {
54
+ scope: 'PIS',
55
+ app_id: @client.app_id,
56
+ grant_type: 'client_credentials'
57
+ }
58
+
59
+ if auth_code
60
+ data = {
61
+ scope: 'AIS',
62
+ code: auth_code,
63
+ grant_type: 'authorization_code'
64
+ }
65
+ end
66
+
67
+ data
68
+ end
69
+
70
+ def refresh_token_data(refresh_token)
71
+ {
72
+ grant_type: 'refresh_token',
73
+ refresh_token: refresh_token
74
+ }
75
+ end
76
+ end
77
+ end
78
+ end