class ActiveMerchant::Billing::Integrations::Allpay::Notification

Public Instance Methods

acknowledge() click to toggle source

TODO 使用查詢功能實作 acknowledge Allpay 沒有遠端驗證功能, 而以 checksum_ok? 代替

# File lib/active_merchant/billing/integrations/allpay/notification.rb, line 20
def acknowledge
  checksum_ok?
end
bank_code() click to toggle source

for ATM

# File lib/active_merchant/billing/integrations/allpay/notification.rb, line 113
def bank_code
  @params['BankCode']
end
barcode1() click to toggle source

for BARCODE

# File lib/active_merchant/billing/integrations/allpay/notification.rb, line 135
def barcode1
  @params['Barcode1']
end
barcode2() click to toggle source
# File lib/active_merchant/billing/integrations/allpay/notification.rb, line 139
def barcode2
  @params['Barcode2']
end
barcode3() click to toggle source
# File lib/active_merchant/billing/integrations/allpay/notification.rb, line 143
def barcode3
  @params['Barcode3']
end
check_mac_value() click to toggle source
# File lib/active_merchant/billing/integrations/allpay/notification.rb, line 108
def check_mac_value
  @params['CheckMacValue']
end
checksum_ok?() click to toggle source
# File lib/active_merchant/billing/integrations/allpay/notification.rb, line 39
def checksum_ok?
  params_copy = @params.clone

  checksum = params_copy.delete('CheckMacValue')

  # 把 params 轉成 query string 前必須先依照 hash key 做 sort
  # 依照英文字母排序,由 A 到 Z 且大小寫不敏感
  raw_data = params_copy.sort_by{ |k,v| k.downcase }.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

  (Digest::MD5.hexdigest(url_endcode_data) == checksum.to_s.downcase)
end
complete?() click to toggle source
# File lib/active_merchant/billing/integrations/allpay/notification.rb, line 24
def complete?
  case @params['RtnCode']
  when '1' #付款成功
    true
  when '2' # ATM 取號成功
    true
  when '10100073' # CVS 或 BARCODE 取號成功
    true
  when '800' #貨到付款訂單建立成功
    true
  else
    false
  end
end
currency() click to toggle source
# File lib/active_merchant/billing/integrations/allpay/notification.rb, line 130
def currency
  'TWD'
end
expire_date() click to toggle source
# File lib/active_merchant/billing/integrations/allpay/notification.rb, line 121
def expire_date
  @params['ExpireDate']
end
gross() click to toggle source
# File lib/active_merchant/billing/integrations/allpay/notification.rb, line 84
def gross
  ::Money.new(@params['TradeAmt'].to_i * 100, currency)
end
item_id()
Alias for: merchant_trade_no
merchant_id() click to toggle source
# File lib/active_merchant/billing/integrations/allpay/notification.rb, line 61
def merchant_id
  @params['MerchantID']
end
merchant_trade_no() click to toggle source

廠商交易編號

# File lib/active_merchant/billing/integrations/allpay/notification.rb, line 66
def merchant_trade_no
  @params['MerchantTradeNo']
end
Also aliased as: item_id
payment_date() click to toggle source
# File lib/active_merchant/billing/integrations/allpay/notification.rb, line 88
def payment_date
  @params['PaymentDate']
end
payment_no() click to toggle source

for CVS

# File lib/active_merchant/billing/integrations/allpay/notification.rb, line 126
def payment_no
  @params['PaymentNo']
end
payment_type() click to toggle source
# File lib/active_merchant/billing/integrations/allpay/notification.rb, line 92
def payment_type
  @params['PaymentType']
end
payment_type_charge_fee() click to toggle source
# File lib/active_merchant/billing/integrations/allpay/notification.rb, line 96
def payment_type_charge_fee
  @params['PaymentTypeChargeFee']
end
rtn_code() click to toggle source
# File lib/active_merchant/billing/integrations/allpay/notification.rb, line 57
def rtn_code
  @params['RtnCode']
end
rtn_msg() click to toggle source
# File lib/active_merchant/billing/integrations/allpay/notification.rb, line 71
def rtn_msg
  @params['RtnMsg']
end
simulate_paid() click to toggle source
# File lib/active_merchant/billing/integrations/allpay/notification.rb, line 104
def simulate_paid
  @params['SimulatePaid']
end
status() click to toggle source
# File lib/active_merchant/billing/integrations/allpay/notification.rb, line 9
def status
  if rtn_code == '1'
    true
  else
    false
  end
end
trade_amt() click to toggle source
# File lib/active_merchant/billing/integrations/allpay/notification.rb, line 81
def trade_amt
  @params['TradeAmt']
end
trade_date() click to toggle source
# File lib/active_merchant/billing/integrations/allpay/notification.rb, line 100
def trade_date
  @params['TradeDate']
end
trade_no() click to toggle source

AllPay 的交易編號

# File lib/active_merchant/billing/integrations/allpay/notification.rb, line 76
def trade_no
  @params['TradeNo']
end
Also aliased as: transaction_id
transaction_id()
Alias for: trade_no
v_account() click to toggle source
# File lib/active_merchant/billing/integrations/allpay/notification.rb, line 117
def v_account
  @params['vAccount']
end