virementmaitrise 0.6.2
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.
- checksums.yaml +7 -0
- data/.gitignore +23 -0
- data/.rspec +3 -0
- data/.travis.yml +7 -0
- data/CHANGELOG.md +6 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +8 -0
- data/Gemfile.lock +59 -0
- data/LICENSE.txt +674 -0
- data/README.md +404 -0
- data/Rakefile +8 -0
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/exemples/ais.rb +53 -0
- data/exemples/pis.rb +148 -0
- data/exemples/ressources.rb +23 -0
- data/lib/virementmaitrise/ais_client.rb +112 -0
- data/lib/virementmaitrise/api/ais/account_holders.rb +60 -0
- data/lib/virementmaitrise/api/ais/accounts.rb +62 -0
- data/lib/virementmaitrise/api/ais/authorize.rb +71 -0
- data/lib/virementmaitrise/api/ais/authorize_decoupled.rb +67 -0
- data/lib/virementmaitrise/api/ais/connect.rb +66 -0
- data/lib/virementmaitrise/api/ais/delete_customer.rb +53 -0
- data/lib/virementmaitrise/api/ais/transactions.rb +62 -0
- data/lib/virementmaitrise/api/auth/authentication.rb +80 -0
- data/lib/virementmaitrise/api/pis/connect.rb +80 -0
- data/lib/virementmaitrise/api/pis/initiate.rb +54 -0
- data/lib/virementmaitrise/api/pis/payments.rb +55 -0
- data/lib/virementmaitrise/api/pis/refund.rb +67 -0
- data/lib/virementmaitrise/api/pis/request_to_pay.rb +61 -0
- data/lib/virementmaitrise/api/pis/settlements.rb +50 -0
- data/lib/virementmaitrise/api/ressources/applications.rb +57 -0
- data/lib/virementmaitrise/api/ressources/providers.rb +63 -0
- data/lib/virementmaitrise/api/ressources/test_accounts.rb +62 -0
- data/lib/virementmaitrise/base_url.rb +23 -0
- data/lib/virementmaitrise/endpoints/ais.rb +16 -0
- data/lib/virementmaitrise/endpoints/authentication.rb +13 -0
- data/lib/virementmaitrise/endpoints/pis.rb +16 -0
- data/lib/virementmaitrise/endpoints/ressources.rb +13 -0
- data/lib/virementmaitrise/exceptions.rb +62 -0
- data/lib/virementmaitrise/faraday/authentication/connection.rb +177 -0
- data/lib/virementmaitrise/pis_client.rb +118 -0
- data/lib/virementmaitrise/utils/constants.rb +11 -0
- data/lib/virementmaitrise/utils/crypto.rb +75 -0
- data/lib/virementmaitrise/utils/date.rb +15 -0
- data/lib/virementmaitrise/utils/json_parser.rb +37 -0
- data/lib/virementmaitrise/utils/query_builder.rb +18 -0
- data/lib/virementmaitrise/utils/validation.rb +32 -0
- data/lib/virementmaitrise/version.rb +5 -0
- data/lib/virementmaitrise.rb +66 -0
- data/virementmaitrise.gemspec +46 -0
- metadata +157 -0
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'virementmaitrise/api/ais/connect'
|
|
4
|
+
require 'virementmaitrise/api/ais/accounts'
|
|
5
|
+
require 'virementmaitrise/api/ais/transactions'
|
|
6
|
+
require 'virementmaitrise/api/ais/account_holders'
|
|
7
|
+
require 'virementmaitrise/api/ais/delete_customer'
|
|
8
|
+
require 'virementmaitrise/api/ais/authorize'
|
|
9
|
+
require 'virementmaitrise/api/ais/authorize_decoupled'
|
|
10
|
+
require 'virementmaitrise/utils/json_parser'
|
|
11
|
+
|
|
12
|
+
module VirementMaitrise
|
|
13
|
+
class AisClient
|
|
14
|
+
DEFAULT_ENVIRONMENT = 'sandbox'
|
|
15
|
+
ENVIRONMENTS = %w[test sandbox production].freeze
|
|
16
|
+
|
|
17
|
+
def initialize(config)
|
|
18
|
+
raise ArgumentError, "app_id is required" if config[:app_id].nil?
|
|
19
|
+
@app_id = config[:app_id]
|
|
20
|
+
raise ArgumentError, "app_secret is required" if config[:app_secret].nil?
|
|
21
|
+
@app_secret = config[:app_secret]
|
|
22
|
+
raise ArgumentError, "private_key is required" if config[:private_key].nil?
|
|
23
|
+
@private_key = config[:private_key]
|
|
24
|
+
|
|
25
|
+
env_value = (config[:environment] || DEFAULT_ENVIRONMENT).to_s.downcase
|
|
26
|
+
unless ENVIRONMENTS.include?(env_value)
|
|
27
|
+
raise ArgumentError, "#{env_value} is not a valid environment. Options are [#{ENVIRONMENTS.join(', ')}]"
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
@environment = env_value
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
# Getters
|
|
34
|
+
attr_reader :app_id, :app_secret, :private_key, :environment, :token, :token_expires_in, :refresh_token
|
|
35
|
+
|
|
36
|
+
private
|
|
37
|
+
|
|
38
|
+
def require_token!
|
|
39
|
+
raise VirementMaitrise::ValidationException, 'Token is required. Please call generate_token first.' if @token.nil?
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
public
|
|
43
|
+
|
|
44
|
+
# Methodes
|
|
45
|
+
def connect(state, redirect_uri, scope = nil)
|
|
46
|
+
res = VirementMaitrise::Ais::Connect.generate self, state, redirect_uri, scope
|
|
47
|
+
|
|
48
|
+
VirementMaitrise::Utils::JsonParser.safe_parse(res.body, context: 'connect')
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def generate_token(auth_code)
|
|
52
|
+
res = VirementMaitrise::Authentication.get_access_token self, auth_code
|
|
53
|
+
body = VirementMaitrise::Utils::JsonParser.safe_parse(res.body, context: 'access token')
|
|
54
|
+
@token = body['access_token']
|
|
55
|
+
@token_expires_in = body['expires_in']
|
|
56
|
+
@refresh_token = body['refresh_token']
|
|
57
|
+
|
|
58
|
+
body
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
def generate_refresh_token(refresh_token = nil)
|
|
62
|
+
res = VirementMaitrise::Authentication.refresh_token self, (refresh_token || @refresh_token)
|
|
63
|
+
body = VirementMaitrise::Utils::JsonParser.safe_parse(res.body, context: 'refresh token')
|
|
64
|
+
@token = body['access_token']
|
|
65
|
+
|
|
66
|
+
body
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
def accounts(customer_id:, account_id: nil, remove_nulls: nil, withBalances: nil)
|
|
70
|
+
require_token!
|
|
71
|
+
res = VirementMaitrise::Ais::Accounts.get self, customer_id, account_id, remove_nulls, withBalances
|
|
72
|
+
|
|
73
|
+
VirementMaitrise::Utils::JsonParser.safe_parse(res.body, context: 'accounts')
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
def transactions(customer_id:, account_id:, remove_nulls: nil, convert_dates: nil, filters: nil)
|
|
77
|
+
require_token!
|
|
78
|
+
res = VirementMaitrise::Ais::Transactions.get self, customer_id, account_id, remove_nulls, convert_dates, filters
|
|
79
|
+
|
|
80
|
+
VirementMaitrise::Utils::JsonParser.safe_parse(res.body, context: 'transactions')
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
def account_holders(customer_id:, remove_nulls: nil)
|
|
84
|
+
require_token!
|
|
85
|
+
res = VirementMaitrise::Ais::AccountHolders.get self, customer_id, remove_nulls
|
|
86
|
+
|
|
87
|
+
VirementMaitrise::Utils::JsonParser.safe_parse(res.body, context: 'account holders')
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
def delete_customer(customer_id:)
|
|
91
|
+
require_token!
|
|
92
|
+
res = VirementMaitrise::Ais::DeleteCustomer.delete self, customer_id
|
|
93
|
+
|
|
94
|
+
VirementMaitrise::Utils::JsonParser.safe_parse(res.body, context: 'delete customer')
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
def authorize(provider_id:, redirect_uri:, app_id_auth: false, state: nil, x_psu_id: nil, x_psu_ip_address: nil)
|
|
98
|
+
require_token!
|
|
99
|
+
res = VirementMaitrise::Ais::Authorize.get self, app_id_auth, provider_id, redirect_uri, state, x_psu_id,
|
|
100
|
+
x_psu_ip_address
|
|
101
|
+
|
|
102
|
+
VirementMaitrise::Utils::JsonParser.safe_parse(res.body, context: 'authorize')
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
def authorize_decoupled(provider_id:, polling_id:, app_id_auth: false)
|
|
106
|
+
require_token!
|
|
107
|
+
res = VirementMaitrise::Ais::AuthorizeDecoupled.get self, app_id_auth, provider_id, polling_id
|
|
108
|
+
|
|
109
|
+
VirementMaitrise::Utils::JsonParser.safe_parse(res.body, context: 'authorize decoupled')
|
|
110
|
+
end
|
|
111
|
+
end
|
|
112
|
+
end
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'base64'
|
|
4
|
+
require 'json'
|
|
5
|
+
require 'faraday'
|
|
6
|
+
require 'virementmaitrise/utils/validation'
|
|
7
|
+
require 'virementmaitrise/exceptions'
|
|
8
|
+
require 'virementmaitrise/utils/date'
|
|
9
|
+
require 'virementmaitrise/utils/constants'
|
|
10
|
+
require 'virementmaitrise/utils/query_builder'
|
|
11
|
+
|
|
12
|
+
module VirementMaitrise
|
|
13
|
+
module Ais
|
|
14
|
+
class AccountHolders
|
|
15
|
+
class << self
|
|
16
|
+
# ------------ PUBLIC METHOD ------------
|
|
17
|
+
def get(client, customer_id, remove_nulls)
|
|
18
|
+
@client = client
|
|
19
|
+
|
|
20
|
+
# Do the request
|
|
21
|
+
_request customer_id, remove_nulls
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
private
|
|
25
|
+
|
|
26
|
+
# ------------ REQUEST ------------
|
|
27
|
+
def _request(customer_id, remove_nulls)
|
|
28
|
+
# Get the url request
|
|
29
|
+
url = _endpoint customer_id
|
|
30
|
+
|
|
31
|
+
# Build uri params
|
|
32
|
+
params = {}
|
|
33
|
+
params['remove_nulls'] = remove_nulls if remove_nulls
|
|
34
|
+
|
|
35
|
+
query_string = VirementMaitrise::Utils::QueryBuilder.build_query_string(params)
|
|
36
|
+
|
|
37
|
+
# Do connect request
|
|
38
|
+
VirementMaitrise::Faraday::Authentication::Connection.get(
|
|
39
|
+
url: url + query_string,
|
|
40
|
+
client: @client,
|
|
41
|
+
custom_content_type: 'application/json',
|
|
42
|
+
bearer: "Bearer #{@client.token}",
|
|
43
|
+
secure_headers: true
|
|
44
|
+
)
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
# ------------ API ENDPOINT ------------
|
|
48
|
+
def _endpoint(customer_id)
|
|
49
|
+
"#{_api_base_url}/#{VirementMaitrise::Api::Endpoints::Ais::ACCOUNTHOLDERS}/#{customer_id}/accountholders"
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
# ------------ BASE URL ------------
|
|
53
|
+
def _api_base_url
|
|
54
|
+
VirementMaitrise::Api::BaseUrl::FINTECTURE_API_URL[@client.environment.to_sym]
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
end
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'base64'
|
|
4
|
+
require 'json'
|
|
5
|
+
require 'faraday'
|
|
6
|
+
require 'virementmaitrise/utils/validation'
|
|
7
|
+
require 'virementmaitrise/exceptions'
|
|
8
|
+
require 'virementmaitrise/utils/date'
|
|
9
|
+
require 'virementmaitrise/utils/constants'
|
|
10
|
+
require 'virementmaitrise/utils/query_builder'
|
|
11
|
+
|
|
12
|
+
module VirementMaitrise
|
|
13
|
+
module Ais
|
|
14
|
+
class Accounts
|
|
15
|
+
class << self
|
|
16
|
+
# ------------ PUBLIC METHOD ------------
|
|
17
|
+
def get(client, customer_id, account_id, remove_nulls, withBalances)
|
|
18
|
+
@client = client
|
|
19
|
+
|
|
20
|
+
# Do the request
|
|
21
|
+
_request customer_id, account_id, remove_nulls, withBalances
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
private
|
|
25
|
+
|
|
26
|
+
# ------------ REQUEST ------------
|
|
27
|
+
def _request(customer_id, account_id, remove_nulls, withBalances)
|
|
28
|
+
# Get the url request
|
|
29
|
+
url = _endpoint customer_id, account_id
|
|
30
|
+
|
|
31
|
+
# Build uri params
|
|
32
|
+
params = {}
|
|
33
|
+
params['remove_nulls'] = remove_nulls if remove_nulls
|
|
34
|
+
params['withBalances'] = withBalances if withBalances
|
|
35
|
+
|
|
36
|
+
query_string = VirementMaitrise::Utils::QueryBuilder.build_query_string(params)
|
|
37
|
+
|
|
38
|
+
# Do connect request
|
|
39
|
+
VirementMaitrise::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, account_id)
|
|
50
|
+
base = "#{_api_base_url}/#{VirementMaitrise::Api::Endpoints::Ais::ACCOUNTS}/#{customer_id}/accounts"
|
|
51
|
+
account_id ? "#{base}/#{account_id}" : base
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
# ------------ BASE URL ------------
|
|
55
|
+
def _api_base_url
|
|
56
|
+
VirementMaitrise::Api::BaseUrl::FINTECTURE_API_URL[@client.environment.to_sym]
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
end
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'base64'
|
|
4
|
+
require 'json'
|
|
5
|
+
require 'faraday'
|
|
6
|
+
require 'virementmaitrise/utils/validation'
|
|
7
|
+
require 'virementmaitrise/exceptions'
|
|
8
|
+
require 'virementmaitrise/utils/date'
|
|
9
|
+
require 'virementmaitrise/utils/constants'
|
|
10
|
+
require 'virementmaitrise/utils/query_builder'
|
|
11
|
+
|
|
12
|
+
module VirementMaitrise
|
|
13
|
+
module Ais
|
|
14
|
+
class Authorize
|
|
15
|
+
class << self
|
|
16
|
+
# ------------ PUBLIC METHOD ------------
|
|
17
|
+
def get(client, app_id_auth, provider_id, redirect_uri, state, x_psu_id, x_psu_ip_address)
|
|
18
|
+
@client = client
|
|
19
|
+
|
|
20
|
+
# Do the request
|
|
21
|
+
_request app_id_auth, provider_id, redirect_uri, state, x_psu_id, x_psu_ip_address
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
private
|
|
25
|
+
|
|
26
|
+
# ------------ REQUEST ------------
|
|
27
|
+
def _request(app_id_auth, provider_id, redirect_uri, state, x_psu_id, x_psu_ip_address)
|
|
28
|
+
# Get the url request
|
|
29
|
+
url = _endpoint provider_id
|
|
30
|
+
|
|
31
|
+
# Build uri params
|
|
32
|
+
params = {}
|
|
33
|
+
params['response_type'] = 'code' if app_id_auth
|
|
34
|
+
params['redirect_uri'] = redirect_uri if redirect_uri
|
|
35
|
+
params['state'] = state if state
|
|
36
|
+
params['model'] = 'redirect'
|
|
37
|
+
|
|
38
|
+
query_string = VirementMaitrise::Utils::QueryBuilder.build_query_string(params)
|
|
39
|
+
|
|
40
|
+
# Build additional headers
|
|
41
|
+
additional_headers = {}
|
|
42
|
+
additional_headers['app_id'] = @client.app_id if app_id_auth
|
|
43
|
+
additional_headers['x-psu-id'] = x_psu_id if x_psu_id
|
|
44
|
+
additional_headers['x-psu-ip-address'] = x_psu_ip_address if x_psu_ip_address
|
|
45
|
+
|
|
46
|
+
# Do connect request
|
|
47
|
+
VirementMaitrise::Faraday::Authentication::Connection.get(
|
|
48
|
+
url: url + query_string,
|
|
49
|
+
client: @client,
|
|
50
|
+
custom_content_type: 'application/json',
|
|
51
|
+
bearer: "Bearer #{@client.token}",
|
|
52
|
+
secure_headers: true,
|
|
53
|
+
additional_headers: additional_headers,
|
|
54
|
+
disableAuthorization: app_id_auth ? true : false
|
|
55
|
+
)
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
# ------------ API ENDPOINT ------------
|
|
59
|
+
def _endpoint(provider_id)
|
|
60
|
+
"#{_api_base_url}/#{VirementMaitrise::Api::Endpoints::Ais::AUTHORIZE}/#{provider_id}/authorize"
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
# ------------ BASE URL ------------
|
|
64
|
+
def _api_base_url
|
|
65
|
+
VirementMaitrise::Api::BaseUrl::FINTECTURE_API_URL[@client.environment.to_sym]
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
end
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'base64'
|
|
4
|
+
require 'json'
|
|
5
|
+
require 'faraday'
|
|
6
|
+
require 'virementmaitrise/utils/validation'
|
|
7
|
+
require 'virementmaitrise/exceptions'
|
|
8
|
+
require 'virementmaitrise/utils/date'
|
|
9
|
+
require 'virementmaitrise/utils/constants'
|
|
10
|
+
require 'virementmaitrise/utils/query_builder'
|
|
11
|
+
|
|
12
|
+
module VirementMaitrise
|
|
13
|
+
module Ais
|
|
14
|
+
class AuthorizeDecoupled
|
|
15
|
+
class << self
|
|
16
|
+
# ------------ PUBLIC METHOD ------------
|
|
17
|
+
def get(client, app_id_auth, provider_id, polling_id)
|
|
18
|
+
@client = client
|
|
19
|
+
|
|
20
|
+
# Do the request
|
|
21
|
+
_request app_id_auth, provider_id, polling_id
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
private
|
|
25
|
+
|
|
26
|
+
# ------------ REQUEST ------------
|
|
27
|
+
def _request(app_id_auth, provider_id, polling_id)
|
|
28
|
+
# Get the url request
|
|
29
|
+
url = _endpoint provider_id, polling_id
|
|
30
|
+
|
|
31
|
+
# Build uri params
|
|
32
|
+
params = {}
|
|
33
|
+
params['response_type'] = 'code' if app_id_auth
|
|
34
|
+
params['model'] = 'decoupled'
|
|
35
|
+
|
|
36
|
+
query_string = VirementMaitrise::Utils::QueryBuilder.build_query_string(params)
|
|
37
|
+
|
|
38
|
+
# Build additional headers
|
|
39
|
+
additional_headers = {}
|
|
40
|
+
additional_headers['app_id'] = @client.app_id if app_id_auth
|
|
41
|
+
|
|
42
|
+
# Do connect request
|
|
43
|
+
VirementMaitrise::Faraday::Authentication::Connection.get(
|
|
44
|
+
url: url + query_string,
|
|
45
|
+
client: @client,
|
|
46
|
+
custom_content_type: 'application/json',
|
|
47
|
+
bearer: "Bearer #{@client.token}",
|
|
48
|
+
secure_headers: true,
|
|
49
|
+
additional_headers: additional_headers,
|
|
50
|
+
disableAuthorization: app_id_auth ? true : false
|
|
51
|
+
)
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
# ------------ API ENDPOINT ------------
|
|
55
|
+
def _endpoint(provider_id, polling_id)
|
|
56
|
+
"#{_api_base_url}/#{VirementMaitrise::Api::Endpoints::Ais::AUTHORIZE}/#{provider_id}/authorize/decoupled/#{polling_id}"
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
# ------------ BASE URL ------------
|
|
60
|
+
def _api_base_url
|
|
61
|
+
VirementMaitrise::Api::BaseUrl::FINTECTURE_API_URL[@client.environment.to_sym]
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
end
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'base64'
|
|
4
|
+
require 'json'
|
|
5
|
+
require 'faraday'
|
|
6
|
+
require 'virementmaitrise/utils/validation'
|
|
7
|
+
require 'virementmaitrise/exceptions'
|
|
8
|
+
require 'virementmaitrise/utils/date'
|
|
9
|
+
require 'virementmaitrise/utils/constants'
|
|
10
|
+
require 'virementmaitrise/utils/query_builder'
|
|
11
|
+
|
|
12
|
+
module VirementMaitrise
|
|
13
|
+
module Ais
|
|
14
|
+
class Connect
|
|
15
|
+
class << self
|
|
16
|
+
# ------------ PUBLIC METHOD ------------
|
|
17
|
+
def generate(client, state, redirect_uri, scope)
|
|
18
|
+
@client = client
|
|
19
|
+
|
|
20
|
+
# Do the request
|
|
21
|
+
_request state, redirect_uri, scope
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
private
|
|
25
|
+
|
|
26
|
+
# ------------ REQUEST ------------
|
|
27
|
+
def _request(state, redirect_uri, scope)
|
|
28
|
+
# Get the url request
|
|
29
|
+
url = _endpoint
|
|
30
|
+
|
|
31
|
+
# Build uri params
|
|
32
|
+
params = {}
|
|
33
|
+
params['state'] = state
|
|
34
|
+
params['redirect_uri'] = redirect_uri
|
|
35
|
+
params['scope'] = scope if scope
|
|
36
|
+
|
|
37
|
+
query_string = VirementMaitrise::Utils::QueryBuilder.build_query_string(params)
|
|
38
|
+
|
|
39
|
+
# Build additional headers
|
|
40
|
+
additional_headers = {}
|
|
41
|
+
additional_headers['app_id'] = @client.app_id
|
|
42
|
+
|
|
43
|
+
# Do connect request
|
|
44
|
+
VirementMaitrise::Faraday::Authentication::Connection.get(
|
|
45
|
+
url: url + query_string,
|
|
46
|
+
client: @client,
|
|
47
|
+
custom_content_type: 'application/json',
|
|
48
|
+
secure_headers: true,
|
|
49
|
+
additional_headers: additional_headers
|
|
50
|
+
)
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
# ------------ API ENDPOINT ------------
|
|
54
|
+
def _endpoint
|
|
55
|
+
"#{_api_base_url}/#{VirementMaitrise::Api::Endpoints::Ais::CONNECT}"
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
# ------------ BASE URL ------------
|
|
59
|
+
def _api_base_url
|
|
60
|
+
VirementMaitrise::Api::BaseUrl::FINTECTURE_API_URL[@client.environment.to_sym]
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
end
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'base64'
|
|
4
|
+
require 'json'
|
|
5
|
+
require 'faraday'
|
|
6
|
+
require 'virementmaitrise/utils/validation'
|
|
7
|
+
require 'virementmaitrise/exceptions'
|
|
8
|
+
require 'virementmaitrise/utils/date'
|
|
9
|
+
require 'virementmaitrise/utils/constants'
|
|
10
|
+
|
|
11
|
+
module VirementMaitrise
|
|
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
|
+
VirementMaitrise::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}/#{VirementMaitrise::Api::Endpoints::Ais::CUSTOMER}/#{customer_id}"
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
# ------------ BASE URL ------------
|
|
46
|
+
def _api_base_url
|
|
47
|
+
VirementMaitrise::Api::BaseUrl::FINTECTURE_API_URL[@client.environment.to_sym]
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
end
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'base64'
|
|
4
|
+
require 'json'
|
|
5
|
+
require 'faraday'
|
|
6
|
+
require 'virementmaitrise/utils/validation'
|
|
7
|
+
require 'virementmaitrise/exceptions'
|
|
8
|
+
require 'virementmaitrise/utils/date'
|
|
9
|
+
require 'virementmaitrise/utils/constants'
|
|
10
|
+
require 'virementmaitrise/utils/query_builder'
|
|
11
|
+
|
|
12
|
+
module VirementMaitrise
|
|
13
|
+
module Ais
|
|
14
|
+
class Transactions
|
|
15
|
+
class << self
|
|
16
|
+
# ------------ PUBLIC METHOD ------------
|
|
17
|
+
def get(client, customer_id, account_id, remove_nulls, convert_dates, filters)
|
|
18
|
+
@client = client
|
|
19
|
+
|
|
20
|
+
# Do the request
|
|
21
|
+
_request customer_id, account_id, remove_nulls, convert_dates, filters
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
private
|
|
25
|
+
|
|
26
|
+
# ------------ REQUEST ------------
|
|
27
|
+
def _request(customer_id, account_id, remove_nulls, convert_dates, filters)
|
|
28
|
+
# Get the url request
|
|
29
|
+
url = _endpoint customer_id, account_id
|
|
30
|
+
|
|
31
|
+
# Build uri params
|
|
32
|
+
params = {}
|
|
33
|
+
params['remove_nulls'] = remove_nulls if remove_nulls
|
|
34
|
+
params['convert_dates'] = convert_dates if convert_dates
|
|
35
|
+
filters.each { |key, value| params[key] = value } if filters
|
|
36
|
+
|
|
37
|
+
query_string = VirementMaitrise::Utils::QueryBuilder.build_query_string(params)
|
|
38
|
+
|
|
39
|
+
# Do connect request
|
|
40
|
+
VirementMaitrise::Faraday::Authentication::Connection.get(
|
|
41
|
+
url: url + query_string,
|
|
42
|
+
client: @client,
|
|
43
|
+
custom_content_type: 'application/json',
|
|
44
|
+
bearer: "Bearer #{@client.token}",
|
|
45
|
+
secure_headers: true
|
|
46
|
+
)
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
# ------------ API ENDPOINT ------------
|
|
50
|
+
def _endpoint(customer_id, account_id)
|
|
51
|
+
"#{_api_base_url}/#{VirementMaitrise::Api::Endpoints::Ais::TRANSACTIONS}/#{customer_id}/accounts/#{account_id}/transactions"
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
# ------------ BASE URL ------------
|
|
55
|
+
def _api_base_url
|
|
56
|
+
VirementMaitrise::Api::BaseUrl::FINTECTURE_API_URL[@client.environment.to_sym]
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
end
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'json'
|
|
4
|
+
require 'faraday'
|
|
5
|
+
require 'virementmaitrise/utils/query_builder'
|
|
6
|
+
|
|
7
|
+
module VirementMaitrise
|
|
8
|
+
class Authentication
|
|
9
|
+
class << self
|
|
10
|
+
def authorize(redirect_uri, state = nil)
|
|
11
|
+
params = {
|
|
12
|
+
response_type: 'code',
|
|
13
|
+
app_id: VirementMaitrise.app_id,
|
|
14
|
+
redirect_uri: redirect_uri,
|
|
15
|
+
state: state
|
|
16
|
+
}
|
|
17
|
+
query_string = VirementMaitrise::Utils::QueryBuilder.build_query_string(params)
|
|
18
|
+
|
|
19
|
+
::Faraday.get "#{token_authorize_endpoint}#{query_string}"
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def get_access_token(client, auth_code = nil)
|
|
23
|
+
@client = client
|
|
24
|
+
body = access_token_data auth_code
|
|
25
|
+
|
|
26
|
+
VirementMaitrise::Faraday::Authentication::Connection.post url: access_token_url, req_body: body, client: client
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def refresh_token(client, refresh_token)
|
|
30
|
+
@client = client
|
|
31
|
+
body = refresh_token_data refresh_token
|
|
32
|
+
|
|
33
|
+
VirementMaitrise::Faraday::Authentication::Connection.post url: refresh_token_url, req_body: body, client: client
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
private
|
|
37
|
+
|
|
38
|
+
def base_url
|
|
39
|
+
VirementMaitrise::Api::BaseUrl::FINTECTURE_OAUTH_URL[@client.environment.to_sym]
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def token_authorize_endpoint
|
|
43
|
+
"#{base_url}#{VirementMaitrise::Api::Endpoints::Authentication::OAUTH_TOKEN_AUTHORIZE}"
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def access_token_url
|
|
47
|
+
"#{base_url}#{VirementMaitrise::Api::Endpoints::Authentication::OAUTH_ACCESS_TOKEN}"
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def refresh_token_url
|
|
51
|
+
"#{base_url}#{VirementMaitrise::Api::Endpoints::Authentication::OAUTH_REFRESH_TOKEN}"
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def access_token_data(auth_code)
|
|
55
|
+
data = {
|
|
56
|
+
scope: 'PIS',
|
|
57
|
+
app_id: @client.app_id,
|
|
58
|
+
grant_type: 'client_credentials'
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
if auth_code
|
|
62
|
+
data = {
|
|
63
|
+
scope: 'AIS',
|
|
64
|
+
code: auth_code,
|
|
65
|
+
grant_type: 'authorization_code'
|
|
66
|
+
}
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
data
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
def refresh_token_data(refresh_token)
|
|
73
|
+
{
|
|
74
|
+
grant_type: 'refresh_token',
|
|
75
|
+
refresh_token: refresh_token
|
|
76
|
+
}
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
end
|