com.braintreepayments.api.dropin.DropInRequest Java Examples

The following examples show how to use com.braintreepayments.api.dropin.DropInRequest. 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: FlutterBraintreeDropIn.java    From FlutterBraintree with MIT License 6 votes vote down vote up
private static void readGooglePaymentParameters(DropInRequest dropInRequest, MethodCall call) {
  HashMap<String, Object> arg = call.argument("googlePaymentRequest");
  if (arg == null) {
    dropInRequest.disableGooglePayment();
    return;
  }
  GooglePaymentRequest googlePaymentRequest = new GooglePaymentRequest()
          .transactionInfo(TransactionInfo.newBuilder()
                  .setTotalPrice((String) arg.get("totalPrice"))
                  .setCurrencyCode((String) arg.get("currencyCode"))
                  .setTotalPriceStatus(WalletConstants.TOTAL_PRICE_STATUS_FINAL)
                  .build())
          .billingAddressRequired((Boolean) arg.get("billingAddressRequired"))
          .googleMerchantId((String) arg.get("merchantID"));
  dropInRequest.googlePaymentRequest(googlePaymentRequest);
}
 
Example #2
Source File: MainActivity.java    From braintree_android with MIT License 6 votes vote down vote up
private DropInRequest getDropInRequest() {
    GooglePaymentRequest googlePaymentRequest = new GooglePaymentRequest()
            .transactionInfo(TransactionInfo.newBuilder()
                    .setCurrencyCode(Settings.getGooglePaymentCurrency(this))
                    .setTotalPrice("1.00")
                    .setTotalPriceStatus(WalletConstants.TOTAL_PRICE_STATUS_FINAL)
                    .build())
            .allowPrepaidCards(Settings.areGooglePaymentPrepaidCardsAllowed(this))
            .billingAddressFormat(WalletConstants.BILLING_ADDRESS_FORMAT_FULL)
            .billingAddressRequired(Settings.isGooglePaymentBillingAddressRequired(this))
            .emailRequired(Settings.isGooglePaymentEmailRequired(this))
            .phoneNumberRequired(Settings.isGooglePaymentPhoneNumberRequired(this))
            .shippingAddressRequired(Settings.isGooglePaymentShippingAddressRequired(this))
            .shippingAddressRequirements(ShippingAddressRequirements.newBuilder()
                    .addAllowedCountryCodes(Settings.getGooglePaymentAllowedCountriesForShipping(this))
                    .build())
            .googleMerchantId(Settings.getGooglePaymentMerchantId(this));

    return new DropInRequest()
            .amount("1.00")
            .clientToken(mAuthorization)
            .collectDeviceData(Settings.shouldCollectDeviceData(this))
            .requestThreeDSecureVerification(Settings.isThreeDSecureEnabled(this))
            .googlePaymentRequest(googlePaymentRequest);
}
 
Example #3
Source File: SupportedPaymentMethodAdapterUnitTest.java    From braintree-android-drop-in with MIT License 6 votes vote down vote up
@Test
public void callsOnPaymentMethodSelectedListenerWhenPaymentMethodClicked() {
    Configuration configuration = getConfiguration(true, true, true, true);
    PaymentMethodSelectedListener listener = mock(PaymentMethodSelectedListener.class);

    SupportedPaymentMethodsAdapter adapter = new SupportedPaymentMethodsAdapter(
            RuntimeEnvironment.application, listener);
    adapter.setup(configuration, new DropInRequest(), true, true);

    adapter.getView(0, null, null).callOnClick();
    adapter.getView(1, null, null).callOnClick();
    adapter.getView(2, null, null).callOnClick();
    adapter.getView(3, null, null).callOnClick();

    verify(listener).onPaymentMethodSelected(PaymentMethodType.PAYPAL);
    verify(listener).onPaymentMethodSelected(PaymentMethodType.PAY_WITH_VENMO);
    verify(listener).onPaymentMethodSelected(PaymentMethodType.UNKNOWN);
    verify(listener).onPaymentMethodSelected(PaymentMethodType.GOOGLE_PAYMENT);
    verifyNoMoreInteractions(listener);
}
 
