9

I'm using the PayPal Mobile Payment Library to make users pay for journeys from my android app.

When the user clicks on Pay using Paypal button, the login screen shows up, when the user logs in, he is able to make the payment successfully. This is all works fine for my app. All what I need is get the user details after the user has completed/cancelled the payment in the onActivityResult code.

Please see my code below, unfortunately it doesn't get me the details from the paypal account, so I'm wondering if there's another method to get user details from paypal after he logs in.

@Override
    public void onActivityResult(int requestCode, int resultCode, Intent data)
    {
        switch (requestCode)
        {
            case PAYPAL_REQUESTCODE:
            {
                Log.w("tag","jemail#"+ PayPal.getInstance().getAccountEmail());
                Log.w("tag","jname#"+ PayPal.getInstance().getAccountName());
                Log.w("tag","jphone#"+ PayPal.getInstance().getAccountPhone());
                Log.w("tag","jdialcode#"+ PayPal.getInstance().getAccountCountryDialingCode());

                switch(resultCode)
                {
                    case Activity.RESULT_OK:
                    {
                        String payKey = data.getStringExtra(PayPalActivity.EXTRA_PAY_KEY);

                            Log.d("tag", "PayPal payment succeeded");
                            Log.d("tag", "PayPal payKey: " + payKey);

What I do is that I login, then cancel the transaction Here is the Log that I get

04-30 12:30:19.672: W/tag(24697): jemail#
04-30 12:30:19.672: W/tag(24697): jname#
04-30 12:30:19.672: W/tag(24697): jphone#+44
04-30 12:30:19.672: W/tag(24697): jdialcode#44

Then I click back in my app, then click next to go to the payment page again, and click on the pay with paypal button again, this time I would be already logged in, then I cancel transaction

04-30 12:30:43.878: W/tag(24697): jemail#
04-30 12:30:43.878: W/tag(24697): jname#H.O.P.E
04-30 12:30:43.878: W/tag(24697): jphone#+44
04-30 12:30:43.878: W/tag(24697): jdialcode#44
Mohamed Heiba
  • 1,813
  • 4
  • 38
  • 67

2 Answers2

3

You can not get payer information such as email, name and phone etc at this point. You might also noticed that there are corresponding set methods like payPal.setAccountEmail("payer@xyz.com"). They were designed to pre-populate PayPal dialog with payer information if you already have these information.

However, you can use PayPal IPN (Instant Payment Notification) to get a call back from PayPal system when payment has been processed. From the IPN message you can extract payer information. Use Pay Key to identify payer from the IPN message. In addition, you have to pass PayPalAdvancedPayment object while calling PayPal Activity. Please check out this document, PayPal Mobile implementation guide

Calling procedure as follows:

    PayPalAdvancedPayment payment = new PayPalAdvancedPayment();
    payment.setIpnUrl("http://server/test");
    payment.setReceivers... // Receiver objects
    PayPal.getInstance().checkout(payment, this.getBaseContext());
Shamim Ahmmed
  • 8,265
  • 6
  • 25
  • 36
  • Thanks for your help. However, I want to users to login via PayPal and I would then have their details from PayPal, i.e. like Facebook login, Twitter login, etc. The problem is I dont know if PayPal access https://www.x.com/developers/paypal/products/login-with-paypal will actually work with the PayPal Mobile Payment Library button, i.e. I don't know if the user logs in via PayPal access, whether he will be logged in also to the PayPal MPL session or not, cause if not, then useless to me. Please tell me if you want to explain more – Mohamed Heiba May 07 '13 at 17:53
  • 2
    Yes, you can fetch PayPal user profile information as the PayPal provides OAuth2 standard. First you have to login user via PayPal login and generate a authentication token. Once you receive a valid authentication token, you can call user profile data if the user allowed your app to access their profile data (https://identity.x.com/xidentity/resources/profile/me). The profile access permission is granted during OAuth login procedure. The procedure is similar to Facebook, Google or other OAuth2 standard – Shamim Ahmmed May 07 '13 at 20:23
3

Check this (OAuth): https://developer.paypal.com/webapps/developer/docs/integration/direct/log-in-with-paypal/#getStart

and this: https://developer.paypal.com/webapps/developer/docs/integration/direct/log-in-with-paypal/detailed/

Use HttpClient and WebView to authenticate and proceed further - WebFrame may be bit complex for this app but that's only thing I can think of right away - unless you use other OAuth providers' App libraries

Also see - http://developer.android.com/reference/android/webkit/WebView.html

CKmum
  • 641
  • 6
  • 17
  • 1
    Useful information but the question was how to get these information using PayPal Mobile Payment Library – Shamim Ahmmed May 07 '13 at 22:38
  • 1
    MPL is not an Identity management tool; rather it helps process payments. use PayPal OAuth for getting details and stitch them together. – CKmum May 08 '13 at 04:49