wesley-key-sdk 3.0.6 → 4.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (107) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +156 -132
  3. data/bin/console +4 -4
  4. data/lib/webhooks_and_callbacks_api/api_helper.rb +10 -0
  5. data/lib/{cypress_test_api/controllers/base_controller.rb → webhooks_and_callbacks_api/apis/base_api.rb} +17 -10
  6. data/lib/webhooks_and_callbacks_api/apis/orders_api.rb +34 -0
  7. data/lib/webhooks_and_callbacks_api/client.rb +76 -0
  8. data/lib/{cypress_test_api → webhooks_and_callbacks_api}/configuration.rb +61 -46
  9. data/lib/webhooks_and_callbacks_api/events/callbacks/callbacks_a_handler.rb +66 -0
  10. data/lib/webhooks_and_callbacks_api/events/callbacks/callbacks_b_handler.rb +78 -0
  11. data/lib/webhooks_and_callbacks_api/events/signature_verification_failure.rb +33 -0
  12. data/lib/webhooks_and_callbacks_api/events/signature_verification_result.rb +14 -0
  13. data/lib/webhooks_and_callbacks_api/events/unknown_event.rb +32 -0
  14. data/lib/webhooks_and_callbacks_api/events/webhooks/webhooks_a_handler.rb +67 -0
  15. data/lib/webhooks_and_callbacks_api/events/webhooks/webhooks_b_handler.rb +86 -0
  16. data/lib/webhooks_and_callbacks_api/events/webhooks/webhooks_c_handler.rb +79 -0
  17. data/lib/webhooks_and_callbacks_api/events/webhooks/webhooks_handler.rb +67 -0
  18. data/lib/webhooks_and_callbacks_api/events/webhooks/webhooks_no_verification_handler.rb +39 -0
  19. data/lib/{cypress_test_api → webhooks_and_callbacks_api}/exceptions/api_exception.rb +4 -4
  20. data/lib/webhooks_and_callbacks_api/exceptions/error_exception.rb +57 -0
  21. data/lib/webhooks_and_callbacks_api/http/api_response.rb +19 -0
  22. data/lib/webhooks_and_callbacks_api/http/auth/api_key.rb +52 -0
  23. data/lib/webhooks_and_callbacks_api/http/auth/bearer_auth.rb +53 -0
  24. data/lib/webhooks_and_callbacks_api/http/http_call_back.rb +10 -0
  25. data/lib/webhooks_and_callbacks_api/http/http_method_enum.rb +10 -0
  26. data/lib/webhooks_and_callbacks_api/http/http_request.rb +10 -0
  27. data/lib/webhooks_and_callbacks_api/http/http_response.rb +10 -0
  28. data/lib/{cypress_test_api → webhooks_and_callbacks_api}/http/proxy_settings.rb +4 -4
  29. data/lib/webhooks_and_callbacks_api/logging/configuration/api_logging_configuration.rb +186 -0
  30. data/lib/webhooks_and_callbacks_api/logging/sdk_logger.rb +17 -0
  31. data/lib/webhooks_and_callbacks_api/models/address.rb +114 -0
  32. data/lib/webhooks_and_callbacks_api/models/audit_log_event.rb +115 -0
  33. data/lib/{cypress_test_api → webhooks_and_callbacks_api}/models/base_model.rb +4 -4
  34. data/lib/webhooks_and_callbacks_api/models/create_order_request.rb +131 -0
  35. data/lib/webhooks_and_callbacks_api/models/delivery_details.rb +104 -0
  36. data/lib/webhooks_and_callbacks_api/models/email_notification_callback.rb +97 -0
  37. data/lib/webhooks_and_callbacks_api/models/event.rb +52 -0
  38. data/lib/webhooks_and_callbacks_api/models/event_type.rb +26 -0
  39. data/lib/webhooks_and_callbacks_api/models/event_type1.rb +26 -0
  40. data/lib/webhooks_and_callbacks_api/models/event_type2.rb +26 -0
  41. data/lib/webhooks_and_callbacks_api/models/event_type3.rb +26 -0
  42. data/lib/webhooks_and_callbacks_api/models/fulfillment_callback.rb +411 -0
  43. data/lib/webhooks_and_callbacks_api/models/fulfillment_status.rb +40 -0
  44. data/lib/webhooks_and_callbacks_api/models/fulfillment_statuss.rb +40 -0
  45. data/lib/webhooks_and_callbacks_api/models/inventory_stock_decrease_event.rb +90 -0
  46. data/lib/webhooks_and_callbacks_api/models/inventory_stock_depleted_event.rb +90 -0
  47. data/lib/webhooks_and_callbacks_api/models/inventory_stock_increase_event.rb +90 -0
  48. data/lib/webhooks_and_callbacks_api/models/notification_callback.rb +119 -0
  49. data/lib/{cypress_test_api/models/o_auth_scope_o_auth_acg_enum.rb → webhooks_and_callbacks_api/models/oauth_scope_oauth_acg.rb} +19 -19
  50. data/lib/webhooks_and_callbacks_api/models/order.rb +161 -0
  51. data/lib/webhooks_and_callbacks_api/models/order_created_event.rb +314 -0
  52. data/lib/webhooks_and_callbacks_api/models/order_item.rb +102 -0
  53. data/lib/webhooks_and_callbacks_api/models/order_updated_event.rb +100 -0
  54. data/lib/webhooks_and_callbacks_api/models/package.rb +95 -0
  55. data/lib/webhooks_and_callbacks_api/models/payment_callback.rb +167 -0
  56. data/lib/webhooks_and_callbacks_api/models/payment_completed_event.rb +98 -0
  57. data/lib/webhooks_and_callbacks_api/models/payment_status.rb +40 -0
  58. data/lib/webhooks_and_callbacks_api/models/payment_status_created_event.rb +89 -0
  59. data/lib/webhooks_and_callbacks_api/models/payment_status_updated_event.rb +89 -0
  60. data/lib/webhooks_and_callbacks_api/models/primitive_collection_event.rb +98 -0
  61. data/lib/webhooks_and_callbacks_api/models/root_level_primitive_one_of_event_request.rb +40 -0
  62. data/lib/webhooks_and_callbacks_api/models/root_level_primitive_one_of_event_request1.rb +40 -0
  63. data/lib/webhooks_and_callbacks_api/models/sms_notification_callback.rb +95 -0
  64. data/lib/webhooks_and_callbacks_api/models/status.rb +44 -0
  65. data/lib/webhooks_and_callbacks_api/models/status1.rb +36 -0
  66. data/lib/webhooks_and_callbacks_api/models/status2.rb +36 -0
  67. data/lib/webhooks_and_callbacks_api/models/system_alert_notification_event.rb +90 -0
  68. data/lib/webhooks_and_callbacks_api/models/system_maintenance_notification_event.rb +90 -0
  69. data/lib/webhooks_and_callbacks_api/models/system_performance_notification_event.rb +90 -0
  70. data/lib/webhooks_and_callbacks_api/models/user_action_notification_event.rb +90 -0
  71. data/lib/webhooks_and_callbacks_api/models/user_preference_notification_event.rb +90 -0
  72. data/lib/webhooks_and_callbacks_api/models/user_status_notification_event.rb +90 -0
  73. data/lib/webhooks_and_callbacks_api/models/webhook.rb +142 -0
  74. data/lib/webhooks_and_callbacks_api/models/webhook_registration.rb +103 -0
  75. data/lib/webhooks_and_callbacks_api/models/webhook_update.rb +105 -0
  76. data/lib/webhooks_and_callbacks_api/utilities/date_time_helper.rb +11 -0
  77. data/lib/{cypress_test_api → webhooks_and_callbacks_api}/utilities/file_wrapper.rb +4 -4
  78. data/lib/webhooks_and_callbacks_api/utilities/union_type_lookup.rb +172 -0
  79. data/lib/webhooks_and_callbacks_api.rb +122 -0
  80. metadata +78 -64
  81. data/lib/cypress_test_api/api_helper.rb +0 -10
  82. data/lib/cypress_test_api/client.rb +0 -58
  83. data/lib/cypress_test_api/controllers/api_controller.rb +0 -102
  84. data/lib/cypress_test_api/http/http_call_back.rb +0 -10
  85. data/lib/cypress_test_api/http/http_method_enum.rb +0 -10
  86. data/lib/cypress_test_api/http/http_request.rb +0 -10
  87. data/lib/cypress_test_api/http/http_response.rb +0 -10
  88. data/lib/cypress_test_api/models/custom_enum.rb +0 -40
  89. data/lib/cypress_test_api/models/deer.rb +0 -68
  90. data/lib/cypress_test_api/models/item.rb +0 -166
  91. data/lib/cypress_test_api/models/item_response.rb +0 -80
  92. data/lib/cypress_test_api/models/lion.rb +0 -68
  93. data/lib/cypress_test_api/models/message.rb +0 -68
  94. data/lib/cypress_test_api/models/message2.rb +0 -71
  95. data/lib/cypress_test_api/models/multiple_arrays_request.rb +0 -70
  96. data/lib/cypress_test_api/models/nac_tag.rb +0 -265
  97. data/lib/cypress_test_api/models/response_http400.rb +0 -62
  98. data/lib/cypress_test_api/models/response_http404.rb +0 -62
  99. data/lib/cypress_test_api/models/status11_enum.rb +0 -40
  100. data/lib/cypress_test_api/models/status1_enum.rb +0 -40
  101. data/lib/cypress_test_api/models/status_enum.rb +0 -40
  102. data/lib/cypress_test_api/models/tokens_request.rb +0 -60
  103. data/lib/cypress_test_api/utilities/date_time_helper.rb +0 -11
  104. data/lib/cypress_test_api.rb +0 -55
  105. data/test/controllers/controller_test_base.rb +0 -23
  106. data/test/controllers/test_api_controller.rb +0 -40
  107. data/test/http_response_catcher.rb +0 -19