Example #4
Source File: EditCardView.java    From braintree-android-drop-in with MIT License 6 votes vote down vote up
public void setup(AppCompatActivity activity, Configuration configuration, DropInRequest dropInRequest) {
    mConfiguration = configuration;

    boolean showCardCheckbox = !Authorization.isTokenizationKey(dropInRequest.getAuthorization())
            && dropInRequest.isSaveCardCheckBoxShown();

    mCardForm.cardRequired(true)
            .expirationRequired(true)
            .cvvRequired(configuration.isCvvChallengePresent())
            .postalCodeRequired(configuration.isPostalCodeChallengePresent())
            .cardholderName(dropInRequest.getCardholderNameStatus())
            .saveCardCheckBoxVisible(showCardCheckbox)
            .saveCardCheckBoxChecked(dropInRequest.getDefaultVaultSetting())
            .setup(activity);
    mCardForm.setOnCardFormSubmitListener(this);

    mAnimatedButtonView.setClickListener(this);
}
 
Example #5
Source File: MainActivity.java    From braintree-android-drop-in with MIT License 6 votes vote down vote up
public void launchDropIn(View v) {
    DropInRequest dropInRequest = new DropInRequest()
            .clientToken(mAuthorization)
            .requestThreeDSecureVerification(Settings.isThreeDSecureEnabled(this))
            .collectDeviceData(Settings.shouldCollectDeviceData(this))
            .googlePaymentRequest(getGooglePaymentRequest())
            .maskCardNumber(true)
            .maskSecurityCode(true)
            .allowVaultCardOverride(Settings.isSaveCardCheckBoxVisible(this))
            .vaultCard(Settings.defaultVaultSetting(this))
            .vaultManager(Settings.isVaultManagerEnabled(this))
            .cardholderNameStatus(Settings.getCardholderNameStatus(this));
    if (Settings.isThreeDSecureEnabled(this)) {
        dropInRequest.threeDSecureRequest(demoThreeDSecureRequest());
    }

    startActivityForResult(dropInRequest.getIntent(this), DROP_IN_REQUEST);
}
 
Example #6
Source File: SupportedPaymentMethodAdapterUnitTest.java    From braintree-android-drop-in with MIT License 5 votes vote down vote up
@Test
public void allPaymentMethodsAvailableIfEnabled() {
    Configuration configuration = getConfiguration(true, true, true, true);

    SupportedPaymentMethodsAdapter adapter = new SupportedPaymentMethodsAdapter(
            RuntimeEnvironment.application, null);
    adapter.setup(configuration, new DropInRequest(), true, true);

    assertEquals(4, adapter.getCount());
    assertEquals(PaymentMethodType.PAYPAL, adapter.getItem(0));
    assertEquals(PaymentMethodType.PAY_WITH_VENMO, adapter.getItem(1));
    assertEquals(PaymentMethodType.UNKNOWN, adapter.getItem(2));
    assertEquals(PaymentMethodType.GOOGLE_PAYMENT, adapter.getItem(3));
}
 
