com.braintreepayments.api.models.CardBuilder Java Examples

The following examples show how to use com.braintreepayments.api.models.CardBuilder. 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: ThreeDSecureUnitTest.java    From braintree_android with MIT License 6 votes vote down vote up
@Test
public void performVerification_withCardBuilder_tokenizesAndPerformsVerification() {
    CardNonce cardNonce = mock(CardNonce.class);
    when(cardNonce.getNonce()).thenReturn("card-nonce");
    MockStaticTokenizationClient.mockTokenizeSuccess(cardNonce);
    MockStaticCardinal.initCompletesSuccessfully("df-reference-id");

    CardBuilder cardBuilder = new CardBuilder();
    ThreeDSecureRequest request = new ThreeDSecureRequest()
            .amount("10");

    ThreeDSecure.performVerification(mFragment, cardBuilder, request);

    ArgumentCaptor<String> captor = ArgumentCaptor.forClass(String.class);

    verifyStatic();
    TokenizationClient.versionedPath(captor.capture());

    assertTrue(captor.getValue().contains("card-nonce"));
}
 
Example #2
Source File: CardTest.java    From braintree_android with MIT License 6 votes vote down vote up
@Test
public void tokenize_whenInvalidCountryCode_callsErrorCallbackWithDetailedError() throws Exception {
    CardBuilder cardBuilder = new CardBuilder()
            .cardNumber(VISA)
            .expirationDate("08/20")
            .countryCode("ABC");

    final CountDownLatch countDownLatch = new CountDownLatch(1);
    BraintreeFragment fragment = setupBraintreeFragment(new TestClientTokenBuilder().build());
    fragment.addListener(new BraintreeErrorListener() {
        @Override
        public void onError(Exception error) {
            assertEquals("Country code (alpha3) is not an accepted country",
                    ((ErrorWithResponse) error).errorFor("creditCard").errorFor("billingAddress")
                            .getFieldErrors().get(0).getMessage());
            countDownLatch.countDown();
        }
    });

    Card.tokenize(fragment, cardBuilder);

    countDownLatch.await();
}
 
Example #3
Source File: CardTest.java    From braintree_android with MIT License 6 votes vote down vote up
@Ignore("Sample merchant account is not set up for postal code verification")
@Test(timeout = 10000)
public void tokenize_callsErrorCallbackForInvalidPostalCode() throws Exception {
    CardBuilder cardBuilder = new CardBuilder()
            .cardNumber(VISA)
            .expirationDate("08/20")
            .postalCode("20000");

    final CountDownLatch countDownLatch = new CountDownLatch(1);
    BraintreeFragment fragment = setupBraintreeFragment(
            new TestClientTokenBuilder().withPostalCodeVerification().build());
    fragment.addListener(new BraintreeErrorListener() {
        @Override
        public void onError(Exception error) {
            assertEquals("Postal code verification failed",
                    ((ErrorWithResponse) error).errorFor("creditCard").errorFor("billingAddress")
                            .getFieldErrors().get(0).getMessage());
            countDownLatch.countDown();
        }
    });

    Card.tokenize(fragment, cardBuilder);

    countDownLatch.await();
}
 
Example #4
Source File: CardTest.java    From braintree_android with MIT License 6 votes vote down vote up
@Test(timeout = 10000)
public void tokenize_tokenizesACardWithACompleteBillingAddress() throws Exception {
    CardBuilder cardBuilder = new CardBuilder()
            .cardNumber(VISA)
            .expirationDate("08/20")
            .cvv("123")
            .cardholderName("Joe Smith")
            .firstName("Joe")
            .lastName("Smith")
            .company("Company")
            .streetAddress("1 Main St")
            .extendedAddress("Unit 1")
            .locality("Some Town")
            .postalCode("12345")
            .region("Some Region")
            .countryCode("USA");

    assertTokenizationSuccessful(new TestClientTokenBuilder().build(), cardBuilder);
}
 
