Braintree/src/main/java/com/braintreepayments/api/BraintreeFragment.java
public static BraintreeFragment newInstance(AppCompatActivity activity, String authorization)
            throws InvalidArgumentException {
        if (activity == null) {
            throw new InvalidArgumentException("Activity is null");
        }

        FragmentManager fm = activity.getSupportFragmentManager();
        BraintreeFragment braintreeFragment = (BraintreeFragment) fm.findFragmentByTag(TAG);
        if (braintreeFragment == null) {
            braintreeFragment = new BraintreeFragment();
            Bundle bundle = new Bundle();

            try {
                Authorization auth = Authorization.fromString(authorization);
                bundle.putParcelable(EXTRA_AUTHORIZATION_TOKEN, auth);
            } catch (InvalidArgumentException e) {
                throw new InvalidArgumentException("Tokenization Key or client token was invalid.");
            }

            bundle.putString(EXTRA_SESSION_ID, UUIDHelper.getFormattedUUID());
            bundle.putString(EXTRA_INTEGRATION_TYPE, IntegrationType.get(activity));
            braintreeFragment.setArguments(bundle);

            try {
                if (VERSION.SDK_INT >= VERSION_CODES.N) {
                    try {
                        fm.beginTransaction().add(braintreeFragment, TAG).commitNow();
                    } catch (IllegalStateException | NullPointerException e) {
                        fm.beginTransaction().add(braintreeFragment, TAG).commit();
                        try {
                            fm.executePendingTransactions();
                        } catch (IllegalStateException ignored) {}
                    }
                } else {
                    fm.beginTransaction().add(braintreeFragment, TAG).commit();
                    try {
                        fm.executePendingTransactions();
                    } catch (IllegalStateException ignored) {}
                }
            } catch (IllegalStateException e) {
                throw new InvalidArgumentException(e.getMessage());
            }
        }

        braintreeFragment.mContext = activity.getApplicationContext();

        return braintreeFragment;
    }
public static BraintreeFragment newInstance(AppCompatActivity activity, String authorization)
            throws InvalidArgumentException {
        if (activity == null) {
            throw new InvalidArgumentException("Activity is null");
        }

        FragmentManager fm = activity.getSupportFragmentManager();
        BraintreeFragment braintreeFragment = (BraintreeFragment) fm.findFragmentByTag(TAG);
        if (braintreeFragment == null) {
            braintreeFragment = new BraintreeFragment();
            Bundle bundle = new Bundle();

            try {
                Authorization auth = Authorization.fromString(authorization);
                bundle.putParcelable(EXTRA_AUTHORIZATION_TOKEN, auth);
            } catch (InvalidArgumentException e) {
                throw new InvalidArgumentException("Tokenization Key or client token was invalid.");
            }

            bundle.putString(EXTRA_SESSION_ID, UUIDHelper.getFormattedUUID());
            bundle.putString(EXTRA_INTEGRATION_TYPE, IntegrationType.get(activity));
            braintreeFragment.setArguments(bundle);

            try {
                if (VERSION.SDK_INT >= VERSION_CODES.N) {
                    try {
                        fm.beginTransaction().add(braintreeFragment, TAG).commitNow();
                    } catch (IllegalStateException | NullPointerException e) {
                        fm.beginTransaction().add(braintreeFragment, TAG).commit();
                        try {
                            fm.executePendingTransactions();
                        } catch (IllegalStateException ignored) {}
                    }
                } else {
                    fm.beginTransaction().add(braintreeFragment, TAG).commit();
                    try {
                        fm.executePendingTransactions();
                    } catch (IllegalStateException ignored) {}
                }
            } catch (IllegalStateException e) {
                throw new InvalidArgumentException(e.getMessage());
            }
        }

        braintreeFragment.mContext = activity.getApplicationContext();

        return braintreeFragment;
    }
public static BraintreeFragment newInstance ( AppCompatActivity activity , String authorization ) throws InvalidArgumentException { if ( activity == null ) { throw new InvalidArgumentException ( "Activity is null" ) ; } FragmentManager fm = activity . getSupportFragmentManager ( ) ; BraintreeFragment braintreeFragment = ( BraintreeFragment ) fm . findFragmentByTag ( TAG ) ; if ( braintreeFragment == null ) { braintreeFragment = new BraintreeFragment ( ) ; Bundle bundle = new Bundle ( ) ; try { Authorization auth = Authorization . fromString ( authorization ) ; bundle . putParcelable ( EXTRA_AUTHORIZATION_TOKEN , auth ) ; } catch ( InvalidArgumentException e ) { throw new InvalidArgumentException ( "Tokenization Key or client token was invalid." ) ; } bundle . putString ( EXTRA_SESSION_ID , UUIDHelper . getFormattedUUID ( ) ) ; bundle . putString ( EXTRA_INTEGRATION_TYPE , IntegrationType . get ( activity ) ) ; braintreeFragment . setArguments ( bundle ) ; try { if ( VERSION . SDK_INT >= VERSION_CODES . N ) { try { fm . beginTransaction ( ) . add ( braintreeFragment , TAG ) . commitNow ( ) ; } catch ( IllegalStateException | NullPointerException e ) { fm . beginTransaction ( ) . add ( braintreeFragment , TAG ) . commit ( ) ; try { fm . executePendingTransactions ( ) ; } catch ( IllegalStateException ignored ) { } } } else { fm . beginTransaction ( ) . add ( braintreeFragment , TAG ) . commit ( ) ; try { fm . executePendingTransactions ( ) ; } catch ( IllegalStateException ignored ) { } } } catch ( IllegalStateException e ) { throw new InvalidArgumentException ( e . getMessage ( ) ) ; } } braintreeFragment . mContext = activity . getApplicationContext ( ) ; return braintreeFragment ; }
Create a new instance of {@link BraintreeFragment} using the client token and add it to the
{@link AppCompatActivity}'s {@link FragmentManager}.

@param activity The {@link AppCompatActivity} to add the {@link BraintreeFragment} to.
@param authorization The tokenization key or client token to use.
@return {@link BraintreeFragment}
@throws InvalidArgumentException If the tokenization key or client token is not valid or cannot be
parsed.
Create a new instance of { @link BraintreeFragment } using the client token and add it to the { @link AppCompatActivity } s { @link FragmentManager } .