Example #7
Source File: FlutterBraintreeDropIn.java    From FlutterBraintree with MIT License 5 votes vote down vote up
@Override
public void onMethodCall(MethodCall call, Result result) {
  if (call.method.equals("start")) {
    String clientToken = call.argument("clientToken");
    String tokenizationKey = call.argument("tokenizationKey");
    DropInRequest dropInRequest = new DropInRequest()
            .amount((String) call.argument("amount"))
            .collectDeviceData((Boolean) call.argument("collectDeviceData"))
            .requestThreeDSecureVerification((Boolean) call.argument("requestThreeDSecureVerification"))
            .maskCardNumber((Boolean) call.argument("maskCardNumber"))
            .vaultManager((Boolean) call.argument("vaultManagerEnabled"));

    if (clientToken != null)
      dropInRequest.clientToken(clientToken);
    else if (tokenizationKey != null)
      dropInRequest.tokenizationKey(tokenizationKey);

    readGooglePaymentParameters(dropInRequest, call);
    readPayPalParameters(dropInRequest, call);
    if (!((Boolean) call.argument("venmoEnabled")))
      dropInRequest.disableVenmo();
    if (!((Boolean) call.argument("cardEnabled")))
      dropInRequest.disableCard();

    if (activeResult != null) {
      result.error("drop_in_already_running", "Cannot launch another Drop-in activity while one is already running.", null);
      return;
    }
    this.activeResult = result;
    activity.startActivityForResult(dropInRequest.getIntent(activity), DROP_IN_REQUEST_CODE);
  } else {
    result.notImplemented();
  }
}
 
Example #8
Source File: FlutterBraintreeDropIn.java    From FlutterBraintree with MIT License 5 votes vote down vote up
private static void readPayPalParameters(DropInRequest dropInRequest, MethodCall call) {
  HashMap<String, Object> arg = call.argument("paypalRequest");
  if (arg == null) {
    dropInRequest.disablePayPal();
    return;
  }
  String amount = (String) arg.get("amount");
  PayPalRequest paypalRequest = amount == null ? new PayPalRequest() : new PayPalRequest(amount);
  paypalRequest.currencyCode((String) arg.get("currencyCode"))
          .displayName((String) arg.get("displayName"))
          .billingAgreementDescription((String) arg.get("billingAgreementDescription"));
  dropInRequest.paypalRequest(paypalRequest);
}
 
Example #9
Source File: SupportedPaymentMethodAdapterUnitTest.java    From braintree-android-drop-in with MIT License 5 votes vote down vote up
@Test
public void googlePayNotAvailableIfDisabledInDropInRequest() {
    Configuration configuration = getConfiguration(false, false, false, true);
    DropInRequest dropInRequest = new DropInRequest()
            .disableGooglePayment();

    SupportedPaymentMethodsAdapter adapter = new SupportedPaymentMethodsAdapter(
            RuntimeEnvironment.application, null);
    adapter.setup(configuration, dropInRequest, true, false);

    assertEquals(0, adapter.getCount());
}
 
Example #10
Source File: SupportedPaymentMethodAdapterUnitTest.java    From braintree-android-drop-in with MIT License 5 votes vote down vote up
@Test
public void prefersGooglePayOverGooglePaymentIfBothEnabled() {
    Configuration configuration = getConfiguration(false, false, false, true);
    DropInRequest dropInRequest = new DropInRequest();

    SupportedPaymentMethodsAdapter adapter = new SupportedPaymentMethodsAdapter(
            RuntimeEnvironment.application, null);
    adapter.setup(configuration, dropInRequest, true, false);

    assertEquals(1, adapter.getCount());
    assertEquals(PaymentMethodType.GOOGLE_PAYMENT, adapter.getItem(0));
}
 
Example #11
Source File: SupportedPaymentMethodAdapterUnitTest.java    From braintree-android-drop-in with MIT License 5 votes vote down vote up
@Test
public void googlePaymentNotAvailableIfDisabledInDropInRequest() {
    Configuration configuration = getConfiguration(false, false, false, true);
    DropInRequest dropInRequest = new DropInRequest()
            .disableGooglePayment()
            .disableGooglePayment();

    SupportedPaymentMethodsAdapter adapter = new SupportedPaymentMethodsAdapter(
            RuntimeEnvironment.application, null);
    adapter.setup(configuration, dropInRequest, true, false);

    assertEquals(0, adapter.getCount());
}
 
