Migrating from v2 to v3

While Android v3 is a major version bump and indicates breaking changes, we kept these changes to a minimum. In fact, depending how you are integrating with the Braintree Android SDK, you may not experience any breaking changes.

Motivations

Fragment has been deprecated

Android P will deprecate the Android framework's version of Fragment (i.e. android.app.Fragment).

In our Android v2 SDK, BraintreeFragment extended the Android framework Fragment for the reason that it would be the most available copy of the Fragment class. With the decision that this version of Fragment would be deprecated, we needed BraintreeFragment to inherit from one of the newer Fragment classes. This would be considered a breaking change for the reason that integrators may be using BraintreeFragment in a way that differs from our integration guide.

AndroidX

A new suite of libraries – AndroidX – is now available for Android. We decided to switch from the Android support libraries to AndroidX in this version of our SDK, since we are already making breaking changes to BraintreeFragment. If you currently use AndroidX, this gets you one step closer to not needing Jetifier!

If your app is not using AndroidX yet, we recommend migrating from the Android support libraries to AndroidX.

minSdkVersion 21

Braintree now requires HTTPS connections to be TLSv1.2, so this update bumps the minimum Android SDK version to one that fully supports TLSv1.2. Android 21 is the first available Android version that has enabled TLSv1.2 by default.

Changed APIs

BraintreeFragment

The biggest change is that BraintreeFragment now inherits from androidx.fragment.app.Fragment, which uses a support FragmentManager to attach to your AndroidX version of AppCompatActivity.

If your app is not using AndroidX, Android has an excellent guide on Migrating to AndroidX.

If your app is using Activity, upgrade it to an AndroidX AppCompatActivity.

Your previous Activity hosting BraintreeFragment may look something like this:

Java
// ...
import android.app.Activity;
// ...

public class MainActivity extends Activity {

  private BraintreeFragment mBraintreeFragment;

  @Override
  public void onCreate(Bundle savedInstanceState) {
    try {
      mBraintreeFragment = BraintreeFragment.newInstance(this, AUTHORIZATION_FROM_SERVER);
    } catch (InvalidArgumentException e) {
      // the authorization provided was of an invalid form
    }
  }
}

It should now look like this:

Java
// ...
import androidx.appcompat.app.AppCompatActivity;
// ...

public class MainActivity extends AppCompatActivity {

  private BraintreeFragment mBraintreeFragment;

  @Override
  public void onCreate(Bundle savedInstanceState) {
    try {
      mBraintreeFragment = BraintreeFragment.newInstance(this, AUTHORIZATION_FROM_SERVER);
    } catch (InvalidArgumentException e) {
      // the authorization provided was of an invalid form
    }
  }
}

Android Pay

Android Pay was deprecated when Google Pay was made available. See the Android Pay to Google Pay migration guide and Google Pay Client-Side Implementation instructions to transition to Google Pay.

PayPal Future Payments

PayPal Future Payments were deprecated when PayPal Billing Agreements were made available. Our current PayPal Vault guide shows an integration using Billing Agreements. If you have a PayPal Vault flow integration that still uses Future Payments, convert to using Billing Agreements.

CardBuilder country code setters

CardBuilder#countryCode should be used for inputting country code. The following country code setters have been removed:

  • countryCodeAlpha2(String)
  • countryCodeAlpha3(String)
  • countryCodeNumeric(String)
  • countryName(String)

3D Secure web view flow

3D Secure now only uses the browser-switch flow. See our 3D Secure Client-side Implementation instructions.