Client SDK/Migration

Migrating from v1 to v2

We've made some big changes in the 2nd major version of the Braintree Android SDK which will simplify your integration and make your life easier.

Motivations

In a nutshell, we want to make your integration experience as simple and easy as possible. In our major remodel we sought to reduce complexity and improve ease of use.

Added APIs

BraintreeFragment

The single biggest breaking change is the introduction of a new class, BraintreeFragment, which is designed to replace the Braintree class. BraintreeFragment is a headless Fragment which is added to your activity. By centralizing our architecture around a Fragment object, we can tie into lifecycle events, removing the need to notify us of them manually.

Create an instance of BraintreeFragment by calling BraintreeFragment#newInstance(Activity, authorization). Under the hood, we'll attach the fragment to your activity, and, if your activity implements any Braintree interface, we'll attach those as well. You should keep a reference to a BraintreeFragment in any activity where you expect to use it, and should make the call to BraintreeFragment#newInstance in your activity's onCreate method.

Moved APIs

Payment Method Creation

In the spirit of keeping things simple, we've moved quite a bit of our logic into dedicated classes, such as Card, PayPal, and AndroidPay. Each of these classes contains one or more static methods which you'll use to authorize various payment instruments.

For example, previously your call to add a PayPal account might have looked something like this:

Changed APIs

Previously, the Braintree SDK contained two interfaces which you could implement to be notified of a new Payment method or nonce. Now, there's just one. Instead of implententing PaymentMethodCreatedListener or PaymentMethodNonceListener, you'll just implement PaymentMethodNonceCreatedListener, in which you'll get an instance of PaymentMethodNonce.
A PaymentMethodNonce is an abstract class which is inherited by classes such as CardNonce, PayPalAccountNonce, and AndroidPayCardNonce, which themselves contain specific information regarding your payment method of choice. You can get a nonce from any PaymentMethodNonce.