Java Code Examples for com.braintreepayments.api.dropin.DropInResult#getPaymentMethodNonce()

The following examples show how to use com.braintreepayments.api.dropin.DropInResult#getPaymentMethodNonce() . 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: MainActivity.java    From braintree-android-drop-in with MIT License 6 votes vote down vote up
@Override
public void onResult(DropInResult result) {
    if (result.getPaymentMethodType() == null) {
        mAddPaymentMethodButton.setVisibility(VISIBLE);
    } else {
        mAddPaymentMethodButton.setVisibility(GONE);

        mPaymentMethodType = result.getPaymentMethodType();

        mPaymentMethodIcon.setImageResource(result.getPaymentMethodType().getDrawable());
        if (result.getPaymentMethodNonce() != null) {
            displayResult(result.getPaymentMethodNonce(), result.getDeviceData());
        }

        mPurchaseButton.setEnabled(true);
    }
}
 
Example 2
Source File: FlutterBraintreeDropIn.java    From FlutterBraintree with MIT License 5 votes vote down vote up
@Override
public boolean onActivityResult(int requestCode, int resultCode, Intent data)  {
  if (activeResult == null)
    return false;

  switch (requestCode) {
    case DROP_IN_REQUEST_CODE:
      if (resultCode == Activity.RESULT_OK) {
        DropInResult dropInResult = data.getParcelableExtra(DropInResult.EXTRA_DROP_IN_RESULT);
        PaymentMethodNonce paymentMethodNonce = dropInResult.getPaymentMethodNonce();
        HashMap<String, Object> result = new HashMap<String, Object>();

        HashMap<String, Object> nonceResult = new HashMap<String, Object>();
        nonceResult.put("nonce", paymentMethodNonce.getNonce());
        nonceResult.put("typeLabel", paymentMethodNonce.getTypeLabel());
        nonceResult.put("description", paymentMethodNonce.getDescription());
        nonceResult.put("isDefault", paymentMethodNonce.isDefault());

        result.put("paymentMethodNonce", nonceResult);
        result.put("deviceData", dropInResult.getDeviceData());
        activeResult.success(result);
      } else if (resultCode == Activity.RESULT_CANCELED) {
        activeResult.success(null);
      } else {
        Exception error = (Exception) data.getSerializableExtra(DropInActivity.EXTRA_ERROR);
        activeResult.error("braintree_error", error.getMessage(), null);
      }
      activeResult = null;
      return true;
    default:
      return false;
  }
}
 
Example 3
Source File: RNBraintreeDropInModule.java    From react-native-braintree-payments-drop-in with MIT License 5 votes vote down vote up
@Override
public void onActivityResult(Activity activity, int requestCode, int resultCode, Intent data) {
  super.onActivityResult(requestCode, resultCode, data);

  if (requestCode != DROP_IN_REQUEST || mPromise == null) {
    return;
  }

  if (resultCode == Activity.RESULT_OK) {
    DropInResult result = data.getParcelableExtra(DropInResult.EXTRA_DROP_IN_RESULT);
    PaymentMethodNonce paymentMethodNonce = result.getPaymentMethodNonce();

    if (isVerifyingThreeDSecure && paymentMethodNonce instanceof CardNonce) {
      CardNonce cardNonce = (CardNonce) paymentMethodNonce;
      ThreeDSecureInfo threeDSecureInfo = cardNonce.getThreeDSecureInfo();
      if (!threeDSecureInfo.isLiabilityShiftPossible()) {
        mPromise.reject("3DSECURE_NOT_ABLE_TO_SHIFT_LIABILITY", "3D Secure liability cannot be shifted");
      } else if (!threeDSecureInfo.isLiabilityShifted()) {
        mPromise.reject("3DSECURE_LIABILITY_NOT_SHIFTED", "3D Secure liability was not shifted");
      } else {
        resolvePayment(paymentMethodNonce);
      }
    } else {
      resolvePayment(paymentMethodNonce);
    }
  } else if (resultCode == Activity.RESULT_CANCELED) {
    mPromise.reject("USER_CANCELLATION", "The user cancelled");
  } else {
    Exception exception = (Exception) data.getSerializableExtra(DropInActivity.EXTRA_ERROR);
    mPromise.reject(exception.getMessage(), exception.getMessage());
  }

  mPromise = null;
}