Example #12
Source File: SupportedPaymentMethodAdapterUnitTest.java    From braintree-android-drop-in with MIT License 5 votes vote down vote up
@Test
public void venmoNotAvailableIfDisabledInDropInRequest() {
    Configuration configuration = getConfiguration(false, true, false, false);
    DropInRequest dropInRequest = new DropInRequest()
            .disableVenmo();

    SupportedPaymentMethodsAdapter adapter = new SupportedPaymentMethodsAdapter(
            RuntimeEnvironment.application, null);
    adapter.setup(configuration, dropInRequest, false, false);

    assertEquals(0, adapter.getCount());
}
 
Example #13
Source File: SupportedPaymentMethodAdapterUnitTest.java    From braintree-android-drop-in with MIT License 5 votes vote down vote up
@Test
public void paypalNotAvailableIfDisabledInDropInRequest() {
    Configuration configuration = getConfiguration(true, false, false, false);
    DropInRequest dropInRequest = new DropInRequest()
            .disablePayPal();

    SupportedPaymentMethodsAdapter adapter = new SupportedPaymentMethodsAdapter(
            RuntimeEnvironment.application, null);
    adapter.setup(configuration, dropInRequest, false, false);

    assertEquals(0, adapter.getCount());
}
 
Example #14
Source File: SupportedPaymentMethodAdapterUnitTest.java    From braintree-android-drop-in with MIT License 5 votes vote down vote up
@Test
public void cardsNotAvailableIfDisableInDropInRequest() {
    Configuration configuration = getConfiguration(false, false, true, false);
    DropInRequest dropInRequest = new DropInRequest()
            .disableCard();

    SupportedPaymentMethodsAdapter adapter = new SupportedPaymentMethodsAdapter(
            RuntimeEnvironment.application, null);
    adapter.setup(configuration, dropInRequest, false, false);

    assertEquals(0, adapter.getCount());
}
 
Example #15
Source File: SupportedPaymentMethodAdapterUnitTest.java    From braintree-android-drop-in with MIT License 5 votes vote down vote up
@Test
public void cardsAvailableIfOnlyUnionPayPresentAndSupported() {
    Configuration configuration = getConfiguration(false, false, false, false);
    when(configuration.getCardConfiguration().getSupportedCardTypes())
            .thenReturn(new HashSet<>(Arrays.asList(PaymentMethodType.UNIONPAY.getCanonicalName())));

    SupportedPaymentMethodsAdapter adapter = new SupportedPaymentMethodsAdapter(
            RuntimeEnvironment.application, null);
    adapter.setup(configuration, new DropInRequest(), false, true);

    assertEquals(1, adapter.getCount());
    assertEquals(PaymentMethodType.UNKNOWN, adapter.getItem(0));
}
 
Example #16
Source File: SupportedPaymentMethodAdapterUnitTest.java    From braintree-android-drop-in with MIT License 5 votes vote down vote up
@Test
public void cardsNotAvailableIfOnlyUnionPayPresentAndNotSupported() {
    Configuration configuration = getConfiguration(false, false, false, false);
    when(configuration.getCardConfiguration().getSupportedCardTypes())
            .thenReturn(new HashSet<>(Arrays.asList(PaymentMethodType.UNIONPAY.getCanonicalName())));

    SupportedPaymentMethodsAdapter adapter = new SupportedPaymentMethodsAdapter(
            RuntimeEnvironment.application, null);
    adapter.setup(configuration, new DropInRequest(), false, false);

    assertEquals(0, adapter.getCount());
}
 
Example #17
Source File: SupportedPaymentMethodAdapterUnitTest.java    From braintree-android-drop-in with MIT License 5 votes vote down vote up
@Test
public void cardsAvailableIfUnionPayNotSupportedAndOtherCardsPresent() {
    Configuration configuration = getConfiguration(false, false, true, false);

    SupportedPaymentMethodsAdapter adapter = new SupportedPaymentMethodsAdapter(
            RuntimeEnvironment.application, null);
    adapter.setup(configuration, new DropInRequest(), false, false);

    assertEquals(1, adapter.getCount());
    assertEquals(PaymentMethodType.UNKNOWN, adapter.getItem(0));
}
 
