You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

122 lines
4.1 KiB

using System;
using System.Text;
namespace n5coredll
{
public class RequestResult {
private static string STATUS = "STATUS";
private string status;
public string Status {
get { return status; }
}
private void setStatus(string pStatus) {
this.status = pStatus;
}
public RequestResult() {
}
public RequestResult(string pStatus) {
this.setStatus(pStatus);
}
public static string toJsonForLinkTest() {
return "{\"EVENT_NAME\":\"ECHO\"}";
}
public static string toJsonForSettlement()
{
return "{\"EVENT_NAME\":\"SETTLE\",\"PAYMENT_APP_ID\":\"EPS\"}";
}
public static string toJsonForReprint()
{
return "{\"EVENT_NAME\":\"PRINT\",\"IS_REPRINT\":true}";
}
public static string toJsonForReprint(string txnId, string traceNo, bool isReprint)
{
string reprintStr = "";
if (isReprint)
reprintStr = "true";
else
reprintStr = "false";
string result = "";
if (txnId!="" && traceNo!="")
result = "{\"EVENT_NAME\":\"PRINT\",\"PAYMENT_APP_ID\":\"EPS\",\"TXN_ID\":\"" + txnId + "\",\"TRACE_NO\":\"" + traceNo + "\",\"IS_REPRINT\":" + reprintStr + "}";
else if(txnId!="" && traceNo == "")
result = "{\"EVENT_NAME\":\"PRINT\",\"PAYMENT_APP_ID\":\"EPS\",\"TXN_ID\":\"" + txnId + "\",\"IS_REPRINT\":" + reprintStr + "}";
else if (traceNo != "" && txnId == "")
result = "{\"EVENT_NAME\":\"PRINT\",\"PAYMENT_APP_ID\":\"EPS\",\"TRACE_NO\":\"" + traceNo + "\",\"IS_REPRINT\":" + reprintStr + "}";
return result;
}
public static string toJsonForAbort()
{
return "{\"EVENT_NAME\":\"ABORT\"}";
}
public static string toJsonForScan()
{
return "{\"EVENT_NAME\":\"SCAN\"}";
}
public static string toJsonForReadCardNFC()
{
return "{\"EVENT_NAME\":\"READ_CARD\"}";
}
public static string toJsonForAddPoint(string inputTxnId, decimal txnAmt)
{
string cardSaleMsg = "{\"EVENT_NAME\":\"ADD_POINT\",\"TXN_ID\":\"" + inputTxnId + "\",\"TXN_AMT\":" + txnAmt + "}";
return cardSaleMsg;
}
public static string toJsonForBatchEnquiry(string settleDate)
{
return "{\"EVENT_NAME\":\"BATCH_ENQUIRY\",\"SETTLE_DATE\":\"" + settleDate + "\"}";
}
public static string toJsonForSettleEnquiry(string batchId)
{
return "{\"EVENT_NAME\":\"SETTLE_ENQUIRY\",\"BATCH_ID\":\"" + batchId + "\"}";
}
public static string toJsonForSummaryEnquiry(string period)
{
return "{\"EVENT_NAME\":\"SUMMARY_ENQUIRY\",\"TXN_DATE_START_TO_END\":\"" + period + "\"}";
}
public static RequestResult toReqResultFromJsonMsg(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;
RequestResult reqResult = new RequestResult();
for (int i = 0; i < column.Length; i++) {
valueColumn = column[i].Split(':');
valueColumn0 = valueColumn[0].Replace('"', ' ').Trim();
valueColumn1 = valueColumn[1].Replace('"', ' ').Trim();
if (RequestResult.STATUS.Equals(valueColumn0)) {
reqResult.setStatus(valueColumn1);
}
}
return reqResult;
}
public static String createRespErrJson(String eventName, String status)
{
return "{\"EVENT_NAME\":\"" +eventName + "\",\"STATUS\":\"" + status + "\"}";
}
}
}