genesis_ruby 0.2.2 → 0.2.4

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.
Files changed (98) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +57 -0
  3. data/Gemfile.lock +50 -41
  4. data/README.md +56 -0
  5. data/VERSION +1 -1
  6. data/lib/genesis_ruby/api/constants/transactions/parameters/non_financial/billing_api/order_by_fields.rb +33 -0
  7. data/lib/genesis_ruby/api/constants/transactions/parameters/non_financial/billing_api/response_fields.rb +67 -0
  8. data/lib/genesis_ruby/api/constants/transactions/parameters/non_financial/billing_api/transaction_types.rb +48 -0
  9. data/lib/genesis_ruby/api/constants/transactions/parameters/non_financial/externally_processed.rb +22 -0
  10. data/lib/genesis_ruby/api/constants/transactions/parameters/non_financial/processing_type.rb +22 -0
  11. data/lib/genesis_ruby/api/constants/transactions/parameters/non_financial/sca_exemptions.rb +25 -0
  12. data/lib/genesis_ruby/api/constants/transactions/parameters/non_financial/sort_directions.rb +24 -0
  13. data/lib/genesis_ruby/api/constants/transactions/parameters/online_banking/iframe_targets.rb +26 -0
  14. data/lib/genesis_ruby/api/constants/transactions/parameters/online_banking/payment_types.rb +3 -0
  15. data/lib/genesis_ruby/api/constants/transactions.rb +5 -0
  16. data/lib/genesis_ruby/api/mixins/requests/financial/bank_attributes.rb +26 -0
  17. data/lib/genesis_ruby/api/mixins/requests/financial/beneficiary_attributes.rb +38 -0
  18. data/lib/genesis_ruby/api/mixins/requests/financial/customer_account_attributes.rb +21 -0
  19. data/lib/genesis_ruby/api/mixins/requests/financial/online_banking_payments/payer_attributes.rb +65 -0
  20. data/lib/genesis_ruby/api/mixins/requests/non_financial/billing_api/sort_attributes.rb +18 -0
  21. data/lib/genesis_ruby/api/mixins/requests/non_financial/date_attributes.rb +64 -0
  22. data/lib/genesis_ruby/api/mixins/requests/non_financial/mode_attributes.rb +24 -0
  23. data/lib/genesis_ruby/api/mixins/requests/non_financial/paging_attributes.rb +33 -0
  24. data/lib/genesis_ruby/api/mixins/requests/non_financial/tokenization/card_data_attributes.rb +62 -0
  25. data/lib/genesis_ruby/api/mixins/requests/non_financial/tokenization/token_attributes.rb +23 -0
  26. data/lib/genesis_ruby/api/mixins/requests/non_financial/tokenization/tokenization_attributes.rb +51 -0
  27. data/lib/genesis_ruby/api/mixins/requests/restricted_setter.rb +18 -0
  28. data/lib/genesis_ruby/api/request.rb +15 -0
  29. data/lib/genesis_ruby/api/requests/base/consumer.rb +24 -0
  30. data/lib/genesis_ruby/api/requests/base/financial.rb +10 -1
  31. data/lib/genesis_ruby/api/requests/base/financials/credit_card.rb +5 -7
  32. data/lib/genesis_ruby/api/requests/base/financials/south_american_payments.rb +11 -14
  33. data/lib/genesis_ruby/api/requests/base/graphql.rb +60 -0
  34. data/lib/genesis_ruby/api/requests/base/reference.rb +2 -1
  35. data/lib/genesis_ruby/api/requests/financial/cards/bancontact.rb +8 -9
  36. data/lib/genesis_ruby/api/requests/financial/cash_payments/cash.rb +13 -14
  37. data/lib/genesis_ruby/api/requests/financial/cash_payments/pix.rb +23 -25
  38. data/lib/genesis_ruby/api/requests/financial/mobile/apple_pay.rb +18 -20
  39. data/lib/genesis_ruby/api/requests/financial/mobile/google_pay.rb +20 -24
  40. data/lib/genesis_ruby/api/requests/financial/online_banking_payments/banco_do_brasil.rb +57 -0
  41. data/lib/genesis_ruby/api/requests/financial/online_banking_payments/eps.rb +46 -0
  42. data/lib/genesis_ruby/api/requests/financial/online_banking_payments/idebit/pay_in.rb +48 -0
  43. data/lib/genesis_ruby/api/requests/financial/online_banking_payments/idebit/pay_out.rb +28 -0
  44. data/lib/genesis_ruby/api/requests/financial/online_banking_payments/insta_debit/pay_in.rb +61 -0
  45. data/lib/genesis_ruby/api/requests/financial/online_banking_payments/insta_debit/pay_out.rb +24 -0
  46. data/lib/genesis_ruby/api/requests/financial/online_banking_payments/multibanco.rb +48 -0
  47. data/lib/genesis_ruby/api/requests/financial/online_banking_payments/my_bank.rb +47 -0
  48. data/lib/genesis_ruby/api/requests/financial/online_banking_payments/online_banking/pay_in.rb +17 -18
  49. data/lib/genesis_ruby/api/requests/financial/online_banking_payments/online_banking/pay_out.rb +33 -38
  50. data/lib/genesis_ruby/api/requests/financial/online_banking_payments/pay_u.rb +61 -0
  51. data/lib/genesis_ruby/api/requests/financial/online_banking_payments/post_finance.rb +53 -0
  52. data/lib/genesis_ruby/api/requests/financial/online_banking_payments/safety_pay.rb +57 -0
  53. data/lib/genesis_ruby/api/requests/financial/online_banking_payments/sofort.rb +63 -0
  54. data/lib/genesis_ruby/api/requests/financial/online_banking_payments/trustly_sale.rb +75 -0
  55. data/lib/genesis_ruby/api/requests/financial/online_banking_payments/upi.rb +54 -0
  56. data/lib/genesis_ruby/api/requests/financial/online_banking_payments/wechat.rb +50 -0
  57. data/lib/genesis_ruby/api/requests/financial/sdd/recurring/init_recurring_sale.rb +23 -0
  58. data/lib/genesis_ruby/api/requests/financial/sdd/recurring/recurring_sale.rb +28 -0
  59. data/lib/genesis_ruby/api/requests/financial/sdd/refund.rb +26 -0
  60. data/lib/genesis_ruby/api/requests/financial/sdd/sale.rb +57 -0
  61. data/lib/genesis_ruby/api/requests/financial/void.rb +12 -5
  62. data/lib/genesis_ruby/api/requests/financial/wallets/alipay.rb +46 -0
  63. data/lib/genesis_ruby/api/requests/financial/wallets/{pay_pay.rb → pay_pal.rb} +18 -20
  64. data/lib/genesis_ruby/api/requests/non_financial/billing_api/transactions.rb +203 -0
  65. data/lib/genesis_ruby/api/requests/non_financial/consumers/create.rb +44 -0
  66. data/lib/genesis_ruby/api/requests/non_financial/consumers/disable.rb +40 -0
  67. data/lib/genesis_ruby/api/requests/non_financial/consumers/enable.rb +40 -0
  68. data/lib/genesis_ruby/api/requests/non_financial/consumers/get_cards.rb +40 -0
  69. data/lib/genesis_ruby/api/requests/non_financial/consumers/retrieve.rb +40 -0
  70. data/lib/genesis_ruby/api/requests/non_financial/consumers/update.rb +45 -0
  71. data/lib/genesis_ruby/api/requests/non_financial/fraud/retrieval/date_range.rb +81 -0
  72. data/lib/genesis_ruby/api/requests/non_financial/fraud/retrieval/transaction.rb +52 -0
  73. data/lib/genesis_ruby/api/requests/non_financial/processed_transactions/date_range.rb +68 -0
  74. data/lib/genesis_ruby/api/requests/non_financial/processed_transactions/post_date_range.rb +72 -0
  75. data/lib/genesis_ruby/api/requests/non_financial/processed_transactions/transaction.rb +48 -0
  76. data/lib/genesis_ruby/api/requests/non_financial/reconcile/date_range.rb +2 -50
  77. data/lib/genesis_ruby/api/requests/non_financial/sca/checker.rb +77 -0
  78. data/lib/genesis_ruby/api/requests/non_financial/tokenization/cryptogram.rb +43 -0
  79. data/lib/genesis_ruby/api/requests/non_financial/tokenization/delete_token.rb +43 -0
  80. data/lib/genesis_ruby/api/requests/non_financial/tokenization/detokenize.rb +43 -0
  81. data/lib/genesis_ruby/api/requests/non_financial/tokenization/get_card.rb +43 -0
  82. data/lib/genesis_ruby/api/requests/non_financial/tokenization/tokenize.rb +45 -0
  83. data/lib/genesis_ruby/api/requests/non_financial/tokenization/update_token.rb +45 -0
  84. data/lib/genesis_ruby/api/requests/non_financial/tokenization/validate_token.rb +43 -0
  85. data/lib/genesis_ruby/builder.rb +5 -0
  86. data/lib/genesis_ruby/builders/graphql.rb +118 -0
  87. data/lib/genesis_ruby/configuration.rb +11 -2
  88. data/lib/genesis_ruby/dependencies.rb +3 -0
  89. data/lib/genesis_ruby/network/adapter/net_http_adapter.rb +20 -9
  90. data/lib/genesis_ruby/network/base_network.rb +1 -14
  91. data/lib/genesis_ruby/utils/formatters/response/formats/timestamp.rb +1 -1
  92. data/lib/genesis_ruby/utils/options/api_config.rb +19 -0
  93. data/lib/genesis_ruby/utils/options/network_adapter_config.rb +49 -14
  94. data/lib/genesis_ruby/utils/transactions/financial_types.rb +1 -1
  95. data/lib/genesis_ruby/utils/transactions/references/refundable_types.rb +1 -1
  96. data/lib/genesis_ruby/utils/transactions/wpf_types.rb +1 -1
  97. data/lib/genesis_ruby/version.rb +1 -1
  98. metadata +66 -4
