Search in sources :

Example 1 with PaymentMethodNoncesUpdatedListener

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

the class BraintreeFragmentUnitTest method removeListener_noPaymentMethodNoncesUpdatedCallbacksReceived.

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

        @Override
        public void onPaymentMethodNoncesUpdated(List<PaymentMethodNonce> paymentMethodNonces) {
            fail("Listener was called");
        }
    };
    fragment.addListener(listener);
    fragment.removeListener(listener);
    fragment.postCallback(new ArrayList<PaymentMethodNonce>());
}
Also used : PaymentMethodNoncesUpdatedListener(com.braintreepayments.api.interfaces.PaymentMethodNoncesUpdatedListener) List(java.util.List) ArrayList(java.util.ArrayList) PaymentMethodNonce(com.braintreepayments.api.models.PaymentMethodNonce) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 2 with PaymentMethodNoncesUpdatedListener

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

the class BraintreeFragmentUnitTest method addAndRemoveListenersAddAndRemoveAllListeners.

@Test
public void addAndRemoveListenersAddAndRemoveAllListeners() throws InvalidArgumentException {
    BraintreeFragment fragment = BraintreeFragment.newInstance(mActivity, TOKENIZATION_KEY);
    ConfigurationListener configurationListener = new ConfigurationListener() {

        @Override
        public void onConfigurationFetched(Configuration configuration) {
        }
    };
    BraintreeErrorListener braintreeErrorListener = new BraintreeErrorListener() {

        @Override
        public void onError(Exception error) {
        }
    };
    PaymentMethodNoncesUpdatedListener paymentMethodNoncesUpdatedListener = new PaymentMethodNoncesUpdatedListener() {

        @Override
        public void onPaymentMethodNoncesUpdated(List<PaymentMethodNonce> paymentMethodNonces) {
        }
    };
    PaymentMethodNonceCreatedListener paymentMethodNonceCreatedListener = new PaymentMethodNonceCreatedListener() {

        @Override
        public void onPaymentMethodNonceCreated(PaymentMethodNonce paymentMethodNonce) {
        }
    };
    BraintreeCancelListener braintreeCancelListener = new BraintreeCancelListener() {

        @Override
        public void onCancel(int requestCode) {
        }
    };
    UnionPayListener unionPayListener = new UnionPayListener() {

        @Override
        public void onCapabilitiesFetched(UnionPayCapabilities capabilities) {
        }

        @Override
        public void onSmsCodeSent(String enrollmentId, boolean smsCodeRequired) {
        }
    };
    AmericanExpressListener americanExpressListener = new AmericanExpressListener() {

        @Override
        public void onRewardsBalanceFetched(AmericanExpressRewardsBalance rewardsBalance) {
        }
    };
    BraintreePaymentResultListener braintreePaymentResultListener = new BraintreePaymentResultListener() {

        @Override
        public void onBraintreePaymentResult(BraintreePaymentResult result) {
        }
    };
    fragment.addListener(configurationListener);
    fragment.addListener(braintreeErrorListener);
    fragment.addListener(paymentMethodNoncesUpdatedListener);
    fragment.addListener(paymentMethodNonceCreatedListener);
    fragment.addListener(braintreeCancelListener);
    fragment.addListener(unionPayListener);
    fragment.addListener(americanExpressListener);
    fragment.addListener(braintreePaymentResultListener);
    assertEquals(8, fragment.getListeners().size());
    fragment.removeListener(configurationListener);
    fragment.removeListener(braintreeErrorListener);
    fragment.removeListener(paymentMethodNoncesUpdatedListener);
    fragment.removeListener(paymentMethodNonceCreatedListener);
    fragment.removeListener(braintreeCancelListener);
    fragment.removeListener(unionPayListener);
    fragment.removeListener(americanExpressListener);
    fragment.removeListener(braintreePaymentResultListener);
    assertEquals(0, fragment.getListeners().size());
}
Also used : PaymentMethodNoncesUpdatedListener(com.braintreepayments.api.interfaces.PaymentMethodNoncesUpdatedListener) UnionPayListener(com.braintreepayments.api.interfaces.UnionPayListener) Configuration(com.braintreepayments.api.models.Configuration) BraintreeCancelListener(com.braintreepayments.api.interfaces.BraintreeCancelListener) UnionPayCapabilities(com.braintreepayments.api.models.UnionPayCapabilities) BraintreeErrorListener(com.braintreepayments.api.interfaces.BraintreeErrorListener) JSONException(org.json.JSONException) InvalidArgumentException(com.braintreepayments.api.exceptions.InvalidArgumentException) ConfigurationListener(com.braintreepayments.api.interfaces.ConfigurationListener) BraintreePaymentResult(com.braintreepayments.api.models.BraintreePaymentResult) AmericanExpressRewardsBalance(com.braintreepayments.api.models.AmericanExpressRewardsBalance) List(java.util.List) ArrayList(java.util.ArrayList) PaymentMethodNonceCreatedListener(com.braintreepayments.api.interfaces.PaymentMethodNonceCreatedListener) AmericanExpressListener(com.braintreepayments.api.interfaces.AmericanExpressListener) PaymentMethodNonce(com.braintreepayments.api.models.PaymentMethodNonce) BraintreePaymentResultListener(com.braintreepayments.api.interfaces.BraintreePaymentResultListener) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 3 with PaymentMethodNoncesUpdatedListener

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