@@ -1,9 +1,9 @@
1
- # cypress_test_api
1
+ # webhooks_and_callbacks_api
2
2
  #
3
- # This file was automatically generated by APIMATIC v3.0
4
- # ( https://www.apimatic.io ).
3
+ # This file was automatically generated by
4
+ # APIMATIC v3.0 ( https://www.apimatic.io ).
5
5
 
6
- module CypressTestApi
6
+ module WebhooksAndCallbacksApi
7
7
  # An enum for SDK environments.
8
8
  class Environment
9
9
  ENVIRONMENT = [
@@ -14,7 +14,7 @@ module CypressTestApi
14
14
  def self.from_value(value, default_value = PRODUCTION)
15
15
  return default_value if value.nil?
16
16
 
17
- default_value
17
+ default_value
18
18
  end
19
19
  end
20
20
 
@@ -28,7 +28,7 @@ module CypressTestApi
28
28
  def self.from_value(value, default_value = DEFAULT)
29
29
  return default_value if value.nil?
30
30
 
31
- default_value
31
+ default_value
32
32
  end
33
33
  end
34
34
 
@@ -36,31 +36,37 @@ module CypressTestApi
36
36
  # are configured in this class.
37
37
  class Configuration < CoreLibrary::HttpClientConfiguration
38
38
  # The attribute readers for properties.
39
- attr_reader :environment, :default_host
39
+ attr_reader :environment, :api_key_credentials, :bearer_auth_credentials
40
40
 
41
41
  class << self
42
42
  attr_reader :environments
43
43
  end
44
44
 
45
45
  def initialize(
46
- connection: nil, adapter: :net_http_persistent, timeout: 60,
46
+ connection: nil, adapter: :net_http_persistent, timeout: 50,
47
47
  max_retries: 0, retry_interval: 1, backoff_factor: 2,
48
- retry_statuses: [408, 413, 429, 500, 502, 503, 504, 521, 522, 524],
49
- retry_methods: %i[get put], http_callback: nil, proxy_settings: nil,
50
- environment: Environment::PRODUCTION, default_host: 'www.example.com'
51
- )
48
+ retry_statuses: [408, 413, 429, 500, 502, 503, 504, 521, 522, 524, 408, 413, 429, 500, 502, 503, 504, 521, 522, 524],
49
+ retry_methods: %i[get put get put], http_callback: nil,
50
+ proxy_settings: nil, logging_configuration: nil,
51
+ environment: Environment::PRODUCTION, api_key_credentials: nil,
52
+ bearer_auth_credentials: nil
53
+ )
52
54
  super connection: connection, adapter: adapter, timeout: timeout,
