Set Up Your Clientanchor

important

The SSL certificates for all Braintree SDKs are set to expire by June 30, 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.

Client side payment token flowDiagram demonstrating the required interaction between the client, Braintree servers and your server.

Android SDK setupanchor

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

  1. Kotlin
  2. Groovy
dependencies {
    implementation("com.braintreepayments.api:drop-in:6.13.0")
}

For other installation techniques and notes, see the Android Client SDK Guide.

Get a client tokenanchor

Client tokens are optional: You can initialize Braintree with a tokenization key instead of a client token. If you are using a tokenization key, you may skip this section and use the tokenization key for your authorization instead.

Your server is responsible for generating a client token, which contains the authorization and configuration details that your client needs to initialize the client SDK.

Initialize Braintree with a ClientTokenProvider to asychronously fetch a client token on your behalf when it is needed in the SDK.

Try it nowanchor

So you can jump right in we generated a tokenization key for you. This is for testing purposes only! When you're ready to build your own integration, use your own tokenization key or generate your own client token.

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

  private DropInClient dropInClient;

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    dropInClient = new DropInClient(this, dropInRequest, "sandbox_f252zhq7_hh4cpc39zq4rgjcg");
    dropInClient.setListener(this);
  }
}

Present Drop-in UIanchor

At this point, you are ready to collect payment information from your customer.

Drop-in is the easiest way to get started. It provides a fully fledged payments experience out of the box. You can also choose to create a custom UI and then tokenize the payment information directly.

  1. Java
  2. Kotlin
public void onBraintreeSubmit(View v) {
  DropInRequest dropInRequest = new DropInRequest();
  dropInClient.launchDropInForResult(this, DROPIN_REQUEST_CODE);
}

To handle the result of the Drop-in flow, implement a DropInListener:

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

  @Override
  public void onDropInSuccess(@NonNull DropInResult dropInResult) {
      // send dropInResult.getPaymentMethodNonce().getString() to server
  }

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

Test your integrationanchor

Create a sandbox accountanchor

If you haven't already, sign up for a free Braintree sandbox account:

Sign Up for a Braintree Sandbox Account

Log in to obtain your sandbox API credentials. You'll need your:

  • Sandbox merchant ID
  • Public key
  • Private key

Use these credentials for your development and testing.

important

When you go live, you will need to replace your sandbox API credentials with production API credentials.

Test valuesanchor

When testing in the sandbox, be sure to use our test card numbers (e.g. 4111111111111111) and nonces (e.g. fake-valid-nonce). Real payment method data will not work in the sandbox. See our Testing page for more details.

Send payment method nonce to serveranchor

Send the resulting payment method nonce to your server (this example uses Android Async Http Client - adapt to your own setup):

  1. Android
void postNonceToServer(String nonce) {
  AsyncHttpClient client = new AsyncHttpClient();
  RequestParams params = new RequestParams();
  params.put("payment_method_nonce", nonce);
  client.post("http://your-server/checkout", params,
    new AsyncHttpResponseHandler() {
      // Your implementation here
    }
  );
}

world.greeted = trueanchor

At this point, you should have a working client-side checkout flow. When your user provides payment information, you receive a payment method nonce and send it to your server.

Next, your server closes the loop by using the payment method nonce to create a transaction.


Next Page: Simple Server