Let there be three windows.
GrandParent->parent->child.
GrandParent opens parent and parent opens child.
In our case child closes automatically and returns to parent. but when parent is closed it doesn't return to GrandParent instead it goes to another tab.
I already tried the solution of creating a function in grandparent and calling it in parent. But it doesn't work.
// GrandParent
window.open(url) // url to open payment gateway in popup
// add function in grandParent to focus on parent window when popup closes
window.receiveDataFromPopup = function(data) { console.log(data) };
// Now grandparent opens parent
// parent opens another popup(child) for OTP and closes after verification
// Now we are at parent
// call grandparent function to focus on it
window.opener.receiveDataFromPopup('hola');
//close parent popup
window.close()