2015-01-30 07:02:08 +00:00
|
|
|
class NkuhtDonatesController < ApplicationController
|
|
|
|
|
|
|
|
include ApplicationHelper
|
|
|
|
|
|
|
|
include SimpleCaptcha::ControllerHelpers
|
|
|
|
|
|
|
|
def index
|
|
|
|
|
|
|
|
nkuht_donate = NkuhtDonateMain.new
|
|
|
|
|
|
|
|
nkuht_donate_units = NkuhtDonateUnit.all
|
|
|
|
nkuht_donate_departments = NkuhtDonateDepartment.all
|
|
|
|
nkuht_donate_uses = NkuhtDonateUse.all
|
|
|
|
|
|
|
|
{
|
|
|
|
"nkuht_donate" => nkuht_donate,
|
|
|
|
"nkuht_donate_units" => nkuht_donate_units,
|
|
|
|
"nkuht_donate_departments" => nkuht_donate_departments,
|
|
|
|
"nkuht_donate_uses" => nkuht_donate_uses
|
|
|
|
}
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
def donate_list
|
|
|
|
params = OrbitHelper.params
|
|
|
|
|
|
|
|
if !params[:mq].blank?
|
|
|
|
nkuht_donates = NkuhtDonateMain.where(:donate_public=>true).any_of({:name => /#{params[:mq]}/i}).order_by(:created_at=>"desc").page(params[:page_no]).per(20)
|
|
|
|
else
|
|
|
|
nkuht_donates = NkuhtDonateMain.where(:donate_public=>true).order_by(:created_at=>"desc").page(params[:page_no]).per(20)
|
|
|
|
end
|
|
|
|
|
|
|
|
{
|
|
|
|
"nkuht_donates" => nkuht_donates,
|
|
|
|
"total_pages" => nkuht_donates.total_pages
|
|
|
|
}
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
def receipt_notice
|
|
|
|
|
|
|
|
params = OrbitHelper.params
|
|
|
|
|
|
|
|
nkuht_donate = NkuhtDonateMain.find(params[:no])
|
|
|
|
|
|
|
|
{
|
|
|
|
"nkuht_donate" => nkuht_donate
|
|
|
|
}
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
|
|
|
|
|
|
|
@nkuht_donate = NkuhtDonateMain.new(nkuht_donate_params)
|
|
|
|
|
|
|
|
@nkuht_donate.donation_serial_number = NkuhtDonateMain.get_serial_number
|
|
|
|
@nkuht_donate.donation_payment_number = NkuhtDonateMain.get_payment_number
|
2015-02-11 08:13:31 +00:00
|
|
|
|
|
|
|
if @nkuht_donate.donation_amount.to_i < 1
|
2015-01-30 07:02:08 +00:00
|
|
|
|
|
|
|
@notice = []
|
|
|
|
@notice << t('nkuht_donate.donation_amount_err')
|
|
|
|
redirect_to "#{params[:referer_url]}", :notice => @notice
|
|
|
|
|
2015-02-11 08:13:31 +00:00
|
|
|
elsif @nkuht_donate.donation_way == '2' and @nkuht_donate.donation_amount.to_i > 30000
|
2015-01-30 07:02:08 +00:00
|
|
|
|
|
|
|
@notice = []
|
|
|
|
@notice << t('nkuht_donate.donation_amount_atm')
|
|
|
|
redirect_to "#{params[:referer_url]}", :notice => @notice
|
|
|
|
|
2015-02-11 08:13:31 +00:00
|
|
|
elsif @nkuht_donate.donation_way == '3' and @nkuht_donate.donation_amount.to_i > 20000
|
2015-01-30 07:02:08 +00:00
|
|
|
|
|
|
|
@notice = []
|
|
|
|
@notice << t('nkuht_donate.donation_amount_market')
|
|
|
|
redirect_to "#{params[:referer_url]}", :notice => @notice
|
|
|
|
|
|
|
|
elsif simple_captcha_valid? && @nkuht_donate.save
|
|
|
|
|
|
|
|
# ways1: 信用卡
|
|
|
|
# ways2: atm轉帳
|
|
|
|
# ways3: 超商繳款
|
|
|
|
# ways4: 現金
|
|
|
|
# ways5: 支票
|
|
|
|
# ways6: 匯款
|
|
|
|
|
|
|
|
if @nkuht_donate.donation_way == '1'
|
|
|
|
redirect_to "#{params[:referer_url]}/?method=print_card_payment&no=#{@nkuht_donate.id}"
|
|
|
|
elsif @nkuht_donate.donation_way == '2'
|
|
|
|
redirect_to "#{params[:referer_url]}/?method=print_atm_payment&no=#{@nkuht_donate.id}"
|
|
|
|
elsif @nkuht_donate.donation_way == '3'
|
|
|
|
redirect_to "#{params[:referer_url]}/?method=print_market_payment&no=#{@nkuht_donate.id}&layout=false"
|
|
|
|
else
|
|
|
|
redirect_to "#{params[:referer_url]}/?method=print_msg&no=#{@nkuht_donate.id}"
|
|
|
|
end
|
|
|
|
else
|
|
|
|
|
|
|
|
if !simple_captcha_valid?
|
|
|
|
@notice = [t('recaptcha.errors.verification_failed')]
|
|
|
|
else
|
|
|
|
|
|
|
|
@notice = []
|
|
|
|
@errors = @nkuht_donate.errors.messages.first
|
|
|
|
|
|
|
|
@notice << t('recaptcha.errors.verification_failed') if !gotcha_valid?
|
|
|
|
@notice << "#{t("nkuht_donate.donation_amount")}#{@errors[1][0]}" if !@errors.blank?
|
|
|
|
|
|
|
|
end
|
|
|
|
redirect_to "#{params[:referer_url]}", :notice => @notice
|
|
|
|
# redirect_to "#{params[:referer_url]}", :notice => t('recaptcha.errors.verification_failed')
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
def print_card_payment
|
|
|
|
|
|
|
|
params = OrbitHelper.params
|
|
|
|
|
|
|
|
nkuht_donate = NkuhtDonateMain.find(params[:no])
|
|
|
|
|
|
|
|
{
|
|
|
|
"nkuht_donate" => nkuht_donate
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
def print_atm_payment
|
|
|
|
|
|
|
|
require 'digest/sha1'
|
|
|
|
require 'openssl'
|
|
|
|
require 'base64'
|
|
|
|
# require 'mcrypt'
|
|
|
|
|
|
|
|
params = OrbitHelper.params
|
|
|
|
|
|
|
|
nkuht_donate = NkuhtDonateMain.find(params[:no])
|
|
|
|
|
|
|
|
sendseqno = nkuht_donate.donation_serial_time.to_datetime.strftime("%Y%m%d%H%M%S") + "%04d" % (nkuht_donate.donation_serial_number)
|
|
|
|
|
|
|
|
{
|
|
|
|
"nkuht_donate" => nkuht_donate,
|
|
|
|
"xmldata" => Base64.encode64("<?xml version='1.0' encoding='Big5'?><CardPayRq><SendSeqNo>#{sendseqno}</SendSeqNo><MID>T00774955421</MID><FunCode></FunCode><UserData></UserData><ONO>#{nkuht_donate.donation_payment_number}</ONO><InAccountNo>#{nkuht_donate.donation_payment_number}</InAccountNo ><Amount>#{nkuht_donate.donation_amount}</Amount><MAC>#{nkuht_donate.get_atm_mac_number}</MAC><RsURL>http://donations.nkuht.edu.tw/donate_atm</RsURL></CardPayRq>")
|
|
|
|
}
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
def print_market_payment
|
|
|
|
|
|
|
|
require 'barby'
|
|
|
|
require 'barby/barcode/code_39'
|
|
|
|
require 'barby/outputter/png_outputter'
|
|
|
|
|
|
|
|
params = OrbitHelper.params
|
|
|
|
|
|
|
|
nkuht_donate = NkuhtDonateMain.find(params[:no])
|
|
|
|
|
|
|
|
barcodes = nkuht_donate.get_market_number
|
|
|
|
|
|
|
|
barcodes.each_with_index do |code,i|
|
|
|
|
barcode =Barby::Code39.new(code, true)
|
|
|
|
File.open("public/code39_#{i + 1}.png", 'w'){|f|
|
|
|
|
# f.write barcode.to_png(:margin => 3, :xdim => 2, :height => 50)
|
|
|
|
f.write barcode.to_png(:height => 40)
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
{
|
|
|
|
"nkuht_donate" => nkuht_donate,
|
|
|
|
"barcodes" => barcodes
|
|
|
|
}
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
def print_msg
|
|
|
|
|
|
|
|
params = OrbitHelper.params
|
|
|
|
|
|
|
|
nkuht_donate = NkuhtDonateMain.find(params[:no])
|
|
|
|
|
|
|
|
{
|
|
|
|
"nkuht_donate" => nkuht_donate
|
|
|
|
}
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
def payment_ok
|
|
|
|
end
|
|
|
|
|
|
|
|
def payment_no
|
|
|
|
|
|
|
|
params = OrbitHelper.params
|
|
|
|
|
|
|
|
nkuht_donate = NkuhtDonateMain.where(:_id => params['no']).first
|
|
|
|
|
|
|
|
msg = {
|
|
|
|
'V211' => '傳送序號重複,訊息丟棄',
|
|
|
|
'V212' => '此筆訂單之收款資料已存在且已成功付款',
|
|
|
|
'V213' => '此筆訂單之收款資料已存在,但交易仍在進行中',
|
|
|
|
'V214' => '此筆訂單之收款資料已存在,但主機交易中斷狀態不明',
|
|
|
|
'J001' => '主機交易逾時 Pending',
|
|
|
|
'0' => '收款交易成功',
|
|
|
|
'' => '收款交易失敗'}
|
|
|
|
|
|
|
|
{
|
|
|
|
"nkuht_donate" => nkuht_donate,
|
|
|
|
"msg" => msg
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
def nkuht_donate_params
|
|
|
|
params.require(:nkuht_donate_main).permit!
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|