fintecture 0.1.7 → 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 (55) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +17 -16
  3. data/.rspec +3 -3
  4. data/.travis.yml +7 -7
  5. data/CODE_OF_CONDUCT.md +74 -74
  6. data/Gemfile +8 -6
  7. data/Gemfile.lock +59 -40
  8. data/LICENSE.txt +674 -674
  9. data/README.md +404 -121
  10. data/Rakefile +8 -6
  11. data/bin/console +15 -14
  12. data/bin/setup +8 -8
  13. data/exemples/ais.rb +53 -0
  14. data/exemples/config_ais.json +8 -0
  15. data/exemples/config_pis.json +6 -0
  16. data/exemples/pis.rb +148 -0
  17. data/exemples/ressources.rb +23 -0
  18. data/fintecture.gemspec +44 -43
  19. data/lib/fintecture/ais_client.rb +94 -0
  20. data/lib/fintecture/api/ais/account_holders.rb +61 -0
  21. data/lib/fintecture/api/ais/accounts.rb +63 -0
  22. data/lib/fintecture/api/ais/authorize.rb +72 -0
  23. data/lib/fintecture/api/ais/authorize_decoupled.rb +68 -0
  24. data/lib/fintecture/api/ais/connect.rb +65 -0
  25. data/lib/fintecture/api/ais/delete_customer.rb +53 -0
  26. data/lib/fintecture/api/ais/transactions.rb +64 -0
  27. data/lib/fintecture/{authentication.rb → api/auth/authentication.rb} +78 -76
  28. data/lib/fintecture/api/pis/connect.rb +77 -0
  29. data/lib/fintecture/api/pis/initiate.rb +52 -0
  30. data/lib/fintecture/api/pis/payments.rb +48 -0
  31. data/lib/fintecture/api/pis/refund.rb +67 -0
  32. data/lib/fintecture/api/pis/request_to_pay.rb +63 -0
  33. data/lib/fintecture/api/pis/settlements.rb +48 -0
  34. data/lib/fintecture/api/ressources/applications.rb +57 -0
  35. data/lib/fintecture/api/ressources/providers.rb +61 -0
  36. data/lib/fintecture/api/ressources/test_accounts.rb +60 -0
  37. data/lib/fintecture/base_url.rb +26 -0
  38. data/lib/fintecture/endpoints/ais.rb +17 -0
  39. data/lib/fintecture/{api/endpoints → endpoints}/authentication.rb +13 -13
  40. data/lib/fintecture/endpoints/pis.rb +16 -0
  41. data/lib/fintecture/endpoints/ressources.rb +13 -0
  42. data/lib/fintecture/exceptions.rb +72 -4
  43. data/lib/fintecture/faraday/authentication/connection.rb +140 -74
  44. data/lib/fintecture/pis_client.rb +100 -0
  45. data/lib/fintecture/utils/constants.rb +11 -14
  46. data/lib/fintecture/utils/crypto.rb +75 -76
  47. data/lib/fintecture/utils/date.rb +15 -15
  48. data/lib/fintecture/utils/validation.rb +32 -17
  49. data/lib/fintecture/version.rb +5 -3
  50. data/lib/fintecture.rb +65 -82
  51. metadata +35 -13
  52. data/lib/fintecture/api/base_url.rb +0 -28
  53. data/lib/fintecture/api/endpoints/pis.rb +0 -13
  54. data/lib/fintecture/connect.rb +0 -172
  55. data/lib/fintecture/pis.rb +0 -61
