Configuration

In order to use the Drop-in UI, you'll first need to generate a client token on your server.

note

Upgrade to Android v2 to use a tokenization key, a static form of client authorization obtained from the Control Panel.

Setup

There are several ways to include Braintree's Drop-in in your project.

Gradle

Gradle is the preferred build system for working with the Braintree Android SDK.

In your build.gradle, add the following:

Groovy
Copy
Copied
dependencies {
  compile 'com.braintreepayments.api:braintree:1+'
}

Maven

You must be using android-maven-plugin.

In your pom.xml add the following:

XML
Copy
Copied
<dependencies>
  <dependency>
    <groupId>com.braintreepayments.api</groupId>
    <artifactId>braintree</artifactId>
    <version>[1.0.0,)</version>
    <type>aar</type>
  </dependency>
</dependencies>

Client-side implementation

If you're going to launch the Drop-in UI from a button, and you've set the button's onClick handler in XML via android:onClick="onBraintreeSubmit", add the method as:

Java
Copy
Copied
public void onBraintreeSubmit(View v) {
  Intent intent = new Intent(context, BraintreePaymentActivity.class);
    .putExtra(BraintreePaymentActivity.EXTRA_CLIENT_TOKEN, clientToken);

  // REQUEST_CODE is arbitrary and is only used within this activity.
  startActivityForResult(intent, REQUEST_CODE);
}

When your user provides payment information, your app receives a paymentMethodNonce in your calling Activity's onActivityResult, which you will override to get the response or any possible errors:

Java
Copy
Copied
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
  if (requestCode == REQUEST_CODE) {
    switch (resultCode) {
      case BraintreePaymentActivity.RESULT_OK:
        String paymentMethodNonce = data
          .getStringExtra(BraintreePaymentActivity.EXTRA_PAYMENT_METHOD_NONCE);
        break;
      case BraintreePaymentActivity.BRAINTREE_RESULT_DEVELOPER_ERROR:
      case BraintreePaymentActivity.BRAINTREE_RESULT_SERVER_ERROR:
      case BraintreePaymentActivity.BRAINTREE_RESULT_SERVER_UNAVAILABLE:
        // handle errors here, a throwable may be available in
        // data.getSerializableExtra(BraintreePaymentActivity.EXTRA_ERROR_MESSAGE)
        break;
      default:
        break;
    }
  }
}

Configuring payment methods

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.

PayPal

In order for your Drop-in to support PayPal payments, you must allow for PayPal's browser switch by adding an intent filter to your AndroidManifest.xml.

Venmo

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

3D Secure

To support 3D Secure verification in the Drop-in UI, make sure to follow the browser switch setup instructions in the Client SDK Setup. Once setup, 3D Secure must be enabled on your DropInRequest along with an amount:

Java
Copy
Copied
DropInRequest dropInRequest = new DropInRequest()
    .amount("1.00")
    .requestThreeDSecureVerification(true);

Displaying the 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 DropInResult#fetchDropInResult. A payment method will only be returned when using a client token created with a customer_id.

Java
Copy
Copied
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();

            PaymentMethodType paymentMethodType = result.getPaymentMethodType();
            if (paymentMethodType == PaymentMethodType.ANDROID_PAY || paymentMethodType == PaymentMethodType.GOOGLE_PAYMENT) {
                // The last payment method the user used was Android Pay or Google Pay.
                // The Android/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 = result.getPaymentMethodNonce();
            }
        } else {
            // there was no existing payment method
        }
    }
  }
});

Next steps

Next Page: Customization →

Still have questions?

If you can’t find an answer, contact our Support team