Class: ActiveMerchant::Billing::Integrations::Adyen::Helper

Inherits:
Helper
  • Object
show all
Defined in:
lib/active_merchant/billing/integrations/adyen/helper.rb

Constant Summary collapse

SIGNATURE_FIELDS =

the values of these fields are concatenated, HMAC digested, Base64 encoded, and sent along with the POST data to make hoodwinkery difficult

[
  :paymentAmount,
  :currencyCode,
  :shipBeforeDate,
  :merchantReference,
  :skinCode,
  :merchantAccount,
  :sessionValidity,
]
ADDRESS_SIGNATURE_FIELDS =

same as above but for the customer’s street address, which is to be separately hashed, as specified by Adyen country should be ISO 3166-1 alpha-2 format, see en.wikipedia.org/wiki/ISO_3166-1_alpha-2 )

%w( billingAddress.street billingAddress.houseNumberOrName billingAddress.city billingAddress.postalCode billingAddress.stateOrProvince billingAddress.country )

Instance Attribute Summary

Attributes inherited from Helper

#fields

Instance Method Summary collapse

Methods inherited from Helper

#add_field, #add_fields, #billing_address, mapping, #shipping_address

Constructor Details

#initialize(order, account, options = {}) ⇒ Helper

Returns a new instance of Helper.



27
28
29
30
31
32
33
34
35
# File 'lib/active_merchant/billing/integrations/adyen/helper.rb', line 27

def initialize(order, , options = {})
  super
  add_field('currencyCode',    'USD')
  add_field('shipBeforeDate',  Date.today + 10)
  add_field('skinCode',        'notavalidskincode')
  add_field('shopperLocale',   'en_GB')
  add_field('orderData',       'orderData')
  add_field('sessionValidity', "#{ (Date.today + 10).to_s }T11:00:00Z" )
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class ActiveMerchant::Billing::Integrations::Helper

Instance Method Details

#form_fieldsObject



51
52
53
54
55
56
# File 'lib/active_merchant/billing/integrations/adyen/helper.rb', line 51

def form_fields
  @fields.merge!('merchantSig' => generate_signature)
  @fields.merge!('billingAddressSig' => generate_address_signature) if @billing_address
  @fields.merge!('orderData' => @order_data) if @order_data
  @fields
end

#generate_address_signature_stringObject



67
68
# File 'lib/active_merchant/billing/integrations/adyen/helper.rb', line 67

def generate_address_signature_string
end

#generate_signatureObject



62
63
64
65
# File 'lib/active_merchant/billing/integrations/adyen/helper.rb', line 62

def generate_signature
  digest = OpenSSL::HMAC.digest(OpenSSL::Digest::SHA1.new, @shared_secret, generate_signature_string)
  return Base64.encode64(digest).strip
end

#generate_signature_stringObject



58
59
60
# File 'lib/active_merchant/billing/integrations/adyen/helper.rb', line 58

def generate_signature_string
  SIGNATURE_FIELDS.map {|key| @fields[key.to_s]} * ""
end

#set_order_data(value) ⇒ Object

orderData is a string of HTML which is displayed along with the CC form it is GZipped, Base64 encoded, and sent along with the POST data



39
40
41
42
43
44
45
# File 'lib/active_merchant/billing/integrations/adyen/helper.rb', line 39

def set_order_data(value)
  str = StringIO.new
  gz = Zlib::GzipWriter.new str
  gz.write value
  gz.close
  @order_data = Base64.encode64(str.string()).gsub("\n","")
end

#shared_secret(value) ⇒ Object



47
48
49
# File 'lib/active_merchant/billing/integrations/adyen/helper.rb', line 47

def shared_secret(value)
  @shared_secret = value
end