Drop-in UI

Setup and Integrationanchor

important

The SSL certificates for all Braintree SDKs are set to expire by June 31, 2025. This will impact existing versions of the SDK in published versions of your app. To reduce the impact, upgrade the Android SDK to version 4.45.0+ or version 5.0.0+ for the new SSL certifications.

If you do not decommission your app versions that include the older SDK versions or force upgrade your app with the updated certificates by the expiration date, 100% of your customer traffic will fail.

Configurationanchor

To use the Drop-in UI, you'll need to get a tokenization key from the Control Panel or you can generate a client token on your server.

Setupanchor

Gradleanchor

Use Gradle to integrate with the Braintree Android SDK.

In your app's build.gradle, add the following:

  1. Groovy
dependencies {
  implementation 'com.braintreepayments.api:drop-in:6.13.0'
}

Client-side implementationanchor

Starting Drop-inanchor

First, create a DropInClient in the onCreate method of an Android Activity or Fragment. Implement the DropInListener interface as well to receive callback notifications from the SDK.

Then, to launch the Drop-in UI call DropInClient#launchDropIn(DropInRequest):

  1. Java
  2. Kotlin
public class MyActivity extends AppCompatActivity implements DropInListener {

  private DropInClient dropInClient;

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // DropInClient can also be instantiated with a tokenization key
    dropInClient = new DropInClient(this, new ExampleClientTokenProvider());

    // Make sure to register listener in onCreate
    dropInClient.setListener(this);
  }

  private void launchDropIn() {
    DropInRequest dropInRequest = new DropInRequest();
    dropInClient.launchDropIn(dropInRequest);
  }
  
  @Override
  public void onDropInSuccess(@NonNull DropInResult dropInResult) {  
    String paymentMethodNonce = dropInResult.getPaymentMethodNonce().getString();
    // use the result to update your UI and send the payment method nonce to your server
  }

  @Override
  public void onDropInFailure(@NonNull Exception error) {
    if (error instanceof UserCanceledException) {
      // the user canceled
    } else {
      // handle error
    }
  }
}

Configuring payment methodsanchor

Additional steps are required for the Drop-in UI to accept payment methods other than cards. After completing the Drop-in setup instructions, follow the steps below for each payment method type.

PayPalanchor

Construct a PayPalCheckoutRequest or PayPalVaultRequest, and add it to your DropInRequest:

  1. Java
  2. Kotlin
PayPalVaultRequest payPalRequest = new PayPalVaultRequest();
dropInRequest.setPayPalRequest(payPalRequest);

Google Payanchor

In order for Drop-in to support Google Pay, you must ensure you've added the required meta-data tag in your AndroidManifest.xml.

Construct a GooglePayRequest, and add it to your DropInRequest:

  1. Java
  2. Kotlin
GooglePayRequest googlePayRequest = new GooglePayRequest();
googlePayRequest.setTransactionInfo(TransactionInfo.newBuilder()
  .setTotalPrice("1.00")
  .setTotalPriceStatus(WalletConstants.TOTAL_PRICE_STATUS_FINAL)
  .setCurrencyCode("USD")
  .build());
googlePayRequest.setBillingAddressRequired(true);

dropInRequest.setGooglePayRequest(googlePayRequest);

If using a client token with a customer id, the Google Pay card will not automatically be vaulted. You can use the payment method nonce to create a payment method on your server.

Venmoanchor

To support Venmo payments in the Drop-in UI, make sure to follow the browser switch setup instructions in the Client SDK Setup.

Construct a VenmoRequest, and add it to your DropInRequest:

  1. Java
  2. Kotlin
VenmoRequest venmoRequest = new VenmoRequest(VenmoPaymentMethodUsage.MULTI_USE);
dropInRequest.setVenmoRequest(venmoRequest);

3D Secureanchor

Drop-in supports 3D Secure verification. To use 3D Secure in your integration, construct a ThreeDSecureRequest with an amount and add it to your DropInRequest:

  1. Java
  2. Kotlin
ThreeDSecureRequest threeDSecureRequest = new ThreeDSecureRequest();
threeDSecureRequest.setAmount("10");
dropInRequest.setThreeDSecureRequest(threeDSecureRequest);

Once you have added 3D Secure to Drop-in, you will need to complete the server-side implementation for 3D Secure.

Displaying the most recently added payment methodanchor

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.

  1. Java
  2. Kotlin
DropInClient dropInClient = new DropInClient(this, new ExampleClientTokenProvider());
dropInClient.fetchMostRecentPaymentMethod(this, (dropInResult, error) -> {
  if (error != null) {
    // an error occurred
  } else if (dropInResult != null) {
    if (dropInResult.getPaymentMethodType() != null) {
      DropInPaymentMethod paymentMethodType = dropInResult.getPaymentMethodType();

      // use the icon and name to show in your UI
      int icon = paymentMethodType.getDrawable();
      int name = paymentMethodType.getLocalizedName();

      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 {
        // Use the payment method show in your UI and charge the user
        // at the time of checkout.
        PaymentMethodNonce paymentMethod = dropInResult.getPaymentMethodNonce();
      }
    } else {
      // there was no existing payment method
    }
  }
});

Browser Switchanchor

The Drop-in, in most cases, handles browser switching internally. Specifying an <intent-filter /> in AndroidManifest.xml is most often no longer required. Any payment method that requires a browser switch will work automatically.

On the other hand, there are some scenarios that will require you to set a custom URL scheme for browser switch deep linking. For example, if your applicationId contains uppercase letters, you will need to override the default deep link configuration set by the DropIn library.

Internally we use a manifest placeholder to support deep linking into DropInActivity. You can override the deep link intent filter for DropInActivity by placing the following xml snippet in your app's AndroidManifest.xml:

  1. XML
<activity android:name="com.braintreepayments.api.DropInActivity"
  android:exported="true"
  tools:node="merge"
  >
  <intent-filter tools:node="removeAll" />
  <intent-filter>
    <action android:name="android.intent.action.VIEW" />
    <data android:scheme="my-custom-url-scheme" />
    <category android:name="android.intent.category.DEFAULT" />
    <category android:name="android.intent.category.BROWSABLE" />
  </intent-filter>
</activity>

You can then set the custom url scheme on DropInRequest to align with the overridden AndroidManifest.xml value:

  1. Java
  2. Kotlin
dropInRequest.setCustomUrlScheme("my-custom-url-scheme");

Once set, the DropIn SDK will use this custom url scheme when deep linking instead of the default one.

Next stepsanchor


Next Page: Customization