Example #5
Source File: CardTest.java    From braintree_android with MIT License 6 votes vote down vote up
@Ignore("Sample merchant account is not set up for CVV verification")
@Test(timeout = 10000)
public void tokenize_callsErrorCallbackForInvalidCvv() throws Exception {
    CardBuilder cardBuilder = new CardBuilder()
            .cardNumber(VISA)
            .expirationDate("08/20")
            .cvv("200");

    final CountDownLatch countDownLatch = new CountDownLatch(1);
    BraintreeFragment fragment = setupBraintreeFragment(new TestClientTokenBuilder().withCvvVerification().build());
    fragment.addListener(new BraintreeErrorListener() {
        @Override
        public void onError(Exception error) {
            assertEquals("CVV verification failed",
                    ((ErrorWithResponse) error).errorFor("creditCard").getFieldErrors().get(0).getMessage());
            countDownLatch.countDown();
        }
    });

    Card.tokenize(fragment, cardBuilder);

    countDownLatch.await();
}
 
Example #6
Source File: TokenizationClientUnitTest.java    From braintree_android with MIT License 6 votes vote down vote up
@Test
public void tokenize_tokenizesCardsWithGraphQLWhenEnabled() throws BraintreeException {
    BraintreeFragment fragment = new MockFragmentBuilder()
            .configuration(new TestConfigurationBuilder()
                    .graphQL()
                    .build())
            .build();
    CardBuilder cardBuilder = new CardBuilder();

    TokenizationClient.tokenize(fragment, cardBuilder, null);

    ArgumentCaptor<String> captor = ArgumentCaptor.forClass(String.class);
    verifyZeroInteractions(fragment.getHttpClient());
    verify(fragment.getGraphQLHttpClient()).post(captor.capture(), any(HttpResponseCallback.class));
    assertEquals(cardBuilder.buildGraphQL(fragment.getApplicationContext(), fragment.getAuthorization()),
            captor.getValue());
}
 
Example #7
Source File: ThreeDSecureV2UnitTest.java    From braintree_android with MIT License 6 votes vote down vote up
@Test
public void performVerification_withCardBuilder_tokenizesAndPerformsVerification() {
    CardNonce cardNonce = mock(CardNonce.class);
    when(cardNonce.getNonce()).thenReturn("card-nonce");
    MockStaticTokenizationClient.mockTokenizeSuccess(cardNonce);

    MockStaticCardinal.initCompletesSuccessfully("fake-df");

    CardBuilder cardBuilder = new CardBuilder();
    ThreeDSecureRequest request = new ThreeDSecureRequest()
            .amount("10");

    ThreeDSecure.performVerification(mFragment, cardBuilder, request);

    ArgumentCaptor<String> captor = ArgumentCaptor.forClass(String.class);

    verifyStatic();
    //noinspection ResultOfMethodCallIgnored
    TokenizationClient.versionedPath(captor.capture());

    assertTrue(captor.getValue().contains("card-nonce"));
}
 
Example #8
Source File: BraintreeFragmentTestUtils.java    From braintree_android with MIT License 6 votes vote down vote up
public static CardNonce tokenize(BraintreeFragment fragment, CardBuilder cardBuilder) {
    final CountDownLatch latch = new CountDownLatch(1);
    final CardNonce[] cardNonce = new CardNonce[1];
    PaymentMethodNonceCreatedListener listener = new PaymentMethodNonceCreatedListener() {
        @Override
        public void onPaymentMethodNonceCreated(PaymentMethodNonce paymentMethodNonce) {
            cardNonce[0] = (CardNonce) paymentMethodNonce;
            latch.countDown();
        }
    };
    fragment.addListener(listener);

    Card.tokenize(fragment, cardBuilder);

    try {
        latch.await();
    } catch (InterruptedException ignored) {}

    fragment.removeListener(listener);
    return cardNonce[0];
}
 
Example #9
Source File: TokenizationClientUnitTest.java    From braintree_android with MIT License 6 votes vote down vote up
@Test
public void tokenize_sendGraphQLAnalyticsEventOnSuccess() {
    BraintreeFragment fragment = new MockFragmentBuilder()
            .configuration(new TestConfigurationBuilder()
                    .graphQL()
                    .build())
            .graphQLSuccessResponse(stringFromFixture("response/graphql/credit_card.json"))
            .build();
    CardBuilder cardBuilder = new CardBuilder();

    TokenizationClient.tokenize(fragment, cardBuilder, new PaymentMethodNonceCallback() {
        @Override
        public void success(PaymentMethodNonce paymentMethodNonce) {}

        @Override
        public void failure(Exception exception) {}
    });

    verify(fragment).sendAnalyticsEvent("card.graphql.tokenization.success");
}
 
