Class: DIBS::HMAC

Inherits:
Object
  • Object
show all
Defined in:
lib/dibs/hmac.rb

Constant Summary collapse

DIBS_PARAM_NAMES =
%{
  currency
  merchant
  amount
  orderId
  acceptReturnUrl
  oiTypes
  oiNames
  billingFirstName
  billingLastName
  billingAddress
  billingAddress2
  billingPostalCode
  billingPostalPlace
  billingEmail
  billingMobile
  cancelReturnUrl
  callbackUrl
  language
  addFee
  payType
  capturenow
  shippingFirstName
  shippingLastName
  shippingAddress
  shippingAddress2
  shippingPostalCode
  shippingPostalPlace
  socialSecurityNumber
  createTicket
  createTicketAndAuth
  test
  account
  status
  amount
  currency
  transaction
  actionCode
  acquirer
  cardNumberMasked
  expMonth
  expYear
  cardTypeName
  captureStatus
  status3D
  ECI
  enrollStatus
  xidPresent
  ticket
  ticketStatus
  fee
  verificationIdPresent
  validationErrors
  acquirerOrderId
  acquirerCustomerId
  acquirerFirstName
  acquirerLastName
  acquirerDeliveryAddress
  acquirerDeliveryPostalCode
  acquirerDeliveryPostalPlace
  acquirerDeliveryCountryCode
  expandOrderInformation
  ticketId
  merchantId
}.strip.split("\n").map {|name| name.strip }

Class Method Summary collapse

Class Method Details

.calculate(params, key) ⇒ Object



77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/dibs/hmac.rb', line 77

def self.calculate(params, key)
  param_string = ""
  params.keys.sort.each do |key|
    if DIBS_PARAM_NAMES.include?(key.to_s) || key.to_s.start_with?("s_") || key.to_s.match(/oiRow[0-9]+/)
      value = params[key]
      param_string += "&" if param_string.length > 0
      param_string += "#{key}=#{value}"
    end
  end

  OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new('sha256'),Array(key).pack('H*'), param_string)
end

.valid?(params, key) ⇒ Boolean

Returns:

  • (Boolean)


90
91
92
# File 'lib/dibs/hmac.rb', line 90

def self.valid?(params, key)
  params['MAC'] || params[:MAC] == calculate(params, key)
end