Class: Omnipay::Signer

Inherits:
Object
  • Object
show all
Defined in:
lib/omnipay/signer.rb

Overview

Class responsible for computing a signature of a payment.

Instance Method Summary collapse

Constructor Details

#initialize(transaction_id, amount, context) ⇒ Signer

Parameters:

  • transaction_id (String)

    the transactions’s unique identifier

  • amount (Integer)

    the amount **in cents** of the transaction

  • context (Hash)

    the transaction’s context hash



12
13
14
15
16
# File 'lib/omnipay/signer.rb', line 12

def initialize(transaction_id, amount, context)
  @transaction_id = transaction_id
  @amount = amount
  @context = context || {}
end

Instance Method Details

#signatureString

Actually computes the signature

Returns:

  • (String)

    The computed signature



20
21
22
23
# File 'lib/omnipay/signer.rb', line 20

def signature
  to_sign = "#{secret_token}:#{@transaction_id}:#{@amount}:#{self.class.hash_to_string @context}"
  CGI.escape(Base64.encode64(OpenSSL::HMAC.digest('sha1', secret_token, to_sign)))
end