genesis_ruby 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (132) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +11 -0
  3. data/Gemfile +6 -0
  4. data/Gemfile.lock +158 -0
  5. data/LICENSE +21 -0
  6. data/README.md +343 -0
  7. data/Rakefile +12 -0
  8. data/VERSION +1 -0
  9. data/genesis_ruby.gemspec +43 -0
  10. data/lib/genesis_ruby/api/constants/currencies/iso4217.rb +1106 -0
  11. data/lib/genesis_ruby/api/constants/date_time_formats.rb +45 -0
  12. data/lib/genesis_ruby/api/constants/endpoints.rb +18 -0
  13. data/lib/genesis_ruby/api/constants/environments.rb +17 -0
  14. data/lib/genesis_ruby/api/constants/states/state.rb +43 -0
  15. data/lib/genesis_ruby/api/constants/states.rb +86 -0
  16. data/lib/genesis_ruby/api/constants/transactions/parameters/business/payment_types.rb +24 -0
  17. data/lib/genesis_ruby/api/constants/transactions/parameters/recurring/categories.rb +24 -0
  18. data/lib/genesis_ruby/api/constants/transactions/parameters/recurring/types.rb +28 -0
  19. data/lib/genesis_ruby/api/constants/transactions/parameters/sca_exemptions.rb +34 -0
  20. data/lib/genesis_ruby/api/constants/transactions/parameters/threeds/version2/browser/color_depths.rb +46 -0
  21. data/lib/genesis_ruby/api/constants/transactions/parameters/threeds/version2/card_holder_account/password_change_indicators.rb +37 -0
  22. data/lib/genesis_ruby/api/constants/transactions/parameters/threeds/version2/card_holder_account/registration_indicators.rb +37 -0
  23. data/lib/genesis_ruby/api/constants/transactions/parameters/threeds/version2/card_holder_account/shipping_address_usage_indicators.rb +34 -0
  24. data/lib/genesis_ruby/api/constants/transactions/parameters/threeds/version2/card_holder_account/suspicious_activity_indicators.rb +28 -0
  25. data/lib/genesis_ruby/api/constants/transactions/parameters/threeds/version2/card_holder_account/update_indicators.rb +34 -0
  26. data/lib/genesis_ruby/api/constants/transactions/parameters/threeds/version2/control/challenge_indicators.rb +34 -0
  27. data/lib/genesis_ruby/api/constants/transactions/parameters/threeds/version2/control/challenge_window_sizes.rb +37 -0
  28. data/lib/genesis_ruby/api/constants/transactions/parameters/threeds/version2/control/device_types.rb +28 -0
  29. data/lib/genesis_ruby/api/constants/transactions/parameters/threeds/version2/merchant_risk/delivery_timeframes.rb +34 -0
  30. data/lib/genesis_ruby/api/constants/transactions/parameters/threeds/version2/merchant_risk/pre_order_purchase_indicators.rb +28 -0
  31. data/lib/genesis_ruby/api/constants/transactions/parameters/threeds/version2/merchant_risk/reorder_item_indicators.rb +28 -0
  32. data/lib/genesis_ruby/api/constants/transactions/parameters/threeds/version2/merchant_risk/shipping_indicators.rb +46 -0
  33. data/lib/genesis_ruby/api/constants/transactions/parameters/threeds/version2/purchase/categories.rb +43 -0
  34. data/lib/genesis_ruby/api/constants/transactions/parameters/threeds/version2/sdk/interfaces.rb +31 -0
  35. data/lib/genesis_ruby/api/constants/transactions/parameters/threeds/version2/sdk/ui_types.rb +37 -0
  36. data/lib/genesis_ruby/api/constants/transactions.rb +371 -0
  37. data/lib/genesis_ruby/api/mixins/constants/common.rb +27 -0
  38. data/lib/genesis_ruby/api/mixins/requests/address_info_attributes.rb +20 -0
  39. data/lib/genesis_ruby/api/mixins/requests/customer_address/billing_info_attributes.rb +33 -0
  40. data/lib/genesis_ruby/api/mixins/requests/customer_address/customer_info_attributes.rb +26 -0
  41. data/lib/genesis_ruby/api/mixins/requests/customer_address/shipping_info_attributes.rb +33 -0
  42. data/lib/genesis_ruby/api/mixins/requests/document_attributes.rb +14 -0
  43. data/lib/genesis_ruby/api/mixins/requests/financial/async_attributes.rb +34 -0
  44. data/lib/genesis_ruby/api/mixins/requests/financial/base_attributes.rb +16 -0
  45. data/lib/genesis_ruby/api/mixins/requests/financial/business/airlines_air_carriers_attributes.rb +60 -0
  46. data/lib/genesis_ruby/api/mixins/requests/financial/business/business_attributes.rb +56 -0
  47. data/lib/genesis_ruby/api/mixins/requests/financial/business/car_plane_and_boat_rentals_attributes.rb +53 -0
  48. data/lib/genesis_ruby/api/mixins/requests/financial/business/cruise_lines_attributes.rb +50 -0
  49. data/lib/genesis_ruby/api/mixins/requests/financial/business/event_management_attributes.rb +54 -0
  50. data/lib/genesis_ruby/api/mixins/requests/financial/business/furniture_attributes.rb +53 -0
  51. data/lib/genesis_ruby/api/mixins/requests/financial/business/hotels_and_real_estate_rentals_attributes.rb +53 -0
  52. data/lib/genesis_ruby/api/mixins/requests/financial/business/travel_agencies_attributes.rb +88 -0
  53. data/lib/genesis_ruby/api/mixins/requests/financial/cards/credit_card_attributes.rb +31 -0
  54. data/lib/genesis_ruby/api/mixins/requests/financial/cards/fx_rate_attributes.rb +18 -0
  55. data/lib/genesis_ruby/api/mixins/requests/financial/cards/recurring/recurring_category_attributes.rb +31 -0
  56. data/lib/genesis_ruby/api/mixins/requests/financial/cards/recurring/recurring_type_attributes.rb +31 -0
  57. data/lib/genesis_ruby/api/mixins/requests/financial/cards/tokenization_attributes.rb +39 -0
  58. data/lib/genesis_ruby/api/mixins/requests/financial/crypto_attributes.rb +25 -0
  59. data/lib/genesis_ruby/api/mixins/requests/financial/dynamic_descriptor_attributes.rb +114 -0
  60. data/lib/genesis_ruby/api/mixins/requests/financial/gaming_attributes.rb +25 -0
  61. data/lib/genesis_ruby/api/mixins/requests/financial/moto_attributes.rb +25 -0
  62. data/lib/genesis_ruby/api/mixins/requests/financial/notification_attributes.rb +25 -0
  63. data/lib/genesis_ruby/api/mixins/requests/financial/payment_attributes.rb +32 -0
  64. data/lib/genesis_ruby/api/mixins/requests/financial/pending_payment_attributes.rb +25 -0
  65. data/lib/genesis_ruby/api/mixins/requests/financial/reference_attributes.rb +16 -0
  66. data/lib/genesis_ruby/api/mixins/requests/financial/risk_attributes.rb +47 -0
  67. data/lib/genesis_ruby/api/mixins/requests/financial/sca_attributes.rb +37 -0
  68. data/lib/genesis_ruby/api/mixins/requests/financial/threeds/version2/browser.rb +92 -0
  69. data/lib/genesis_ruby/api/mixins/requests/financial/threeds/version2/card_holder_account.rb +183 -0
  70. data/lib/genesis_ruby/api/mixins/requests/financial/threeds/version2/common_attributes.rb +52 -0
  71. data/lib/genesis_ruby/api/mixins/requests/financial/threeds/version2/control.rb +61 -0
  72. data/lib/genesis_ruby/api/mixins/requests/financial/threeds/version2/merchant_risk.rb +114 -0
  73. data/lib/genesis_ruby/api/mixins/requests/financial/threeds/version2/method.rb +44 -0
  74. data/lib/genesis_ruby/api/mixins/requests/financial/threeds/version2/purchase.rb +42 -0
  75. data/lib/genesis_ruby/api/mixins/requests/financial/threeds/version2/recurring.rb +49 -0
  76. data/lib/genesis_ruby/api/mixins/requests/financial/threeds/version2/sdk.rb +107 -0
  77. data/lib/genesis_ruby/api/mixins/requests/financial/threeds/version2/wpf_attributes.rb +61 -0
  78. data/lib/genesis_ruby/api/mixins/requests/restricted_setter.rb +75 -0
  79. data/lib/genesis_ruby/api/request.rb +171 -0
  80. data/lib/genesis_ruby/api/requests/base/financial.rb +44 -0
  81. data/lib/genesis_ruby/api/requests/base/financials/credit_card.rb +27 -0
  82. data/lib/genesis_ruby/api/requests/financial/cards/authorize.rb +60 -0
  83. data/lib/genesis_ruby/api/requests/financial/cards/authorize3d.rb +76 -0
  84. data/lib/genesis_ruby/api/requests/financial/cards/sale.rb +59 -0
  85. data/lib/genesis_ruby/api/requests/financial/cards/sale3d.rb +75 -0
  86. data/lib/genesis_ruby/api/requests/wpf/create.rb +142 -0
  87. data/lib/genesis_ruby/api/response.rb +91 -0
  88. data/lib/genesis_ruby/builder.rb +42 -0
  89. data/lib/genesis_ruby/builders/base.rb +18 -0
  90. data/lib/genesis_ruby/builders/xml.rb +95 -0
  91. data/lib/genesis_ruby/configuration.rb +177 -0
  92. data/lib/genesis_ruby/connection.rb +20 -0
  93. data/lib/genesis_ruby/dependencies.rb +19 -0
  94. data/lib/genesis_ruby/errors/builder_error.rb +14 -0
  95. data/lib/genesis_ruby/errors/endpoint_not_set_error.rb +14 -0
  96. data/lib/genesis_ruby/errors/error.rb +18 -0
  97. data/lib/genesis_ruby/errors/invalid_argument_error.rb +14 -0
  98. data/lib/genesis_ruby/errors/network_error.rb +14 -0
  99. data/lib/genesis_ruby/errors/object_formatter_error.rb +14 -0
  100. data/lib/genesis_ruby/errors/parameter_error.rb +12 -0
  101. data/lib/genesis_ruby/errors/parser_error.rb +14 -0
  102. data/lib/genesis_ruby/errors/response_error.rb +14 -0
  103. data/lib/genesis_ruby/network/adapter/base_adapter.rb +31 -0
  104. data/lib/genesis_ruby/network/adapter/net_http_adapter.rb +92 -0
  105. data/lib/genesis_ruby/network/base_network.rb +83 -0
  106. data/lib/genesis_ruby/network/net_http.rb +28 -0
  107. data/lib/genesis_ruby/parser.rb +44 -0
  108. data/lib/genesis_ruby/parsers/base.rb +25 -0
  109. data/lib/genesis_ruby/parsers/xml.rb +120 -0
  110. data/lib/genesis_ruby/utils/common.rb +108 -0
  111. data/lib/genesis_ruby/utils/formatters/base.rb +40 -0
  112. data/lib/genesis_ruby/utils/formatters/response/definitions.rb +21 -0
  113. data/lib/genesis_ruby/utils/formatters/response/formats/amount.rb +34 -0
  114. data/lib/genesis_ruby/utils/formatters/response/formats/timestamp.rb +29 -0
  115. data/lib/genesis_ruby/utils/formatters/response/loader.rb +42 -0
  116. data/lib/genesis_ruby/utils/money/base/strategy.rb +38 -0
  117. data/lib/genesis_ruby/utils/money/conversions/amount_to_exponent.rb +22 -0
  118. data/lib/genesis_ruby/utils/money/conversions/exponent_to_amount.rb +22 -0
  119. data/lib/genesis_ruby/utils/money/format.rb +34 -0
  120. data/lib/genesis_ruby/utils/money_format.rb +39 -0
  121. data/lib/genesis_ruby/utils/object_formatter.rb +67 -0
  122. data/lib/genesis_ruby/utils/options/api_config.rb +36 -0
  123. data/lib/genesis_ruby/utils/options/base.rb +35 -0
  124. data/lib/genesis_ruby/utils/options/network_adapter_config.rb +41 -0
  125. data/lib/genesis_ruby/utils/transactions/financial_types.rb +50 -0
  126. data/lib/genesis_ruby/utils/transactions/references/capturable_types.rb +52 -0
  127. data/lib/genesis_ruby/utils/transactions/references/refundable_types.rb +70 -0
  128. data/lib/genesis_ruby/utils/transactions/references/voidable_types.rb +49 -0
  129. data/lib/genesis_ruby/utils/transactions/wpf_types.rb +43 -0
  130. data/lib/genesis_ruby/version.rb +5 -0
  131. data/lib/genesis_ruby.rb +57 -0
  132. metadata +372 -0
