Log in with PayPal: Closing the login window to return to main site - paypal

I have successfully integrated PayPal Identify/Login but the issue is, the site (my return URL) opens up in the PayPal popup dialogue where the client logged in.
I want the login window to close and then have the main calling window go to the return URL, so the user continues on the main screen.
I can't find any details on how to do this on the PayPal Developer Docs. Is there an option in the button render that I am missing?
Current code:
paypal.use( ['login'], function (login) {
login.render ({
"appid":"My_API_ID",
"authend":"sandbox",
"scopes":"openid profile email address",
"containerid":"paypalLogin",
"responseType":"code",
"locale":"en-us",
"buttonType":"LWP",
"buttonShape":"pill",
"buttonSize":"lg",
"fullPage":"false",
"returnurl":"http://mysite/php/paypal/paypal_api_login.php"
});
});

The redirect back happens in the window. Add JS code there to save the URL info or redirect the opening window (set window.opener.location.href) and window.close() if desired.
Not tested but should be as simple as:
<script type="text/javascript">
if(window.opener) {
window.opener.location.href = window.location.href;
window.close()
}
</script>
or maybe better to also add and check for an additional parameter
<script type="text/javascript">
const REDIRECT_PARAM = '&redirected_opener=true';
if(window.opener && !window.location.href.includes(REDIRECT_PARAM)) {
window.opener.location.href = window.location.href + REDIRECT_PARAM;
window.close()
}
</script>

Related

Run Javascript Once Per Session

Having a struggle, I have created a Modal Popup for a mail signup however it has become annoying showing everytime on a page load so I am wanting to just show this once per session and no matter how I adjust the script I cannot get this to happen. Please can anyone help?
The code is as follows for the popup:
<script type="text/javascript">
window.onload = function() {
OpenBootstrapPopup();
};
function OpenBootstrapPopup() {
$("#simpleModal").modal('show');
}
</script>
<script>
$('#simpleModal').on('click', 'button.close', function(eventObject) {
$('#simpleModal').modal('hide');
});
</script>
I just want the modal popup to show once per session

connect to quickbooks, refresh app

In my app I have the 'Connect To QuickBooks' button that works as it should. When it is clicked it opens a window that allows the user to sigh in to their company. My problem is that I need to refresh my app to show the new information (Company name, etc), but I have not been able to find a way to refresh my app from the OauthHandler.aspx, that is opened in another browser window, by the 'Connect To QuickBooks' call. I must not be understanding something, can anybody help.
Thanks
Use the following in OauthHandler.aspx-
My refreshed page is default.aspx. Please set the page you want for your application.
<script type="text/javascript">
try {
var parentlocation = window.parent.opener.location.hostname;
var currentlocation = window.location.hostname;
if (parentlocation != currentlocation) {
window.location = "/default.aspx";
}
else {
window.opener.location.href = window.opener.location.href;
window.close();
}
}
catch (e) {
window.location = "/default.aspx";
}
</script>

How to cancel redirection of page with click?

I have a redirection code (working fine) in several pages as follow :
<meta http-equiv="refresh" content ="42; url=http://my url.html#">
But i want the automatic redirection to be cancelled or delayed if the user clicks in any point of the page.
What code should i use ?
Thanks
Here is the code for click on page anywhere:
<script>
$('html').click(function () {
alert("ok"); // Do whatever you want here, just replace. Since i dont know your code. So i can help you till this point.
});
</script>
Remove you <meta http-equiv="refresh"> from Documents <head></head>
Insert a simple JS-Timer and use window.location to refer the User after the Page loaded.
var timeVar = setInterval(function () {myTimer()}, 1000);
var t = 9;
function myTimer() {
if (t>0) {
document.getElementById("timer").innerHTML = t;
t--;
}
else { window.location = 'what/ever/you/are/workingon.html'; }
}
function StopFunction() { clearInterval(timeVar); }
<p>Redirecting in <span id="timer" style="font-weight: bold;">10</span>Seconds.</p>
<p onclick="StopFunction();" style="cursor: pointer; ">Cancel!</p>
The User will load your page and when not canceling the Timer be redirected to the Page you defined. If stopping the Timer the user wont be redirected and stay on the Page. br
Try just to empty cache, it should work.

Facebook Logout issue

I'm using the following code to logout from Facebook.
string url = string.Format("https://m.facebook.com/logout.php?confirm=1&next={0}&access_token={1}",
ConfigurationManager.AppSettings["Facebooklogout"],
token)
Note :
ConfigurationManager.AppSettings["Facebooklogout"]="http://localhost:56481/MenUs.Web/REGISTRATION/userinterestgroups.aspx"
But instead of logging out, it's directing me to my Facebook profile page.
Please provide me a solution
There is m.facebook.com bug that says next is being ignored. You could always use https://www.facebook.com/logout instead.
Also your logout URL has to be in the domain of the app you registered on Facebook, localhost will not work.
string url = string.Format("https://www.facebook.com/logout?confirm=1&next={0}&access_token={1}",
ConfigurationManager.AppSettings["Facebooklogout"],
token)
Please take note above, the logout URL must be in the same domain as the app. So the above would not redirect to localhost:xxx
I have resolved the above issue long ago by using the following javascript on click of "Save Button".
<script type="text/javascript">
function logoutFacebook() {
}
window.onload = function () {
var ID = document.getElementById('hfID').value
FB.init({ apiKey: ID });
FB.getLoginStatus(handleSessionResponse);
}
function handleSessionResponse(response) {
FB.logout(handleSessionResponse);
}
</script>

Popup browser back to parent browser after a certain page is reached

I have a popup (which I used by necessity) that is opened on a link click. I have the user going through a series of pages picking attributes to then be sent to a shopping cart.
My problem: After the user reaches the end of the selection process i want to kill the open popup and send the request back to the original browser (parent) so the user can checkout.
Any idea how I would do this?
Javascript: in the child (popup) window.
window.opener.location = 'page.html";
window.close();
Is that what your looking for?
The parent window can be accessed using "opener" in JavaScript.
Example:
window.opener.title='hello parent window';
or
window.opener.location.href='http://redirect.address';
Script in my child form:
<script language="JavaScript" type="text/javascript">
function SetData() {
// form validation
// var frmvalidator = new Validator("myForm");
// frmvalidator.addValidation("name","req","Please enter Account Name");
// get the new dialog values
var str1 = document.getElementById("name").value;
var winArgs = str1;
// pass the values back as arguments
window.returnValue = winArgs;
window.close();
document.myForm.submit();
}
</script>
Script in my parent form:
<% #account_head= current_company.account_heads.find_by_name("Sundry Debtors")%>
<script type="text/javascript">
function OpenDialog() {
var winSettings = 'center:yes;resizable:no;help:yes;status:no;dialogWidth:450px;dialogHeight:200px';
// return the dialog control values after passing them as a parameter
winArgs = window.showModalDialog('<%= "/accounts/new?account_head_id=#{#account_head.id} #man" %>', winSettings);
if(winArgs == null) {
window.alert("no data returned!");
} else {
// set the values from what's returned
document.getElementById("to_account_auto_complete").value = winArgs;
}
}
</script>
This is work but not as i want, any one if found good solution please suggest.