Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get user name, phone and email from PayPal Mobile Payment Library

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
like image 422
Mohamed Heiba Avatar asked Apr 30 '13 11:04

Mohamed Heiba


2 Answers

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("[email protected]"). 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());
like image 52
Shamim Ahmmed Avatar answered Oct 02 '22 20:10

Shamim Ahmmed


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

like image 22
CKmum Avatar answered Oct 02 '22 20:10

CKmum