53
55
  max_retries: max_retries, retry_interval: retry_interval,
54
56
  backoff_factor: backoff_factor, retry_statuses: retry_statuses,
55
57
  retry_methods: retry_methods, http_callback: http_callback,
56
- proxy_settings: proxy_settings
57
-
58
+ proxy_settings: proxy_settings,
59
+ logging_configuration: logging_configuration
60
+
58
61
  # Current API environment
59
62
  @environment = String(environment)
60
-
61
- # defaultHost value
62
- @default_host = default_host
63
-
63
+
64
+ # The object holding Custom Header Signature credentials
65
+ @api_key_credentials = api_key_credentials
66
+
67
+ # The object holding OAuth 2 Bearer token credentials
68
+ @bearer_auth_credentials = bearer_auth_credentials
69
+
64
70
  # The Http Client to use for making requests.
65
71
  set_http_client CoreLibrary::FaradayClient.new(self)
66
72
  end
@@ -68,20 +74,24 @@ module CypressTestApi
68
74
  def clone_with(connection: nil, adapter: nil, timeout: nil,
69
75
  max_retries: nil, retry_interval: nil, backoff_factor: nil,
70
76
  retry_statuses: nil, retry_methods: nil, http_callback: nil,
71
- proxy_settings: nil, environment: nil, default_host: nil)
72
- connection ||= self.connection
73
- adapter ||= self.adapter
74
- timeout ||= self.timeout
75
- max_retries ||= self.max_retries
76
- retry_interval ||= self.retry_interval
77
- backoff_factor ||= self.backoff_factor
78
- retry_statuses ||= self.retry_statuses
79
- retry_methods ||= self.retry_methods
80
- http_callback ||= self.http_callback
81
- proxy_settings ||= self.proxy_settings
82
- environment ||= self.environment
83
- default_host ||= self.default_host
84
-
77
+ proxy_settings: nil, logging_configuration: nil,
78
+ environment: nil, api_key_credentials: nil,
79
+ bearer_auth_credentials: nil)
80
+ connection ||= self.connection
81
+ adapter ||= self.adapter
82
+ timeout ||= self.timeout
83
+ max_retries ||= self.max_retries
84
+ retry_interval ||= self.retry_interval
85
+ backoff_factor ||= self.backoff_factor
86
+ retry_statuses ||= self.retry_statuses
87
+ retry_methods ||= self.retry_methods
88
+ http_callback ||= self.http_callback
89
+ proxy_settings ||= self.proxy_settings
90
+ logging_configuration ||= self.logging_configuration
91
+ environment ||= self.environment
92
+ api_key_credentials ||= self.api_key_credentials
93
+ bearer_auth_credentials ||= self.bearer_auth_credentials
94
+
85
95
  Configuration.new(connection: connection, adapter: adapter,
86
96
  timeout: timeout, max_retries: max_retries,
87
97
  retry_interval: retry_interval,
@@ -90,14 +100,17 @@ module CypressTestApi
90
100
  retry_methods: retry_methods,
91
101
  http_callback: http_callback,
92
102
  proxy_settings: proxy_settings,
93
- environment: environment, default_host: default_host)
103
+ logging_configuration: logging_configuration,
104
+ environment: environment,
105
+ api_key_credentials: api_key_credentials,
106
+ bearer_auth_credentials: bearer_auth_credentials)
94
107
  end
