fintecture 0.2.1 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -3
- data/Gemfile +4 -2
- data/Gemfile.lock +1 -1
- data/README.md +328 -162
- data/Rakefile +5 -3
- data/bin/console +4 -3
- data/exemples/ais.rb +53 -0
- data/exemples/config_ais.json +8 -0
- data/exemples/config_pis.json +6 -0
- data/exemples/pis.rb +148 -0
- data/exemples/ressources.rb +23 -0
- data/fintecture.gemspec +16 -15
- data/lib/fintecture/ais_client.rb +94 -0
- data/lib/fintecture/api/ais/account_holders.rb +61 -0
- data/lib/fintecture/api/ais/accounts.rb +63 -0
- data/lib/fintecture/api/ais/authorize.rb +72 -0
- data/lib/fintecture/api/ais/authorize_decoupled.rb +68 -0
- data/lib/fintecture/api/ais/connect.rb +65 -0
- data/lib/fintecture/api/ais/delete_customer.rb +53 -0
- data/lib/fintecture/api/ais/transactions.rb +64 -0
- data/lib/fintecture/{authentication.rb → api/auth/authentication.rb} +25 -23
- data/lib/fintecture/api/pis/connect.rb +77 -0
- data/lib/fintecture/api/pis/initiate.rb +52 -0
- data/lib/fintecture/api/pis/payments.rb +48 -0
- data/lib/fintecture/api/pis/refund.rb +67 -0
- data/lib/fintecture/api/pis/request_to_pay.rb +63 -0
- data/lib/fintecture/api/pis/settlements.rb +48 -0
- data/lib/fintecture/api/ressources/applications.rb +57 -0
- data/lib/fintecture/api/ressources/providers.rb +61 -0
- data/lib/fintecture/api/ressources/test_accounts.rb +60 -0
- data/lib/fintecture/base_url.rb +26 -0
- data/lib/fintecture/endpoints/ais.rb +17 -0
- data/lib/fintecture/{api/endpoints → endpoints}/authentication.rb +3 -3
- data/lib/fintecture/endpoints/pis.rb +16 -0
- data/lib/fintecture/endpoints/ressources.rb +13 -0
- data/lib/fintecture/exceptions.rb +52 -13
- data/lib/fintecture/faraday/authentication/connection.rb +60 -40
- data/lib/fintecture/pis_client.rb +100 -0
- data/lib/fintecture/utils/constants.rb +5 -8
- data/lib/fintecture/utils/crypto.rb +15 -18
- data/lib/fintecture/utils/date.rb +4 -4
- data/lib/fintecture/utils/validation.rb +12 -6
- data/lib/fintecture/version.rb +3 -1
- data/lib/fintecture.rb +21 -38
- metadata +31 -8
- data/lib/fintecture/api/base_url.rb +0 -29
- data/lib/fintecture/api/endpoints/pis.rb +0 -14
- data/lib/fintecture/connect.rb +0 -38
- data/lib/fintecture/pis.rb +0 -262
@@ -1,26 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'fintecture/exceptions'
|
2
4
|
|
3
5
|
module Fintecture
|
4
6
|
module Utils
|
5
7
|
class Validation
|
6
8
|
class << self
|
7
|
-
|
8
9
|
def raise_if_klass_mismatch(target, klass, param_name = nil)
|
9
10
|
return if target.is_a? klass
|
10
11
|
|
11
|
-
raise Fintecture::ValidationException
|
12
|
+
raise Fintecture::ValidationException,
|
13
|
+
"invalid #{param_name || 'parameter'} format, the parameter should be a #{klass} instead a #{target.class.name}"
|
12
14
|
end
|
13
15
|
|
14
16
|
def raise_if_invalid_date_format(date)
|
15
17
|
return unless date
|
18
|
+
|
16
19
|
valid_format = date.match(/\d{4}-\d{2}-\d{2}/)
|
17
|
-
valid_date =
|
20
|
+
valid_date = begin
|
21
|
+
::Date.strptime(date, '%Y-%m-%d')
|
22
|
+
rescue StandardError
|
23
|
+
false
|
24
|
+
end
|
18
25
|
return if valid_format && valid_date
|
19
26
|
|
20
|
-
raise Fintecture::ValidationException
|
27
|
+
raise Fintecture::ValidationException, "invalidss #{date} date, the format should be YYYY-MM-DD"
|
21
28
|
end
|
22
|
-
|
23
29
|
end
|
24
30
|
end
|
25
31
|
end
|
26
|
-
end
|
32
|
+
end
|
data/lib/fintecture/version.rb
CHANGED
data/lib/fintecture.rb
CHANGED
@@ -1,8 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'logger'
|
2
4
|
require 'uri'
|
3
5
|
require 'faraday'
|
4
6
|
|
5
|
-
#ToRemove
|
7
|
+
# ToRemove
|
6
8
|
require 'openssl'
|
7
9
|
require 'cgi'
|
8
10
|
|
@@ -10,73 +12,54 @@ require 'cgi'
|
|
10
12
|
require 'fintecture/version'
|
11
13
|
|
12
14
|
# Modules
|
13
|
-
require 'fintecture/
|
14
|
-
|
15
|
+
require 'fintecture/api/auth/authentication'
|
16
|
+
|
17
|
+
# Clients
|
18
|
+
require 'fintecture/pis_client'
|
19
|
+
require 'fintecture/ais_client'
|
15
20
|
|
16
21
|
# Utilities
|
17
22
|
require 'fintecture/utils/crypto'
|
18
23
|
|
19
24
|
# Endpoints
|
20
|
-
require 'fintecture/
|
21
|
-
require 'fintecture/
|
25
|
+
require 'fintecture/base_url'
|
26
|
+
require 'fintecture/endpoints/authentication'
|
27
|
+
require 'fintecture/endpoints/ais'
|
28
|
+
require 'fintecture/endpoints/pis'
|
29
|
+
require 'fintecture/endpoints/ressources'
|
22
30
|
|
23
31
|
# Connections
|
24
32
|
require 'fintecture/faraday/authentication/connection'
|
25
33
|
|
26
|
-
|
27
34
|
module Fintecture
|
28
35
|
@log_level = nil
|
29
36
|
@logger = nil
|
30
|
-
@environment = 'sandbox'
|
31
|
-
|
32
|
-
ENVIRONMENTS = %w[local test sandbox production].freeze
|
33
37
|
|
34
38
|
class << self
|
35
|
-
attr_accessor :
|
36
|
-
|
37
|
-
def environment=(environment)
|
38
|
-
environment = environment.downcase
|
39
|
-
|
40
|
-
raise "#{environment} not a valid environment, options are [#{ENVIRONMENTS.join(', ')}]" unless ENVIRONMENTS.include?(environment)
|
41
|
-
|
42
|
-
@environment = environment
|
43
|
-
end
|
44
|
-
|
45
|
-
def environment
|
46
|
-
@environment
|
47
|
-
end
|
39
|
+
attr_accessor :logger
|
40
|
+
attr_reader :log_level
|
48
41
|
|
49
42
|
# Logging
|
50
43
|
LEVEL_DEBUG = Logger::DEBUG
|
51
44
|
LEVEL_ERROR = Logger::ERROR
|
52
45
|
LEVEL_INFO = Logger::INFO
|
53
46
|
|
54
|
-
def log_level
|
55
|
-
@log_level
|
56
|
-
end
|
57
|
-
|
58
47
|
def log_level=(val)
|
59
|
-
|
48
|
+
case val
|
49
|
+
when 'debug'
|
60
50
|
val = LEVEL_DEBUG
|
61
|
-
|
51
|
+
when 'info'
|
62
52
|
val = LEVEL_INFO
|
63
53
|
end
|
64
54
|
|
65
55
|
if !val.nil? && ![LEVEL_DEBUG, LEVEL_ERROR, LEVEL_INFO].include?(val)
|
66
56
|
raise ArgumentError, 'log_level should only be set to `nil`, `debug` or `info`'
|
67
57
|
end
|
68
|
-
@log_level = val
|
69
|
-
end
|
70
58
|
|
71
|
-
|
72
|
-
@logger
|
73
|
-
end
|
74
|
-
|
75
|
-
def logger=(val)
|
76
|
-
@logger = val
|
59
|
+
@log_level = val
|
77
60
|
end
|
78
|
-
|
79
61
|
end
|
80
62
|
end
|
81
63
|
|
82
|
-
Fintecture.log_level = ENV[
|
64
|
+
Fintecture.log_level = ENV['FINTECTURE_LOG'] unless ENV['FINTECTURE_LOG'].nil?
|
65
|
+
# TODO: Mettre a jour la gem sur le site de package
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fintecture
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Fintecture
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-10-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -84,16 +84,39 @@ files:
|
|
84
84
|
- Rakefile
|
85
85
|
- bin/console
|
86
86
|
- bin/setup
|
87
|
+
- exemples/ais.rb
|
88
|
+
- exemples/config_ais.json
|
89
|
+
- exemples/config_pis.json
|
90
|
+
- exemples/pis.rb
|
91
|
+
- exemples/ressources.rb
|
87
92
|
- fintecture.gemspec
|
88
93
|
- lib/fintecture.rb
|
89
|
-
- lib/fintecture/
|
90
|
-
- lib/fintecture/api/
|
91
|
-
- lib/fintecture/api/
|
92
|
-
- lib/fintecture/
|
93
|
-
- lib/fintecture/
|
94
|
+
- lib/fintecture/ais_client.rb
|
95
|
+
- lib/fintecture/api/ais/account_holders.rb
|
96
|
+
- lib/fintecture/api/ais/accounts.rb
|
97
|
+
- lib/fintecture/api/ais/authorize.rb
|
98
|
+
- lib/fintecture/api/ais/authorize_decoupled.rb
|
99
|
+
- lib/fintecture/api/ais/connect.rb
|
100
|
+
- lib/fintecture/api/ais/delete_customer.rb
|
101
|
+
- lib/fintecture/api/ais/transactions.rb
|
102
|
+
- lib/fintecture/api/auth/authentication.rb
|
103
|
+
- lib/fintecture/api/pis/connect.rb
|
104
|
+
- lib/fintecture/api/pis/initiate.rb
|
105
|
+
- lib/fintecture/api/pis/payments.rb
|
106
|
+
- lib/fintecture/api/pis/refund.rb
|
107
|
+
- lib/fintecture/api/pis/request_to_pay.rb
|
108
|
+
- lib/fintecture/api/pis/settlements.rb
|
109
|
+
- lib/fintecture/api/ressources/applications.rb
|
110
|
+
- lib/fintecture/api/ressources/providers.rb
|
111
|
+
- lib/fintecture/api/ressources/test_accounts.rb
|
112
|
+
- lib/fintecture/base_url.rb
|
113
|
+
- lib/fintecture/endpoints/ais.rb
|
114
|
+
- lib/fintecture/endpoints/authentication.rb
|
115
|
+
- lib/fintecture/endpoints/pis.rb
|
116
|
+
- lib/fintecture/endpoints/ressources.rb
|
94
117
|
- lib/fintecture/exceptions.rb
|
95
118
|
- lib/fintecture/faraday/authentication/connection.rb
|
96
|
-
- lib/fintecture/
|
119
|
+
- lib/fintecture/pis_client.rb
|
97
120
|
- lib/fintecture/utils/constants.rb
|
98
121
|
- lib/fintecture/utils/crypto.rb
|
99
122
|
- lib/fintecture/utils/date.rb
|
@@ -1,29 +0,0 @@
|
|
1
|
-
module Fintecture
|
2
|
-
module Api
|
3
|
-
module BaseUrl
|
4
|
-
|
5
|
-
FINTECTURE_OAUTH_URL = {
|
6
|
-
local: 'http://localhost:3030/oauth',
|
7
|
-
test: 'https://oauth-sandbox-test.fintecture.com/oauth',
|
8
|
-
sandbox: 'https://api-sandbox.fintecture.com/oauth',
|
9
|
-
production: 'https://api.fintecture.com/oauth'
|
10
|
-
}
|
11
|
-
|
12
|
-
FINTECTURE_API_URL = {
|
13
|
-
local: 'http://localhost:3030',
|
14
|
-
test: 'https://api-sandbox-test.fintecture.com',
|
15
|
-
sandbox: 'https://api-sandbox.fintecture.com',
|
16
|
-
production: 'https://api.fintecture.com'
|
17
|
-
}
|
18
|
-
|
19
|
-
FINTECTURE_CONNECT_URL = {
|
20
|
-
local: 'http://localhost:4201',
|
21
|
-
test: 'https://connect-test.fintecture.com',
|
22
|
-
sandbox: 'https://connect-sandbox.fintecture.com',
|
23
|
-
production: 'https://connect.fintecture.com'
|
24
|
-
}
|
25
|
-
|
26
|
-
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
@@ -1,14 +0,0 @@
|
|
1
|
-
module Fintecture
|
2
|
-
module Api
|
3
|
-
module Endpoints
|
4
|
-
module Pis
|
5
|
-
PIS = 'pis/v2'
|
6
|
-
PISPROVIDER = "#{PIS}/provider"
|
7
|
-
PISCUSTOMER = "#{PIS}/customer"
|
8
|
-
REQUEST_TO_PAY = "#{PIS}/request-to-pay"
|
9
|
-
PAYMENTS = "#{PIS}/payments"
|
10
|
-
CONNECT = "#{PIS}/connect"
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
data/lib/fintecture/connect.rb
DELETED
@@ -1,38 +0,0 @@
|
|
1
|
-
require 'base64'
|
2
|
-
require 'json'
|
3
|
-
require 'faraday'
|
4
|
-
require 'fintecture/pis'
|
5
|
-
require 'fintecture/utils/validation'
|
6
|
-
require 'fintecture/exceptions'
|
7
|
-
require 'fintecture/utils/date'
|
8
|
-
require 'fintecture/utils/constants'
|
9
|
-
|
10
|
-
module Fintecture
|
11
|
-
class Connect
|
12
|
-
class << self
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
# Build the base of url
|
17
|
-
def api_base_url
|
18
|
-
Fintecture::Api::BaseUrl::FINTECTURE_API_URL[Fintecture.environment.to_sym]
|
19
|
-
end
|
20
|
-
|
21
|
-
|
22
|
-
private
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
def as_json(element)
|
28
|
-
return JSON(element.to_json) if element.is_a? Hash
|
29
|
-
|
30
|
-
begin
|
31
|
-
element.as_json
|
32
|
-
rescue NoMethodError
|
33
|
-
raise Fintecture::ValidationException.new("invalid parameter format, the parameter should be a Hash or an Object Model instead a #{element.class.name}")
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
data/lib/fintecture/pis.rb
DELETED
@@ -1,262 +0,0 @@
|
|
1
|
-
require 'json'
|
2
|
-
require 'faraday'
|
3
|
-
require 'fintecture/api/endpoints/pis'
|
4
|
-
require 'fintecture/api/base_url'
|
5
|
-
|
6
|
-
module Fintecture
|
7
|
-
class Pis
|
8
|
-
class << self
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
# ------------ PUBLIC METHODS ------------
|
14
|
-
# Connect
|
15
|
-
def get_connect(access_token = nil, payment_attrs = nil)
|
16
|
-
# Build the request payload
|
17
|
-
payload = build_payload_connect(as_json payment_attrs)
|
18
|
-
# Do the _get_connect_request request
|
19
|
-
_get_connect_request access_token, payload, payment_attrs
|
20
|
-
end
|
21
|
-
|
22
|
-
# Request_to_pay
|
23
|
-
def request_to_pay(access_token = nil, payment_attrs = nil)
|
24
|
-
# Build the request payload
|
25
|
-
payload = build_payload_request_to_pay(as_json payment_attrs)
|
26
|
-
# Do the _request_to_pay_request request
|
27
|
-
_request_to_pay_request access_token, payload, payment_attrs
|
28
|
-
end
|
29
|
-
|
30
|
-
# Get_payments
|
31
|
-
def get_payments(access_token = nil, session_id = nil)
|
32
|
-
# Do the get_payments request
|
33
|
-
_get_payments_request access_token, session_id
|
34
|
-
end
|
35
|
-
|
36
|
-
# Get_access_token
|
37
|
-
def get_access_token
|
38
|
-
# Do the get_access_token request
|
39
|
-
response = Fintecture::Authentication.get_access_token
|
40
|
-
JSON.parse response.body
|
41
|
-
end
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
private
|
47
|
-
# ------------ REQUESTS ------------
|
48
|
-
# Connect
|
49
|
-
def _get_connect_request(access_token, payload, payment_attrs)
|
50
|
-
|
51
|
-
# Get the url request
|
52
|
-
url = connect_endpoint
|
53
|
-
|
54
|
-
# Build uri params
|
55
|
-
params = {}
|
56
|
-
params['state'] = payment_attrs['state']
|
57
|
-
params['redirect_uri'] = payment_attrs['redirect_uri'] if payment_attrs['redirect_uri']
|
58
|
-
query_string = "?#{params.map{|key, value| "#{key}=#{value}"}.join('&')}"
|
59
|
-
|
60
|
-
# Do connect request
|
61
|
-
Fintecture::Faraday::Authentication::Connection.post(
|
62
|
-
url: url + query_string,
|
63
|
-
req_body: payload.to_json,
|
64
|
-
custom_content_type: 'application/json',
|
65
|
-
bearer: "Bearer #{access_token}",
|
66
|
-
secure_headers: true
|
67
|
-
)
|
68
|
-
end
|
69
|
-
|
70
|
-
# Request_to_pay
|
71
|
-
def _request_to_pay_request(access_token, payload, payment_attrs)
|
72
|
-
|
73
|
-
# Get the url request
|
74
|
-
url = request_to_pay_endpoint
|
75
|
-
|
76
|
-
additional_headers = {}
|
77
|
-
additional_headers['x-language'] = payment_attrs[:x_language]
|
78
|
-
|
79
|
-
# Do connect request
|
80
|
-
Fintecture::Faraday::Authentication::Connection.post(
|
81
|
-
url: url,
|
82
|
-
req_body: payload.to_json,
|
83
|
-
custom_content_type: 'application/json',
|
84
|
-
bearer: "Bearer #{access_token}",
|
85
|
-
secure_headers: true,
|
86
|
-
additional_headers: additional_headers
|
87
|
-
)
|
88
|
-
end
|
89
|
-
|
90
|
-
# Get_payments
|
91
|
-
def _get_payments_request(access_token, session_id)
|
92
|
-
url = payment_endpoint
|
93
|
-
|
94
|
-
Fintecture::Faraday::Authentication::Connection.get(
|
95
|
-
url: "#{url}/#{session_id}",
|
96
|
-
custom_content_type: 'application/json',
|
97
|
-
bearer: "Bearer #{access_token}",
|
98
|
-
secure_headers: true
|
99
|
-
)
|
100
|
-
end
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
# ------------ BUILD PAYLOADS ------------
|
106
|
-
# Connect - Build the payload from payment_attrs
|
107
|
-
def build_payload_connect(payment_attrs = nil)
|
108
|
-
# Mandatory attributes
|
109
|
-
attributes = {
|
110
|
-
amount: payment_attrs['amount'].to_s,
|
111
|
-
currency: payment_attrs['currency'],
|
112
|
-
communication: payment_attrs['communication'],
|
113
|
-
end_to_end_id: payment_attrs['end_to_end_id'] || Fintecture::Utils::Crypto.generate_uuid_only_chars
|
114
|
-
}
|
115
|
-
|
116
|
-
# Optionals attributes
|
117
|
-
attributes['execution_date'] = payment_attrs['execution_date'] if payment_attrs['execution_date']
|
118
|
-
attributes['debited_account_id'] = payment_attrs['debited_account_id'] if payment_attrs['debited_account_id']
|
119
|
-
attributes['debited_account_type'] = payment_attrs['debited_account_type'] if payment_attrs['debited_account_type']
|
120
|
-
attributes['scheme'] = payment_attrs['scheme'] if payment_attrs['scheme']
|
121
|
-
|
122
|
-
# Mandatory attributes => beneficiary
|
123
|
-
if payment_attrs['beneficiary']
|
124
|
-
attributes['beneficiary'] = {
|
125
|
-
name: payment_attrs['beneficiary']['name'],
|
126
|
-
street: payment_attrs['beneficiary']['street'],
|
127
|
-
zip: payment_attrs['beneficiary']['zip'],
|
128
|
-
city: payment_attrs['beneficiary']['city'],
|
129
|
-
country: payment_attrs['beneficiary']['country'],
|
130
|
-
iban: payment_attrs['beneficiary']['iban'],
|
131
|
-
swift_bic: payment_attrs['beneficiary']['swift_bic']
|
132
|
-
}
|
133
|
-
|
134
|
-
# Optionals attributes => beneficiary
|
135
|
-
attributes['beneficiary']['number'] = payment_attrs['beneficiary']['number'] if payment_attrs['beneficiary']['number']
|
136
|
-
attributes['beneficiary']['complement'] = payment_attrs['beneficiary']['complement'] if payment_attrs['beneficiary']['complement']
|
137
|
-
attributes['beneficiary']['form'] = payment_attrs['beneficiary']['form'] if payment_attrs['beneficiary']['form']
|
138
|
-
attributes['beneficiary']['incorporation'] = payment_attrs['beneficiary']['incorporation'] if payment_attrs['beneficiary']['incorporation']
|
139
|
-
end
|
140
|
-
|
141
|
-
# Mandatory meta data
|
142
|
-
meta = {
|
143
|
-
psu_name: payment_attrs['customer_full_name'],
|
144
|
-
psu_email: payment_attrs['customer_email'],
|
145
|
-
psu_phone: payment_attrs['customer_phone']
|
146
|
-
}
|
147
|
-
|
148
|
-
# Optionals meta data
|
149
|
-
meta['psu_phone_prefix'] = payment_attrs['customer_phone_prefix'] if payment_attrs['customer_phone_prefix']
|
150
|
-
meta['psu_ip'] = payment_attrs['customer_ip'] if payment_attrs['customer_ip']
|
151
|
-
|
152
|
-
# Mandatory meta => psu_address
|
153
|
-
meta['psu_address'] = {
|
154
|
-
street: payment_attrs['customer_address']['street'],
|
155
|
-
city: payment_attrs['customer_address']['city'],
|
156
|
-
zip: payment_attrs['customer_address']['zip'],
|
157
|
-
country: payment_attrs['customer_address']['country']
|
158
|
-
}
|
159
|
-
|
160
|
-
# Optionals meta => psu_address
|
161
|
-
meta['psu_address']['number'] = payment_attrs['customer_address']['number'] if payment_attrs['customer_address']['number']
|
162
|
-
meta['psu_address']['complement'] = payment_attrs['customer_address']['complement'] if payment_attrs['customer_address']['complement']
|
163
|
-
|
164
|
-
# Return the payload
|
165
|
-
{
|
166
|
-
meta: meta,
|
167
|
-
data: {
|
168
|
-
type: 'PIS',
|
169
|
-
attributes: attributes,
|
170
|
-
}
|
171
|
-
}
|
172
|
-
end
|
173
|
-
|
174
|
-
# Request_to_pay - Build the payload from payment_attrs
|
175
|
-
def build_payload_request_to_pay(payment_attrs = nil)
|
176
|
-
# Mandatory attributes
|
177
|
-
attributes = {
|
178
|
-
amount: payment_attrs['amount'],
|
179
|
-
currency: payment_attrs['currency'],
|
180
|
-
communication: payment_attrs['communication']
|
181
|
-
}
|
182
|
-
|
183
|
-
# Mandatory meta data
|
184
|
-
meta = {
|
185
|
-
psu_name: payment_attrs['customer_full_name'],
|
186
|
-
psu_email: payment_attrs['customer_email'],
|
187
|
-
psu_phone: payment_attrs['customer_phone'],
|
188
|
-
psu_phone_prefix: payment_attrs['customer_phone_prefix']
|
189
|
-
}
|
190
|
-
|
191
|
-
# Optionals meta psu_address
|
192
|
-
if payment_attrs['customer_address']
|
193
|
-
meta['psu_address'] = {}
|
194
|
-
meta['psu_address']['street'] = payment_attrs['customer_address']['street'] if payment_attrs['customer_address']['street']
|
195
|
-
meta['psu_address']['number'] = payment_attrs['customer_address']['number'] if payment_attrs['customer_address']['number']
|
196
|
-
meta['psu_address']['city'] = payment_attrs['customer_address']['city'] if payment_attrs['customer_address']['city']
|
197
|
-
meta['psu_address']['zip'] = payment_attrs['customer_address']['zip'] if payment_attrs['customer_address']['zip']
|
198
|
-
meta['psu_address']['country'] = payment_attrs['customer_address']['country'] if payment_attrs['customer_address']['country']
|
199
|
-
end
|
200
|
-
|
201
|
-
# Optionals meta data
|
202
|
-
meta['expirary'] = payment_attrs['expirary'] if payment_attrs['expirary']
|
203
|
-
meta['cc'] = payment_attrs['cc'] if payment_attrs['cc']
|
204
|
-
meta['bcc'] = payment_attrs['bcc'] if payment_attrs['bcc']
|
205
|
-
|
206
|
-
|
207
|
-
# Return the payload
|
208
|
-
{
|
209
|
-
meta: meta,
|
210
|
-
data: {
|
211
|
-
type: 'REQUEST_TO_PAY',
|
212
|
-
attributes: attributes,
|
213
|
-
}
|
214
|
-
}
|
215
|
-
end
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
# ------------ API ENDPOINTS ------------
|
221
|
-
# Request_to_pay
|
222
|
-
def request_to_pay_endpoint
|
223
|
-
"#{api_base_url}/#{Fintecture::Api::Endpoints::Pis::REQUEST_TO_PAY}"
|
224
|
-
end
|
225
|
-
|
226
|
-
# Payment
|
227
|
-
def payment_endpoint
|
228
|
-
"#{api_base_url}/#{Fintecture::Api::Endpoints::Pis::PAYMENTS}"
|
229
|
-
end
|
230
|
-
|
231
|
-
# Connect
|
232
|
-
def connect_endpoint
|
233
|
-
"#{api_base_url}/#{Fintecture::Api::Endpoints::Pis::CONNECT}"
|
234
|
-
end
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
# ------------ BASE URL ------------
|
240
|
-
def base_url
|
241
|
-
Fintecture::Api::BaseUrl::FINTECTURE_CONNECT_URL[Fintecture.environment.to_sym]
|
242
|
-
end
|
243
|
-
|
244
|
-
def api_base_url
|
245
|
-
Fintecture::Api::BaseUrl::FINTECTURE_API_URL[Fintecture.environment.to_sym]
|
246
|
-
end
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
# ------------ TOOLS ------------
|
251
|
-
def as_json(element)
|
252
|
-
return JSON(element.to_json) if element.is_a? Hash
|
253
|
-
|
254
|
-
begin
|
255
|
-
element.as_json
|
256
|
-
rescue NoMethodError
|
257
|
-
raise Fintecture::ValidationException.new("invalid parameter format, the parameter should be a Hash or an Object Model instead a #{element.class.name}")
|
258
|
-
end
|
259
|
-
end
|
260
|
-
end
|
261
|
-
end
|
262
|
-
end
|