Example #18
Source File: SupportedPaymentMethodAdapterUnitTest.java    From braintree-android-drop-in with MIT License 5 votes vote down vote up
@Test
public void noPaymentMethodsAvailableIfNotEnabled() {
    Configuration configuration = getConfiguration(false, false, false, false);

    SupportedPaymentMethodsAdapter adapter = new SupportedPaymentMethodsAdapter(
            RuntimeEnvironment.application, null);
    adapter.setup(configuration, new DropInRequest(), false, false);

    assertEquals(0, adapter.getCount());
}
 
Example #19
Source File: EditCardViewUnitTest.java    From braintree-android-drop-in with MIT License 5 votes vote down vote up
@Test
public void setup_withDropInRequestShowingSaveCardCheckBoxAndNotPreChecked_showsSaveCardCheckboxNotChecked() {
            Configuration configuration = new TestConfigurationBuilder()
            .buildConfiguration();
    DropInRequest dropInRequest = new DropInRequest()
            .allowVaultCardOverride(true)
            .vaultCard(false);

    mView.setup(mActivity, configuration, dropInRequest);

    CheckBox checkBox = mView.findViewById(R.id.bt_card_form_save_card_checkbox);
    assertThat(checkBox).isVisible();
    assertThat(checkBox).isNotChecked();
}
 
Example #20
Source File: EditCardViewUnitTest.java    From braintree-android-drop-in with MIT License 5 votes vote down vote up
@Test
public void setup_withDropInRequestShowingSaveCardCheckBoxAndPreChecked_showsSaveCardCheckboxChecked() {
    Configuration configuration = new TestConfigurationBuilder()
            .buildConfiguration();
    DropInRequest dropInRequest = new DropInRequest()
            .allowVaultCardOverride(true)
            .vaultCard(true);

    mView.setup(mActivity, configuration, dropInRequest);

    CheckBox checkBox = mView.findViewById(R.id.bt_card_form_save_card_checkbox);
    assertThat(checkBox).isVisible();
    assertThat(checkBox).isChecked();
}
 
Example #21
Source File: EditCardViewUnitTest.java    From braintree-android-drop-in with MIT License 5 votes vote down vote up
@Test
public void setup_withDropInRequestHidingSaveCardCheckBox_hidesSaveCardCheckbox() {
    Configuration configuration = new TestConfigurationBuilder()
            .buildConfiguration();
    DropInRequest dropInRequest = new DropInRequest()
            .allowVaultCardOverride(false);

    mView.setup(mActivity, configuration, dropInRequest);

    assertThat(mView.findViewById(R.id.bt_card_form_save_card_checkbox)).isNotVisible();
}
 
Example #22
Source File: EditCardViewUnitTest.java    From braintree-android-drop-in with MIT License 5 votes vote down vote up
@Test
public void setup_withDropInRequestShowingSaveCardCheckBox_showsSaveCardCheckbox() {
    Configuration configuration = new TestConfigurationBuilder()
            .buildConfiguration();
    DropInRequest dropInRequest = new DropInRequest()
            .allowVaultCardOverride(true);

    mView.setup(mActivity, configuration, dropInRequest);

    assertThat(mView.findViewById(R.id.bt_card_form_save_card_checkbox)).isVisible();
}
 
Example #23
Source File: EditCardViewUnitTest.java    From braintree-android-drop-in with MIT License 5 votes vote down vote up
@Test
public void setup_withSaveCardCheckboxVisibleAndTokenizationKey_hidesSaveCardCheckbox() {
    Configuration configuration = new TestConfigurationBuilder()
            .buildConfiguration();
    DropInRequest dropInRequest = new DropInRequest()
            .allowVaultCardOverride(true)
            .tokenizationKey("some_tokenization_key");

    mView.setup(mActivity, configuration, dropInRequest);

    CheckBox checkBox = mView.findViewById(R.id.bt_card_form_save_card_checkbox);
    assertThat(checkBox).isNotVisible();
}
 
