Search code examples
paypalpaypal-rest-sdk

PayPal Login with Java Rest API


I am currently trying to integrate a PayPal Login into my JSF application.

The user should be redirected to PayPal, login and then be redirected back to our site. With the redirected token, I want to fetch the users email.

I am using the latest Java Restful API and used the exact sample PayPal provided.

Map<String, String> configurationMap = new HashMap<String, String>();
    configurationMap.put("mode", "sandbox");

    APIContext apiContext = new APIContext();
    apiContext.setConfigurationMap(configurationMap);

    List<String> scopelist = new ArrayList<String>();
    scopelist.add("openid");
    scopelist.add("email");
    String redirectURI = "https://22af922.ngrok.com/";

    ClientCredentials clientCredentials = new ClientCredentials();
    clientCredentials.setClientID("my_client_id");

    String redirectUrl = Session.getRedirectURL(redirectURI, scopelist, apiContext, clientCredentials); 

Generating the redirect url works fine, however, on redirect, it keeps telling me that the redirect_uri does not match the redirect_uri in my application settings, even though I am using the exact same url I have setup in my PayPal app.

Any help is very appreciated. Thanks in advance.


Solution

  • I fixed it by doing the following.

    1. Go to http://developer.paypal.com/ and login
    2. Go to Sandbox > Accounts
    3. Click on the -developer account -> Profile -> API Credentials
    4. Make sure the return url is the same as the return url you are trying to use
    5. Press Save

    Even though the return url in those settings was equal to the one in my app settings, just using the save button in that specific place did the trick. I have absolutely no idea why this fixed it...