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 ...@@ -103,6 +103,7 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi
private String GSTR1_URL_V3 = ""; private String GSTR1_URL_V3 = "";
private String GSTR2_URL_V3 = ""; private String GSTR2_URL_V3 = "";
private String GSTR2A_URL_V3 = ""; private String GSTR2A_URL_V3 = "";
private String GSTR3_URL_V3 = "";
private String GSTR3B_URL_V3 = ""; private String GSTR3B_URL_V3 = "";
private final String APPLICATION_JSON = "application/json"; private final String APPLICATION_JSON = "application/json";
private String appKey = ""; private String appKey = "";
...@@ -111,6 +112,9 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi ...@@ -111,6 +112,9 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi
private String appKeyEncryptedAndCoded = ""; private String appKeyEncryptedAndCoded = "";
private String clientId = ""; private String clientId = "";
private String clientSecret = ""; private String clientSecret = "";
String userName = "", gstin = "", periodCode = "", stateCode = "", authToken = "";
byte[] authSEK = null;
AESEncryption aesEncryption = null; AESEncryption aesEncryption = null;
PubKeyEncryption pubKeyEncryption = null; PubKeyEncryption pubKeyEncryption = null;
Connection conn = null; Connection conn = null;
...@@ -200,6 +204,11 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi ...@@ -200,6 +204,11 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi
GSTR2A_URL_V3 = rs.getString("SERVICE_URI"); GSTR2A_URL_V3 = rs.getString("SERVICE_URI");
} }
break; break;
case "gstr3_url_v3" :
{
GSTR3_URL_V3 = rs.getString("SERVICE_URI");
}
break;
case "gstr3b_url_v3" : case "gstr3b_url_v3" :
{ {
GSTR3B_URL_V3 = rs.getString("SERVICE_URI"); GSTR3B_URL_V3 = rs.getString("SERVICE_URI");
...@@ -225,6 +234,7 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi ...@@ -225,6 +234,7 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi
System.out.println("GSTR1_URL_V3["+GSTR1_URL_V3+"]"); System.out.println("GSTR1_URL_V3["+GSTR1_URL_V3+"]");
System.out.println("GSTR2_URL_V3["+GSTR2_URL_V3+"]"); System.out.println("GSTR2_URL_V3["+GSTR2_URL_V3+"]");
System.out.println("GSTR2A_URL_V3["+GSTR2A_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+"]"); System.out.println("GSTR3B_URL_V3["+GSTR3B_URL_V3+"]");
} }
catch (Exception e) catch (Exception e)
...@@ -255,18 +265,16 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi ...@@ -255,18 +265,16 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi
{ {
Document allXMLDom = null; Document allXMLDom = null;
NodeList detail1NList = null, detail1ChildNList = null, detail2NList = null, detail2ChildNList = 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 = "", action = "", siteCode = "", gspAuthString = "", gspAuthSignature = "", currentYearTurnover = "", signedData = "", panNo = "", aadhaarNo = "",
signMethod = "", summaryData = ""; signMethod = "", summaryData = "";
String loginCode = "", chgTerm = "", callStatus = "", responseId = "", responseJsonStr= ""; String loginCode = "", chgTerm = "", callStatus = "", responseId = "", responseJsonStr= "";
byte[] authSEK = null;
APICallData apiCallData = null; APICallData apiCallData = null;
boolean isDataLogged = false; boolean isDataLogged = false;
try try
{ {
String userName = "", authToken = "";
String transactionId = UUID.randomUUID().toString().replaceAll("-", ""); String transactionId = UUID.randomUUID().toString().replaceAll("-", "");
loginCode = e12GenericUtility.getValueFromXTRA_PARAMS(xtraParams, "loginCode"); loginCode = e12GenericUtility.getValueFromXTRA_PARAMS(xtraParams, "loginCode");
...@@ -391,7 +399,7 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi ...@@ -391,7 +399,7 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi
System.out.println("authToken and authSEK from detail2"); System.out.println("authToken and authSEK from detail2");
authSEK = aesEncryption.decrypt(sek, appKeyInBytes); authSEK = aesEncryption.decrypt(sek, appKeyInBytes);
System.out.println("AuthSEK = "+ aesEncryption.encodeBase64String(authSEK)); System.out.println("authSEK = "+ aesEncryption.encodeBase64String(authSEK));
} }
else else
{ {
...@@ -448,7 +456,7 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi ...@@ -448,7 +456,7 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi
sek = object.getString("sek"); sek = object.getString("sek");
authSEK = aesEncryption.decrypt(sek, appKeyInBytes); authSEK = aesEncryption.decrypt(sek, appKeyInBytes);
System.out.println("AuthSEK = "+ aesEncryption.encodeBase64String(authSEK)); System.out.println("authSEK = "+ aesEncryption.encodeBase64String(authSEK));
callStatus = "1"; callStatus = "1";
apiCallData.setCallStatus(callStatus); apiCallData.setCallStatus(callStatus);
...@@ -517,52 +525,52 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi ...@@ -517,52 +525,52 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi
{ {
if("SAVE".equalsIgnoreCase(action)) 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)) else if ("SUBMIT".equalsIgnoreCase(action))
{ {
retString = submitGstr1(authToken, stateCode, userName, gstin, periodCode, authSEK, xtraParams, conn); retString = submitGstr1(xtraParams, conn);
} }
else if ("FILE".equalsIgnoreCase(action)) 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)) else if("GSTR2A".equalsIgnoreCase(returnsType))
{ {
if("GETINV".equalsIgnoreCase(action)) 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)) else if("GSTR2".equalsIgnoreCase(returnsType))
{ {
if("SAVE".equalsIgnoreCase(action)) 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)) else if ("SUBMIT".equalsIgnoreCase(action))
{ {
retString = submitGstr2(authToken, stateCode, userName, gstin, periodCode, authSEK, xtraParams, conn); retString = submitGstr2(xtraParams, conn);
} }
else if ("FILE".equalsIgnoreCase(action)) 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)) else if("GSTR3B".equalsIgnoreCase(returnsType))
{ {
if("SAVE".equalsIgnoreCase(action)) 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)) else if("SUBMIT".equalsIgnoreCase(action))
{ {
retString = submitGstr3b(authToken, stateCode, userName, gstin, periodCode, authSEK, xtraParams, conn); retString = submitGstr3b(xtraParams, conn);
} }
else if("FILE".equalsIgnoreCase(action)) 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 ...@@ -584,7 +592,7 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi
return retString; 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 retString = "", errMsg = "";
String gstr1Data = "", gstr1Rek = ""; String gstr1Data = "", gstr1Rek = "";
...@@ -930,20 +938,6 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi ...@@ -930,20 +938,6 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi
cdnrList.add(cdnr); 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 //tran_type : 06,07 = Exports and tran_type : 27,28 = Exports amendments
if("EXP".equalsIgnoreCase(udfStr1) || "EXPA".equalsIgnoreCase(udfStr1)) if("EXP".equalsIgnoreCase(udfStr1) || "EXPA".equalsIgnoreCase(udfStr1))
{ {
...@@ -1380,7 +1374,7 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi ...@@ -1380,7 +1374,7 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi
gstr1.docIssued = docIssuedList; gstr1.docIssued = docIssuedList;
} }
String gspAuthString = "", gspAuthSignature = "", gspAuthStringRet = "", gspAuthSignatureRet = ""; /*String gspAuthString = "", gspAuthSignature = "", gspAuthStringRet = "", gspAuthSignatureRet = "";
APICallData apiRetStatsCallData = null; APICallData apiRetStatsCallData = null;
List<APICallData> retStatAPICallList = new ArrayList<APICallData>(); List<APICallData> retStatAPICallList = new ArrayList<APICallData>();
int retStatusCallCnt = 0; int retStatusCallCnt = 0;
...@@ -1388,7 +1382,7 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi ...@@ -1388,7 +1382,7 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi
loginCode = e12GenericUtility.getValueFromXTRA_PARAMS(xtraParams, "loginCode"); loginCode = e12GenericUtility.getValueFromXTRA_PARAMS(xtraParams, "loginCode");
chgTerm = e12GenericUtility.getValueFromXTRA_PARAMS(xtraParams, "chgTerm"); chgTerm = e12GenericUtility.getValueFromXTRA_PARAMS(xtraParams, "chgTerm");
*/
ObjectMapper objectMapper = new ObjectMapper(); ObjectMapper objectMapper = new ObjectMapper();
String json = objectMapper.writeValueAsString(gstr1); String json = objectMapper.writeValueAsString(gstr1);
...@@ -1405,13 +1399,15 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi ...@@ -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+"]"); System.out.println("DIFFERANCE IN TIME FOR PAYLOAD CREATION GSTR1 IN HH:MM:SS ["+payloadDiffHours +":"+payloadDiffMinutes+":"+payloadDiffSeconds+"]");
byte[] jsonBase64 = Base64.getEncoder().encode(json.getBytes()); retString = saveGSTRData(json, noOfRecords, tranIdList, "1", conn, xtraParams);
String encryptedPayload = aesEncryption.encryptEK(jsonBase64, authSek);
/*byte[] jsonBase64 = Base64.getEncoder().encode(json.getBytes());
String encryptedPayload = aesEncryption.encryptEK(jsonBase64, authSEK);
HMac hmac = new HMac(new SHA256Digest()); HMac hmac = new HMac(new SHA256Digest());
byte[] resBuf = new byte[hmac.getMacSize()]; byte[] resBuf = new byte[hmac.getMacSize()];
hmac.init(new KeyParameter(authSek)); hmac.init(new KeyParameter(authSEK));
hmac.update(jsonBase64, 0, jsonBase64.length); hmac.update(jsonBase64, 0, jsonBase64.length);
hmac.doFinal(resBuf, 0); hmac.doFinal(resBuf, 0);
...@@ -1461,7 +1457,7 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi ...@@ -1461,7 +1457,7 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi
gstr1Data = gstr1RespObj.getString("data"); gstr1Data = gstr1RespObj.getString("data");
gstr1Rek = gstr1RespObj.getString("rek"); gstr1Rek = gstr1RespObj.getString("rek");
byte[] apiEKGstr1 = aesEncryption.decrypt(gstr1Rek, authSek); byte[] apiEKGstr1 = aesEncryption.decrypt(gstr1Rek, authSEK);
String gstr1RespJsoninBase64 = new String(aesEncryption.decrypt(gstr1Data, apiEKGstr1)); String gstr1RespJsoninBase64 = new String(aesEncryption.decrypt(gstr1Data, apiEKGstr1));
byte[] gstr1RespJsonInBytes = aesEncryption.decodeBase64StringTOByte(gstr1RespJsoninBase64); byte[] gstr1RespJsonInBytes = aesEncryption.decodeBase64StringTOByte(gstr1RespJsoninBase64);
...@@ -1528,7 +1524,7 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi ...@@ -1528,7 +1524,7 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi
retStatsData = retStatsRespObj.getString("data"); retStatsData = retStatsRespObj.getString("data");
retStatsRek = retStatsRespObj.getString("rek"); retStatsRek = retStatsRespObj.getString("rek");
byte[] apiEKRetstats = aesEncryption.decrypt(retStatsRek, authSek); byte[] apiEKRetstats = aesEncryption.decrypt(retStatsRek, authSEK);
String retStatsRespJsoninBase64 = new String(aesEncryption.decrypt(retStatsData, apiEKRetstats)); String retStatsRespJsoninBase64 = new String(aesEncryption.decrypt(retStatsData, apiEKRetstats));
...@@ -1707,7 +1703,7 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi ...@@ -1707,7 +1703,7 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi
{ {
gstCommonUtil.updateAPICallLogHistory(eachAPICallData, null); gstCommonUtil.updateAPICallLogHistory(eachAPICallData, null);
} }
} }*/
} }
} }
catch (Exception e) catch (Exception e)
...@@ -1718,7 +1714,7 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi ...@@ -1718,7 +1714,7 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi
} }
return retString; 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 retString = "";
String errMsg = "", gspAuthString = "", gspAuthSignature = ""; String errMsg = "", gspAuthString = "", gspAuthSignature = "";
...@@ -1801,7 +1797,7 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi ...@@ -1801,7 +1797,7 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi
responseId = transId; responseId = transId;
System.out.println("transId to getStatus after SUBMIT call["+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 = conn.prepareStatement(sql);
pstmt.setString(1, "S"); pstmt.setString(1, "S");
...@@ -1870,7 +1866,7 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi ...@@ -1870,7 +1866,7 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi
} }
return retString; 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 retString = "";
String errMsg = "", gspAuthString = "", gspAuthSignature = "", signType = "",signId = ""; String errMsg = "", gspAuthString = "", gspAuthSignature = "", signType = "",signId = "";
...@@ -1888,12 +1884,12 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi ...@@ -1888,12 +1884,12 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi
gspAuthSignature = gspSignature.sign(gspAuthString, aspPrivateKey); gspAuthSignature = gspSignature.sign(gspAuthString, aspPrivateKey);
byte[] jsonBase64 = Base64.getEncoder().encode(summaryData.toString().getBytes()); 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()); HMac hmac = new HMac(new SHA256Digest());
byte[] resBuf = new byte[hmac.getMacSize()]; byte[] resBuf = new byte[hmac.getMacSize()];
hmac.init(new KeyParameter(authSek)); hmac.init(new KeyParameter(authSEK));
hmac.update(jsonBase64, 0, jsonBase64.length); hmac.update(jsonBase64, 0, jsonBase64.length);
hmac.doFinal(resBuf, 0); hmac.doFinal(resBuf, 0);
...@@ -1949,7 +1945,7 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi ...@@ -1949,7 +1945,7 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi
String fileGstr1Data = fileGstr1RespObj.getString("data"); String fileGstr1Data = fileGstr1RespObj.getString("data");
String fileGstr1Rek = fileGstr1RespObj.getString("rek"); 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)); String fileGstr1JsoninBase64 = new String(aesEncryption.decrypt(fileGstr1Data, fileGstr1ApiEK));
...@@ -2004,7 +2000,7 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi ...@@ -2004,7 +2000,7 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi
return retString; 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 retString = "";
String errMsg = "", gspAuthString = "", gspAuthSignature = ""; String errMsg = "", gspAuthString = "", gspAuthSignature = "";
...@@ -2053,7 +2049,7 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi ...@@ -2053,7 +2049,7 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi
String gstr1Sumrydata = getGstr1SumryRespObj.getString("data"); String gstr1Sumrydata = getGstr1SumryRespObj.getString("data");
String gstr1Sumryrek = getGstr1SumryRespObj.getString("rek"); 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)); String respJsoninBase64 = new String(aesEncryption.decrypt(gstr1Sumrydata, apiEK));
...@@ -2068,12 +2064,12 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi ...@@ -2068,12 +2064,12 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi
String gspAuthStringFile = "", gspAuthSignatureFile = ""; String gspAuthStringFile = "", gspAuthSignatureFile = "";
byte[] jsonBase64 = Base64.getEncoder().encode(gstr1SumryJsonObj.toString().getBytes()); 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()); HMac hmac = new HMac(new SHA256Digest());
byte[] resBuf = new byte[hmac.getMacSize()]; byte[] resBuf = new byte[hmac.getMacSize()];
hmac.init(new KeyParameter(authSek)); hmac.init(new KeyParameter(authSEK));
hmac.update(jsonBase64, 0, jsonBase64.length); hmac.update(jsonBase64, 0, jsonBase64.length);
hmac.doFinal(resBuf, 0); hmac.doFinal(resBuf, 0);
...@@ -2118,7 +2114,7 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi ...@@ -2118,7 +2114,7 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi
String fileGstr1Data = fileGstr1RespObj.getString("data"); String fileGstr1Data = fileGstr1RespObj.getString("data");
String fileGstr1Rek = fileGstr1RespObj.getString("rek"); 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)); String fileGstr1JsoninBase64 = new String(aesEncryption.decrypt(fileGstr1Data, fileGstr1ApiEK));
...@@ -2207,7 +2203,7 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi ...@@ -2207,7 +2203,7 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi
} }
return retString; 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 retString = "";
String errMsg = "", gspAuthString = "", gspAuthSignature = ""; String errMsg = "", gspAuthString = "", gspAuthSignature = "";
...@@ -2331,7 +2327,7 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi ...@@ -2331,7 +2327,7 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi
} }
return retString; 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 retString = "", errMsg = "";
String gstr2Data = "", gstr2Rek = ""; String gstr2Data = "", gstr2Rek = "";
...@@ -3029,12 +3025,12 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi ...@@ -3029,12 +3025,12 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi
gstr2.cdnur = cdnurList; gstr2.cdnur = cdnurList;
} }
String gspAuthString = "", gspAuthSignature = "", gspAuthStringRet = "", gspAuthSignatureRet = ""; /*String gspAuthString = "", gspAuthSignature = "", gspAuthStringRet = "", gspAuthSignatureRet = "";
APICallData apiRetStatsCallData = null; APICallData apiRetStatsCallData = null;
List<APICallData> retStatAPICallList = new ArrayList<APICallData>(); List<APICallData> retStatAPICallList = new ArrayList<APICallData>();
loginCode = e12GenericUtility.getValueFromXTRA_PARAMS(xtraParams, "loginCode"); loginCode = e12GenericUtility.getValueFromXTRA_PARAMS(xtraParams, "loginCode");
chgTerm = e12GenericUtility.getValueFromXTRA_PARAMS(xtraParams, "chgTerm"); chgTerm = e12GenericUtility.getValueFromXTRA_PARAMS(xtraParams, "chgTerm");*/
ObjectMapper objectMapper = new ObjectMapper(); ObjectMapper objectMapper = new ObjectMapper();
...@@ -3042,13 +3038,15 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi ...@@ -3042,13 +3038,15 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi
System.out.println("jsonPayload to SAVE GSTR2["+json+"]"); System.out.println("jsonPayload to SAVE GSTR2["+json+"]");
byte[] jsonBase64 = Base64.getEncoder().encode(json.getBytes()); retString = saveGSTRData(json, noOfRecords, tranIdList, "2", conn, xtraParams);
String encryptedPayload = aesEncryption.encryptEK(jsonBase64, authSek);
/*byte[] jsonBase64 = Base64.getEncoder().encode(json.getBytes());
String encryptedPayload = aesEncryption.encryptEK(jsonBase64, authSEK);
HMac hmac = new HMac(new SHA256Digest()); HMac hmac = new HMac(new SHA256Digest());
byte[] resBuf = new byte[hmac.getMacSize()]; byte[] resBuf = new byte[hmac.getMacSize()];
hmac.init(new KeyParameter(authSek)); hmac.init(new KeyParameter(authSEK));
hmac.update(jsonBase64, 0, jsonBase64.length); hmac.update(jsonBase64, 0, jsonBase64.length);
hmac.doFinal(resBuf, 0); hmac.doFinal(resBuf, 0);
...@@ -3098,7 +3096,7 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi ...@@ -3098,7 +3096,7 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi
gstr2Data = gstr2RespObj.getString("data"); gstr2Data = gstr2RespObj.getString("data");
gstr2Rek = gstr2RespObj.getString("rek"); gstr2Rek = gstr2RespObj.getString("rek");
byte[] apiEKGstr2 = aesEncryption.decrypt(gstr2Rek, authSek); byte[] apiEKGstr2 = aesEncryption.decrypt(gstr2Rek, authSEK);
String gstr2RespJsoninBase64 = new String(aesEncryption.decrypt(gstr2Data, apiEKGstr2)); String gstr2RespJsoninBase64 = new String(aesEncryption.decrypt(gstr2Data, apiEKGstr2));
byte[] gstr2RespJsonInBytes = aesEncryption.decodeBase64StringTOByte(gstr2RespJsoninBase64); byte[] gstr2RespJsonInBytes = aesEncryption.decodeBase64StringTOByte(gstr2RespJsoninBase64);
...@@ -3153,7 +3151,7 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi ...@@ -3153,7 +3151,7 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi
retStatsData = retStatsRespObj.getString("data"); retStatsData = retStatsRespObj.getString("data");
retStatsRek = retStatsRespObj.getString("rek"); retStatsRek = retStatsRespObj.getString("rek");
byte[] apiEKRetstats = aesEncryption.decrypt(retStatsRek, authSek); byte[] apiEKRetstats = aesEncryption.decrypt(retStatsRek, authSEK);
String retStatsRespJsoninBase64 = new String(aesEncryption.decrypt(retStatsData, apiEKRetstats)); String retStatsRespJsoninBase64 = new String(aesEncryption.decrypt(retStatsData, apiEKRetstats));
...@@ -3324,7 +3322,7 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi ...@@ -3324,7 +3322,7 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi
{ {
gstCommonUtil.updateAPICallLogHistory(eachAPICallData, null); gstCommonUtil.updateAPICallLogHistory(eachAPICallData, null);
} }
} }*/
} }
} }
catch(Exception e) catch(Exception e)
...@@ -3335,7 +3333,7 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi ...@@ -3335,7 +3333,7 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi
} }
return retString; 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 retString = "";
String errMsg = "", gspAuthString = "", gspAuthSignature = ""; String errMsg = "", gspAuthString = "", gspAuthSignature = "";
...@@ -3488,7 +3486,7 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi ...@@ -3488,7 +3486,7 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi
} }
return retString; 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 retString = "";
String errMsg = "", gspAuthString = "", gspAuthSignature = "", signType = "",signId = ""; String errMsg = "", gspAuthString = "", gspAuthSignature = "", signType = "",signId = "";
...@@ -3506,12 +3504,12 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi ...@@ -3506,12 +3504,12 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi
gspAuthSignature = gspSignature.sign(gspAuthString, aspPrivateKey); gspAuthSignature = gspSignature.sign(gspAuthString, aspPrivateKey);
byte[] jsonBase64 = Base64.getEncoder().encode(summaryData.toString().getBytes()); 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()); HMac hmac = new HMac(new SHA256Digest());
byte[] resBuf = new byte[hmac.getMacSize()]; byte[] resBuf = new byte[hmac.getMacSize()];
hmac.init(new KeyParameter(authSek)); hmac.init(new KeyParameter(authSEK));
hmac.update(jsonBase64, 0, jsonBase64.length); hmac.update(jsonBase64, 0, jsonBase64.length);
hmac.doFinal(resBuf, 0); hmac.doFinal(resBuf, 0);
...@@ -3567,7 +3565,7 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi ...@@ -3567,7 +3565,7 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi
String fileGstr2Data = fileGstr2RespObj.getString("data"); String fileGstr2Data = fileGstr2RespObj.getString("data");
String fileGstr2Rek = fileGstr2RespObj.getString("rek"); 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)); String fileGstr2JsoninBase64 = new String(aesEncryption.decrypt(fileGstr2Data, fileGstr2ApiEK));
...@@ -3620,7 +3618,7 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi ...@@ -3620,7 +3618,7 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi
return retString; 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 = ""; String retString = "";
GSTR3B gstr3b = null; GSTR3B gstr3b = null;
...@@ -3630,12 +3628,8 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi ...@@ -3630,12 +3628,8 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi
List<ITCData> itcInelgDataList = new ArrayList<ITCData>(); List<ITCData> itcInelgDataList = new ArrayList<ITCData>();
List<InwardSuppliesDetails> inwardSuppliesList = new ArrayList<InwardSuppliesDetails>(); List<InwardSuppliesDetails> inwardSuppliesList = new ArrayList<InwardSuppliesDetails>();
String transactionId = UUID.randomUUID().toString().replaceAll("-", ""); int noOfRecords = 0;
String gspAuthString = "", gspAuthSignature = "", callStatus = "", gstr3bData = "", gstr3bRek = "", responseId = "", gspAuthStringRet = "", ArrayList<String> tranIdList = new ArrayList<String>();
gspAuthSignatureRet = "", retStatsData = "", retStatsRek = "", retStatusCallStatus = "", retStatusResponseJsonStr = "", errMsg = "",
responseJsonStr = "", loginCode = "", chgTerm = "";
APICallData apiRetStatsCallData = null;
ArrayList<APICallData> retStatAPICallList = new ArrayList<APICallData>();
try try
{ {
...@@ -3787,428 +3781,159 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi ...@@ -3787,428 +3781,159 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi
System.out.println("jsonPaylaod to save GSTR3B ["+json+"]"); 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"); loginCode = e12GenericUtility.getValueFromXTRA_PARAMS(xtraParams, "loginCode");
chgTerm = e12GenericUtility.getValueFromXTRA_PARAMS(xtraParams, "chgTerm"); chgTerm = e12GenericUtility.getValueFromXTRA_PARAMS(xtraParams, "chgTerm");
String json = "{\"gstin\":\""+gstin+"\",\"ret_period\":\""+periodCode+"\"}";
byte[] jsonBase64 = Base64.getEncoder().encode(json.getBytes()); byte[] jsonBase64 = Base64.getEncoder().encode(json.getBytes());
String encryptedPayload = aesEncryption.encryptEK(jsonBase64, authSek); String encryptedPayload = aesEncryption.encryptEK(jsonBase64, authSEK);
HMac hmac = new HMac(new SHA256Digest()); HMac hmac = new HMac(new SHA256Digest());
byte[] resBuf = new byte[hmac.getMacSize()]; byte[] resBuf = new byte[hmac.getMacSize()];
hmac.init(new KeyParameter(authSek)); hmac.init(new KeyParameter(authSEK));
hmac.update(jsonBase64, 0, jsonBase64.length); hmac.update(jsonBase64, 0, jsonBase64.length);
hmac.doFinal(resBuf, 0); hmac.doFinal(resBuf, 0);
JSONObject gstr3bHeaderObj = new JSONObject(); JSONObject reqBody = new JSONObject();
gstr3bHeaderObj.put("action", "RETSAVE"); reqBody.put("action", "RETSUBMIT");
gstr3bHeaderObj.put("data", encryptedPayload); reqBody.put("data", encryptedPayload);
gstr3bHeaderObj.put("hmac", new String(Base64.getEncoder().encode(resBuf))); reqBody.put("hmac", new String(Base64.getEncoder().encode(resBuf)));
long timeStamp = new Timestamp().getDateTime(); long timeStamp = new Timestamp().getDateTime();
gspAuthString = clientId + ":" + transactionId + ":" + timeStamp + ":" + gstin; gspAuthString = clientId + ":" + transactionId + ":" + timeStamp + ":" + gstin;
gspAuthSignature = gspSignature.sign(gspAuthString, aspPrivateKey); gspAuthSignature = gspSignature.sign(gspAuthString, aspPrivateKey);
HttpRequest saveGstr3bReq = Unirest.post(String.format("%s%s", GSP_API_URL, GSTR3B_URL_V3)) HttpRequest gstr3bSubmitReq = Unirest.post(String.format("%s%s", GSP_API_URL, GSTR3B_URL_V3))
.header("Content-Type", APPLICATION_JSON) .header("Content-Type", APPLICATION_JSON)
.header("action", "RETSUBMIT")
.header("state-cd", stateCode)
.header("clientid", clientId) .header("clientid", clientId)
.header("client-secret", clientSecret) .header("client-secret", clientSecret)
.header("txn",transactionId) .header("ip-usr", ipAddress)
.header("state-cd", stateCode)
.header("auth-token", authToken)
.header("gstin", gstin)
.header("username", userName) .header("username", userName)
.header("auth-token", authToken)
.header("txn", transactionId)
.header("ret_period", periodCode) .header("ret_period", periodCode)
.header("ip-usr", ipAddress) .header("gstin", gstin)
.header("X-Asp-Auth-Token", gspAuthString) .header("X-Asp-Auth-Token", gspAuthString)
.header("X-Asp-Auth-Signature", gspAuthSignature) .header("X-Asp-Auth-Signature", gspAuthSignature)
.body(new JsonNode(gstr3bHeaderObj.toString())) .body(new JsonNode(reqBody.toString()))
.getHttpRequest(); .getHttpRequest();
System.out.println("SAVE GSTR3B url["+saveGstr3bReq.getUrl()+"]"); System.out.println("RETSUBMIT GSTR3B url["+gstr3bSubmitReq.getUrl()+"]");
System.out.println("SAVE GSTR3B method["+saveGstr3bReq.getHttpMethod()+"]"); System.out.println("RETSUBMIT GSTR3B method["+gstr3bSubmitReq.getHttpMethod()+"]");
System.out.println("SAVE GSTR3B request header["+saveGstr3bReq.getHeaders()+"]"); System.out.println("RETSUBMIT GSTR3B request header["+gstr3bSubmitReq.getHeaders()+"]");
System.out.println("SAVE GSTR3B request payload["+IOUtils.toString(saveGstr3bReq.getBody().getEntity().getContent())+"]"); System.out.println("RETSUBMIT GSTR3B request payload["+IOUtils.toString(gstr3bSubmitReq.getBody().getEntity().getContent())+"]");
HttpResponse<JsonNode> gstr3bResp = saveGstr3bReq.asJson(); HttpResponse<JsonNode> gstr3bSubmitResp = gstr3bSubmitReq.asJson();
System.out.println(String.format("gstr3bResp Request : Status[%s] Response[%s]", gstr3bResp.getStatus(), gstr3bResp.getBody())); System.out.println(String.format("gstr3bSubmitResp Request : Status[%s] Response[%s]", gstr3bSubmitResp.getStatus(), gstr3bSubmitResp.getBody()));
if (gstr3bResp.getStatus() == 200) if (gstr3bSubmitResp.getStatus() == 200)
{ {
JSONObject gstr3bRespObj = gstr3bResp.getBody().getObject(); JSONObject gstr3bSubmitRespObj = gstr3bSubmitResp.getBody().getObject();
if(gstr3bSubmitRespObj.has("data") && gstr3bSubmitRespObj.has("rek"))
if(gstr3bRespObj.has("data") && gstr3bRespObj.has("rek"))
{ {
callStatus = "1"; callStatus = "1";
gstr3bData = gstr3bRespObj.getString("data"); String gstr3bSubmitdata = gstr3bSubmitRespObj.getString("data");
gstr3bRek = gstr3bRespObj.getString("rek"); String gstr3bSubmitrek = gstr3bSubmitRespObj.getString("rek");
byte[] apiEKGstr3b = aesEncryption.decrypt(gstr3bRek, authSek);
String gstr3bRespJsoninBase64 = new String(aesEncryption.decrypt(gstr3bData, apiEKGstr3b));
byte[] gstr3bRespJsonInBytes = aesEncryption.decodeBase64StringTOByte(gstr3bRespJsoninBase64); byte[] apiEK = aesEncryption.decrypt(gstr3bSubmitrek, authSEK);
String respJsoninBase64 = new String(aesEncryption.decrypt(gstr3bSubmitdata, apiEK));
JSONObject gstr3bTransIdRespObj = new JSONObject(new String(gstr3bRespJsonInBytes)); byte[] respJsonInBytes = aesEncryption.decodeBase64StringTOByte(respJsoninBase64);
String transId = gstr3bTransIdRespObj.getString("reference_id");
JSONObject gstr3bSubmitObj = new JSONObject(new String(respJsonInBytes));
String transId = gstr3bSubmitObj.getString("reference_id");
responseId = transId; responseId = transId;
System.out.println("transId to getStatus after SUBMIT call["+transId+"]");
System.out.println("transId to getStatus["+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'";
boolean isRetStatusError = false; pstmt = conn.prepareStatement(sql);
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");
byte[] apiEKRetstats = aesEncryption.decrypt(retStatsRek, authSek);
String retStatsRespJsoninBase64 = new String(aesEncryption.decrypt(retStatsData, apiEKRetstats));
byte[] retStatsRespJsonInBytes = aesEncryption.decodeBase64StringTOByte(retStatsRespJsoninBase64); 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);
JSONObject retStatsJsonData = new JSONObject(new String(retStatsRespJsonInBytes)); updateCnt = pstmt.executeUpdate();
System.out.println( "retStatsJsonData["+retStatsJsonData+"]");
if("IP".equalsIgnoreCase((String)retStatsJsonData.get("status_cd"))) if(pstmt!=null)
{
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"); pstmt.close();
} pstmt = null;
} }
retStatusResponseJsonStr = errMsg; System.out.println("submit status updated of ["+siteCode+"] for ["+periodCode+"] update count ["+updateCnt+"]");*/
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 else
{ {
retStatusCallStatus = "2"; callStatus = "2";
JSONObject errorJSON = retStatusResp.getBody().getObject().getJSONObject("error"); JSONObject errorJSON = gstr3bSubmitResp.getBody().getObject().getJSONObject("error");
retStatusResponseJsonStr = errorJSON.toString(); responseJsonStr = errorJSON.toString();
errMsg = "Message : "+errorJSON.getString("message")+" \nError code : "+errorJSON.getString("error_cd"); errMsg = "Message : "+errorJSON.getString("message")+" \nError code : "+errorJSON.getString("error_cd");
retString = getError(errMsg, "GSTAPIERR", conn); retString = getError(errMsg, "GSTAPIERR", conn);
isRetStatusError = true;
} }
} }
else if(retStatusResp.getStatus() == 500) else if(gstr3bSubmitResp.getStatus() == 500)
{ {
retStatusCallStatus = "2"; callStatus = "2";
errMsg = "Message : Error occurred at GSTN server \nResponse code : "+retStatusResp.getStatus(); errMsg = "Message : Error occurred at GSTN server \nResponse code : "+gstr3bSubmitResp.getStatus();
retStatusResponseJsonStr = errMsg; responseJsonStr = errMsg;
retString = getError(errMsg, "GSTAPIERR", conn); retString = getError(errMsg, "GSTAPIERR", conn);
isRetStatusError = true;
} }
else else
{ {
retStatusCallStatus = "2"; callStatus = "2";
JSONObject errorJSON = retStatusResp.getBody().getObject().getJSONObject("error"); JSONObject errorJSON = gstr3bSubmitResp.getBody().getObject().getJSONObject("error");
retStatusResponseJsonStr = errorJSON.toString(); responseJsonStr = errorJSON.toString();
errMsg = "Message : "+errorJSON.getString("message")+" \nError code : "+errorJSON.getString("error_cd"); errMsg = "Message : "+errorJSON.getString("message")+" \nError code : "+errorJSON.getString("error_cd");
retString = getError(errMsg, "GSTAPIERR", conn); retString = getError(errMsg, "GSTAPIERR", conn);
isRetStatusError = true;
} }
apiRetStatsCallData = new APICallData(); APICallData apiCallData = new APICallData();
apiRetStatsCallData.setPeriodCode(periodCode); apiCallData.setPeriodCode(periodCode);
apiRetStatsCallData.setCallDate(new Date()); apiCallData.setCallDate(new Date());
apiRetStatsCallData.setSiteCode(siteCode); apiCallData.setSiteCode(siteCode);
apiRetStatsCallData.setUserId(loginCode); apiCallData.setUserId(loginCode);
apiRetStatsCallData.setCallType("RETSTATUS"); apiCallData.setCallType("RETSUBMIT");
apiRetStatsCallData.setRecType("3"); apiCallData.setRecType("3");
apiRetStatsCallData.setNoOfRecords(0); apiCallData.setNoOfRecords(0);
apiRetStatsCallData.setCallStatus(retStatusCallStatus); apiCallData.setCallStatus(callStatus);
apiRetStatsCallData.setResponseId(""); apiCallData.setResponseId(responseId);
apiRetStatsCallData.setResponseJsonStr(retStatusResponseJsonStr); apiCallData.setResponseJsonStr(responseJsonStr);
apiRetStatsCallData.setChgUser(loginCode); apiCallData.setChgUser(loginCode);
apiRetStatsCallData.setChgDate(new Date()); apiCallData.setChgDate(new Date());
apiRetStatsCallData.setChgTerm(chgTerm); apiCallData.setChgTerm(chgTerm);
retStatAPICallList.add(apiRetStatsCallData);
if(isRetStatusError)
{
break;
}
else
{
continue;
}
}
}
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);
}
}
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);
}
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);
}
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);
}
}
}
catch(Exception e)
{
System.out.println("GSTDataSubmitWizPos.saveGstr3b()["+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
{
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");
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); gstCommonUtil.updateAPICallLogHistory(apiCallData, null);
} }
...@@ -4220,7 +3945,7 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi ...@@ -4220,7 +3945,7 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi
} }
return retString; 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 private String fileGstr3b(String summaryData, String signedData, String panNo, String aadhaarNo, String signMethod, String xtraParams, Connection conn) throws ITMException
{ {
String retString = ""; String retString = "";
String errMsg = "", gspAuthString = "", gspAuthSignature = "", signType = "",signId = ""; String errMsg = "", gspAuthString = "", gspAuthSignature = "", signType = "",signId = "";
...@@ -4238,12 +3963,12 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi ...@@ -4238,12 +3963,12 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi
gspAuthSignature = gspSignature.sign(gspAuthString, aspPrivateKey); gspAuthSignature = gspSignature.sign(gspAuthString, aspPrivateKey);
byte[] jsonBase64 = Base64.getEncoder().encode(summaryData.toString().getBytes()); 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()); HMac hmac = new HMac(new SHA256Digest());
byte[] resBuf = new byte[hmac.getMacSize()]; byte[] resBuf = new byte[hmac.getMacSize()];
hmac.init(new KeyParameter(authSek)); hmac.init(new KeyParameter(authSEK));
hmac.update(jsonBase64, 0, jsonBase64.length); hmac.update(jsonBase64, 0, jsonBase64.length);
hmac.doFinal(resBuf, 0); hmac.doFinal(resBuf, 0);
...@@ -4299,7 +4024,7 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi ...@@ -4299,7 +4024,7 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi
String fileGstr3bData = fileGstr3bRespObj.getString("data"); String fileGstr3bData = fileGstr3bRespObj.getString("data");
String fileGstr3bRek = fileGstr3bRespObj.getString("rek"); String fileGstr3bRek = fileGstr3bRespObj.getString("rek");
byte[] fileGstr3bApiEK = aesEncryption.decrypt(fileGstr3bRek, authSek); byte[] fileGstr3bApiEK = aesEncryption.decrypt(fileGstr3bRek, authSEK);
String fileGstr3bJsoninBase64 = new String(aesEncryption.decrypt(fileGstr3bData, fileGstr3bApiEK)); String fileGstr3bJsoninBase64 = new String(aesEncryption.decrypt(fileGstr3bData, fileGstr3bApiEK));
...@@ -5760,7 +5485,358 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi ...@@ -5760,7 +5485,358 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi
return intraNilSupplies; 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))
{
RETURN_URL = GSTR1_URL_V3;
}
else if("2".equalsIgnoreCase(recType))
{
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;
}
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)
{
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.saveGSTRData()["+e.getMessage()+"]");
e.printStackTrace();
throw new ITMException(e);
}
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 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; 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