fintecture 0.5.1 → 0.6.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.
- checksums.yaml +4 -4
- data/.gitignore +18 -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 +405 -408
- 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 +84 -77
- data/lib/fintecture/api/pis/initiate.rb +52 -52
- data/lib/fintecture/api/pis/payments.rb +54 -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 +48 -48
- 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 +12 -6
@@ -1,77 +1,84 @@
|
|
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
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
payload
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
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, **options)
|
17
|
+
|
18
|
+
@client = client
|
19
|
+
|
20
|
+
# Build the request payload
|
21
|
+
payload = _build_payload(payload)
|
22
|
+
|
23
|
+
# Do the request
|
24
|
+
_request payload, state, redirect_uri, origin_uri, options
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
# ------------ REQUEST ------------
|
30
|
+
def _request(payload, state, redirect_uri, origin_uri, options)
|
31
|
+
defaults = {
|
32
|
+
:with_virtualbeneficiary => false
|
33
|
+
}
|
34
|
+
options = defaults.merge(options)
|
35
|
+
|
36
|
+
# Get the url request
|
37
|
+
url = _endpoint
|
38
|
+
|
39
|
+
# Build uri params
|
40
|
+
params = {}
|
41
|
+
params['redirect_uri'] = redirect_uri if redirect_uri
|
42
|
+
params['origin_uri'] = origin_uri if origin_uri
|
43
|
+
params['with_virtualbeneficiary'] = 'true' if options[:with_virtualbeneficiary]
|
44
|
+
params['state'] = state
|
45
|
+
|
46
|
+
query_string = "?#{params.map { |key, value| "#{key}=#{value}" }.join('&')}"
|
47
|
+
|
48
|
+
# Do connect request
|
49
|
+
Fintecture::Faraday::Authentication::Connection.post(
|
50
|
+
url: url + query_string,
|
51
|
+
req_body: payload.to_json,
|
52
|
+
client: @client,
|
53
|
+
custom_content_type: 'application/json',
|
54
|
+
bearer: "Bearer #{@client.token}",
|
55
|
+
secure_headers: true
|
56
|
+
)
|
57
|
+
end
|
58
|
+
|
59
|
+
# ------------ BUILD PAYLOAD ------------
|
60
|
+
def _build_payload(payload)
|
61
|
+
payload[:data][:attributes][:amount] = payload[:data][:attributes][:amount].to_s
|
62
|
+
|
63
|
+
unless payload[:data][:attributes][:end_to_end_id]
|
64
|
+
payload[:data][:attributes][:end_to_end_id] =
|
65
|
+
Fintecture::Utils::Crypto.generate_uuid_only_chars
|
66
|
+
end
|
67
|
+
|
68
|
+
payload
|
69
|
+
end
|
70
|
+
|
71
|
+
# ------------ API ENDPOINT ------------
|
72
|
+
def _endpoint
|
73
|
+
"#{_api_base_url}/#{Fintecture::Api::Endpoints::Pis::CONNECT}"
|
74
|
+
end
|
75
|
+
|
76
|
+
# ------------ BASE URL ------------
|
77
|
+
def _api_base_url
|
78
|
+
Fintecture::Api::BaseUrl::FINTECTURE_API_URL[@client.environment.to_sym]
|
79
|
+
end
|
80
|
+
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
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,54 @@
|
|
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
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
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, options = {})
|
14
|
+
@client = client
|
15
|
+
|
16
|
+
# Do the get_payments request
|
17
|
+
_request session_id, options
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
# ------------ REQUEST ------------
|
23
|
+
def _request(session_id, options)
|
24
|
+
url = _endpoint
|
25
|
+
|
26
|
+
# Build uri params
|
27
|
+
params = {}
|
28
|
+
params['with_virtualbeneficiary'] = 'true' if options[:with_virtualbeneficiary]
|
29
|
+
|
30
|
+
query_string = "?#{params.map { |key, value| "#{key}=#{value}" }.join('&')}"
|
31
|
+
|
32
|
+
Fintecture::Faraday::Authentication::Connection.get(
|
33
|
+
url: "#{url}/#{session_id}" + query_string,
|
34
|
+
client: @client,
|
35
|
+
custom_content_type: 'application/json',
|
36
|
+
bearer: "Bearer #{@client.token}",
|
37
|
+
secure_headers: true
|
38
|
+
)
|
39
|
+
end
|
40
|
+
|
41
|
+
# ------------ API ENDPOINT ------------
|
42
|
+
def _endpoint
|
43
|
+
"#{_api_base_url}/#{Fintecture::Api::Endpoints::Pis::PAYMENTS}"
|
44
|
+
end
|
45
|
+
|
46
|
+
# ------------ BASE URL ------------
|
47
|
+
def _api_base_url
|
48
|
+
Fintecture::Api::BaseUrl::FINTECTURE_API_URL[@client.environment.to_sym]
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
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, user_id)
|
13
|
-
@client = client
|
14
|
-
|
15
|
-
# Build the request payload
|
16
|
-
payload = _build_payload session_id, amount, user_id
|
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, user_id)
|
41
|
-
# Return the payload
|
42
|
-
{
|
43
|
-
meta: {
|
44
|
-
session_id: session_id,
|
45
|
-
user_id: user_id
|
46
|
-
},
|
47
|
-
data: {
|
48
|
-
attributes: {
|
49
|
-
amount: amount.to_s
|
50
|
-
}
|
51
|
-
}
|
52
|
-
}
|
53
|
-
end
|
54
|
-
|
55
|
-
# ------------ API ENDPOINT ------------
|
56
|
-
def _endpoint
|
57
|
-
"#{_api_base_url}/#{Fintecture::Api::Endpoints::Pis::REFUND}"
|
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
|
-
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, user_id)
|
13
|
+
@client = client
|
14
|
+
|
15
|
+
# Build the request payload
|
16
|
+
payload = _build_payload session_id, amount, user_id
|
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, user_id)
|
41
|
+
# Return the payload
|
42
|
+
{
|
43
|
+
meta: {
|
44
|
+
session_id: session_id,
|
45
|
+
user_id: user_id
|
46
|
+
},
|
47
|
+
data: {
|
48
|
+
attributes: {
|
49
|
+
amount: amount.to_s
|
50
|
+
}
|
51
|
+
}
|
52
|
+
}
|
53
|
+
end
|
54
|
+
|
55
|
+
# ------------ API ENDPOINT ------------
|
56
|
+
def _endpoint
|
57
|
+
"#{_api_base_url}/#{Fintecture::Api::Endpoints::Pis::REFUND}"
|
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
|
+
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
|