genesis_ruby 0.1.0 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (33) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +27 -0
  3. data/Gemfile.lock +24 -25
  4. data/README.md +401 -2
  5. data/VERSION +1 -1
  6. data/genesis_ruby.gemspec +7 -4
  7. data/lib/genesis_ruby/api/constants/date_time_formats.rb +1 -1
  8. data/lib/genesis_ruby/api/constants/transactions/parameters/refund/bank_account_types.rb +27 -0
  9. data/lib/genesis_ruby/api/notification.rb +156 -0
  10. data/lib/genesis_ruby/api/requests/base/financials/credit_card.rb +0 -2
  11. data/lib/genesis_ruby/api/requests/base/reference.rb +29 -0
  12. data/lib/genesis_ruby/api/requests/financial/capture.rb +30 -0
  13. data/lib/genesis_ruby/api/requests/financial/cards/threeds/v2/method_continue.rb +145 -0
  14. data/lib/genesis_ruby/api/requests/financial/refund.rb +48 -0
  15. data/lib/genesis_ruby/api/requests/financial/void.rb +28 -0
  16. data/lib/genesis_ruby/api/requests/non_financial/reconcile/date_range.rb +95 -0
  17. data/lib/genesis_ruby/api/requests/non_financial/reconcile/transaction.rb +37 -0
  18. data/lib/genesis_ruby/api/requests/wpf/reconcile.rb +33 -0
  19. data/lib/genesis_ruby/api/response.rb +6 -5
  20. data/lib/genesis_ruby/builder.rb +3 -2
  21. data/lib/genesis_ruby/builders/form.rb +44 -0
  22. data/lib/genesis_ruby/dependencies.rb +8 -0
  23. data/lib/genesis_ruby/network/adapter/base_adapter.rb +10 -0
  24. data/lib/genesis_ruby/network/adapter/net_http_adapter.rb +30 -8
  25. data/lib/genesis_ruby/network/base_network.rb +16 -0
  26. data/lib/genesis_ruby/network/net_http.rb +5 -0
  27. data/lib/genesis_ruby/utils/common.rb +8 -1
  28. data/lib/genesis_ruby/utils/options/api_config.rb +15 -12
  29. data/lib/genesis_ruby/utils/options/network_adapter_config.rb +3 -4
  30. data/lib/genesis_ruby/utils/threeds/v2.rb +21 -0
  31. data/lib/genesis_ruby/version.rb +1 -1
  32. data/lib/genesis_ruby.rb +5 -2
  33. metadata +20 -7
@@ -0,0 +1,44 @@
1
+ require 'genesis_ruby/builders/base'
2
+ require 'uri'
3
+
4
+ module GenesisRuby
5
+ module Builders
6
+ # XML, Nokogiri Builder Implementation
7
+ class Form < Base
8
+
9
+ # Initialize Nokogiri XML Builder
10
+ def initialize
11
+ @builder = URI
12
+ super
13
+ end
14
+
15
+ # Generated HTTP Query Document
16
+ def output
17
+ document
18
+ end
19
+
20
+ def populate_nodes(structure)
21
+ self.document = @builder.encode_www_form(transform_structure(structure))
22
+ end
23
+
24
+ private
25
+
26
+ attr_accessor :buffer, :document
27
+
28
+ # Transform structure from hash to array
29
+ # { key: 'value' } -> [[key, value]]
30
+ def transform_structure(structure)
31
+ self.buffer = []
32
+ structure.each { |key, value| add_buffer [key, value] }
33
+
34
+ buffer
35
+ end
36
+
37
+ # Fill up parameters
38
+ def add_buffer(value)
39
+ @buffer.push(value)
40
+ end
41
+
42
+ end
43
+ end
44
+ end
@@ -12,6 +12,14 @@ require 'genesis_ruby/api/mixins/requests/restricted_setter'
12
12
  # Load API Attributes
13
13
  Dir["#{File.dirname(__FILE__)}/api/mixins/**/*_attributes.rb"].sort.each { |file| require file }
14
14
 
15
+ # =================================
16
+ # Transaction Requests Bases
17
+ # =================================
18
+ require 'genesis_ruby/api/requests/base/financial'
19
+ require 'genesis_ruby/api/requests/base/financials/credit_card'
20
+ require 'genesis_ruby/api/requests/base/reference'
21
+ require 'genesis_ruby/api/notification'
22
+
15
23
  # Load Financial and Non Financial API Requests
16
24
  Dir["#{File.dirname(__FILE__)}/api/requests/*financial/**/*.rb"].sort.each { |file| require file }
17
25
 
@@ -25,6 +25,16 @@ module GenesisRuby
25
25
  raise NotImplementedError, 'Execute method must be implemented'
26
26
  end
27
27
 