95
108
 
96
109
 
97
110
  # All the environments the SDK can run in.
98
111
  ENVIRONMENTS = {
99
112
  Environment::PRODUCTION => {
100
- Server::DEFAULT => 'https://{defaultHost}'
113
+ Server::DEFAULT => 'http://localhost:3000/callbacks'
101
114
  }
102
115
  }.freeze
103
116
 
@@ -106,50 +119,52 @@ module CypressTestApi
106
119
  # required.
107
120
  # @return [String] The base URI.
108
121
  def get_base_uri(server = Server::DEFAULT)
109
- parameters = {
110
- 'defaultHost' => { 'value' => default_host, 'encode' => false }
111
- }
112
- APIHelper.append_url_with_template_parameters(
113
- ENVIRONMENTS[environment][server], parameters
114
- )
122
+ ENVIRONMENTS[environment][server].clone
115
123
  end
116
124
 
117
125
  # Builds a Configuration instance using environment variables.
118
126
  def self.build_default_config_from_env
119
127
  # === Core environment ===
120
128
  environment = Environment.from_value(ENV.fetch('ENVIRONMENT', 'production'))
121
- default_host = ENV.fetch('DEFAULT_HOST', 'www.example.com')
122
- timeout = (ENV['TIMEOUT'] || 60).to_f
129
+ timeout = (ENV['TIMEOUT'] || 50).to_f
123
130
  max_retries = (ENV['MAX_RETRIES'] || 0).to_i
124
131
  retry_interval = (ENV['RETRY_INTERVAL'] || 1).to_f
125
132
  backoff_factor = (ENV['BACKOFF_FACTOR'] || 2).to_f
126
133
  retry_statuses = ENV.fetch('RETRY_STATUSES',
127
- '[408, 413, 429, 500, 502, 503, 504, 521, 522, 524]').gsub(/[\[\]]/, '')
134
+ '[408, 413, 429, 500, 502, 503, 504, 521, 522, 524, 408, 413, 429, 500, 502, 503, 504, 521, 522, 524]').gsub(/[\[\]]/, '')
128
135
  .split(',')
129
136
  .map(&:strip)
130
137
  .map do |item|
131
138
  item.match?(/\A\d+\z/) ? item.to_i : item.downcase
132
139
  end
133
- retry_methods = ENV.fetch('RETRY_METHODS', '%i[get put]').gsub(/[\[\]]/, '')
140
+ retry_methods = ENV.fetch('RETRY_METHODS', '%i[get put get put]').gsub(/[\[\]]/, '')
134
141
  .split(',')
135
142
  .map(&:strip)
136
143
  .map do |item|
137
144
  item.match?(/\A\d+\z/) ? item.to_i : item.downcase
138
145
  end
139
146
 
147
+ # === Authentication credentials ===
148
+ api_key_credentials = ApiKeyCredentials.from_env
149
+ bearer_auth_credentials = BearerAuthCredentials.from_env
150
+
140
151
  # === Proxy settings ===
141
152
  proxy_settings = ProxySettings.from_env
153
+ # === Logging Configuration ===
154
+ logging_configuration = LoggingConfiguration.from_env if LoggingConfiguration.any_logging_configured?
142
155
 
143
156
  Configuration.new(
144
157
  environment: environment,
145
- default_host: default_host,
146
158
  timeout: timeout,
147
159
  max_retries: max_retries,
148
160
  retry_interval: retry_interval,
149
161
  backoff_factor: backoff_factor,
150
162
  retry_statuses: retry_statuses,
151
163
  retry_methods: retry_methods,
152
- proxy_settings: proxy_settings
164
+ api_key_credentials: api_key_credentials,
165
+ bearer_auth_credentials: bearer_auth_credentials,
166
+ proxy_settings: proxy_settings,
167
+ logging_configuration: logging_configuration
153
168
  )
154
169
  end
155
170
  end
