Module: ActiveMerchant::Billing::Integrations::Pizza::Common

Included in:
SampoEst::Helper, SampoEst::Notification, SebEst::Helper, SebEst::Notification, SwedbankEst::Helper, SwedbankEst::Notification
Defined in:
lib/active_merchant/billing/integrations/pizza.rb

Overview

Calculation using method VK_VERSION=008: VK_MAC is RSA signature of the request fields coded into BASE64. VK_MAC will be calculated using secret key of the sender using RSA. Signature will be calculated for string that consists of all field lengths and contents in the query. Also empty fields are used in calculation – lenght “000”. Unnumbered (optional) fields are not used in calculation. MAC(x1,x2,…,xn) := RSA( SHA-1(p(x1 )|| x1|| p(x2 )|| x2 || … ||p( xn )||xn),d,n) where: || is string concatenation mark x1, x2, …, xn are parameters of the query p(x) is length of the field x represented by three digits d is RSA secret exponent n is RSA modulus

Instance Method Summary collapse

Instance Method Details

#func_p(val) ⇒ Object

p(x) is length of the field x represented by three digits



85
86
87
# File 'lib/active_merchant/billing/integrations/pizza.rb', line 85

def func_p(val)
  sprintf("%03i", val.size)
end

#generate_data_string(service_msg_number, sigparams) ⇒ Object

Generate a string to be signed out of service message parameters. p(x1 )|| x1|| p(x2 )|| x2 || … ||p( xn )||xn || is string concatenation mark p(x) is length of the field x represented by three digits Parameters val1, val2, value3 would be turned into: ‘003val1003val2006value3’



95
96
97
98
99
100
101
102
# File 'lib/active_merchant/billing/integrations/pizza.rb', line 95

def generate_data_string(service_msg_number, sigparams)
  str = ''
  Pizza.required_service_params[Integer(service_msg_number)].each do |param|
    val = sigparams[param].to_s # nil goes to ''
    str << func_p(val) << val
  end
  str
end

#generate_mac(service_msg_number, sigparams) ⇒ Object



109
110
111
# File 'lib/active_merchant/billing/integrations/pizza.rb', line 109

def generate_mac(service_msg_number, sigparams)
  Base64.encode64(generate_signature(service_msg_number, sigparams)).gsub(/\n/,'')
end

#generate_signature(service_msg_number, sigparams) ⇒ Object



104
105
106
107
# File 'lib/active_merchant/billing/integrations/pizza.rb', line 104

def generate_signature(service_msg_number, sigparams)
  privkey = self.class.parent.get_private_key
  privkey.sign(OpenSSL::Digest::SHA1.new, generate_data_string(service_msg_number, sigparams))
end