Method: Stripe::Webhook::Signature.generate_header

Defined in:
lib/stripe/webhook.rb

.generate_header(timestamp, signature, scheme: EXPECTED_SCHEME) ⇒ Object

Compute the Stripe-Signature header for a given webhook body & secret. Useful for signing payloads in unit tests.

Raises:

  • (ArgumentError)


91
92
93
94
95
96
97
98
99
100
# File 'lib/stripe/webhook.rb', line 91

def self.generate_header(timestamp, signature, scheme: EXPECTED_SCHEME)
  raise ArgumentError, "timestamp should be an instance of Time" \
    unless timestamp.is_a?(Time)
  raise ArgumentError, "signature should be a string" \
    unless signature.is_a?(String)
  raise ArgumentError, "scheme should be a string" \
    unless scheme.is_a?(String)

  "t=#{timestamp.to_i},#{scheme}=#{signature}"
end