Example #10
Source File: TokenizationClientUnitTest.java    From braintree_android with MIT License 6 votes vote down vote up
@Test
public void tokenize_sendGraphQLAnalyticsEventOnFailure() {
    BraintreeFragment fragment = new MockFragmentBuilder()
            .configuration(new TestConfigurationBuilder()
                    .graphQL()
                    .build())
            .graphQLErrorResponse(ErrorWithResponse.fromGraphQLJson(stringFromFixture("errors/graphql/credit_card_error.json")))
            .build();
    CardBuilder cardBuilder = new CardBuilder();

    TokenizationClient.tokenize(fragment, cardBuilder, new PaymentMethodNonceCallback() {
        @Override
        public void success(PaymentMethodNonce paymentMethodNonce) {}

        @Override
        public void failure(Exception exception) {}
    });

    verify(fragment).sendAnalyticsEvent("card.graphql.tokenization.failure");
}
 
Example #11
Source File: ThreeDSecureTest.java    From braintree_android with MIT License 6 votes vote down vote up
@Test(timeout = 10000)
public void performVerification_postsPaymentMethodNonceToListenersWhenLookupReturnsACard()
        throws InterruptedException {
    String clientToken = new TestClientTokenBuilder().build();
    BraintreeFragment fragment = getFragmentWithAuthorization(mActivity, clientToken);
    String nonce = tokenize(fragment, new CardBuilder()
            .cardNumber("4000000000000051")
            .expirationDate("12/20")).getNonce();
    fragment.addListener(new PaymentMethodNonceCreatedListener() {
        @Override
        public void onPaymentMethodNonceCreated(PaymentMethodNonce paymentMethodNonce) {
            assertIsANonce(paymentMethodNonce.getNonce());
            assertEquals("51", ((CardNonce) paymentMethodNonce).getLastTwo());
            assertTrue(((CardNonce) paymentMethodNonce).getThreeDSecureInfo().wasVerified());
            mCountDownLatch.countDown();
        }
    });

    ThreeDSecure.performVerification(fragment, nonce, "5");

    mCountDownLatch.await();
}
 
Example #12
Source File: ThreeDSecureVerificationTest.java    From braintree_android with MIT License 6 votes vote down vote up
@Test(timeout = 10000)
public void performVerification_doesALookupAndReturnsACardAndANullACSUrlWhenAuthenticationIsNotRequired()
        throws InterruptedException {
    BraintreeFragment fragment = getFragment();
    fragment.addListener(new PaymentMethodNonceCreatedListener() {
        @Override
        public void onPaymentMethodNonceCreated(PaymentMethodNonce paymentMethodNonce) {
            assertIsANonce(paymentMethodNonce.getNonce());
            CardNonce cardNonce = (CardNonce) paymentMethodNonce;

            assertEquals("51", cardNonce.getLastTwo());
            assertFalse(cardNonce.getThreeDSecureInfo().isLiabilityShifted());
            assertFalse(cardNonce.getThreeDSecureInfo().isLiabilityShiftPossible());
            assertTrue(((CardNonce) paymentMethodNonce).getThreeDSecureInfo().wasVerified());

            mCountDownLatch.countDown();
        }
    });
    CardBuilder cardBuilder = new CardBuilder()
            .cardNumber(THREE_D_SECURE_VERIFICATON_NOT_REQUIRED)
            .expirationDate("12/20");

    ThreeDSecure.performVerification(fragment, cardBuilder, TEST_AMOUNT);

    mCountDownLatch.await();
}
 
