class OffsitePayments::Integrations::SmilePay::Notification

Attributes

custom_user_confirmation_param[RW]

Public Instance Methods

acknowledge() click to toggle source

SmilePay 沒有遠端驗證功能, 而以認證碼代替

# File lib/offsite_payments/integrations/smile_pay.rb, line 170
def acknowledge
  if test? # SmilePay 客服回答測試環境時認證碼只會傳0
    true
  else
    # TODO 使用查詢功能實作 acknowledge
    params['Mid_smilepay'].to_i == calculated_mid_smile_key
  end
end
complete?() click to toggle source
# File lib/offsite_payments/integrations/smile_pay.rb, line 107
def complete?
  if ['A','D'].include?(params['Classif'])
    # Credit Card
    return params['Response_id'] == '1'
  else
    # No status except for non credit card payments
    true
  end
end
currency() click to toggle source
# File lib/offsite_payments/integrations/smile_pay.rb, line 159
def currency
  case params['Moneytype']
  when 'TW'
    'TWD'
  when 'CN'
    'CNY'
  end
end
gross() click to toggle source

the money amount we received in X.2 decimal.

# File lib/offsite_payments/integrations/smile_pay.rb, line 146
def gross
  ::Money.new(params['Amount'].to_i * 100, currency)
end
item_id() click to toggle source
# File lib/offsite_payments/integrations/smile_pay.rb, line 117
def item_id
  # 訂單號碼
  params['Data_id']
end
payer_email() click to toggle source
# File lib/offsite_payments/integrations/smile_pay.rb, line 132
def payer_email
  params['Email']
end
received_at() click to toggle source

When was this payment received by the client.

# File lib/offsite_payments/integrations/smile_pay.rb, line 128
def received_at
  params['Process_date'] + params['Process_time']
end
receiver_email() click to toggle source
# File lib/offsite_payments/integrations/smile_pay.rb, line 136
def receiver_email
  nil
end
security_key() click to toggle source
# File lib/offsite_payments/integrations/smile_pay.rb, line 140
def security_key
  # 驗證碼
  params['Mid_smilepay']
end
status() click to toggle source
# File lib/offsite_payments/integrations/smile_pay.rb, line 155
def status
  params['Response_msg'] || 'Completed'
end
test?() click to toggle source

Was this a test transaction?

# File lib/offsite_payments/integrations/smile_pay.rb, line 151
def test?
  OffsitePayments.mode == :test
end
transaction_id() click to toggle source
# File lib/offsite_payments/integrations/smile_pay.rb, line 122
def transaction_id
  # Smile Pay 端訂單號碼
  params['Smseid']
end

Private Instance Methods

calculated_mid_smile_key() click to toggle source
# File lib/offsite_payments/integrations/smile_pay.rb, line 181
def calculated_mid_smile_key
  b = "%08d" % (gross().dollars).to_i
  c = params['Smseid'][-4..-1].gsub(/\D/,'9')
  d = ( custom_user_confirmation_param() + b + c ).chars.to_a

  # 偶數位數字(從左算起)
  sum_even = d.values_at(* d.each_index.select(&:odd?)).compact.map(&:to_i).inject{|sum,x| sum + x }
  # 奇數位數字(從左算起)
  sum_odd = d.values_at(* d.each_index.select(&:even?)).compact.map(&:to_i).inject{|sum,x| sum + x }

  sum_even * 3 + sum_odd * 9
end