Class: DkPaymentGateway::Signature

Inherits:
Object
  • Object
show all
Defined in:
lib/dk_payment_gateway/signature.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(private_key) ⇒ Signature

Returns a new instance of Signature.



13
14
15
# File 'lib/dk_payment_gateway/signature.rb', line 13

def initialize(private_key)
  @private_key = private_key
end

Instance Attribute Details

#private_keyObject (readonly)

Returns the value of attribute private_key.



11
12
13
# File 'lib/dk_payment_gateway/signature.rb', line 11

def private_key
  @private_key
end

Class Method Details

.generate(private_key, request_body) ⇒ Object

Convenience method to generate signature headers



66
67
68
# File 'lib/dk_payment_gateway/signature.rb', line 66

def generate(private_key, request_body)
  new(private_key).generate_headers(request_body)
end

Instance Method Details

#generate_headers(request_body) ⇒ Object

Generate signature headers for a request Returns a hash with DK-Signature, DK-Timestamp, and DK-Nonce



19
20
21
22
23
24
25
26
27
28
29
# File 'lib/dk_payment_gateway/signature.rb', line 19

def generate_headers(request_body)
  timestamp = generate_timestamp
  nonce = generate_nonce
  signature = sign_request(request_body, timestamp, nonce)

  {
    'DK-Signature' => "DKSignature #{signature}",
    'DK-Timestamp' => timestamp,
    'DK-Nonce' => nonce
  }
end