Sha256: 8e125a7b110767d9bc4fc3864d8d2a159c500580426a43e267fc263d4bb18d49
Contents?: true
Size: 1.2 KB
Versions: 1
Compression:
Stored size: 1.2 KB
Contents
require "openssl" require "digest" module Revolut class WebhookEvent < Resource shallow # do not allow any resource operations on this resource # Constructs a new instance of the WebhookEvent class from a request object and a signing secret. # # @param request [ActionDispatch::Request] The request object containing the webhook event data. # @param signing_secret [String] The signing secret used to verify the signature of the webhook event. # @return [WebhookEvent] A new instance of the WebhookEvent class. # @raise [Revolut::SignatureVerificationError] If the signature verification fails. def self.construct_from(request, signing_secret) json = request.body.read timestamp = request.headers["Revolut-Request-Timestamp"] header_signature = request.headers["Revolut-Signature"] payload_to_sign = "v1.#{timestamp}.#{json}" digest = OpenSSL::Digest.new("sha256") signature_digest = "v1=" + OpenSSL::HMAC.hexdigest(digest, signing_secret, payload_to_sign) if signature_digest == header_signature new(JSON.parse(json)) else raise Revolut::SignatureVerificationError, "Signature verification failed" end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
revolut-connect-0.1.5 | lib/revolut/resources/webhook_event.rb |