Class: DIBS::HMAC
- Inherits:
-
Object
- Object
- DIBS::HMAC
- Defined in:
- lib/dibs/hmac.rb
Constant Summary collapse
- DIBS_PARAM_NAMES =
Params taken from the below urls. 2013-10-17 tech.dibs.dk/integration_methods/dibs_payment_window/parameters/ tech.dibs.dk/integration_methods/dibs_payment_window/return_pages/
%{ 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 }.strip.split("\n").map {|name| name.strip }
Class Method Summary collapse
Class Method Details
.calculate(params, key) ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/dibs/hmac.rb', line 74 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
87 88 89 |
# File 'lib/dibs/hmac.rb', line 87 def self.valid?(params, key) params['MAC'] || params[:MAC] == calculate(params, key) end |