Class: OffsitePayments::Integrations::Allpay::Notification

Inherits:
Notification
  • Object
show all
Defined in:
lib/offsite_payments/integrations/allpay.rb

Instance Method Summary collapse

Instance Method Details

#acknowledgeObject

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



187
188
189
# File 'lib/offsite_payments/integrations/allpay.rb', line 187

def acknowledge
  checksum_ok?
end

#bank_codeObject

for ATM



281
282
283
# File 'lib/offsite_payments/integrations/allpay.rb', line 281

def bank_code
  @params['BankCode']
end

#barcode1Object

for BARCODE



303
304
305
# File 'lib/offsite_payments/integrations/allpay.rb', line 303

def barcode1
  @params['Barcode1']
end

#barcode2Object



307
308
309
# File 'lib/offsite_payments/integrations/allpay.rb', line 307

def barcode2
  @params['Barcode2']
end

#barcode3Object



311
312
313
# File 'lib/offsite_payments/integrations/allpay.rb', line 311

def barcode3
  @params['Barcode3']
end

#check_mac_valueObject



276
277
278
# File 'lib/offsite_payments/integrations/allpay.rb', line 276

def check_mac_value
  @params['CheckMacValue']
end

#checksum_ok?Boolean

Returns:

  • (Boolean)


206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
# File 'lib/offsite_payments/integrations/allpay.rb', line 206

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=#{OffsitePayments::Integrations::Allpay.hash_key}&#{raw_data}&HashIV=#{OffsitePayments::Integrations::Allpay.hash_iv}"

  url_endcode_data = OffsitePayments::Integrations::Allpay::Helper.url_encode(hash_raw_data)
  url_endcode_data.downcase!

  (Digest::MD5.hexdigest(url_endcode_data) == checksum.to_s.downcase)
end

#complete?Boolean

Returns:

  • (Boolean)


191
192
193
194
195
196
197
198
199
200
201
202
203
204
# File 'lib/offsite_payments/integrations/allpay.rb', line 191

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



298
299
300
# File 'lib/offsite_payments/integrations/allpay.rb', line 298

def currency
  'TWD'
end

#expire_dateObject



289
290
291
# File 'lib/offsite_payments/integrations/allpay.rb', line 289

def expire_date
  @params['ExpireDate']
end

#grossObject



252
253
254
# File 'lib/offsite_payments/integrations/allpay.rb', line 252

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

#merchant_idObject



229
230
231
# File 'lib/offsite_payments/integrations/allpay.rb', line 229

def merchant_id
  @params['MerchantID']
end

#merchant_trade_noObject Also known as: item_id

廠商交易編號



234
235
236
# File 'lib/offsite_payments/integrations/allpay.rb', line 234

def merchant_trade_no
  @params['MerchantTradeNo']
end

#payment_dateObject



256
257
258
# File 'lib/offsite_payments/integrations/allpay.rb', line 256

def payment_date
  @params['PaymentDate']
end

#payment_noObject

for CVS



294
295
296
# File 'lib/offsite_payments/integrations/allpay.rb', line 294

def payment_no
  @params['PaymentNo']
end

#payment_typeObject



260
261
262
# File 'lib/offsite_payments/integrations/allpay.rb', line 260

def payment_type
  @params['PaymentType']
end

#payment_type_charge_feeObject



264
265
266
# File 'lib/offsite_payments/integrations/allpay.rb', line 264

def payment_type_charge_fee
  @params['PaymentTypeChargeFee']
end

#rtn_codeObject



225
226
227
# File 'lib/offsite_payments/integrations/allpay.rb', line 225

def rtn_code
  @params['RtnCode']
end

#rtn_msgObject



239
240
241
# File 'lib/offsite_payments/integrations/allpay.rb', line 239

def rtn_msg
  @params['RtnMsg']
end

#simulate_paidObject



272
273
274
# File 'lib/offsite_payments/integrations/allpay.rb', line 272

def simulate_paid
  @params['SimulatePaid']
end

#statusObject



176
177
178
179
180
181
182
# File 'lib/offsite_payments/integrations/allpay.rb', line 176

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

#trade_amtObject



249
250
251
# File 'lib/offsite_payments/integrations/allpay.rb', line 249

def trade_amt
  @params['TradeAmt']
end

#trade_dateObject



268
269
270
# File 'lib/offsite_payments/integrations/allpay.rb', line 268

def trade_date
  @params['TradeDate']
end

#trade_noObject Also known as: transaction_id

AllPay 的交易編號



244
245
246
# File 'lib/offsite_payments/integrations/allpay.rb', line 244

def trade_no
  @params['TradeNo']
end

#v_accountObject



285
286
287
# File 'lib/offsite_payments/integrations/allpay.rb', line 285

def 
  @params['vAccount']
end