Setup and Integration

ConfigurationAnchorIcon

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.

SetupAnchorIcon

GradleAnchorIcon

Use Gradle to integrate with the Braintree Android SDK.

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

Client-side implementationAnchorIcon

Starting Drop-inAnchorIcon

Configuring payment methodsAnchorIcon

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.

Google PayAnchorIcon

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

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.

VenmoAnchorIcon

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 SecureAnchorIcon

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 :

Displaying the most recently added payment methodAnchorIcon

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 SwitchAnchorIcon

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 stepsAnchorIcon


Next Page: Customization