PayPal

Checkout with PayPal

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.
Checkout with PayPal is a one-time payment checkout experience.

SetupAnchorIcon

Get the SDKAnchorIcon

Add the following in your app-level build.gradle:
  1. Kotlin
  2. Groovy
dependencies {
    implementation("com.braintreepayments.api:paypal:5.2.0")
}

SetupAnchorIcon

Get the SDKAnchorIcon

Add the following in your app-level build.gradle:
  1. Kotlin
  2. Groovy
dependencies {
    implementation("com.braintreepayments.api:paypal:4.49.1")
}

Invoking the Checkout with PayPal FlowAnchorIcon

InitializationAnchorIcon

Create a PayPalLauncher inside of your Activity's onCreate(). Then, create a PayPalClient with a Tokenization Key or Client Token and an appLinkReturnUrl that is used to return to your app from the PayPal payment flows.
  1. Kotlin
override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState);

    // PayPalLauncher must be initialized in onCreate
    payPalLauncher = PayPalLauncher();
    // can initialize the PayPalClient outside of onCreate if desired
    payPalClient = PayPalClient(
        context = this,
        authorization = "[TOKENIZATION_KEY or CLIENT_TOKEN]",
        appLinkReturnUrl = Uri.parse("https://merchant-app.com") // Merchant App Link
    );
}

Request a paymentAnchorIcon

After the user clicks the PayPal button, create a PayPalCheckoutRequest and call PayPalClient.createPaymentAuthRequest() and handle its result. If the result is Failure, handle the error. If the result is ReadyToLaunch, invoke PayPalLauncher.launch() and check the returned PayPalPendingRequest. If Started is returned, the PayPal flow was launched and the Started.pendingRequestString needs to be persisted. If Failure was returned, handle the error.
  1. Kotlin
  2. Kotlin
private fun onPayPalButtonClick() {
    val payPalCheckoutRequest = PayPalCheckoutRequest(
        amount = "12.34",
        hasUserLocationConsent = true
    );
    payPalClient.createPaymentAuthRequest(this, payPalCheckoutRequest) { paymentAuthRequest ->
        when (paymentAuthRequest) {
            is PayPalPaymentAuthRequest.ReadyToLaunch -> {
                val pendingRequest = payPalLauncher.launch(this, paymentAuthRequest);
                when (pendingRequest) {
                    is PayPalPendingRequest.Started -> {
                        <sdkmatcher sdk="android:v4">
                        First, make sure you have <a href="/braintree/docs/guides/client-sdk/setup/android/v4/#browser-switch-setup">defined your URL scheme</a>.
                        Next, create a BraintreeClient with a <a href="/braintree/docs/guides/client-sdk/setup/android/v4/#client-token-provider">ClientTokenProvider</a> or Tokenization Key.
                        Construct a PayPalClient and implement a PayPalListener to receive results.
                        Call PayPalClient#tokenizePayPalAccount to launch the PayPal flow.
                        An example integration might look like this:
                        <codeblocktabs>
                        <codeblocktab label="Java">
                        <codeblock class="language-java">
                        public class MyActivity extends AppCompatActivity implements PayPalListener {
                            private BraintreeClient braintreeClient;
                            private PayPalClient payPalClient;
                            @Override
                            protected void onCreate(Bundle savedInstanceState) {
                                super.onCreate(savedInstanceState);
                                braintreeClient = new BraintreeClient(this, new ExampleClientTokenProvider());
                                payPalClient = new PayPalClient(this, braintreeClient);
                                payPalClient.setListener(this);
                            }
                            private void myTokenizePayPalAccountWithCheckoutMethod() {
                                PayPalCheckoutRequest request = new PayPalCheckoutRequest("1.00");
                                request.setCurrencyCode("USD");
                                payPalClient.tokenizePayPalAccount(this, request);
                            }
                            @Override
                            public void onPayPalSuccess(@NonNull PayPalAccountNonce payPalAccountNonce) {
                                // send payPalAccountNonce.getString() to server
                            }
                            @Override
                            public void onPayPalFailure(@NonNull Exception error) {
                                if (error instanceof UserCanceledException) {
                                    // user canceled
                                } else {
                                    // handle error
                                }
                            }
                        };
                        </codeblock>
                    }
                }
            }
        }
    }
}
class MyActivity : AppCompatActivity(), PayPalListener {
    private lateinit var braintreeClient: BraintreeClient;
    private lateinit var payPalClient: PayPalClient;

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState);
        braintreeClient = BraintreeClient(this, ExampleClientTokenProvider());
        payPalClient = PayPalClient(this, braintreeClient);
        payPalClient.setListener(this);
    }

    private fun myTokenizePayPalAccountWithCheckoutMethod() {
        val request = PayPalCheckoutRequest("1.00");
        request.currenyCode = "USD";
        payPalClient.tokenizePayPalAccount(this, request);
    }

    override fun onPayPalSuccess(payPalAccountNonce: PayPalAccountNonce) {
        // send payPalAccountNonce.string to server
    }

    override fun onPayPalError(error: Exception) {
        if (error is UserCanceledException) {
            // user canceled
        } else {
            // 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. Java
  2. Kotlin
public class MyActivity extends AppCompatActivity {
    @Override
    protected void onNewIntent(Intent newIntent) {
        super.onNewIntent(newIntent);
        setIntent(newIntent);
    }
}
When you receive a result via onPayPalSuccess, you can query the PayPalAccountNonce result for specific customer information.

Shipping addressAnchorIcon

Shipping addresses may or may not be collected during the Checkout with PayPal flow. However, if you choose to collect shipping addresses yourself, it can be passed along with the your server side Transaction.Sale call. Look at the Server-side page for more information.

Country supportAnchorIcon

PayPal is available to merchants in all countries that we support and to customers in 140+ countries.

Currency presentmentAnchorIcon

The currency of the transaction is presented to the customer in the Checkout with PayPal flow. We support all currencies that PayPal REST APIs support. See the server-side section for details on charging a transaction in a specific currency.

If you accept cookies, we’ll use them to improve and customize your experience and enable our partners to show you personalized PayPal ads when you visit other sites. Manage cookies and learn more