com.braintreepayments.api.dropin.DropInResult Java Examples

The following examples show how to use com.braintreepayments.api.dropin.DropInResult. 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
protected void onResume() {
    super.onResume();

    if (mPurchased) {
        mPurchased = false;
        clearNonce();

        try {
            if (ClientToken.fromString(mAuthorization) instanceof ClientToken) {
                DropInResult.fetchDropInResult(this, mAuthorization, this);
            } else {
                mAddPaymentMethodButton.setVisibility(VISIBLE);
            }
        } catch (InvalidArgumentException e) {
            mAddPaymentMethodButton.setVisibility(VISIBLE);
        }
    }
}
 
Example #2
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 #3
Source File: MainActivity.java    From braintree-android-drop-in with MIT License 6 votes vote down vote up
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    safelyCloseLoadingView();

    if (resultCode == RESULT_OK) {
        DropInResult result = data.getParcelableExtra(DropInResult.EXTRA_DROP_IN_RESULT);
        displayResult(result.getPaymentMethodNonce(), result.getDeviceData());
        mPurchaseButton.setEnabled(true);
    } else if (resultCode != RESULT_CANCELED) {
        safelyCloseLoadingView();
        showDialog(((Exception) data.getSerializableExtra(DropInActivity.EXTRA_ERROR))
                .getMessage());
    }
}
 
Example #4
Source File: MainActivity.java    From braintree_android with MIT License 6 votes vote down vote up
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    if (resultCode == RESULT_OK) {
        if (requestCode == DROP_IN_REQUEST) {
            DropInResult result = data.getParcelableExtra(DropInResult.EXTRA_DROP_IN_RESULT);
            displayNonce(result.getPaymentMethodNonce(), result.getDeviceData());
        } else {
            Parcelable returnedData = data.getParcelableExtra(EXTRA_PAYMENT_RESULT);
            String deviceData = data.getStringExtra(EXTRA_DEVICE_DATA);
            if (returnedData instanceof PaymentMethodNonce) {
                displayNonce((PaymentMethodNonce) returnedData, deviceData);
            }

            mCreateTransactionButton.setEnabled(true);
        }
    } else if (resultCode != RESULT_CANCELED) {
        showDialog(((Exception) data.getSerializableExtra(DropInActivity.EXTRA_ERROR)).getMessage());
    }
}
 
Example #5
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 #6
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;
}
 
Example #7
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());
    }
}