fintecture 0.2.1 → 0.4.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 +17 -19
- data/.rspec +3 -3
- data/.travis.yml +7 -7
- data/CODE_OF_CONDUCT.md +74 -74
- data/Gemfile +8 -6
- data/Gemfile.lock +59 -59
- data/LICENSE.txt +674 -674
- data/README.md +407 -238
- data/Rakefile +8 -6
- data/bin/console +15 -14
- data/bin/setup +8 -8
- 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 +44 -43
- 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} +78 -76
- 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 +50 -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 +13 -13
- data/lib/fintecture/endpoints/pis.rb +16 -0
- data/lib/fintecture/endpoints/ressources.rb +13 -0
- data/lib/fintecture/exceptions.rb +72 -33
- data/lib/fintecture/faraday/authentication/connection.rb +140 -120
- data/lib/fintecture/pis_client.rb +100 -0
- data/lib/fintecture/utils/constants.rb +11 -14
- data/lib/fintecture/utils/crypto.rb +75 -78
- data/lib/fintecture/utils/date.rb +15 -15
- data/lib/fintecture/utils/validation.rb +32 -26
- data/lib/fintecture/version.rb +5 -3
- data/lib/fintecture.rb +65 -82
- metadata +35 -12
- 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
data/lib/fintecture.rb
CHANGED
@@ -1,82 +1,65 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
require '
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
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
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
raise ArgumentError, 'log_level should only be set to `nil`, `debug` or `info`'
|
67
|
-
end
|
68
|
-
@log_level = val
|
69
|
-
end
|
70
|
-
|
71
|
-
def logger
|
72
|
-
@logger
|
73
|
-
end
|
74
|
-
|
75
|
-
def logger=(val)
|
76
|
-
@logger = val
|
77
|
-
end
|
78
|
-
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
|
-
Fintecture.log_level = ENV["FINTECTURE_LOG"] unless ENV["FINTECTURE_LOG"].nil?
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'logger'
|
4
|
+
require 'uri'
|
5
|
+
require 'faraday'
|
6
|
+
|
7
|
+
# ToRemove
|
8
|
+
require 'openssl'
|
9
|
+
require 'cgi'
|
10
|
+
|
11
|
+
# Version
|
12
|
+
require 'fintecture/version'
|
13
|
+
|
14
|
+
# Modules
|
15
|
+
require 'fintecture/api/auth/authentication'
|
16
|
+
|
17
|
+
# Clients
|
18
|
+
require 'fintecture/pis_client'
|
19
|
+
require 'fintecture/ais_client'
|
20
|
+
|
21
|
+
# Utilities
|
22
|
+
require 'fintecture/utils/crypto'
|
23
|
+
|
24
|
+
# Endpoints
|
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'
|
30
|
+
|
31
|
+
# Connections
|
32
|
+
require 'fintecture/faraday/authentication/connection'
|
33
|
+
|
34
|
+
module Fintecture
|
35
|
+
@log_level = nil
|
36
|
+
@logger = nil
|
37
|
+
|
38
|
+
class << self
|
39
|
+
attr_accessor :logger
|
40
|
+
attr_reader :log_level
|
41
|
+
|
42
|
+
# Logging
|
43
|
+
LEVEL_DEBUG = Logger::DEBUG
|
44
|
+
LEVEL_ERROR = Logger::ERROR
|
45
|
+
LEVEL_INFO = Logger::INFO
|
46
|
+
|
47
|
+
def log_level=(val)
|
48
|
+
case val
|
49
|
+
when 'debug'
|
50
|
+
val = LEVEL_DEBUG
|
51
|
+
when 'info'
|
52
|
+
val = LEVEL_INFO
|
53
|
+
end
|
54
|
+
|
55
|
+
if !val.nil? && ![LEVEL_DEBUG, LEVEL_ERROR, LEVEL_INFO].include?(val)
|
56
|
+
raise ArgumentError, 'log_level should only be set to `nil`, `debug` or `info`'
|
57
|
+
end
|
58
|
+
|
59
|
+
@log_level = val
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
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.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Fintecture
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-04-25 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
|
@@ -105,7 +128,7 @@ licenses:
|
|
105
128
|
metadata:
|
106
129
|
homepage_uri: http://fintecture.com
|
107
130
|
source_code_uri: https://github.com/Fintecture/fintecture-sdk-ruby
|
108
|
-
post_install_message:
|
131
|
+
post_install_message:
|
109
132
|
rdoc_options: []
|
110
133
|
require_paths:
|
111
134
|
- lib
|
@@ -120,8 +143,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
120
143
|
- !ruby/object:Gem::Version
|
121
144
|
version: '0'
|
122
145
|
requirements: []
|
123
|
-
rubygems_version: 3.2.
|
124
|
-
signing_key:
|
146
|
+
rubygems_version: 3.2.32
|
147
|
+
signing_key:
|
125
148
|
specification_version: 4
|
126
149
|
summary: Short summary
|
127
150
|
test_files: []
|
@@ -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
|