162 lines
6.4 KiB
Ruby
162 lines
6.4 KiB
Ruby
module Admin::PaymentSetup::HuaNanHelper
|
|
def self.get_setup_form(option_id)
|
|
form_array =
|
|
[['form_url','text',nil],['MerchantID','text',nil],
|
|
['TerminalID','text',nil],['MerchantName','text',nil],
|
|
['merID','text',nil],['store_id','text',nil],['PageVer','text',nil],
|
|
['txType_mask','select',[[I18n.t('payment_settup.yes'),'yes'],[I18n.t('payment_settup.no'),'no']],nil],
|
|
['NumberOfPayOption','number',[nil]],['encode','select',['UTF-8','BIG5'],nil],
|
|
['AutoCap','select',[[I18n.t('payment_settup.no'),'0'],[I18n.t('payment_settup.yes'),'1']],nil]]
|
|
if !option_id.nil?
|
|
value = PaymentSetupList.where(id:option_id).first
|
|
form_array = form_array.collect do |v1|
|
|
v1[-1] = value['data'][v1[0]]
|
|
v1
|
|
end
|
|
end
|
|
form_array
|
|
end
|
|
def self.pay(params,setup,recieve_url,order_num=nil,amount=nil)
|
|
data = setup.data.clone
|
|
['NumberOfPayOption','txType_mask','form_url','store_id'].each do |d_value|
|
|
data.delete(d_value)
|
|
end
|
|
checkValue = get_checkValue({'lidm'=>order_num.to_s,'purchAmt'=>amount.to_s,'setup'=>setup})
|
|
data = data.merge({'lidm'=>order_num,'purchAmt'=>amount,
|
|
'checkValue'=>checkValue,'AuthResURL'=>recieve_url})
|
|
if params['txType']=='1' && setup.data['txType_mask']=='yes'
|
|
data = data.merge({'txType'=>'1','NumberOfPay'=>params['NumberOfPay']})
|
|
else
|
|
data = data.merge({'txType'=>'0'})
|
|
end
|
|
{'form_url'=>setup.data['form_url'],'data'=>data}
|
|
end
|
|
def self.name(obj=nil)
|
|
if !obj.nil?
|
|
obj.data['MerchantName']
|
|
end
|
|
end
|
|
def self.get_txType_and_num_pay(setup)
|
|
mask = setup.data['txType_mask']
|
|
if mask=='yes'
|
|
v1 = [[I18n.t('payment_settup.yes'),'1'],[I18n.t('payment_settup.no'),'0']]
|
|
v2 = setup.data['NumberOfPayOption']
|
|
else
|
|
v1 = [[I18n.t('payment_settup.no'),'0']]
|
|
v2 = nil
|
|
end
|
|
[v1,v2]
|
|
end
|
|
def self.valid_general(id,lidm,status,errcode,authCode,authAmt,xid)
|
|
hv1 = Digest::MD5.hexdigest (id+'|'+lidm.to_s)
|
|
hv2 =
|
|
Digest::MD5.hexdigest (hv1+'|'+status.to_s+'|'+errcode.to_s +
|
|
'|' + authCode.to_s + '|' + authAmt.to_s + '|' + xid.to_s)
|
|
checkValue = hv2[-16..-1]
|
|
end
|
|
def self.valid_union(id,orderNumber,status,errcode,orderAmount,xid)
|
|
hv1 = Digest::MD5.hexdigest (id+'|'+orderNumber.to_s)
|
|
hv2 =
|
|
Digest::MD5.hexdigest (hv1+'|'+status.to_s+'|'+errcode.to_s+
|
|
'|'+orderAmount.to_s+'|'+xid.to_s)
|
|
checkValue = hv2[-16..-1]
|
|
end
|
|
def self.valid_check_value(setup,param,log_obj=nil)
|
|
return_checkValue = param['checkValue']
|
|
id = setup.data['store_id']
|
|
blank_flag = false
|
|
if !param['lidm'].nil?
|
|
pay_type = 'general_card'
|
|
card_type = I18n.t('payment_settup.general_card')
|
|
checkValue = valid_general(id,param['lidm'],param['status'],
|
|
param['errcode'],param['authCode'],param['authAmt'],param['xid'])
|
|
orderNumber = param['lidm']
|
|
amount = param['authAmt']
|
|
elsif !param['orderNumber'].nil?
|
|
pay_type = 'union_card'
|
|
card_type = I18n.t('payment_settup.union_card')
|
|
checkValue = valid_general(id,param['orderNumber'],param['status'],
|
|
param['errcode'],param['orderAmount'],param['xid'])
|
|
orderNumber = param['lidm']
|
|
amount = param['orderAmount']
|
|
else
|
|
blank_flag = true
|
|
end
|
|
result = param['status']=='0'
|
|
if checkValue != return_checkValue
|
|
result = false
|
|
end
|
|
if log_obj.nil?
|
|
if blank_flag
|
|
'something went wrong'
|
|
else
|
|
payment_log = PaymentLog.all.select{|v| v.orderNumber == orderNumber}
|
|
if !(!payment_log.blank? && payment_log.length == 1 && payment_log[0].params == param.permit!)
|
|
payment_log = []
|
|
else
|
|
payment_log = payment_log[0]
|
|
end
|
|
if payment_log.blank?
|
|
payment_log = PaymentLog.create(params: param.permit!,
|
|
result: result,
|
|
payment_setup_id: param['pament_id'],
|
|
orderNumber: orderNumber,
|
|
amount: amount,
|
|
member: param['member_id'],
|
|
account: '***' + param['Last4digitPAN'],
|
|
pay_type: pay_type,
|
|
pay_id: param['pay_id'])
|
|
end
|
|
member_name = payment_log.get_member.name rescue nil
|
|
{ 'orderNumber' => orderNumber,
|
|
'card_type' => card_type,
|
|
'user' => member_name,
|
|
'amount' => amount,
|
|
'account' => '***' + param['Last4digitPAN'].to_s,
|
|
'trading_result' => I18n.t("payment_settup.#{result}")}
|
|
end
|
|
else
|
|
log_obj.update_attributes(params: param,
|
|
result: param['status']=='0',
|
|
payment_setup_id: param['pament_id'],
|
|
orderNumber: orderNumber,
|
|
amount: amount,
|
|
member: param['member_id'],
|
|
account: '***' + param['Last4digitPAN'].to_s,
|
|
pay_type: pay_type,
|
|
pay_id: param['pay_id'])
|
|
end
|
|
end
|
|
def self.regenerate(setup,param,log_obj)
|
|
valid_check_value(setup,param,log_obj)
|
|
end
|
|
def self.get_pay_array(setup)
|
|
txType_opt,num_pay_opt = self.get_txType_and_num_pay(setup)
|
|
[['txType','select',txType_opt,nil,'pay_mask'],['NumberOfPay','select',num_pay_opt,nil,'numofpay']]
|
|
end
|
|
def self.get_checkValue(param)
|
|
if param.class == Hash
|
|
lidm = param['lidm']
|
|
purchAmt = param['purchAmt']
|
|
setup = param['setup']
|
|
hv1 = Digest::MD5.hexdigest (setup.data['store_id']+'|'+lidm)
|
|
hv2 =
|
|
Digest::MD5.hexdigest (hv1+'|'+setup.data['MerchantID']+'|'+setup.data['TerminalID']+'|'+purchAmt)
|
|
checkValue = hv2[-16..-1]
|
|
else
|
|
'error'
|
|
end
|
|
end
|
|
def self.get_test_form(setup)
|
|
data = setup.data.clone
|
|
['NumberOfPayOption','txType_mask','form_url','store_id'].each do |d_value|
|
|
data.delete(d_value)
|
|
end
|
|
txType_opt,num_pay_opt = self.get_txType_and_num_pay(setup)
|
|
{'form_url'=>setup.data['form_url'],
|
|
'readonly_data'=>data,
|
|
'data'=>[['lidm','text',nil,'param'],['txType','select',txType_opt,nil,'pay_mask'],['NumberOfPay','select',num_pay_opt,nil,'numofpay'],
|
|
['purchAmt','number',1,'param'],['checkValue','check',nil],['AuthResURL','recieve_url',nil]]}
|
|
end
|
|
end
|