Example #24
Source File: EditCardViewUnitTest.java    From braintree-android-drop-in with MIT License 5 votes vote down vote up
@Test
public void setup_withoutSaveCardCheckBoxProperties_saveCardCheckboxCheckedAndHidden() {
    Configuration configuration = new TestConfigurationBuilder()
            .buildConfiguration();
    DropInRequest dropInRequest = new DropInRequest();

    mView.setup(mActivity, configuration, dropInRequest);

    CheckBox checkBox = mView.findViewById(R.id.bt_card_form_save_card_checkbox);
    assertThat(checkBox).isNotVisible();
    assertThat(checkBox).isChecked();
}
 
Example #25
Source File: SupportedPaymentMethodsAdapter.java    From braintree-android-drop-in with MIT License 5 votes vote down vote up
public void setup(Configuration configuration, DropInRequest dropInRequest,
                  boolean googlePayEnabled, boolean unionpaySupported) {
    if (dropInRequest.isPayPalEnabled() && configuration.isPayPalEnabled()) {
        mAvailablePaymentMethods.add(PaymentMethodType.PAYPAL);
    }

    if (dropInRequest.isVenmoEnabled() && configuration.getPayWithVenmo().isEnabled(mContext)) {
        mAvailablePaymentMethods.add(PaymentMethodType.PAY_WITH_VENMO);
    }

    if (dropInRequest.isCardEnabled()) {
        Set<String> supportedCardTypes =
                new HashSet<>(configuration.getCardConfiguration().getSupportedCardTypes());
        if (!unionpaySupported) {
            supportedCardTypes.remove(PaymentMethodType.UNIONPAY.getCanonicalName());
        }
        if (supportedCardTypes.size() > 0) {
            mAvailablePaymentMethods.add(PaymentMethodType.UNKNOWN);
        }
    }

    if (googlePayEnabled) {
        if (dropInRequest.isGooglePaymentEnabled()) {
            mAvailablePaymentMethods.add(PaymentMethodType.GOOGLE_PAYMENT);
        }
    }
}
 
Example #26
Source File: RNBraintreeDropInModule.java    From react-native-braintree-payments-drop-in with MIT License 5 votes vote down vote up
@ReactMethod
public void show(final ReadableMap options, final Promise promise) {
  isVerifyingThreeDSecure = false;

  if (!options.hasKey("clientToken")) {
    promise.reject("NO_CLIENT_TOKEN", "You must provide a client token");
    return;
  }

  Activity currentActivity = getCurrentActivity();
  if (currentActivity == null) {
    promise.reject("NO_ACTIVITY", "There is no current activity");
    return;
  }

  DropInRequest dropInRequest = new DropInRequest().clientToken(options.getString("clientToken"));

  if (options.hasKey("threeDSecure")) {
    final ReadableMap threeDSecureOptions = options.getMap("threeDSecure");
    if (!threeDSecureOptions.hasKey("amount")) {
      promise.reject("NO_3DS_AMOUNT", "You must provide an amount for 3D Secure");
      return;
    }

    isVerifyingThreeDSecure = true;

    dropInRequest
    .amount(String.valueOf(threeDSecureOptions.getDouble("amount")))
    .requestThreeDSecureVerification(true);
  }

  mPromise = promise;
  currentActivity.startActivityForResult(dropInRequest.getIntent(currentActivity), DROP_IN_REQUEST);
}
 
Example #27
Source File: EditCardView.java    From braintree-android-drop-in with MIT License 4 votes vote down vote up
/**
 * Deprecated. Use {@link #setup(AppCompatActivity, Configuration, DropInRequest)}
 */
@Deprecated
public void setup(AppCompatActivity activity, Configuration configuration) {
    setup(activity, configuration, new DropInRequest());
}