fintecture 0.4.0 → 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +17 -17
- data/.rspec +3 -3
- data/.travis.yml +7 -7
- data/CODE_OF_CONDUCT.md +74 -74
- data/Gemfile +8 -8
- data/Gemfile.lock +59 -59
- data/LICENSE.txt +674 -674
- data/README.md +407 -407
- data/Rakefile +8 -8
- data/bin/console +15 -15
- data/bin/setup +8 -8
- data/exemples/ais.rb +53 -53
- data/exemples/config_ais.json +7 -7
- data/exemples/config_pis.json +5 -5
- data/exemples/pis.rb +148 -148
- data/exemples/ressources.rb +23 -23
- data/fintecture.gemspec +44 -44
- data/lib/fintecture/ais_client.rb +94 -94
- data/lib/fintecture/api/ais/account_holders.rb +61 -61
- data/lib/fintecture/api/ais/accounts.rb +63 -63
- data/lib/fintecture/api/ais/authorize.rb +72 -72
- data/lib/fintecture/api/ais/authorize_decoupled.rb +68 -68
- data/lib/fintecture/api/ais/connect.rb +65 -65
- data/lib/fintecture/api/ais/delete_customer.rb +53 -53
- data/lib/fintecture/api/ais/transactions.rb +64 -64
- data/lib/fintecture/api/auth/authentication.rb +78 -78
- data/lib/fintecture/api/pis/connect.rb +77 -77
- data/lib/fintecture/api/pis/initiate.rb +52 -52
- data/lib/fintecture/api/pis/payments.rb +48 -48
- data/lib/fintecture/api/pis/refund.rb +67 -67
- data/lib/fintecture/api/pis/request_to_pay.rb +63 -63
- data/lib/fintecture/api/pis/settlements.rb +50 -50
- data/lib/fintecture/api/ressources/applications.rb +57 -57
- data/lib/fintecture/api/ressources/providers.rb +61 -61
- data/lib/fintecture/api/ressources/test_accounts.rb +60 -60
- data/lib/fintecture/base_url.rb +26 -26
- data/lib/fintecture/endpoints/ais.rb +17 -17
- data/lib/fintecture/endpoints/authentication.rb +13 -13
- data/lib/fintecture/endpoints/pis.rb +16 -16
- data/lib/fintecture/endpoints/ressources.rb +13 -13
- data/lib/fintecture/exceptions.rb +75 -72
- data/lib/fintecture/faraday/authentication/connection.rb +140 -140
- data/lib/fintecture/pis_client.rb +100 -100
- data/lib/fintecture/utils/constants.rb +11 -11
- data/lib/fintecture/utils/crypto.rb +75 -75
- data/lib/fintecture/utils/date.rb +15 -15
- data/lib/fintecture/utils/validation.rb +32 -32
- data/lib/fintecture/version.rb +5 -5
- data/lib/fintecture.rb +65 -65
- metadata +8 -8
@@ -1,77 +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
|
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
|
@@ -1,52 +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
|
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
|
@@ -1,48 +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
|
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
|
@@ -1,67 +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
|
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
|
@@ -1,63 +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
|
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
|