PayPal
import { LoadFilesPayPalCodeBlock } from '~/components/CodeBlockInstances/PayPal/LoadFiles.tsx' import { LoadPayPalScriptCodeBlock } from '~/components/CodeBlockInstances/PayPal/LoadPayPalScript.tsx'
Client-Side Implementation
Setup
Before you can add PayPal, you will need to:
- Create, verify, and link your PayPal account in the Braintree Control Panel
- Set up your Android SDK and obtain your client token
- Declare a URL scheme in your AndroidManifest
Get the SDK
Add the following in your app-level build.gradle
:
- Kotlin
- Groovy
dependencies { implementation("com.braintreepayments.api:paypal:5.2.0") }
Initialization
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.
- 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 ) }
Using our Drop-in UI
When using the Drop-in UI, a PayPal payment option will be shown alongside any other payment methods you've enabled. For more details, see the Drop-in UI guide.
Using a Custom UI
You can optionally implement a custom button to start a PayPal flow.
Get the SDK
Add the following in your app-level build.gradle
:
- Kotlin
- Groovy
dependencies { implementation("com.braintreepayments.api:paypal:4.49.1") }
Initialization
Create a BraintreeClient
with a
ClientTokenProvider
or Tokenization Key. Construct a PayPalClient
, and add a click listener to your button
to initiate the PayPal flow. For a complete integration example, see the
Vault or
Checkout pages.
- Kotlin
- Java
class MyActivity : AppCompatActivity() { 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) } private fun onPayPalButtonClick(view: View) { // The PayPalRequest type will be based on integration type (Checkout vs. Vault)<br> payPalClient.tokenizePayPalAccount(this, payPalRequest) } }
Collecting additional data
There is additional data you can gather about your customers as they complete the payment process.
Next: Choose your integration
The rest of your configuration will be determined by how you'd like to use PayPal.
- Want easy payments for repeat customers? Have a subscription model? Use our Vault.
- Want a one-time payment checkout? Use Checkout with PayPal.