This guide explains how to configure Braintree in a React Native Bare (react-native-cli) project using react-native-expo-braintree v3.x.x.
Important: Before starting the steps below, you must complete the App Links configuration described here:
https://github.com/braintree/braintree_android/blob/main/APP_LINK_SETUP.md
Depending on the Braintree methods you use, you must add the appropriate intent filters to your MainActivity.
requestBillingAgreementrequestOneTimePaymenttokenizeCardData
Add the following intent filter inside your MainActivity.
Replace braintree-example-app.web.app with the domain configured
during App Links setup.
<activity>
...
<intent-filter android:autoVerify="true">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="https" />
<data android:host="braintree-example-app.web.app" />
</intent-filter>
</activity>requestVenmoNoncerequest3DSecurePaymentCheck
Add the following intent filter:
<activity>
...
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="${applicationId}.braintree" />
</intent-filter>
</activity>You must add both intent filters.
File location:
android/app/src/main/java/com/{app_name}/MainActivity.kt
requestBillingAgreementrequestOneTimePaymenttokenizeCardData
Add the following inside the onCreate method:
import com.expobraintree.ExpoBraintreeModule
override fun onCreate() {
...
ExpoBraintreeModule.init()
...
}request3DSecurePaymentCheck
Add the following instead:
import com.expobraintree.ExpoBraintreeModule
override fun onCreate() {
...
ExpoBraintreeModule.initThreeDSecure(this)
...
}requestGooglePayPayment
Add the following instead:
import com.expobraintree.ExpoBraintreeModule
override fun onCreate() {
...
ExpoBraintreeModule.initGooglePay(this)
...
}You must add all initialization methods.
If you use 3D Secure, add the following repository to:
android/build.gradle
Add it at the end of the file.
allprojects {
repositories {
maven {
url "https://cardinalcommerceprod.jfrog.io/artifactory/android"
credentials {
username 'braintree_team_sdk'
password 'AKCp8jQcoDy2hxSWhDAUQKXLDPDx6NYRkqrgFLRc3qDrayg6rrCbJpsKKyMwaykVL8FWusJpp'
}
}
}
}Run the following command:
cd ios
pod installAdd a Bundle URL Scheme to your app.
- Open your project in Xcode
- Go to Info
- Add a URL Type
{BUNDLE_IDENTIFIER}.braintree
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>CFBundleURLName</key>
<string>com.myapp</string>
<key>CFBundleURLSchemes</key>
<array>
<string>com.myapp.braintree</string>
</array>
</dict>
</array>Starting with Braintree SDK v6, the iOS SDK was rewritten in
Swift.
Because of this, a small Swift wrapper is required to expose the
functionality needed by AppDelegate.swift.
This guide assumes:
- You are using React Native 0.79+
- Your project uses AppDelegate.swift instead of
AppDelegate.mm
If you are using older React Native (<0.77), refer to the 3.1.0 integration guide.
- Open your iOS project in Xcode
- Create a new file:
<!-- -->
ExpoBraintreeConfig.swift
Add the following code:
import Braintree
import Foundation
public final class ExpoBraintreeConfig {
private init() {}
public static var paymentURLScheme: String {
let bundleIdentifier = Bundle.main.bundleIdentifier ?? ""
return bundleIdentifier + ".braintree"
}
public static func handleUrl(url: URL) -> Bool {
return BTAppContextSwitcher.sharedInstance.handleOpen(url)
}
}Add or update the following method:
func application(
_ application: UIApplication,
open url: URL,
options: [UIApplication.OpenURLOptionsKey : Any] = [:]
) -> Bool {
if url.scheme?.localizedCaseInsensitiveCompare(
ExpoBraintreeConfig.paymentURLScheme
) == .orderedSame {
return ExpoBraintreeConfig.handleUrl(url: url)
}
return RCTLinkingManager.application(
application,
open: url,
options: options
)
}All required Android and iOS configuration examples can be found in the example project directories:
example/android
example/ios
To integrate react-native-expo-braintree v3.x.x in a React Native Bare project:
- Configure Braintree App Links
- Add required Android intent filters
- Initialize the module in MainActivity
- Add 3DSecure repository if required
- Configure iOS URL Scheme
- Create ExpoBraintreeConfig.swift
- Update AppDelegate.swift