@@ -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
@@ -0,0 +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
@@ -0,0 +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,76 +1,78 @@
1
- require 'json'
2
- require 'faraday'
3
-
4
- module Fintecture
5
- class Authentication
6
- class << self
7
-
8
- def authorize(redirect_uri, state = nil)
9
- query_string = "?#{{
10
- response_type: 'code',
11
- app_id: Fintecture.app_id,
12
- redirect_uri: redirect_uri,
13
- state: state
14
- }.map{|key, value| "#{key}=#{value}"}.join('&')}"
15
-
16
- ::Faraday.get "#{token_authorize_endpoint}#{query_string}"
17
- end
18
-
19
- def get_access_token(auth_code = nil)
20
- body = access_token_data auth_code
21
-
22
- Fintecture::Faraday::Authentication::Connection.post url: access_token_url, req_body: body
23
- end
24
-
25
- def refresh_token(refresh_token)
26
- body = refresh_token_data refresh_token
27
-
28
- Fintecture::Faraday::Authentication::Connection.post url: refresh_token_url, req_body: body
29
- end
30
-
31
- private
32
-
33
- def base_url
34
- Fintecture::Api::BaseUrl::FINTECTURE_OAUTH_URL[Fintecture.environment.to_sym]
35
- end
36
-
37
- def token_authorize_endpoint
38
- "#{base_url}#{Fintecture::Api::Endpoints::Authentication::OAUTH_TOKEN_AUTHORIZE}"
39
- end
40
-
41
- def access_token_url
42
- "#{base_url}#{Fintecture::Api::Endpoints::Authentication::OAUTH_ACCESS_TOKEN}"
43
- end
44
-
45
- def refresh_token_url
46
- "#{base_url}#{Fintecture::Api::Endpoints::Authentication::OAUTH_REFRESH_TOKEN}"
47
- end
48
-
49
- def access_token_data(auth_code)
50
- data = {
51
- scope: 'PIS',
52
- app_id: Fintecture.app_id,
53
- grant_type: 'client_credentials'
54
- }
55
-
56
- if auth_code
57
- data = {
58
- scope: 'AIS',
59
- code: auth_code,
60
- grant_type: 'authorization_code'
61
- }
62
- end
63
-
64
- data
65
- end
66
-
67
- def refresh_token_data(refresh_token)
68
- {
69
- grant_type: 'refresh_token',
70
- refresh_token: refresh_token
71
- }
72
- end
73
-
74
- end
75
- end
76
- 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
@@ -0,0 +1,77 @@
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 Pis
13
+ class Connect
14
+ class << self
15
+ # ------------ PUBLIC METHOD ------------
16
+ def generate(client, payload, state, redirect_uri, origin_uri)
17
+ @client = client
18
+
19
+ # Build the request payload
20
+ payload = _build_payload(payload)
21
+
22
+ # Do the request
23
+ _request payload, state, redirect_uri, origin_uri
24
+ end
25
+
26
+ private
27
+
28
+ # ------------ REQUEST ------------
29
+ def _request(payload, state, redirect_uri, origin_uri)
30
+ # Get the url request
31
+ url = _endpoint
32
+
33
+ # Build uri params
34
+ params = {}
35
+ params['redirect_uri'] = redirect_uri if redirect_uri
36
+ params['origin_uri'] = origin_uri if origin_uri
37
+ params['state'] = state
38
+
39
+ query_string = "?#{params.map { |key, value| "#{key}=#{value}" }.join('&')}"
40
+
41
+ # Do connect request
42
+ Fintecture::Faraday::Authentication::Connection.post(
43
+ url: url + query_string,
44
+ req_body: payload.to_json,
45
+ client: @client,
46
+ custom_content_type: 'application/json',
47
+ bearer: "Bearer #{@client.token}",
48
+ secure_headers: true
49
+ )
50
+ end
51
+
52
+ # ------------ BUILD PAYLOAD ------------
53
+ def _build_payload(payload)
54
+ payload[:data][:attributes][:amount] = payload[:data][:attributes][:amount].to_s
55
+
56
+ unless payload[:data][:attributes][:end_to_end_id]
57
+ payload[:data][:attributes][:end_to_end_id] =
58
+ Fintecture::Utils::Crypto.generate_uuid_only_chars
59
+ end
60
+
61
+ payload
62
+ end
63
+
64
+ # ------------ API ENDPOINT ------------
65
+ def _endpoint
66
+ "#{_api_base_url}/#{Fintecture::Api::Endpoints::Pis::CONNECT}"
67
+ end
68
+
69
+ # ------------ BASE URL ------------
70
+ def _api_base_url
71
+ Fintecture::Api::BaseUrl::FINTECTURE_API_URL[@client.environment.to_sym]
72
+ end
73
+
74
+ end
75
+ end
76
+ end
77
+ end
@@ -0,0 +1,52 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Fintecture
4
+ module Pis
5
+ class Initiate
6
+ class << self
7
+ # ------------ PUBLIC METHOD ------------
8
+ def generate(client, payload, provider_id, redirect_uri, state)
9
+ @client = client
10
+
11
+ # Do the _request request
12
+ _request payload, provider_id, redirect_uri, state
13
+ end
14
+
15
+ private
16
+
17
+ # ------------ REQUEST ------------
18
+ def _request(payload, provider_id, redirect_uri, state)
19
+ # Get the url request
20
+ url = _endpoint provider_id
21
+
22
+ # Build uri params
23
+ params = {}
24
+ params['state'] = state
25
+ params['redirect_uri'] = redirect_uri
26
+ query_string = "?#{params.map { |key, value| "#{key}=#{value}" }.join('&')}"
27
+
28
+ # Do connect request
29
+ Fintecture::Faraday::Authentication::Connection.post(
30
+ url: url + query_string,
31
+ req_body: payload.to_json,
32
+ client: @client,
33
+ custom_content_type: 'application/json',
34
+ bearer: "Bearer #{@client.token}",
35
+ secure_headers: true
36
+ )
37
+ end
38
+
39
+ # ------------ API ENDPOINT ------------
40
+ def _endpoint(provider_id)
41
+ "#{_api_base_url}/#{Fintecture::Api::Endpoints::Pis::INITIATE}/#{provider_id}/initiate"
42
+ end
43
+
44
+ # ------------ BASE URL ------------
45
+ def _api_base_url
46
+ Fintecture::Api::BaseUrl::FINTECTURE_API_URL[@client.environment.to_sym]
47
+ end
48
+
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,48 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'json'
4
+ require 'faraday'
5
+ require 'fintecture/endpoints/pis'
6
+ require 'fintecture/base_url'
7
+
8
+ module Fintecture
9
+ module Pis
10
+ class Payments
11
+ class << self
12
+ # ------------ PUBLIC METHOD ------------
13
+ def get(client, session_id)
14
+ @client = client
15
+
16
+ # Do the get_payments request
17
+ _request session_id
18
+ end
19
+
20
+ private
21
+
22
+ # ------------ REQUEST ------------
23
+ def _request(session_id)
24
+ url = _endpoint
25
+
26
+ Fintecture::Faraday::Authentication::Connection.get(
27
+ url: "#{url}/#{session_id}",
28
+ client: @client,
29
+ custom_content_type: 'application/json',
30
+ bearer: "Bearer #{@client.token}",
31
+ secure_headers: true
32
+ )
33
+ end
34
+
35
+ # ------------ API ENDPOINT ------------
36
+ def _endpoint
37
+ "#{_api_base_url}/#{Fintecture::Api::Endpoints::Pis::PAYMENTS}"
38
+ end
39
+
40
+ # ------------ BASE URL ------------
41
+ def _api_base_url
42
+ Fintecture::Api::BaseUrl::FINTECTURE_API_URL[@client.environment.to_sym]
43
+ end
44
+
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,67 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'json'
4
+ require 'faraday'
5
+ require 'fintecture/endpoints/pis'
6
+ require 'fintecture/base_url'
7
+ module Fintecture
8
+ module Pis
9
+ class Refund
10
+ class << self
11
+ # ------------ PUBLIC METHOD ------------
12
+ def generate(client, session_id, amount)
13
+ @client = client
14
+
15
+ # Build the request payload
16
+ payload = _build_payload session_id, amount
17
+ # Do the _request request
18
+ _request payload
19
+ end
20
+
21
+ private
22
+
23
+ # ------------ REQUEST ------------
24
+ def _request(payload)
25
+ # Get the url request
26
+ url = _endpoint
27
+
28
+ # Do connect request
29
+ Fintecture::Faraday::Authentication::Connection.post(
30
+ url: url,
31
+ req_body: payload.to_json,
32
+ client: @client,
33
+ custom_content_type: 'application/json',
34
+ bearer: "Bearer #{@client.token}",
35
+ secure_headers: true
36
+ )
37
+ end
38
+
39
+ # ------------ BUILD PAYLOAD ------------
40
+ def _build_payload(session_id, amount)
41
+ # Return the payload
42
+ {
43
+ meta: {
44
+ session_id: session_id
45
+ },
46
+ data: {
47
+ attributes: {
48
+ amount: amount.to_s
49
+ }
50
+ }
51
+ }
52
+ end
53
+
54
+ # ------------ API ENDPOINT ------------
55
+ def _endpoint
56
+ "#{_api_base_url}/#{Fintecture::Api::Endpoints::Pis::REFUND}"
57
+ end
58
+
59
+ # ------------ BASE URL ------------
60
+ def _api_base_url
61
+ Fintecture::Api::BaseUrl::FINTECTURE_API_URL[@client.environment.to_sym]
62
+ end
63
+
64
+ end
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,63 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'json'
4
+ require 'faraday'
5
+ require 'fintecture/endpoints/pis'
6
+ require 'fintecture/base_url'
7
+ module Fintecture
8
+ module Pis
9
+ class RequestToPay
10
+ class << self
11
+ # ------------ PUBLIC METHOD ------------
12
+ def generate(client, payload = nil, x_language, redirect_uri)
13
+ @client = client
14
+
15
+ # Do the _request request
16
+ _request payload, x_language, redirect_uri
17
+ end
18
+
19
+ private
20
+
21
+ # ------------ REQUEST ------------
22
+ def _request(payload, x_language, redirect_uri)
23
+ # Get the url request
24
+ url = _endpoint
25
+
26
+ # Build uri params
27
+ query_string = ''
28
+ if redirect_uri
29
+ params = {}
30
+ params['redirect_uri'] = redirect_uri
31
+ query_string = "?#{params.map { |key, value| "#{key}=#{value}" }.join('&')}"
32
+ end
33
+
34
+ # Build additional headers
35
+ additional_headers = {}
36
+ additional_headers['x-language'] = x_language
37
+
38
+ # Do connect request
39
+ Fintecture::Faraday::Authentication::Connection.post(
40
+ url: url + query_string,
41
+ req_body: payload.to_json,
42
+ client: @client,
43
+ custom_content_type: 'application/json',
44
+ bearer: "Bearer #{@client.token}",
45
+ secure_headers: true,
46
+ additional_headers: additional_headers
47
+ )
48
+ end
49
+
50
+ # ------------ API ENDPOINT ------------
51
+ def _endpoint
52
+ "#{_api_base_url}/#{Fintecture::Api::Endpoints::Pis::REQUEST_TO_PAY}"
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