Class: SignatureParameter

Inherits:
Object
  • Object
show all
Defined in:
lib/AuthenticationSDK/authentication/http/GetSignatureParameter.rb

Overview

This ID can be found on EBC portal*/

Instance Method Summary collapse

Instance Method Details

#generateSignatureParameter(merchantconfig_obj, gmtdatetime, log_obj) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/AuthenticationSDK/authentication/http/GetSignatureParameter.rb', line 16

def generateSignatureParameter(merchantconfig_obj, gmtdatetime, log_obj)
  request_type = merchantconfig_obj.requestType.upcase
  merchantSecretKey = merchantconfig_obj.merchantSecretKey
  signatureString = Constants::HOST + ': ' + merchantconfig_obj.requestHost
  signatureString << "\n"+ Constants::DATE + ': ' + gmtdatetime
  signatureString << "\n(request-target): "
  if request_type == Constants::GET_REQUEST_TYPE || request_type == Constants::DELETE_REQUEST_TYPE
    targetUrl=gettargetUrlForGetDelete(request_type,merchantconfig_obj)
    signatureString << targetUrl + "\n"
  elsif request_type == Constants::POST_REQUEST_TYPE || request_type == Constants::PUT_REQUEST_TYPE || request_type == Constants::PATCH_REQUEST_TYPE
    targetUrl=gettargetUrlForPutPost(request_type,merchantconfig_obj)
    signatureString << targetUrl + "\n"
    payload = merchantconfig_obj.requestJsonData
    digest = DigestGeneration.new.generateDigest(payload, log_obj)
    digest_payload = Constants::SHA256 + digest
    signatureString << Constants::DIGEST + ': ' + digest_payload + "\n"
  end
  signatureString << Constants::V_C_MERCHANT_ID + ': ' + merchantconfig_obj.merchantId
  encodedSignatureString = signatureString.force_encoding(Encoding::UTF_8)
  decodedKey = Base64.decode64(merchantSecretKey)
  base64EncodedSignature = Base64.strict_encode64(OpenSSL::HMAC.digest('sha256', decodedKey, encodedSignatureString))
  return base64EncodedSignature
rescue StandardError => err
  log_obj.logger.error(err.message)
  log_obj.logger.error(err.backtrace)
  puts 'Check log for more details.'
  exit!
end

#gettargetUrlForGetDelete(request_type, merchantconfig_obj) ⇒ Object



44
45
46
47
48
49
50
51
52
# File 'lib/AuthenticationSDK/authentication/http/GetSignatureParameter.rb', line 44

def gettargetUrlForGetDelete(request_type, merchantconfig_obj)
  targetUrlForGetDelete = ''
  if request_type == Constants::DELETE_REQUEST_TYPE
    targetUrlForGetDelete = Constants::DELETE_REQUEST_TYPE_LOWER + ' ' + merchantconfig_obj.requestTarget
  elsif request_type == Constants::GET_REQUEST_TYPE
    targetUrlForGetDelete = Constants::GET_REQUEST_TYPE_LOWER + ' ' + merchantconfig_obj.requestTarget
  end
  return targetUrlForGetDelete
end

#gettargetUrlForPutPost(request_type, merchantconfig_obj) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
# File 'lib/AuthenticationSDK/authentication/http/GetSignatureParameter.rb', line 53

def gettargetUrlForPutPost(request_type, merchantconfig_obj)
  targetUrlForPutPost = ''
  if request_type == Constants::POST_REQUEST_TYPE
    targetUrlForPutPost = Constants::POST_REQUEST_TYPE_LOWER + ' ' + merchantconfig_obj.requestTarget
  elsif request_type == Constants::PUT_REQUEST_TYPE
    targetUrlForPutPost = Constants::PUT_REQUEST_TYPE_LOWER + ' ' + merchantconfig_obj.requestTarget
  elsif request_type == Constants::PATCH_REQUEST_TYPE
    targetUrlForPutPost = Constants::PATCH_REQUEST_TYPE_LOWER + ' ' + merchantconfig_obj.requestTarget
  end
  return targetUrlForPutPost
end