Example #13
Source File: ThreeDSecureVerificationTest.java    From braintree_android with MIT License 6 votes vote down vote up
@Test(timeout = 10000)
public void performVerification_doesALookupAndReturnsACardWhenAuthenticationIsUnavailable()
        throws InterruptedException {
    BraintreeFragment fragment = getFragment();
    fragment.addListener(new PaymentMethodNonceCreatedListener() {
        @Override
        public void onPaymentMethodNonceCreated(PaymentMethodNonce paymentMethodNonce) {
            assertIsANonce(paymentMethodNonce.getNonce());
            CardNonce cardNonce = (CardNonce) paymentMethodNonce;

            assertEquals("69", cardNonce.getLastTwo());
            assertFalse(cardNonce.getThreeDSecureInfo().isLiabilityShifted());
            assertFalse(cardNonce.getThreeDSecureInfo().isLiabilityShiftPossible());
            assertTrue(((CardNonce) paymentMethodNonce).getThreeDSecureInfo().wasVerified());

            mCountDownLatch.countDown();
        }
    });
    CardBuilder cardBuilder = new CardBuilder()
            .cardNumber(THREE_D_SECURE_AUTHENTICATION_UNAVAILABLE)
            .expirationDate("12/20");

    ThreeDSecure.performVerification(fragment, cardBuilder, TEST_AMOUNT);

    mCountDownLatch.await();
}
 
Example #14
Source File: ThreeDSecureVerificationTest.java    From braintree_android with MIT License 6 votes vote down vote up
@Test(timeout = 10000)
public void performVerification_failsWithATokenizationKey() throws InterruptedException {
    String clientToken = new TestClientTokenBuilder().build();
    BraintreeFragment fragment = getFragment(TOKENIZATION_KEY, clientToken);
    fragment.addListener(new BraintreeErrorListener() {
        @Override
        public void onError(Exception error) {
            assertTrue(error instanceof AuthorizationException);
            assertEquals(
                    "Tokenization key authorization not allowed for this endpoint. Please use an authentication method with upgraded permissions",
                    error.getMessage());
            mCountDownLatch.countDown();
        }
    });
    CardBuilder cardBuilder = new CardBuilder()
            .cardNumber(THREE_D_SECURE_VERIFICATON)
            .expirationDate("12/20");

    ThreeDSecure.performVerification(fragment, cardBuilder, TEST_AMOUNT);

    mCountDownLatch.await();
}
 
Example #15
Source File: ThreeDSecure.java    From braintree_android with MIT License 6 votes vote down vote up
/**
 * @deprecated Use {{@link #performVerification(BraintreeFragment, ThreeDSecureRequest)}} for 3DS 2.0.
 *
 * Verification is associated with a transaction amount and your merchant account. To specify a
 * different merchant account (or, in turn, currency), you will need to specify the merchant
 * account id when <a href="https://developers.braintreepayments.com/android/sdk/overview/generate-client-token">
 * generating a client token</a>
 * <p>
 * During lookup the original payment method nonce is consumed and a new one is returned,
 * which points to the original payment method, as well as the 3D Secure verification.
 * Transactions created with this nonce will be 3D Secure, and benefit from the appropriate
 * liability shift if authentication is successful or fail with a 3D Secure failure.
 *
 * @param fragment    the {@link BraintreeFragment} backing the http request. This fragment will
 *                    also be responsible for handling callbacks to it's listeners
 * @param cardBuilder The cardBuilder created from raw details. Will be tokenized before
 *                    the 3D Secure verification if performed.
 * @param request     the {@link ThreeDSecureRequest} with information used for authentication.
 *                    Note that the nonce will be replaced with the nonce generated from the
 *                    cardBuilder.
 */
@Deprecated
public static void performVerification(final BraintreeFragment fragment,
                                       final CardBuilder cardBuilder,
                                       final ThreeDSecureRequest request) {
    if (request.getAmount() == null) {
        fragment.postCallback(new InvalidArgumentException("The ThreeDSecureRequest amount cannot be null"));
        return;
    }

    TokenizationClient.tokenize(fragment, cardBuilder, new PaymentMethodNonceCallback() {
        @Override
        public void success(PaymentMethodNonce paymentMethodNonce) {
            request.nonce(paymentMethodNonce.getNonce());

            performVerification(fragment, request);
        }

        @Override
        public void failure(Exception exception) {
            fragment.postCallback(exception);
        }
    });
}
 
Example #16
Source File: ThreeDSecure.java    From braintree_android with MIT License 6 votes vote down vote up
/**
 * @deprecated Use {{@link #performVerification(BraintreeFragment, CardBuilder, ThreeDSecureRequest)}} for 3DS 2.0.
 * <p>
 * The amount can be provided via {@link ThreeDSecureRequest#amount(String)}.
 */
