fintecture 0.2.1 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +17 -19
  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 -59
  8. data/LICENSE.txt +674 -674
  9. data/README.md +407 -238
  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 +50 -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 -33
  43. data/lib/fintecture/faraday/authentication/connection.rb +140 -120
  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 -78
  47. data/lib/fintecture/utils/date.rb +15 -15
  48. data/lib/fintecture/utils/validation.rb +32 -26
  49. data/lib/fintecture/version.rb +5 -3
  50. data/lib/fintecture.rb +65 -82
  51. metadata +35 -12
  52. data/lib/fintecture/api/base_url.rb +0 -29
  53. data/lib/fintecture/api/endpoints/pis.rb +0 -14
  54. data/lib/fintecture/connect.rb +0 -38
  55. data/lib/fintecture/pis.rb +0 -262
@@ -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
@@ -0,0 +1,50 @@
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 Settlements
11
+ class << self
12
+ # ------------ PUBLIC METHOD ------------
13
+ def get(client, settlement_id, include_payments)
14
+ @client = client
15
+
16
+ # Do the get_payments request
17
+ _request settlement_id, include_payments
18
+ end
19
+
20
+ private
21
+
22
+ # ------------ REQUEST ------------
23
+ def _request(settlement_id, include_payments)
24
+ url = _endpoint
25
+ url += "/#{settlement_id}" if settlement_id
26
+ url += "?include=payments" if include_payments
27
+
28
+ Fintecture::Faraday::Authentication::Connection.get(
29
+ url: url,
30
+ client: @client,
31
+ custom_content_type: 'application/json',
32
+ bearer: "Bearer #{@client.token}",
33
+ secure_headers: true
34
+ )
35
+ end
36
+
37
+ # ------------ API ENDPOINT ------------
38
+ def _endpoint
39
+ "#{_api_base_url}/#{Fintecture::Api::Endpoints::Pis::SETTLEMENTS}"
40
+ end
41
+
42
+ # ------------ BASE URL ------------
43
+ def _api_base_url
44
+ Fintecture::Api::BaseUrl::FINTECTURE_API_URL[@client.environment.to_sym]
45
+ end
46
+
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,57 @@
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 Applications
14
+ class << self
15
+ # ------------ PUBLIC METHOD ------------
16
+ def get(client)
17
+ @client = client
18
+
19
+ # Do the request
20
+ _request
21
+ end
22
+
23
+ private
24
+
25
+ # ------------ REQUEST ------------
26
+ def _request
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
+ # Do connect request
35
+ Fintecture::Faraday::Authentication::Connection.get(
36
+ url: url,
37
+ client: @client,
38
+ custom_content_type: 'application/json',
39
+ secure_headers: true,
40
+ additional_headers: additional_headers
41
+ )
42
+ end
43
+
44
+ # ------------ API ENDPOINT ------------
45
+ def _endpoint
46
+ "#{_api_base_url}/#{Fintecture::Api::Endpoints::Ressources::APPLICATION}"
47
+ end
48
+
49
+ # ------------ BASE URL ------------
50
+ def _api_base_url
51
+ Fintecture::Api::BaseUrl::FINTECTURE_API_URL[@client.environment.to_sym]
52
+ end
53
+
54
+ end
55
+ end
56
+ end
57
+ 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 Ressources
13
+ class Providers
14
+ class << self
15
+ # ------------ PUBLIC METHOD ------------
16
+ def get(client, provider_id, paramsProviders)
17
+ @client = client
18
+
19
+ # Do the request
20
+ _request provider_id, paramsProviders
21
+ end
22
+
23
+ private
24
+
25
+ # ------------ REQUEST ------------
26
+ def _request(provider_id, paramsProviders)
27
+ # Get the url request
28
+ url = _endpoint provider_id
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 = "?#{paramsProviders.map { |key, value| "#{key}=#{value}" }.join('&')}" if paramsProviders
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
+ secure_headers: true,
44
+ additional_headers: additional_headers
45
+ )
46
+ end
47
+
48
+ # ------------ API ENDPOINT ------------
49
+ def _endpoint(provider_id)
50
+ "#{_api_base_url}/#{Fintecture::Api::Endpoints::Ressources::PROVIDERS}/#{provider_id || ''}"
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,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://host.docker.internal:3333/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://host.docker.internal:3333',
13
+ test: 'https://api-sandbox-test.fintecture.com',
14
+ sandbox: 'https://api-sandbox.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
- module Fintecture
2
- module Api
3
- module Endpoints
4
- module Authentication
5
-
6
- OAUTH_TOKEN_AUTHORIZE = '/token/authorize'
7
- OAUTH_ACCESS_TOKEN = '/accesstoken'
8
- OAUTH_REFRESH_TOKEN = '/refreshtoken'
9
-
10
- end
11
- end
12
- end
13
- end
1
+ # frozen_string_literal: true
2
+
3
+ module Fintecture
4
+ module Api
5
+ module Endpoints
6
+ module Authentication
7
+ OAUTH_TOKEN_AUTHORIZE = '/token/authorize'
8
+ OAUTH_ACCESS_TOKEN = '/accesstoken'
9
+ OAUTH_REFRESH_TOKEN = '/refreshtoken'
10
+ end
11
+ end
12
+ 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
- module Fintecture
2
- class ValidationException < Exception; end
3
- class CryptoException < Exception; end
4
- class ApiException
5
- class << self
6
-
7
- def error(res)
8
- body = JSON.parse res.body
9
-
10
- code = body['code']
11
- log_id = body['log_id']
12
- errors = body['errors']
13
-
14
- raise Exception.new(_construct_message(res.status, code, log_id, errors))
15
- end
16
-
17
-
18
- private
19
- def _construct_message(status, code, log_id, errors_array)
20
- error_string = "\nFintecture server errors : "
21
- error_string += "\n status: #{status} "
22
- error_string += "\n code: #{code}"
23
- error_string += "\n id : #{log_id}"
24
- errors_array.each do |error|
25
- formated_error = error.map {|key,value| " #{key}: #{value}"}.join("\n")
26
- error_string += "\n\n#{formated_error}"
27
- end
28
- error_string += "\n\n"
29
- error_string
30
- end
31
- end
32
- end
33
- end
1
+ # frozen_string_literal: true
2
+
3
+ require 'json'
4
+
5
+ module Fintecture
6
+ class ValidationException < RuntimeError; end
7
+
8
+ class CryptoException < RuntimeError; end
9
+
10
+ class ApiException
11
+ class << self
12
+ def error(res)
13
+ body = JSON.parse res.body
14
+
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
22
+ end
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']
31
+
32
+ error_string = "\nFintecture server errors : "
33
+ error_string += "\n status: #{status} "
34
+ error_string += "\n code: #{code}"
35
+ error_string += "\n id : #{log_id}"
36
+
37
+ errors_array.each do |error|
38
+ formated_error = error.map { |key, value| " #{key}: #{value}" }.join("\n")
39
+ error_string += "\n\n#{formated_error}"
40
+ end
41
+ error_string += "\n\n"
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
69
+ end
70
+ end
71
+ end
72
+ end