Search in sources :

Example 21 with CardBuilder

use of com.braintreepayments.api.models.CardBuilder in project braintree_android by braintree.

the class TokenizationClientUnitTest method tokenize_sendGraphQLAnalyticsEventWhenEnabled.

@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");
}
Also used : UnionPayCardBuilder(com.braintreepayments.api.models.UnionPayCardBuilder) CardBuilder(com.braintreepayments.api.models.CardBuilder) TestConfigurationBuilder(com.braintreepayments.testutils.TestConfigurationBuilder) Test(org.junit.Test)

Example 22 with CardBuilder

use of com.braintreepayments.api.models.CardBuilder in project braintree_android by braintree.

the class TokenizationClientUnitTest method tokenize_sendGraphQLAnalyticsEventOnSuccess.

@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");
}
Also used : UnionPayCardBuilder(com.braintreepayments.api.models.UnionPayCardBuilder) CardBuilder(com.braintreepayments.api.models.CardBuilder) PaymentMethodNonceCallback(com.braintreepayments.api.interfaces.PaymentMethodNonceCallback) TestConfigurationBuilder(com.braintreepayments.testutils.TestConfigurationBuilder) PaymentMethodNonce(com.braintreepayments.api.models.PaymentMethodNonce) BraintreeException(com.braintreepayments.api.exceptions.BraintreeException) JSONException(org.json.JSONException) Test(org.junit.Test)

Example 23 with CardBuilder

use of com.braintreepayments.api.models.CardBuilder in project braintree_android by braintree.

the class TokenizationClientUnitTest method tokenize_tokenizesCardsWithGraphQLWhenEnabled.

@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());
}
Also used : UnionPayCardBuilder(com.braintreepayments.api.models.UnionPayCardBuilder) CardBuilder(com.braintreepayments.api.models.CardBuilder) Matchers.anyString(org.mockito.Matchers.anyString) TestConfigurationBuilder(com.braintreepayments.testutils.TestConfigurationBuilder) HttpResponseCallback(com.braintreepayments.api.interfaces.HttpResponseCallback) Test(org.junit.Test)

Example 24 with CardBuilder

use of com.braintreepayments.api.models.CardBuilder in project braintree_android by braintree.

the class CardTest method tokenize_tokenizesCvvOnly.

@Test(timeout = 10000)
public void tokenize_tokenizesCvvOnly() throws Exception {
    final CountDownLatch countDownLatch = new CountDownLatch(1);
    BraintreeFragment fragment = setupBraintreeFragment(TOKENIZATION_KEY);
    fragment.addListener(new PaymentMethodNonceCreatedListener() {

        @Override
        public void onPaymentMethodNonceCreated(PaymentMethodNonce paymentMethodNonce) {
            CardNonce cardNonce = (CardNonce) paymentMethodNonce;
            assertNotNull(cardNonce.getBinData());
            assertEquals("Unknown", cardNonce.getCardType());
            assertEquals("", cardNonce.getLastFour());
            assertEquals("", cardNonce.getLastTwo());
            assertNotNull(cardNonce.getThreeDSecureInfo());
            assertFalse(cardNonce.isDefault());
            assertEquals("", cardNonce.getDescription());
            assertNotNull(cardNonce.getNonce());
            countDownLatch.countDown();
        }
    });
    CardBuilder cardBuilder = new CardBuilder().cvv("123");
    Card.tokenize(fragment, cardBuilder);
    countDownLatch.await();
}
Also used : CardBuilder(com.braintreepayments.api.models.CardBuilder) CardNonce(com.braintreepayments.api.models.CardNonce) PaymentMethodNonceCreatedListener(com.braintreepayments.api.interfaces.PaymentMethodNonceCreatedListener) CountDownLatch(java.util.concurrent.CountDownLatch) PaymentMethodNonce(com.braintreepayments.api.models.PaymentMethodNonce) Test(org.junit.Test)

Example 25 with CardBuilder

use of com.braintreepayments.api.models.CardBuilder in project braintree_android by braintree.

the class CardTest method tokenize_tokenizesACardWithValidateTrue.

@Test(timeout = 10000)
public void tokenize_tokenizesACardWithValidateTrue() throws Exception {
    CardBuilder cardBuilder = new CardBuilder().cardNumber(VISA).expirationDate("08/20").validate(true);
    assertTokenizationSuccessful(new TestClientTokenBuilder().build(), cardBuilder);
}
Also used : CardBuilder(com.braintreepayments.api.models.CardBuilder) TestClientTokenBuilder(com.braintreepayments.api.test.TestClientTokenBuilder) Test(org.junit.Test)

Aggregations

CardBuilder (com.braintreepayments.api.models.CardBuilder)41 Test (org.junit.Test)39 PaymentMethodNonce (com.braintreepayments.api.models.PaymentMethodNonce)15 TestClientTokenBuilder (com.braintreepayments.api.test.TestClientTokenBuilder)14 CardNonce (com.braintreepayments.api.models.CardNonce)12 PaymentMethodNonceCreatedListener (com.braintreepayments.api.interfaces.PaymentMethodNonceCreatedListener)11 AuthorizationException (com.braintreepayments.api.exceptions.AuthorizationException)10 BraintreeErrorListener (com.braintreepayments.api.interfaces.BraintreeErrorListener)10 InvalidArgumentException (com.braintreepayments.api.exceptions.InvalidArgumentException)7 UnionPayCardBuilder (com.braintreepayments.api.models.UnionPayCardBuilder)7 CountDownLatch (java.util.concurrent.CountDownLatch)6 JSONException (org.json.JSONException)5 TestConfigurationBuilder (com.braintreepayments.testutils.TestConfigurationBuilder)4 HttpResponseCallback (com.braintreepayments.api.interfaces.HttpResponseCallback)3 Matchers.anyString (org.mockito.Matchers.anyString)3 BraintreeException (com.braintreepayments.api.exceptions.BraintreeException)2 BraintreeCancelListener (com.braintreepayments.api.interfaces.BraintreeCancelListener)2 PaymentMethodNonceCallback (com.braintreepayments.api.interfaces.PaymentMethodNonceCallback)2 PaymentMethodNoncesUpdatedListener (com.braintreepayments.api.interfaces.PaymentMethodNoncesUpdatedListener)2 ErrorWithResponse (com.braintreepayments.api.exceptions.ErrorWithResponse)1