Skip to content

Commit

Permalink
Support Digilocker in SDK (#40)
Browse files Browse the repository at this point in the history
* Support Digilocker in SDK

* Change typo

* Use version 1 of the digilocker

* Add gateway option support in digilocker
  • Loading branch information
iAziz786 authored Feb 1, 2022
1 parent 2387e3b commit 0468650
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
31 changes: 28 additions & 3 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const gatewayModes = Object.freeze({
itdProdURL: "https://itd.zoop.one",
itdStagingURL: "https://itd-staging.zoop.one",
eSignV4URL: "https://esign.zoop.one",
digilockerV1URL: "https://gateway.zoop.one/digilocker/v1",
url: "https://prod.aadhaarapi.com",
zoopModel: window.document.getElementById("zoop-gateway-model"),
zoopWindow: null
Expand Down Expand Up @@ -79,6 +80,10 @@ const gatewayModes = Object.freeze({
sdk_version: "2",
logo_url: ""
},
digilockerGatewayOption: {
request_id: "",
gatewayURL: options.digilockerV1URL
}
};

zoop.check = function (json, paramCheck) {
Expand Down Expand Up @@ -348,6 +353,21 @@ const gatewayModes = Object.freeze({
zoop.options.zoopModel.style.display = "block";
};

zoop.initDigilockerGateway = function initDigilockerGateway(gatewayOption = {}) {
zoop.digilockerGatewayOption.gatewayURL += "/start"
};

zoop.openDigilockerGateway = function openDigilockerGateway(request_id) {
zoop.digilockerGatewayOption.request_id = request_id;

const url = `${zoop.digilockerGatewayOption.gatewayURL}/${zoop.digilockerGatewayOption.request_id}`;
if (zoop.options.zoopWindow == null || zoop.options.zoopWindow.closed) {
zoop.options.zoopWindow = window.open(encodeURI(url), "_blank")
} else {
zoop.options.zoopWindow.focus()
}
};

const supportedEvents = {
close: () => { },
"consent-denied": () => { },
Expand All @@ -359,7 +379,9 @@ const gatewayModes = Object.freeze({
"itd-error": () => { },
"itd-consent-denied": () => { },
"itd-gateway-terminated": () => { },
"itd-success": () => { }
"itd-success": () => { },
"digilocker-error": () => { },
"digilocker-success": () => { }
};
zoop.on = function on(eventName = "", callback = () => { }) {
if (typeof eventName !== "string") {
Expand Down Expand Up @@ -387,9 +409,10 @@ const gatewayModes = Object.freeze({
zoop.options.bsaURL,
zoop.options.itdURL,
zoop.options.eSignV4URL,
zoop.options.digilockerV1URL,
];
let message;
if (!URLs.includes(event.origin)) {
if (!URLs.some(url => url.startsWith(event.origin))) {
return console.log("Message is not from Zoop Gateway");
}
if (event.data) {
Expand All @@ -410,13 +433,15 @@ const gatewayModes = Object.freeze({
case "itd-consent-denied":
case "itd-gateway-terminated":
case "itd-success":
case "digilocker-error":
case "digilocker-success":
message.payload =
typeof message.payload === "string"
? JSON.parse(message.payload)
: message.payload;
zoop.options.zoopModel.style.display = "none";
window.document.getElementById("zoop-model-content").innerHTML = "";
// For tab based communication i.e., eSign we are using window.open
// For tab based communication i.e., eSign, digilocker we are using window.open
// which returns an window object to communication with postMessage()
// calls.
if (zoop.options.zoopWindow && !zoop.options.zoopWindow.closed) {
Expand Down
Loading

0 comments on commit 0468650

Please sign in to comment.