Search in sources :

Example 11 with CardNonce

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

the class BraintreeFragmentUnitTest method addListener_flushesPaymentMethodNonceCreatedCallback.

@Test
public void addListener_flushesPaymentMethodNonceCreatedCallback() throws InvalidArgumentException {
    BraintreeFragment fragment = BraintreeFragment.newInstance(mActivity, TOKENIZATION_KEY);
    fragment.postCallback(new CardNonce());
    fragment.addListener(new PaymentMethodNonceCreatedListener() {

        @Override
        public void onPaymentMethodNonceCreated(PaymentMethodNonce paymentMethodNonce) {
            mCalled.set(true);
        }
    });
    assertTrue(mCalled.get());
}
Also used : AndroidPayCardNonce(com.braintreepayments.api.models.AndroidPayCardNonce) CardNonce(com.braintreepayments.api.models.CardNonce) PaymentMethodNonceCreatedListener(com.braintreepayments.api.interfaces.PaymentMethodNonceCreatedListener) PaymentMethodNonce(com.braintreepayments.api.models.PaymentMethodNonce) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 12 with CardNonce

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

the class BraintreeFragmentUnitTest method removeListener_noPaymentMethodNonceCreatedReceived.

@Test
public void removeListener_noPaymentMethodNonceCreatedReceived() throws InvalidArgumentException {
    BraintreeFragment fragment = BraintreeFragment.newInstance(mActivity, TOKENIZATION_KEY);
    PaymentMethodNonceCreatedListener listener = new PaymentMethodNonceCreatedListener() {

        @Override
        public void onPaymentMethodNonceCreated(PaymentMethodNonce paymentMethodNonce) {
            fail("Listener was called");
        }
    };
    fragment.addListener(listener);
    fragment.removeListener(listener);
    fragment.postCallback(new CardNonce());
}
Also used : AndroidPayCardNonce(com.braintreepayments.api.models.AndroidPayCardNonce) CardNonce(com.braintreepayments.api.models.CardNonce) PaymentMethodNonceCreatedListener(com.braintreepayments.api.interfaces.PaymentMethodNonceCreatedListener) PaymentMethodNonce(com.braintreepayments.api.models.PaymentMethodNonce) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 13 with CardNonce

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

the class BraintreeFragmentUnitTest method postCallback_addsPaymentMethodNonceToCache.

@Test
public void postCallback_addsPaymentMethodNonceToCache() throws InvalidArgumentException {
    BraintreeFragment fragment = BraintreeFragment.newInstance(mActivity, TOKENIZATION_KEY);
    assertEquals(0, fragment.getCachedPaymentMethodNonces().size());
    fragment.postCallback(new CardNonce());
    assertEquals(1, fragment.getCachedPaymentMethodNonces().size());
    assertTrue(fragment.getCachedPaymentMethodNonces().get(0) instanceof CardNonce);
}
Also used : AndroidPayCardNonce(com.braintreepayments.api.models.AndroidPayCardNonce) CardNonce(com.braintreepayments.api.models.CardNonce) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 14 with CardNonce

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

the class BraintreeFragmentUnitTest method postCallback_addsPaymentMethodNonceToBeginningOfCache.

@Test
public void postCallback_addsPaymentMethodNonceToBeginningOfCache() throws InvalidArgumentException {
    BraintreeFragment fragment = BraintreeFragment.newInstance(mActivity, TOKENIZATION_KEY);
    assertEquals(0, fragment.getCachedPaymentMethodNonces().size());
    fragment.postCallback(new CardNonce());
    fragment.postCallback(new PayPalAccountNonce());
    assertEquals(2, fragment.getCachedPaymentMethodNonces().size());
    assertTrue(fragment.getCachedPaymentMethodNonces().get(0) instanceof PayPalAccountNonce);
}
Also used : AndroidPayCardNonce(com.braintreepayments.api.models.AndroidPayCardNonce) CardNonce(com.braintreepayments.api.models.CardNonce) PayPalAccountNonce(com.braintreepayments.api.models.PayPalAccountNonce) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 15 with CardNonce

use of com.braintreepayments.api.models.CardNonce 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)

Aggregations

CardNonce (com.braintreepayments.api.models.CardNonce)29 Test (org.junit.Test)24 PaymentMethodNonce (com.braintreepayments.api.models.PaymentMethodNonce)22 PaymentMethodNonceCreatedListener (com.braintreepayments.api.interfaces.PaymentMethodNonceCreatedListener)20 CardBuilder (com.braintreepayments.api.models.CardBuilder)12 AndroidPayCardNonce (com.braintreepayments.api.models.AndroidPayCardNonce)8 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)8 TestClientTokenBuilder (com.braintreepayments.api.test.TestClientTokenBuilder)4 CountDownLatch (java.util.concurrent.CountDownLatch)4 Intent (android.content.Intent)3 UnionPayCardBuilder (com.braintreepayments.api.models.UnionPayCardBuilder)3 PaymentMethodNonceCallback (com.braintreepayments.api.interfaces.PaymentMethodNonceCallback)2 UnionPayListener (com.braintreepayments.api.interfaces.UnionPayListener)2 PayPalAccountNonce (com.braintreepayments.api.models.PayPalAccountNonce)2 UnionPayCapabilities (com.braintreepayments.api.models.UnionPayCapabilities)2 TestConfigurationBuilder (com.braintreepayments.testutils.TestConfigurationBuilder)2 JSONObject (org.json.JSONObject)2 InvocationOnMock (org.mockito.invocation.InvocationOnMock)2 Answer (org.mockito.stubbing.Answer)2 PowerMockito.doAnswer (org.powermock.api.mockito.PowerMockito.doAnswer)2