@Deprecated
public static void performVerification(final BraintreeFragment fragment,
                                       final CardBuilder cardBuilder,
                                       final String amount) {
    TokenizationClient.tokenize(fragment, cardBuilder, new PaymentMethodNonceCallback() {
        @Override
        public void success(PaymentMethodNonce paymentMethodNonce) {
            performVerification(fragment, paymentMethodNonce.getNonce(), amount);
        }

        @Override
        public void failure(Exception exception) {
            fragment.postCallback(exception);
        }
    });
}
 
Example #17
Source File: Card.java    From braintree_android with MIT License 6 votes vote down vote up
/**
 * Create a {@link com.braintreepayments.api.models.CardNonce}.
 * <p>
 * On completion, returns the {@link com.braintreepayments.api.models.PaymentMethodNonce} to
 * {@link com.braintreepayments.api.interfaces.PaymentMethodNonceCreatedListener}.
 * <p>
 * If creation fails validation, {@link com.braintreepayments.api.interfaces.BraintreeErrorListener#onError(Exception)}
 * will be called with the resulting {@link com.braintreepayments.api.exceptions.ErrorWithResponse}.
 * <p>
 * If an error not due to validation (server error, network issue, etc.) occurs, {@link
 * com.braintreepayments.api.interfaces.BraintreeErrorListener#onError(Exception)}
 * will be called with the {@link Exception} that occurred.
 *
 * @param fragment {@link BraintreeFragment}
 * @param cardBuilder {@link CardBuilder}
 */
public static void tokenize(final BraintreeFragment fragment, final CardBuilder cardBuilder) {
    TokenizationClient.tokenize(fragment, cardBuilder, new PaymentMethodNonceCallback() {
        @Override
        public void success(PaymentMethodNonce paymentMethodNonce) {
            DataCollector.collectRiskData(fragment, paymentMethodNonce);

            fragment.postCallback(paymentMethodNonce);
            fragment.sendAnalyticsEvent("card.nonce-received");
        }

        @Override
        public void failure(Exception exception) {
            fragment.postCallback(exception);
            fragment.sendAnalyticsEvent("card.nonce-failed");
        }
    });
}
 
Example #18
Source File: TokenizationClient.java    From braintree_android with MIT License 6 votes vote down vote up
/**
 * Create a {@link PaymentMethodNonce} in the Braintree Gateway.
 * <p>
 * On completion, returns the {@link PaymentMethodNonce} to {@link PaymentMethodNonceCallback}.
 * <p>
 * If creation fails validation, {@link com.braintreepayments.api.interfaces.BraintreeErrorListener#onError(Exception)}
 * will be called with the resulting {@link ErrorWithResponse}.
 * <p>
 * If an error not due to validation (server error, network issue, etc.) occurs, {@link
 * com.braintreepayments.api.interfaces.BraintreeErrorListener#onError(Exception)} (Throwable)}
 * will be called with the {@link Exception} that occurred.
 *
 * @param paymentMethodBuilder {@link PaymentMethodBuilder} for the {@link PaymentMethodNonce}
 *        to be created.
 */
static void tokenize(final BraintreeFragment fragment, final PaymentMethodBuilder paymentMethodBuilder,
        final PaymentMethodNonceCallback callback) {
    paymentMethodBuilder.setSessionId(fragment.getSessionId());

    fragment.waitForConfiguration(new ConfigurationListener() {
        @Override
        public void onConfigurationFetched(Configuration configuration) {
            if (paymentMethodBuilder instanceof CardBuilder &&
                    configuration.getGraphQL().isFeatureEnabled(Features.TOKENIZE_CREDIT_CARDS)) {
                tokenizeGraphQL(fragment, (CardBuilder) paymentMethodBuilder, callback);
            } else {
                tokenizeRest(fragment, paymentMethodBuilder, callback);
            }
        }
    });
}
 
