Braintree Android Drop-In is a readymade UI that allows you to accept card and alternative payments in your Android app.
- All new UI and integration for Drop-In
- Fetch a customer's saved payment method without showing UI
- Added UnionPay support to Drop-In
Please create an issue with any comments or concerns.
Add the dependency in your build.gradle
:
dependencies {
implementation 'com.braintreepayments.api:drop-in:4.1.0'
}
To use the latest build from the master
branch use:
dependencies {
implementation 'com.braintreepayments.api:drop-in:4.1.1-SNAPSHOT'
}
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 == RESULT_OK) {
DropInResult result = data.getParcelableExtra(DropInResult.EXTRA_DROP_IN_RESULT);
String paymentMethodNonce = result.getPaymentMethodNonce().getNonce();
// send paymentMethodNonce to your server
} else if (resultCode == 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.GOOGLE_PAY) {
// The last payment method the user used was GooglePayment. The GooglePayment
// flow will need to be performed by the user again at the time of checkout
// using GooglePayment#requestPayment(...). No PaymentMethodNonce will be
// present in result.getPaymentMethodNonce(), this is only an indication that
// the user last used GooglePayment.
} else {
// show the payment method in your UI and charge the user at the
// time of checkout using the nonce: paymentMethod.getNonce()
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 {
implementation 'io.card:android-sdk:5.+'
}
Drop-In will include a menu icon to scan cards when card.io is included.
- Read the javadocs
- Read the docs
- Find a bug? Open an issue
- Want to contribute? Check out contributing guidelines and submit a pull request.
Here are a few ways to get in touch:
- GitHub Issues - For generally applicable issues and feedback
- Braintree Support / support@braintreepayments.com - for personal support at any phase of integration
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.