Sha256: b865e1353882ac881304d22a807eb566d386fe2835d44248c2a9785e7d58ffe8

Contents?: true

Size: 713 Bytes

Versions: 9

Compression:

Stored size: 713 Bytes

Contents

require 'openssl'
require 'multi_json'

module AtPay
  class Hook
    def initialize(session, details, signature)
      @session   = session
      @details   = details
      @signature = signature

      verify_signature!
      verify_success!
    end

    def details
      MultiJson.load(@details)
    end

    private
    def verify_signature!
      unless OpenSSL::HMAC.hexdigest('sha1', @session.private_key, @details) == @signature
        raise InvalidSignatureError
      end
    end

    def verify_success!
      if @details['type'] == 'error'
        raise Error.new(@details['error'])
      elsif @details['type'] == 'fatal'
        raise FatalError.new(@details['error'])
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
atpay_ruby-0.0.17 lib/atpay/hook.rb
atpay_ruby-0.0.16 lib/atpay/hook.rb
atpay_ruby-0.0.15 lib/atpay/hook.rb
atpay_ruby-0.0.13 lib/atpay/hook.rb
atpay_ruby-0.0.12 lib/atpay/hook.rb
atpay_ruby-0.0.11 lib/atpay/hook.rb
atpay_ruby-0.0.10 lib/atpay/hook.rb
atpay_ruby-0.0.9 lib/atpay/hook.rb
atpay_ruby-0.0.8 lib/atpay/hook.rb