Example #19
Source File: ThreeDSecureTest.java    From braintree_android with MIT License 6 votes vote down vote up
@Test(timeout = 10000)
public void performVerification_acceptsACardBuilderAndPostsAPaymentMethodNonceToListener()
        throws InterruptedException {
    BraintreeFragment fragment = getFragmentWithAuthorization(mActivity,
            new TestClientTokenBuilder().build());
    fragment.addListener(new PaymentMethodNonceCreatedListener() {
        @Override
        public void onPaymentMethodNonceCreated(PaymentMethodNonce paymentMethodNonce) {
            assertIsANonce(paymentMethodNonce.getNonce());
            assertEquals("51", ((CardNonce) paymentMethodNonce).getLastTwo());
            assertTrue(((CardNonce) paymentMethodNonce).getThreeDSecureInfo().wasVerified());
            mCountDownLatch.countDown();
        }
    });
    CardBuilder cardBuilder = new CardBuilder()
            .cardNumber("4000000000000051")
            .expirationDate("12/20");

    ThreeDSecure.performVerification(fragment, cardBuilder, "5");

    mCountDownLatch.await();
}
 
Example #20
Source File: ThreeDSecureUnitTest.java    From braintree_android with MIT License 6 votes vote down vote up
@Test
public void performVerification_withCardBuilderFailsToTokenize_postsError() {
    MockStaticTokenizationClient.mockTokenizeFailure(new RuntimeException("Tokenization Failed"));

    CardBuilder cardBuilder = new CardBuilder();
    ThreeDSecureRequest request = new ThreeDSecureRequest()
            .amount("10");

    ThreeDSecure.performVerification(mFragment, cardBuilder, request);

    ArgumentCaptor<Exception> captor = ArgumentCaptor.forClass(Exception.class);
    verify(mFragment).postCallback(captor.capture());

    assertEquals("Tokenization Failed",
            captor.getValue().getMessage());
}
 
Example #21
Source File: TokenizationClientUnitTest.java    From braintree_android with MIT License 5 votes vote down vote up
@Test
public void tokenize_tokenizesCardsWithRestWhenGraphQLIsDisabled() {
    BraintreeFragment fragment = new MockFragmentBuilder().build();
    CardBuilder cardBuilder = new CardBuilder();

    TokenizationClient.tokenize(fragment, cardBuilder, null);

    ArgumentCaptor<String> captor = ArgumentCaptor.forClass(String.class);
    verifyZeroInteractions(fragment.getGraphQLHttpClient());
    verify(fragment.getHttpClient()).post(anyString(), captor.capture(), any(HttpResponseCallback.class));
    assertEquals(cardBuilder.build(), captor.getValue());
}
 
Example #22
Source File: TokenizationClientUnitTest.java    From braintree_android with MIT License 5 votes vote down vote up
@Test
public void tokenize_includesSessionIdInRequest() throws JSONException {
    BraintreeFragment fragment = new MockFragmentBuilder().build();
    when(fragment.getSessionId()).thenReturn("session-id");

    TokenizationClient.tokenize(fragment, new CardBuilder(), null);

    ArgumentCaptor<String> captor = ArgumentCaptor.forClass(String.class);
    verify(fragment.getHttpClient()).post(anyString(), captor.capture(), any(HttpResponseCallback.class));
    JSONObject data = new JSONObject(captor.getValue()).getJSONObject("_meta");
    assertEquals("session-id", data.getString("sessionId"));
}
 
Example #23
Source File: TokenizationClientUnitTest.java    From braintree_android with MIT License 5 votes vote down vote up
@Test
public void tokenize_sendGraphQLAnalyticsEventWhenEnabled() {
    BraintreeFragment fragment = new MockFragmentBuilder()
            .configuration(new TestConfigurationBuilder()
                    .graphQL()
                    .build())
            .build();
    CardBuilder cardBuilder = new CardBuilder();

    TokenizationClient.tokenize(fragment, cardBuilder, null);

    verify(fragment).sendAnalyticsEvent("card.graphql.tokenization.started");
}
 
