PayPal

PayPal App Switch (Beta)

Important

The SSL certificates for Braintree Mobile (iOS and Android) SDKs are set to expire on March 30, 2026. This will impact existing versions of the SDK in published versions of your app. To reduce the impact, upgrade the Android SDK to version 4.45.0+ or version 5.0.0+ for the new SSL certifications.

If you do not decommission your app versions that include the older SDK versions or force upgrade your app with the updated certificates by the expiration date, 100% of your customer traffic will fail.

Availability

The feature is now available across JavaScript SDK, iOS, and Android for One-time Payments and Vaulted Payments.

eligibility
PayPal App Switch is eligible for:
  • Merchants in the US
  • Customers in the US
  • Merchants using a custom client side integration
  • Merchants using the PayPal Vault flow and PayPal Checkout flow

In this experience the SDK will attempt to switch to the PayPal App after calling PayPalLauncher().launch if the PayPal App is installed and the user meets eligibility requirements. If the switch into the PayPal App cannot be completed, we will fall back to the default browser experience.

Using a custom UIAnchorIcon

You can optionally implement a custom button to start a PayPal flow.

Get the SDKAnchorIcon

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

  1. Kotlin
  2. Groovy
dependencies {
    implementation("com.braintreepayments.api:paypal:5.8.0")
}

In order to use the PayPal App Switch flow your application must be set up for App Links.

Before using this feature, you must register your App Link domain in the Braintree Control Panel:

  1. Log into your Control Panel (e.g. Sandbox, or Production).
  2. Click on the gear icon in the top right corner. A drop-down menu will open.
  3. Click Processing from the drop-down menu.
  4. Scroll to the Payment Methods section.
  5. Next to PayPal, click the Options link. This will take you to your linked PayPal Account(s) page.
  6. Click the View Domain Names button. This will take you to the PayPal Domain Names page.
    • Note: If you have a single PayPal account, it will be at the bottom of the page. If you have multiple PayPal accounts, it will be at the top right of the page.
  7. Click the + Add link on the top right of the page or scroll to the Specify Your Domain Names section.
  8. In the text box enter your list of domain names separated by commas.
    • Note: The value you enter must match your fully qualified domain name exactly – including the "www." if applicable.
  9. Click the Add Domain Names button.
  10. If the domain registration was successful for all the domain names listed in the text box, a banner will display the text "Successfully added domains". The registered domain names will be displayed in alphabetical order under the + Add button.
  11. If the registration was not successful for any of the domain names listed in the text box, a banner will display a list of domain names that failed qualified domain name validation along with their reasons for rejection. Any domain names that were successfully registered will be displayed in alphabetical order under the + Add button.
    • Note: You can re-enter the rejected domain names in the text area with the corrections applied.

You will need to use the following PayPalClient constructor to set your App Link:

  1. Kotlin
val payPalClient =  PayPalClient(
  this, 
  "<#CLIENT_AUTHORIZATION#>",
  Uri.parse("https://demo-app.com/braintree-payments") // Merchant App Link
)

Invoking the PayPal App Switch FlowAnchorIcon

Opt In to The App Switch FlowAnchorIcon

Construct a PayPalVaultRequest or a PayPalCheckoutRequest with enablePayPalAppSwitch set to true and a userAuthenticationEmail included.

An example integration might look like this:

  1. Kotlin
override fun onCreate(savedInstanceState: Bundle?) {
    payPalLauncher = PayPalLauncher()
}

// ONLY REQUIRED IF YOUR ACTIVITY LAUNCH MODE IS SINGLE_TOP
override fun onNewIntent(intent: Intent) {
    handleReturnToAppFromBrowser(intent)
}
    
// ALL OTHER ACTIVITY LAUNCH MODES 
override fun onResume() {
    handleReturnToAppFromBrowser(requireActivity().intent)
}

// vault flows
val request = PayPalVaultRequest(hasUserLocationConsent) 

// one time checkout flows
val request = PayPalCheckoutRequest(amount, hasUserLocationConsent) 

request.userAuthenticationEmail = "sally@gmail.com"
request.enablePayPalAppSwitch = true

fun onPayPalButtonClick() {
    payPalClient.createPaymentAuthRequest(this, request) { paymentAuthRequest ->
        when(paymentAuthRequest) {
            is PayPalPaymentAuthRequest.ReadyToLaunch -> {
                val pendingRequest = payPalLauncher.launch(this@MyActivity, paymentAuthRequest)
                when(pendingRequest) {
                    is (PayPalPendingRequest.Started) { /* store pending request */ }
                    is (PayPalPendingRequest.Failure) { /* handle error */ }
                }
            }
            is PayPalPaymentAuthRequest.Failure -> { /* handle paymentAuthRequest.error */ }
        }
    }
}

fun handleReturnToAppFromBrowser(intent: Intent) {
    // fetch stored PayPalPendingRequest.Started 
    fetchPendingRequestFromPersistentStorage()?.let {
        when (val paymentAuthResult = payPalLauncher.handleReturnToAppFromBrowser(it, intent)) {               
            is PayPalPaymentAuthResult.Success -> {
                completePayPalFlow(paymentAuthResult)
                // clear stored PayPalPendingRequest.Started
            }
            is PayPalPaymentAuthResult.NoResult -> // user returned to app without completing PayPal flow, handle accordingly
        }
    }   
}
    
fun completePayPalFlow(paymentAuthResult: PayPalPaymentAuthResult) {
    payPalClient.tokenize(paymentAuthResult) { result ->
        when(result) {
            is PayPalResult.Success -> { /* handle result.nonce */ }
            is PayPalResult.Failure -> { /* handle result.error */ }
            is PayPalResult.Cancel -> { /* handle user canceled */ }
        }          
    }
}

TestingAnchorIcon

In order to test this flow in Sandbox, you will first need access to the TestFlight PayPal Sandbox app. Additionally, you are required to remove the Production PayPal app from your device to complete the App Switch flow successfully in Sandbox. Please reach out to app-switch-onboarding@paypal.com for access to the TestFlight PayPal Sandbox app.