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

android, android-intent, paypal, paypal-sandbox

Solution

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());

Problem

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 ```

Original source