28
+ # Whether the response is an error (HTTP Code != 200)
29
+ def error?
30
+ raise NotImplementedError, 'Error? method must be implemented'
31
+ end
32
+
33
+ # Response server message
34
+ def server_message
35
+ raise NotImplementedError, 'Server Message method must be implemented'
36
+ end
37
+
28
38
  end
29
39
  end
30
40
  end
@@ -25,14 +25,13 @@ module GenesisRuby
25
25
  def execute
26
26
  raise NetworkError, 'Request is not initialized' unless @request
27
27
 
28
- begin
29
- # TODO: Use GenesisRuby::Api::Request::METHOD_XXX constants for sending GET and PUT request_data.type
30
- @response = @request.post(path, request_data.body, headers)
31
- rescue StandardError => e
32
- raise NetworkError, "Network error raised by #{e.class.name}: #{e.message}"
33
- ensure
34
- # Close the request
35
- @request.finish
28
+ safe_execute do
29
+ case request_data.type
30
+ when Api::Request::METHOD_POST then @response = @request.post path, request_data.body, headers
31
+ when Api::Request::METHOD_PUT then @response = @request.put path, request_data.body, headers
32
+ else
33
+ raise 'Invalid Request Type!'
34
+ end
36
35
  end
37
36
  end
38
37
 
@@ -46,6 +45,19 @@ module GenesisRuby
46
45
  @response_headers ||= @response ? @response.each_header.to_h : {}
47
46
  end
48
47
 
48
+ # Whether the response is an error (HTTP Code != 200)
49
+ def error?
50
+ !@response.is_a? Net::HTTPSuccess
51
+ end
52
+
53
+ # Response server message
54
+ def server_message
55
+ message = status
56
+ message += " #{@response.message}" if @response.message
57
+
58
+ message
59
+ end
60
+
49
61
  private
50
62
 
51
63
  attr_reader :uri, :request, :response, :request_data
@@ -86,6 +98,16 @@ module GenesisRuby
86
98
  }
87
99
  end
88
100
 
101
+ # Safe Request execution
102
+ def safe_execute(&block)
103
+ block.call
104
+ rescue StandardError => e
105
+ raise NetworkError, "Network error raised by #{e.class.name}: #{e.message}"
106
+ ensure
107
+ # Close the request
108
+ @request.finish
109
+ end
110
+
89
111
  end
90
112
  end
91
113
  end
@@ -9,6 +9,7 @@ module GenesisRuby
9
9
 
10
10
  XML_HEADER = 'application/xml'.freeze
11
11
  JSON_HEADER = 'application/json'.freeze
12
+ HTML_HEADER = 'text/html'.freeze
12
13
 
13
14
  # Base constructor
14
15
  def initialize(configuration)
@@ -27,6 +28,16 @@ module GenesisRuby
27
28
  @context.response_headers
28
29
  end
29
30
 
31
+ # Whether returned response is an error response
32
+ def error?
33
+ @context.error?
34
+ end
35
+
36
+ # Returns the server message
37
+ def server_message
38
+ @context.server_message
39
+ end
40
+
30
41
  # Send the request
31
42
  def send_request
32
43
  @context.execute
@@ -47,6 +58,11 @@ module GenesisRuby
47
58
  raise NotImplementedError, 'Is JSON method must be implemented'
48
59
  end
49
60
 
61
+ # Every child defines is HTML Response Type
62
+ def html?
63
+ raise NotImplementedError, 'Is HTML method must be implemented'
64
+ end
65
+
50
66
  protected
51
67
 
52
68
  # GenesisRuby::Configuration, Adapter Context, Network Adapter Config mapper
@@ -16,6 +16,11 @@ module GenesisRuby
16
16
  response_headers['content-type'].downcase.include?(BaseNetwork::JSON_HEADER)
17
17
  end
18
18
 
19
+ # HTML Response Type
20
+ def html?
21
+ response_headers['content-type'].downcase.include?(BaseNetwork::HTML_HEADER)
22
+ end
23
+
19
24
  protected
20
25
 
21
26
  # Adapter Initialization
@@ -93,7 +93,7 @@ module GenesisRuby
93
93
  parsed_date = nil
94
94
 
95
95
  formats.each do |format|
96
- return Date.strptime(date, format)
96
+ return DateTime.strptime(date, format)
97
97
  rescue StandardError
98
98
  parsed_date = nil
99
99
  end
@@ -101,6 +101,13 @@ module GenesisRuby
101
101
  parsed_date
102
102
  end
103
103
 
104
+ # Check if the given string contain time
105
+ def date_has_time?(value)
106
+ return true if value =~ /(?:\d|[01]\d|2[0-3]):[0-5]\d:[0-5]\d/
107
+
108
+ false
109
+ end
110
+
104
111
  end
105
112
 
