Class: ActionController::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/versapay/webhooks.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.check_versapay_signatures(key, *args) ⇒ Object



6
7
8
# File 'lib/versapay/webhooks.rb', line 6

def self.check_versapay_signatures(key, *args)
  before_filter lambda { |controller| controller.check_versapay_signature(key, controller)}, *args
end

Instance Method Details

#check_versapay_signature(key, controller) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/versapay/webhooks.rb', line 10

def check_versapay_signature(key, controller)
  # Save the signature first
  signature = controller.request.parameters["signature"]

  # Only want the parameters passed from VP, and no sig
  params = controller.request.parameters.dup
  ["action", "controller", "signature"].each { |k| params.delete(k) }

  url = controller.request.url.gsub /\?.*/, ""
  check = Versapay::WebhookSignature.hmac(controller.request.method, url, key, params)

  if check == signature
    true
  else
    raise Versapay::InvalidWebhookSignature
  end
end