class OffsitePayments::Integrations::Ecpay::Helper
Public Class Methods
new(order, account, options = {})
click to toggle source
Calls superclass method
# File lib/offsite_payments/integrations/ecpay/helper.rb, line 158 def initialize(order, account, options = {}) super add_field 'MerchantID', OffsitePayments::Integrations::Ecpay.merchant_id add_field 'PaymentType', OffsitePayments::Integrations::Ecpay::PAYMENT_TYPE end
url_encode(text)
click to toggle source
ecpay .NET url encoding Code based from CGI.escape() Some special characters (e.g. “()*!”) are not escaped on ecpay server when they generate their check sum value, causing CheckMacValue Error.
TODO: The following characters still cause CheckMacValue error:
'<', "\n", "\r", '&'
# File lib/offsite_payments/integrations/ecpay/helper.rb, line 206 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/offsite_payments/integrations/ecpay/helper.rb, line 184 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=#{merchant_hash_key}&#{raw_data}&HashIV=#{merchant_hash_iv}" url_encode_data = self.class.url_encode(hash_raw_data) url_encode_data.downcase! binding.pry if OffsitePayments::Integrations::Ecpay.debug add_field 'CheckMacValue', Digest::MD5.hexdigest(url_encode_data).upcase end
hash_iv(iv)
click to toggle source
# File lib/offsite_payments/integrations/ecpay/helper.rb, line 172 def hash_iv(iv) @iv = iv end
hash_key(key)
click to toggle source
# File lib/offsite_payments/integrations/ecpay/helper.rb, line 168 def hash_key(key) @key = key end
merchant_hash_iv()
click to toggle source
# File lib/offsite_payments/integrations/ecpay/helper.rb, line 180 def merchant_hash_iv @iv || OffsitePayments::Integrations::Ecpay.hash_iv end
merchant_hash_key()
click to toggle source
# File lib/offsite_payments/integrations/ecpay/helper.rb, line 176 def merchant_hash_key @key || OffsitePayments::Integrations::Ecpay.hash_key end
merchant_trade_date(date)
click to toggle source
# File lib/offsite_payments/integrations/ecpay/helper.rb, line 164 def merchant_trade_date(date) add_field 'MerchantTradeDate', date.strftime('%Y/%m/%d %H:%M:%S') end