diff --git a/ECR_N5_DLL_TestUI/MainWindow.xaml b/ECR_N5_DLL_TestUI/MainWindow.xaml
index 4fb6ca6..5aaede3 100644
--- a/ECR_N5_DLL_TestUI/MainWindow.xaml
+++ b/ECR_N5_DLL_TestUI/MainWindow.xaml
@@ -14,24 +14,24 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
@@ -43,13 +43,13 @@
-
-
-
-
-
-
-
+
+
+
+
+
+
+
@@ -71,30 +71,43 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/ECR_N5_DLL_TestUI/MainWindow.xaml.cs b/ECR_N5_DLL_TestUI/MainWindow.xaml.cs
index 369ef04..0dfffea 100644
--- a/ECR_N5_DLL_TestUI/MainWindow.xaml.cs
+++ b/ECR_N5_DLL_TestUI/MainWindow.xaml.cs
@@ -27,7 +27,7 @@ namespace ECR_N5_DLL_TestUI
private string dataBits = "8";
private string stopBits = "One";
private string parity = "None";
- private string timeOut = "180000";
+ private string timeOut = "15000";
private string thisEvent;
@@ -46,6 +46,9 @@ namespace ECR_N5_DLL_TestUI
public string batchIdTextBoxValue = null;
public string settleDateTextBoxValue = null;
public string expDateTextBoxValue = null;
+ public string oriTxnDateTextBoxValue = null;
+ public string hostRefNoTextBoxValue = null;
+ public string paymentTypeTextBoxValue = null;
private n5coredll.N5Core n5Core = null;
private bool n5CoreInitSuccess = false;
@@ -54,16 +57,20 @@ namespace ECR_N5_DLL_TestUI
private string txnIdForPreAuth = null;
private string txnIdForOffline = null;
private string txnIdForAdjust = null;
+ private string txnIdForCreateOrder = null;
+ private string enquiryPeriod = null;
private string saleRequestMsg = null;
private string preAuthRequestMsg = null;
private string offlineRequestMsg = null;
private string adjustRequestMsg = null;
-
+ private string createOrderRequestMsg = null;
private string refundRequestMsg = null;
private string retrievalRequestMsg = null;
private string voidRequestMsg = null;
private string settlementRequestMsg = null;
+ private string getInfoRequestMsg = null;
+ private string checkUpdateRequestMsg = null;
private string linkTestRequestMsg = null;
private string reprintRequestMsg = null;
private string terminaionRequestMsg = null;
@@ -72,18 +79,45 @@ namespace ECR_N5_DLL_TestUI
private string addPointRequestMsg = null;
private string batchEnquiryRequestMsg = null;
private string settleEnquiryRequestMsg = null;
+ private string summaryEnquiryRequestMsg = null;
+ private string checkHealthRequestMsg = null;
private Boolean isRepeatSubmit = false;
public MainWindow()
{
InitializeComponent();
}
+ private void requestSummaryEnquiryThead()
+ {
+
+ jsonResultByThead = n5Core.sendSummaryEnquiryRequest(enquiryPeriod);
+ this.requestStrByThead = this.summaryEnquiryRequestMsg;
+ showResult();
+ }
+
+ private void requestCheckHealthThead()
+ {
+
+ jsonResultByThead = n5Core.sendCheckHealth();
+ this.requestStrByThead = this.checkHealthRequestMsg;
+ showResult();
+ }
+
+ private void requestOfflineThead()
+ {
+
+ jsonResultByThead = n5Core.processOffline(txnIdForOffline, txnAmtTextBoxValue, paymentAppIdComboBoxValue, authCodeTextBoxValue, panTextBoxValue, expDateTextBoxValue);
+ this.requestStrByThead = this.offlineRequestMsg;
+ showResult();
+ }
private void requestSaleThead()
{
+ n5Core.sendLinkTestRequest();
if (panTextBoxValue!=null && panTextBoxValue!= "" && expDateTextBoxValue!=null && expDateTextBoxValue!="")
- jsonResultByThead = n5Core.requestSale(txnIdForSale, txnAmtTextBoxValue, "0", paymentAppIdComboBoxValue, qrValueTextBoxValue);
+ jsonResultByThead = n5Core.requestSale(txnIdForSale, txnAmtTextBoxValue, "0", paymentAppIdComboBoxValue, qrValueTextBoxValue,"30000");
else
- jsonResultByThead = n5Core.requestSale(txnIdForSale, txnAmtTextBoxValue, "0", paymentAppIdComboBoxValue, qrValueTextBoxValue);
+ jsonResultByThead = n5Core.requestSale(txnIdForSale, txnAmtTextBoxValue, "0", paymentAppIdComboBoxValue, qrValueTextBoxValue, "30000");
+ //jsonResultByThead = n5Core.requestInstallment(txnIdForSale, txnAmtTextBoxValue, paymentAppIdComboBoxValue,"12", qrValueTextBoxValue, "30000");
this.requestStrByThead = this.saleRequestMsg;
showResult();
}
@@ -93,29 +127,31 @@ namespace ECR_N5_DLL_TestUI
this.requestStrByThead = this.preAuthRequestMsg;
showResult();
}
- private void requestOfflineThead()
+ private void requestCreateOrderThread()
{
-
- jsonResultByThead = n5Core.processOffline(txnIdForOffline, txnAmtTextBoxValue, paymentAppIdComboBoxValue, authCodeTextBoxValue, panTextBoxValue, expDateTextBoxValue);
- this.requestStrByThead = this.offlineRequestMsg;
+ jsonResultByThead = n5Core.requestCreateOrder(txnIdForCreateOrder, txnAmtTextBoxValue, paymentTypeTextBoxValue, "30000");
+ this.requestStrByThead = this.createOrderRequestMsg;
showResult();
}
private void requestAdjustThead()
{
//jsonResultByThead = n5Core.processOffline(txnIdForOffline, txnAmtTextBoxValue, paymentAppIdComboBoxValue, "123456", panTextBoxValue, expDateTextBoxValue);
- // this.requestStrByThead = this.offlineRequestMsg;
- // showResult();
+ // this.requestStrByThead = this.offlineRequestMsg;
+ // showResult();
+ jsonResultByThead = n5Core.processAdjust(txnIdForPreAuth, txnAmtTextBoxValue, "0", paymentAppIdComboBoxValue);
+ this.requestStrByThead = this.adjustRequestMsg;
+ showResult();
}
private void requestRefundThead()
{
- jsonResultByThead = n5Core.requestRefund(txnIdForRefund, txnAmtTextBoxValue, paymentAppIdComboBoxValue, qrValueTextBoxValue);
+ jsonResultByThead = n5Core.requestRefund(txnIdForRefund, txnAmtTextBoxValue, paymentAppIdComboBoxValue, qrValueTextBoxValue, oriTxnDateTextBoxValue, hostRefNoTextBoxValue);
this.requestStrByThead = this.refundRequestMsg;
showResult();
}
private void requestRetrievalThead()
{
- jsonResultByThead = n5Core.requestRetrieval(ecrTxnIdTextBoxValue, 180000);
+ jsonResultByThead = n5Core.requestRetrieval(ecrTxnIdTextBoxValue, 10000);
this.requestStrByThead = this.retrievalRequestMsg;
showResult();
}
@@ -123,17 +159,18 @@ namespace ECR_N5_DLL_TestUI
{
while (isRepeatSubmit)
{
+ /*
String result = n5Core.requestRetrieval(ecrTxnIdTextBoxValue, 10000);
addRepeatLog("=============================count" + repeatCount + "=============================");
addRepeatLog("ecrTxnId = " + ecrTxnIdTextBoxValue);
- RetrievalResult retrievalResult = RetrievalResult.toRetrievalResultFromJsonMsg(result);
- if (retrievalResult != null && retrievalResult.Status.Equals("00"))
- {
- addRepeatLog("Retrieval Success!");
- }
- else
- addRepeatLog("Retrieval Failed!");
+ RetrievalResult retrievalResult = RetrievalResult.toRetrievalResultFromJsonMsg(result);*/
+ String result = n5Core.requestSale(getTxnId(), "10", "0", "CC", "", "30000");
+ addRepeatLog("=============================count" + repeatCount + "=============================");
+ addRepeatLog("ecrTxnId = " + ecrTxnIdTextBoxValue);
+
+ SaleResult saleResult = SaleResult.toSaleResultFromJsonMsg(result);
+ addRepeatLog("Sale Result:" + saleResult.Status);
}
@@ -145,6 +182,7 @@ namespace ECR_N5_DLL_TestUI
this.requestStrByThead = this.voidRequestMsg;
showResult();
}
+
private void requestSettlementThead()
{
jsonResultByThead = n5Core.sendSettlementtRequest();
@@ -152,6 +190,20 @@ namespace ECR_N5_DLL_TestUI
showResult();
}
+ private void requesGetInfoThead()
+ {
+ jsonResultByThead = n5Core.requestGetInfo();
+ this.requestStrByThead = this.getInfoRequestMsg;
+ showResult();
+ }
+
+ private void requesCheckUpdateThead()
+ {
+ jsonResultByThead = n5Core.checkUpdate();
+ this.requestStrByThead = this.checkUpdateRequestMsg;
+ showResult();
+ }
+
private void requestLinkRequestThead()
{
jsonResultByThead = n5Core.sendLinkTestRequest();
@@ -228,20 +280,9 @@ namespace ECR_N5_DLL_TestUI
showResult();
return;
}*/
- if (this.ecrTxnIdTextBox.Text == null || "".Equals(this.ecrTxnIdTextBox.Text.Trim()))
- {
- this.requestStrByThead = "Please input parameter.";
- this.jsonResultByThead = "Please input parameter.";
- showResult();
- this.ecrTxnIdTextBox.Focus();
- return;
- }
- else
- {
ecrTxnIdTextBoxValue = ecrTxnIdTextBox.Text;
Thread th = new Thread(requestRepeatRetrievalThead);
th.Start();
- }
}
@@ -264,10 +305,10 @@ namespace ECR_N5_DLL_TestUI
{
n5Core = n5coredll.N5Core.getInstance();
int initResult = n5Core.initN5Core(portName, baudRate, dataBits, stopBits, parity, timeOut);
- if (initResult == 0)
- {
+ //if (initResult == 0)
+ //{
n5CoreInitSuccess = true;
- }
+ //}
}
if (!n5CoreInitSuccess)
{
@@ -347,15 +388,14 @@ namespace ECR_N5_DLL_TestUI
qrValueTextBoxValue = this.qrValueTextBox.Text;
panTextBoxValue = this.panTextBox.Text;
expDateTextBoxValue = this.expDateTextBox.Text;
-
- txnIdForSale = this.getTxnId();
+ txnIdForPreAuth = this.ecrTxnIdTextBox.Text;
this.requestStrByThead = "Test Function : " + currEventName + "\n txnId = " + txnIdForPreAuth + "\n txnAmt = " + txnAmtTextBoxValue + "\n paymentAppId = " + paymentAppIdComboBoxValue + "\n qrValue = " + qrValueTextBoxValue;
showResult();
- addLog("txnId = " + txnIdForPreAuth + ", txnAmt = " + txnAmtTextBoxValue + ", paymentAppId = " + paymentAppIdComboBoxValue + ",qrValue = " + qrValueTextBoxValue);
+ addLog("txnId = " + txnAmtTextBoxValue + ", txnAmt = " + txnAmtTextBoxValue + ", paymentAppId = " + paymentAppIdComboBoxValue + ",qrValue = " + qrValueTextBoxValue);
//jsonResultByThead = n5Core.requestSale(this.getTxnId(), txnAmtTextBoxValue, "0", paymentAppIdComboBoxValue, qrValueTextBoxValue);
- this.preAuthRequestMsg = this.requestStrByThead;
+ this.adjustRequestMsg = this.requestStrByThead;
- Thread th = new Thread(requestPreauthThead);
+ Thread th = new Thread(requestAdjustThead);
th.Start();
}
@@ -458,6 +498,8 @@ namespace ECR_N5_DLL_TestUI
txnAmtTextBoxValue = this.txnAmtTextBox.Text;
paymentAppIdComboBoxValue = this.paymentAppIdComboBox.Text;
qrValueTextBoxValue = this.qrValueTextBox.Text;
+ oriTxnDateTextBoxValue = this.oriTxnDateTextBox.Text;
+ hostRefNoTextBoxValue = this.hostRefNoTextBox.Text;
txnIdForRefund = this.getTxnId();
this.requestStrByThead = "Test Function : " + currEventName + "\n txnId = " + txnIdForRefund + "\n txnAmt = " + txnAmtTextBoxValue + "\n paymentAppId = " + paymentAppIdComboBoxValue + "\n qrValue = " + qrValueTextBoxValue;
@@ -493,6 +535,27 @@ namespace ECR_N5_DLL_TestUI
th.Start();
}
}
+ else if ("HealthCheck".Equals(this.thisEvent))
+ {
+ this.requestStrByThead = "Test Function : " + currEventName;
+ showResult();
+
+ //jsonResultByThead = n5Core.requestRetrieval(ecrTxnIdTextBoxValue, 180000);
+ this.checkHealthRequestMsg = this.requestStrByThead;
+ Thread th = new Thread(requestCheckHealthThead);
+ th.Start();
+
+ }
+ else if ("SummaryEnquiry".Equals(this.thisEvent))
+ {
+ this.requestStrByThead = "Test Function : " + currEventName;
+ showResult();
+ enquiryPeriod = periodTextBox.Text;
+ //jsonResultByThead = n5Core.requestRetrieval(ecrTxnIdTextBoxValue, 180000);
+ this.summaryEnquiryRequestMsg = this.requestStrByThead;
+ Thread th = new Thread(requestSummaryEnquiryThead);
+ th.Start();
+ }
else if ("Void".Equals(this.thisEvent))
{
if (this.ecrTxnIdTextBox.Text == null || "".Equals(this.ecrTxnIdTextBox.Text.Trim()))
@@ -527,6 +590,59 @@ namespace ECR_N5_DLL_TestUI
Thread th = new Thread(requestSettlementThead);
th.Start();
}
+ else if ("CreateOrder".Equals(this.thisEvent))
+ {
+ if (this.txnAmtTextBox.Text == null || "".Equals(this.txnAmtTextBox.Text.Trim()))
+ {
+ this.requestStrByThead = "Please input parameter.";
+ this.jsonResultByThead = "Please input parameter.";
+ showResult();
+ this.txnAmtTextBox.Focus();
+ return;
+ }
+ else if (this.paymentTypeTextBox.Text == null || "".Equals(this.paymentTypeTextBox.Text.Trim()))
+ {
+ this.requestStrByThead = "Please input parameter.";
+ this.jsonResultByThead = "Please input parameter.";
+ showResult();
+ this.paymentTypeTextBox.Focus();
+ return;
+ }
+ else
+ {
+ txnAmtTextBoxValue = this.txnAmtTextBox.Text;
+ paymentAppIdComboBoxValue = this.paymentAppIdComboBox.Text;
+ paymentTypeTextBoxValue = this.paymentTypeTextBox.Text;
+ txnIdForCreateOrder = this.getTxnId();
+ this.requestStrByThead = "Test Function : " + currEventName;
+ showResult();
+
+ //jsonResultByThead = n5Core.sendSettlementtRequest();
+ this.createOrderRequestMsg = this.requestStrByThead;
+ Thread th = new Thread(requestCreateOrderThread);
+ th.Start();
+ }
+ }
+ else if ("GetInfo".Equals(this.thisEvent))
+ {
+ this.requestStrByThead = "Test Function : " + currEventName;
+ showResult();
+
+ //jsonResultByThead = n5Core.sendSettlementtRequest();
+ this.getInfoRequestMsg = this.requestStrByThead;
+ Thread th = new Thread(requesGetInfoThead);
+ th.Start();
+ }
+ else if ("CheckUpdate".Equals(this.thisEvent))
+ {
+ this.requestStrByThead = "Test Function : " + currEventName;
+ showResult();
+
+ //jsonResultByThead = n5Core.sendSettlementtRequest();
+ this.checkUpdateRequestMsg = this.requestStrByThead;
+ Thread th = new Thread(requesCheckUpdateThead);
+ th.Start();
+ }
else if ("Link Request".Equals(this.thisEvent))
{
this.requestStrByThead = "Test Function : " + currEventName;
@@ -667,6 +783,25 @@ namespace ECR_N5_DLL_TestUI
this.batchIdTextBox.IsEnabled = false;
this.settleDateTextBox.IsEnabled = false;
}
+ else if ("CreateOrder".Equals(this.thisEvent))
+ {
+ this.ecrTxnIdTextBox.Text = "";
+ this.txnAmtTextBox.IsEnabled = true;
+ this.paymentTypeTextBox.IsEnabled = true;
+ if (this.paymentAppIdComboBox.Text == null || "".Equals(this.paymentAppIdComboBox.Text))
+ {
+ this.paymentAppIdComboBox.Text = "CC";
+ }
+ this.batchIdTextBox.Text = "";
+ this.settleDateTextBox.Text = "";
+ this.paymentAppIdComboBox.IsEnabled = true;
+ this.qrValueTextBox.IsEnabled = true;
+ this.panTextBox.IsEnabled = true;
+ this.expDateTextBox.IsEnabled = true;
+ this.ecrTxnIdTextBox.IsEnabled = false;
+ this.batchIdTextBox.IsEnabled = false;
+ this.settleDateTextBox.IsEnabled = false;
+ }
else if("PreAuth".Equals(this.thisEvent))
{
this.ecrTxnIdTextBox.Text = "";
@@ -713,7 +848,7 @@ namespace ECR_N5_DLL_TestUI
this.batchIdTextBox.Text = "";
this.settleDateTextBox.Text = "";
this.paymentAppIdComboBox.IsEnabled = true;
- this.ecrTxnIdTextBox.IsEnabled = false;
+ this.ecrTxnIdTextBox.IsEnabled = true;
this.batchIdTextBox.IsEnabled = false;
this.settleDateTextBox.IsEnabled = false;
}
diff --git a/n5coredll/InstllResult.cs b/n5coredll/InstllResult.cs
new file mode 100644
index 0000000..f9bfc0e
--- /dev/null
+++ b/n5coredll/InstllResult.cs
@@ -0,0 +1,321 @@
+using System;
+using System.Text;
+namespace n5coredll
+{
+ public class InstllResult {
+ private static string TXN_ID = "TXN_ID";
+ private static string STATUS = "STATUS";
+ private static string TXN_AMT = "TXN_AMT";
+ private static string PAYMENT_TYPE = "PAYMENT_TYPE";
+ private static string RESP_CODE = "RESP_CODE";
+ private static string TRACE_NO = "TRACE_NO";
+ private static string TXN_DATE = "TXN_DATE";
+ private static string TXN_TIME = "TXN_TIME";
+ private static string HOST_REF = "HOST_REF";
+ private static string AUTH_CODE = "AUTH_CODE";
+
+ private static string MID = "MID";
+ private static string TID = "TID";
+ private static string PAN = "PAN";
+ private static string EXPIRY_DATE = "EXPIRY_DATE";
+ private static string AID = "AID";
+ private static string ENTRY_MODE = "ENTRY_MODE";
+ private static string BATCH_NO = "BATCH_NO";
+ private static string TC = "TC";
+ private static string APP = "APP";
+ private static string ACQUIRER = "ACQUIRER";
+
+ private string ecrRefTxnId;
+ private string status;
+ private decimal txnAmt;
+ private PaymentType paymentType;
+ private string respCode;
+ private string traceNo;
+ private string txnDate;
+ private string txnTime;
+ private string hostRef;
+ private string couponId;
+ private string authCode;
+
+ private string mid;
+ private string tid;
+ private string pan;
+ private string expiryDate;
+ private string aid;
+ private string entryMode;
+ private string batchNo;
+ private string tc;
+ private string app;
+ private string acquirer;
+
+ private void setEcrRefTxnId(string pEcrRefTxnId) {
+ ecrRefTxnId = pEcrRefTxnId;
+ }
+
+ public string EcrRefTxnId {
+ get { return ecrRefTxnId; }
+ }
+
+ public string Status {
+ get { return status; }
+ }
+ private void setStatus(string pStatus) {
+ this.status = pStatus;
+ }
+ public decimal TxnAmt {
+ get { return txnAmt; }
+ }
+ private void setTxnAmt(decimal pTxnAmt) {
+ this.txnAmt = pTxnAmt;
+ }
+ public PaymentType PaymentType {
+ get { return paymentType; }
+ }
+ private void setPaymentType(PaymentType pPaymentType) {
+ this.paymentType = pPaymentType;
+ }
+ public string RespCode {
+ get { return respCode; }
+ }
+ private void setRespCode(string pRespCode) {
+ this.respCode = pRespCode;
+ }
+ public string TraceNo {
+ get { return traceNo; }
+ }
+ private void setTraceNo(string pTraceNo) {
+ this.traceNo = pTraceNo;
+ }
+ public string TxnDate {
+ get { return txnDate; }
+ }
+ private void setTxnDate(string pTxnDate) {
+ this.txnDate = pTxnDate;
+ }
+ public string TxnTime {
+ get { return txnTime; }
+ }
+ private void setTxnTime(string pTxnTime) {
+ this.txnTime = pTxnTime;
+ }
+ public string HostRef {
+ get { return hostRef; }
+ }
+ private void setHostRef(string pHostRef) {
+ this.hostRef = pHostRef;
+ }
+ public string CouponId {
+ get { return couponId; }
+ }
+ private void setCouponId(string pCouponId) {
+ this.couponId = pCouponId;
+ }
+ public string AuthCode {
+ get { return authCode; }
+ }
+ private void setAuthCode(string pAuthCode) {
+ this.authCode = pAuthCode;
+ }
+ public string Mid {
+ get { return mid; }
+ }
+ private void setMid(string pMid) {
+ this.mid = pMid;
+ }
+ public string Tid {
+ get { return tid; }
+ }
+ private void setTid(string pTid) {
+ this.tid = pTid;
+ }
+ public string Pan {
+ get { return pan; }
+ }
+ private void setPan(string pPan) {
+ this.pan = pPan;
+ }
+ public string ExpiryDate {
+ get { return expiryDate; }
+ }
+ private void setExpiryDate(string pExpiryDate) {
+ this.expiryDate = pExpiryDate;
+ }
+ public string Aid {
+ get { return aid; }
+ }
+ private void setAid(string pAid) {
+ this.aid = pAid;
+ }
+ public string EntryMode {
+ get { return entryMode; }
+ }
+ private void setEntryMode(string pEntryMode) {
+ this.entryMode = pEntryMode;
+ }
+ public string BatchNo {
+ get { return batchNo; }
+ }
+ private void setBatchNo(string pBatchNo) {
+ this.batchNo = pBatchNo;
+ }
+ public string Tc {
+ get { return tc; }
+ }
+ private void setTc(string pTc) {
+ this.tc = pTc;
+ }
+ public string App {
+ get { return app; }
+ }
+ private void setApp(string pApp) {
+ this.app = pApp;
+ }
+ public string Acquirer {
+ get { return acquirer; }
+ }
+ private void setAcquirer(string pAcquirer) {
+ this.acquirer = pAcquirer;
+ }
+
+ private static string curTxnId;
+ public static string getCurTxnId()
+ {
+ return curTxnId;
+ }
+
+ public static string toJsonForInstl(string thisTxnId, decimal txnAmt, string tender, PaymentApp appId, string qrcValue) {
+ if (thisTxnId == null || "".Equals(thisTxnId)) {
+ Console.WriteLine("getTxnId is null ");
+ return null;
+ }
+ string instlMsg;
+ if (tender == null || tender.Equals(string.Empty))
+ instlMsg = "{\"EVENT_NAME\":\"INSTL\",\"PAYMENT_APP_ID\":\"" + ObjectUtil.getPaymentAppValue(appId) + "\",\"TXN_ID\":\"" + thisTxnId + "\",\"QRC_VALUE\":\"" + qrcValue + "\",\"TXN_AMT\":" + txnAmt.ToString() + "}";
+ else
+ instlMsg = "{\"EVENT_NAME\":\"INSTL\",\"PAYMENT_APP_ID\":\"" + ObjectUtil.getPaymentAppValue(appId) + "\",\"TENDER\":\"" + tender + "\",\"TXN_ID\":\"" + thisTxnId + "\",\"QRC_VALUE\":\"" + qrcValue + "\",\"TXN_AMT\":" + txnAmt.ToString() + "}";
+ return instlMsg;
+ }
+
+ private static string getTxnId() {
+ StringBuilder txnIdSb = new StringBuilder();
+ DateTime dt = DateTime.Now;
+ txnIdSb.Append(dt.ToString("yyyyMMddHHmmssfff"));
+ Console.WriteLine("txnIdSb = " + txnIdSb.ToString());
+ int randomTime = 0;
+ if (dt.Ticks.ToString().Length > 8) {
+ Console.WriteLine("Ticks.Length > 8 = " + dt.Ticks.ToString());
+ randomTime = int.Parse(dt.Ticks.ToString().Substring(0, 8));
+ }
+ else {
+ randomTime = int.Parse(dt.Ticks.ToString());
+ }
+
+ if (randomTime > 0) {
+ Random random = new Random(randomTime);
+ for (int i = 0; i < 15; i++) {
+ int thidRandom = random.Next(10);
+ txnIdSb.Append(thidRandom);
+ }
+ Console.WriteLine("txnIdSb.ToString = " + txnIdSb.ToString());
+ return txnIdSb.ToString();
+ }
+ else {
+ Console.WriteLine("randomTime is error = " + randomTime);
+ }
+
+ return "";
+ }
+
+ public static InstllResult toInstllResultFromJsonMsg(string jsonMsg) {
+ if (jsonMsg == null || !jsonMsg.StartsWith("{") || !jsonMsg.EndsWith("}")) {
+ return null;
+ }
+ int jsonLength = jsonMsg.Length;
+ jsonMsg = jsonMsg.Substring(0, jsonLength - 1);
+ jsonMsg = jsonMsg.Substring(1, jsonLength - 2);
+ string[] column = jsonMsg.Split(',');
+ string[] valueColumn = null;
+ string valueColumn0 = null;
+ string valueColumn1 = null;
+ InstllResult result = new InstllResult();
+
+ for (int i = 0; i < column.Length; i++) {
+ valueColumn = column[i].Split(':');
+ valueColumn0 = valueColumn[0].Replace('"', ' ').Trim();
+ valueColumn1 = valueColumn[1].Replace('"', ' ').Trim();
+ if (InstllResult.TXN_ID.Equals(valueColumn0)) {
+ result.setEcrRefTxnId(valueColumn1);
+ }
+ if (InstllResult.STATUS.Equals(valueColumn0)) {
+ result.setStatus(valueColumn1);
+ }
+
+ if (InstllResult.TXN_AMT.Equals(valueColumn0)) {
+ if (valueColumn1 == null || "".Equals(valueColumn1)) {
+ result.setTxnAmt(decimal.Parse("0.00", System.Globalization.NumberStyles.AllowDecimalPoint));
+ }
+ else {
+ result.setTxnAmt(decimal.Parse(valueColumn1));
+ }
+ }
+
+ if (InstllResult.PAYMENT_TYPE.Equals(valueColumn0)) {
+ result.setPaymentType(ObjectUtil.getPaymentType(valueColumn1));
+ }
+
+ if (InstllResult.RESP_CODE.Equals(valueColumn0)) {
+ result.setRespCode(valueColumn1);
+ }
+
+ if (InstllResult.TRACE_NO.Equals(valueColumn0)) {
+ result.setTraceNo(valueColumn1);
+ }
+ if (InstllResult.TXN_DATE.Equals(valueColumn0)) {
+ result.setTxnDate(valueColumn1);
+ }
+ if (InstllResult.TXN_TIME.Equals(valueColumn0)) {
+ result.setTxnTime(valueColumn1);
+ }
+
+ if (InstllResult.HOST_REF.Equals(valueColumn0)) {
+ result.setHostRef(valueColumn1);
+ }
+ if (InstllResult.AUTH_CODE.Equals(valueColumn0)) {
+ result.setAuthCode(valueColumn1);
+ }
+ if (InstllResult.MID.Equals(valueColumn0)) {
+ result.setMid(valueColumn1);
+ }
+ if (InstllResult.TID.Equals(valueColumn0)) {
+ result.setTid(valueColumn1);
+ }
+ if (InstllResult.PAN.Equals(valueColumn0)) {
+ result.setPan(valueColumn1);
+ }
+ if (InstllResult.EXPIRY_DATE.Equals(valueColumn0)) {
+ result.setExpiryDate(valueColumn1);
+ }
+ if (InstllResult.AID.Equals(valueColumn0)) {
+ result.setAid(valueColumn1);
+ }
+ if (InstllResult.ENTRY_MODE.Equals(valueColumn0)) {
+ result.setEntryMode(valueColumn1);
+ }
+ if (InstllResult.BATCH_NO.Equals(valueColumn0)) {
+ result.setBatchNo(valueColumn1);
+ }
+ if (InstllResult.APP.Equals(valueColumn0)) {
+ result.setApp(valueColumn1);
+ }
+ if (InstllResult.TC.Equals(valueColumn0)) {
+ result.setTc(valueColumn1);
+ }
+ if (InstllResult.ACQUIRER.Equals(valueColumn0)) {
+ result.setAcquirer(valueColumn1);
+ }
+
+ }
+ return result;
+ }
+ }
+}
diff --git a/n5coredll/LogUtil.cs b/n5coredll/LogUtil.cs
deleted file mode 100644
index b4726dd..0000000
--- a/n5coredll/LogUtil.cs
+++ /dev/null
@@ -1,72 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.IO;
-using System.Linq;
-using System.Text;
-
-namespace n5coredll
-{
- public class LogUtil
- {
- private static String mLogPath;
- private static LogUtil mInstance;
- public static LogUtil getInstance()
- {
- if (mInstance == null)
- mInstance = new LogUtil();
-
- return mInstance;
- }
-
- public void setLogPath(String logPath)
- {
- if (logPath.EndsWith(@"\"))
- mLogPath = logPath;
- else
- mLogPath = logPath + @"\";
- }
-
- private String getCurLogFile()
- {
-
- StringBuilder txnIdSb = new StringBuilder();
- DateTime dt = DateTime.Now;
- return ("n5dll" + "_" + dt.ToString("yyyyMMdd") +".log");
- }
-
- public void addRepeatLog(string logInfo)
- {
- try
- {
- String path = mLogPath + getCurLogFile();
- //path = @"C:\Users\rexli\AppData\Local\Temp\test.log";
- if (!File.Exists(path))
- {
- using (StreamWriter sw = File.CreateText(path))
- {
- sw.WriteLine(DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss:ffff") + " [LOGGER] " + logInfo);
- sw.Flush();
- sw.Close();
- }
-
- }
- else
- {
- using (StreamWriter sw = File.AppendText(path))
- {
- sw.WriteLine(DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss:ffff") + " [LOGGER] " + logInfo);
- sw.Flush();
- sw.Close();
- }
-
- }
- // Console.WriteLine(logInfo);
-
- }
- catch (Exception err)
- {
- Console.WriteLine("Exception = " + err);
- }
- }
- }
-}
\ No newline at end of file
diff --git a/n5coredll/N5Core.cs b/n5coredll/N5Core.cs
index d8c9125..7e210cc 100644
--- a/n5coredll/N5Core.cs
+++ b/n5coredll/N5Core.cs
@@ -2,10 +2,11 @@
using System.IO.Ports;
using System.Runtime.InteropServices;
using System.Text;
+using System.Threading;
namespace n5coredll
{
-
+
[ClassInterface(ClassInterfaceType.AutoDual)]
[Guid("92138541-8E7B-43FD-A4A4-748F28A934CD")]
[ProgId("n5coredll.N5Core")]
@@ -20,7 +21,7 @@ namespace n5coredll
private int mRecvTimes;
private byte[] mTotalRecvResult = new byte[10000];
private int mRecvIndex = 0;
-
+
private bool isReadyBack = false;
private int timeOut = 1200000;
private bool isGetACK = false;
@@ -88,10 +89,11 @@ namespace n5coredll
if (this.timeOut < 120000)
this.timeOut = 120000;
}
- catch {
+ catch
+ {
this.timeOut = 120000;
}
-
+
else
this.timeOut = 120000;
bool result = openSerialPort();
@@ -101,7 +103,7 @@ namespace n5coredll
if (RequestResult.toReqResultFromJsonMsg(echoResult).Status == STATUS_SUCC)
return 0;
else
- return - 1;
+ return -1;
}
else
return -1;
@@ -157,31 +159,24 @@ namespace n5coredll
}*/
//For Pacific Coffee only
- public string requestManualSale(string dtxnId, string dtxnAmt, string dtipAmt, string appId, string qrcValue, string pan, string expDate)
- {
- return processSale(dtxnId, dtxnAmt, dtipAmt, appId, qrcValue, pan, expDate);
- }
-
- public string requestSale(string dtxnId, string dtxnAmt, string dtipAmt, string appId, string qrcValue)
- {
- return processSale(dtxnId, dtxnAmt, dtipAmt, appId, qrcValue, "","");
- }
public string requestSale(string dtxnId, string dtxnAmt, string dtipAmt, string appId, string qrcValue, string pTimeout)
{
return processSale(dtxnId, dtxnAmt, dtipAmt, appId, qrcValue, "", "", pTimeout);
}
+ /*
public string requestSaleWithTimeout(string dtxnId, string dtxnAmt, string dtipAmt, string appId, string qrcValue, string pTimeout)
{
return processSale(dtxnId, dtxnAmt, dtipAmt, appId, qrcValue, "", "", pTimeout);
}
-
- public string requestRefund(string dtxnId, string dtxnAmt, string appId, string qrcValue)
+ */
+ public string requestRefund(string dtxnId, string dtxnAmt, string appId, string qrcValue, string txnDate, string hostRefNo)
{
- return processRefund(dtxnId, dtxnAmt, appId, qrcValue);
+ return processRefund(dtxnId, dtxnAmt, appId, qrcValue, txnDate, hostRefNo);
}
-
+
+ /*
private string processSale(string dtxnId, string dtxnAmt, string dtipAmt, string appId, string qrcValue, string pan, string expDate)
{
if (ifBusy)
@@ -208,26 +203,11 @@ namespace n5coredll
if (openSerialPort())
{
PaymentApp tmpAppId = ObjectUtil.getPaymentApp(appId);
- /*
- if (appId == "CC")
- tmpAppId = PaymentApp.CC;
- else if (appId == "QRC")
- tmpAppId = PaymentApp.QRC;
- else if (appId == "AMEX")
- tmpAppId = PaymentApp.AMEX;
- else if (appId == "CPN")
- tmpAppId = PaymentApp.CPN;
- else if (appId == "DC")
- tmpAppId = PaymentApp.DC;
- else if (appId == "NONE")
- tmpAppId = PaymentApp.NONE;
- else
- tmpAppId = PaymentApp.NONE;
- */
+
if (dtxnId == null)
dtxnId = getTxnId();
- string reqSaleStr = SaleResult.toJsonForSale(dtxnId, txnAmt, tipAmt, tmpAppId, qrcValue,pan,expDate);
+ string reqSaleStr = SaleResult.toJsonForSale(dtxnId, txnAmt, tipAmt, tmpAppId, qrcValue, pan, expDate);
Console.WriteLine("reqSaleStr = " + reqSaleStr);
if (reqSaleStr == null || "".Equals(reqSaleStr))
{
@@ -276,23 +256,22 @@ namespace n5coredll
this.resendReqMsg();
if (isReadyBack)
{
- closeSerialPort();
if (currResultJsonStr != null && !"".Equals(currResultJsonStr))
{
ifBusy = false;
+ closeSerialPort();
return currResultJsonStr;
}
}
}
else
{
- closeSerialPort();
TimeSpan txnInqSp = nowTime - lastInqTime;
if (inqCount >= 12)
ifEnd = true;
else if (inqCount == 0 || (inqCount > 0 && txnInqSp.TotalSeconds > 5))
{
- string retrivReusltStr = requestRetrieval(dtxnId, 10000);
+ string retrivReusltStr = requestInnerRetrieval(dtxnId, 10000);
inqCount++;
lastInqTime = DateTime.Now;
if (retrivReusltStr != null && !"".Equals(retrivReusltStr))
@@ -311,6 +290,7 @@ namespace n5coredll
retrivReusltStr = retrivReusltStr.Replace("\"STATUS\":\"00\"", "\"STATUS\":\"" + status + "\"");
}
ifBusy = false;
+ closeSerialPort();
return retrivReusltStr;
}
else if (retrievalResult.Status == STATUS_NO_TXN)
@@ -318,9 +298,10 @@ namespace n5coredll
string saleResultStr = "{\"EVENT_NAME\":\"SALE_RESP\",\"STATUS\":\"10\",\"TXN_ID\":\"" + dtxnId + "\",\"TXN_AMT\":" + txnAmt + ",\"QRC_VALUE\":\"" + qrcValue + "\"}";
//String saleResultStr = "\"EVENT_NAME\":\"SALE_RESP\",\"STATUS\":\"10\"";
- // retrivReusltStr = retrivReusltStr.Replace("RETRIEVAL_RESP", "SALE_RESP");
+ // retrivReusltStr = retrivReusltStr.Replace("RETRIEVAL_RESP", "SALE_RESP");
//retrivReusltStr = retrivReusltStr.Replace("\"STATUS\":\"13\"", "\"STATUS\":\"10\"");
ifBusy = false;
+ closeSerialPort();
return saleResultStr;
}
@@ -329,13 +310,13 @@ namespace n5coredll
isReadyBack = false;
}
}
-
+
Console.WriteLine("Timeout return : " + DateTime.Now.ToString());
closeSerialPort();
ifBusy = false;
return RequestResult.createRespErrJson("SALE_RESP", ERR_STATUS_TIMEOUT);
- }
+ }*/
private string processSale(string dtxnId, string dtxnAmt, string dtipAmt, string appId, string qrcValue, string pan, string expDate, string pTimeout)
{
@@ -353,6 +334,24 @@ namespace n5coredll
return RequestResult.createRespErrJson("SALE_RESP", ERR_STATUS_PARAM);
}
+ if (pTimeout != null && !pTimeout.Equals(string.Empty))
+ try
+ {
+ this.timeOut = int.Parse(pTimeout);
+
+ if (this.timeOut < 120000)
+ pTimeout = "120000";
+ else if (this.timeOut > 300000)
+ pTimeout = "300000";
+ }
+ catch
+ {
+ pTimeout = "120000";
+ }
+
+ else
+ pTimeout = "120000";
+
sendTime = 0;
isSending = false;
mRecvTimes = 0;
@@ -392,6 +391,7 @@ namespace n5coredll
return RequestResult.createRespErrJson("SALE_RESP", ERR_STATUS_PARAM);
}
currReqByteArr = packReqMsg(reqSaleStr);
+ //currReqByteArr = packReqMsg_test(reqSaleStr);
if (currReqByteArr == null || currReqByteArr.Length == 0)
{
Console.WriteLine("currReqByteArr is null. ");
@@ -436,9 +436,11 @@ namespace n5coredll
this.resendReqMsg();
if (isReadyBack)
{
- closeSerialPort();
if (currResultJsonStr != null && !"".Equals(currResultJsonStr))
{
+ if (currResultJsonStr.StartsWith("SALE")) {
+ closeSerialPort();
+ }
ifBusy = false;
return currResultJsonStr;
}
@@ -446,13 +448,12 @@ namespace n5coredll
}
else
{
- closeSerialPort();
TimeSpan txnInqSp = nowTime - lastInqTime;
//if (inqCount >= 12)
// ifEnd = true;
if (inqCount == 0 || (inqCount > 0 && txnInqSp.TotalSeconds > 5))
{
- retrivReusltStr = requestRetrieval(dtxnId, 10000);
+ retrivReusltStr = requestInnerRetrieval(dtxnId, 10000);
inqCount++;
lastInqTime = DateTime.Now;
if (retrivReusltStr != null && !"".Equals(retrivReusltStr))
@@ -471,6 +472,8 @@ namespace n5coredll
retrivReusltStr = retrivReusltStr.Replace("\"STATUS\":\"00\"", "\"STATUS\":\"" + status + "\"");
}
ifBusy = false;
+
+ closeSerialPort();
return retrivReusltStr;
}
else if (retrievalResult.Status == STATUS_NO_TXN)
@@ -481,6 +484,8 @@ namespace n5coredll
// retrivReusltStr = retrivReusltStr.Replace("RETRIEVAL_RESP", "SALE_RESP");
//retrivReusltStr = retrivReusltStr.Replace("\"STATUS\":\"13\"", "\"STATUS\":\"10\"");
ifBusy = false;
+
+ closeSerialPort();
return saleResultStr;
}
@@ -491,7 +496,7 @@ namespace n5coredll
}
//Do last txn inquiry
- retrivReusltStr = requestRetrieval(dtxnId, 10000);
+ retrivReusltStr = requestInnerRetrieval(dtxnId, 10000);
retrievalResult = RetrievalResult.toRetrievalResultFromJsonMsg(retrivReusltStr);
if (retrievalResult.Status == STATUS_SUCC)
{
@@ -506,6 +511,8 @@ namespace n5coredll
retrivReusltStr = retrivReusltStr.Replace("\"STATUS\":\"00\"", "\"STATUS\":\"" + status + "\"");
}
ifBusy = false;
+
+ closeSerialPort();
return retrivReusltStr;
}
else if (retrievalResult.Status == STATUS_NO_TXN)
@@ -516,6 +523,8 @@ namespace n5coredll
// retrivReusltStr = retrivReusltStr.Replace("RETRIEVAL_RESP", "SALE_RESP");
//retrivReusltStr = retrivReusltStr.Replace("\"STATUS\":\"13\"", "\"STATUS\":\"10\"");
ifBusy = false;
+
+ closeSerialPort();
return saleResultStr;
}
@@ -526,6 +535,219 @@ namespace n5coredll
return RequestResult.createRespErrJson("SALE_RESP", ERR_STATUS_TIMEOUT);
}
+ public string requestInstallment(string dtxnId, string dtxnAmt, string appId, string tender, string qrcValue, string pTimeout)
+ {
+ if (ifBusy)
+ return RequestResult.createRespErrJson("INSTL_RESP", ERR_STATUS_BUSY);
+ ifBusy = true;
+ SaleResult saleResult = null;
+ decimal txnAmt = decimal.Parse(dtxnAmt);
+ if (txnAmt.CompareTo(decimal.Parse("0")) < 1 )
+ {
+ Console.WriteLine("dtxnAmt parameter error");
+ closeSerialPort();
+ ifBusy = false;
+ return RequestResult.createRespErrJson("INSTL_RESP", ERR_STATUS_PARAM);
+ }
+
+ if (pTimeout != null && !pTimeout.Equals(string.Empty))
+ try
+ {
+ this.timeOut = int.Parse(pTimeout);
+
+ if (this.timeOut < 120000)
+ pTimeout = "120000";
+ else if (this.timeOut > 300000)
+ pTimeout = "300000";
+ }
+ catch
+ {
+ pTimeout = "120000";
+ }
+
+ else
+ pTimeout = "120000";
+ sendTime = 0;
+ isSending = false;
+ mRecvTimes = 0;
+ isReadyBack = false;
+ currReqByteArr = null;
+ currResultJsonStr = null;
+ isGetACK = false;
+ if (openSerialPort())
+ {
+ PaymentApp tmpAppId = ObjectUtil.getPaymentApp(appId);
+ /*
+ if (appId == "CC")
+ tmpAppId = PaymentApp.CC;
+ else if (appId == "QRC")
+ tmpAppId = PaymentApp.QRC;
+ else if (appId == "AMEX")
+ tmpAppId = PaymentApp.AMEX;
+ else if (appId == "CPN")
+ tmpAppId = PaymentApp.CPN;
+ else if (appId == "DC")
+ tmpAppId = PaymentApp.DC;
+ else if (appId == "NONE")
+ tmpAppId = PaymentApp.NONE;
+ else
+ tmpAppId = PaymentApp.NONE;
+ */
+ if (dtxnId == null)
+ dtxnId = getTxnId();
+
+ string reqSaleStr = InstllResult.toJsonForInstl(dtxnId, txnAmt, tender, tmpAppId, qrcValue);
+ Console.WriteLine("reqSaleStr = " + reqSaleStr);
+ if (reqSaleStr == null || "".Equals(reqSaleStr))
+ {
+ Console.WriteLine("reqSaleStr is null. ");
+ closeSerialPort();
+ ifBusy = false;
+ return RequestResult.createRespErrJson("INSTL_RESP", ERR_STATUS_PARAM);
+ }
+ currReqByteArr = packReqMsg(reqSaleStr);
+ if (currReqByteArr == null || currReqByteArr.Length == 0)
+ {
+ Console.WriteLine("currReqByteArr is null. ");
+ closeSerialPort();
+ ifBusy = false;
+ return RequestResult.createRespErrJson("INSTL_RESP", ERR_STATUS_PARAM);
+ }
+
+ Console.WriteLine("currReqByteArr = " + currReqByteArr);
+ Console.WriteLine("currReqByteArr.Length = " + currReqByteArr.Length);
+ saleResult = null;
+ this.sendReqMsg();
+ }
+ else
+ {
+ Console.WriteLine("serialPort no open. ");
+ closeSerialPort();
+ ifBusy = false;
+ return RequestResult.createRespErrJson("INSTL_RESP", ERR_STATUS_OPENCOM);
+ }
+
+ int iTimeout = int.Parse(pTimeout);
+
+ int sleepTime = iTimeout / 1000;
+ DateTime startTime = DateTime.Now;
+
+ Boolean ifEnd = false;
+ int inqCount = 0;
+ DateTime lastInqTime = DateTime.Now;
+ string retrivReusltStr;
+ RetrievalResult retrievalResult;
+
+ while (!ifEnd)
+ {
+ DateTime nowTime = DateTime.Now;
+ TimeSpan sp = nowTime - startTime;
+ if (sp.TotalSeconds > sleepTime)
+ ifEnd = true;
+ else if (sp.TotalSeconds < 30)
+ {
+ if (!isSending && !isGetACK)
+ this.resendReqMsg();
+ if (isReadyBack)
+ {
+ if (currResultJsonStr != null && !"".Equals(currResultJsonStr))
+ {
+ if (currResultJsonStr.StartsWith("INSTL"))
+ {
+ closeSerialPort();
+ }
+ ifBusy = false;
+ return currResultJsonStr;
+ }
+ }
+ }
+ else
+ {
+ TimeSpan txnInqSp = nowTime - lastInqTime;
+ //if (inqCount >= 12)
+ // ifEnd = true;
+ if (inqCount == 0 || (inqCount > 0 && txnInqSp.TotalSeconds > 5))
+ {
+ retrivReusltStr = requestInnerRetrieval(dtxnId, 10000);
+ inqCount++;
+ lastInqTime = DateTime.Now;
+ if (retrivReusltStr != null && !"".Equals(retrivReusltStr))
+ {
+ retrievalResult = RetrievalResult.toRetrievalResultFromJsonMsg(retrivReusltStr);
+ if (retrievalResult.Status == STATUS_SUCC)
+ {
+ if (retrievalResult.TxnStatus != TxnStatus.Confirming)
+ {
+ retrivReusltStr = retrivReusltStr.Replace("RETRIEVAL_RESP", "SALE_RESP");
+ String status = "10";
+ if (retrievalResult.TxnStatus == TxnStatus.Approved)
+ status = "00";
+ else
+ status = "10";
+ retrivReusltStr = retrivReusltStr.Replace("\"STATUS\":\"00\"", "\"STATUS\":\"" + status + "\"");
+ }
+ ifBusy = false;
+
+ closeSerialPort();
+ return retrivReusltStr;
+ }
+ else if (retrievalResult.Status == STATUS_NO_TXN)
+ {
+ string saleResultStr = "{\"EVENT_NAME\":\"INSTL_RESP\",\"STATUS\":\"10\",\"TXN_ID\":\"" + dtxnId + "\",\"TXN_AMT\":" + txnAmt + ",\"QRC_VALUE\":\"" + qrcValue + "\"}";
+
+ //String saleResultStr = "\"EVENT_NAME\":\"SALE_RESP\",\"STATUS\":\"10\"";
+ // retrivReusltStr = retrivReusltStr.Replace("RETRIEVAL_RESP", "SALE_RESP");
+ //retrivReusltStr = retrivReusltStr.Replace("\"STATUS\":\"13\"", "\"STATUS\":\"10\"");
+ ifBusy = false;
+
+ closeSerialPort();
+ return saleResultStr;
+ }
+
+ }
+ }
+ isReadyBack = false;
+ }
+ }
+
+ //Do last txn inquiry
+ retrivReusltStr = requestInnerRetrieval(dtxnId, 10000);
+ retrievalResult = RetrievalResult.toRetrievalResultFromJsonMsg(retrivReusltStr);
+ if (retrievalResult.Status == STATUS_SUCC)
+ {
+ if (retrievalResult.TxnStatus != TxnStatus.Confirming)
+ {
+ retrivReusltStr = retrivReusltStr.Replace("RETRIEVAL_RESP", "SALE_RESP");
+ String status = "10";
+ if (retrievalResult.TxnStatus == TxnStatus.Approved)
+ status = "00";
+ else
+ status = "10";
+ retrivReusltStr = retrivReusltStr.Replace("\"STATUS\":\"00\"", "\"STATUS\":\"" + status + "\"");
+ }
+ ifBusy = false;
+ closeSerialPort();
+ return retrivReusltStr;
+ }
+ else if (retrievalResult.Status == STATUS_NO_TXN)
+ {
+ string saleResultStr = "{\"EVENT_NAME\":\"INSTL_RESP\",\"STATUS\":\"10\",\"TXN_ID\":\"" + dtxnId + "\",\"TXN_AMT\":" + txnAmt + ",\"QRC_VALUE\":\"" + qrcValue + "\"}";
+
+ //String saleResultStr = "\"EVENT_NAME\":\"SALE_RESP\",\"STATUS\":\"10\"";
+ // retrivReusltStr = retrivReusltStr.Replace("RETRIEVAL_RESP", "SALE_RESP");
+ //retrivReusltStr = retrivReusltStr.Replace("\"STATUS\":\"13\"", "\"STATUS\":\"10\"");
+ ifBusy = false;
+ closeSerialPort();
+ return saleResultStr;
+ }
+
+
+ Console.WriteLine("Timeout return : " + DateTime.Now.ToString());
+ closeSerialPort();
+ ifBusy = false;
+ return RequestResult.createRespErrJson("INSTL_RESP", ERR_STATUS_TIMEOUT);
+ }
+
public string processPreauth(string dtxnId, string dtxnAmt, string appId, string pan, string expDate)
{
if (ifBusy)
@@ -619,9 +841,12 @@ namespace n5coredll
this.resendReqMsg();
if (isReadyBack)
{
- closeSerialPort();
if (currResultJsonStr != null && !"".Equals(currResultJsonStr))
{
+ if (currResultJsonStr.StartsWith("PREAUTH"))
+ {
+ closeSerialPort();
+ }
ifBusy = false;
return currResultJsonStr;
}
@@ -629,13 +854,12 @@ namespace n5coredll
}
else
{
- closeSerialPort();
TimeSpan txnInqSp = nowTime - lastInqTime;
if (inqCount >= 12)
ifEnd = true;
else if (inqCount == 0 || (inqCount > 0 && txnInqSp.TotalSeconds > 5))
{
- string retrivReusltStr = requestRetrieval(dtxnId, 10000);
+ string retrivReusltStr = requestInnerRetrieval(dtxnId, 10000);
inqCount++;
lastInqTime = DateTime.Now;
if (retrivReusltStr != null && !"".Equals(retrivReusltStr))
@@ -654,6 +878,7 @@ namespace n5coredll
retrivReusltStr = retrivReusltStr.Replace("\"STATUS\":\"00\"", "\"STATUS\":\"" + status + "\"");
}
ifBusy = false;
+ closeSerialPort();
return retrivReusltStr;
}
else if (retrievalResult.Status == STATUS_NO_TXN)
@@ -664,6 +889,7 @@ namespace n5coredll
// retrivReusltStr = retrivReusltStr.Replace("RETRIEVAL_RESP", "SALE_RESP");
//retrivReusltStr = retrivReusltStr.Replace("\"STATUS\":\"13\"", "\"STATUS\":\"10\"");
ifBusy = false;
+ closeSerialPort();
return saleResultStr;
}
@@ -689,7 +915,7 @@ namespace n5coredll
ifBusy = true;
SaleResult saleResult = null;
decimal txnAmt = decimal.Parse(dtxnAmt);
- if (txnAmt.CompareTo(decimal.Parse("0")) < 1 )
+ if (txnAmt.CompareTo(decimal.Parse("0")) < 1)
{
Console.WriteLine("dtxnAmt or dtipAmt parameter error");
closeSerialPort();
@@ -775,9 +1001,10 @@ namespace n5coredll
this.resendReqMsg();
if (isReadyBack)
{
- closeSerialPort();
if (currResultJsonStr != null && !"".Equals(currResultJsonStr))
{
+ if (currResultJsonStr.StartsWith("OFFLINE"))
+ closeSerialPort();
ifBusy = false;
return currResultJsonStr;
}
@@ -785,7 +1012,6 @@ namespace n5coredll
}
else
{
- closeSerialPort();
TimeSpan txnInqSp = nowTime - lastInqTime;
if (inqCount >= 12)
ifEnd = true;
@@ -810,6 +1036,8 @@ namespace n5coredll
retrivReusltStr = retrivReusltStr.Replace("\"STATUS\":\"00\"", "\"STATUS\":\"" + status + "\"");
}
ifBusy = false;
+
+ closeSerialPort();
return retrivReusltStr;
}
else if (retrievalResult.Status == STATUS_NO_TXN)
@@ -820,6 +1048,8 @@ namespace n5coredll
// retrivReusltStr = retrivReusltStr.Replace("RETRIEVAL_RESP", "SALE_RESP");
//retrivReusltStr = retrivReusltStr.Replace("\"STATUS\":\"13\"", "\"STATUS\":\"10\"");
ifBusy = false;
+
+ closeSerialPort();
return saleResultStr;
}
@@ -930,9 +1160,10 @@ namespace n5coredll
this.resendReqMsg();
if (isReadyBack)
{
- closeSerialPort();
if (currResultJsonStr != null && !"".Equals(currResultJsonStr))
{
+ if (currResultJsonStr.StartsWith("ADJUST"))
+ closeSerialPort();
ifBusy = false;
return currResultJsonStr;
}
@@ -940,7 +1171,6 @@ namespace n5coredll
}
else
{
- closeSerialPort();
TimeSpan txnInqSp = nowTime - lastInqTime;
if (inqCount >= 12)
ifEnd = true;
@@ -965,6 +1195,8 @@ namespace n5coredll
retrivReusltStr = retrivReusltStr.Replace("\"STATUS\":\"00\"", "\"STATUS\":\"" + status + "\"");
}
ifBusy = false;
+
+ closeSerialPort();
return retrivReusltStr;
}
else if (retrievalResult.Status == STATUS_NO_TXN)
@@ -975,6 +1207,8 @@ namespace n5coredll
// retrivReusltStr = retrivReusltStr.Replace("RETRIEVAL_RESP", "SALE_RESP");
//retrivReusltStr = retrivReusltStr.Replace("\"STATUS\":\"13\"", "\"STATUS\":\"10\"");
ifBusy = false;
+
+ closeSerialPort();
return saleResultStr;
}
@@ -998,7 +1232,7 @@ namespace n5coredll
ifBusy = true;
if (originalEcrRefTxnId == null || "".Equals(originalEcrRefTxnId.Trim()))
{
- Console.WriteLine("parameter error");
+ Console.WriteLine("parameter error");
closeSerialPort();
ifBusy = false;
return RequestResult.createRespErrJson("VOID_RESP", ERR_STATUS_PARAM);
@@ -1062,9 +1296,10 @@ namespace n5coredll
this.resendReqMsg();
if (isReadyBack)
{
- closeSerialPort();
if (currResultJsonStr != null && !"".Equals(currResultJsonStr))
{
+ if (currResultJsonStr.StartsWith("VOID"))
+ closeSerialPort();
ifBusy = false;
return currResultJsonStr;
}
@@ -1096,6 +1331,8 @@ namespace n5coredll
status = "10";
retrivReusltStr = retrivReusltStr.Replace("\"STATUS\":\"00\"", "\"STATUS\":\"" + status + "\"");
}
+ ifBusy = false;
+ closeSerialPort();
return retrivReusltStr;
}
else if (retrievalResult.Status == STATUS_NO_TXN)
@@ -1104,6 +1341,7 @@ namespace n5coredll
//retrivReusltStr = retrivReusltStr.Replace("RETRIEVAL_RESP", "VOID_RESP");
ifBusy = false;
+ closeSerialPort();
return voidResultStr;
}
@@ -1112,14 +1350,14 @@ namespace n5coredll
isReadyBack = false;
}
}
-
+
Console.WriteLine("Timeout return : " + DateTime.Now.ToString());
closeSerialPort();
ifBusy = false;
return RequestResult.createRespErrJson("VOID_RESP", ERR_STATUS_TIMEOUT);
}
- private string processRefund(string dtxnId, string dtxnAmt, string appId, string qrcValue)
+ private string processRefund(string dtxnId, string dtxnAmt, string appId, string qrcValue, string txnDate, string hostRefNo)
{
if (ifBusy)
return RequestResult.createRespErrJson("REFUND_RESP", ERR_STATUS_BUSY);
@@ -1164,7 +1402,7 @@ namespace n5coredll
if (dtxnId == null)
dtxnId = getTxnId();
- string reqRefundStr = RefundResult.toJsonForRefund(dtxnId, txnAmt, tmpAppId, qrcValue);
+ string reqRefundStr = RefundResult.toJsonForRefund(dtxnId, txnAmt, tmpAppId, qrcValue, txnDate, hostRefNo);
Console.WriteLine("reqRefundStr = " + reqRefundStr);
if (reqRefundStr == null || "".Equals(reqRefundStr))
{
@@ -1216,9 +1454,11 @@ namespace n5coredll
this.resendReqMsg();
if (isReadyBack)
{
- closeSerialPort();
+
if (currResultJsonStr != null && !"".Equals(currResultJsonStr))
{
+ if (currResultJsonStr.StartsWith("REFUND"))
+ closeSerialPort();
ifBusy = false;
return currResultJsonStr;
}
@@ -1226,7 +1466,6 @@ namespace n5coredll
}
else
{
- closeSerialPort();
TimeSpan txnInqSp = nowTime - lastInqTime;
if (inqCount >= 12)
ifEnd = true;
@@ -1251,6 +1490,7 @@ namespace n5coredll
retrivReusltStr = retrivReusltStr.Replace("\"STATUS\":\"00\"", "\"STATUS\":\"" + status + "\"");
}
ifBusy = false;
+ closeSerialPort();
return retrivReusltStr;
}
else if (retrievalResult.Status == STATUS_NO_TXN)
@@ -1261,6 +1501,7 @@ namespace n5coredll
// retrivReusltStr = retrivReusltStr.Replace("RETRIEVAL_RESP", "SALE_RESP");
//retrivReusltStr = retrivReusltStr.Replace("\"STATUS\":\"13\"", "\"STATUS\":\"10\"");
ifBusy = false;
+ closeSerialPort();
return saleResultStr;
}
@@ -1274,9 +1515,11 @@ namespace n5coredll
Console.WriteLine("Timeout return : " + DateTime.Now.ToString());
closeSerialPort();
ifBusy = false;
- return RequestResult.createRespErrJson("SALE_RESP", ERR_STATUS_TIMEOUT);
+ return RequestResult.createRespErrJson("REFUND_RESP", ERR_STATUS_TIMEOUT);
}
+
+
int linkTimeout = 10000;
public string sendLinkTestRequest()
{
@@ -1298,7 +1541,7 @@ namespace n5coredll
{
closeSerialPort();
ifBusy = false;
- return RequestResult.createRespErrJson("ECHO_RESP", ERR_STATUS_PARAM);
+ return RequestResult.createRespErrJson("ECHO_RESP", ERR_STATUS_PARAM);
//return "Request failed: params error";
}
@@ -1308,7 +1551,7 @@ namespace n5coredll
}
else
{
-
+
closeSerialPort();
ifBusy = false;
return RequestResult.createRespErrJson("ECHO_RESP", ERR_STATUS_OPENCOM);
@@ -1331,6 +1574,7 @@ namespace n5coredll
this.resendReqMsg();
if (isReadyBack)
{
+ Thread.Sleep(500);
closeSerialPort();
if (currResultJsonStr != null && !"".Equals(currResultJsonStr))
{
@@ -1413,6 +1657,140 @@ namespace n5coredll
return RequestResult.createRespErrJson("SETTLE_RESP", ERR_STATUS_TIMEOUT);
}
+ public string requestGetInfo()
+ {
+ if (ifBusy)
+ return RequestResult.createRespErrJson("GETDEVICEINFO_RESP", ERR_STATUS_BUSY);
+ ifBusy = true;
+ sendTime = 0;
+ isSending = false;
+ mRecvTimes = 0;
+ isReadyBack = false;
+ currReqByteArr = null;
+ currResultJsonStr = null;
+ RequestResult reqResult = null;
+ isGetACK = false;
+ if (openSerialPort())
+ {
+ currReqByteArr = this.packReqMsg(RequestResult.toJsonGetInfo());
+ if (currReqByteArr == null || currReqByteArr.Length == 0)
+ {
+ closeSerialPort();
+ ifBusy = false;
+ return RequestResult.createRespErrJson("GETDEVICEINFO_RESP", ERR_STATUS_PARAM);
+ //return "Request failed: params error";
+ }
+
+ Console.WriteLine("currReqByteArr = " + currReqByteArr);
+ Console.WriteLine("currReqByteArr.Length = " + currReqByteArr.Length);
+ this.sendReqMsg();
+ }
+ else
+ {
+ ifBusy = false;
+ closeSerialPort();
+ return RequestResult.createRespErrJson("GETDEVICEINFO_RESP", ERR_STATUS_OPENCOM);
+ }
+
+ int sleepTime = timeOut / 1000;
+
+ DateTime startTime = DateTime.Now;
+
+ Boolean ifEnd = false;
+ while (!ifEnd)
+ {
+ DateTime nowTime = DateTime.Now;
+ TimeSpan sp = nowTime - startTime;
+ if (sp.TotalSeconds > sleepTime)
+ ifEnd = true;
+ else
+ {
+ if (!isSending && !isGetACK)
+ this.resendReqMsg();
+ if (isReadyBack)
+ {
+ closeSerialPort();
+ if (currResultJsonStr != null && !"".Equals(currResultJsonStr))
+ {
+ ifBusy = false;
+ return currResultJsonStr;
+ }
+ }
+ }
+ }
+
+ Console.WriteLine("Timeout return : " + DateTime.Now.ToString());
+ ifBusy = false;
+ return RequestResult.createRespErrJson("GETDEVICEINFO_RESP", ERR_STATUS_TIMEOUT);
+ }
+
+ public string checkUpdate()
+ {
+ if (ifBusy)
+ return RequestResult.createRespErrJson("CHECKUPDATE", ERR_STATUS_BUSY);
+ ifBusy = true;
+ sendTime = 0;
+ isSending = false;
+ mRecvTimes = 0;
+ isReadyBack = false;
+ currReqByteArr = null;
+ currResultJsonStr = null;
+ RequestResult reqResult = null;
+ isGetACK = false;
+ if (openSerialPort())
+ {
+ currReqByteArr = this.packReqMsg(RequestResult.toCheckUpdate());
+ if (currReqByteArr == null || currReqByteArr.Length == 0)
+ {
+ closeSerialPort();
+ ifBusy = false;
+ return RequestResult.createRespErrJson("CHECKUPDATE", ERR_STATUS_PARAM);
+ //return "Request failed: params error";
+ }
+
+ Console.WriteLine("currReqByteArr = " + currReqByteArr);
+ Console.WriteLine("currReqByteArr.Length = " + currReqByteArr.Length);
+ this.sendReqMsg();
+ }
+ else
+ {
+ ifBusy = false;
+ closeSerialPort();
+ return RequestResult.createRespErrJson("CHECKUPDATE", ERR_STATUS_OPENCOM);
+ }
+
+ int sleepTime = timeOut / 1000;
+
+ DateTime startTime = DateTime.Now;
+
+ Boolean ifEnd = false;
+ while (!ifEnd)
+ {
+ DateTime nowTime = DateTime.Now;
+ TimeSpan sp = nowTime - startTime;
+ if (sp.TotalSeconds > sleepTime)
+ ifEnd = true;
+ else
+ {
+ if (!isSending && !isGetACK)
+ this.resendReqMsg();
+ if (isReadyBack)
+ {
+ closeSerialPort();
+ if (currResultJsonStr != null && !"".Equals(currResultJsonStr))
+ {
+ ifBusy = false;
+ return currResultJsonStr;
+ }
+ }
+ }
+ }
+
+ Console.WriteLine("Timeout return : " + DateTime.Now.ToString());
+ ifBusy = false;
+ return RequestResult.createRespErrJson("CHECKUPDATE", ERR_STATUS_TIMEOUT);
+ }
+
public string sendParam()
{
if (ifBusy)
@@ -1424,17 +1802,97 @@ namespace n5coredll
isReadyBack = false;
currReqByteArr = null;
currResultJsonStr = null;
- RequestResult reqResult = null;
+ RequestResult reqResult = null;
+ isGetACK = false;
+ if (openSerialPort())
+ {
+ currReqByteArr = this.packReqMsg(RequestResult.toJsonParam());
+ if (currReqByteArr == null || currReqByteArr.Length == 0)
+ {
+ closeSerialPort();
+ ifBusy = false;
+ return RequestResult.createRespErrJson("PARAM_RESP", ERR_STATUS_PARAM);
+ //return "Request failed: params error";
+ }
+
+ Console.WriteLine("currReqByteArr = " + currReqByteArr);
+ Console.WriteLine("currReqByteArr.Length = " + currReqByteArr.Length);
+ this.sendReqMsg();
+ }
+ else
+ {
+ ifBusy = false;
+ closeSerialPort();
+ return RequestResult.createRespErrJson("PARAM_RESP", ERR_STATUS_OPENCOM);
+ }
+
+ int sleepTime = timeOut / 1000;
+
+ DateTime startTime = DateTime.Now;
+
+ Boolean ifEnd = false;
+ while (!ifEnd)
+ {
+ DateTime nowTime = DateTime.Now;
+ TimeSpan sp = nowTime - startTime;
+ if (sp.TotalSeconds > sleepTime)
+ ifEnd = true;
+ else
+ {
+ if (!isSending && !isGetACK)
+ this.resendReqMsg();
+ if (isReadyBack)
+ {
+ closeSerialPort();
+ if (currResultJsonStr != null && !"".Equals(currResultJsonStr))
+ {
+ ifBusy = false;
+ return currResultJsonStr;
+ }
+ }
+ }
+ }
+
+ Console.WriteLine("Timeout return : " + DateTime.Now.ToString());
+ ifBusy = false;
+ return RequestResult.createRespErrJson("PARAM_RESP", ERR_STATUS_TIMEOUT);
+ }
+
+ public string requestRetrieval(string txnId, int pTimeOut)
+ {
+ RetrievalResult retrievalResult = null;
+ if (txnId == null || "".Equals(txnId.Trim()))
+ {
+ Console.WriteLine("parameter error");
+ closeSerialPort();
+ //return "Request failed: params error";
+ return RequestResult.createRespErrJson("RETRIEVAL_RESP", ERR_STATUS_PARAM);
+ }
+
+ sendTime = 0;
+ isSending = false;
+ mRecvTimes = 0;
+ isReadyBack = false;
+ currReqByteArr = null;
+ currResultJsonStr = null;
isGetACK = false;
+
if (openSerialPort())
{
- currReqByteArr = this.packReqMsg(RequestResult.toJsonParam());
+ string reqRetrievalStr = RetrievalResult.toJsonForRetrieval(txnId);
+ Console.WriteLine("reqRetrievalStr = " + reqRetrievalStr);
+ if (reqRetrievalStr == null || "".Equals(reqRetrievalStr))
+ {
+ Console.WriteLine("reqRetrievalStr is null. ");
+ closeSerialPort();
+ return RequestResult.createRespErrJson("RETRIEVAL_RESP", ERR_STATUS_PARAM);
+ }
+ currReqByteArr = packReqMsg(reqRetrievalStr);
if (currReqByteArr == null || currReqByteArr.Length == 0)
{
+ Console.WriteLine("currReqByteArr is null. ");
closeSerialPort();
- ifBusy = false;
- return RequestResult.createRespErrJson("PARAM_RESP", ERR_STATUS_PARAM);
- //return "Request failed: params error";
+ return RequestResult.createRespErrJson("RETRIEVAL_RESP", ERR_STATUS_PARAM);
}
Console.WriteLine("currReqByteArr = " + currReqByteArr);
@@ -1443,12 +1901,12 @@ namespace n5coredll
}
else
{
- ifBusy = false;
+ Console.WriteLine("serialPort no open. ");
closeSerialPort();
- return RequestResult.createRespErrJson("PARAM_RESP", ERR_STATUS_OPENCOM);
+ return RequestResult.createRespErrJson("RETRIEVAL_RESP", ERR_STATUS_OPENCOM);
}
- int sleepTime = timeOut / 1000;
+ int sleepTime = pTimeOut / 1000;
DateTime startTime = DateTime.Now;
@@ -1474,20 +1932,48 @@ namespace n5coredll
}
}
}
+ /*
+ for (int i = 0; i < sleepTime; i++)
+ {
+ Console.WriteLine("retrievalResult = " + retrievalResult);
+ if (!isReadyBack)
+ {
+ if (i > 9 && i % 10 == 0 && !isGetACK)
+ {
+ this.resendReqMsg();
+ }
+ Console.WriteLine("Sleep i = " + i + ", " + DateTime.Now.ToString());
+ System.Threading.Thread.Sleep(1000);
+ }
+ else
+ {
+ closeSerialPort();
+ if (currResultJsonStr != null && !"".Equals(currResultJsonStr))
+ {
+ return currResultJsonStr;
+ }
+ else
+ {
+ //return "Request failed: sytem error";
+ return RequestResult.createRespErrJson("RETRIEVAL_RESP", ERR_STATUS_SYSTEM);
+ }
+
+ }
+ }*/
+ //
Console.WriteLine("Timeout return : " + DateTime.Now.ToString());
- ifBusy = false;
- return RequestResult.createRespErrJson("PARAM_RESP", ERR_STATUS_TIMEOUT);
+ closeSerialPort();
+ return RequestResult.createRespErrJson("RETRIEVAL_RESP", ERR_STATUS_TIMEOUT);
}
- public string requestRetrieval(string txnId, int pTimeOut)
+
+ private string requestInnerRetrieval(string txnId, int pTimeOut)
{
RetrievalResult retrievalResult = null;
if (txnId == null || "".Equals(txnId.Trim()))
{
Console.WriteLine("parameter error");
- closeSerialPort();
- //return "Request failed: params error";
return RequestResult.createRespErrJson("RETRIEVAL_RESP", ERR_STATUS_PARAM);
}
@@ -1506,14 +1992,12 @@ namespace n5coredll
if (reqRetrievalStr == null || "".Equals(reqRetrievalStr))
{
Console.WriteLine("reqRetrievalStr is null. ");
- closeSerialPort();
return RequestResult.createRespErrJson("RETRIEVAL_RESP", ERR_STATUS_PARAM);
}
currReqByteArr = packReqMsg(reqRetrievalStr);
if (currReqByteArr == null || currReqByteArr.Length == 0)
{
Console.WriteLine("currReqByteArr is null. ");
- closeSerialPort();
return RequestResult.createRespErrJson("RETRIEVAL_RESP", ERR_STATUS_PARAM);
}
@@ -1524,7 +2008,6 @@ namespace n5coredll
else
{
Console.WriteLine("serialPort no open. ");
- closeSerialPort();
return RequestResult.createRespErrJson("RETRIEVAL_RESP", ERR_STATUS_OPENCOM);
}
@@ -1539,13 +2022,12 @@ namespace n5coredll
TimeSpan sp = nowTime - startTime;
if (sp.TotalSeconds > sleepTime)
ifEnd = true;
- else
+ else
{
if (!isSending && !isGetACK)
this.resendReqMsg();
if (isReadyBack)
{
- closeSerialPort();
if (currResultJsonStr != null && !"".Equals(currResultJsonStr))
{
ifBusy = false;
@@ -1583,12 +2065,104 @@ namespace n5coredll
}
}*/
- //
- Console.WriteLine("Timeout return : " + DateTime.Now.ToString());
- closeSerialPort();
+ //
+ Console.WriteLine("Timeout return : " + DateTime.Now.ToString());
return RequestResult.createRespErrJson("RETRIEVAL_RESP", ERR_STATUS_TIMEOUT);
}
+ public string requestCreateOrder(string txnId, string dtxnAmt, string paymentType, string pTimeOut)
+ {
+ if (ifBusy)
+ return RequestResult.createRespErrJson("CREATE_ORDER_RESP", ERR_STATUS_BUSY);
+ ifBusy = true;
+ RequestResult result = null;
+ decimal txnAmt = decimal.Parse(dtxnAmt);
+ if (txnId == null || "".Equals(txnId.Trim()))
+ {
+ Console.WriteLine("parameter error");
+ closeSerialPort();
+ //return "Request failed: params error";
+ return RequestResult.createRespErrJson("CREATE_ORDER_RESP", ERR_STATUS_PARAM);
+ }
+
+ if (txnAmt.CompareTo(decimal.Parse("0")) < 1)
+ {
+ Console.WriteLine("dtxnAmt parameter error");
+ closeSerialPort();
+ ifBusy = false;
+ return RequestResult.createRespErrJson("CREATE_ORDER_RESP", ERR_STATUS_PARAM);
+ }
+
+ sendTime = 0;
+ isSending = false;
+ mRecvTimes = 0;
+ isReadyBack = false;
+ currReqByteArr = null;
+ currResultJsonStr = null;
+ isGetACK = false;
+
+ if (openSerialPort())
+ {
+ string requestStr = RequestResult.toJsonForCreateOrder(txnId,txnAmt,paymentType);
+ Console.WriteLine("requestStr = " + requestStr);
+ if (requestStr == null || "".Equals(requestStr))
+ {
+ Console.WriteLine("requestStr is null. ");
+ closeSerialPort();
+ return RequestResult.createRespErrJson("CREATE_ORDER_RESP", ERR_STATUS_PARAM);
+ }
+ currReqByteArr = packReqMsg(requestStr);
+ if (currReqByteArr == null || currReqByteArr.Length == 0)
+ {
+ Console.WriteLine("currReqByteArr is null. ");
+ closeSerialPort();
+ return RequestResult.createRespErrJson("CREATE_ORDER_RESP", ERR_STATUS_PARAM);
+ }
+
+ Console.WriteLine("currReqByteArr = " + currReqByteArr);
+ Console.WriteLine("currReqByteArr.Length = " + currReqByteArr.Length);
+ this.sendReqMsg();
+ }
+ else
+ {
+ Console.WriteLine("serialPort no open. ");
+ closeSerialPort();
+ return RequestResult.createRespErrJson("CREATE_ORDER_RESP", ERR_STATUS_OPENCOM);
+ }
+ int iTimeout = int.Parse(pTimeOut);
+
+ int sleepTime = iTimeout / 1000;
+
+ DateTime startTime = DateTime.Now;
+
+ Boolean ifEnd = false;
+ while (!ifEnd)
+ {
+ DateTime nowTime = DateTime.Now;
+ TimeSpan sp = nowTime - startTime;
+ if (sp.TotalSeconds > sleepTime)
+ ifEnd = true;
+ else
+ {
+ if (!isSending && !isGetACK)
+ this.resendReqMsg();
+ if (isReadyBack)
+ {
+ closeSerialPort();
+ if (currResultJsonStr != null && !"".Equals(currResultJsonStr))
+ {
+ ifBusy = false;
+ return currResultJsonStr;
+ }
+ }
+ }
+ }
+
+ //
+ Console.WriteLine("Timeout return : " + DateTime.Now.ToString());
+ closeSerialPort();
+ return RequestResult.createRespErrJson("CREATE_ORDER_RESP", ERR_STATUS_TIMEOUT);
+ }
int abortTimeout = 10000;
public string sendAbortRequest()
{
@@ -1646,10 +2220,11 @@ namespace n5coredll
this.resendReqMsg();
if (isReadyBack)
{
- closeSerialPort();
if (currResultJsonStr != null && !"".Equals(currResultJsonStr))
{
- ifBusy = false;
+ if (ifBusy)
+ closeSerialPort();
+ //ifBusy = false;
return currResultJsonStr;
}
}
@@ -1757,7 +2332,7 @@ namespace n5coredll
ifBusy = false;
return RequestResult.createRespErrJson("PRINT_RESP", ERR_STATUS_TIMEOUT);
}
-
+
public string sendScanRequest()
{
if (ifBusy)
@@ -2157,12 +2732,83 @@ namespace n5coredll
return RequestResult.createRespErrJson("SUMMARY_ENQUIRY", ERR_STATUS_TIMEOUT);
}
+ public string sendCheckHealth()
+ {
+ if (ifBusy)
+ return RequestResult.createRespErrJson("HEALTH_CHECK", ERR_STATUS_BUSY);
+ ifBusy = true;
+ sendTime = 0;
+ isSending = false;
+ mRecvTimes = 0;
+ isReadyBack = false;
+ currReqByteArr = null;
+ currResultJsonStr = null;
+ isGetACK = false;
+ if (openSerialPort())
+ {
+ currReqByteArr = this.packReqMsg(RequestResult.toJsonHealthCheck());
+ if (currReqByteArr == null || currReqByteArr.Length == 0)
+ {
+ closeSerialPort();
+ ifBusy = false;
+ return RequestResult.createRespErrJson("HEALTH_CHECK", ERR_STATUS_PARAM);
+ //return "Request failed: params error";
+ }
+
+ Console.WriteLine("currReqByteArr = " + currReqByteArr);
+ Console.WriteLine("currReqByteArr.Length = " + currReqByteArr.Length);
+ this.sendReqMsg();
+ }
+ else
+ {
+ ifBusy = false;
+ closeSerialPort();
+ return RequestResult.createRespErrJson("HEALTH_CHECK", ERR_STATUS_OPENCOM);
+ }
+
+ int sleepTime = timeOut / 1000;
+
+ DateTime startTime = DateTime.Now;
+
+ Boolean ifEnd = false;
+ while (!ifEnd)
+ {
+ DateTime nowTime = DateTime.Now;
+ TimeSpan sp = nowTime - startTime;
+ if (sp.TotalSeconds > sleepTime)
+ ifEnd = true;
+ else
+ {
+ if (!isSending && !isGetACK)
+ this.resendReqMsg();
+ if (isReadyBack)
+ {
+ closeSerialPort();
+ if (currResultJsonStr != null && !"".Equals(currResultJsonStr))
+ {
+ ifBusy = false;
+ return currResultJsonStr;
+ }
+ }
+ }
+ }
+
+ Console.WriteLine("Timeout return : " + DateTime.Now.ToString());
+ ifBusy = false;
+ return RequestResult.createRespErrJson("HEALTH_CHECK", ERR_STATUS_TIMEOUT);
+ }
+
private void closeSerialPort()
{
if (serialPort1 != null && serialPort1.IsOpen)
{
Console.WriteLine("SerialPort Close ");
- serialPort1.Close();
+ try
+ {
+ serialPort1.Close();
+ }catch(Exception ex){
+ Console.WriteLine("Exception = " + ex);
+ }
}
}
@@ -2193,7 +2839,7 @@ namespace n5coredll
serialPort1.Parity = (Parity)Enum.Parse(typeof(Parity), parity);
serialPort1.ReceivedBytesThreshold = 1;
serialPort1.DataReceived += new SerialDataReceivedEventHandler(m_DataReceived);
-
+
if (!serialPort1.IsOpen)
{
serialPort1.Open();
@@ -2244,7 +2890,7 @@ namespace n5coredll
mTotalRecvCount += recvCount;
Console.WriteLine("mTotalRecvCount = " + mTotalRecvCount);
- if (recvResult[0] == 0x06 && mRecvTimes ==1)
+ if (recvResult[0] == 0x06 && mRecvTimes == 1)
{
isGetACK = true;
Console.WriteLine("ACK!");
@@ -2371,7 +3017,7 @@ namespace n5coredll
}
catch { }
}
-
+
private void reset()
{
mTotalRecvResult = new byte[4096];
@@ -2395,6 +3041,7 @@ namespace n5coredll
private void resendReqMsg()
{
+ Console.WriteLine("Execute resendReqMsg!");
if (!isSending || sendTime > 3)
{
this.isReadyBack = true;
@@ -2426,7 +3073,9 @@ namespace n5coredll
isSending = true;
serialPort1.Write(currReqByteArr, 0, currReqByteArr.Length);
}
- catch { };
+ catch(Exception ex) {
+ Console.WriteLine("error:" + ex.Message);
+ };
Console.WriteLine("serialPort1 Write end ");
}
@@ -2473,6 +3122,52 @@ namespace n5coredll
return finalMsg;
}
+ private Byte[] packReqMsg_test(string reqJson)
+ {
+ Console.WriteLine("packReqMsg -> " + reqJson);
+ byte[] bytesJsonReq = System.Text.Encoding.Default.GetBytes(reqJson);
+
+ //Step 1: Add STX 0x02 in 1st byte and msgLength with BCD format in 2-3 byte
+ int msgLength = bytesJsonReq.Length;
+ string msgLengthStrWithZeorLeft = msgLength.ToString().PadLeft(4, '0');
+ Byte[] msgLengthBCD = ObjectUtil.ConvertFrom(msgLengthStrWithZeorLeft);
+ byte[] bytesAddSTXAddMsgLenReq = new byte[bytesJsonReq.Length + 1 + 2];
+ bytesAddSTXAddMsgLenReq[0] = 0x02;
+ bytesAddSTXAddMsgLenReq[1] = msgLengthBCD[0];
+ bytesAddSTXAddMsgLenReq[2] = msgLengthBCD[1];
+ System.Array.Copy(bytesJsonReq, 0, bytesAddSTXAddMsgLenReq, 3, bytesJsonReq.Length);
+
+ //Step 2: calculate LRC
+ byte[] bytesAddETXAddMsgLenReq = new byte[bytesJsonReq.Length + 1 + 2];
+
+ bytesAddETXAddMsgLenReq[0] = msgLengthBCD[0];
+ bytesAddETXAddMsgLenReq[1] = msgLengthBCD[1];
+ System.Array.Copy(bytesJsonReq, 0, bytesAddETXAddMsgLenReq, 2, bytesJsonReq.Length);
+ bytesAddETXAddMsgLenReq[bytesAddETXAddMsgLenReq.Length - 1] = 0x03;
+ Byte result_lrc = ObjectUtil.lrc(bytesAddETXAddMsgLenReq);
+
+ //Step 3: pack
+ byte[] finalMsg = new byte[bytesJsonReq.Length + 7];
+ System.Array.Copy(bytesAddSTXAddMsgLenReq, 0, finalMsg, 1, bytesAddSTXAddMsgLenReq.Length);
+ finalMsg[0] = 0x06;
+ finalMsg[finalMsg.Length - 3] = 0x03;
+ finalMsg[finalMsg.Length - 2] = result_lrc;
+
+ finalMsg[finalMsg.Length - 1] = 0x06;
+
+ StringBuilder reqMsgSb = new StringBuilder();
+ for (int i = 0; i < finalMsg.Length; i++)
+ {
+ if (finalMsg[i].ToString().Length == 1)
+ {
+ reqMsgSb.Append("0");
+ }
+ reqMsgSb.Append(finalMsg[i].ToString());
+ }
+ Console.WriteLine("finalMsg = " + reqMsgSb.ToString());
+ return finalMsg;
+ }
+
private int readFromSerialPort(byte[] msg)
{
Console.WriteLine("Execute readFromSerialPort!");
diff --git a/n5coredll/RefundResult.cs b/n5coredll/RefundResult.cs
index d03f67d..8df6a3b 100644
--- a/n5coredll/RefundResult.cs
+++ b/n5coredll/RefundResult.cs
@@ -237,6 +237,12 @@ namespace n5coredll
return cardRefundMsg;
}
+ public static string toJsonForRefund(string txnIId, decimal txnAmt, PaymentApp appId, string qrcValue, string txnDate, string hostRefNo)
+ {
+ string cardRefundMsg = "{\"EVENT_NAME\":\"REFUND\",\"PAYMENT_APP_ID\":\"" + ObjectUtil.getPaymentAppValue(appId) + "\",\"TXN_ID\":\"" + txnIId + "\",\"QRC_VALUE\":\"" + qrcValue + "\",\"TXN_AMT\":" + txnAmt.ToString() + ",\"TXN_DATE\":\"" + txnDate + "\",\"HOST_REF\":\"" + hostRefNo + "\"}";
+ return cardRefundMsg;
+ }
+
private static string getTxnId() {
StringBuilder txnIdSb = new StringBuilder();
DateTime dt = DateTime.Now;
diff --git a/n5coredll/RequestResult.cs b/n5coredll/RequestResult.cs
index f874082..b7fadbf 100644
--- a/n5coredll/RequestResult.cs
+++ b/n5coredll/RequestResult.cs
@@ -30,6 +30,18 @@ namespace n5coredll
return "{\"EVENT_NAME\":\"SETTLE\"}";
}
+ public static string toJsonGetInfo()
+ {
+ // return "{\"EVENT_NAME\":\"GET_INFO\"}";
+ return "{\"EVENT_NAME\":\"GETDEVICEINFO\",\"PAYMENT_APP_ID\":\"CC\"}";
+ }
+
+ public static string toCheckUpdate()
+ {
+ // return "{\"EVENT_NAME\":\"GET_INFO\"}";
+ return "{\"EVENT_NAME\":\"CHECKUPDATE\"}";
+ }
+
public static string toJsonParam()
{
return "{\"EVENT_NAME\":\"PARAM\",\"PAYMENT_APP_ID\":\"CC\"}";
@@ -61,6 +73,13 @@ namespace n5coredll
return cardSaleMsg;
}
+ public static string toJsonForCreateOrder(string inputTxnId, decimal txnAmt, string paymentType)
+ {
+ string cardSaleMsg = "{\"EVENT_NAME\":\"CREATE_ORDER\",\"TXN_ID\":\"" + inputTxnId + "\",\"TXN_AMT\":" + txnAmt + ",\"PAYMENT_TYPE\":\"" +paymentType + "\",\"PAYMENT_APP_ID\":\"QRC\"}";
+ return cardSaleMsg;
+ }
+
+
public static string toJsonForBatchEnquiry(string settleDate)
{
return "{\"EVENT_NAME\":\"BATCH_ENQUIRY\",\"SETTLE_DATE\":\"" + settleDate + "\"}";
@@ -75,6 +94,12 @@ namespace n5coredll
{
return "{\"EVENT_NAME\":\"SUMMARY_ENQUIRY\",\"TXN_DATE_START_TO_END\":\"" + period + "\"}";
}
+
+ public static string toJsonHealthCheck()
+ {
+ return "{\"EVENT_NAME\":\"HEALTH_CHECK\"}";
+ }
+
public static RequestResult toReqResultFromJsonMsg(string jsonMsg) {
if (jsonMsg == null || !jsonMsg.StartsWith("{") || !jsonMsg.EndsWith("}")) {
return null;
diff --git a/n5coredll/dll/IbmsSerialPort.dll b/n5coredll/dll/IbmsSerialPort.dll
new file mode 100644
index 0000000..2817e8a
Binary files /dev/null and b/n5coredll/dll/IbmsSerialPort.dll differ
diff --git a/n5coredll/dll/IbmsSerialPort.lib b/n5coredll/dll/IbmsSerialPort.lib
new file mode 100644
index 0000000..721ca5f
Binary files /dev/null and b/n5coredll/dll/IbmsSerialPort.lib differ
diff --git a/n5coredll/n5coredll.csproj b/n5coredll/n5coredll.csproj
index 4fd4891..269e558 100644
--- a/n5coredll/n5coredll.csproj
+++ b/n5coredll/n5coredll.csproj
@@ -9,7 +9,7 @@
Properties
n5coredll
n5coredll
- v4.0
+ v3.5
512
@@ -23,6 +23,7 @@
4
AnyCPU
true
+ true
pdbonly
@@ -49,7 +50,6 @@
-
@@ -62,6 +62,7 @@
True
Settings.settings
+