@@ -0,0 +1,29 @@
1
+ require 'genesis_ruby/utils/formatters/base'
2
+ require 'date'
3
+
4
+ module GenesisRuby
5
+ module Utils
6
+ module Formatters
7
+ module Response
8
+ module Formats
9
+ # Response Timestamp format
10
+ class Timestamp < Base
11
+
12
+ # The Response keys that the formatter will be applied to
13
+ def formatting_keys
14
+ %w(timestamp)
15
+ end
16
+
17
+ # Format the given timestamp to DateTime object
18
+ def format_key(timestamp)
19
+ DateTime.parse timestamp
20
+ rescue StandardError
21
+ timestamp
22
+ end
23
+
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,42 @@
1
+ require 'genesis_ruby/utils/formatters/response/definitions'
2
+
3
+ module GenesisRuby
4
+ module Utils
5
+ module Formatters
6
+ module Response
7
+ # Response Formatter initializer
8
+ class Loader
9
+
10
+ include Response
11
+
12
+ # Load the Available Formatters
13
+ def initialize
14
+ initialize_formatters
15
+ end
16
+
17
+ # Initialized Formatters array
18
+ def formats
19
+ @formats ||= []
20
+ end
21
+
22
+ # Add new formatter to the formatter array
23
+ def formats=(formatter_class)
24
+ @formats = formats
25
+
26
+ @formats.push formatter_class
27
+ end
28
+
29
+ private
30
+
31
+ # Initialize the Available Formatters
32
+ def initialize_formatters
33
+ available_formatters.each do |formatter_class|
34
+ self.formats = formatter_class.new
35
+ end
36
+ end
37
+
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,38 @@
1
+ require 'genesis_ruby/errors/invalid_argument_error'
2
+ require 'bigdecimal'
3
+
4
+ module GenesisRuby
5
+ module Utils
6
+ module Money
7
+ module Base
8
+ # Base Conversion Strategy class
9
+ class Strategy
10
+
11
+ attr_accessor :amount, :currency, :currency_exponent
12
+
13
+ # Class constructor
14
+ def initialize(amount, currency, currency_exponent)
15
+ @amount = parse_amount(amount)
16
+ @currency = currency
17
+ @currency_exponent = currency_exponent
18
+ end
19
+
20
+ # Convert Strategy method
21
+ def convert
22
+ raise NotImplementedError
23
+ end
24
+
25
+ protected
26
+
27
+ # Validate and parse amount into BigDecimal
28
+ def parse_amount(amount)
29
+ BigDecimal(amount.to_s)
30
+ rescue StandardError
31
+ raise InvalidArgumentError, 'Invalid amount value given.'
32
+ end
33
+
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,22 @@
1
+ require 'genesis_ruby/utils/money/base/strategy'
2
+
3
+ module GenesisRuby
4
+ module Utils
5
+ module Money
6
+ module Conversions
7
+ # Amount To Exponent Money Conversion Strategy
8
+ class AmountToExponent < GenesisRuby::Utils::Money::Base::Strategy
9
+
10
+ # Convert amount to ISO-4217 minor currency unit
11
+ def convert
12
+ format(
13
+ '%d',
14
+ (amount * parse_amount(10**currency_exponent))
15
+ )
16
+ end
17
+
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,22 @@
1
+ require 'genesis_ruby/utils/money/base/strategy'
2
+
3
+ module GenesisRuby
4
+ module Utils
5
+ module Money
6
+ module Conversions
7
+ # Amount To Exponent Money Conversion Strategy
8
+ class ExponentToAmount < GenesisRuby::Utils::Money::Base::Strategy
9
+
10
+ # Convert ISO-4217 minor currency unit to amount
11
+ def convert
12
+ format(
13
+ "%.#{currency_exponent}f",
14
+ (amount / parse_amount(10**currency_exponent)).truncate(currency_exponent)
15
+ )
16
+ end
17
+
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,34 @@
1
+ require 'genesis_ruby/errors/invalid_argument_error'
2
+
3
+ module GenesisRuby
4
+ module Utils
5
+ module Money
6
+ # Money Helper
7
+ class Format
8
+
9
+ attr_accessor :strategy
10
+
11
+ def initialize(strategy)
12
+ @strategy = strategy
13
+ end
14
+
15
+ # Execute Convert Strategy
16
+ def convert
17
+ unless valid_amount_exponent?
18
+ raise GenesisRuby::InvalidArgumentError, 'Currency exponent do not match the given amount'
19
+ end
20
+
21
+ strategy.convert
22
+ end
23
+
24
+ # Validate the given amount against the defined currency exponent
25
+ def valid_amount_exponent?
26
+ amount_sign, amount_digits, amount_base, amount_exponent = strategy.amount.split # rubocop:disable Lint/UselessAssignment
27
+
28
+ !amount_sign.negative? && (amount_digits.length - amount_exponent) <= strategy.currency_exponent
29
+ end
30
+
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,39 @@
1
+ require 'genesis_ruby/api/constants/currencies/iso4217'
2
+ require 'genesis_ruby/utils/money/conversions/amount_to_exponent'
3
+ require 'genesis_ruby/utils/money/conversions/exponent_to_amount'
4
+ require 'genesis_ruby/utils/money/format'
5
+
6
+ module GenesisRuby
7
+ module Utils
8
+ # Money Helper
9
+ class MoneyFormat
10
+
11
+ class << self
12
+
13
+ # Convert major to minor currency format units
14
+ def amount_to_exponent(amount, currency)
15
+ strategy = GenesisRuby::Utils::Money::Conversions::AmountToExponent.new(
16
+ amount,
17
+ currency,
18
+ GenesisRuby::Api::Constants::Currencies::Iso4217.fetch_exponent(currency)
19
+ )
20
+
21
+ GenesisRuby::Utils::Money::Format.new(strategy).convert
22
+ end
23
+
24
+ # Convert minor to major currency format units
25
+ def exponent_to_amount(amount, currency)
26
+ strategy = GenesisRuby::Utils::Money::Conversions::ExponentToAmount.new(
27
+ amount,
28
+ currency,
29
+ GenesisRuby::Api::Constants::Currencies::Iso4217.fetch_exponent(currency)
30
+ )
31
+
32
+ GenesisRuby::Utils::Money::Format.new(strategy).convert
33
+ end
34
+
35
+ end
36
+
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,67 @@
1
+ require 'genesis_ruby/errors/object_formatter_error'
2
+
3
+ module GenesisRuby
4
+ module Utils
5
+ # Object Formatter component
6
+ class ObjectFormatter
7
+
8
+ # Available Formatters
9
+ def formats
10
+ @formats ||= []
11
+ end
12
+
13
+ # Add new formatter to the formatter array
14
+ def formats=(formatters)
15
+ raise ObjectFormatterError, 'Invalid array value given for Formats.' unless formatters.is_a? Array
16
+
17
+ formats.push *formatters
18
+ end
19
+
20
+ # Apply all Formatter on the given object
21
+ def format_structure(response_object)
22
+ return format_hash(response_object) if response_object.is_a? Hash
23
+ return format_array(response_object) if response_object.is_a? Array
24
+
25
+ response_object
26
+ end
27
+
28
+ private
29
+
30
+ # Format Object with Hash type
31
+ def format_hash(response_object)
32
+ response_object.each do |response_key, response_value|
33
+ response_object[response_key] = if response_value.is_a?(Hash) || response_value.is_a?(Array)
34
+ format_structure(response_value)
35
+ else
36
+ format_value(response_object, response_key, response_value)
37
+ end
38
+ end
39
+
40
+ response_object
41
+ end
42
+
43
+ # Format Object with Array type
44
+ def format_array(response_object)
45
+ response_object.each do |response_value|
46
+ format_structure(response_value)
47
+ end
48
+ end
49
+
50
+ # Format Object key value
51
+ def format_value(response_object, response_key, response_value)
52
+ formats.each do |formatter|
53
+ next unless formatter.formatting_keys.include?(response_key.to_s)
54
+
55
+ required_values = formatter.collect_required_key_values(response_object)
56
+
57
+ return response_value if required_values.count != formatter.required_keys.count
58
+
59
+ return formatter.format_key(response_value, *required_values)
60
+ end
61
+
62
+ response_value
63
+ end
64
+
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,36 @@
1
+ require 'genesis_ruby/utils/options/base'
2
+
3
+ module GenesisRuby
4
+ module Utils
5
+ module Options
6
+ # Configurable Options used for the API Request configuration
7
+ class ApiConfig < Base
8
+
9
+ # Load pre-defined XML configuration
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
15
+ end
16
+
17
+ # Load pre-defined JSON configuration
18
+ 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
23
+ end
24
+
25
+ # Load pre-defined FORM configuration
26
+ 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
31
+ end
32
+
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,35 @@
1
+ module GenesisRuby
2
+ module Utils
3
+ module Options
4
+ # Simple key value hash object
5
+ # Usage: ConfigurableOptions.<name>=, ConfigurableOptions.<name>
6
+ class Base < Hash
7
+
8
+ def []=(key, value)
9
+ super(key.to_sym, value)
10
+ end
11
+
12
+ def [](key)
13
+ super(key.to_sym)
14
+ end
15
+
16
+ # Dynamic accessors for the hash[keys]
17
+ def method_missing(name, *args)
18
+ name_string = name.to_s
19
+ if name_string.chomp!('=')
20
+ self[name_string] = args.first
21
+ else
22
+ self[name_string]
23
+ end
24
+ end
25
+
26
+ # Define ConfigurableOptions.method("<method>") call
27
+ # If we dont have defined hash key we will raise exception
28
+ def respond_to_missing?(name, include_private = false)
29
+ method_missing(name) || super
30
+ end
31
+
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,41 @@
1
+ require 'genesis_ruby/utils/options/base'
2
+
3
+ module GenesisRuby
4
+ module Utils
5
+ module Options
6
+ # Configurable Options used for the API Request configuration
7
+ class NetworkAdapterConfig < Base
8
+
9
+ # 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)
17
+
18
+ self
19
+ end
20
+
21
+ protected
22
+
23
+ # Retrieve the Request data format that must be used as Content-Type header
24
+ def fetch_content_type(data_format)
25
+ # TODO: Builder Constants
26
+ case data_format
27
+ when 'xml'
28
+ 'text/xml'
29
+ when 'json'
30
+ 'application/json'
31
+ when 'form'
32
+ 'application/x-www-form-urlencoded'
33
+ else
34
+ raise InvalidArgumentError, 'Invalid request format type. Allowed are XML, JSON and FORM'
35
+ end
36
+ end
37
+
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,50 @@
1
+ module GenesisRuby
2
+ module Utils
3
+ module Transactions
4
+ # Financial Transaction Types Helper methods
5
+ class FinancialTypes
6
+
7
+ class << self
8
+
9
+ include GenesisRuby::Api::Constants::Transactions
10
+
11
+ # Return array containing all available Web Payment Form transaction types
12
+ def all # rubocop:disable Metrics/MethodLength
13
+ [
14
+ AFRICAN_MOBILE_PAYOUT, AFRICAN_MOBILE_SALE, APPLE_PAY, ARGENCARD, AURA, AUTHORIZE, AUTHORIZE_3D,
15
+ BALOTO, BANCOMER, BANCONTACT, BANCO_DE_OCCIDENTE, BANCO_DO_BRASIL, BITPAY_PAYOUT, BITPAY_REFUND,
16
+ BITPAY_SALE, BOLETO, BRADESCO,
17
+ CABAL, CAPTURE, CASHU, CENCOSUD, CREDIT,
18
+ DAVIVIENDA,
19
+ EFECTY, ELO, EPS,
20
+ EZEECARD_PAYOUT, EZEEWALLET,
21
+ FASHIONCHEQUE,
22
+ GIROPAY, GOOGLE_PAY,
23
+ IDEAL, IDEBIT_PAYIN, IDEBIT_PAYOUT, INCREMENTAL_AUTHORIZE, INSTA_DEBIT_PAYIN, INSTA_DEBIT_PAYOUT,
24
+ INTERSOLVE, ITAU,
25
+ MULTIBANCO, MY_BANK,
26
+ NARANJA, NATIVA, NEOSURF, NETELLER,
27
+ ONLINE_BANKING_PAYIN, ONLINE_BANKING_PAYOUT,
28
+ OXXO,
29
+ P24, PAGO_FACIL, PARTIAL_REVERSAL, PAYOUT, PAYSAFECARD, PAYU, PAY_PAL, PIX, POLI, POST_FINANCE, PPRO, PSE,
30
+ RAPI_PAGO, REDPAGOS, REFUND, RUSSIAN_MOBILE_PAYOUT, RUSSIAN_MOBILE_SALE,
31
+ SAFETYPAY, SALE, SALE_3D, SANTANDER, SCT_PAYOUT, SDD_INIT_RECURRING_SALE, SDD_RECURRING_SALE, SDD_REFUND,
32
+ SDD_SALE, SOFORT,
33
+ TARJETA_SHOPPING, TCS, TRANSFER_TO_PAYOUT, TRUSTLY_SALE,
34
+ UPI,
35
+ VOID,
36
+ WEBMONEY, WEBPAY, WECHAT
37
+ ]
38
+ end
39
+
40
+ # Validates the given type against the available Web Payment Form transaction types
41
+ def valid?(type)
42
+ all.include? type.to_s.downcase
43
+ end
44
+
45
+ end
46
+
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,52 @@
1
+ module GenesisRuby
2
+ module Utils
3
+ module Transactions
4
+ module References
5
+ # Capturable Transaction Types Helper Methods
6
+ class CapturableTypes
7
+
8
+ class << self
9
+
10
+ include GenesisRuby::Api::Constants::Transactions
11
+
12
+ # Array containing all available Capturable Types
13
+ def all
14
+ [
15
+ APPLE_PAY, AUTHORIZE, AUTHORIZE_3D,
16
+ GOOGLE_PAY,
17
+ INVOICE,
18
+ PAY_PAL
19
+ ]
20
+ end
21
+
22
+ # Checks if the given type is allowed for the execution of Reference Capture Transaction Type
23
+ def allowed_reference?(type)
24
+ all.include?(type.to_s.downcase)
25
+ end
26
+
27
+ # Checks if the given type is a Capture type
28
+ def valid?(type)
29
+ [
30
+ CAPTURE,
31
+ INVOICE_CAPTURE
32
+ ].include?(type.to_s.downcase)
33
+ end
34
+
35
+ # Fetches the correct Transaction type that must be used for the execution of the Capture
36
+ # ex. invoice -> invoice_capture
37
+ def fetch_reference(type)
38
+ case type.to_s.downcase
39
+ when INVOICE
40
+ INVOICE_CAPTURE
41
+ else
42
+ CAPTURE
43
+ end
44
+ end
45
+
46
+ end
47
+
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,70 @@
1
+ module GenesisRuby
2
+ module Utils
3
+ module Transactions
4
+ module References
5
+ # Refundable Transaction Types Helper Methods
6
+ class RefundableTypes
7
+
8
+ class << self
9
+
10
+ include GenesisRuby::Api::Constants::Transactions
11
+
12
+ # Array containing all available Refundable Types
13
+ def all # rubocop:disable Metrics/MethodLength
14
+ [
15
+ AFRICAN_MOBILE_PAYOUT, AFRICAN_MOBILE_SALE, APPLE_PAY,
16
+ BALOTO, BANCOMER, BANCONTACT, BANCO_DE_OCCIDENTE, BANCO_DO_BRASIL, BITPAY_SALE, BOLETO, BRADESCO,
17
+ CAPTURE, CASHU,
18
+ DAVIVIENDA,
19
+ EFECTY, EPS, FASHIONCHEQUE,
20
+ GIROPAY, GOOGLE_PAY,
21
+ IDEAL, IDEBIT_PAYIN, INIT_RECURRING_SALE, INIT_RECURRING_SALE_3D, INVOICE_CAPTURE, ITAU,
22
+ MY_BANK,
23
+ NEOSURF,
24
+ ONLINE_BANKING_PAYIN, OXXO,
25
+ P24, PAGO_FACIL, PARTIAL_REVERSAL, PAYU, PAY_PAL, PIX, POST_FINANCE, PPRO, PSE, RAPI_PAGO,
26
+ RECURRING_SALE, REDPAGOS,
27
+ SAFETYPAY, SALE, SALE_3D, SANTANDER, SDD_INIT_RECURRING_SALE, SDD_RECURRING_SALE, SDD_SALE, SOFORT,
28
+ TRUSTLY_SALE,
29
+ UPI,
30
+ WEBPAY, WECHAT
31
+ ]
32
+ end
33
+
34
+ # Checks if the given type is allowed for the execution of Reference Refund Transaction Type
35
+ def allowed_reference?(type)
36
+ all.include?(type.to_s.downcase)
37
+ end
38
+
39
+ # Checks if the given type is a Refund type
40
+ def valid?(type)
41
+ [
42
+ BITPAY_REFUND,
43
+ INVOICE_REFUND,
44
+ REFUND,
45
+ SDD_REFUND
46
+ ].include?(type.to_s.downcase)
47
+ end
48
+
49
+ # Fetches the correct Transaction type that must be used for the execution of the Refund
50
+ # ex. sdd_sale -> sdd_refund, sale -> refund
51
+ def fetch_reference(type)
52
+ case type.to_s.downcase
53
+ when BITPAY_SALE
54
+ BITPAY_REFUND
55
+ when SDD_SALE, SDD_RECURRING_SALE, SDD_INIT_RECURRING_SALE
56
+ SDD_REFUND
57
+ when INVOICE_CAPTURE
58
+ INVOICE_REFUND
59
+ else
60
+ REFUND
61
+ end
62
+ end
63
+
64
+ end
65
+
66
+ end
67
+ end
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,49 @@
1
+ module GenesisRuby
2
+ module Utils
3
+ module Transactions
4
+ module References
5
+ # Voidable Transaction Types Helper Methods
6
+ class VoidableTypes
7
+
8
+ class << self
9
+
10
+ include GenesisRuby::Api::Constants::Transactions
11
+
12
+ # Array containing all available Voidable Types
13
+ def all
14
+ [
15
+ AFRICAN_MOBILE_PAYOUT, AFRICAN_MOBILE_SALE, APPLE_PAY, AUTHORIZE, AUTHORIZE_3D,
16
+ FASHIONCHEQUE,
17
+ GOOGLE_PAY,
18
+ INTERSOLVE, INVOICE,
19
+ PAY_PAL,
20
+ REFUND,
21
+ SALE, SALE_3D,
22
+ TCS, TRUSTLY_SALE
23
+ ]
24
+ end
25
+
26
+ # Checks if the given type is allowed for the execution of Reference Void Transaction Type
27
+ def allowed_reference?(type)
28
+ all.include?(type.to_s.downcase)
29
+ end
30
+
31
+ # Checks if the given type is a Void type
32
+ def valid?(type)
33
+ [
34
+ VOID
35
+ ].include?(type.to_s.downcase)
36
+ end
37
+
38
+ # Fetches the correct Transaction type that must be used for the execution of the Void
39
+ def fetch_reference(_type)
40
+ VOID
41
+ end
42
+
43
+ end
44
+
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,43 @@
1
+ module GenesisRuby
2
+ module Utils
3
+ module Transactions
4
+ # Web Payment Form Transaction Types Helper methods
5
+ class WpfTypes
6
+
7
+ class << self
8
+
9
+ include GenesisRuby::Api::Constants::Transactions
10
+
11
+ # Return array containing all available Web Payment Form transaction types
12
+ def all # rubocop:disable Metrics/MethodLength
13
+ [
14
+ ACCOUNT_VERIFICATION, ARGENCARD, APPLE_PAY, AURA, AUTHORIZE, AUTHORIZE_3D,
15
+ BALOTO, BANCOMER, BANCONTACT, BANCO_DE_OCCIDENTE, BANCO_DO_BRASIL, BITPAY_PAYOUT, BITPAY_SALE, BOLETO,
16
+ BRADESCO,
17
+ CABAL, CASHU, CENCOSUD, DAVIVIENDA,
18
+ EFECTY, ELO, EPS, EZEEWALLET, FASHIONCHEQUE,
19
+ GIROPAY, GOOGLE_PAY,
20
+ IDEAL, IDEBIT_PAYIN, INSTA_DEBIT_PAYIN, INTERSOLVE, ITAU,
21
+ MULTIBANCO, MY_BANK,
22
+ NARANJA, NATIVA, NEOSURF, NETELLER,
23
+ ONLINE_BANKING_PAYIN, OXXO,
24
+ P24, PAGO_FACIL, PAY_PAL, PAYSAFECARD, PAYU, PIX, POLI, POST_FINANCE, PPRO, PSE,
25
+ RAPI_PAGO, REDPAGOS, RUSSIAN_MOBILE_SALE,
26
+ SAFETYPAY, SALE, SALE_3D, SANTANDER, SDD_INIT_RECURRING_SALE, SDD_SALE,
27
+ TARJETA_SHOPPING, TCS, TRUSTLY_SALE,
28
+ UPI,
29
+ WEBMONEY, WEBPAY, WECHAT
30
+ ]
31
+ end
32
+
33
+ # Validates the given type against the available Web Payment Form transaction types
34
+ def valid?(type)
35
+ all.include? type.to_s.downcase
36
+ end
37
+
38
+ end
39
+
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,5 @@
1
+ module GenesisRuby
2
+
3
+ VERSION = '0.1.0'.freeze
4
+
5
+ end