Search in sources :

Example 6 with PaymentMethodNonceCreatedListener

use of com.braintreepayments.api.interfaces.PaymentMethodNonceCreatedListener 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 7 with PaymentMethodNonceCreatedListener

use of com.braintreepayments.api.interfaces.PaymentMethodNonceCreatedListener 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 8 with PaymentMethodNonceCreatedListener

use of com.braintreepayments.api.interfaces.PaymentMethodNonceCreatedListener 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 9 with PaymentMethodNonceCreatedListener

use of com.braintreepayments.api.interfaces.PaymentMethodNonceCreatedListener 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)

Example 10 with PaymentMethodNonceCreatedListener

use of com.braintreepayments.api.interfaces.PaymentMethodNonceCreatedListener in project braintree_android by braintree.

the class CardTest method assertTokenizationSuccessful.

private void assertTokenizationSuccessful(String authorization, CardBuilder cardBuilder) throws Exception {
    final CountDownLatch countDownLatch = new CountDownLatch(1);
    BraintreeFragment fragment = setupBraintreeFragment(authorization);
    fragment.addListener(new PaymentMethodNonceCreatedListener() {

        @Override
        public void onPaymentMethodNonceCreated(PaymentMethodNonce paymentMethodNonce) {
            CardNonce cardNonce = (CardNonce) paymentMethodNonce;
            assertNotNull(cardNonce.getNonce());
            assertEquals("Visa", cardNonce.getCardType());
            assertEquals("1111", cardNonce.getLastFour());
            assertEquals("11", cardNonce.getLastTwo());
            assertEquals(BinData.UNKNOWN, cardNonce.getBinData().getPrepaid());
            assertEquals(BinData.UNKNOWN, cardNonce.getBinData().getHealthcare());
            assertEquals(BinData.UNKNOWN, cardNonce.getBinData().getDebit());
            assertEquals(BinData.UNKNOWN, cardNonce.getBinData().getDurbinRegulated());
            assertEquals(BinData.UNKNOWN, cardNonce.getBinData().getCommercial());
            assertEquals(BinData.UNKNOWN, cardNonce.getBinData().getPayroll());
            assertEquals(BinData.UNKNOWN, cardNonce.getBinData().getIssuingBank());
            assertEquals(BinData.UNKNOWN, cardNonce.getBinData().getCountryOfIssuance());
            assertEquals(BinData.UNKNOWN, cardNonce.getBinData().getProductId());
            assertFalse(cardNonce.getThreeDSecureInfo().wasVerified());
            countDownLatch.countDown();
        }
    });
    Card.tokenize(fragment, cardBuilder);
    countDownLatch.await();
}
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)

Aggregations

PaymentMethodNonceCreatedListener (com.braintreepayments.api.interfaces.PaymentMethodNonceCreatedListener)21 PaymentMethodNonce (com.braintreepayments.api.models.PaymentMethodNonce)21 CardNonce (com.braintreepayments.api.models.CardNonce)20 Test (org.junit.Test)19 CardBuilder (com.braintreepayments.api.models.CardBuilder)11 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)4 UnionPayListener (com.braintreepayments.api.interfaces.UnionPayListener)3 AndroidPayCardNonce (com.braintreepayments.api.models.AndroidPayCardNonce)3 UnionPayCapabilities (com.braintreepayments.api.models.UnionPayCapabilities)3 TestClientTokenBuilder (com.braintreepayments.api.test.TestClientTokenBuilder)3 CountDownLatch (java.util.concurrent.CountDownLatch)3 Intent (android.content.Intent)2 UnionPayCardBuilder (com.braintreepayments.api.models.UnionPayCardBuilder)2 TestConfigurationBuilder (com.braintreepayments.testutils.TestConfigurationBuilder)2 Uri (android.net.Uri)1 InvalidArgumentException (com.braintreepayments.api.exceptions.InvalidArgumentException)1 AmericanExpressListener (com.braintreepayments.api.interfaces.AmericanExpressListener)1 BraintreeCancelListener (com.braintreepayments.api.interfaces.BraintreeCancelListener)1 BraintreeErrorListener (com.braintreepayments.api.interfaces.BraintreeErrorListener)1 BraintreePaymentResultListener (com.braintreepayments.api.interfaces.BraintreePaymentResultListener)1