braintree/braintree-android-drop-in


Braintree Drop-In SDK for Android https://developers.braintreepayments.com/guides/drop-in/android/v2

Download


Step 1. Add the JitPack repository to your build file

Add it in your root settings.gradle at the end of repositories:

	dependencyResolutionManagement {
		repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
		repositories {
			mavenCentral()
			maven { url 'https://jitpack.io' }
		}
	}

Add it in your settings.gradle.kts at the end of repositories:

	dependencyResolutionManagement {
		repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
		repositories {
			mavenCentral()
			maven { url = uri("https://jitpack.io") }
		}
	}

Add to pom.xml

	<repositories>
		<repository>
		    <id>jitpack.io</id>
		    <url>https://jitpack.io</url>
		</repository>
	</repositories>

Add it in your build.sbt at the end of resolvers:

 
    resolvers += "jitpack" at "https://jitpack.io"
        
    

Add it in your project.clj at the end of repositories:

 
    :repositories [["jitpack" "https://jitpack.io"]]
        
    

Step 2. Add the dependency

	dependencies {
		implementation 'com.github.braintree:braintree-android-drop-in:'
	}
	dependencies {
		implementation("com.github.braintree:braintree-android-drop-in:")
	}
	<dependency>
	    <groupId>com.github.braintree</groupId>
	    <artifactId>braintree-android-drop-in</artifactId>
	    <version></version>
	</dependency>

                            
    libraryDependencies += "com.github.braintree" % "braintree-android-drop-in" % ""
        
        

                            
    :dependencies [[com.github.braintree/braintree-android-drop-in ""]]
        
        

Readme


Braintree Android Drop-In

Tests

Braintree Android Drop-In is a readymade UI that allows you to accept card and alternative payments in your Android app.

<img alt="Screenshot of Drop-In" src="screenshots/vaulted-payment-methods.png" width="200"/>

📣 Announcements

  • A new major version of the SDK is now available. See the v6 migration guide for details.
  • Upgrade your integration to continue accepting Braintree payments The SSL certificates for the Android SDK are set to expire by June 31, 2025. Upgrade to v6.16.0+ to continue using the Braintree SDK.

Adding it to your project

Add the dependency in your build.gradle:

dependencies {
  implementation 'com.braintreepayments.api:drop-in:6.17.0'
}

Additionally, add the following Maven repository and (non-sensitive) credentials to your app-level gradle:

repositories {
    maven {
        url "https://cardinalcommerceprod.jfrog.io/artifactory/android"
        credentials {
            username 'braintree_team_sdk'
            password 'cmVmdGtuOjAxOjIwMzgzMzI5Nzg6Q3U0eUx5Zzl5TDFnZXpQMXpESndSN2tBWHhJ'
        }
    }
}

To preview the latest work in progress builds, add the following SNAPSHOT dependency in your build.gradle:

dependencies {
  implementation 'com.braintreepayments.api:drop-in:6.17.1-SNAPSHOT'
}

You will also need to add the Sonatype snapshots repo to your top-level build.gradle to import SNAPSHOT builds:

allprojects {
    repositories {
        maven {
            url 'https://oss.sonatype.org/content/repositories/snapshots/'
        }
    }
}

Versions

This SDK abides by our Client SDK Deprecation Policy. For more information on the potential statuses of an SDK, check our developer docs.

| Major version number | Status | Released | Deprecated | Unsupported | | -------------------- | ------ | -------- | ---------- | ----------- | | 6.x.x | Active | November 2021 | TBA | TBA | | 5.x.x | Unsupported | September 2020 | November 2022 | November 2023 | | 4.x.x | Unsupported | February 2019 | September 2021 | September 2022 |

Versions 3 and below are unsupported.

Usage

Create a DropInRequest to start the Drop-in UI with specified options:

val dropInRequest = DropInRequest()

DropInClient is responsible for launching the Drop-in UI. To launch Drop-in, instantiate a DropInClient with client authorization and call DropInClient#launchDropInForResult with the DropInRequest you configured above and a request code that you have defined for Drop-in:

val dropInClient = DropInClient(this, "<#CLIENT_AUTHORIZATION#>")
dropInClient.setListener(this)
dropInClient.launchDropIn(dropInRequest)

To handle the result of the Drop-in flow, implement DropInListener methods onDropInSuccess() and onDropInFailure():

override fun onDropInSuccess(result: DropInResult) {
  // use the result to update your UI and send the payment method nonce to your server
  val paymentMethodNonce = result.paymentMethodNonce?.string
}

override fun onDropInFailure(error: Exception) {
  // an error occurred, checked the returned exception
}

Localization

Drop-In is currently localized for 25 languages. To view localized text for a specific locale, open its corresponding values-<LOCALE_NAME>/strings.xml resource file.

3D Secure + Drop-in

Drop-In supports 3D-Secure verification. Assuming you have 3D-Secure configured for your account, create a ThreeDSecureRequest() object, setting ThreeDSecurePostalAddress and ThreeDSecureAdditionalInformation fields where possible; the more fields that are set, the less likely a user will be presented with a challenge. For more information, check our 3D Secure Migration Guide. Make sure to attach this object to the BTDropInRequest before use.

val address = ThreeDSecurePostalAddress()
address.givenName = "Jill" // ASCII-printable characters required, else will throw a validation error
address.surname = "Doe" // ASCII-printable characters required, else will throw a validation error
address.phoneNumber = "5551234567"
address.streetAddress = "555 Smith St"
address.extendedAddress = "#2"
address.locality = "Chicago"
address.region = "IL"
address.postalCode = "12345"
address.countryCodeAlpha2 = "US"

// Optional additional information.
// For best results, provide as many additional elements as possible.
val additionalInformation = ThreeDSecureAdditionalInformation()
additionalInformation.shippingAddress = address

val threeDSecureRequest = ThreeDSecureRequest()
threeDSecureRequest.amount = "1.00"
threeDSecureRequest.email = "test@email.com"
threeDSecureRequest.billingAddress = address
threeDSecureRequest.versionRequested = VERSION_2
threeDSecureRequest.additionalInformation = additionalInformation

val dropInRequest = DropInRequest()
dropInRequest.threeDSecureRequest = threeDSecureRequest

Fetch last used payment method

If your user already has an existing payment method, you may not need to show Drop-in. You can check if they have an existing payment method using DropInClient#fetchMostRecentPaymentMethod. A payment method will only be returned when using a client token created with a customer_id.

val dropInClient = DropInClient(this, "<#CLIENT_TOKEN_WITH_CUSTOMER_ID>", dropInRequest)
dropInClient.fetchMostRecentPaymentMethod(this) { dropInResult, error ->
    error?.let {
        // an error occurred
    }
    dropInResult?.let { result ->
        result.paymentMethodType?.let { paymentMethodType ->
            // use the icon and name to show in your UI
            val icon = paymentMethodType.drawable
            val name = paymentMethodType.localizedName

            if (paymentMethodType == DropInPaymentMethod.GOOGLE_PAY) {
                // The last payment method the user used was Google Pay.
                // The Google Pay flow will need to be performed by the
                // user again at the time of checkout.
            } else {
                // Show the payment method in your UI and charge the user
                // at the time of checkout.
                val paymentMethod = result.paymentMethodNonce
            }
        }
    } ?: run {
        // there was no existing payment method
    }
}

Help

Feedback

Here are a few ways to get in touch:

License

Braintree Android Drop-In is open source and available under the MIT license. See the LICENSE file for more info.