Class: ActiveMerchant::Billing::Integrations::Allpay::Notification
- Inherits:
-
Notification
- Object
- Notification
- ActiveMerchant::Billing::Integrations::Allpay::Notification
- Defined in:
- lib/active_merchant/billing/integrations/allpay/notification.rb
Instance Method Summary collapse
-
#acknowledge ⇒ Object
TODO 使用查詢功能實作 acknowledge Allpay 沒有遠端驗證功能, 而以 checksum_ok? 代替.
-
#bank_code ⇒ Object
for ATM.
-
#barcode1 ⇒ Object
for BARCODE.
- #barcode2 ⇒ Object
- #barcode3 ⇒ Object
- #check_mac_value ⇒ Object
- #checksum_ok? ⇒ Boolean
- #complete? ⇒ Boolean
- #currency ⇒ Object
- #expire_date ⇒ Object
- #gross ⇒ Object
- #merchant_id ⇒ Object
-
#merchant_trade_no ⇒ Object
(also: #item_id)
廠商交易編號.
- #payment_date ⇒ Object
-
#payment_no ⇒ Object
for CVS.
- #payment_type ⇒ Object
- #payment_type_charge_fee ⇒ Object
- #rtn_code ⇒ Object
- #rtn_msg ⇒ Object
- #simulate_paid ⇒ Object
- #status ⇒ Object
- #trade_amt ⇒ Object
- #trade_date ⇒ Object
-
#trade_no ⇒ Object
(also: #transaction_id)
AllPay 的交易編號.
- #v_account ⇒ Object
Instance Method Details
#acknowledge ⇒ Object
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_code ⇒ Object
for ATM
113 114 115 |
# File 'lib/active_merchant/billing/integrations/allpay/notification.rb', line 113 def bank_code @params['BankCode'] end |
#barcode1 ⇒ Object
for BARCODE
135 136 137 |
# File 'lib/active_merchant/billing/integrations/allpay/notification.rb', line 135 def @params['Barcode1'] end |
#barcode2 ⇒ Object
139 140 141 |
# File 'lib/active_merchant/billing/integrations/allpay/notification.rb', line 139 def @params['Barcode2'] end |
#barcode3 ⇒ Object
143 144 145 |
# File 'lib/active_merchant/billing/integrations/allpay/notification.rb', line 143 def @params['Barcode3'] end |
#check_mac_value ⇒ Object
108 109 110 |
# File 'lib/active_merchant/billing/integrations/allpay/notification.rb', line 108 def check_mac_value @params['CheckMacValue'] end |
#checksum_ok? ⇒ 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
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 |
#currency ⇒ Object
130 131 132 |
# File 'lib/active_merchant/billing/integrations/allpay/notification.rb', line 130 def currency 'TWD' end |
#expire_date ⇒ Object
121 122 123 |
# File 'lib/active_merchant/billing/integrations/allpay/notification.rb', line 121 def expire_date @params['ExpireDate'] end |
#gross ⇒ Object
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_id ⇒ Object
61 62 63 |
# File 'lib/active_merchant/billing/integrations/allpay/notification.rb', line 61 def merchant_id @params['MerchantID'] end |
#merchant_trade_no ⇒ Object 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_date ⇒ Object
88 89 90 |
# File 'lib/active_merchant/billing/integrations/allpay/notification.rb', line 88 def payment_date @params['PaymentDate'] end |
#payment_no ⇒ Object
for CVS
126 127 128 |
# File 'lib/active_merchant/billing/integrations/allpay/notification.rb', line 126 def payment_no @params['PaymentNo'] end |
#payment_type ⇒ Object
92 93 94 |
# File 'lib/active_merchant/billing/integrations/allpay/notification.rb', line 92 def payment_type @params['PaymentType'] end |
#payment_type_charge_fee ⇒ Object
96 97 98 |
# File 'lib/active_merchant/billing/integrations/allpay/notification.rb', line 96 def payment_type_charge_fee @params['PaymentTypeChargeFee'] end |
#rtn_code ⇒ Object
57 58 59 |
# File 'lib/active_merchant/billing/integrations/allpay/notification.rb', line 57 def rtn_code @params['RtnCode'] end |
#rtn_msg ⇒ Object
71 72 73 |
# File 'lib/active_merchant/billing/integrations/allpay/notification.rb', line 71 def rtn_msg @params['RtnMsg'] end |
#simulate_paid ⇒ Object
104 105 106 |
# File 'lib/active_merchant/billing/integrations/allpay/notification.rb', line 104 def simulate_paid @params['SimulatePaid'] end |
#status ⇒ Object
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_amt ⇒ Object
81 82 83 |
# File 'lib/active_merchant/billing/integrations/allpay/notification.rb', line 81 def trade_amt @params['TradeAmt'] end |
#trade_date ⇒ Object
100 101 102 |
# File 'lib/active_merchant/billing/integrations/allpay/notification.rb', line 100 def trade_date @params['TradeDate'] end |
#trade_no ⇒ Object 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_account ⇒ Object
117 118 119 |
# File 'lib/active_merchant/billing/integrations/allpay/notification.rb', line 117 def v_account @params['vAccount'] end |