@@ -0,0 +1,45 @@
1
+ module GenesisRuby
2
+ module Api
3
+ module Requests
4
+ module NonFinancial
5
+ module Tokenization
6
+ # Tokenizes cardholder data and issues a corresponding token. Merchants should take
7
+ # care to save the plain-text token value in their system as once issued it is not possible
8
+ # to obtain it again.
9
+ class Tokenize < Base::Versioned
10
+
11
+ include Api::Mixins::Requests::NonFinancial::Tokenization::CardDataAttributes
12
+ include Api::Mixins::Requests::NonFinancial::Tokenization::TokenizationAttributes
13
+
14
+ def initialize(configuration, builder_interface = Builder::XML)
15
+ super configuration, builder_interface
16
+
17
+ self.request_path = 'tokenize'
18
+ end
19
+
20
+ protected
21
+
22
+ # Tokenize field validations
23
+ def init_field_validations
24
+ super
25
+
26
+ required_fields.push *tokenization_required_fields, *%i[card_number]
27
+ end
28
+
29
+ # API Request structure
30
+ def request_structure
31
+ {
32
+ tokenize_request: tokenization_attributes_structure.merge(
33
+ {
34
+ card_data: card_data_attributes_structure
35
+ }
36
+ )
37
+ }
38
+ end
39
+
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,45 @@
1
+ module GenesisRuby
2
+ module Api
3
+ module Requests
4
+ module NonFinancial
5
+ module Tokenization
6
+ # Updates the tokenized data corresponding to an existing valid token
7
+ class UpdateToken < Base::Versioned
8
+
9
+ include Api::Mixins::Requests::NonFinancial::Tokenization::CardDataAttributes
10
+ include Api::Mixins::Requests::NonFinancial::Tokenization::TokenAttributes
11
+ include Api::Mixins::Requests::NonFinancial::Tokenization::TokenizationAttributes
12
+
13
+ def initialize(configuration, builder_interface = Builder::XML)
14
+ super configuration, builder_interface
15
+
16
+ self.request_path = 'update_token'
17
+ end
18
+
19
+ protected
20
+
21
+ # Update Token field validations
22
+ def init_field_validations
23
+ super
24
+
25
+ required_fields.push *tokenization_required_fields, *%i[card_number token]
26
+ end
27
+
28
+ # API Request structure
29
+ def request_structure
30
+ {
31
+ update_token_request: tokenization_attributes_structure.merge(
32
+ {
33
+ token: token,
34
+ card_data: card_data_attributes_structure
35
+ }
36
+ )
37
+ }
38
+ end
39
+
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,43 @@
1
+ module GenesisRuby
2
+ module Api
3
+ module Requests
4
+ module NonFinancial
5
+ module Tokenization
6
+ # Validates if a token is active, owned by a merchant, etc.
7
+ class ValidateToken < Base::Versioned
8
+
9
+ include Api::Mixins::Requests::NonFinancial::Tokenization::TokenAttributes
10
+ include Api::Mixins::Requests::NonFinancial::Tokenization::TokenizationAttributes
11
+
12
+ def initialize(configuration, builder_interface = Builder::XML)
13
+ super configuration, builder_interface
14
+
15
+ self.request_path = 'validate_token'
16
+ end
17
+
18
+ protected
19
+
20
+ # Validate Token field validations
21
+ def init_field_validations
22
+ super
23
+
24
+ required_fields.push *tokenization_required_fields, *%i[token]
25
+ end
26
+
27
+ # API Request structure
28
+ def request_structure
29
+ {
30
+ validate_token_request: tokenization_attributes_structure.merge(
31
+ {
32
+ token: token
33
+ }
34
+ )
35
+ }
36
+ end
37
+
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
@@ -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,9 @@ 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/base/consumer'
25
+ require 'genesis_ruby/api/requests/financial/sdd/sale'
26
+ require 'genesis_ruby/api/requests/base/graphql'
24
27
  require 'genesis_ruby/api/notification'