106
113
  end
@@ -8,26 +8,29 @@ module GenesisRuby
8
8
 
9
9
  # Load pre-defined XML configuration
10
10
  def load_xml_config
11
- self.protocol = GenesisRuby::Api::Request::PROTOCOL_HTTPS
12
- self.port = GenesisRuby::Api::Request::PORT_HTTPS
13
- self.type = GenesisRuby::Api::Request::METHOD_POST
14
- self.format = 'xml' # TODO: use the builder constant
11
+ self.protocol = GenesisRuby::Api::Request::PROTOCOL_HTTPS
12
+ self.port = GenesisRuby::Api::Request::PORT_HTTPS
13
+ self.type = GenesisRuby::Api::Request::METHOD_POST
14
+ self.format = Builder::XML
15
+ self.parser_skip_root_node = true
15
16
  end
16
17
 
17
18
  # Load pre-defined JSON configuration
18
19
  def load_json_config
19
- self.protocol = GenesisRuby::Api::Request::PROTOCOL_HTTPS
20
- self.port = GenesisRuby::Api::Request::PORT_HTTPS
21
- self.type = GenesisRuby::Api::Request::METHOD_POST
22
- self.format = 'json' # TODO: use the builder constant
20
+ self.protocol = GenesisRuby::Api::Request::PROTOCOL_HTTPS
21
+ self.port = GenesisRuby::Api::Request::PORT_HTTPS
22
+ self.type = GenesisRuby::Api::Request::METHOD_POST
23
+ self.format = Builder::JSON
24
+ self.parser_skip_root_node = false
23
25
  end
24
26
 
25
27
  # Load pre-defined FORM configuration
26
28
  def load_form_config
27
- self.protocol = GenesisRuby::Api::Request::PROTOCOL_HTTPS
28
- self.port = GenesisRuby::Api::Request::PORT_HTTPS
29
- self.type = GenesisRuby::Api::Request::METHOD_POST
30
- self.format = 'form' # TODO: use the builder constant
29
+ self.protocol = GenesisRuby::Api::Request::PROTOCOL_HTTPS
30
+ self.port = GenesisRuby::Api::Request::PORT_HTTPS
31
+ self.type = GenesisRuby::Api::Request::METHOD_POST
32
+ self.format = Builder::FORM
33
+ self.parser_skip_root_node = true
31
34
  end
32
35
 
33
36
  end
@@ -22,13 +22,12 @@ module GenesisRuby
22
22
 
23
23
  # Retrieve the Request data format that must be used as Content-Type header
24
24
  def fetch_content_type(data_format)
25
- # TODO: Builder Constants
26
25
  case data_format
27
- when 'xml'
26
+ when Builder::XML
28
27
  'text/xml'
29
- when 'json'
28
+ when Builder::JSON
30
29
  'application/json'
31
- when 'form'
30
+ when Builder::FORM
32
31
  'application/x-www-form-urlencoded'
33
32
  else
34
33
  raise InvalidArgumentError, 'Invalid request format type. Allowed are XML, JSON and FORM'
@@ -0,0 +1,21 @@
1
+ require 'digest'
2
+
3
+ module GenesisRuby
4
+ module Utils
5
+ module Threeds
6
+ # Threeds V2 Utils
7
+ class V2
8
+
9
+ class << self
10
+
11
+ # Generate 3DSV2 signature
12
+ def generate_signature(unique_id:, amount:, timestamp:, merchant_password:)
13
+ Digest::SHA512.hexdigest "#{unique_id}#{amount}#{timestamp}#{merchant_password}"
14
+ end
15
+
16
+ end
17
+
18
+ end
19
+ end
20
+ end
21
+ end
@@ -1,5 +1,5 @@
1
1
  module GenesisRuby
2
2
 
3
- VERSION = '0.1.0'.freeze
3
+ VERSION = '0.1.2'.freeze
4
4
 
5
5
  end
data/lib/genesis_ruby.rb CHANGED
@@ -12,7 +12,7 @@ module GenesisRuby
12
12
 
13
13
  # Transaction Request Initializer
14
14
  def self.for(config:, request:)
15
- unless request.is_a?(Class) || request < GenesisRuby::Api::Request
15
+ unless request.is_a?(Class) && request < GenesisRuby::Api::Request
16
16
  raise InvalidArgumentError, 'Given Request is invalid'
17
17
  end
18
18
 
@@ -31,7 +31,10 @@ module GenesisRuby
31
31
  def initialize(configuration, request = nil)
32
32
  @configuration = configuration
33
33
  @request = request
34
- @response = GenesisRuby::Api::Response.new(configuration)
34
+ @response = GenesisRuby::Api::Response.new(
35
+ configuration,
36
+ request&.api_config || GenesisRuby::Utils::Options::ApiConfig.new
37
+ )
35
38
  @network = GenesisRuby::Connection.for(configuration)
