Search in sources :

Example 16 with TestClientTokenBuilder

use of com.braintreepayments.api.test.TestClientTokenBuilder in project braintree_android by braintree.

the class CardTest method tokenize_callsErrorCallbackForInvalidPostalCode.

@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();
}
Also used : CardBuilder(com.braintreepayments.api.models.CardBuilder) TestClientTokenBuilder(com.braintreepayments.api.test.TestClientTokenBuilder) ErrorWithResponse(com.braintreepayments.api.exceptions.ErrorWithResponse) 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 17 with TestClientTokenBuilder

use of com.braintreepayments.api.test.TestClientTokenBuilder in project braintree_android by braintree.

the class CardTest method tokenize_tokenizesACardWithCvv.

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

Example 18 with TestClientTokenBuilder

use of com.braintreepayments.api.test.TestClientTokenBuilder in project braintree_android by braintree.

the class PaymentMethodTest method getPaymentMethodNonces_getsPaymentMethodsFromServer.

@Test(timeout = 10000)
public void getPaymentMethodNonces_getsPaymentMethodsFromServer() throws InterruptedException, InvalidArgumentException {
    final CountDownLatch latch = new CountDownLatch(1);
    final String clientToken = new TestClientTokenBuilder().build();
    BraintreeFragment fragment = BraintreeFragment.newInstance(mActivity, clientToken);
    getInstrumentation().waitForIdleSync();
    fragment.addListener(new PaymentMethodNoncesUpdatedListener() {

        @Override
        public void onPaymentMethodNoncesUpdated(List<PaymentMethodNonce> paymentMethodNonces) {
            assertEquals(1, paymentMethodNonces.size());
            assertIsANonce(paymentMethodNonces.get(0).getNonce());
            assertEquals("11", ((CardNonce) paymentMethodNonces.get(0)).getLastTwo());
            latch.countDown();
        }
    });
    fragment.addListener(new BraintreeErrorListener() {

        @Override
        public void onError(Exception error) {
            fail(error.getMessage());
        }
    });
    tokenize(fragment, new CardBuilder().cardNumber(VISA).expirationMonth("04").expirationYear(validExpirationYear()));
    PaymentMethod.getPaymentMethodNonces(fragment);
    latch.await();
}
Also used : PaymentMethodNoncesUpdatedListener(com.braintreepayments.api.interfaces.PaymentMethodNoncesUpdatedListener) CardBuilder(com.braintreepayments.api.models.CardBuilder) TestClientTokenBuilder(com.braintreepayments.api.test.TestClientTokenBuilder) CardNonce(com.braintreepayments.api.models.CardNonce) CountDownLatch(java.util.concurrent.CountDownLatch) PaymentMethodNonce(com.braintreepayments.api.models.PaymentMethodNonce) BraintreeErrorListener(com.braintreepayments.api.interfaces.BraintreeErrorListener) AuthorizationException(com.braintreepayments.api.exceptions.AuthorizationException) InvalidArgumentException(com.braintreepayments.api.exceptions.InvalidArgumentException) Test(org.junit.Test)

Example 19 with TestClientTokenBuilder

use of com.braintreepayments.api.test.TestClientTokenBuilder in project braintree_android by braintree.

the class ThreeDSecureTest method performVerification_postsPaymentMethodNonceToListenersWhenLookupReturnsACard.

@Test(timeout = 10000)
public void performVerification_postsPaymentMethodNonceToListenersWhenLookupReturnsACard() throws InterruptedException, InvalidArgumentException {
    String clientToken = new TestClientTokenBuilder().withThreeDSecure().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();
}
Also used : CardBuilder(com.braintreepayments.api.models.CardBuilder) TestClientTokenBuilder(com.braintreepayments.api.test.TestClientTokenBuilder) CardNonce(com.braintreepayments.api.models.CardNonce) PaymentMethodNonceCreatedListener(com.braintreepayments.api.interfaces.PaymentMethodNonceCreatedListener) PaymentMethodNonce(com.braintreepayments.api.models.PaymentMethodNonce) Test(org.junit.Test)

Aggregations

TestClientTokenBuilder (com.braintreepayments.api.test.TestClientTokenBuilder)19 Test (org.junit.Test)16 CardBuilder (com.braintreepayments.api.models.CardBuilder)14 CountDownLatch (java.util.concurrent.CountDownLatch)7 BraintreeErrorListener (com.braintreepayments.api.interfaces.BraintreeErrorListener)5 AuthorizationException (com.braintreepayments.api.exceptions.AuthorizationException)4 CardNonce (com.braintreepayments.api.models.CardNonce)4 PaymentMethodNonce (com.braintreepayments.api.models.PaymentMethodNonce)4 InvalidArgumentException (com.braintreepayments.api.exceptions.InvalidArgumentException)3 PaymentMethodNonceCreatedListener (com.braintreepayments.api.interfaces.PaymentMethodNonceCreatedListener)3 JSONException (org.json.JSONException)3 Before (org.junit.Before)3 ThreeDSecureRequest (com.braintreepayments.api.models.ThreeDSecureRequest)2 ErrorWithResponse (com.braintreepayments.api.exceptions.ErrorWithResponse)1 PaymentMethodNoncesUpdatedListener (com.braintreepayments.api.interfaces.PaymentMethodNoncesUpdatedListener)1 Configuration (com.braintreepayments.api.models.Configuration)1 ThreeDSecureInfo (com.braintreepayments.api.models.ThreeDSecureInfo)1 HttpURLConnection (java.net.HttpURLConnection)1