Class: ActiveMerchant::Billing::Integrations::Allpay::Helper

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Helper.



92
93
94
95
96
# File 'lib/active_merchant/billing/integrations/allpay/helper.rb', line 92

def initialize(order, , options = {})
  super
  add_field 'MerchantID', ActiveMerchant::Billing::Integrations::Allpay.merchant_id
  add_field 'PaymentType', ActiveMerchant::Billing::Integrations::Allpay::PAYMENT_TYPE
end

Class Method Details

.url_encode(text) ⇒ Object

Allpay .NET url encoding Code based from CGI.escape() Some special characters (e.g. “()*!”) are not escaped on Allpay server when they generate their check sum value, causing CheckMacValue Error.

TODO: The following characters still cause CheckMacValue error:

'<', "\n", "\r", '&'


124
125
126
127
128
129
130
131
# File 'lib/active_merchant/billing/integrations/allpay/helper.rb', line 124

def self.url_encode(text)
  text = text.dup
  text.gsub!(/([^ a-zA-Z0-9\(\)\!\*_.-]+)/) do
    '%' + $1.unpack('H2' * $1.bytesize).join('%')
  end
  text.tr!(' ', '+')
  text
end

Instance Method Details

#encrypted_dataObject



102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/active_merchant/billing/integrations/allpay/helper.rb', line 102

def encrypted_data

  raw_data = @fields.sort.map{|field, value|
    # utf8, authenticity_token, commit are generated from form helper, needed to skip
    "#{field}=#{value}" if field!='utf8' && field!='authenticity_token' && field!='commit'
  }.join('&')

  hash_raw_data = "HashKey=#{ActiveMerchant::Billing::Integrations::Allpay.hash_key}&#{raw_data}&HashIV=#{ActiveMerchant::Billing::Integrations::Allpay.hash_iv}"
  url_encode_data = self.class.url_encode(hash_raw_data)
  url_encode_data.downcase!

  binding.pry if ActiveMerchant::Billing::Integrations::Allpay.debug

  add_field 'CheckMacValue', Digest::MD5.hexdigest(url_encode_data).upcase
end

#merchant_trade_date(date) ⇒ Object



98
99
100
# File 'lib/active_merchant/billing/integrations/allpay/helper.rb', line 98

def merchant_trade_date(date)
  add_field 'MerchantTradeDate', date.strftime('%Y/%m/%d %H:%M:%S')
end