Method: Stripe::Webhook::Signature.compute_signature

Defined in:
lib/stripe/webhook.rb

.compute_signature(timestamp, payload, secret) ⇒ Object

Computes a webhook signature given a time (probably the current time), a payload, and a signing secret.

Raises:

  • (ArgumentError)


76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/stripe/webhook.rb', line 76

def self.compute_signature(timestamp, payload, secret)
  raise ArgumentError, "timestamp should be an instance of Time" \
    unless timestamp.is_a?(Time)
  raise ArgumentError, "payload should be a string" \
    unless payload.is_a?(String)
  raise ArgumentError, "secret should be a string" \
    unless secret.is_a?(String)

  timestamped_payload = "#{timestamp.to_i}.#{payload}"
  OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new("sha256"), secret,
                          timestamped_payload)
end