Class: TrustPayRails::Signature
- Inherits:
-
Object
- Object
- TrustPayRails::Signature
- Defined in:
- lib/trust_pay_rails/signature.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(key) ⇒ Signature
constructor
A new instance of Signature.
-
#sign(data = {}) ⇒ Object
FIXME: use ruby 2.1 required arguments when we switch.
- #signature_match?(data = {}) ⇒ Boolean
Constructor Details
#initialize(key) ⇒ Signature
Returns a new instance of Signature.
14 15 16 |
# File 'lib/trust_pay_rails/signature.rb', line 14 def initialize(key) @key = key end |
Class Method Details
.sign(data = {}) ⇒ Object
6 7 8 |
# File 'lib/trust_pay_rails/signature.rb', line 6 def self.sign(data={}) new(TrustPayRails.key).sign(data) end |
.signature_match?(data) ⇒ Boolean
10 11 12 |
# File 'lib/trust_pay_rails/signature.rb', line 10 def self.signature_match?(data) new(TrustPayRails.key).signature_match?(data) end |
Instance Method Details
#sign(data = {}) ⇒ Object
FIXME: use ruby 2.1 required arguments when we switch
19 20 21 |
# File 'lib/trust_pay_rails/signature.rb', line 19 def sign(data={}) hmac_sha_256(@key, data.slice(:aid, :typ, :amt, :cur, :ref, :res, :tid, :oid, :tss).values.join).upcase end |
#signature_match?(data = {}) ⇒ Boolean
23 24 25 |
# File 'lib/trust_pay_rails/signature.rb', line 23 def signature_match?(data={}) sign(data) == data[:sig] end |