PayPal Mobile Checkout

SetupAnchorIcon

Before you can add the PayPal Mobile Checkout, you will need to:

  1. Create, verify, and link your PayPal account in the Braintree Control Panel
  2. Obtain either a client token or tokenization key and setup your client

Using a custom UIAnchorIcon

The PayPal Mobile Checkout flow is currently only available via a custom UI and cannot be used via the Drop-in. Implement a custom button to start the PayPal Mobile Checkout flow.

  1. Kotlin
  2. Java
class MyActivity : AppCompatActivity() {

  private lateinit var braintreeClient: BraintreeClient
  private lateinit var payPalNativeCheckoutClient: PayPalNativeCheckoutClient

  override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    braintreeClient = BraintreeClient(this, ExampleClientTokenProvider())
    payPalNativeCheckoutClient = PayPalNativeCheckoutClient(braintreeClient)
  }

  private fun onPayPalButtonClick(view: View) {
    // Launch PayPal Mobile Checkout flow
  }
}

Get the SDKAnchorIcon

Add the following in your app-level build.gradle:

  1. Kotlin
  2. Groovy
dependencies {
    implementation("com.braintreepayments.api:paypal-native-checkout:4.49.1")
}

Additionally, add the following Maven repository and (non-sensitive) credentials to your app-level gradle.

  1. Groovy
repositories {
    maven {
        url "https://cardinalcommerceprod.jfrog.io/artifactory/android",
        credentials {
            username 'braintree_team_sdk',
            password 'cmVmdGtuOjAxOjIwMzgzMzI5Nzg6Q3U0eUx5Zzl5TDFnZXpQMXpESndSN2tBWHhJ'
        }
    }
}

Register the apps ReturnUrlAnchorIcon

After authentication the checkout sdk requires a return url to redirect to the client application.

  1. Login to the PayPal Developer Dashboard
  2. Select your app from the My Apps & Credentials page
  3. Under the other features tab, check Log in with PayPal and click Advanced Settings
  4. Enter a new Return Url and click save
    • You can use an Android App Link registered within the Developer Console to handle SDK redirects.
    • Alternatively, you can use your application ID (typically referenced via BuildConfig.APPLICATION_ID) and register your application ID with ://paypalpay as the suffix. For example, if your application ID is com.paypal.app, input com.paypal.app://paypalpay in the Developer Console.
    • The return URL in the Developer Dashboard and the SDK must match exactly.
    • If you change the return URL in the Developer Dashboard, PayPal must review your app again. The review period automatically begins any time the return URL changes.
  5. Select the checkboxes for Full name and Email found within the Information requested from customers section. These are scopes of the Identity API.

Invoking the PayPal Mobile Checkout FlowAnchorIcon

Create a BraintreeClient with a ClientTokenProvider or tokenization key. Construct a PayPalNativeCheckoutClient and implement a PayPalNativeCheckoutListener to receive results. Then construct your PayPalNativeCheckoutRequest or PayPalNativeVaultRequest, which will be used to make your call to PayPalNativeCheckoutClient#launchNativeCheckout to launch the PayPal Mobile Checkout flow. The returnUrl must be set using setReturnUrl inside PayPalNativeRequest. The returnUrl is the same one that is enabled in the PayPal Developer Portal. An amount is required to invoke the one-time payment flow.

An example integration might look like this:

  1. Kotlin
  2. Java
class MyActivity : AppCompatActivity(), PayPalNativeCheckoutListener {
     
  private lateinit var braintreeClient: BraintreeClient
  private lateinit var payPalNativeClient: PayPalNativeCheckoutClient
 
  override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    braintreeClient = BraintreeClient(this, ExampleClientTokenProvider())
    payPalNativeClient = PayPalNativeCheckoutClient(braintreeClient)
    payPalNativeClient.setListener(this)
  }
 
  private fun myTokenizePayPalAccountWithCheckoutMethod() {
    // One time checkout
    val request = PayPalNativeCheckoutRequest("1.00")

    // Set the applications return url
    request.returnUrl = "com.braintreepayments.demo://paypalpay"

    // Configure other values on 'request' as needed.

    payPalNativeClient.launchNativeCheckout(this, request)
  }
   
  override fun onPayPalSuccess(payPalAccountNonce: PayPalAccountNonce) {
    // send payPalAccountNonce.string to server
  }
 
  override fun onPayPalError(error: Exception) {
    // handle error
  }
}

If you are using using an Activity and your Activity's launch mode is singleTop, singleTask, or singleInstance you will also need to override onNewIntent:

  1. Kotlin
  2. Java
class MyActivity : AppCompatActivity() {
     
  override fun onNewIntent(newIntent: Intent?) {
    super.onNewIntent(newIntent)
 
    intent = newIntent
  }
}