genesis_ruby 0.2.2 → 0.2.3
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/CHANGELOG.md +17 -0
- data/Gemfile.lock +50 -41
- data/README.md +16 -0
- data/VERSION +1 -1
- data/lib/genesis_ruby/api/constants/transactions/parameters/non_financial/billing_api/order_by_fields.rb +33 -0
- data/lib/genesis_ruby/api/constants/transactions/parameters/non_financial/billing_api/response_fields.rb +67 -0
- data/lib/genesis_ruby/api/constants/transactions/parameters/non_financial/billing_api/transaction_types.rb +48 -0
- data/lib/genesis_ruby/api/constants/transactions/parameters/non_financial/sort_directions.rb +24 -0
- data/lib/genesis_ruby/api/constants/transactions/parameters/online_banking/payment_types.rb +3 -0
- data/lib/genesis_ruby/api/constants/transactions.rb +5 -0
- data/lib/genesis_ruby/api/mixins/requests/financial/bank_attributes.rb +26 -0
- data/lib/genesis_ruby/api/mixins/requests/non_financial/billing_api/sort_attributes.rb +18 -0
- data/lib/genesis_ruby/api/mixins/requests/non_financial/date_attributes.rb +64 -0
- data/lib/genesis_ruby/api/mixins/requests/non_financial/paging_attributes.rb +33 -0
- data/lib/genesis_ruby/api/mixins/requests/restricted_setter.rb +18 -0
- data/lib/genesis_ruby/api/request.rb +15 -0
- data/lib/genesis_ruby/api/requests/base/graphql.rb +60 -0
- data/lib/genesis_ruby/api/requests/financial/online_banking_payments/banco_do_brasil.rb +60 -0
- data/lib/genesis_ruby/api/requests/financial/online_banking_payments/eps.rb +47 -0
- data/lib/genesis_ruby/api/requests/financial/online_banking_payments/idebit/pay_in.rb +55 -0
- data/lib/genesis_ruby/api/requests/financial/online_banking_payments/idebit/pay_out.rb +28 -0
- data/lib/genesis_ruby/api/requests/financial/online_banking_payments/wechat.rb +53 -0
- data/lib/genesis_ruby/api/requests/financial/sdd/recurring/init_recurring_sale.rb +23 -0
- data/lib/genesis_ruby/api/requests/financial/sdd/recurring/recurring_sale.rb +28 -0
- data/lib/genesis_ruby/api/requests/financial/sdd/refund.rb +26 -0
- data/lib/genesis_ruby/api/requests/financial/sdd/sale.rb +61 -0
- data/lib/genesis_ruby/api/requests/financial/wallets/alipay.rb +49 -0
- data/lib/genesis_ruby/api/requests/non_financial/billing_api/transactions.rb +203 -0
- data/lib/genesis_ruby/api/requests/non_financial/reconcile/date_range.rb +2 -50
- data/lib/genesis_ruby/builder.rb +5 -0
- data/lib/genesis_ruby/builders/graphql.rb +118 -0
- data/lib/genesis_ruby/configuration.rb +11 -2
- data/lib/genesis_ruby/dependencies.rb +2 -0
- data/lib/genesis_ruby/network/adapter/net_http_adapter.rb +20 -9
- data/lib/genesis_ruby/network/base_network.rb +1 -14
- data/lib/genesis_ruby/utils/formatters/response/formats/timestamp.rb +1 -1
- data/lib/genesis_ruby/utils/options/api_config.rb +19 -0
- data/lib/genesis_ruby/utils/options/network_adapter_config.rb +49 -14
- data/lib/genesis_ruby/utils/transactions/financial_types.rb +1 -1
- data/lib/genesis_ruby/utils/transactions/references/refundable_types.rb +1 -1
- data/lib/genesis_ruby/utils/transactions/wpf_types.rb +1 -1
- data/lib/genesis_ruby/version.rb +1 -1
- metadata +25 -4
- /data/lib/genesis_ruby/api/requests/financial/wallets/{pay_pay.rb → pay_pal.rb} +0 -0
@@ -0,0 +1,203 @@
|
|
1
|
+
require 'date'
|
2
|
+
require 'genesis_ruby/api/constants/transactions/parameters/non_financial/billing_api/order_by_fields'
|
3
|
+
require 'genesis_ruby/api/constants/transactions/parameters/non_financial/billing_api/response_fields'
|
4
|
+
require 'genesis_ruby/api/constants/transactions/parameters/non_financial/billing_api/transaction_types'
|
5
|
+
require 'genesis_ruby/api/constants/transactions/parameters/non_financial/sort_directions'
|
6
|
+
|
7
|
+
module GenesisRuby
|
8
|
+
module Api
|
9
|
+
module Requests
|
10
|
+
module NonFinancial
|
11
|
+
module BillingApi
|
12
|
+
# Billing Transactions API allows to programmatically retrieve information about billing transactions
|
13
|
+
# using given filters, pagination, and sort parameters.
|
14
|
+
class Transactions < Base::Graphql # rubocop:disable Metrics/ClassLength
|
15
|
+
|
16
|
+
include Api::Mixins::Requests::NonFinancial::BillingApi::SortAttributes
|
17
|
+
include Api::Mixins::Requests::NonFinancial::DateAttributes
|
18
|
+
include Api::Mixins::Requests::NonFinancial::PagingAttributes
|
19
|
+
|
20
|
+
def initialize(configuration, _builder_interface = nil)
|
21
|
+
super configuration
|
22
|
+
|
23
|
+
self.root_key = 'query'
|
24
|
+
self.request_name = 'billingTransactions'
|
25
|
+
self.request_path = 'billing_transactions'
|
26
|
+
end
|
27
|
+
|
28
|
+
# Response Fields
|
29
|
+
def response_fields
|
30
|
+
@response_fields || []
|
31
|
+
end
|
32
|
+
|
33
|
+
# Response Fields
|
34
|
+
def response_fields=(value)
|
35
|
+
parse_array_of_strings attribute: __method__,
|
36
|
+
value: value,
|
37
|
+
allowed: Api::Constants::Transactions::Parameters::NonFinancial::BillingApi::
|
38
|
+
ResponseFields.all
|
39
|
+
end
|
40
|
+
|
41
|
+
# List of billing transaction unique IDs. Max number of elements is 10000. Primary filter.
|
42
|
+
def unique_id
|
43
|
+
@unique_id || []
|
44
|
+
end
|
45
|
+
|
46
|
+
# List of billing transaction unique IDs. Max number of elements is 10000. Primary filter.
|
47
|
+
def unique_id=(value)
|
48
|
+
parse_array_of_strings attribute: __method__, value: value, allow_empty: true
|
49
|
+
end
|
50
|
+
|
51
|
+
# List of billing statement names. Max number of elements allowed is 10. Primary filter.
|
52
|
+
def billing_statement
|
53
|
+
@billing_statement || []
|
54
|
+
end
|
55
|
+
|
56
|
+
# List of billing statement names. Max number of elements allowed is 10. Primary filter.
|
57
|
+
def billing_statement=(value)
|
58
|
+
parse_array_of_strings attribute: __method__, value: value, allow_empty: true
|
59
|
+
end
|
60
|
+
|
61
|
+
# List of merchant transaction IDs. Max number of elements allowed is 10000. Primary filter.
|
62
|
+
def merchant_transaction_id
|
63
|
+
@merchant_transaction_id || []
|
64
|
+
end
|
65
|
+
|
66
|
+
# List of merchant transaction IDs. Max number of elements allowed is 10000. Primary filter.
|
67
|
+
def merchant_transaction_id=(value)
|
68
|
+
parse_array_of_strings attribute: __method__, value: value, allow_empty: true
|
69
|
+
end
|
70
|
+
|
71
|
+
# List of master account names. Max number of elements allowed is 10. Secondary filter.
|
72
|
+
def master_account_name
|
73
|
+
@master_account_name || []
|
74
|
+
end
|
75
|
+
|
76
|
+
# List of master account names. Max number of elements allowed is 10. Secondary filter.
|
77
|
+
def master_account_name=(value)
|
78
|
+
parse_array_of_strings attribute: __method__, value: value, allow_empty: true
|
79
|
+
end
|
80
|
+
|
81
|
+
# List of billing transaction types. Max number of elements allowed is 10.
|
82
|
+
def transaction_type
|
83
|
+
@transaction_type || []
|
84
|
+
end
|
85
|
+
|
86
|
+
# List of billing transaction types. Max number of elements allowed is 10.
|
87
|
+
def transaction_type=(value)
|
88
|
+
parse_array_of_strings attribute: __method__,
|
89
|
+
value: value,
|
90
|
+
allowed: Api::Constants::Transactions::Parameters::NonFinancial::BillingApi::
|
91
|
+
TransactionTypes.all,
|
92
|
+
allow_empty: true
|
93
|
+
end
|
94
|
+
|
95
|
+
protected
|
96
|
+
|
97
|
+
# Billing API Authorization Token
|
98
|
+
def init_authorization_token
|
99
|
+
api_config.bearer_token = configuration.billing_api_token
|
100
|
+
end
|
101
|
+
|
102
|
+
# Billing API Transactions field validations
|
103
|
+
def init_field_validations
|
104
|
+
super
|
105
|
+
|
106
|
+
required_fields.push *%i[response_fields]
|
107
|
+
field_values.merge! sort_by_direction: Api::Constants::Transactions::Parameters::NonFinancial::
|
108
|
+
SortDirections.all,
|
109
|
+
sort_by_field: Api::Constants::Transactions::Parameters::NonFinancial::BillingApi::
|
110
|
+
OrderByFields.all
|
111
|
+
end
|
112
|
+
|
113
|
+
# Billing API Transactions custom validations
|
114
|
+
def check_requirements
|
115
|
+
super
|
116
|
+
|
117
|
+
validate_filters
|
118
|
+
validate_dates if @start_date || @end_date
|
119
|
+
validate_array_fields_size
|
120
|
+
end
|
121
|
+
|
122
|
+
# Transactions GraphQL query filters
|
123
|
+
def query_filters # rubocop:disable Metrics/MethodLength
|
124
|
+
{
|
125
|
+
filter: {
|
126
|
+
startDate: escape_argument(:start_date),
|
127
|
+
endDate: escape_argument(:end_date),
|
128
|
+
uniqueId: unique_id,
|
129
|
+
billingStatement: billing_statement,
|
130
|
+
merchantTransactionId: merchant_transaction_id,
|
131
|
+
masterAccountName: master_account_name,
|
132
|
+
transactionType: transaction_type
|
133
|
+
},
|
134
|
+
sort: {
|
135
|
+
byDirection: sort_by_direction,
|
136
|
+
byField: sort_by_field
|
137
|
+
},
|
138
|
+
paging: {
|
139
|
+
page: page,
|
140
|
+
perPage: per_page
|
141
|
+
}
|
142
|
+
}
|
143
|
+
end
|
144
|
+
|
145
|
+
# Transactions Response Fields
|
146
|
+
def query_response_fields
|
147
|
+
{
|
148
|
+
items: response_fields,
|
149
|
+
paging: paging_query_fields
|
150
|
+
}
|
151
|
+
end
|
152
|
+
|
153
|
+
# Format given timestamp string to GraphQL suitable argument
|
154
|
+
def escape_argument(attribute)
|
155
|
+
__send__(attribute).to_s.empty? ? nil : "\"#{__send__(attribute)}\""
|
156
|
+
end
|
157
|
+
|
158
|
+
# Validate Billing API Primary filters
|
159
|
+
def validate_filters
|
160
|
+
unless start_date.nil? && end_date.nil? && unique_id.empty? && billing_statement.empty? &&
|
161
|
+
merchant_transaction_id.empty?
|
162
|
+
return
|
163
|
+
end
|
164
|
+
|
165
|
+
raise ParameterError, 'At least one Primary filter is required!'
|
166
|
+
end
|
167
|
+
|
168
|
+
# Validate StartDate and EndDate
|
169
|
+
def validate_dates
|
170
|
+
message = 'If filter startDate is provided, then endDate should also be provided and vice versa.'
|
171
|
+
raise ParameterError, message unless @start_date.is_a?(DateTime) && @end_date.is_a?(DateTime)
|
172
|
+
|
173
|
+
raise ParameterError, 'EndData must be after StartDate!' if @start_date == @end_date
|
174
|
+
|
175
|
+
days_diff = @end_date - @start_date
|
176
|
+
message = 'Maximum difference between StartDate and EndDate is 7 days'
|
177
|
+
raise ParameterError, message unless days_diff >= 0 && days_diff <= 7
|
178
|
+
end
|
179
|
+
|
180
|
+
# Validate Billing API Array field requirements
|
181
|
+
def validate_array_fields_size
|
182
|
+
validate_array_size :unique_id, 10_000
|
183
|
+
validate_array_size :billing_statement, 10
|
184
|
+
validate_array_size :merchant_transaction_id, 10_000
|
185
|
+
validate_array_size :master_account_name, 10
|
186
|
+
validate_array_size :transaction_type, 10
|
187
|
+
end
|
188
|
+
|
189
|
+
# Validate Max size of the given Array attribute
|
190
|
+
def validate_array_size(attribute, size)
|
191
|
+
message = format 'Max array length on %{attribute} exceed allowed size of %{size}',
|
192
|
+
attribute: attribute,
|
193
|
+
size: size
|
194
|
+
|
195
|
+
raise ParameterError, message if __send__(attribute).length > size
|
196
|
+
end
|
197
|
+
|
198
|
+
end
|
199
|
+
end
|
200
|
+
end
|
201
|
+
end
|
202
|
+
end
|
203
|
+
end
|
@@ -8,43 +8,9 @@ module GenesisRuby
|
|
8
8
|
# The response is paginated, each request will return 100 entries max.
|
9
9
|
class DateRange < Api::Request
|
10
10
|
|
11
|
-
|
12
|
-
|
13
|
-
# Start of the requested date range (time is optional)
|
14
|
-
def start_date
|
15
|
-
format = if start_date_time?
|
16
|
-
Constants::DateTimeFormats::YYYY_MM_DD_H_I_S
|
17
|
-
else
|
18
|
-
Constants::DateTimeFormats::YYYY_MM_DD_ISO_8601
|
19
|
-
end
|
20
|
-
|
21
|
-
@start_date&.strftime format
|
22
|
-
end
|
23
|
-
|
24
|
-
# Start of the requested date range (time is optional)
|
25
|
-
def start_date=(value)
|
26
|
-
self.start_date_time = Utils::Common.date_has_time? value
|
27
|
-
|
28
|
-
parse_date attribute: __method__, value: value, allow_empty: false
|
29
|
-
end
|
30
|
-
|
31
|
-
# Start of the requested date range (time is optional)
|
32
|
-
def end_date
|
33
|
-
format = if end_date_time?
|
34
|
-
Constants::DateTimeFormats::YYYY_MM_DD_H_I_S
|
35
|
-
else
|
36
|
-
Constants::DateTimeFormats::YYYY_MM_DD_ISO_8601
|
37
|
-
end
|
38
|
-
|
39
|
-
@end_date&.strftime format
|
40
|
-
end
|
11
|
+
include Api::Mixins::Requests::NonFinancial::DateAttributes
|
41
12
|
|
42
|
-
|
43
|
-
def end_date=(value)
|
44
|
-
self.end_date_time = Utils::Common.date_has_time? value
|
45
|
-
|
46
|
-
parse_date attribute: __method__, value: value, allow_empty: true
|
47
|
-
end
|
13
|
+
attr_reader :page
|
48
14
|
|
49
15
|
# The page within the paginated result, defaults to 1
|
50
16
|
def page=(value)
|
@@ -75,20 +41,6 @@ module GenesisRuby
|
|
75
41
|
}
|
76
42
|
end
|
77
43
|
|
78
|
-
private
|
79
|
-
|
80
|
-
attr_accessor :start_date_time, :end_date_time
|
81
|
-
|
82
|
-
# Start Date has time within the given string
|
83
|
-
def start_date_time?
|
84
|
-
self.start_date_time ||= false
|
85
|
-
end
|
86
|
-
|
87
|
-
# End Date has time within the given string
|
88
|
-
def end_date_time?
|
89
|
-
self.end_date_time ||= false
|
90
|
-
end
|
91
|
-
|
92
44
|
end
|
93
45
|
end
|
94
46
|
end
|
data/lib/genesis_ruby/builder.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'genesis_ruby/builders/xml'
|
2
2
|
require 'genesis_ruby/builders/form'
|
3
3
|
require 'genesis_ruby/builders/json'
|
4
|
+
require 'genesis_ruby/builders/graphql'
|
4
5
|
require 'genesis_ruby/errors/builder_error'
|
5
6
|
|
6
7
|
module GenesisRuby
|
@@ -16,12 +17,16 @@ module GenesisRuby
|
|
16
17
|
# Builder FORM
|
17
18
|
FORM = 'form'.freeze
|
18
19
|
|
20
|
+
# Builder GraphQL
|
21
|
+
GRAPHQL = 'graphql'.freeze
|
22
|
+
|
19
23
|
# Initialize the Builder Interface based on the Request requirements
|
20
24
|
def initialize(request_interface)
|
21
25
|
case request_interface
|
22
26
|
when XML then @builder_context = Builders::Xml.new
|
23
27
|
when FORM then @builder_context = Builders::Form.new
|
24
28
|
when JSON then @builder_context = Builders::Json.new
|
29
|
+
when GRAPHQL then @builder_context = Builders::Graphql.new
|
25
30
|
else
|
26
31
|
raise GenesisRuby::BuilderError, 'Invalid Builder interface!'
|
27
32
|
end
|
@@ -0,0 +1,118 @@
|
|
1
|
+
require 'genesis_ruby/builders/base'
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
module GenesisRuby
|
5
|
+
module Builders
|
6
|
+
# GraphQL builder
|
7
|
+
class Graphql < Base
|
8
|
+
|
9
|
+
# Builder GraphQL constructor
|
10
|
+
def initialize
|
11
|
+
@document = ''
|
12
|
+
super
|
13
|
+
end
|
14
|
+
|
15
|
+
# Outputs generated document
|
16
|
+
def output
|
17
|
+
@document
|
18
|
+
end
|
19
|
+
|
20
|
+
# Created GraphQL query from provided structure
|
21
|
+
def populate_nodes(structure)
|
22
|
+
validate_structure(structure)
|
23
|
+
|
24
|
+
@document = build_query(structure)
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
# Validates given structure
|
30
|
+
def validate_structure(structure)
|
31
|
+
raise BuilderError, 'Invalid Hash structure given in Graphql builder!' unless structure.is_a? Hash
|
32
|
+
|
33
|
+
root_key = structure.keys.first
|
34
|
+
|
35
|
+
raise BuilderError, 'Missing structure root key in Graphql builder' if root_key.nil?
|
36
|
+
raise BuilderError, 'Invalid GraphQL structure given in GraphQL builder' unless structure[root_key].is_a? Hash
|
37
|
+
end
|
38
|
+
|
39
|
+
# Build GraphQL Query
|
40
|
+
def build_query(structure)
|
41
|
+
ident = ' ' * 2
|
42
|
+
root_key = structure.keys.first
|
43
|
+
filters = build_filters structure[root_key][:filters]
|
44
|
+
response_fields = build_response_fields structure[root_key][:response_fields], ident * 2
|
45
|
+
|
46
|
+
format("%{root} {\n#{ident}%{action}(%{filters})\n#{ident}{\n%{response_fields}\n#{ident}}\n}",
|
47
|
+
root: root_key,
|
48
|
+
action: structure[root_key][:action].to_s,
|
49
|
+
filters: filters,
|
50
|
+
response_fields: response_fields)
|
51
|
+
end
|
52
|
+
|
53
|
+
# Build GraphQL filters
|
54
|
+
def build_filters(data)
|
55
|
+
out = ''
|
56
|
+
|
57
|
+
return out unless data.is_a? Hash
|
58
|
+
|
59
|
+
data.each do |key, value|
|
60
|
+
out += splat_hash Hash[key, value]
|
61
|
+
out += ', ' unless data.keys.last == key
|
62
|
+
end
|
63
|
+
|
64
|
+
out
|
65
|
+
end
|
66
|
+
|
67
|
+
# Builds given hash in the GraphQL syntax
|
68
|
+
# { key: { key1: 'value1', key2: 'value2' } } becomes key: { key1: value1, key2: value2 }
|
69
|
+
def splat_hash(data)
|
70
|
+
out = ''
|
71
|
+
root_key = data.keys.first
|
72
|
+
|
73
|
+
return out unless data[root_key].is_a? Hash
|
74
|
+
|
75
|
+
data[root_key].each do |key, value|
|
76
|
+
out += format '%{key}: %{value}', key: key.to_s, value: value.to_s
|
77
|
+
out += ', ' unless key == data[root_key].keys.last
|
78
|
+
end
|
79
|
+
|
80
|
+
format '%{key}: { %{out} }', key: root_key, out: out
|
81
|
+
end
|
82
|
+
|
83
|
+
# Build GraphQL query response fields
|
84
|
+
def build_response_fields(data, ident)
|
85
|
+
out = ''
|
86
|
+
|
87
|
+
return out unless data.is_a? Hash
|
88
|
+
|
89
|
+
data.each do |key, value|
|
90
|
+
out += formatted_array Hash[key, value], ident
|
91
|
+
out += "\n" unless key == data.keys.last
|
92
|
+
end
|
93
|
+
|
94
|
+
out
|
95
|
+
end
|
96
|
+
|
97
|
+
# Build given array into formatted GraphQL query items
|
98
|
+
# items: [item1 item2 item3] will output
|
99
|
+
# items
|
100
|
+
# {
|
101
|
+
# item1
|
102
|
+
# item2
|
103
|
+
# item3
|
104
|
+
# }
|
105
|
+
def formatted_array(data, ident)
|
106
|
+
out = ''
|
107
|
+
root_key = data.keys.first
|
108
|
+
|
109
|
+
return out unless data[root_key].is_a? Array
|
110
|
+
|
111
|
+
out += data[root_key].map { |key| "#{ident} #{key}" }.join("\n")
|
112
|
+
|
113
|
+
format "#{ident}%{key}\n#{ident}{\n%{out}\n#{ident}}", key: root_key, out: out
|
114
|
+
end
|
115
|
+
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
@@ -20,8 +20,8 @@ module GenesisRuby
|
|
20
20
|
# Default sanitize Response
|
21
21
|
DEFAULT_SANITIZE_RESPONSE = true
|
22
22
|
|
23
|
-
# Genesis basic configuration - credentials, endpoint, environment, token
|
24
|
-
attr_writer :username, :password, :token, :interface, :format_response, :sanitize_response
|
23
|
+
# Genesis basic configuration - credentials, endpoint, environment, token, etc
|
24
|
+
attr_writer :username, :password, :token, :interface, :format_response, :sanitize_response, :billing_api_token
|
25
25
|
|
26
26
|
# Configuration constructor
|
27
27
|
def initialize
|
@@ -64,6 +64,11 @@ module GenesisRuby
|
|
64
64
|
@force_smart_routing ||= false
|
65
65
|
end
|
66
66
|
|
67
|
+
# Defines the Bearer token used for authorization in Billing API Service
|
68
|
+
def billing_api_token
|
69
|
+
@billing_api_token || ''
|
70
|
+
end
|
71
|
+
|
67
72
|
# Genesis Request Timeout
|
68
73
|
def timeout=(value)
|
69
74
|
timeout = value.to_i
|
@@ -187,6 +192,10 @@ module GenesisRuby
|
|
187
192
|
smart_router: {
|
188
193
|
GenesisRuby::Api::Constants::Environments::PRODUCTION => 'prod.api.',
|
189
194
|
GenesisRuby::Api::Constants::Environments::STAGING => 'staging.api.'
|
195
|
+
},
|
196
|
+
api_service: {
|
197
|
+
GenesisRuby::Api::Constants::Environments::PRODUCTION => 'prod.api.',
|
198
|
+
GenesisRuby::Api::Constants::Environments::STAGING => 'staging.api.'
|
190
199
|
}
|
191
200
|
}
|
192
201
|
end
|
@@ -21,6 +21,8 @@ require 'genesis_ruby/api/requests/base/financials/credit_card'
|
|
21
21
|
require 'genesis_ruby/api/requests/base/financials/south_american_payments'
|
22
22
|
require 'genesis_ruby/api/requests/base/reference'
|
23
23
|
require 'genesis_ruby/api/requests/base/versioned'
|
24
|
+
require 'genesis_ruby/api/requests/financial/sdd/sale'
|
25
|
+
require 'genesis_ruby/api/requests/base/graphql'
|
24
26
|
require 'genesis_ruby/api/notification'
|
25
27
|
|
26
28
|
# Load Financial and Non Financial API Requests
|
@@ -90,17 +90,28 @@ module GenesisRuby
|
|
90
90
|
|
91
91
|
# Define Headers
|
92
92
|
def headers
|
93
|
-
|
94
|
-
'Authorization' => "Basic #{request_data.user_login}",
|
95
|
-
'User-Agent' => request_data.user_agent
|
96
|
-
}
|
93
|
+
data = common_headers
|
97
94
|
|
98
|
-
unless request_data.type == Api::Request::METHOD_GET
|
99
|
-
|
100
|
-
|
101
|
-
|
95
|
+
data.merge! payload_headers unless request_data.type == Api::Request::METHOD_GET
|
96
|
+
data.merge! request_data.headers if request_data.headers.is_a?(Hash) && !request_data.headers.empty?
|
97
|
+
|
98
|
+
data
|
99
|
+
end
|
100
|
+
|
101
|
+
# Provides default request headers
|
102
|
+
def common_headers
|
103
|
+
{
|
104
|
+
'Authorization' => request_data.user_login.to_s,
|
105
|
+
'User-Agent' => request_data.user_agent.to_s
|
106
|
+
}
|
107
|
+
end
|
102
108
|
|
103
|
-
|
109
|
+
# Payload Headers
|
110
|
+
def payload_headers
|
111
|
+
{
|
112
|
+
'Content-Type' => request_data.format,
|
113
|
+
'Content-Length' => request_data.body&.length.to_s
|
114
|
+
}
|
104
115
|
end
|
105
116
|
|
106
117
|
# Safe Request execution
|
@@ -1,6 +1,4 @@
|
|
1
|
-
require 'genesis_ruby/errors/invalid_argument_error'
|
2
1
|
require 'genesis_ruby/utils/options/network_adapter_config'
|
3
|
-
require 'base64'
|
4
2
|
|
5
3
|
module GenesisRuby
|
6
4
|
module Network
|
@@ -75,18 +73,7 @@ module GenesisRuby
|
|
75
73
|
|
76
74
|
# Map the Request to the Network Adapter object
|
77
75
|
def adapter_data_mapper(request)
|
78
|
-
network_adapter_config.map_from_request(request).merge(
|
79
|
-
{
|
80
|
-
user_login: build_user_login,
|
81
|
-
user_agent: network_user_agent,
|
82
|
-
timeout: configuration.timeout
|
83
|
-
}
|
84
|
-
)
|
85
|
-
end
|
86
|
-
|
87
|
-
# Build the User login string used for the Authorization Header
|
88
|
-
def build_user_login
|
89
|
-
Base64.urlsafe_encode64("#{configuration.username}:#{configuration.password}")
|
76
|
+
network_adapter_config.map_from_request(request, configuration).merge({ user_agent: network_user_agent })
|
90
77
|
end
|
91
78
|
|
92
79
|
# The default user agent for every Network
|
@@ -13,6 +13,8 @@ module GenesisRuby
|
|
13
13
|
self.type = GenesisRuby::Api::Request::METHOD_POST
|
14
14
|
self.format = Builder::XML
|
15
15
|
self.parser_skip_root_node = true
|
16
|
+
self.authorization = GenesisRuby::Api::Request::AUTH_TYPE_BASIC
|
17
|
+
self.bearer_token = nil
|
16
18
|
end
|
17
19
|
|
18
20
|
# Load pre-defined JSON configuration
|
@@ -22,6 +24,8 @@ module GenesisRuby
|
|
22
24
|
self.type = GenesisRuby::Api::Request::METHOD_POST
|
23
25
|
self.format = Builder::JSON
|
24
26
|
self.parser_skip_root_node = false
|
27
|
+
self.authorization = GenesisRuby::Api::Request::AUTH_TYPE_BASIC
|
28
|
+
self.bearer_token = nil
|
25
29
|
end
|
26
30
|
|
27
31
|
# Load pre-defined FORM configuration
|
@@ -31,6 +35,8 @@ module GenesisRuby
|
|
31
35
|
self.type = GenesisRuby::Api::Request::METHOD_POST
|
32
36
|
self.format = Builder::FORM
|
33
37
|
self.parser_skip_root_node = true
|
38
|
+
self.authorization = GenesisRuby::Api::Request::AUTH_TYPE_BASIC
|
39
|
+
self.bearer_token = nil
|
34
40
|
end
|
35
41
|
|
36
42
|
# Load pre-defined GET configuration
|
@@ -40,6 +46,19 @@ module GenesisRuby
|
|
40
46
|
self.type = GenesisRuby::Api::Request::METHOD_GET
|
41
47
|
self.format = Builder::XML
|
42
48
|
self.parser_skip_root_node = false
|
49
|
+
self.authorization = GenesisRuby::Api::Request::AUTH_TYPE_BASIC
|
50
|
+
self.bearer_token = nil
|
51
|
+
end
|
52
|
+
|
53
|
+
# Load pre-defined GraphQL configuration
|
54
|
+
def load_graphql_config
|
55
|
+
self.protocol = GenesisRuby::Api::Request::PROTOCOL_HTTPS
|
56
|
+
self.port = GenesisRuby::Api::Request::PORT_HTTPS
|
57
|
+
self.type = GenesisRuby::Api::Request::METHOD_POST
|
58
|
+
self.format = Builder::GRAPHQL
|
59
|
+
self.parser_skip_root_node = false
|
60
|
+
self.authorization = GenesisRuby::Api::Request::AUTH_TYPE_TOKEN
|
61
|
+
self.bearer_token = nil
|
43
62
|
end
|
44
63
|
|
45
64
|
end
|
@@ -1,4 +1,6 @@
|
|
1
1
|
require 'genesis_ruby/utils/options/base'
|
2
|
+
require 'genesis_ruby/errors/invalid_argument_error'
|
3
|
+
require 'base64'
|
2
4
|
|
3
5
|
module GenesisRuby
|
4
6
|
module Utils
|
@@ -7,13 +9,17 @@ module GenesisRuby
|
|
7
9
|
class NetworkAdapterConfig < Base
|
8
10
|
|
9
11
|
# Map the Adapter configuration from the Request object
|
10
|
-
def map_from_request(request) # rubocop:disable Metrics/AbcSize
|
11
|
-
self.body
|
12
|
-
self.url
|
13
|
-
self.type
|
14
|
-
self.port
|
15
|
-
self.protocol
|
16
|
-
self.format
|
12
|
+
def map_from_request(request, configuration) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
|
13
|
+
self.body = request.build_document
|
14
|
+
self.url = request.api_config.url
|
15
|
+
self.type = request.api_config.type
|
16
|
+
self.port = request.api_config.port
|
17
|
+
self.protocol = request.api_config.protocol
|
18
|
+
self.format = fetch_content_type request.api_config.format
|
19
|
+
self.authorization = request.api_config.authorization
|
20
|
+
self.user_login = build_user_login request, configuration
|
21
|
+
self.setimeout = configuration.timeout
|
22
|
+
self.headers = build_additional_headers request
|
17
23
|
|
18
24
|
self
|
19
25
|
end
|
@@ -23,17 +29,46 @@ module GenesisRuby
|
|
23
29
|
# Retrieve the Request data format that must be used as Content-Type header
|
24
30
|
def fetch_content_type(data_format)
|
25
31
|
case data_format
|
26
|
-
when Builder::XML
|
27
|
-
|
28
|
-
when Builder::
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
+
when Builder::XML then 'text/xml'
|
33
|
+
when Builder::JSON then 'application/json'
|
34
|
+
when Builder::FORM then 'application/x-www-form-urlencoded'
|
35
|
+
when Builder::GRAPHQL then 'application/graphql'
|
36
|
+
else raise InvalidArgumentError, 'Invalid request format type. Allowed are XML, JSON and FORM'
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
# Build the User login string used for the Authorization Header
|
41
|
+
def build_user_login(request, configuration)
|
42
|
+
auth = request.api_config.authorization
|
43
|
+
kind = fetch_authorization_kind auth
|
44
|
+
|
45
|
+
return "#{kind} #{request.api_config.bearer_token}" if auth == Api::Request::AUTH_TYPE_TOKEN
|
46
|
+
|
47
|
+
"#{kind} #{Base64.urlsafe_encode64("#{configuration.username}:#{configuration.password}")}"
|
48
|
+
end
|
49
|
+
|
50
|
+
# Fetches the Request authorization kind
|
51
|
+
# TODO: Add AUTH_TYPE_NONE, should be used for METHOD CONTINUE request
|
52
|
+
def fetch_authorization_kind(auth)
|
53
|
+
case auth
|
54
|
+
when Api::Request::AUTH_TYPE_BASIC
|
55
|
+
'Basic'
|
56
|
+
when Api::Request::AUTH_TYPE_TOKEN
|
57
|
+
'Bearer'
|
32
58
|
else
|
33
|
-
raise InvalidArgumentError, 'Invalid
|
59
|
+
raise InvalidArgumentError, 'Invalid Authorization given in the Request. Allowed: BASIC, TOKEN'
|
34
60
|
end
|
35
61
|
end
|
36
62
|
|
63
|
+
# Build additional headers to be added based on the specific request format
|
64
|
+
def build_additional_headers(request)
|
65
|
+
headers = {}
|
66
|
+
|
67
|
+
headers.merge! 'Accept' => 'application/json' if request.api_config.format == Builder::GRAPHQL
|
68
|
+
|
69
|
+
headers
|
70
|
+
end
|
71
|
+
|
37
72
|
end
|
38
73
|
end
|
39
74
|
end
|
@@ -11,7 +11,7 @@ module GenesisRuby
|
|
11
11
|
# Return array containing all available Web Payment Form transaction types
|
12
12
|
def all # rubocop:disable Metrics/MethodLength
|
13
13
|
[
|
14
|
-
AFRICAN_MOBILE_PAYOUT, AFRICAN_MOBILE_SALE, APPLE_PAY, ARGENCARD, AURA, AUTHORIZE, AUTHORIZE_3D,
|
14
|
+
AFRICAN_MOBILE_PAYOUT, AFRICAN_MOBILE_SALE, ALIPAY, APPLE_PAY, ARGENCARD, AURA, AUTHORIZE, AUTHORIZE_3D,
|
15
15
|
BALOTO, BANCOMER, BANCONTACT, BANCO_DE_OCCIDENTE, BANCO_DO_BRASIL, BITPAY_PAYOUT, BITPAY_REFUND,
|
16
16
|
BITPAY_SALE, BOLETO, BRADESCO,
|
17
17
|
CABAL, CAPTURE, CASHU, CENCOSUD, CREDIT,
|