the class BraintreeFragmentUnitTest method addListener_flushesPaymentMethodNoncesUpdatedCallback.

@Test
public void addListener_flushesPaymentMethodNoncesUpdatedCallback() throws InvalidArgumentException {
    BraintreeFragment fragment = BraintreeFragment.newInstance(mActivity, TOKENIZATION_KEY);
    fragment.postCallback(new ArrayList<PaymentMethodNonce>());
    fragment.addListener(new PaymentMethodNoncesUpdatedListener() {

        @Override
        public void onPaymentMethodNoncesUpdated(List<PaymentMethodNonce> paymentMethodNonces) {
            mCalled.set(true);
        }
    });
    assertTrue(mCalled.get());
}
Also used : PaymentMethodNoncesUpdatedListener(com.braintreepayments.api.interfaces.PaymentMethodNoncesUpdatedListener) PaymentMethodNonce(com.braintreepayments.api.models.PaymentMethodNonce) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 4 with PaymentMethodNoncesUpdatedListener

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

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

the class PaymentMethodTest method getPaymentMethodNonces_failsWithATokenizationKey.

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

        @Override
        public void onPaymentMethodNoncesUpdated(List<PaymentMethodNonce> paymentMethodNonces) {
            fail("getPaymentMethodNonces succeeded");
        }
    });
    fragment.addListener(new BraintreeErrorListener() {

        @Override
        public void onError(Exception error) {
            assertTrue(error instanceof AuthorizationException);
            assertEquals("Tokenization key authorization not allowed for this endpoint. Please use an authentication method with upgraded permissions", error.getMessage());
            latch.countDown();
        }
    });
    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) AuthorizationException(com.braintreepayments.api.exceptions.AuthorizationException) 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)

Aggregations

PaymentMethodNoncesUpdatedListener (com.braintreepayments.api.interfaces.PaymentMethodNoncesUpdatedListener)5 PaymentMethodNonce (com.braintreepayments.api.models.PaymentMethodNonce)5 Test (org.junit.Test)5 InvalidArgumentException (com.braintreepayments.api.exceptions.InvalidArgumentException)3 BraintreeErrorListener (com.braintreepayments.api.interfaces.BraintreeErrorListener)3 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)3 AuthorizationException (com.braintreepayments.api.exceptions.AuthorizationException)2 CardBuilder (com.braintreepayments.api.models.CardBuilder)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 AmericanExpressListener (com.braintreepayments.api.interfaces.AmericanExpressListener)1 BraintreeCancelListener (com.braintreepayments.api.interfaces.BraintreeCancelListener)1 BraintreePaymentResultListener (com.braintreepayments.api.interfaces.BraintreePaymentResultListener)1 ConfigurationListener (com.braintreepayments.api.interfaces.ConfigurationListener)1 PaymentMethodNonceCreatedListener (com.braintreepayments.api.interfaces.PaymentMethodNonceCreatedListener)1 UnionPayListener (com.braintreepayments.api.interfaces.UnionPayListener)1 AmericanExpressRewardsBalance (com.braintreepayments.api.models.AmericanExpressRewardsBalance)1 BraintreePaymentResult (com.braintreepayments.api.models.BraintreePaymentResult)1 CardNonce (com.braintreepayments.api.models.CardNonce)1