Search in sources :

Example 6 with CardBuilder

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

the class CardTest method tokenize_failsWithTokenizationKeyAndValidateTrue.

@Test(timeout = 10000)
public void tokenize_failsWithTokenizationKeyAndValidateTrue() throws Exception {
    CardBuilder cardBuilder = new CardBuilder().cardNumber(VISA).expirationDate("08/20").validate(true);
    final CountDownLatch countDownLatch = new CountDownLatch(1);
    BraintreeFragment fragment = setupBraintreeFragment(TOKENIZATION_KEY);
    fragment.addListener(new BraintreeErrorListener() {

        @Override
        public void onError(Exception error) {
            assertTrue(error instanceof AuthorizationException);
            if (mRequestProtocol.equals(GRAPHQL)) {
                assertEquals("Validation is not supported for requests authorized with a tokenization key.", error.getMessage());
            } else {
                assertEquals("Tokenization key authorization not allowed for this endpoint. Please use an " + "authentication method with upgraded permissions", error.getMessage());
            }
            countDownLatch.countDown();
        }
    });
    Card.tokenize(fragment, cardBuilder);
    countDownLatch.await();
}
Also used : CardBuilder(com.braintreepayments.api.models.CardBuilder) AuthorizationException(com.braintreepayments.api.exceptions.AuthorizationException) CountDownLatch(java.util.concurrent.CountDownLatch) BraintreeErrorListener(com.braintreepayments.api.interfaces.BraintreeErrorListener) JSONException(org.json.JSONException) AuthorizationException(com.braintreepayments.api.exceptions.AuthorizationException) Test(org.junit.Test)

Example 7 with CardBuilder

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

the class CardTest method tokenize_tokenizesACardWithValidateFalse.

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

Example 8 with CardBuilder

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

the class CardTest method tokenize_tokenizesACardWithATokenizationKey.

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

Example 9 with CardBuilder

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

the class CardTest method tokenize_callsErrorCallbackForInvalidCvv.

@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();
}
Also used : CardBuilder(com.braintreepayments.api.models.CardBuilder) TestClientTokenBuilder(com.braintreepayments.api.test.TestClientTokenBuilder) CountDownLatch(java.util.concurrent.CountDownLatch) BraintreeErrorListener(com.braintreepayments.api.interfaces.BraintreeErrorListener) JSONException(org.json.JSONException) AuthorizationException(com.braintreepayments.api.exceptions.AuthorizationException) Test(org.junit.Test)

Example 10 with CardBuilder

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

the class CardTest method tokenize_tokenizesACardWithoutACustomer.

@Test(timeout = 10000)
public void tokenize_tokenizesACardWithoutACustomer() throws Exception {
    CardBuilder cardBuilder = new CardBuilder().cardNumber(VISA).expirationDate("08/20");
    assertTokenizationSuccessful(new TestClientTokenBuilder().withoutCustomer().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