Example #24
Source File: CardTest.java    From braintree_android with MIT License 5 votes vote down vote up
private void assertTokenizationSuccessful(String authorization, CardBuilder cardBuilder) throws Exception {
    final CountDownLatch countDownLatch = new CountDownLatch(1);
    BraintreeFragment fragment = setupBraintreeFragment(authorization);
    fragment.addListener(new PaymentMethodNonceCreatedListener() {
        @Override
        public void onPaymentMethodNonceCreated(PaymentMethodNonce paymentMethodNonce) {
            CardNonce cardNonce = (CardNonce) paymentMethodNonce;

            assertNotNull(cardNonce.getNonce());
            assertEquals("Visa", cardNonce.getCardType());
            assertEquals("1111", cardNonce.getLastFour());
            assertEquals("11", cardNonce.getLastTwo());
            assertEquals(BinData.UNKNOWN, cardNonce.getBinData().getPrepaid());
            assertEquals(BinData.UNKNOWN, cardNonce.getBinData().getHealthcare());
            assertEquals(BinData.UNKNOWN, cardNonce.getBinData().getDebit());
            assertEquals(BinData.UNKNOWN, cardNonce.getBinData().getDurbinRegulated());
            assertEquals(BinData.UNKNOWN, cardNonce.getBinData().getCommercial());
            assertEquals(BinData.UNKNOWN, cardNonce.getBinData().getPayroll());
            assertEquals(BinData.UNKNOWN, cardNonce.getBinData().getIssuingBank());
            assertEquals(BinData.UNKNOWN, cardNonce.getBinData().getCountryOfIssuance());
            assertEquals(BinData.UNKNOWN, cardNonce.getBinData().getProductId());
            assertFalse(cardNonce.getThreeDSecureInfo().wasVerified());

            countDownLatch.countDown();
        }
    });
    fragment.addListener(new BraintreeErrorListener() {
        @Override
        public void onError(Exception error) {
            throw new RuntimeException(error);
        }
    });

    Card.tokenize(fragment, cardBuilder);

    countDownLatch.await();
}
 
Example #25
Source File: CardUnitTest.java    From braintree_android with MIT License 5 votes vote down vote up
@Test
public void tokenize_sendsAnalyticsEventOnSuccess() {
    mockSuccessCallback();

    Card.tokenize(mBraintreeFragment, new CardBuilder());

    verify(mBraintreeFragment).sendAnalyticsEvent("card.nonce-received");
}
 
Example #26
Source File: CardActivity.java    From braintree_android with MIT License 5 votes vote down vote up
public void onPurchase(View v) {
    setProgressBarIndeterminateVisibility(true);

    if (mIsUnionPay) {
        UnionPayCardBuilder unionPayCardBuilder = new UnionPayCardBuilder()
                .cardNumber(mCardForm.getCardNumber())
                .expirationMonth(mCardForm.getExpirationMonth())
                .expirationYear(mCardForm.getExpirationYear())
                .cvv(mCardForm.getCvv())
                .postalCode(mCardForm.getPostalCode())
                .mobileCountryCode(mCardForm.getCountryCode())
                .mobilePhoneNumber(mCardForm.getMobileNumber())
                .smsCode(mSmsCode.getText().toString())
                .enrollmentId(mEnrollmentId);

        UnionPay.tokenize(mBraintreeFragment, unionPayCardBuilder);
    } else {
        CardBuilder cardBuilder = new CardBuilder()
                .cardNumber(mCardForm.getCardNumber())
                .expirationMonth(mCardForm.getExpirationMonth())
                .expirationYear(mCardForm.getExpirationYear())
                .cvv(mCardForm.getCvv())
                .validate(false) // TODO GQL currently only returns the bin if validate = false
                .postalCode(mCardForm.getPostalCode());

        Card.tokenize(mBraintreeFragment, cardBuilder);
    }
}
 
Example #27
Source File: ThreeDSecureVerificationTest.java    From braintree_android with MIT License 5 votes vote down vote up
@Test(timeout = 10000)
public void performVerification_doesALookupAndReturnsACardWhenThereIsALookupError() throws InterruptedException {
    BraintreeFragment fragment = getFragment();
    fragment.addListener(new PaymentMethodNonceCreatedListener() {
        @Override
        public void onPaymentMethodNonceCreated(PaymentMethodNonce paymentMethodNonce) {
            assertIsANonce(paymentMethodNonce.getNonce());
            CardNonce cardNonce = (CardNonce) paymentMethodNonce;

            assertEquals("77", cardNonce.getLastTwo());
            assertFalse(cardNonce.getThreeDSecureInfo().isLiabilityShifted());
            assertFalse(cardNonce.getThreeDSecureInfo().isLiabilityShiftPossible());
            assertTrue(((CardNonce) paymentMethodNonce).getThreeDSecureInfo().wasVerified());

            mCountDownLatch.countDown();
        }
    });

    fragment.addListener(new BraintreeErrorListener() {
        @Override
        public void onError(Exception error) {
            fail(error.getMessage());
        }
    });

    CardBuilder cardBuilder = new CardBuilder()
            .cardNumber(THREE_D_SECURE_LOOKUP_ERROR)
            .expirationDate("12/20");

    ThreeDSecure.performVerification(fragment, cardBuilder, TEST_AMOUNT);

    mCountDownLatch.await();
}
 
