Commit e79ee794 authored by steurwadkar's avatar steurwadkar

F17ABAS001 source code commit


git-svn-id: http://15.206.35.175/svn/proteus/business-java/trunk@106517 ce508802-f39f-4f6c-b175-0d175dae99d5
parent c967d288
......@@ -103,6 +103,7 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi
private String GSTR1_URL_V3 = "";
private String GSTR2_URL_V3 = "";
private String GSTR2A_URL_V3 = "";
private String GSTR3_URL_V3 = "";
private String GSTR3B_URL_V3 = "";
private final String APPLICATION_JSON = "application/json";
private String appKey = "";
......@@ -111,6 +112,9 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi
private String appKeyEncryptedAndCoded = "";
private String clientId = "";
private String clientSecret = "";
String userName = "", gstin = "", periodCode = "", stateCode = "", authToken = "";
byte[] authSEK = null;
AESEncryption aesEncryption = null;
PubKeyEncryption pubKeyEncryption = null;
Connection conn = null;
......@@ -200,6 +204,11 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi
GSTR2A_URL_V3 = rs.getString("SERVICE_URI");
}
break;
case "gstr3_url_v3" :
{
GSTR3_URL_V3 = rs.getString("SERVICE_URI");
}
break;
case "gstr3b_url_v3" :
{
GSTR3B_URL_V3 = rs.getString("SERVICE_URI");
......@@ -225,6 +234,7 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi
System.out.println("GSTR1_URL_V3["+GSTR1_URL_V3+"]");
System.out.println("GSTR2_URL_V3["+GSTR2_URL_V3+"]");
System.out.println("GSTR2A_URL_V3["+GSTR2A_URL_V3+"]");
System.out.println("GSTR3_URL_V3["+GSTR3_URL_V3+"]");
System.out.println("GSTR3B_URL_V3["+GSTR3B_URL_V3+"]");
}
catch (Exception e)
......@@ -255,18 +265,16 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi
{
Document allXMLDom = null;
NodeList detail1NList = null, detail1ChildNList = null, detail2NList = null, detail2ChildNList = null;
String retString = "", nodeName = "", otp = "", stateCode = "", sek = "", returnsType = "", gstin = "", periodCode = "", grossTurnover = "",
String retString = "", nodeName = "", otp = "", sek = "", returnsType = "", grossTurnover = "",
action = "", siteCode = "", gspAuthString = "", gspAuthSignature = "", currentYearTurnover = "", signedData = "", panNo = "", aadhaarNo = "",
signMethod = "", summaryData = "";
String loginCode = "", chgTerm = "", callStatus = "", responseId = "", responseJsonStr= "";
byte[] authSEK = null;
APICallData apiCallData = null;
boolean isDataLogged = false;
try
{
String userName = "", authToken = "";
String transactionId = UUID.randomUUID().toString().replaceAll("-", "");
loginCode = e12GenericUtility.getValueFromXTRA_PARAMS(xtraParams, "loginCode");
......@@ -391,7 +399,7 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi
System.out.println("authToken and authSEK from detail2");
authSEK = aesEncryption.decrypt(sek, appKeyInBytes);
System.out.println("AuthSEK = "+ aesEncryption.encodeBase64String(authSEK));
System.out.println("authSEK = "+ aesEncryption.encodeBase64String(authSEK));
}
else
{
......@@ -448,7 +456,7 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi
sek = object.getString("sek");
authSEK = aesEncryption.decrypt(sek, appKeyInBytes);
System.out.println("AuthSEK = "+ aesEncryption.encodeBase64String(authSEK));
System.out.println("authSEK = "+ aesEncryption.encodeBase64String(authSEK));
callStatus = "1";
apiCallData.setCallStatus(callStatus);
......@@ -517,52 +525,52 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi
{
if("SAVE".equalsIgnoreCase(action))
{
retString = saveGstr1(authToken, siteCode, stateCode, userName, gstin, periodCode, grossTurnover, currentYearTurnover, authSEK, xtraParams, conn);
retString = createGstr1Json( siteCode, grossTurnover, currentYearTurnover, xtraParams, conn);
}
else if ("SUBMIT".equalsIgnoreCase(action))
{
retString = submitGstr1(authToken, stateCode, userName, gstin, periodCode, authSEK, xtraParams, conn);
retString = submitGstr1(xtraParams, conn);
}
else if ("FILE".equalsIgnoreCase(action))
{
retString = fileGstr1(authToken, stateCode, userName, gstin, periodCode, authSEK, summaryData, signedData, panNo, aadhaarNo, signMethod, xtraParams, conn);
retString = fileGstr1(summaryData, signedData, panNo, aadhaarNo, signMethod, xtraParams, conn);
}
}
else if("GSTR2A".equalsIgnoreCase(returnsType))
{
if("GETINV".equalsIgnoreCase(action))
{
retString = downloadGstr2AData(authToken, stateCode, userName, gstin, periodCode, siteCode, authSEK, xtraParams, conn);
retString = downloadGstr2AData(siteCode, xtraParams, conn);
}
}
else if("GSTR2".equalsIgnoreCase(returnsType))
{
if("SAVE".equalsIgnoreCase(action))
{
retString = saveGstr2(authToken, siteCode, stateCode, userName, gstin, periodCode, grossTurnover, currentYearTurnover, authSEK, xtraParams, conn);
retString = createGstr2Json(siteCode, xtraParams, conn);
}
else if ("SUBMIT".equalsIgnoreCase(action))
{
retString = submitGstr2(authToken, stateCode, userName, gstin, periodCode, authSEK, xtraParams, conn);
retString = submitGstr2(xtraParams, conn);
}
else if ("FILE".equalsIgnoreCase(action))
{
retString = fileGstr2(authToken, stateCode, userName, gstin, periodCode, authSEK, summaryData, signedData, panNo, aadhaarNo, signMethod, xtraParams, conn);
retString = fileGstr2(summaryData, signedData, panNo, aadhaarNo, signMethod, xtraParams, conn);
}
}
else if("GSTR3B".equalsIgnoreCase(returnsType))
{
if("SAVE".equalsIgnoreCase(action))
{
retString = saveGstr3b(authToken, siteCode, stateCode, userName, gstin, periodCode, grossTurnover, currentYearTurnover, authSEK, xtraParams, conn);
retString = createGstr3bJson(siteCode, xtraParams, conn);
}
else if("SUBMIT".equalsIgnoreCase(action))
{
retString = submitGstr3b(authToken, stateCode, userName, gstin, periodCode, authSEK, xtraParams, conn);
retString = submitGstr3b(xtraParams, conn);
}
else if("FILE".equalsIgnoreCase(action))
{
retString = fileGstr3b(authToken, stateCode, userName, gstin, periodCode, authSEK, summaryData, signedData, panNo, aadhaarNo, signMethod, xtraParams, conn);
retString = fileGstr3b(summaryData, signedData, panNo, aadhaarNo, signMethod, xtraParams, conn);
}
}
}
......@@ -584,7 +592,7 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi
return retString;
}
private String saveGstr1(String authToken, String siteCode, String stateCode, String userName, String gstin, String periodCode, String grossTurnover, String currentYearTurnover, byte[] authSek, String xtraParams, Connection conn) throws ITMException
private String createGstr1Json(String siteCode, String grossTurnover, String currentYearTurnover, String xtraParams, Connection conn) throws ITMException
{
String retString = "", errMsg = "";
String gstr1Data = "", gstr1Rek = "";
......@@ -930,20 +938,6 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi
cdnrList.add(cdnr);
}
}
//tran_type : 15,16,17,18,19,20,21,22,23,24,25,26 = Nil Supplies
/*if("NIL".equalsIgnoreCase(udfStr1))
{
invoice.supplyType = "INTRB2B";
invoice.totalNilAmount = rs.getDouble("AMOUNT");
invoice.totalExemptedAmount = 123.45;
invoice.totalNonGSTAmout = 1258.5;
invoices.add(invoice);
nil = new Nil();
nil.invoices = invoices;
}*/
//tran_type : 06,07 = Exports and tran_type : 27,28 = Exports amendments
if("EXP".equalsIgnoreCase(udfStr1) || "EXPA".equalsIgnoreCase(udfStr1))
{
......@@ -1380,7 +1374,7 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi
gstr1.docIssued = docIssuedList;
}
String gspAuthString = "", gspAuthSignature = "", gspAuthStringRet = "", gspAuthSignatureRet = "";
/*String gspAuthString = "", gspAuthSignature = "", gspAuthStringRet = "", gspAuthSignatureRet = "";
APICallData apiRetStatsCallData = null;
List<APICallData> retStatAPICallList = new ArrayList<APICallData>();
int retStatusCallCnt = 0;
......@@ -1388,7 +1382,7 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi
loginCode = e12GenericUtility.getValueFromXTRA_PARAMS(xtraParams, "loginCode");
chgTerm = e12GenericUtility.getValueFromXTRA_PARAMS(xtraParams, "chgTerm");
*/
ObjectMapper objectMapper = new ObjectMapper();
String json = objectMapper.writeValueAsString(gstr1);
......@@ -1405,13 +1399,15 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi
System.out.println("DIFFERANCE IN TIME FOR PAYLOAD CREATION GSTR1 IN HH:MM:SS ["+payloadDiffHours +":"+payloadDiffMinutes+":"+payloadDiffSeconds+"]");
byte[] jsonBase64 = Base64.getEncoder().encode(json.getBytes());
String encryptedPayload = aesEncryption.encryptEK(jsonBase64, authSek);
retString = saveGSTRData(json, noOfRecords, tranIdList, "1", conn, xtraParams);
/*byte[] jsonBase64 = Base64.getEncoder().encode(json.getBytes());
String encryptedPayload = aesEncryption.encryptEK(jsonBase64, authSEK);
HMac hmac = new HMac(new SHA256Digest());
byte[] resBuf = new byte[hmac.getMacSize()];
hmac.init(new KeyParameter(authSek));
hmac.init(new KeyParameter(authSEK));
hmac.update(jsonBase64, 0, jsonBase64.length);
hmac.doFinal(resBuf, 0);
......@@ -1461,7 +1457,7 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi
gstr1Data = gstr1RespObj.getString("data");
gstr1Rek = gstr1RespObj.getString("rek");
byte[] apiEKGstr1 = aesEncryption.decrypt(gstr1Rek, authSek);
byte[] apiEKGstr1 = aesEncryption.decrypt(gstr1Rek, authSEK);
String gstr1RespJsoninBase64 = new String(aesEncryption.decrypt(gstr1Data, apiEKGstr1));
byte[] gstr1RespJsonInBytes = aesEncryption.decodeBase64StringTOByte(gstr1RespJsoninBase64);
......@@ -1528,7 +1524,7 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi
retStatsData = retStatsRespObj.getString("data");
retStatsRek = retStatsRespObj.getString("rek");
byte[] apiEKRetstats = aesEncryption.decrypt(retStatsRek, authSek);
byte[] apiEKRetstats = aesEncryption.decrypt(retStatsRek, authSEK);
String retStatsRespJsoninBase64 = new String(aesEncryption.decrypt(retStatsData, apiEKRetstats));
......@@ -1707,7 +1703,7 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi
{
gstCommonUtil.updateAPICallLogHistory(eachAPICallData, null);
}
}
}*/
}
}
catch (Exception e)
......@@ -1718,7 +1714,7 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi
}
return retString;
}
private String submitGstr1(String authToken, String stateCode, String userName, String gstin, String periodCode, byte[] authSEK, String xtraParams,Connection conn) throws ITMException
private String submitGstr1(String xtraParams,Connection conn) throws ITMException
{
String retString = "";
String errMsg = "", gspAuthString = "", gspAuthSignature = "";
......@@ -1801,7 +1797,7 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi
responseId = transId;
System.out.println("transId to getStatus after SUBMIT call["+transId+"]");
sql = "UPDATE GST_DATA_HDR SET SUBMIT_STATUS = ? AND SUBMIT_DATE = ? WHERE PRD_CODE = ? AND SITE_CODE = ? AND REC_TYPE = '1'";
sql = "UPDATE GST_DATA_HDR SET SUBMIT_STATUS = ?, SUBMIT_DATE = ? WHERE PRD_CODE = ? AND SITE_CODE = ? AND REC_TYPE = '1'";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, "S");
......@@ -1870,7 +1866,7 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi
}
return retString;
}
private String fileGstr1(String authToken, String stateCode, String userName, String gstin, String periodCode, byte[] authSek, String summaryData, String signedData, String panNo, String aadhaarNo, String signMethod, String xtraParams, Connection conn) throws ITMException
private String fileGstr1(String summaryData, String signedData, String panNo, String aadhaarNo, String signMethod, String xtraParams, Connection conn) throws ITMException
{
String retString = "";
String errMsg = "", gspAuthString = "", gspAuthSignature = "", signType = "",signId = "";
......@@ -1888,12 +1884,12 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi
gspAuthSignature = gspSignature.sign(gspAuthString, aspPrivateKey);
byte[] jsonBase64 = Base64.getEncoder().encode(summaryData.toString().getBytes());
String encryptedPayload = aesEncryption.encryptEK(jsonBase64, authSek);
String encryptedPayload = aesEncryption.encryptEK(jsonBase64, authSEK);
HMac hmac = new HMac(new SHA256Digest());
byte[] resBuf = new byte[hmac.getMacSize()];
hmac.init(new KeyParameter(authSek));
hmac.init(new KeyParameter(authSEK));
hmac.update(jsonBase64, 0, jsonBase64.length);
hmac.doFinal(resBuf, 0);
......@@ -1949,7 +1945,7 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi
String fileGstr1Data = fileGstr1RespObj.getString("data");
String fileGstr1Rek = fileGstr1RespObj.getString("rek");
byte[] fileGstr1ApiEK = aesEncryption.decrypt(fileGstr1Rek, authSek);
byte[] fileGstr1ApiEK = aesEncryption.decrypt(fileGstr1Rek, authSEK);
String fileGstr1JsoninBase64 = new String(aesEncryption.decrypt(fileGstr1Data, fileGstr1ApiEK));
......@@ -2004,7 +2000,7 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi
return retString;
}
/*private String getGstr1Summary(String authToken, String stateCode, String userName, String gstin, String periodCode, byte[] authSek, String action, String xtraParams, Connection conn) throws ITMException
/*private String getGstr1Summary(String authToken, String stateCode, String userName, String gstin, String periodCode, byte[] authSEK, String action, String xtraParams, Connection conn) throws ITMException
{
String retString = "";
String errMsg = "", gspAuthString = "", gspAuthSignature = "";
......@@ -2053,7 +2049,7 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi
String gstr1Sumrydata = getGstr1SumryRespObj.getString("data");
String gstr1Sumryrek = getGstr1SumryRespObj.getString("rek");
byte[] apiEK = aesEncryption.decrypt(gstr1Sumryrek, authSek);
byte[] apiEK = aesEncryption.decrypt(gstr1Sumryrek, authSEK);
String respJsoninBase64 = new String(aesEncryption.decrypt(gstr1Sumrydata, apiEK));
......@@ -2068,12 +2064,12 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi
String gspAuthStringFile = "", gspAuthSignatureFile = "";
byte[] jsonBase64 = Base64.getEncoder().encode(gstr1SumryJsonObj.toString().getBytes());
String encryptedPayload = aesEncryption.encryptEK(jsonBase64, authSek);
String encryptedPayload = aesEncryption.encryptEK(jsonBase64, authSEK);
HMac hmac = new HMac(new SHA256Digest());
byte[] resBuf = new byte[hmac.getMacSize()];
hmac.init(new KeyParameter(authSek));
hmac.init(new KeyParameter(authSEK));
hmac.update(jsonBase64, 0, jsonBase64.length);
hmac.doFinal(resBuf, 0);
......@@ -2118,7 +2114,7 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi
String fileGstr1Data = fileGstr1RespObj.getString("data");
String fileGstr1Rek = fileGstr1RespObj.getString("rek");
byte[] fileGstr1ApiEK = aesEncryption.decrypt(fileGstr1Rek, authSek);
byte[] fileGstr1ApiEK = aesEncryption.decrypt(fileGstr1Rek, authSEK);
String fileGstr1JsoninBase64 = new String(aesEncryption.decrypt(fileGstr1Data, fileGstr1ApiEK));
......@@ -2207,7 +2203,7 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi
}
return retString;
}*/
private String downloadGstr2AData(String authToken, String stateCode, String userName, String gstin, String periodCode, String siteCode, byte[] authSEK, String xtraParams, Connection conn) throws ITMException
private String downloadGstr2AData(String siteCode, String xtraParams, Connection conn) throws ITMException
{
String retString = "";
String errMsg = "", gspAuthString = "", gspAuthSignature = "";
......@@ -2331,7 +2327,7 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi
}
return retString;
}
private String saveGstr2(String authToken, String siteCode, String stateCode, String userName, String gstin, String periodCode, String grossTurnover, String currentYearTurnover, byte[] authSek, String xtraParams, Connection conn) throws ITMException
private String createGstr2Json(String siteCode, String xtraParams, Connection conn) throws ITMException
{
String retString = "", errMsg = "";
String gstr2Data = "", gstr2Rek = "";
......@@ -3029,12 +3025,12 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi
gstr2.cdnur = cdnurList;
}
String gspAuthString = "", gspAuthSignature = "", gspAuthStringRet = "", gspAuthSignatureRet = "";
/*String gspAuthString = "", gspAuthSignature = "", gspAuthStringRet = "", gspAuthSignatureRet = "";
APICallData apiRetStatsCallData = null;
List<APICallData> retStatAPICallList = new ArrayList<APICallData>();
loginCode = e12GenericUtility.getValueFromXTRA_PARAMS(xtraParams, "loginCode");
chgTerm = e12GenericUtility.getValueFromXTRA_PARAMS(xtraParams, "chgTerm");
chgTerm = e12GenericUtility.getValueFromXTRA_PARAMS(xtraParams, "chgTerm");*/
ObjectMapper objectMapper = new ObjectMapper();
......@@ -3042,13 +3038,15 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi
System.out.println("jsonPayload to SAVE GSTR2["+json+"]");
byte[] jsonBase64 = Base64.getEncoder().encode(json.getBytes());
String encryptedPayload = aesEncryption.encryptEK(jsonBase64, authSek);
retString = saveGSTRData(json, noOfRecords, tranIdList, "2", conn, xtraParams);
/*byte[] jsonBase64 = Base64.getEncoder().encode(json.getBytes());
String encryptedPayload = aesEncryption.encryptEK(jsonBase64, authSEK);
HMac hmac = new HMac(new SHA256Digest());
byte[] resBuf = new byte[hmac.getMacSize()];
hmac.init(new KeyParameter(authSek));
hmac.init(new KeyParameter(authSEK));
hmac.update(jsonBase64, 0, jsonBase64.length);
hmac.doFinal(resBuf, 0);
......@@ -3098,7 +3096,7 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi
gstr2Data = gstr2RespObj.getString("data");
gstr2Rek = gstr2RespObj.getString("rek");
byte[] apiEKGstr2 = aesEncryption.decrypt(gstr2Rek, authSek);
byte[] apiEKGstr2 = aesEncryption.decrypt(gstr2Rek, authSEK);
String gstr2RespJsoninBase64 = new String(aesEncryption.decrypt(gstr2Data, apiEKGstr2));
byte[] gstr2RespJsonInBytes = aesEncryption.decodeBase64StringTOByte(gstr2RespJsoninBase64);
......@@ -3153,7 +3151,7 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi
retStatsData = retStatsRespObj.getString("data");
retStatsRek = retStatsRespObj.getString("rek");
byte[] apiEKRetstats = aesEncryption.decrypt(retStatsRek, authSek);
byte[] apiEKRetstats = aesEncryption.decrypt(retStatsRek, authSEK);
String retStatsRespJsoninBase64 = new String(aesEncryption.decrypt(retStatsData, apiEKRetstats));
......@@ -3324,7 +3322,7 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi
{
gstCommonUtil.updateAPICallLogHistory(eachAPICallData, null);
}
}
}*/
}
}
catch(Exception e)
......@@ -3335,7 +3333,7 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi
}
return retString;
}
private String submitGstr2(String authToken, String stateCode, String userName, String gstin, String periodCode, byte[] authSEK, String xtraParams,Connection conn) throws ITMException
private String submitGstr2(String xtraParams,Connection conn) throws ITMException
{
String retString = "";
String errMsg = "", gspAuthString = "", gspAuthSignature = "";
......@@ -3488,7 +3486,7 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi
}
return retString;
}
private String fileGstr2(String authToken, String stateCode, String userName, String gstin, String periodCode, byte[] authSek, String summaryData, String signedData, String panNo, String aadhaarNo, String signMethod, String xtraParams, Connection conn) throws ITMException
private String fileGstr2(String summaryData, String signedData, String panNo, String aadhaarNo, String signMethod, String xtraParams, Connection conn) throws ITMException
{
String retString = "";
String errMsg = "", gspAuthString = "", gspAuthSignature = "", signType = "",signId = "";
......@@ -3506,12 +3504,12 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi
gspAuthSignature = gspSignature.sign(gspAuthString, aspPrivateKey);
byte[] jsonBase64 = Base64.getEncoder().encode(summaryData.toString().getBytes());
String encryptedPayload = aesEncryption.encryptEK(jsonBase64, authSek);
String encryptedPayload = aesEncryption.encryptEK(jsonBase64, authSEK);
HMac hmac = new HMac(new SHA256Digest());
byte[] resBuf = new byte[hmac.getMacSize()];
hmac.init(new KeyParameter(authSek));
hmac.init(new KeyParameter(authSEK));
hmac.update(jsonBase64, 0, jsonBase64.length);
hmac.doFinal(resBuf, 0);
......@@ -3567,7 +3565,7 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi
String fileGstr2Data = fileGstr2RespObj.getString("data");
String fileGstr2Rek = fileGstr2RespObj.getString("rek");
byte[] fileGstr2ApiEK = aesEncryption.decrypt(fileGstr2Rek, authSek);
byte[] fileGstr2ApiEK = aesEncryption.decrypt(fileGstr2Rek, authSEK);
String fileGstr2JsoninBase64 = new String(aesEncryption.decrypt(fileGstr2Data, fileGstr2ApiEK));
......@@ -3620,7 +3618,7 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi
return retString;
}
private String saveGstr3b(String authToken, String siteCode, String stateCode, String userName, String gstin, String periodCode, String grossTurnover, String currentYearTurnover, byte[] authSek, String xtraParams, Connection conn) throws ITMException
private String createGstr3bJson(String siteCode, String xtraParams, Connection conn) throws ITMException
{
String retString = "";
GSTR3B gstr3b = null;
......@@ -3630,12 +3628,8 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi
List<ITCData> itcInelgDataList = new ArrayList<ITCData>();
List<InwardSuppliesDetails> inwardSuppliesList = new ArrayList<InwardSuppliesDetails>();
String transactionId = UUID.randomUUID().toString().replaceAll("-", "");
String gspAuthString = "", gspAuthSignature = "", callStatus = "", gstr3bData = "", gstr3bRek = "", responseId = "", gspAuthStringRet = "",
gspAuthSignatureRet = "", retStatsData = "", retStatsRek = "", retStatusCallStatus = "", retStatusResponseJsonStr = "", errMsg = "",
responseJsonStr = "", loginCode = "", chgTerm = "";
APICallData apiRetStatsCallData = null;
ArrayList<APICallData> retStatAPICallList = new ArrayList<APICallData>();
int noOfRecords = 0;
ArrayList<String> tranIdList = new ArrayList<String>();
try
{
......@@ -3787,602 +3781,333 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi
System.out.println("jsonPaylaod to save GSTR3B ["+json+"]");
retString = saveGSTRData(json, noOfRecords, tranIdList, "6", conn, xtraParams);
}
catch(Exception e)
{
System.out.println("GSTDataSubmitWizPos.saveGstr3b()["+e.getMessage()+"]");
e.printStackTrace();
throw new ITMException(e);
}
return retString;
}
private String submitGstr3b(String xtraParams,Connection conn) throws ITMException
{
String retString = "";
String errMsg = "", gspAuthString = "", gspAuthSignature = "";
String transactionId = UUID.randomUUID().toString().replaceAll("-", "");
String loginCode = "", chgTerm = "", siteCode = "", callStatus = "", responseJsonStr = "", responseId = "";
String sql = "";
PreparedStatement pstmt = null;
int updateCnt = 0;
try
{
siteCode = e12GenericUtility.getValueFromXTRA_PARAMS(xtraParams, "loginSiteCode");
loginCode = e12GenericUtility.getValueFromXTRA_PARAMS(xtraParams, "loginCode");
chgTerm = e12GenericUtility.getValueFromXTRA_PARAMS(xtraParams, "chgTerm");
byte[] jsonBase64 = Base64.getEncoder().encode(json.getBytes());
String encryptedPayload = aesEncryption.encryptEK(jsonBase64, authSek);
String json = "{\"gstin\":\""+gstin+"\",\"ret_period\":\""+periodCode+"\"}";
byte[] jsonBase64 = Base64.getEncoder().encode(json.getBytes());
String encryptedPayload = aesEncryption.encryptEK(jsonBase64, authSEK);
HMac hmac = new HMac(new SHA256Digest());
byte[] resBuf = new byte[hmac.getMacSize()];
hmac.init(new KeyParameter(authSek));
hmac.init(new KeyParameter(authSEK));
hmac.update(jsonBase64, 0, jsonBase64.length);
hmac.doFinal(resBuf, 0);
JSONObject reqBody = new JSONObject();
reqBody.put("action", "RETSUBMIT");
reqBody.put("data", encryptedPayload);
reqBody.put("hmac", new String(Base64.getEncoder().encode(resBuf)));
long timeStamp = new Timestamp().getDateTime();
gspAuthString = clientId + ":" + transactionId + ":" + timeStamp + ":" + gstin;
gspAuthSignature = gspSignature.sign(gspAuthString, aspPrivateKey);
JSONObject gstr3bHeaderObj = new JSONObject();
gstr3bHeaderObj.put("action", "RETSAVE");
gstr3bHeaderObj.put("data", encryptedPayload);
gstr3bHeaderObj.put("hmac", new String(Base64.getEncoder().encode(resBuf)));
HttpRequest gstr3bSubmitReq = Unirest.post(String.format("%s%s", GSP_API_URL, GSTR3B_URL_V3))
.header("Content-Type", APPLICATION_JSON)
.header("action", "RETSUBMIT")
.header("state-cd", stateCode)
.header("clientid", clientId)
.header("client-secret", clientSecret)
.header("ip-usr", ipAddress)
.header("username", userName)
.header("auth-token", authToken)
.header("txn", transactionId)
.header("ret_period", periodCode)
.header("gstin", gstin)
.header("X-Asp-Auth-Token", gspAuthString)
.header("X-Asp-Auth-Signature", gspAuthSignature)
.body(new JsonNode(reqBody.toString()))
.getHttpRequest();
System.out.println("RETSUBMIT GSTR3B url["+gstr3bSubmitReq.getUrl()+"]");
System.out.println("RETSUBMIT GSTR3B method["+gstr3bSubmitReq.getHttpMethod()+"]");
System.out.println("RETSUBMIT GSTR3B request header["+gstr3bSubmitReq.getHeaders()+"]");
System.out.println("RETSUBMIT GSTR3B request payload["+IOUtils.toString(gstr3bSubmitReq.getBody().getEntity().getContent())+"]");
HttpResponse<JsonNode> gstr3bSubmitResp = gstr3bSubmitReq.asJson();
System.out.println(String.format("gstr3bSubmitResp Request : Status[%s] Response[%s]", gstr3bSubmitResp.getStatus(), gstr3bSubmitResp.getBody()));
if (gstr3bSubmitResp.getStatus() == 200)
{
JSONObject gstr3bSubmitRespObj = gstr3bSubmitResp.getBody().getObject();
if(gstr3bSubmitRespObj.has("data") && gstr3bSubmitRespObj.has("rek"))
{
callStatus = "1";
String gstr3bSubmitdata = gstr3bSubmitRespObj.getString("data");
String gstr3bSubmitrek = gstr3bSubmitRespObj.getString("rek");
byte[] apiEK = aesEncryption.decrypt(gstr3bSubmitrek, authSEK);
String respJsoninBase64 = new String(aesEncryption.decrypt(gstr3bSubmitdata, apiEK));
byte[] respJsonInBytes = aesEncryption.decodeBase64StringTOByte(respJsoninBase64);
JSONObject gstr3bSubmitObj = new JSONObject(new String(respJsonInBytes));
String transId = gstr3bSubmitObj.getString("reference_id");
responseId = transId;
System.out.println("transId to getStatus after SUBMIT call["+transId+"]");
//TODO need to check
/*sql = "UPDATE GST_DATA_HDR SET SUBMIT_STATUS = ? AND SUBMIT_DATE = ? WHERE PRD_CODE = ? AND SITE_CODE = ? AND REC_TYPE = '1'";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, "S");
pstmt.setTimestamp(2, java.sql.Timestamp.valueOf(e12GenericUtility.getValidDateString(new Date(), e12GenericUtility.getDBDateTimeFormat())));
pstmt.setString(3, periodCode);
pstmt.setString(4, siteCode);
updateCnt = pstmt.executeUpdate();
if(pstmt!=null)
{
pstmt.close();
pstmt = null;
}
System.out.println("submit status updated of ["+siteCode+"] for ["+periodCode+"] update count ["+updateCnt+"]");*/
}
else
{
callStatus = "2";
JSONObject errorJSON = gstr3bSubmitResp.getBody().getObject().getJSONObject("error");
responseJsonStr = errorJSON.toString();
errMsg = "Message : "+errorJSON.getString("message")+" \nError code : "+errorJSON.getString("error_cd");
retString = getError(errMsg, "GSTAPIERR", conn);
}
}
else if(gstr3bSubmitResp.getStatus() == 500)
{
callStatus = "2";
errMsg = "Message : Error occurred at GSTN server \nResponse code : "+gstr3bSubmitResp.getStatus();
responseJsonStr = errMsg;
retString = getError(errMsg, "GSTAPIERR", conn);
}
else
{
callStatus = "2";
JSONObject errorJSON = gstr3bSubmitResp.getBody().getObject().getJSONObject("error");
responseJsonStr = errorJSON.toString();
errMsg = "Message : "+errorJSON.getString("message")+" \nError code : "+errorJSON.getString("error_cd");
retString = getError(errMsg, "GSTAPIERR", conn);
}
APICallData apiCallData = new APICallData();
apiCallData.setPeriodCode(periodCode);
apiCallData.setCallDate(new Date());
apiCallData.setSiteCode(siteCode);
apiCallData.setUserId(loginCode);
apiCallData.setCallType("RETSUBMIT");
apiCallData.setRecType("3");
apiCallData.setNoOfRecords(0);
apiCallData.setCallStatus(callStatus);
apiCallData.setResponseId(responseId);
apiCallData.setResponseJsonStr(responseJsonStr);
apiCallData.setChgUser(loginCode);
apiCallData.setChgDate(new Date());
apiCallData.setChgTerm(chgTerm);
gstCommonUtil.updateAPICallLogHistory(apiCallData, null);
}
catch(Exception e)
{
System.out.println("GSTDataSubmitWizPos.submitGstr3b()["+e.getMessage()+"]");
e.printStackTrace();
throw new ITMException(e);
}
return retString;
}
private String fileGstr3b(String summaryData, String signedData, String panNo, String aadhaarNo, String signMethod, String xtraParams, Connection conn) throws ITMException
{
String retString = "";
String errMsg = "", gspAuthString = "", gspAuthSignature = "", signType = "",signId = "";
String transactionId = UUID.randomUUID().toString().replaceAll("-", "");
String loginCode = "", chgTerm = "", siteCode = "", callStatus = "", responseJsonStr = "";
try
{
siteCode = e12GenericUtility.getValueFromXTRA_PARAMS(xtraParams, "loginSiteCode");
loginCode = e12GenericUtility.getValueFromXTRA_PARAMS(xtraParams, "loginCode");
chgTerm = e12GenericUtility.getValueFromXTRA_PARAMS(xtraParams, "chgTerm");
long timeStamp = new Timestamp().getDateTime();
gspAuthString = clientId + ":" + transactionId + ":" + timeStamp + ":" + gstin;
gspAuthSignature = gspSignature.sign(gspAuthString, aspPrivateKey);
HttpRequest saveGstr3bReq = Unirest.post(String.format("%s%s", GSP_API_URL, GSTR3B_URL_V3))
byte[] jsonBase64 = Base64.getEncoder().encode(summaryData.toString().getBytes());
String encryptedPayload = aesEncryption.encryptEK(jsonBase64, authSEK);
HMac hmac = new HMac(new SHA256Digest());
byte[] resBuf = new byte[hmac.getMacSize()];
hmac.init(new KeyParameter(authSEK));
hmac.update(jsonBase64, 0, jsonBase64.length);
hmac.doFinal(resBuf, 0);
if("D".equalsIgnoreCase(signMethod))
{
signType = "DSC";
signId = panNo;
}
else if("E".equalsIgnoreCase(signMethod))
{
signType = "ESIGN";
signId = aadhaarNo;
}
JSONObject fileGstr3bDataJsonObj = new JSONObject();
fileGstr3bDataJsonObj.put("action", "RETFILE");
fileGstr3bDataJsonObj.put("data", encryptedPayload);
fileGstr3bDataJsonObj.put("hmac", new String(Base64.getEncoder().encode(resBuf)));
fileGstr3bDataJsonObj.put("sign", signedData);
fileGstr3bDataJsonObj.put("st", signType);
fileGstr3bDataJsonObj.put("sid", signId);
HttpRequest fileGstr3bReq = Unirest.post(String.format("%s%s", GSP_API_URL, GSTR3B_URL_V3))
.header("Content-Type", APPLICATION_JSON)
.header("state-cd", stateCode)
.header("clientid", clientId)
.header("client-secret", clientSecret)
.header("txn",transactionId)
.header("state-cd", stateCode)
.header("auth-token", authToken)
.header("gstin", gstin)
.header("ip-usr", ipAddress)
.header("username", userName)
.header("auth-token", authToken)
.header("txn", transactionId)
.header("ret_period", periodCode)
.header("ip-usr", ipAddress)
.header("gstin", gstin)
.header("X-Asp-Auth-Token", gspAuthString)
.header("X-Asp-Auth-Signature", gspAuthSignature)
.body(new JsonNode(gstr3bHeaderObj.toString()))
.header("X-Asp-Auth-Signature", gspAuthSignature)
.body(new JsonNode(fileGstr3bDataJsonObj.toString()))
.getHttpRequest();
System.out.println("SAVE GSTR3B url["+saveGstr3bReq.getUrl()+"]");
System.out.println("SAVE GSTR3B method["+saveGstr3bReq.getHttpMethod()+"]");
System.out.println("SAVE GSTR3B request header["+saveGstr3bReq.getHeaders()+"]");
System.out.println("SAVE GSTR3B request payload["+IOUtils.toString(saveGstr3bReq.getBody().getEntity().getContent())+"]");
HttpResponse<JsonNode> gstr3bResp = saveGstr3bReq.asJson();
System.out.println(String.format("gstr3bResp Request : Status[%s] Response[%s]", gstr3bResp.getStatus(), gstr3bResp.getBody()));
System.out.println("FILE GSTR3B url["+fileGstr3bReq.getUrl()+"]");
System.out.println("FILE GSTR3B method["+fileGstr3bReq.getHttpMethod()+"]");
System.out.println("FILE GSTR3B request header["+fileGstr3bReq.getHeaders()+"]");
System.out.println("FILE GSTR3B request payload["+IOUtils.toString(fileGstr3bReq.getBody().getEntity().getContent())+"]");
if (gstr3bResp.getStatus() == 200)
{
JSONObject gstr3bRespObj = gstr3bResp.getBody().getObject();
if(gstr3bRespObj.has("data") && gstr3bRespObj.has("rek"))
HttpResponse<JsonNode> fileGstr3bResp = fileGstr3bReq.asJson();
System.out.println(String.format("fileGstr3bResp Request : Status[%s] Response[%s]", fileGstr3bResp.getStatus(), fileGstr3bResp.getBody()));
if (fileGstr3bResp.getStatus() == 200)
{
JSONObject fileGstr3bRespObj = fileGstr3bResp.getBody().getObject();
if(fileGstr3bRespObj.has("data") && fileGstr3bRespObj.has("rek"))
{
callStatus = "1";
gstr3bData = gstr3bRespObj.getString("data");
gstr3bRek = gstr3bRespObj.getString("rek");
byte[] apiEKGstr3b = aesEncryption.decrypt(gstr3bRek, authSek);
String gstr3bRespJsoninBase64 = new String(aesEncryption.decrypt(gstr3bData, apiEKGstr3b));
byte[] gstr3bRespJsonInBytes = aesEncryption.decodeBase64StringTOByte(gstr3bRespJsoninBase64);
JSONObject gstr3bTransIdRespObj = new JSONObject(new String(gstr3bRespJsonInBytes));
String transId = gstr3bTransIdRespObj.getString("reference_id");
responseId = transId;
System.out.println("transId to getStatus["+transId+"]");
boolean isRetStatusError = false;
while(true)
{
long timeStampRet = new Timestamp().getDateTime();
gspAuthStringRet = clientId + ":" + transactionId + ":" + timeStampRet + ":" + gstin;
gspAuthSignatureRet = gspSignature.sign(gspAuthStringRet, aspPrivateKey);
HttpRequest retStatusReq = Unirest.get(String.format("%s%s", GSP_API_URL, GSTR_URL_V3))
.queryString("action","RETSTATUS")
.queryString("gstin", gstin)
.queryString("ret_period", periodCode)
.queryString("ref_id",transId)
.header("Content-Type", APPLICATION_JSON)
.header("state-cd", stateCode)
.header("clientid", clientId)
.header("client-secret", clientSecret)
.header("ip-usr", ipAddress)
.header("username", userName)
.header("auth-token", authToken)
.header("txn", transactionId)
.header("ret_period", periodCode)
.header("gstin", gstin)
.header("X-Asp-Auth-Token", gspAuthStringRet)
.header("X-Asp-Auth-Signature", gspAuthSignatureRet)
.getHttpRequest();
System.out.println("RETSTATUS url["+retStatusReq.getUrl()+"]");
System.out.println("RETSTATUS method["+retStatusReq.getHttpMethod()+"]");
System.out.println("RETSTATUS request header["+retStatusReq.getHeaders()+"]");
HttpResponse<JsonNode> retStatusResp = retStatusReq.asJson();
System.out.println(String.format("retStatusResp Request : Status[%s] Response[%s]", retStatusResp.getStatus(), retStatusResp.getBody()));
if (retStatusResp.getStatus() == 200)
{
JSONObject retStatsRespObj = retStatusResp.getBody().getObject();
if(retStatsRespObj.has("data") && retStatsRespObj.has("rek"))
{
retStatsData = retStatsRespObj.getString("data");
retStatsRek = retStatsRespObj.getString("rek");
String fileGstr3bData = fileGstr3bRespObj.getString("data");
String fileGstr3bRek = fileGstr3bRespObj.getString("rek");
byte[] apiEKRetstats = aesEncryption.decrypt(retStatsRek, authSek);
byte[] fileGstr3bApiEK = aesEncryption.decrypt(fileGstr3bRek, authSEK);
String retStatsRespJsoninBase64 = new String(aesEncryption.decrypt(retStatsData, apiEKRetstats));
String fileGstr3bJsoninBase64 = new String(aesEncryption.decrypt(fileGstr3bData, fileGstr3bApiEK));
byte[] retStatsRespJsonInBytes = aesEncryption.decodeBase64StringTOByte(retStatsRespJsoninBase64);
byte[] fileGstr3bJsonInBytes = aesEncryption.decodeBase64StringTOByte(fileGstr3bJsoninBase64);
JSONObject retStatsJsonData = new JSONObject(new String(retStatsRespJsonInBytes));
System.out.println( "retStatsJsonData["+retStatsJsonData+"]");
if("IP".equalsIgnoreCase((String)retStatsJsonData.get("status_cd")))
{
retStatusCallStatus = "0";
retStatusResponseJsonStr = "IP";
}
else if("P".equalsIgnoreCase((String)retStatsJsonData.get("status_cd")))
{
retStatusCallStatus = "1";
isRetStatusError = true;
}
else if("PE".equalsIgnoreCase((String)retStatsJsonData.get("status_cd")))
{
retStatusCallStatus = "2";
errMsg = getRetStatusErrMsg(retStatsJsonData);
retStatusResponseJsonStr = errMsg;
retString = getError(errMsg, "GSTAPIERR", conn);
isRetStatusError = true;
}
else if("ER".equalsIgnoreCase(retStatsJsonData.getString("status_cd")))
{
retStatusCallStatus = "2";
if(retStatsJsonData.has("error_report"))
{
JSONObject errorJSON = retStatsJsonData.getJSONObject("error_report");
if(errorJSON.has("error_msg") && errorJSON.has("error_cd"))
{
errMsg = "Message : "+errorJSON.getString("error_msg")+" \nError code : "+errorJSON.getString("error_cd");
}
}
retStatusResponseJsonStr = errMsg;
retString = getError(errMsg, "GSTAPIERR", conn);
isRetStatusError = true;
}
else
{
retStatusCallStatus = "2";
if(retStatsJsonData.has("status_cd"))
{
errMsg = "Message : "+retStatsJsonData.getString("status_cd")+" \nError code : "+retStatsJsonData.getString("status_cd");
}
retStatusResponseJsonStr = errMsg;
retString = getError(errMsg, "GSTAPIERR", conn);
isRetStatusError = true;
}
}
else
{
retStatusCallStatus = "2";
JSONObject errorJSON = retStatusResp.getBody().getObject().getJSONObject("error");
retStatusResponseJsonStr = errorJSON.toString();
errMsg = "Message : "+errorJSON.getString("message")+" \nError code : "+errorJSON.getString("error_cd");
retString = getError(errMsg, "GSTAPIERR", conn);
isRetStatusError = true;
}
}
else if(retStatusResp.getStatus() == 500)
{
retStatusCallStatus = "2";
errMsg = "Message : Error occurred at GSTN server \nResponse code : "+retStatusResp.getStatus();
retStatusResponseJsonStr = errMsg;
retString = getError(errMsg, "GSTAPIERR", conn);
isRetStatusError = true;
}
else
{
retStatusCallStatus = "2";
JSONObject errorJSON = retStatusResp.getBody().getObject().getJSONObject("error");
retStatusResponseJsonStr = errorJSON.toString();
errMsg = "Message : "+errorJSON.getString("message")+" \nError code : "+errorJSON.getString("error_cd");
retString = getError(errMsg, "GSTAPIERR", conn);
isRetStatusError = true;
}
apiRetStatsCallData = new APICallData();
apiRetStatsCallData.setPeriodCode(periodCode);
apiRetStatsCallData.setCallDate(new Date());
apiRetStatsCallData.setSiteCode(siteCode);
apiRetStatsCallData.setUserId(loginCode);
apiRetStatsCallData.setCallType("RETSTATUS");
apiRetStatsCallData.setRecType("3");
apiRetStatsCallData.setNoOfRecords(0);
apiRetStatsCallData.setCallStatus(retStatusCallStatus);
apiRetStatsCallData.setResponseId("");
apiRetStatsCallData.setResponseJsonStr(retStatusResponseJsonStr);
apiRetStatsCallData.setChgUser(loginCode);
apiRetStatsCallData.setChgDate(new Date());
apiRetStatsCallData.setChgTerm(chgTerm);
retStatAPICallList.add(apiRetStatsCallData);
if(isRetStatusError)
{
break;
}
else
{
continue;
}
}
System.out.println(new String(fileGstr3bJsonInBytes));
}
else
{
{
callStatus = "2";
JSONObject errorJSON = gstr3bResp.getBody().getObject().getJSONObject("error");
JSONObject errorJSON = fileGstr3bResp.getBody().getObject().getJSONObject("error");
responseJsonStr = errorJSON.toString();
errMsg = "Message : "+errorJSON.getString("message")+" \nError code : "+errorJSON.getString("error_cd");
retString = getError(errMsg, "GSTAPIERR", conn);
}
}
else if(gstr3bResp.getStatus() == 500)
{
callStatus = "2";
errMsg = "Message : Error occurred at GSTN server \nResponse code : "+gstr3bResp.getStatus();
responseJsonStr = errMsg;
retString = getError(errMsg, "GSTAPIERR", conn);
}
errMsg = "Message : "+errorJSON.getString("message")+" \nError code : "+errorJSON.getString("error_cd");
retString = getError(errMsg, "GSTAPIERR", conn);
}
}
else
{
{
callStatus = "2";
JSONObject errorJSON = gstr3bResp.getBody().getObject().getJSONObject("error");
responseJsonStr = errorJSON.toString();
errMsg = "Message : "+errorJSON.getString("message")+" \nError code : "+errorJSON.getString("error_cd");
retString = getError(errMsg, "GSTAPIERR", conn);
}
JSONObject errorJSON = fileGstr3bResp.getBody().getObject().getJSONObject("error");
responseJsonStr = errorJSON.toString();
errMsg = "Message : "+errorJSON.getString("message")+" \nError code : "+errorJSON.getString("error_cd");
retString = getError(errMsg, "GSTAPIERR", conn);
}
APICallData apiCallData = new APICallData();
apiCallData.setPeriodCode(periodCode);
apiCallData.setCallDate(new Date());
apiCallData.setSiteCode(siteCode);
apiCallData.setUserId(loginCode);
apiCallData.setCallType("RETSAVE");
apiCallData.setRecType("3");
apiCallData.setNoOfRecords(0);
apiCallData.setCallStatus(callStatus);
apiCallData.setResponseId(responseId);
apiCallData.setResponseJsonStr(responseJsonStr);
apiCallData.setChgUser(loginCode);
apiCallData.setChgDate(new Date());
apiCallData.setChgTerm(chgTerm);
gstCommonUtil.updateAPICallLogHistory(apiCallData, null);
if(retStatAPICallList.size()>0)
{
for(APICallData eachAPICallData : retStatAPICallList)
{
gstCommonUtil.updateAPICallLogHistory(eachAPICallData, null);
}
}
apiCallData.setPeriodCode(periodCode);
apiCallData.setCallDate(new Date());
apiCallData.setSiteCode(siteCode);
apiCallData.setUserId(loginCode);
apiCallData.setCallType("RETFILE");
apiCallData.setRecType("3");
apiCallData.setNoOfRecords(0);
apiCallData.setCallStatus(callStatus);
apiCallData.setResponseId("");
apiCallData.setResponseJsonStr(responseJsonStr);
apiCallData.setChgUser(loginCode);
apiCallData.setChgDate(new Date());
apiCallData.setChgTerm(chgTerm);
gstCommonUtil.updateAPICallLogHistory(apiCallData, null);
}
catch(Exception e)
{
System.out.println("GSTDataSubmitWizPos.saveGstr3b()["+e.getMessage()+"]");
System.out.println("GSTDataSubmitWizPos.fileGstr3b()["+e.getMessage()+"]");
e.printStackTrace();
throw new ITMException(e);
}
return retString;
}
private String submitGstr3b(String authToken, String stateCode, String userName, String gstin, String periodCode, byte[] authSEK, String xtraParams,Connection conn) throws ITMException
private void insertB2BInvoiceData(String stateCode, String periodCode, String siteCode, JSONObject gstr2InvoiceJsonObj, String xtraParams, Connection conn) throws ITMException
{
String retString = "";
String errMsg = "", gspAuthString = "", gspAuthSignature = "";
String transactionId = UUID.randomUUID().toString().replaceAll("-", "");
String loginCode = "", chgTerm = "", siteCode = "", callStatus = "", responseJsonStr = "", responseId = "";
JSONArray b2bInvArry = new JSONArray();
JSONObject b2bJsonObj = new JSONObject();
JSONArray b2bInvJsonArry = new JSONArray();
JSONObject b2bInvJsonObj = new JSONObject();
JSONArray b2bInvLineItmsArry = new JSONArray();
JSONObject b2bInvLineItemObj = new JSONObject();
String tranId = "", cptyGSTIN = "", iNum = "", iDate = "", reversCharge = "", docCheckSum = "", pos = "", invType = "", tranType = "";
String ecomOperetorGSTIN = "", loginCode = "", chgTerm = "";
String sql = "";
PreparedStatement pstmt = null;
int updateCnt = 0;
int lineNo = 0, hdrInsCnt = 0;
double amount = 0.0, lineAmt = 0.0, irt = 0.0, iamt = 0.0, crt = 0.0, camt = 0.0, srt = 0.0, samt = 0.0, csamt = 0.0, rate = 0.0;
int [] detInsCnt = null;
String hdrInsSql = "", detInsSql = "";
PreparedStatement hdrInsPstmt = null, detInsPstmt = null;
boolean isError = false;
try
{
siteCode = e12GenericUtility.getValueFromXTRA_PARAMS(xtraParams, "loginSiteCode");
loginCode = e12GenericUtility.getValueFromXTRA_PARAMS(xtraParams, "loginCode");
chgTerm = e12GenericUtility.getValueFromXTRA_PARAMS(xtraParams, "chgTerm");
String json = "{\"gstin\":\""+gstin+"\",\"ret_period\":\""+periodCode+"\"}";
byte[] jsonBase64 = Base64.getEncoder().encode(json.getBytes());
String encryptedPayload = aesEncryption.encryptEK(jsonBase64, authSEK);
HMac hmac = new HMac(new SHA256Digest());
byte[] resBuf = new byte[hmac.getMacSize()];
hmac.init(new KeyParameter(authSEK));
hmac.update(jsonBase64, 0, jsonBase64.length);
hmac.doFinal(resBuf, 0);
JSONObject reqBody = new JSONObject();
reqBody.put("action", "RETSUBMIT");
reqBody.put("data", encryptedPayload);
reqBody.put("hmac", new String(Base64.getEncoder().encode(resBuf)));
long timeStamp = new Timestamp().getDateTime();
gspAuthString = clientId + ":" + transactionId + ":" + timeStamp + ":" + gstin;
gspAuthSignature = gspSignature.sign(gspAuthString, aspPrivateKey);
HttpRequest gstr3bSubmitReq = Unirest.post(String.format("%s%s", GSP_API_URL, GSTR3B_URL_V3))
.header("Content-Type", APPLICATION_JSON)
.header("action", "RETSUBMIT")
.header("state-cd", stateCode)
.header("clientid", clientId)
.header("client-secret", clientSecret)
.header("ip-usr", ipAddress)
.header("username", userName)
.header("auth-token", authToken)
.header("txn", transactionId)
.header("ret_period", periodCode)
.header("gstin", gstin)
.header("X-Asp-Auth-Token", gspAuthString)
.header("X-Asp-Auth-Signature", gspAuthSignature)
.body(new JsonNode(reqBody.toString()))
.getHttpRequest();
System.out.println("RETSUBMIT GSTR3B url["+gstr3bSubmitReq.getUrl()+"]");
System.out.println("RETSUBMIT GSTR3B method["+gstr3bSubmitReq.getHttpMethod()+"]");
System.out.println("RETSUBMIT GSTR3B request header["+gstr3bSubmitReq.getHeaders()+"]");
System.out.println("RETSUBMIT GSTR3B request payload["+IOUtils.toString(gstr3bSubmitReq.getBody().getEntity().getContent())+"]");
HttpResponse<JsonNode> gstr3bSubmitResp = gstr3bSubmitReq.asJson();
System.out.println(String.format("gstr3bSubmitResp Request : Status[%s] Response[%s]", gstr3bSubmitResp.getStatus(), gstr3bSubmitResp.getBody()));
if (gstr3bSubmitResp.getStatus() == 200)
{
JSONObject gstr3bSubmitRespObj = gstr3bSubmitResp.getBody().getObject();
if(gstr3bSubmitRespObj.has("data") && gstr3bSubmitRespObj.has("rek"))
{
callStatus = "1";
String gstr3bSubmitdata = gstr3bSubmitRespObj.getString("data");
String gstr3bSubmitrek = gstr3bSubmitRespObj.getString("rek");
byte[] apiEK = aesEncryption.decrypt(gstr3bSubmitrek, authSEK);
String respJsoninBase64 = new String(aesEncryption.decrypt(gstr3bSubmitdata, apiEK));
byte[] respJsonInBytes = aesEncryption.decodeBase64StringTOByte(respJsoninBase64);
JSONObject gstr3bSubmitObj = new JSONObject(new String(respJsonInBytes));
String transId = gstr3bSubmitObj.getString("reference_id");
responseId = transId;
System.out.println("transId to getStatus after SUBMIT call["+transId+"]");
//TODO need to check
/*sql = "UPDATE GST_DATA_HDR SET SUBMIT_STATUS = ? AND SUBMIT_DATE = ? WHERE PRD_CODE = ? AND SITE_CODE = ? AND REC_TYPE = '1'";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, "S");
pstmt.setTimestamp(2, java.sql.Timestamp.valueOf(e12GenericUtility.getValidDateString(new Date(), e12GenericUtility.getDBDateTimeFormat())));
pstmt.setString(3, periodCode);
pstmt.setString(4, siteCode);
updateCnt = pstmt.executeUpdate();
if(pstmt!=null)
{
pstmt.close();
pstmt = null;
}
System.out.println("submit status updated of ["+siteCode+"] for ["+periodCode+"] update count ["+updateCnt+"]");*/
}
else
{
callStatus = "2";
JSONObject errorJSON = gstr3bSubmitResp.getBody().getObject().getJSONObject("error");
responseJsonStr = errorJSON.toString();
errMsg = "Message : "+errorJSON.getString("message")+" \nError code : "+errorJSON.getString("error_cd");
retString = getError(errMsg, "GSTAPIERR", conn);
}
}
else if(gstr3bSubmitResp.getStatus() == 500)
{
callStatus = "2";
errMsg = "Message : Error occurred at GSTN server \nResponse code : "+gstr3bSubmitResp.getStatus();
responseJsonStr = errMsg;
retString = getError(errMsg, "GSTAPIERR", conn);
}
else
{
callStatus = "2";
JSONObject errorJSON = gstr3bSubmitResp.getBody().getObject().getJSONObject("error");
responseJsonStr = errorJSON.toString();
errMsg = "Message : "+errorJSON.getString("message")+" \nError code : "+errorJSON.getString("error_cd");
retString = getError(errMsg, "GSTAPIERR", conn);
}
APICallData apiCallData = new APICallData();
apiCallData.setPeriodCode(periodCode);
apiCallData.setCallDate(new Date());
apiCallData.setSiteCode(siteCode);
apiCallData.setUserId(loginCode);
apiCallData.setCallType("RETSUBMIT");
apiCallData.setRecType("3");
apiCallData.setNoOfRecords(0);
apiCallData.setCallStatus(callStatus);
apiCallData.setResponseId(responseId);
apiCallData.setResponseJsonStr(responseJsonStr);
apiCallData.setChgUser(loginCode);
apiCallData.setChgDate(new Date());
apiCallData.setChgTerm(chgTerm);
gstCommonUtil.updateAPICallLogHistory(apiCallData, null);
}
catch(Exception e)
{
System.out.println("GSTDataSubmitWizPos.submitGstr3b()["+e.getMessage()+"]");
e.printStackTrace();
throw new ITMException(e);
}
return retString;
}
private String fileGstr3b(String authToken, String stateCode, String userName, String gstin, String periodCode, byte[] authSek, String summaryData, String signedData, String panNo, String aadhaarNo, String signMethod, String xtraParams, Connection conn) throws ITMException
{
String retString = "";
String errMsg = "", gspAuthString = "", gspAuthSignature = "", signType = "",signId = "";
String transactionId = UUID.randomUUID().toString().replaceAll("-", "");
String loginCode = "", chgTerm = "", siteCode = "", callStatus = "", responseJsonStr = "";
try
{
siteCode = e12GenericUtility.getValueFromXTRA_PARAMS(xtraParams, "loginSiteCode");
loginCode = e12GenericUtility.getValueFromXTRA_PARAMS(xtraParams, "loginCode");
chgTerm = e12GenericUtility.getValueFromXTRA_PARAMS(xtraParams, "chgTerm");
long timeStamp = new Timestamp().getDateTime();
gspAuthString = clientId + ":" + transactionId + ":" + timeStamp + ":" + gstin;
gspAuthSignature = gspSignature.sign(gspAuthString, aspPrivateKey);
byte[] jsonBase64 = Base64.getEncoder().encode(summaryData.toString().getBytes());
String encryptedPayload = aesEncryption.encryptEK(jsonBase64, authSek);
HMac hmac = new HMac(new SHA256Digest());
byte[] resBuf = new byte[hmac.getMacSize()];
hmac.init(new KeyParameter(authSek));
hmac.update(jsonBase64, 0, jsonBase64.length);
hmac.doFinal(resBuf, 0);
if("D".equalsIgnoreCase(signMethod))
{
signType = "DSC";
signId = panNo;
}
else if("E".equalsIgnoreCase(signMethod))
{
signType = "ESIGN";
signId = aadhaarNo;
}
JSONObject fileGstr3bDataJsonObj = new JSONObject();
fileGstr3bDataJsonObj.put("action", "RETFILE");
fileGstr3bDataJsonObj.put("data", encryptedPayload);
fileGstr3bDataJsonObj.put("hmac", new String(Base64.getEncoder().encode(resBuf)));
fileGstr3bDataJsonObj.put("sign", signedData);
fileGstr3bDataJsonObj.put("st", signType);
fileGstr3bDataJsonObj.put("sid", signId);
HttpRequest fileGstr3bReq = Unirest.post(String.format("%s%s", GSP_API_URL, GSTR3B_URL_V3))
.header("Content-Type", APPLICATION_JSON)
.header("state-cd", stateCode)
.header("clientid", clientId)
.header("client-secret", clientSecret)
.header("ip-usr", ipAddress)
.header("username", userName)
.header("auth-token", authToken)
.header("txn", transactionId)
.header("ret_period", periodCode)
.header("gstin", gstin)
.header("X-Asp-Auth-Token", gspAuthString)
.header("X-Asp-Auth-Signature", gspAuthSignature)
.body(new JsonNode(fileGstr3bDataJsonObj.toString()))
.getHttpRequest();
System.out.println("FILE GSTR3B url["+fileGstr3bReq.getUrl()+"]");
System.out.println("FILE GSTR3B method["+fileGstr3bReq.getHttpMethod()+"]");
System.out.println("FILE GSTR3B request header["+fileGstr3bReq.getHeaders()+"]");
System.out.println("FILE GSTR3B request payload["+IOUtils.toString(fileGstr3bReq.getBody().getEntity().getContent())+"]");
HttpResponse<JsonNode> fileGstr3bResp = fileGstr3bReq.asJson();
System.out.println(String.format("fileGstr3bResp Request : Status[%s] Response[%s]", fileGstr3bResp.getStatus(), fileGstr3bResp.getBody()));
if (fileGstr3bResp.getStatus() == 200)
{
JSONObject fileGstr3bRespObj = fileGstr3bResp.getBody().getObject();
if(fileGstr3bRespObj.has("data") && fileGstr3bRespObj.has("rek"))
{
callStatus = "1";
String fileGstr3bData = fileGstr3bRespObj.getString("data");
String fileGstr3bRek = fileGstr3bRespObj.getString("rek");
byte[] fileGstr3bApiEK = aesEncryption.decrypt(fileGstr3bRek, authSek);
String fileGstr3bJsoninBase64 = new String(aesEncryption.decrypt(fileGstr3bData, fileGstr3bApiEK));
byte[] fileGstr3bJsonInBytes = aesEncryption.decodeBase64StringTOByte(fileGstr3bJsoninBase64);
System.out.println(new String(fileGstr3bJsonInBytes));
}
else
{
callStatus = "2";
JSONObject errorJSON = fileGstr3bResp.getBody().getObject().getJSONObject("error");
responseJsonStr = errorJSON.toString();
errMsg = "Message : "+errorJSON.getString("message")+" \nError code : "+errorJSON.getString("error_cd");
retString = getError(errMsg, "GSTAPIERR", conn);
}
}
else
{
callStatus = "2";
JSONObject errorJSON = fileGstr3bResp.getBody().getObject().getJSONObject("error");
responseJsonStr = errorJSON.toString();
errMsg = "Message : "+errorJSON.getString("message")+" \nError code : "+errorJSON.getString("error_cd");
retString = getError(errMsg, "GSTAPIERR", conn);
}
APICallData apiCallData = new APICallData();
apiCallData.setPeriodCode(periodCode);
apiCallData.setCallDate(new Date());
apiCallData.setSiteCode(siteCode);
apiCallData.setUserId(loginCode);
apiCallData.setCallType("RETFILE");
apiCallData.setRecType("3");
apiCallData.setNoOfRecords(0);
apiCallData.setCallStatus(callStatus);
apiCallData.setResponseId("");
apiCallData.setResponseJsonStr(responseJsonStr);
apiCallData.setChgUser(loginCode);
apiCallData.setChgDate(new Date());
apiCallData.setChgTerm(chgTerm);
gstCommonUtil.updateAPICallLogHistory(apiCallData, null);
}
catch(Exception e)
{
System.out.println("GSTDataSubmitWizPos.fileGstr3b()["+e.getMessage()+"]");
e.printStackTrace();
throw new ITMException(e);
}
return retString;
}
private void insertB2BInvoiceData(String stateCode, String periodCode, String siteCode, JSONObject gstr2InvoiceJsonObj, String xtraParams, Connection conn) throws ITMException
{
JSONArray b2bInvArry = new JSONArray();
JSONObject b2bJsonObj = new JSONObject();
JSONArray b2bInvJsonArry = new JSONArray();
JSONObject b2bInvJsonObj = new JSONObject();
JSONArray b2bInvLineItmsArry = new JSONArray();
JSONObject b2bInvLineItemObj = new JSONObject();
String tranId = "", cptyGSTIN = "", iNum = "", iDate = "", reversCharge = "", docCheckSum = "", pos = "", invType = "", tranType = "";
String ecomOperetorGSTIN = "", loginCode = "", chgTerm = "";
int lineNo = 0, hdrInsCnt = 0;
double amount = 0.0, lineAmt = 0.0, irt = 0.0, iamt = 0.0, crt = 0.0, camt = 0.0, srt = 0.0, samt = 0.0, csamt = 0.0, rate = 0.0;
int [] detInsCnt = null;
String hdrInsSql = "", detInsSql = "";
PreparedStatement hdrInsPstmt = null, detInsPstmt = null;
boolean isError = false;
try
{
loginCode = e12GenericUtility.getValueFromXTRA_PARAMS(xtraParams, "loginCode");
chgTerm = e12GenericUtility.getValueFromXTRA_PARAMS(xtraParams, "chgTerm");
hdrInsSql = " INSERT INTO GST_DATA_HDR (TRAN_ID, TRAN_DATE, TRAN_ID__REF, SITE_CODE, PRD_CODE, REC_TYPE, TRAN_TYPE, CUST_CODE, CUST_NAME,"
+ " SUBMISSION_TYPE, DOC_CHECKSUM, DOC_TYPE, DOC_NO, DOC_DATE, AMOUNT, REVERSE_CHRG, LR_NO, LR_DATE, REAS_CODE, REF_ID__INV,"
+ " REF_DATE__INV, PROV_ASSMNT, ORDER_NO, ORDER_DATE, REMARKS, SUBMIT_STATUS, SUBMIT_DATE, ADD_USER, ADD_DATE, ADD_TERM, CHG_USER,"
+ " CHG_DATE, CHG_TERM, TAX_REG_NO, RECO_STATUS, ECOM_REG_NO, REF_SER, GST_CODE, GST_TYPE, REF_ID)"
+ " VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
hdrInsPstmt = conn.prepareStatement(hdrInsSql);
hdrInsSql = " INSERT INTO GST_DATA_HDR (TRAN_ID, TRAN_DATE, TRAN_ID__REF, SITE_CODE, PRD_CODE, REC_TYPE, TRAN_TYPE, CUST_CODE, CUST_NAME,"
+ " SUBMISSION_TYPE, DOC_CHECKSUM, DOC_TYPE, DOC_NO, DOC_DATE, AMOUNT, REVERSE_CHRG, LR_NO, LR_DATE, REAS_CODE, REF_ID__INV,"
+ " REF_DATE__INV, PROV_ASSMNT, ORDER_NO, ORDER_DATE, REMARKS, SUBMIT_STATUS, SUBMIT_DATE, ADD_USER, ADD_DATE, ADD_TERM, CHG_USER,"
+ " CHG_DATE, CHG_TERM, TAX_REG_NO, RECO_STATUS, ECOM_REG_NO, REF_SER, GST_CODE, GST_TYPE, REF_ID)"
+ " VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
hdrInsPstmt = conn.prepareStatement(hdrInsSql);
b2bInvArry = gstr2InvoiceJsonObj.getJSONArray("b2b");
......@@ -5732,35 +5457,386 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi
}
}
if(pstmt!=null)
if(pstmt!=null)
{
pstmt.close();
pstmt = null;
}
if(rs!=null)
{
rs.close();
rs = null;
}
if(intraNilSupplies != null)
{
intraNilSupplies.compoundSuppliesAmt = compoundingAmount;
intraNilSupplies.nilSuppliesAmt = nilAmount;
intraNilSupplies.exempetedSuppliesAmt = exemtAmount;
intraNilSupplies.nonGSTSuppliesAmt = nonGSTAmount;
}
}
catch(Exception e)
{
System.out.println("GSTDataSubmitWizPos.getIntraNilRateSummary()["+e.getMessage()+"]");
e.printStackTrace();
}
return intraNilSupplies;
}
public String saveGSTRData(String jsonPayload, int noOfRecords, ArrayList<String> tranIdList, String recType, Connection conn, String xtraParams) throws ITMException
{
String retString = "";
String gspAuthString = "", gspAuthSignature = "", transactionId = "", RETURN_URL = "", errMsg = "", callStatus = "", responseId = "",
retStatusCallStatus = "", retStatsData = "", retStatsRek = "", retStatusResponseJsonStr = "", responseJsonStr = "",
gspAuthStringRet = "", gspAuthSignatureRet = "",loginCode = "", chgTerm = "", siteCode = "", gstrData = "", gstrRek = "";
Date restSaveEndTime = null;
int retStatusCallCnt = 0;
long diffStatus = 0L;
APICallData apiRetStatsCallData = null;
List<APICallData> retStatAPICallList = new ArrayList<>();
try
{
siteCode = e12GenericUtility.getValueFromXTRA_PARAMS(xtraParams, "loginSiteCode");
loginCode = e12GenericUtility.getValueFromXTRA_PARAMS(xtraParams, "loginCode");
chgTerm = e12GenericUtility.getValueFromXTRA_PARAMS(xtraParams, "chgTerm");
transactionId = UUID.randomUUID().toString().replaceAll("-", "");
byte[] jsonBase64 = Base64.getEncoder().encode(jsonPayload.getBytes());
String encryptedPayload = aesEncryption.encryptEK(jsonBase64, authSEK);
HMac hmac = new HMac(new SHA256Digest());
byte[] resBuf = new byte[hmac.getMacSize()];
hmac.init(new KeyParameter(authSEK));
hmac.update(jsonBase64, 0, jsonBase64.length);
hmac.doFinal(resBuf, 0);
JSONObject gstr1HeaderObj = new JSONObject();
gstr1HeaderObj.put("action", "RETSAVE");
gstr1HeaderObj.put("data", encryptedPayload);
gstr1HeaderObj.put("hmac", new String(Base64.getEncoder().encode(resBuf)));
long timeStamp = new Timestamp().getDateTime();
gspAuthString = clientId + ":" + transactionId + ":" + timeStamp + ":" + gstin;
gspAuthSignature = gspSignature.sign(gspAuthString, aspPrivateKey);
Date startTime = new Date();
if("1".equalsIgnoreCase(recType))
{
pstmt.close();
pstmt = null;
RETURN_URL = GSTR1_URL_V3;
}
if(rs!=null)
else if("2".equalsIgnoreCase(recType))
{
rs.close();
rs = null;
RETURN_URL = GSTR2_URL_V3;
}
else if("3".equalsIgnoreCase(recType))
{
RETURN_URL = GSTR3_URL_V3;
}
else if("6".equalsIgnoreCase(recType))
{
RETURN_URL = GSTR3B_URL_V3;
}
if(intraNilSupplies != null)
HttpRequest saveGstrReq = Unirest.put(String.format("%s%s", GSP_API_URL, RETURN_URL))
.header("Content-Type", APPLICATION_JSON)
.header("clientid", clientId)
.header("client-secret", clientSecret)
.header("txn",transactionId)
.header("state-cd", stateCode)
.header("auth-token", authToken)
.header("gstin", gstin)
.header("username", userName)
.header("ret_period", periodCode)
.header("ip-usr", ipAddress)
.header("X-Asp-Auth-Token", gspAuthString)
.header("X-Asp-Auth-Signature", gspAuthSignature)
.body(new JsonNode(gstr1HeaderObj.toString()))
.getHttpRequest();
System.out.println("SAVE GSTR"+recType+" url["+saveGstrReq.getUrl()+"]");
System.out.println("SAVE GSTR"+recType+" method["+saveGstrReq.getHttpMethod()+"]");
System.out.println("SAVE GSTR"+recType+" request header["+saveGstrReq.getHeaders()+"]");
System.out.println("SAVE GSTR"+recType+" request payload["+IOUtils.toString(saveGstrReq.getBody().getEntity().getContent())+"]");
HttpResponse<JsonNode> gstrResp = saveGstrReq.asJson();
System.out.println(String.format("gstrResp Request : Status[%s] Response[%s]", gstrResp.getStatus(), gstrResp.getBody()));
if (gstrResp.getStatus() == 200)
{
JSONObject gstrRespObj = gstrResp.getBody().getObject();
if(gstrRespObj.has("data") && gstrRespObj.has("rek"))
{
callStatus = "1";
gstrData = gstrRespObj.getString("data");
gstrRek = gstrRespObj.getString("rek");
byte[] apiEKGstr = aesEncryption.decrypt(gstrRek, authSEK);
String gstrRespJsoninBase64 = new String(aesEncryption.decrypt(gstrData, apiEKGstr));
byte[] gstrRespJsonInBytes = aesEncryption.decodeBase64StringTOByte(gstrRespJsoninBase64);
JSONObject gstrTransIdRespObj = new JSONObject(new String(gstrRespJsonInBytes));
String transId = gstrTransIdRespObj.getString("reference_id");
responseId = transId;
System.out.println("transId to getStatus["+transId+"]");
restSaveEndTime = new Date();
long retSaveDiff = restSaveEndTime.getTime() - startTime.getTime();
long retSaveDiffSeconds = retSaveDiff / 1000 % 60;
long retSaveDiffMinutes = retSaveDiff / (60 * 1000) % 60;
long retSaveDiffHours = retSaveDiff / (60 * 60 * 1000);
System.out.println("DIFFERANCE IN TIME FOR RETSAVE GSTR1 IN HH:MM:SS ["+retSaveDiffHours +":"+retSaveDiffMinutes+":"+retSaveDiffSeconds+"]");
boolean isRetStatusError = false;
while(true)
{
Thread.sleep(noOfRecords);//TODO NEED TO REMOVE WITH BETTER OPTION
retStatusCallCnt++;
long timeStampRet = new Timestamp().getDateTime();
gspAuthStringRet = clientId + ":" + transactionId + ":" + timeStampRet + ":" + gstin;
gspAuthSignatureRet = gspSignature.sign(gspAuthStringRet, aspPrivateKey);
HttpRequest retStatusReq = Unirest.get(String.format("%s%s", GSP_API_URL, GSTR_URL_V3))
.queryString("action","RETSTATUS")
.queryString("gstin", gstin)
.queryString("ret_period", periodCode)
.queryString("ref_id",transId)
.header("Content-Type", APPLICATION_JSON)
.header("state-cd", stateCode)
.header("clientid", clientId)
.header("client-secret", clientSecret)
.header("ip-usr", ipAddress)
.header("username", userName)
.header("auth-token", authToken)
.header("txn", transactionId)
.header("ret_period", periodCode)
.header("gstin", gstin)
.header("X-Asp-Auth-Token", gspAuthStringRet)
.header("X-Asp-Auth-Signature", gspAuthSignatureRet)
.getHttpRequest();
System.out.println("RETSTATUS url["+retStatusReq.getUrl()+"]");
System.out.println("RETSTATUS method["+retStatusReq.getHttpMethod()+"]");
System.out.println("RETSTATUS request header["+retStatusReq.getHeaders()+"]");
HttpResponse<JsonNode> retStatusResp = retStatusReq.asJson();
System.out.println(String.format("retStatusResp Request : Status[%s] Response[%s]", retStatusResp.getStatus(), retStatusResp.getBody()));
if (retStatusResp.getStatus() == 200)
{
JSONObject retStatsRespObj = retStatusResp.getBody().getObject();
if(retStatsRespObj.has("data") && retStatsRespObj.has("rek"))
{
retStatsData = retStatsRespObj.getString("data");
retStatsRek = retStatsRespObj.getString("rek");
byte[] apiEKRetstats = aesEncryption.decrypt(retStatsRek, authSEK);
String retStatsRespJsoninBase64 = new String(aesEncryption.decrypt(retStatsData, apiEKRetstats));
byte[] retStatsRespJsonInBytes = aesEncryption.decodeBase64StringTOByte(retStatsRespJsoninBase64);
JSONObject retStatsJsonData = new JSONObject(new String(retStatsRespJsonInBytes));
System.out.println( "retStatsJsonData["+retStatsJsonData+"]");
if("IP".equalsIgnoreCase((String)retStatsJsonData.get("status_cd")))
{
retStatusCallStatus = "0";
retStatusResponseJsonStr = "IP";
}
else if("P".equalsIgnoreCase((String)retStatsJsonData.get("status_cd")))
{
retStatusCallStatus = "1";
if(tranIdList.size() > 0)
{
updateSubmissionStatus(tranIdList, conn);
}
isRetStatusError = true;
}
else if("PE".equalsIgnoreCase((String)retStatsJsonData.get("status_cd")))
{
retStatusCallStatus = "2";
errMsg = getRetStatusErrMsg(retStatsJsonData);
retStatusResponseJsonStr = errMsg;
retString = getError(errMsg, "GSTAPIERR", conn);
isRetStatusError = true;
}
else if("ER".equalsIgnoreCase(retStatsJsonData.getString("status_cd")))
{
retStatusCallStatus = "2";
if(retStatsJsonData.has("error_report"))
{
JSONObject errorJSON = retStatsJsonData.getJSONObject("error_report");
if(errorJSON.has("error_msg") && errorJSON.has("error_cd"))
{
errMsg = "Message : "+errorJSON.getString("error_msg")+" \nError code : "+errorJSON.getString("error_cd");
}
}
retStatusResponseJsonStr = errMsg;
retString = getError(errMsg, "GSTAPIERR", conn);
isRetStatusError = true;
}
else
{
retStatusCallStatus = "2";
if(retStatsJsonData.has("status_cd"))
{
errMsg = "Message : "+retStatsJsonData.getString("status_cd")+" \nError code : "+retStatsJsonData.getString("status_cd");
}
retStatusResponseJsonStr = errMsg;
retString = getError(errMsg, "GSTAPIERR", conn);
isRetStatusError = true;
}
}
else
{
retStatusCallStatus = "2";
JSONObject errorJSON = retStatusResp.getBody().getObject().getJSONObject("error");
retStatusResponseJsonStr = errorJSON.toString();
errMsg = "Message : "+errorJSON.getString("message")+" \nError code : "+errorJSON.getString("error_cd");
retString = getError(errMsg, "GSTAPIERR", conn);
isRetStatusError = true;
}
}
else if(retStatusResp.getStatus() == 500)
{
retStatusCallStatus = "2";
errMsg = "Message : Error occurred at GSTN server \nResponse code : "+retStatusResp.getStatus();
retStatusResponseJsonStr = errMsg;
retString = getError(errMsg, "GSTAPIERR", conn);
isRetStatusError = true;
}
else
{
retStatusCallStatus = "2";
JSONObject errorJSON = retStatusResp.getBody().getObject().getJSONObject("error");
retStatusResponseJsonStr = errorJSON.toString();
errMsg = "Message : "+errorJSON.getString("message")+" \nError code : "+errorJSON.getString("error_cd");
retString = getError(errMsg, "GSTAPIERR", conn);
isRetStatusError = true;
}
apiRetStatsCallData = new APICallData();
apiRetStatsCallData.setPeriodCode(periodCode);
apiRetStatsCallData.setCallDate(new Date());
apiRetStatsCallData.setSiteCode(siteCode);
apiRetStatsCallData.setUserId(loginCode);
apiRetStatsCallData.setCallType("RETSTATUS");
apiRetStatsCallData.setRecType(recType);
apiRetStatsCallData.setNoOfRecords(0);
apiRetStatsCallData.setCallStatus(retStatusCallStatus);
apiRetStatsCallData.setResponseId("");
apiRetStatsCallData.setResponseJsonStr(retStatusResponseJsonStr);
apiRetStatsCallData.setChgUser(loginCode);
apiRetStatsCallData.setChgDate(new Date());
apiRetStatsCallData.setChgTerm(chgTerm);
retStatAPICallList.add(apiRetStatsCallData);
if(isRetStatusError)
{
break;
}
else
{
continue;
}
}
}
else
{
callStatus = "2";
JSONObject errorJSON = gstrResp.getBody().getObject().getJSONObject("error");
responseJsonStr = errorJSON.toString();
errMsg = "Message : "+errorJSON.getString("message")+" \nError code : "+errorJSON.getString("error_cd");
retString = getError(errMsg, "GSTAPIERR", conn);
}
}
else if(gstrResp.getStatus() == 500)
{
callStatus = "2";
errMsg = "Message : Error occurred at GSTN server \nResponse code : "+gstrResp.getStatus();
responseJsonStr = errMsg;
retString = getError(errMsg, "GSTAPIERR", conn);
}
else
{
callStatus = "2";
JSONObject errorJSON = gstrResp.getBody().getObject().getJSONObject("error");
responseJsonStr = errorJSON.toString();
errMsg = "Message : "+errorJSON.getString("message")+" \nError code : "+errorJSON.getString("error_cd");
retString = getError(errMsg, "GSTAPIERR", conn);
}
System.out.println("total retStatusCallCnt ["+retStatusCallCnt+"]");
Date endTime = new Date();
long diff = endTime.getTime() - startTime.getTime();
long diffSeconds = diff / 1000 % 60;
long diffMinutes = diff / (60 * 1000) % 60;
long diffHours = diff / (60 * 60 * 1000);
if(restSaveEndTime != null)
{
intraNilSupplies.compoundSuppliesAmt = compoundingAmount;
intraNilSupplies.nilSuppliesAmt = nilAmount;
intraNilSupplies.exempetedSuppliesAmt = exemtAmount;
intraNilSupplies.nonGSTSuppliesAmt = nonGSTAmount;
diffStatus = endTime.getTime() - restSaveEndTime.getTime();
}
long diffStatsSeconds = diffStatus / 1000 % 60;
long diffStatsMinutes = diffStatus / (60 * 1000) % 60;
long diffStatsHours = diffStatus / (60 * 60 * 1000);
System.out.println("DIFFERANCE IN TIME FOR RETSTATUS GSTR1 IN HH:MM:SS ["+diffStatsHours +":"+diffStatsMinutes+":"+diffStatsSeconds+"]");
System.out.println("DIFFERANCE IN TIME FOR SAVE GSTR1 IN HH:MM:SS ["+diffHours +":"+diffMinutes+":"+diffSeconds+"]");
APICallData apiCallData = new APICallData();
apiCallData.setPeriodCode(periodCode);
apiCallData.setCallDate(new Date());
apiCallData.setSiteCode(siteCode);
apiCallData.setUserId(loginCode);
apiCallData.setCallType("RETSAVE");
apiCallData.setRecType("1");
apiCallData.setNoOfRecords(noOfRecords);
apiCallData.setCallStatus(callStatus);
apiCallData.setResponseId(responseId);
apiCallData.setResponseJsonStr(responseJsonStr);
apiCallData.setChgUser(loginCode);
apiCallData.setChgDate(new Date());
apiCallData.setChgTerm(chgTerm);
gstCommonUtil.updateAPICallLogHistory(apiCallData, null);
if(retStatAPICallList.size()>0)
{
for(APICallData eachAPICallData : retStatAPICallList)
{
gstCommonUtil.updateAPICallLogHistory(eachAPICallData, null);
}
}
}
catch(Exception e)
{
System.out.println("GSTDataSubmitWizPos.getIntraNilRateSummary()["+e.getMessage()+"]");
System.out.println("GSTDataSubmitWizPos.saveGSTRData()["+e.getMessage()+"]");
e.printStackTrace();
throw new ITMException(e);
}
return intraNilSupplies;
return retString;
}
private void insertGSTHdrDetData(List<String> hdrColumnList, List<String> hdrDataTypeList, List<String> hdrDataList, List<String> detColumnList, List<String> detDataTypeList, List<List<String>> detDataList, Connection conn) throws ITMException
{
boolean isError = false;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment