Module: ActiveMerchant::Billing::Integrations::Dwolla::Common

Included in:
Notification, Return
Defined in:
lib/active_merchant/billing/integrations/dwolla/common.rb

Instance Method Summary collapse

Instance Method Details

#verify_signature(checkoutId, amount, notification_signature, secret) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
# File 'lib/active_merchant/billing/integrations/dwolla/common.rb', line 8

def verify_signature(checkoutId, amount, notification_signature, secret)
  if secret.nil?
    raise ArgumentError, "You need to provide the Application secret as the option :credential3 to verify that the notification originated from Dwolla"
  end

  expected_signature = OpenSSL::HMAC.hexdigest(OpenSSL::Digest::SHA1.new, secret, "%s&%.2f" % [checkoutId, amount])

  if notification_signature != expected_signature
    raise StandardError, "Dwolla signature verification failed."
  end
end