PayPal Mobile Checkout
As of July 2024, the PayPalNativeCheckout module has been deprecated. The PayPalNativeCheckout module will be supported for critical bugs for 1 year and will then be transitioned to an unsupported state after July 2025.
In its place, we recommend integrating the PayPal module. Merchants are recommended to proactively migrate from the PayPalNativeCheckout module to the PayPal module before July 2025 in order to ensure a seamless migration experience.
In order to migrate to the PayPal module, follow the steps within the Checkout with PayPal page.
PayPal Mobile Checkout is available to eligible merchants using a custom client-side integration. It is only available in Android v4.13+ and iOS v5.11+ and is not currently available for the Drop-in UI or JavaScript.
PayPal Mobile Checkout is eligible for:
- Merchants in the US, Canada, Europe, and the UK.
- Customers in the US, Canada, Europe, and the UK. Please note, customers in other regions can use PayPal to complete their transaction but will see the standard web experience.
The PayPal Mobile Checkout flow doesn't support the following:
- In-person point of sale (PoS) transactions
- Multi-seller payments
Setup
Before you can add the PayPal Mobile Checkout, you will need to:
- Create, verify, and link your PayPal account in the Braintree Control Panel
- Obtain either a client token or tokenization key and setup your client
Using a custom UI
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.
- Kotlin
- 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 SDK
Add the following in your app-level build.gradle:
- Kotlin
- 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.
- Groovy
repositories {
maven {
url "https://cardinalcommerceprod.jfrog.io/artifactory/android",
credentials {
username 'braintree_team_sdk',
password 'cmVmdGtuOjAxOjIwMzgzMzI5Nzg6Q3U0eUx5Zzl5TDFnZXpQMXpESndSN2tBWHhJ'
}
}
}Register the apps ReturnUrl
After authentication the checkout sdk requires a return url to redirect to the client application.
- Login to the PayPal Developer Dashboard
- Select your app from the My Apps & Credentials page
- Under the other features tab, check Log in with PayPal and click Advanced Settings
- 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.
- 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 Flow
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:
- Kotlin
- 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:
- Kotlin
- Java
class MyActivity : AppCompatActivity() {
override fun onNewIntent(newIntent: Intent?) {
super.onNewIntent(newIntent)
intent = newIntent
}
}