Class: ActiveMerchant::Billing::Integrations::Allpay::Notification

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

Instance Method Summary collapse

Instance Method Details

#acknowledgeObject

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



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

def acknowledge
  checksum_ok?
end

#bank_codeObject

for ATM



113
114
115
# File 'lib/active_merchant/billing/integrations/allpay/notification.rb', line 113

def bank_code
  @params['BankCode']
end

#barcode1Object

for BARCODE



135
136
137
# File 'lib/active_merchant/billing/integrations/allpay/notification.rb', line 135

def barcode1
  @params['Barcode1']
end

#barcode2Object



139
140
141
# File 'lib/active_merchant/billing/integrations/allpay/notification.rb', line 139

def barcode2
  @params['Barcode2']
end

#barcode3Object



143
144
145
# File 'lib/active_merchant/billing/integrations/allpay/notification.rb', line 143

def barcode3
  @params['Barcode3']
end

#check_mac_valueObject



108
109
110
# File 'lib/active_merchant/billing/integrations/allpay/notification.rb', line 108

def check_mac_value
  @params['CheckMacValue']
end

#checksum_ok?Boolean

Returns:

  • (Boolean)


39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# 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?Boolean

Returns:

  • (Boolean)


24
25
26
27
28
29
30
31
32
33
34
35
36
37
# 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

#currencyObject



130
131
132
# File 'lib/active_merchant/billing/integrations/allpay/notification.rb', line 130

def currency
  'TWD'
end

#expire_dateObject



121
122
123
# File 'lib/active_merchant/billing/integrations/allpay/notification.rb', line 121

def expire_date
  @params['ExpireDate']
end

#grossObject



84
85
86
# File 'lib/active_merchant/billing/integrations/allpay/notification.rb', line 84

def gross
  ::Money.new(@params['TradeAmt'].to_i * 100, currency)
end

#merchant_idObject



61
62
63
# File 'lib/active_merchant/billing/integrations/allpay/notification.rb', line 61

def merchant_id
  @params['MerchantID']
end

#merchant_trade_noObject Also known as: item_id

廠商交易編號



66
67
68
# File 'lib/active_merchant/billing/integrations/allpay/notification.rb', line 66

def merchant_trade_no
  @params['MerchantTradeNo']
end

#payment_dateObject



88
89
90
# File 'lib/active_merchant/billing/integrations/allpay/notification.rb', line 88

def payment_date
  @params['PaymentDate']
end

#payment_noObject

for CVS



126
127
128
# File 'lib/active_merchant/billing/integrations/allpay/notification.rb', line 126

def payment_no
  @params['PaymentNo']
end

#payment_typeObject



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

def payment_type
  @params['PaymentType']
end

#payment_type_charge_feeObject



96
97
98
# File 'lib/active_merchant/billing/integrations/allpay/notification.rb', line 96

def payment_type_charge_fee
  @params['PaymentTypeChargeFee']
end

#rtn_codeObject



57
58
59
# File 'lib/active_merchant/billing/integrations/allpay/notification.rb', line 57

def rtn_code
  @params['RtnCode']
end

#rtn_msgObject



71
72
73
# File 'lib/active_merchant/billing/integrations/allpay/notification.rb', line 71

def rtn_msg
  @params['RtnMsg']
end

#simulate_paidObject



104
105
106
# File 'lib/active_merchant/billing/integrations/allpay/notification.rb', line 104

def simulate_paid
  @params['SimulatePaid']
end

#statusObject



9
10
11
12
13
14
15
# File 'lib/active_merchant/billing/integrations/allpay/notification.rb', line 9

def status
  if rtn_code == '1'
    true
  else
    false
  end
end

#trade_amtObject



81
82
83
# File 'lib/active_merchant/billing/integrations/allpay/notification.rb', line 81

def trade_amt
  @params['TradeAmt']
end

#trade_dateObject



100
101
102
# File 'lib/active_merchant/billing/integrations/allpay/notification.rb', line 100

def trade_date
  @params['TradeDate']
end

#trade_noObject Also known as: transaction_id

AllPay 的交易編號



76
77
78
# File 'lib/active_merchant/billing/integrations/allpay/notification.rb', line 76

def trade_no
  @params['TradeNo']
end

#v_accountObject



117
118
119
# File 'lib/active_merchant/billing/integrations/allpay/notification.rb', line 117

def 
  @params['vAccount']
end