Class: SquareEvent::Webhook

Inherits:
Object
  • Object
show all
Defined in:
lib/square_event/webhook.rb

Defined Under Namespace

Modules: Signature

Class Method Summary collapse

Class Method Details

.construct_event(payload, signature, secret, notification_url, environment, timestamp) ⇒ Object

Initializes an webook Event object from a JSON payload.

TODO: raise JSON::ParserError if the payload is not valid JSON, or SignatureVerificationError if the signature verification fails.



8
9
10
11
12
13
14
# File 'lib/square_event/webhook.rb', line 8

def self.construct_event(payload, signature, secret, notification_url, environment, timestamp)

  Signature.verify_header(payload, signature, secret, notification_url)

  data = JSON.parse(payload, symbolize_names: true)
  Event.construct_from(data, environment, timestamp)
end