Search in sources :

Example 21 with BraintreeErrorListener

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

the class IdealTest method fetchIssuingBanks_returnsIssuingBanks.

@Test(timeout = 10000)
public void fetchIssuingBanks_returnsIssuingBanks() throws InterruptedException {
    Ideal.fetchIssuingBanks(mBraintreeFragment, new BraintreeResponseListener<List<IdealBank>>() {

        @Override
        public void onResponse(List<IdealBank> idealBanks) {
            assertFalse(idealBanks.isEmpty());
            assertFalse(TextUtils.isEmpty(idealBanks.get(0).getId()));
            assertFalse(TextUtils.isEmpty(idealBanks.get(0).getName()));
            assertFalse(TextUtils.isEmpty(idealBanks.get(0).getImageUri()));
            mCountDownLatch.countDown();
        }
    });
    mBraintreeFragment.addListener(new BraintreeErrorListener() {

        @Override
        public void onError(Exception error) {
            fail(error.getMessage());
        }
    });
    mCountDownLatch.await();
}
Also used : IdealBank(com.braintreepayments.api.models.IdealBank) List(java.util.List) BraintreeErrorListener(com.braintreepayments.api.interfaces.BraintreeErrorListener) InvalidArgumentException(com.braintreepayments.api.exceptions.InvalidArgumentException) Test(org.junit.Test)

Example 22 with BraintreeErrorListener

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

the class IdealTest method startPayment_returnsError_whenOrderId_isAbsent.

@Test(timeout = 10000)
public void startPayment_returnsError_whenOrderId_isAbsent() throws InterruptedException {
    IdealRequest builder = new IdealRequest().currency("EUR").amount("10").issuerId("INGBNL2A");
    Ideal.startPayment(mBraintreeFragment, builder, null);
    mBraintreeFragment.addListener(new BraintreeErrorListener() {

        @Override
        public void onError(Exception error) {
            assertTrue(error instanceof BraintreeApiErrorResponse);
            mCountDownLatch.countDown();
        }
    });
    mBraintreeFragment.addListener(new BraintreePaymentResultListener() {

        @Override
        public void onBraintreePaymentResult(BraintreePaymentResult result) {
            fail("BraintreeApiErrorResponse expected");
        }
    });
    mCountDownLatch.await();
}
Also used : BraintreePaymentResult(com.braintreepayments.api.models.BraintreePaymentResult) BraintreeApiErrorResponse(com.braintreepayments.api.exceptions.BraintreeApiErrorResponse) IdealRequest(com.braintreepayments.api.models.IdealRequest) BraintreeErrorListener(com.braintreepayments.api.interfaces.BraintreeErrorListener) InvalidArgumentException(com.braintreepayments.api.exceptions.InvalidArgumentException) BraintreePaymentResultListener(com.braintreepayments.api.interfaces.BraintreePaymentResultListener) Test(org.junit.Test)

Example 23 with BraintreeErrorListener

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

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

Example 25 with BraintreeErrorListener

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

the class ThreeDSecureTest method onActivityResult_postsRecoverableErrorsToListener.

@Test(timeout = 2000)
public void onActivityResult_postsRecoverableErrorsToListener() throws InterruptedException {
    BraintreeFragment fragment = getMockFragmentWithConfiguration(mActivity, new TestConfigurationBuilder().build());
    fragment.addListener(new BraintreeErrorListener() {

        @Override
        public void onError(Exception error) {
            assertEquals("Failed to authenticate, please try a different form of payment", error.getMessage());
            mCountDownLatch.countDown();
        }
    });
    Intent data = new Intent().putExtra(ThreeDSecureWebViewActivity.EXTRA_THREE_D_SECURE_RESULT, ThreeDSecureAuthenticationResponse.fromJson(stringFromFixture("errors/three_d_secure_error.json")));
    ThreeDSecure.onActivityResult(fragment, Activity.RESULT_OK, data);
    mCountDownLatch.await();
}
Also used : Intent(android.content.Intent) TestConfigurationBuilder(com.braintreepayments.testutils.TestConfigurationBuilder) BraintreeErrorListener(com.braintreepayments.api.interfaces.BraintreeErrorListener) JSONException(org.json.JSONException) InvalidArgumentException(com.braintreepayments.api.exceptions.InvalidArgumentException) Test(org.junit.Test)

Aggregations

BraintreeErrorListener (com.braintreepayments.api.interfaces.BraintreeErrorListener)27 Test (org.junit.Test)27 InvalidArgumentException (com.braintreepayments.api.exceptions.InvalidArgumentException)24 JSONException (org.json.JSONException)15 AuthorizationException (com.braintreepayments.api.exceptions.AuthorizationException)10 CardBuilder (com.braintreepayments.api.models.CardBuilder)10 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)9 CountDownLatch (java.util.concurrent.CountDownLatch)6 ErrorWithResponse (com.braintreepayments.api.exceptions.ErrorWithResponse)5 TestClientTokenBuilder (com.braintreepayments.api.test.TestClientTokenBuilder)5 Intent (android.content.Intent)4 BraintreePaymentResultListener (com.braintreepayments.api.interfaces.BraintreePaymentResultListener)3 PaymentMethodNoncesUpdatedListener (com.braintreepayments.api.interfaces.PaymentMethodNoncesUpdatedListener)3 UnionPayListener (com.braintreepayments.api.interfaces.UnionPayListener)3 BraintreePaymentResult (com.braintreepayments.api.models.BraintreePaymentResult)3 PaymentMethodNonce (com.braintreepayments.api.models.PaymentMethodNonce)3 UnionPayCapabilities (com.braintreepayments.api.models.UnionPayCapabilities)3 IdealRequest (com.braintreepayments.api.models.IdealRequest)2 UnionPayCardBuilder (com.braintreepayments.api.models.UnionPayCardBuilder)2 TestConfigurationBuilder (com.braintreepayments.testutils.TestConfigurationBuilder)2