I have successfully logging to PayPal and my returnurl
receive the pay pal data (code=xxxxxxxxxx&scope=email ,
but i need to receive this data on the client side.
Do paypal have some event like
login.successful(response){} ,login.submit(response){}
? some successful login event where i get see the sode =xxxxx that paypal sent to my returnurl
I need to receive this data not only at my returnurl
, i need it at my client side.
<!DOCTYPE html>
<html lang="en">
<head>
<script src = "https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<span id='cwppButton'></span>
<script src='https://www.paypalobjects.com/js/external/connect/api.js'></script>
<script>
paypal.use( ['login'], function (login) {
login.render ({
"appid":"xxx-xxx",
"authend":"sandbox",
"scopes":"email address profile",
"containerid":"cwppButton",
"responseType":"code",
"locale":"en-us",
"buttonType":"CWP",
"buttonShape":"pill",
"buttonSize":"lg",
"fullPage":"false",
"returnurl":"https://xxxx/"
});
console.log("login : "+JSON.stringify(login));//login : {"build":16}
});
</script>
</head>
<body>
</body>
</html>
Only way that i had found is to use returnurl parameter to receive the response.
You need to build service/controller that will receive the data from response and send it back to your page.
This is how i did it:
My returnurl send data to my controller,i work with this data ,and then i send request to my page with query-string that i have build from pay pal data that i had received,and read it on my page (PageLoad event)
This is not the best way ,but it working.If you have another way to do this please let me know.
public void PayPalLisiner()
{
try
{
//get pay pal data
string AuthorizationCode = HttpContext.Current.Request.QueryString["code"];
//my function that work with data,and prepare query-string
string PayPalLogin = privateZoneService.PayPalLogin(AuthorizationCode);
//set request with query-string parameters
HttpContext.Current.Response.Redirect("http://demo.com/login?PayPalLogin=" + PayPalLogin);
}
catch (Exception ex)
{
Logger.Error(ex.Message);
}
}