Class: UnivapayClientSdk::CustomsHandler
- Inherits:
-
Object
- Object
- UnivapayClientSdk::CustomsHandler
- Includes:
- CoreLibrary
- Defined in:
- lib/univapay_client_sdk/events/webhooks/customs_handler.rb
Overview
CustomsHandler is responsible for verifying request signatures and parsing incoming customs events into strongly typed objects.
Instance Method Summary collapse
-
#initialize ⇒ CustomsHandler
constructor
Creates a new instance of the CustomsHandler.
-
#parse_event(request) ⇒ Object
Parse the event.
Constructor Details
#initialize ⇒ CustomsHandler
Creates a new instance of the CustomsHandler.
12 |
# File 'lib/univapay_client_sdk/events/webhooks/customs_handler.rb', line 12 def initialize; end |
Instance Method Details
#parse_event(request) ⇒ Object
Parse the event.
@return[CustomsDeclarationWebhookCallback, UnknownEvent] CustomsDeclarationWebhookCallback for successful parsing;
UnknownEvent for unknown events.
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/univapay_client_sdk/events/webhooks/customs_handler.rb', line 21 def parse_event(request) return UnknownEvent.new(['Invalid request env.']) unless request.respond_to?(:env) && request.env.is_a?(Hash) raw_body = RackRequestHelper.read_raw_body(request) return UnknownEvent.new(['Invalid request body.']) if raw_body.nil? || raw_body.empty? # Deserialize payload begin union = UnionTypeLookUp.get(:Customs) raw = RackRequestHelper.read_raw_body(request) APIHelper.deserialize_union_type(union, raw, false, true) rescue StandardError => e UnknownEvent.new(['Deserialization failed.', e.]) end end |