25
28
 
26
29
  # Load Financial and Non Financial API Requests
@@ -90,17 +90,28 @@ module GenesisRuby
90
90
 
91
91
  # Define Headers
92
92
  def headers
93
- headers = {
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
- headers.merge! 'Content-Type' => request_data.format,
100
- 'Content-Length' => request_data.body&.length.to_s
101
- end
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
- headers
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
@@ -11,7 +11,7 @@ module GenesisRuby
11
11
 
12
12
  # The Response keys that the formatter will be applied to
13
13
  def formatting_keys
14
- %w(timestamp)
14
+ %w(timestamp transactionDate valueDate transaction_date post_date)
15
15
  end
16
16
 
17
17
  # Format the given timestamp to DateTime object
@@ -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 = request.build_document
12
- self.url = request.api_config.url
13
- self.type = request.api_config.type
14
- self.port = request.api_config.port
15
- self.protocol = request.api_config.protocol
16
- self.format = fetch_content_type(request.api_config.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
- 'text/xml'
28
- when Builder::JSON
29
- 'application/json'
30
- when Builder::FORM
31
- 'application/x-www-form-urlencoded'
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 request format type. Allowed are XML, JSON and FORM'
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,
@@ -12,7 +12,7 @@ module GenesisRuby
12
12
  # Array containing all available Refundable Types
13
13
  def all # rubocop:disable Metrics/MethodLength
14
14
  [
15
- AFRICAN_MOBILE_PAYOUT, AFRICAN_MOBILE_SALE, APPLE_PAY,
15
+ AFRICAN_MOBILE_PAYOUT, AFRICAN_MOBILE_SALE, ALIPAY, APPLE_PAY,
16
16
  BALOTO, BANCOMER, BANCONTACT, BANCO_DE_OCCIDENTE, BANCO_DO_BRASIL, BITPAY_SALE, BOLETO, BRADESCO,
17
17
  CAPTURE, CASHU,
18
18
  DAVIVIENDA,
@@ -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
- ACCOUNT_VERIFICATION, ARGENCARD, APPLE_PAY, AURA, AUTHORIZE, AUTHORIZE_3D,
14
+ ACCOUNT_VERIFICATION, ALIPAY, ARGENCARD, APPLE_PAY, AURA, AUTHORIZE, AUTHORIZE_3D,
15
15
  BALOTO, BANCOMER, BANCONTACT, BANCO_DE_OCCIDENTE, BANCO_DO_BRASIL, BITPAY_PAYOUT, BITPAY_SALE, BOLETO,
16
16
  BRADESCO,
17
17
  CABAL, CASHU, CENCOSUD, DAVIVIENDA,
@@ -1,5 +1,5 @@
1
1
  module GenesisRuby
2
2
 
3
- VERSION = '0.2.2'.freeze
3
+ VERSION = '0.2.4'.freeze
4
4
 
5
5
  end