Class: Webhookdb::Stripe

Inherits:
Object
  • Object
show all
Extended by:
MethodUtilities
Includes:
Appydays::Configurable, Appydays::Loggable
Defined in:
lib/webhookdb/stripe.rb

Class Method Summary collapse

Methods included from MethodUtilities

attr_predicate, attr_predicate_accessor, singleton_attr_accessor, singleton_attr_reader, singleton_attr_writer, singleton_method_alias, singleton_predicate_accessor, singleton_predicate_reader

Class Method Details

.webhook_response(request, webhook_secret) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/webhookdb/stripe.rb', line 18

def self.webhook_response(request, webhook_secret)
  auth = request.env["HTTP_STRIPE_SIGNATURE"]

  return Webhookdb::WebhookResponse.error("missing hmac") if auth.nil?

  request.body.rewind
  request_data = request.body.read

  begin
    Stripe::Webhook.construct_event(
      request_data, auth, webhook_secret,
    )
  rescue Stripe::SignatureVerificationError => e
    self.logger.warn "stripe_signature_verification_error", message: e.to_s
    return Webhookdb::WebhookResponse.error("invalid hmac")
  end

  return Webhookdb::WebhookResponse.ok
end