Java Code Examples for com.braintreepayments.api.BraintreeFragment#newInstance()

The following examples show how to use com.braintreepayments.api.BraintreeFragment#newInstance() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FlutterBraintreeCustom.java    From FlutterBraintree with MIT License 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_flutter_braintree_custom);
    try {
        Intent intent = getIntent();
        braintreeFragment = BraintreeFragment.newInstance(this, intent.getStringExtra("authorization"));
        String type = intent.getStringExtra("type");
        if (type.equals("tokenizeCreditCard")) {
            tokenizeCreditCard();
        } else if (type.equals("requestPaypalNonce")) {
            requestPaypalNonce();
        } else {
            throw new Exception("Invalid request type: " + type);
        }
    } catch (Exception e) {
        Intent result = new Intent();
        result.putExtra("error", e);
        setResult(2, result);
        finish();
        return;
    }
}
 
Example 2
Source File: Braintree.java    From react-native-braintree-android with MIT License 6 votes vote down vote up
@ReactMethod
public void setup(final String token, final Callback successCallback, final Callback errorCallback) {
  try {
    this.mBraintreeFragment = BraintreeFragment.newInstance(getCurrentActivity(), token);
    this.mBraintreeFragment.addListener(new PaymentMethodNonceCreatedListener() {
      @Override
      public void onPaymentMethodNonceCreated(PaymentMethodNonce paymentMethodNonce) {
        nonceCallback(paymentMethodNonce.getNonce());
      }
    });
    this.setToken(token);
    successCallback.invoke(this.getToken());
  } catch (InvalidArgumentException e) {
    errorCallback.invoke(e.getMessage());
  }
}
 
Example 3
Source File: MainActivity.java    From braintree-android-drop-in with MIT License 5 votes vote down vote up
@Override
protected void onAuthorizationFetched() {
    try {
        mBraintreeFragment = BraintreeFragment.newInstance(this, mAuthorization);

        if (ClientToken.fromString(mAuthorization) instanceof ClientToken) {
            DropInResult.fetchDropInResult(this, mAuthorization, this);
        } else {
            mAddPaymentMethodButton.setVisibility(VISIBLE);
        }
    } catch (InvalidArgumentException e) {
        showDialog(e.getMessage());
    }
}
 
Example 4
Source File: BaseActivity.java    From braintree-android-drop-in with MIT License 5 votes vote down vote up
protected BraintreeFragment getBraintreeFragment() throws InvalidArgumentException {
    if (TextUtils.isEmpty(mDropInRequest.getAuthorization())) {
        throw new InvalidArgumentException("A client token or tokenization key must be " +
                "specified in the " + DropInRequest.class.getSimpleName());
    }

    try {
        mClientTokenPresent = Authorization.fromString(mDropInRequest.getAuthorization())
                instanceof ClientToken;
    } catch (InvalidArgumentException e) {
        mClientTokenPresent = false;
    }

    return BraintreeFragment.newInstance(this, mDropInRequest.getAuthorization());
}
 
Example 5
Source File: DropInResultUnitTest.java    From braintree-android-drop-in with MIT License 5 votes vote down vote up
private BraintreeFragment setupFragment(BraintreeHttpClient httpClient) throws InvalidArgumentException {
    BraintreeFragment fragment = BraintreeFragment.newInstance(mActivity,
            base64EncodedClientTokenFromFixture("client_token.json"));
    setHttpClient(fragment, httpClient);
    ConfigurationManagerTestUtils.setFetchingConfiguration(false);

    return fragment;
}
 
Example 6
Source File: VenmoActivity.java    From braintree_android with MIT License 5 votes vote down vote up
@Override
protected void onAuthorizationFetched() {
    try {
        mBraintreeFragment = BraintreeFragment.newInstance(this, mAuthorization);
    } catch (InvalidArgumentException e) {
        onError(e);
    }
}
 
Example 7
Source File: PayPalTwoFactorAuthActivity.java    From braintree_android with MIT License 5 votes vote down vote up
@Override
protected void onAuthorizationFetched() {
    try {
        if (!Settings.SANDBOX_INDIA_ENV_NAME.equals(Settings.getEnvironment(this))) {
            onError(new Exception("To use feature, enable the \"Sandbox India\" environment."));
            return;
        }

        mBraintreeFragment = BraintreeFragment.newInstance(this, mAuthorization);
        mBillingAgreementButton.setEnabled(true);
    } catch (InvalidArgumentException e) {
        onError(e);
    }
}
 
Example 8
Source File: VisaCheckoutActivity.java    From braintree_android with MIT License 5 votes vote down vote up
@Override
protected void onAuthorizationFetched() {
    try {
        mBraintreeFragment = BraintreeFragment.newInstance(this, mAuthorization);
    } catch (InvalidArgumentException e) {
        onError(e);
    }

    VisaCheckout.createProfileBuilder(mBraintreeFragment, this);
}
 
Example 9
Source File: LocalPaymentsActivity.java    From braintree_android with MIT License 5 votes vote down vote up
@Override
protected void onAuthorizationFetched() {
    if (!Settings.SANDBOX_ENV_NAME.equals(Settings.getEnvironment(this))) {
        onError(new Exception("To use this feature, enable the \"Sandbox\" environment."));
        return;
    }

    try {
        mBraintreeFragment = BraintreeFragment.newInstance(this, Settings.getLocalPaymentsTokenizationKey(this));
        mIdealButton.setEnabled(true);
    } catch (InvalidArgumentException e) {
        onError(e);
    }
}
 
Example 10
Source File: PayPalActivity.java    From braintree_android with MIT License 5 votes vote down vote up
@Override
protected void onAuthorizationFetched() {
    try {
        mBraintreeFragment = BraintreeFragment.newInstance(this, mAuthorization);
    } catch (InvalidArgumentException e) {
        onError(e);
    }

    enableButtons(true);
}
 
Example 11
Source File: CardActivity.java    From braintree_android with MIT License 5 votes vote down vote up
@Override
protected void onAuthorizationFetched() {
    try {
        mBraintreeFragment = BraintreeFragment.newInstance(this, mAuthorization);
    } catch (InvalidArgumentException e) {
        onError(e);
    }

    mPurchaseButton.setEnabled(true);
}
 
Example 12
Source File: GooglePaymentActivity.java    From braintree_android with MIT License 5 votes vote down vote up
@Override
protected void onAuthorizationFetched() {
    try {
        mBraintreeFragment = BraintreeFragment.newInstance(this, mAuthorization);
    } catch (InvalidArgumentException e) {
        onError(e);
    }
}
 
Example 13
Source File: PreferredPaymentMethodsActivity.java    From braintree_android with MIT License 5 votes vote down vote up
@Override
protected void onAuthorizationFetched() {
    try {
        mBraintreeFragment = BraintreeFragment.newInstance(this, mAuthorization);
    } catch (InvalidArgumentException e) {
        onError(e);
    }

    mPreferredPaymentMethodsButton.setEnabled(true);
}