@@ -0,0 +1,66 @@
1
+ # webhooks_and_callbacks_api
2
+ #
3
+ # This file was automatically generated by
4
+ # APIMATIC v3.0 ( https://www.apimatic.io ).
5
+
6
+ module WebhooksAndCallbacksApi
7
+ # CallbacksAHandler is responsible for verifying request signatures
8
+ # and parsing incoming callbacksA events into strongly typed objects.
9
+ class CallbacksAHandler
10
+ include CoreLibrary
11
+ # Creates a new instance of the CallbacksAHandler.
12
+ # Initializes the handler.
13
+ # @param [String] secret_key
14
+ # The secret used to generate and validate HMAC signatures for verifying request authenticity.
15
+ # @raise [ArgumentError] If the secret_key is not provided.
16
+ def initialize(secret_key)
17
+ raise ArgumentError, 'secret_key must be provided for signature verification.' unless secret_key
18
+
19
+ @verifier = HmacSignatureVerifier.new(
20
+ secret_key: secret_key,
21
+ signature_header: 'X-Signature',
22
+ hash_algorithm: 'sha256',
23
+ encoder: HexEncoder.new
24
+ )
25
+ end
26
+
27
+ # Perform signature verification and return the result.
28
+ #
29
+ # @param [Rack::Request] request The incoming HTTP request to verify.
30
+ # @return [SignatureVerificationResult] The result of the signature verification.
31
+ def verify(request)
32
+ @verifier.verify(request)
33
+ end
34
+
35
+ # Verify the request signature and parse the event.
36
+ #
37
+ # @param [Rack::Request] request The incoming HTTP request containing the event payload.
38
+ # @return[PaymentCallback, FulfillmentCallback,
39
+ # SignatureVerificationFailure, UnknownEvent]
40
+ # PaymentCallback, FulfillmentCallback for successful parsing;
41
+ #
42
+ # SignatureVerificationFailure when signature fails;
43
+ # UnknownEvent for
44
+ # unknown events.
45
+ def verify_and_parse_event(request)
46
+ unless request.respond_to?(:env) && request.env.is_a?(Hash)
47
+ return SignatureVerificationFailure.new(['Invalid request env.'])
48
+ end
49
+
50
+ raw_body = RackRequestHelper.read_raw_body(request)
51
+ return SignatureVerificationFailure.new(['Invalid request body.']) if raw_body.nil? || raw_body.empty?
52
+
53
+ verification_result = verify(request)
54
+ return SignatureVerificationFailure.new(verification_result.errors) unless verification_result.ok
55
+
56
+ # Deserialize payload
57
+ begin
58
+ union = UnionTypeLookUp.get(:CallbacksA)
59
+ raw = RackRequestHelper.read_raw_body(request)
60
+ APIHelper.deserialize_union_type(union, raw, false, true)
61
+ rescue StandardError => e
62
+ UnknownEvent.new(['Deserialization failed.', e.message])
63
+ end
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,78 @@
1
+ # webhooks_and_callbacks_api
2
+ #
3
+ # This file was automatically generated by
4
+ # APIMATIC v3.0 ( https://www.apimatic.io ).
5
+
6
+ module WebhooksAndCallbacksApi
7
+ # CallbacksBHandler is responsible for verifying request signatures
8
+ # and parsing incoming callbacksB events into strongly typed objects.
9
+ class CallbacksBHandler
10
+ include CoreLibrary
11
+ # Creates a new instance of the CallbacksBHandler.
12
+ # Initializes the handler.
13
+ # @param [String] secret_key
14
+ # The secret used to generate and validate HMAC signatures for verifying request authenticity.
15
+ # @raise [ArgumentError] If the secret_key is not provided.
16
+ def initialize(secret_key)
17
+ raise ArgumentError, 'secret_key must be provided for signature verification.' unless secret_key
18
+
19
+ @verifier = HmacSignatureVerifier.new(
20
+ secret_key: secret_key,
21
+ signature_header: 'X-Signature',
22
+ hash_algorithm: 'sha256',
23
+ encoder: HexEncoder.new,
24
+ canonical_message_builder: method(:_canonical_message_builder)
25
+ )
26
+ end
27
+
28
+ # Perform signature verification and return the result.
29
+ #
30
+ # @param [Rack::Request] request The incoming HTTP request to verify.
31
+ # @return [SignatureVerificationResult] The result of the signature verification.
32
+ def verify(request)
33
+ @verifier.verify(request)
34
+ end
35
+
36
+ # Verify the request signature and parse the event.
37
+ #
38
+ # @param [Rack::Request] request The incoming HTTP request containing the event payload.
39
+ # @return[NotificationCallback, SignatureVerificationFailure, UnknownEvent]
40
+ # NotificationCallback for successful parsing;
41
+ #
42
+ # SignatureVerificationFailure when signature fails;
43
+ # UnknownEvent for
44
+ # unknown events.
45
+ def verify_and_parse_event(request)
46
+ unless request.respond_to?(:env) && request.env.is_a?(Hash)
47
+ return SignatureVerificationFailure.new(['Invalid request env.'])
48
+ end
49
+
50
+ raw_body = RackRequestHelper.read_raw_body(request)
51
+ return SignatureVerificationFailure.new(['Invalid request body.']) if raw_body.nil? || raw_body.empty?
52
+
53
+ verification_result = verify(request)
54
+ return SignatureVerificationFailure.new(verification_result.errors) unless verification_result.ok
55
+
56
+ # Deserialize payload
57
+ begin
58
+ union = UnionTypeLookUp.get(:CallbacksB)
59
+ raw = RackRequestHelper.read_raw_body(request)
60
+ APIHelper.deserialize_union_type(union, raw, false, true)
61
+ rescue StandardError => e
62
+ UnknownEvent.new(['Deserialization failed.', e.message])
63
+ end
64
+ end
65
+
66
+ # Builds the canonical message from the request for the signature verification.
67
+ #
68
+ # @param [Rack::Request] request The incoming HTTP request.
69
+ # @return [String, nil] The canonical message as a string, or nil if it could not be constructed.
70
+ def _canonical_message_builder(request)
71
+ payload = RackRequestHelper.read_raw_body(request)
72
+ notification_type = JsonPointerHelper.get_value_by_json_pointer(
73
+ APIHelper.json_deserialize(payload), 'notificationType'
74
+ )
75
+ notification_type.to_s
76
+ end
77
+ end
78
+ end
@@ -0,0 +1,33 @@
1
+ # webhooks_and_callbacks_api
2
+ #
3
+ # This file was automatically generated by
4
+ # APIMATIC v3.0 ( https://www.apimatic.io ).
5
+
6
+ module WebhooksAndCallbacksApi
7
+ # Represents a signature verification failure.
8
+ # @param errors [Array<String>] List of error messages describing why verification failed.
9
+ class SignatureVerificationFailure
10
+ # @return [Array<String>]
11
+ attr_reader :errors
12
+
13
+ # Initialize with the list of errors.
14
+ # @param errors [Array<String>] Error messages that caused the failure.
15
+ def initialize(errors)
16
+ @errors = errors
17
+ end
18
+
19
+ # Provides a user-friendly string representation of the failure.
20
+ # @return [String]
21
+ def to_s
22
+ class_name = self.class.name.split('::').last
23
+ "<#{class_name} errors: #{@errors}>"
24
+ end
25
+
26
+ # Provides a debugging-friendly string with detailed object information.
27
+ # @return [String]
28
+ def inspect
29
+ class_name = self.class.name.split('::').last
30
+ "<#{class_name} errors: #{@errors.inspect}>"
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,14 @@
1
+ # webhooks_and_callbacks_api
2
+ #
3
+ # This file was automatically generated by
4
+ # APIMATIC v3.0 ( https://www.apimatic.io ).
5
+
6
+ module WebhooksAndCallbacksApi
7
+ # Outcome of signature verification.
8
+ # @!attribute [r] ok
9
+ # @return [Boolean] True if the signature verification passed.
10
+ # @!attribute [r] errors
11
+ # @return [Array<String>, nil] Optional list of errors raised by the verifier. None when ok=true.
12
+ class SignatureVerificationResult < CoreLibrary::SignatureVerificationResult
13
+ end
14
+ end
@@ -0,0 +1,32 @@
1
+ # webhooks_and_callbacks_api
2
+ #
3
+ # This file was automatically generated by
4
+ # APIMATIC v3.0 ( https://www.apimatic.io ).
5
+
6
+ module WebhooksAndCallbacksApi
7
+ # Represents an unrecognized or unsupported event during processing.
8
+ class UnknownEvent
9
+ # @return [Array<String>]
10
+ attr_reader :errors
11
+
12
+ # Initialize with the errors that caused the failure.
13
+ # @param errors [Array<String>] A list of error messages describing the reasons for verification failure.
14
+ def initialize(errors)
15
+ @errors = errors
16
+ end
17
+
18
+ # Provides a user-friendly string representation of the failure.
19
+ # @return [String]
20
+ def to_s
21
+ class_name = self.class.name.split('::').last
22
+ "<#{class_name} errors: #{@errors}>"
23
+ end
24
+
25
+ # Provides a debugging-friendly string with detailed object information.
26
+ # @return [String]
27
+ def inspect
28
+ class_name = self.class.name.split('::').last
29
+ "<#{class_name} errors: #{@errors.inspect}>"
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,67 @@
1
+ # webhooks_and_callbacks_api
2
+ #
3
+ # This file was automatically generated by
4
+ # APIMATIC v3.0 ( https://www.apimatic.io ).
5
+
6
+ module WebhooksAndCallbacksApi
7
+ # WebhooksAHandler is responsible for verifying request signatures
8
+ # and parsing incoming webhooksA events into strongly typed objects.
9
+ class WebhooksAHandler
10
+ include CoreLibrary
11
+ # Creates a new instance of the WebhooksAHandler.
12
+ # Initializes the handler.
13
+ # @param [String] secret_key
14
+ # The secret used to generate and validate HMAC signatures for verifying request authenticity.
15
+ # @raise [ArgumentError] If the secret_key is not provided.
16
+ def initialize(secret_key)
17
+ raise ArgumentError, 'secret_key must be provided for signature verification.' unless secret_key
18
+
19
+ @verifier = HmacSignatureVerifier.new(
20
+ secret_key: secret_key,
21
+ signature_header: 'X-Signature',
22
+ hash_algorithm: 'sha256',
23
+ encoder: HexEncoder.new,
24
+ signature_value_template: 'sha256={digest}'
25
+ )
26
+ end
27
+
28
+ # Perform signature verification and return the result.
29
+ #
30
+ # @param [Rack::Request] request The incoming HTTP request to verify.
31
+ # @return [SignatureVerificationResult] The result of the signature verification.
32
+ def verify(request)
33
+ @verifier.verify(request)
34
+ end
35
+
36
+ # Verify the request signature and parse the event.
37
+ #
38
+ # @param [Rack::Request] request The incoming HTTP request containing the event payload.
39
+ # @return[PaymentStatusUpdatedEvent, PaymentStatusCreatedEvent,
40
+ # SignatureVerificationFailure, UnknownEvent]
41
+ # PaymentStatusUpdatedEvent, PaymentStatusCreatedEvent for successful
42
+ # parsing;
43
+ # SignatureVerificationFailure when signature fails;
44
+ #
45
+ # UnknownEvent for unknown events.
46
+ def verify_and_parse_event(request)
47
+ unless request.respond_to?(:env) && request.env.is_a?(Hash)
48
+ return SignatureVerificationFailure.new(['Invalid request env.'])
49
+ end
50
+
51
+ raw_body = RackRequestHelper.read_raw_body(request)
52
+ return SignatureVerificationFailure.new(['Invalid request body.']) if raw_body.nil? || raw_body.empty?
53
+
54
+ verification_result = verify(request)
55
+ return SignatureVerificationFailure.new(verification_result.errors) unless verification_result.ok
56
+
57
+ # Deserialize payload
58
+ begin
59
+ union = UnionTypeLookUp.get(:WebhooksA)
60
+ raw = RackRequestHelper.read_raw_body(request)
61
+ APIHelper.deserialize_union_type(union, raw, false, true)
62
+ rescue StandardError => e
63
+ UnknownEvent.new(['Deserialization failed.', e.message])
64
+ end
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,86 @@
1
+ # webhooks_and_callbacks_api
2
+ #
3
+ # This file was automatically generated by
4
+ # APIMATIC v3.0 ( https://www.apimatic.io ).
5
+
6
+ module WebhooksAndCallbacksApi
7
+ # WebhooksBHandler is responsible for verifying request signatures
8
+ # and parsing incoming webhooksB events into strongly typed objects.
9
+ class WebhooksBHandler
10
+ include CoreLibrary
11
+ # Creates a new instance of the WebhooksBHandler.
12
+ # Initializes the handler.
13
+ # @param [String] secret_key
14
+ # The secret used to generate and validate HMAC signatures for verifying request authenticity.
15
+ # @raise [ArgumentError] If the secret_key is not provided.
16
+ def initialize(secret_key)
17
+ raise ArgumentError, 'secret_key must be provided for signature verification.' unless secret_key
18
+
19
+ @verifier = HmacSignatureVerifier.new(
20
+ secret_key: secret_key,
21
+ signature_header: 'X-Webhook-Signature',
22
+ hash_algorithm: 'sha512',
23
+ encoder: Base64Encoder.new,
24
+ signature_value_template: 'v1={digest}',
25
+ canonical_message_builder: method(:_canonical_message_builder)
26
+ )
27
+ end
28
+
29
+ # Perform signature verification and return the result.
30
+ #
31
+ # @param [Rack::Request] request The incoming HTTP request to verify.
32
+ # @return [SignatureVerificationResult] The result of the signature verification.
33
+ def verify(request)
34
+ @verifier.verify(request)
35
+ end
36
+
37
+ # Verify the request signature and parse the event.
38
+ #
39
+ # @param [Rack::Request] request The incoming HTTP request containing the event payload.
40
+ # @return[UserActionNotificationEvent, UserStatusNotificationEvent,
41
+ # UserPreferenceNotificationEvent, SystemAlertNotificationEvent,
42
+ # SystemMaintenanceNotificationEvent, SystemPerformanceNotificationEvent,
43
+ # InventoryStockIncreaseEvent, InventoryStockDecreaseEvent,
44
+ # InventoryStockDepletedEvent, SignatureVerificationFailure, UnknownEvent]
45
+ # UserActionNotificationEvent, UserStatusNotificationEvent,
46
+ # UserPreferenceNotificationEvent, SystemAlertNotificationEvent,
47
+ # SystemMaintenanceNotificationEvent, SystemPerformanceNotificationEvent,
48
+ # InventoryStockIncreaseEvent, InventoryStockDecreaseEvent,
49
+ # InventoryStockDepletedEvent for successful parsing;
50
+ #
51
+ # SignatureVerificationFailure when signature fails;
52
+ # UnknownEvent for
53
+ # unknown events.
54
+ def verify_and_parse_event(request)
55
+ unless request.respond_to?(:env) && request.env.is_a?(Hash)
56
+ return SignatureVerificationFailure.new(['Invalid request env.'])
57
+ end
58
+
59
+ raw_body = RackRequestHelper.read_raw_body(request)
60
+ return SignatureVerificationFailure.new(['Invalid request body.']) if raw_body.nil? || raw_body.empty?
61
+
62
+ verification_result = verify(request)
63
+ return SignatureVerificationFailure.new(verification_result.errors) unless verification_result.ok
64
+
65
+ # Deserialize payload
66
+ begin
67
+ union = UnionTypeLookUp.get(:WebhooksB)
68
+ raw = RackRequestHelper.read_raw_body(request)
69
+ APIHelper.deserialize_union_type(union, raw, false, true)
70
+ rescue StandardError => e
71
+ UnknownEvent.new(['Deserialization failed.', e.message])
72
+ end
73
+ end
74
+
75
+ # Builds the canonical message from the request for the signature verification.
76
+ #
77
+ # @param [Rack::Request] request The incoming HTTP request.
78
+ # @return [String, nil] The canonical message as a string, or nil if it could not be constructed.
79
+ def _canonical_message_builder(request)
80
+ payload = RackRequestHelper.read_raw_body(request)
81
+ method = request.request_method
82
+ x_timestamp = request.get_header(RackRequestHelper.prepend_header('X-Timestamp'))
83
+ "#{method}|#{x_timestamp}|#{payload}"
84
+ end
85
+ end
86
+ end
@@ -0,0 +1,79 @@
1
+ # webhooks_and_callbacks_api
2
+ #
3
+ # This file was automatically generated by
4
+ # APIMATIC v3.0 ( https://www.apimatic.io ).
5
+
6
+ module WebhooksAndCallbacksApi
7
+ # WebhooksCHandler is responsible for verifying request signatures
8
+ # and parsing incoming webhooksC events into strongly typed objects.
9
+ class WebhooksCHandler
10
+ include CoreLibrary
11
+ # Creates a new instance of the WebhooksCHandler.
12
+ # Initializes the handler.
13
+ # @param [String] secret_key
14
+ # The secret used to generate and validate HMAC signatures for verifying request authenticity.
15
+ # @raise [ArgumentError] If the secret_key is not provided.
16
+ def initialize(secret_key)
17
+ raise ArgumentError, 'secret_key must be provided for signature verification.' unless secret_key
18
+
19
+ @verifier = HmacSignatureVerifier.new(
20
+ secret_key: secret_key,
21
+ signature_header: 'X-Webhook-Signature',
22
+ hash_algorithm: 'sha512',
23
+ encoder: Base64UrlEncoder.new,
24
+ signature_value_template: 'v1={digest}',
25
+ canonical_message_builder: method(:_canonical_message_builder)
26
+ )
27
+ end
28
+
29
+ # Perform signature verification and return the result.
30
+ #
31
+ # @param [Rack::Request] request The incoming HTTP request to verify.
32
+ # @return [SignatureVerificationResult] The result of the signature verification.
33
+ def verify(request)
34
+ @verifier.verify(request)
35
+ end
36
+
37
+ # Verify the request signature and parse the event.
38
+ #
39
+ # @param [Rack::Request] request The incoming HTTP request containing the event payload.
40
+ # @return[String, Integer, Array<Float>, Hash[String, String],
41
+ # SignatureVerificationFailure, UnknownEvent]
42
+ # String, Integer, Array[Float], Hash[String, String] for successful
43
+ # parsing;
44
+ # SignatureVerificationFailure when signature fails;
45
+ #
46
+ # UnknownEvent for unknown events.
47
+ def verify_and_parse_event(request)
48
+ unless request.respond_to?(:env) && request.env.is_a?(Hash)
49
+ return SignatureVerificationFailure.new(['Invalid request env.'])
50
+ end
51
+
52
+ raw_body = RackRequestHelper.read_raw_body(request)
53
+ return SignatureVerificationFailure.new(['Invalid request body.']) if raw_body.nil? || raw_body.empty?
54
+
55
+ verification_result = verify(request)
56
+ return SignatureVerificationFailure.new(verification_result.errors) unless verification_result.ok
57
+
58
+ # Deserialize payload
59
+ begin
60
+ union = UnionTypeLookUp.get(:WebhooksC)
61
+ raw = RackRequestHelper.read_raw_body(request)
62
+ APIHelper.deserialize_union_type(union, raw, false, true)
63
+ rescue StandardError => e
64
+ UnknownEvent.new(['Deserialization failed.', e.message])
65
+ end
66
+ end
67
+
68
+ # Builds the canonical message from the request for the signature verification.
69
+ #
70
+ # @param [Rack::Request] request The incoming HTTP request.
71
+ # @return [String, nil] The canonical message as a string, or nil if it could not be constructed.
72
+ def _canonical_message_builder(request)
73
+ payload = RackRequestHelper.read_raw_body(request)
74
+ method = request.request_method
75
+ x_timestamp = request.get_header(RackRequestHelper.prepend_header('X-Timestamp'))
76
+ "#{method}|#{x_timestamp}|#{payload}"
77
+ end
78
+ end
79
+ end