Search in sources :

Example 1 with CardNonce

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

the class UnionPayUnitTest method mockSuccessCallback.

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

        @Override
        public Void answer(InvocationOnMock invocation) throws Throwable {
            UnionPayCardBuilder cardBuilder = (UnionPayCardBuilder) invocation.getArguments()[1];
            CardNonce cardNonce = mock(CardNonce.class);
            boolean hasSmsCode = false;
            try {
                hasSmsCode = new JSONObject(cardBuilder.build()).getJSONObject("options").has("smsCode");
            } catch (JSONException ignored) {
            }
            if (hasSmsCode) {
                when(cardNonce.getNonce()).thenReturn("nonce");
            }
            ((PaymentMethodNonceCallback) invocation.getArguments()[2]).success(cardNonce);
            return null;
        }
    }).when(TokenizationClient.class);
    TokenizationClient.tokenize(any(BraintreeFragment.class), any(UnionPayCardBuilder.class), any(PaymentMethodNonceCallback.class));
}
Also used : Answer(org.mockito.stubbing.Answer) PowerMockito.doAnswer(org.powermock.api.mockito.PowerMockito.doAnswer) JSONObject(org.json.JSONObject) InvocationOnMock(org.mockito.invocation.InvocationOnMock) UnionPayCardBuilder(com.braintreepayments.api.models.UnionPayCardBuilder) PaymentMethodNonceCallback(com.braintreepayments.api.interfaces.PaymentMethodNonceCallback) JSONException(org.json.JSONException) CardNonce(com.braintreepayments.api.models.CardNonce)

Example 2 with CardNonce

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

the class BraintreeFragmentUnitTest method postCallback_addsAllPaymentMethodNoncesToCache.

@Test
public void postCallback_addsAllPaymentMethodNoncesToCache() throws InvalidArgumentException {
    BraintreeFragment fragment = BraintreeFragment.newInstance(mActivity, TOKENIZATION_KEY);
    assertEquals(0, fragment.getCachedPaymentMethodNonces().size());
    List<PaymentMethodNonce> paymentMethodNonceList = new ArrayList<>();
    paymentMethodNonceList.add(new CardNonce());
    paymentMethodNonceList.add(new PayPalAccountNonce());
    fragment.postCallback(paymentMethodNonceList);
    assertEquals(2, fragment.getCachedPaymentMethodNonces().size());
    assertTrue(fragment.getCachedPaymentMethodNonces().get(0) instanceof CardNonce);
    assertTrue(fragment.getCachedPaymentMethodNonces().get(1) instanceof PayPalAccountNonce);
}
Also used : ArrayList(java.util.ArrayList) AndroidPayCardNonce(com.braintreepayments.api.models.AndroidPayCardNonce) CardNonce(com.braintreepayments.api.models.CardNonce) PayPalAccountNonce(com.braintreepayments.api.models.PayPalAccountNonce) PaymentMethodNonce(com.braintreepayments.api.models.PaymentMethodNonce) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 3 with CardNonce

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

the class BraintreeFragmentUnitTest method postCallback_onlyAllowsOneAndroidPayCardNonceToBePresent.

@Test
public void postCallback_onlyAllowsOneAndroidPayCardNonceToBePresent() throws InvalidArgumentException {
    BraintreeFragment fragment = BraintreeFragment.newInstance(mActivity, TOKENIZATION_KEY);
    assertEquals(0, fragment.getCachedPaymentMethodNonces().size());
    fragment.postCallback(new CardNonce());
    fragment.postCallback(new AndroidPayCardNonce());
    fragment.postCallback(new AndroidPayCardNonce());
    assertEquals(2, fragment.getCachedPaymentMethodNonces().size());
    assertTrue(fragment.getCachedPaymentMethodNonces().get(0) instanceof AndroidPayCardNonce);
}
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)

Example 4 with CardNonce

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

the class ThreeDSecureTest method performVerification_acceptsACardBuilderAndPostsAPaymentMethodNonceToListener.

@Test(timeout = 10000)
public void performVerification_acceptsACardBuilderAndPostsAPaymentMethodNonceToListener() throws InterruptedException {
    String clientToken = new TestClientTokenBuilder().withThreeDSecure().build();
    BraintreeFragment fragment = getFragmentWithAuthorization(mActivity, clientToken);
    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();
        }
    });
    CardBuilder cardBuilder = new CardBuilder().cardNumber("4000000000000051").expirationDate("12/20");
    ThreeDSecure.performVerification(fragment, cardBuilder, "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)

Example 5 with CardNonce

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

the class ThreeDSecureTest method performVerification_acceptsAThreeDSecureRequest_postsPaymentMethodNonceToListenersWhenLookupReturnsACard.

@Test(timeout = 10000)
public void performVerification_acceptsAThreeDSecureRequest_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());
            ThreeDSecureInfo threeDSecureInfo = ((CardNonce) paymentMethodNonce).getThreeDSecureInfo();
            assertFalse(threeDSecureInfo.isLiabilityShifted());
            assertFalse(threeDSecureInfo.isLiabilityShiftPossible());
            assertTrue(((CardNonce) paymentMethodNonce).getThreeDSecureInfo().wasVerified());
            mCountDownLatch.countDown();
        }
    });
    ThreeDSecureRequest request = new ThreeDSecureRequest().nonce(nonce).amount("5");
    ThreeDSecure.performVerification(fragment, request);
    mCountDownLatch.await();
}
Also used : ThreeDSecureRequest(com.braintreepayments.api.models.ThreeDSecureRequest) CardBuilder(com.braintreepayments.api.models.CardBuilder) TestClientTokenBuilder(com.braintreepayments.api.test.TestClientTokenBuilder) ThreeDSecureInfo(com.braintreepayments.api.models.ThreeDSecureInfo) CardNonce(com.braintreepayments.api.models.CardNonce) PaymentMethodNonceCreatedListener(com.braintreepayments.api.interfaces.PaymentMethodNonceCreatedListener) 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