Example #28
Source File: ThreeDSecureVerificationTest.java    From braintree_android with MIT License 5 votes vote down vote up
@Test(timeout = 10000)
public void performVerification_doesALookupAndReturnsACardWhenThereIsAMPILookupError() throws InterruptedException {
    BraintreeFragment fragment = getFragment();
    fragment.addListener(new PaymentMethodNonceCreatedListener() {
        @Override
        public void onPaymentMethodNonceCreated(PaymentMethodNonce paymentMethodNonce) {
            assertIsANonce(paymentMethodNonce.getNonce());
            CardNonce cardNonce = (CardNonce) paymentMethodNonce;

            assertEquals("85", cardNonce.getLastTwo());
            assertFalse(cardNonce.getThreeDSecureInfo().isLiabilityShifted());
            assertFalse(cardNonce.getThreeDSecureInfo().isLiabilityShiftPossible());
            assertTrue(((CardNonce) paymentMethodNonce).getThreeDSecureInfo().wasVerified());

            mCountDownLatch.countDown();
        }
    });

    fragment.addListener(new BraintreeErrorListener() {
        @Override
        public void onError(Exception error) {
            fail(error.getMessage());
        }
    });

    CardBuilder cardBuilder = new CardBuilder()
            .cardNumber(THREE_D_SECURE_MPI_LOOKUP_ERROR)
            .expirationDate("12/20");

    ThreeDSecure.performVerification(fragment, cardBuilder, TEST_AMOUNT);

    mCountDownLatch.await();
}
 
Example #29
Source File: ThreeDSecureUnitTest.java    From braintree_android with MIT License 5 votes vote down vote up
@Test
public void performVerification_withCardBuilder_errorsWhenNoAmount() {
    MockStaticTokenizationClient.mockTokenizeSuccess(null);

    CardBuilder cardBuilder = new CardBuilder();
    ThreeDSecureRequest request = new ThreeDSecureRequest();

    ThreeDSecure.performVerification(mFragment, cardBuilder, request);

    ArgumentCaptor<Exception> captor = ArgumentCaptor.forClass(Exception.class);
    verify(mFragment).postCallback(captor.capture());

    assertEquals("The ThreeDSecureRequest amount cannot be null",
            captor.getValue().getMessage());
}
 
Example #30
Source File: ThreeDSecureTest.java    From braintree_android with MIT License 5 votes vote down vote up
@Test(timeout = 10000)
public void performVerification_acceptsAThreeDSecureRequest_postsPaymentMethodNonceToListenersWhenLookupReturnsACard()
        throws InterruptedException {
    String clientToken = new TestClientTokenBuilder().build();
    BraintreeFragment fragment = getFragmentWithAuthorization(mActivity, clientToken);
    String nonce = tokenize(fragment, new CardBuilder()
            .cardNumber("4000000000000051")
            .expirationDate("12/20")).getNonce();
    fragment.addListener(new PaymentMethodNonceCreatedListener() {
        @Override
        public void onPaymentMethodNonceCreated(PaymentMethodNonce paymentMethodNonce) {
            assertIsANonce(paymentMethodNonce.getNonce());
            assertEquals("51", ((CardNonce) paymentMethodNonce).getLastTwo());

            ThreeDSecureInfo threeDSecureInfo = ((CardNonce) paymentMethodNonce).getThreeDSecureInfo();
            assertFalse(threeDSecureInfo.isLiabilityShifted());
            assertFalse(threeDSecureInfo.isLiabilityShiftPossible());
            assertTrue(((CardNonce) paymentMethodNonce).getThreeDSecureInfo().wasVerified());
            mCountDownLatch.countDown();
        }
    });

    ThreeDSecureRequest request = new ThreeDSecureRequest()
            .nonce(nonce)
            .amount("5");

    ThreeDSecure.performVerification(fragment, request);

    mCountDownLatch.await();
}