class Origami::BankIntegrationController < ApplicationController #BaseOrigamiController

	def settle_trans
		if(params[:type] == 'request')
			card_settle_trans = CardSettleTran.new()
			card_settle_trans.req_date = Date.today
			card_settle_trans.req_time = Time.now
			card_settle_trans.req_cmd = params[:data][:cmd_type]
			card_settle_trans.req_type = params[:data][:payment_type]
			card_settle_trans.save()

			card_settle_trans_id = card_settle_trans.id
			response = {status: 'success', card_settle_trans_id: card_settle_trans_id}
		else
			card_settle_trans = CardSettleTran.find(params[:card_settle_trans_id])
			card_settle_trans.res_date = Date.today
			card_settle_trans.res_time = Time.now
			card_settle_trans.res_cmd = params[:data][:CMD]
			card_settle_trans.res_type = params[:data][:TYPE]
			card_settle_trans.status = params[:data][:STATUS]
			card_settle_trans.sale_cnt = params[:data][:SALECNT]
			card_settle_trans.sale_amt = params[:data][:SALEAMT].to_f
			card_settle_trans.void_cnt = params[:data][:VOIDCNT]
			card_settle_trans.void_amt = params[:data][:VOIDAMT].to_f
			card_settle_trans.refund_cnt = params[:data][:REFUNDCNT]
			card_settle_trans.refund_amt = params[:data][:REFUNDAMT].to_f
			card_settle_trans.print_text_part1_type = params[:data][:PRINTTEXTPART1TYPE]
			card_settle_trans.print_text_part1_value = params[:data][:PRINTTEXTPART1VALUE]
			card_settle_trans.print_text_part2_type = params[:data][:PRINTTEXTPART2TYPE]
			card_settle_trans.print_text_part2_value = params[:data][:PRINTTEXTPART2VALUE]
			card_settle_trans.print_text_part3_type = params[:data][:PRINTTEXTPART3TYPE]
			card_settle_trans.print_text_part3_value = params[:data][:PRINTTEXTPART3VALUE]
			card_settle_trans.print_text_part4_type = params[:data][:PRINTTEXTPART4TYPE]
			card_settle_trans.print_text_part4_value = params[:data][:PRINTTEXTPART4VALUE]
			card_settle_trans.save()
			response = {status: 'success'}
		end
		render json: response
	end

	def sale_trans
		if(params[:type] == 'request')
			card_sale_trans = CardSaleTran.new()
			card_sale_trans.sale_id = params[:data][:sale_id]
			card_sale_trans.req_date = Date.today
			card_sale_trans.req_time = Time.now
			card_sale_trans.req_amt = params[:data][:amt]
			card_sale_trans.req_inv_no = params[:data][:inv_no]
			card_sale_trans.req_cmd = params[:data][:cmd_type]
			card_sale_trans.req_type = params[:data][:payment_type]
			card_sale_trans.save()

			card_sale_trans_id = card_sale_trans.id
			response = {status: 'success', card_sale_trans_id: card_sale_trans_id}
		else
			card_sale_trans = CardSaleTran.find(params[:card_sale_trans_id])
			card_sale_trans.res_date = params[:data][:DATE]
			card_sale_trans.res_time = params[:data][:TIME]
			card_sale_trans.res_amt = params[:data][:AMT].to_f / 100
			card_sale_trans.res_inv_no = params[:data][:ECRREF]
			card_sale_trans.res_cmd = params[:data][:CMD]
			card_sale_trans.res_type = params[:data][:TYPE]
			card_sale_trans.status = params[:data][:STATUS]
			card_sale_trans.resp = params[:data][:RESP]
			card_sale_trans.trace = params[:data][:TRACE]
			card_sale_trans.app_code = params[:data][:APPCODE]
			card_sale_trans.pan = params[:data][:PAN]
			card_sale_trans.exp_date = params[:data][:EXPDATE]
			card_sale_trans.tips = params[:data][:TIPS]
			card_sale_trans.entry_mode = params[:data][:ENTRYMODE]
			card_sale_trans.terminal_id = params[:data][:TERMINALID]
			card_sale_trans.merchant_id = params[:data][:MERCHANTID]
			card_sale_trans.card_holder = params[:data][:CARDHOLDERNAME]
			card_sale_trans.batch_no = params[:data][:BATCHNO]
			card_sale_trans.ref_no = params[:data][:REFNUM]
			card_sale_trans.app = params[:data][:APP]
			card_sale_trans.emv_app_id = params[:data][:AID]
			card_sale_trans.emv_cyptrogram = params[:data][:TC]
			card_sale_trans.curr_code = params[:data][:CURRCODE]
			card_sale_trans.fx_rate = params[:data][:FXRATE]
			card_sale_trans.foreign_amt = params[:data][:FOREIGNAMT]
			card_sale_trans.dcc_msg = params[:data][:DCCMSG]
			card_sale_trans.tender = params[:data][:TENDER]
			card_sale_trans.print_text_part1_type = params[:data][:PRINTTEXTPART1TYPE]
			card_sale_trans.print_text_part1_value = params[:data][:PRINTTEXTPART1VALUE]
			card_sale_trans.print_text_part2_type = params[:data][:PRINTTEXTPART2TYPE]
			card_sale_trans.print_text_part2_value = params[:data][:PRINTTEXTPART2VALUE]
			card_sale_trans.print_text_part3_type = params[:data][:PRINTTEXTPART3TYPE]
			card_sale_trans.print_text_part3_value = params[:data][:PRINTTEXTPART3VALUE]
			card_sale_trans.print_text_part4_type = params[:data][:PRINTTEXTPART4TYPE]
			card_sale_trans.print_text_part4_value = params[:data][:PRINTTEXTPART4VALUE]
			card_sale_trans.save()

			response = {status: 'success'}
		end
		render json: response
	end

end
