Search in sources :

Example 6 with CardNonce

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

the class BraintreeFragmentTestUtils method tokenize.

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];
}
Also used : CardNonce(com.braintreepayments.api.models.CardNonce) PaymentMethodNonceCreatedListener(com.braintreepayments.api.interfaces.PaymentMethodNonceCreatedListener) CountDownLatch(java.util.concurrent.CountDownLatch) PaymentMethodNonce(com.braintreepayments.api.models.PaymentMethodNonce)

Example 7 with CardNonce

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

the class ThreeDSecureVerificationTest method performVerification_doesALookupAndReturnsACardWhenThereIsALookupError.

@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();
        }
    });
    CardBuilder cardBuilder = new CardBuilder().cardNumber(THREE_D_SECURE_LOOKUP_ERROR).expirationDate("12/20");
    ThreeDSecure.performVerification(fragment, cardBuilder, TEST_AMOUNT);
    mCountDownLatch.await();
}
Also used : CardBuilder(com.braintreepayments.api.models.CardBuilder) CardNonce(com.braintreepayments.api.models.CardNonce) PaymentMethodNonceCreatedListener(com.braintreepayments.api.interfaces.PaymentMethodNonceCreatedListener) PaymentMethodNonce(com.braintreepayments.api.models.PaymentMethodNonce) Test(org.junit.Test)

Example 8 with CardNonce

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

the class CardUnitTest method mockSuccessCallback.

/* helpers */
private void mockSuccessCallback() {
    mockStatic(TokenizationClient.class);
    doAnswer(new Answer<Void>() {

        @Override
        public Void answer(InvocationOnMock invocation) throws Throwable {
            ((PaymentMethodNonceCallback) invocation.getArguments()[2]).success(new CardNonce());
            return null;
        }
    }).when(TokenizationClient.class);
    TokenizationClient.tokenize(any(BraintreeFragment.class), any(PaymentMethodBuilder.class), any(PaymentMethodNonceCallback.class));
}
Also used : Answer(org.mockito.stubbing.Answer) PowerMockito.doAnswer(org.powermock.api.mockito.PowerMockito.doAnswer) PaymentMethodBuilder(com.braintreepayments.api.models.PaymentMethodBuilder) InvocationOnMock(org.mockito.invocation.InvocationOnMock) PaymentMethodNonceCallback(com.braintreepayments.api.interfaces.PaymentMethodNonceCallback) CardNonce(com.braintreepayments.api.models.CardNonce)

Example 9 with CardNonce

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

the class BraintreeFragmentUnitTest method postCallback_postsPaymentMethodNonceToListener.

@Test
public void postCallback_postsPaymentMethodNonceToListener() throws InvalidArgumentException {
    BraintreeFragment fragment = BraintreeFragment.newInstance(mActivity, TOKENIZATION_KEY);
    final AtomicBoolean wasCalled = new AtomicBoolean(false);
    fragment.addListener(new PaymentMethodNonceCreatedListener() {

        @Override
        public void onPaymentMethodNonceCreated(PaymentMethodNonce paymentMethodNonce) {
            assertTrue(paymentMethodNonce instanceof CardNonce);
            wasCalled.set(true);
        }
    });
    fragment.postCallback(new CardNonce());
    assertTrue(wasCalled.get());
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) 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 10 with CardNonce

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

the class BraintreeFragmentUnitTest method postCallback_doesNotRemoveAndroidPayCardNonceWhenAnotherNonceIsAdded.

@Test
public void postCallback_doesNotRemoveAndroidPayCardNonceWhenAnotherNonceIsAdded() throws InvalidArgumentException {
    BraintreeFragment fragment = BraintreeFragment.newInstance(mActivity, TOKENIZATION_KEY);
    assertEquals(0, fragment.getCachedPaymentMethodNonces().size());
    fragment.postCallback(new AndroidPayCardNonce());
    fragment.postCallback(new CardNonce());
    assertEquals(2, fragment.getCachedPaymentMethodNonces().size());
}
Also used : AndroidPayCardNonce(com.braintreepayments.api.models.AndroidPayCardNonce) AndroidPayCardNonce(com.braintreepayments.api.models.AndroidPayCardNonce) CardNonce(com.braintreepayments.api.models.CardNonce) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) 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