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.bblackbelt:braintree-android-drop-in:3.0.5'
}
dependencies {
implementation("com.github.bblackbelt:braintree-android-drop-in:3.0.5")
}
<dependency>
<groupId>com.github.bblackbelt</groupId>
<artifactId>braintree-android-drop-in</artifactId>
<version>3.0.5</version>
</dependency>
libraryDependencies += "com.github.bblackbelt" % "braintree-android-drop-in" % "3.0.5"
:dependencies [[com.github.bblackbelt/braintree-android-drop-in "3.0.5"]]
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="300"/>Please create an issue with any comments or concerns.
In your build.gradle
:
dependencies {
compile 'com.braintreepayments.api:drop-in:3.0.0'
}
Create a DropInRequest
and use the Intent
to start Drop-In:
DropInRequest dropInRequest = new DropInRequest()
.clientToken(mClientToken);
startActivityForResult(dropInRequest.getIntent(context), DROP_IN_REQUEST);
Handle the response:
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == DROP_IN_REQUEST) {
if (resultCode == Activity.RESULT_OK) {
DropInResult result = data.getParcelableExtra(DropInResult.EXTRA_DROP_IN_RESULT);
String paymentMethodNonce = result.getPaymentMethodNonce().getNonce();
// send paymentMethodNonce to your server
} else if (resultCode == Activity.RESULT_CANCELED) {
// canceled
} else {
// an error occurred, checked the returned exception
Exception exception = (Exception) data.getSerializableExtra(DropInActivity.EXTRA_ERROR);
}
}
}
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 DropInResult#fetchDropInResult
. Note that a payment method will only be returned when using a client token created with a customer_id
.
DropInResult.fetchDropInResult(activity, clientToken, new DropInResult.DropInResultListener() {
@Override
public void onError(Exception exception) {
// an error occurred
}
@Override
public void onResult(DropInResult result) {
if (result.getPaymentMethodType() != null) {
// use the icon and name to show in your UI
int icon = result.getPaymentMethodType().getDrawable();
int name = result.getPaymentMethodType().getLocalizedName();
if (result.getPaymentMethodType() == PaymentMethodType.ANDROID_PAY) {
// the last payment method the user used was Android Pay
// the Android Pay flow will need to be performed by the
// user again at the time of checkout
} else {
// use the payment method show in your UI and charge the user
// at the time of checkout
PaymentMethodNonce paymentMethod = result.getPaymentMethodNonce();
}
} else {
// there was no existing payment method
}
}
});
To offer card scanning via card.io, add the dependency in your build.gradle
:
dependencies {
compile 'io.card:android-sdk:[5.3.0,6.0.0)'
}
Drop-In will include a menu icon to scan cards when card.io is included.
Here are a few ways to get in touch:
Subscribe to our Google Group to be notified when SDK releases go out.
Braintree Android Drop-In is open source and available under the MIT license. See the LICENSE file for more info.