36
39
  end
37
40
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: genesis_ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - emerchantpay Ltd.
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-09-15 00:00:00.000000000 Z
11
+ date: 2023-11-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: net-http
@@ -42,16 +42,16 @@ dependencies:
42
42
  name: bundler
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ">="
45
+ - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '0'
47
+ version: '2.1'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ">="
52
+ - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '0'
54
+ version: '2.1'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: faker
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -232,6 +232,7 @@ files:
232
232
  - lib/genesis_ruby/api/constants/transactions/parameters/business/payment_types.rb
233
233
  - lib/genesis_ruby/api/constants/transactions/parameters/recurring/categories.rb
234
234
  - lib/genesis_ruby/api/constants/transactions/parameters/recurring/types.rb
235
+ - lib/genesis_ruby/api/constants/transactions/parameters/refund/bank_account_types.rb
235
236
  - lib/genesis_ruby/api/constants/transactions/parameters/sca_exemptions.rb
236
237
  - lib/genesis_ruby/api/constants/transactions/parameters/threeds/version2/browser/color_depths.rb
237
238
  - lib/genesis_ruby/api/constants/transactions/parameters/threeds/version2/card_holder_account/password_change_indicators.rb
@@ -291,17 +292,27 @@ files:
291
292
  - lib/genesis_ruby/api/mixins/requests/financial/threeds/version2/sdk.rb
292
293
  - lib/genesis_ruby/api/mixins/requests/financial/threeds/version2/wpf_attributes.rb
293
294
  - lib/genesis_ruby/api/mixins/requests/restricted_setter.rb
295
+ - lib/genesis_ruby/api/notification.rb
294
296
  - lib/genesis_ruby/api/request.rb
295
297
  - lib/genesis_ruby/api/requests/base/financial.rb
296
298
  - lib/genesis_ruby/api/requests/base/financials/credit_card.rb
299
+ - lib/genesis_ruby/api/requests/base/reference.rb
300
+ - lib/genesis_ruby/api/requests/financial/capture.rb
297
301
  - lib/genesis_ruby/api/requests/financial/cards/authorize.rb
298
302
  - lib/genesis_ruby/api/requests/financial/cards/authorize3d.rb
299
303
  - lib/genesis_ruby/api/requests/financial/cards/sale.rb
300
304
  - lib/genesis_ruby/api/requests/financial/cards/sale3d.rb
305
+ - lib/genesis_ruby/api/requests/financial/cards/threeds/v2/method_continue.rb
306
+ - lib/genesis_ruby/api/requests/financial/refund.rb
307
+ - lib/genesis_ruby/api/requests/financial/void.rb
308
+ - lib/genesis_ruby/api/requests/non_financial/reconcile/date_range.rb
309
+ - lib/genesis_ruby/api/requests/non_financial/reconcile/transaction.rb
301
310
  - lib/genesis_ruby/api/requests/wpf/create.rb
311
+ - lib/genesis_ruby/api/requests/wpf/reconcile.rb
302
312
  - lib/genesis_ruby/api/response.rb
303
313
  - lib/genesis_ruby/builder.rb
304
314
  - lib/genesis_ruby/builders/base.rb
315
+ - lib/genesis_ruby/builders/form.rb
305
316
  - lib/genesis_ruby/builders/xml.rb
306
317
  - lib/genesis_ruby/configuration.rb
307
318
  - lib/genesis_ruby/connection.rb
@@ -337,6 +348,7 @@ files:
337
348
  - lib/genesis_ruby/utils/options/api_config.rb
338
349
  - lib/genesis_ruby/utils/options/base.rb
339
350
  - lib/genesis_ruby/utils/options/network_adapter_config.rb
351
+ - lib/genesis_ruby/utils/threeds/v2.rb
340
352
  - lib/genesis_ruby/utils/transactions/financial_types.rb
341
353
  - lib/genesis_ruby/utils/transactions/references/capturable_types.rb
342
354
  - lib/genesis_ruby/utils/transactions/references/refundable_types.rb
@@ -349,7 +361,8 @@ licenses:
349
361
  metadata:
350
362
  homepage_uri: https://github.com/GenesisGateway/genesis_ruby
351
363
  source_code_uri: https://github.com/GenesisGateway/genesis_ruby
352
- changelog_uri: https://github.com/GenesisGateway/genesis_ruby/CHANGELOG.md
364
+ changelog_uri: https://github.com/GenesisGateway/genesis_ruby/blob/main/CHANGELOG.md
365
+ documentation_uri: https://github.com/GenesisGateway/genesis_ruby/blob/main/README.md
353
366
  post_install_message:
354
367
  rdoc_options: []
355
368
  require_paths: