class ActiveMerchant::Billing::Integrations::Allpay::Helper
Public Class Methods
new(order, account, options = {})
click to toggle source
Calls superclass method
# File lib/active_merchant/billing/integrations/allpay/helper.rb, line 92 def initialize(order, account, options = {}) super add_field 'MerchantID', ActiveMerchant::Billing::Integrations::Allpay.merchant_id add_field 'PaymentType', ActiveMerchant::Billing::Integrations::Allpay::PAYMENT_TYPE end
url_encode(text)
click to toggle source
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", '&'
# 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
Public Instance Methods
encrypted_data()
click to toggle source
# 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)
click to toggle source
# 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