Xamarin - Auto Login

246 Views Asked by At

I am implementing a PayPal payment method for a Xamarin Forms Application. When the user purchases a product for the very first time, they will have to login to their PayPal account. However, I would like to save the user's credentials so they don't have to keep logging in every time they use the app. Ideally, it should automatically log them in when they open it up.

Right now, what I'm trying to do is open up PayPal in a WebView and programmatically pass the appropriate text into both login input fields (email and password) so I can then call the click function on the login button (somehow).

For my XAML file, I have:

<WebView x:Name="webView" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand"/>

For my C# file, I have:

namespace MyApp.Views
{
   public partial class PaymentPage : ContentPage
   {
       public PaymentPage()
       {
           InitializeComponent();
           webView.Source = "https://www.paypal.com/signin";
       }

       async private void Button_Clicked(object sender, EventArgs e)
       {
           var element = webView.EvaluateJavaScriptAsync("document.getElementsByClassName('loginEmail')[0]");
       }
   }
}

I'm trying to access the email input field and enter the recorded email programmatically. Unfortunately, this keeps returning the string "{}" and assigning it to the variable page. Would anyone know how to fix this? Once I this is resolved, I'm sure I can do the same for the password. But then I will need to call the login button click programmatically afterwards. So, if anyone can help on that as well, that would be greatly appreciated.

Thanks!

1

There are 1 best solutions below

0
Preston PHX On BEST ANSWER
  1. Do not use PayPal in a webview. Use an approved browser view mechanism that has an address bar, such as a Safari View Controller on iOS or Chrome Custom Tab on Android.

  2. Do not attempt to programmatically manipulate the login form. The user must enter their credentials themselves or worse case have them saved by the browser.

Failure to abide by the above will result in your accounts and/or your buyers' accounts being closed or frozen by PayPal, and password resets being required.


To create PayPal transactions without a login, the feature you are looking for is called "reference transactions", or the newest v2 vault (not v1 vault). You can contact PayPal's general business support (not technical support) to ask about having your account approved for reference transactions, which may or may not be granted depending on your business history and use case.