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

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

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Helper.



20
21
22
23
24
# File 'lib/active_merchant/billing/integrations/allpay/helper.rb', line 20

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

Instance Method Details

#choose_payment(payment) ⇒ Object



46
47
48
# File 'lib/active_merchant/billing/integrations/allpay/helper.rb', line 46

def choose_payment(payment)
  add_field 'ChoosePayment', payment
end

#client_back_url(url) ⇒ Object



54
55
56
# File 'lib/active_merchant/billing/integrations/allpay/helper.rb', line 54

def client_back_url(url)
  add_field 'ClientBackURL', url
end

#encrypted_dataObject



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/active_merchant/billing/integrations/allpay/helper.rb', line 58

def encrypted_data

  hash_data = {
    :ChoosePayment => @fields['ChoosePayment'],
    :ClientBackURL => @fields['ClientBackURL'],
    :ItemName => @fields['ItemName'],
    :MerchantID => @fields['MerchantID'],
    :MerchantTradeDate => @fields['MerchantTradeDate'],
    :MerchantTradeNo => @fields['MerchantTradeNo'],
    :PaymentType => @fields['PaymentType'],
    :ReturnURL => @fields['ReturnURL'],
    :TotalAmount => @fields['TotalAmount'],
    :TradeDesc => @fields['TradeDesc']
  }

  raw_data = hash_data.map do |x, y|
    "#{x}=#{y}"
  end.join('&')

  hash_raw_data = "HashKey=#{ActiveMerchant::Billing::Integrations::Allpay.hash_key}&#{raw_data}&HashIV=#{ActiveMerchant::Billing::Integrations::Allpay.hash_iv}"

  url_endcode_data = (CGI::escape(hash_raw_data)).downcase

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

#item_name(item) ⇒ Object



42
43
44
# File 'lib/active_merchant/billing/integrations/allpay/helper.rb', line 42

def item_name(item)
  add_field 'ItemName', item
end

#merchant_trade_date(date) ⇒ Object



30
31
32
# File 'lib/active_merchant/billing/integrations/allpay/helper.rb', line 30

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

#merchant_trade_no(trade_number) ⇒ Object



26
27
28
# File 'lib/active_merchant/billing/integrations/allpay/helper.rb', line 26

def merchant_trade_no(trade_number)
  add_field 'MerchantTradeNo', trade_number
end

#return_url(url) ⇒ Object



50
51
52
# File 'lib/active_merchant/billing/integrations/allpay/helper.rb', line 50

def return_url(url)
  add_field 'ReturnURL', url
end

#total_amount(amount) ⇒ Object



34
35
36
# File 'lib/active_merchant/billing/integrations/allpay/helper.rb', line 34

def total_amount(amount)
  add_field 'TotalAmount', amount
end

#trade_desc(description) ⇒ Object



38
39
40
# File 'lib/active_merchant/billing/integrations/allpay/helper.rb', line 38

def trade_desc(description)
  add_field 'TradeDesc', description
end