use of com.braintreepayments.api.models.Authorization in project braintree_android by braintree.
the class ThreeDSecureVerificationTest method getFragment.
private BraintreeFragment getFragment(String authorization, String configuration) {
try {
Authorization auth = Authorization.fromString(authorization);
writeMockConfiguration(getTargetContext(), auth.getConfigUrl(), auth.getBearer(), configuration);
BraintreeFragment fragment = BraintreeFragment.newInstance(mActivity, authorization);
while (!fragment.isAdded()) {
try {
Thread.sleep(10);
} catch (InterruptedException ignored) {
}
}
return fragment;
} catch (InvalidArgumentException e) {
fail(e.getMessage());
return new BraintreeFragment();
}
}
use of com.braintreepayments.api.models.Authorization in project braintree_android by braintree.
the class BraintreeFragment method newInstance.
/**
* Create a new instance of {@link BraintreeFragment} using the client token and add it to the
* {@link Activity}'s {@link FragmentManager}.
*
* @param activity The {@link Activity} to add the {@link Fragment} 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.
*/
public static BraintreeFragment newInstance(Activity activity, String authorization) throws InvalidArgumentException {
if (activity == null) {
throw new InvalidArgumentException("Activity is null");
}
FragmentManager fm = activity.getFragmentManager();
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;
}
Aggregations