Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added esign validation using kafka events #383

Merged
merged 5 commits into from
Aug 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion backend/donor-service/configs/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,17 @@ const NOTIFY_TEMPLATE_ID = process.env.NOTIFY_TEMPLATE_ID;
const UPDATE_TEMPLATE_ID = process.env.UPDATE_TEMPLATE_ID;
const UNPLEDGE_TEMPLATE_ID = process.env.UNPLEDGE_TEMPLATE_ID;
const API_KEY = process.env.API_KEY;
const ESIGN_STATUS = Object.freeze({
'PENDING': 0,
'SUCCESS': 1,
'FAILED': 2,
'EXPIRED': 3,
});
const ESIGN_VALIDATION_KAFKA_BROKERS = process.env.ESIGN_VALIDATION_KAFKA_BROKERS || 'localhost:5101';
const ESIGN_VALIDATION_EXPIRE_TIME = process.env.ESIGN_VALIDATION_EXPIRE_TIME || 2*60;
const ESIGN_VALIDATION_PREVENT_3RD_PARTY = process.env.ESIGN_VALIDATION_PREVENT_3RD_PARTY === "true" || false;
const ESIGN_VALIDATION_KAFKA_TOPIC = process.env.ESIGN_VALIDATION_TOPIC || 'esign_topic';
const ESIGN_VALIDATION_KAFKA_TOPIC_GROUP = process.env.ESIGN_VALIDATION_TOPIC || 'notto_esign_group_1';
module.exports = {
REDIS_URL,
BASE_URL,
Expand All @@ -48,5 +59,11 @@ module.exports = {
ABHA_CLIENT_URL,
UPDATE_TEMPLATE_ID,
UNPLEDGE_TEMPLATE_ID,
API_KEY
API_KEY,
ESIGN_VALIDATION_KAFKA_BROKERS,
ESIGN_VALIDATION_EXPIRE_TIME,
ESIGN_STATUS,
ESIGN_VALIDATION_PREVENT_3RD_PARTY,
ESIGN_VALIDATION_KAFKA_TOPIC,
ESIGN_VALIDATION_KAFKA_TOPIC_GROUP,
}
84 changes: 72 additions & 12 deletions backend/donor-service/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,18 @@ const {isABHARegistered, getKeyBasedOnEntityName, getPledgeStatus} = require("./
const {PLEDGE_STATUS, GENDER_MAP, SOCIAL_SHARE_TEMPLATE_MAP} = require('./configs/constants')
const app = express();
const {convertToSocialShareResponse} = require("./utils/utils");
const consumer = require("./services/esign.consumer");

(async() => {
await redis.initRedis({REDIS_URL: config.REDIS_URL})
await redis.initRedis({REDIS_URL: config.REDIS_URL});
if (config.ESIGN_VALIDATION_PREVENT_3RD_PARTY) {
await consumer.initSubscription();
}
})();

const {getEsignVerificationKey} = require("./services/esign.consumer");
const swaggerDocs = yaml.load('./abha-swagger.yaml');
app.use(bodyParser.urlencoded({extended: false, limit: '500kb'}));
app.use((bodyParser.json({limit: '500kb'})));

app.use('/api-docs', swagger.serve, swagger.setup(swaggerDocs));

if (config.LOG_LEVEL === "DEBUG") {
Expand Down Expand Up @@ -347,6 +350,20 @@ app.post('/esign/init', async (req, res) => {
// const pledge = JSON.parse(req.query.data)
const pledge = req.body.data;
const esignData = await getEsignData(pledge);
if (config.ESIGN_VALIDATION_PREVENT_3RD_PARTY) {
const verificationData = {
"firstName": R.pathOr("", ["personalDetails", "firstName"], pledge),
"middleName": R.pathOr("", ["personalDetails", "middleName"], pledge),
"lastName": R.pathOr("", ["personalDetails", "lastName"], pledge),
"dob": R.pathOr("", ["personalDetails", "dob"], pledge),
"pincode": R.pathOr("", ["addressDetails", "pincode"], pledge),
"esignStatus": config.ESIGN_STATUS.PENDING.toString()
};
for(const[key, value] of Object.entries(verificationData)) {
console.log(key, value)
await redis.storeHashWithExpiry(getEsignVerificationKey(esignData.txnId), key, value, config.ESIGN_VALIDATION_EXPIRE_TIME)
}
}
res.send({
signUrl: esignData.espUrl,
xmlContent: esignData.xmlContent,
Expand Down Expand Up @@ -544,19 +561,62 @@ async function getESingDoc(abha) {
}

app.get('/esign/:abha/status', async (req, res) => {
console.log("Get status api called")
try {
await getESingDoc(req.params.abha)
.then(function (response) {
res.send({message: "SUCCESS"})
if (config.ESIGN_VALIDATION_PREVENT_3RD_PARTY) {
const transactionID = await redis.getKey(getEsginKey(req.params.abha))
const storedTransaction = await redis.getHash(getEsignVerificationKey(transactionID));
if(!storedTransaction || storedTransaction?.esignStatus === config.ESIGN_STATUS.PENDING.toString()) {
res.status(404).send({
preventThirdParty: true,
code: config.ESIGN_STATUS.PENDING.toString(),
message: !!storedTransaction ? "PENDING" : "NOT FOUND",
})
return
}
if(storedTransaction?.esignStatus === config.ESIGN_STATUS.FAILED.toString()) {
res.status(403).send({
preventThirdParty: true,
code: config.ESIGN_STATUS.FAILED.toString(),
message: "FAILED",
errors: JSON.parse(storedTransaction?.esignErrors)
})
return
}
else if(storedTransaction?.esignStatus === config.ESIGN_STATUS.SUCCESS.toString()){
res.status(200).send({
code: config.ESIGN_STATUS.SUCCESS.toString(),
message: "SUCCESS"
})
return
}
res.status(404).send({
preventThirdParty: true,
code: config.ESIGN_STATUS.EXPIRED.toString(),
message: "EXPIRED OR NOT GENERATED"
})
.catch(function (error) {
console.error(error)
res.status(404).send({message: "NOT GENERATED"})
});
} else {
await getESingDoc(req.params.abha)
.then(function (response) {
res.send({
code: config.ESIGN_STATUS.SUCCESS.toString(),
message: "SUCCESS"
})
})
.catch(function (error) {
console.error(error)
res.status(404).send({
preventThirdParty: false,
code: config.ESIGN_STATUS.EXPIRED.toString(),
message: "NOT GENERATED"
})
});
}
} catch (e) {
// console.error(e)
res.status(404).send({message: "NOT GENERATED"})
res.status(404).send({
code: config.ESIGN_STATUS.EXPIRED.toString(),
message: "EXPIRED OR NOT GENERATED"
})
}
});

Expand Down
Loading