Search in sources :

Example 6 with BraintreeErrorListener

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

the class ThreeDSecureTest method onActivityResult_postsUnrecoverableErrorsToListeners.

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

        @Override
        public void onError(Exception error) {
            assertEquals("Error!", error.getMessage());
            mCountDownLatch.countDown();
        }
    });
    ThreeDSecureAuthenticationResponse authResponse = ThreeDSecureAuthenticationResponse.fromException("Error!");
    Intent data = new Intent().putExtra(ThreeDSecureWebViewActivity.EXTRA_THREE_D_SECURE_RESULT, authResponse);
    ThreeDSecure.onActivityResult(fragment, Activity.RESULT_OK, data);
    mCountDownLatch.await();
}
Also used : ThreeDSecureAuthenticationResponse(com.braintreepayments.api.models.ThreeDSecureAuthenticationResponse) 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)

Example 7 with BraintreeErrorListener

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

the class UnionPayTest method enroll_whenSmsCodeRequiredFalse_onSmsCodeSentReturnsFalse.

@Test(timeout = 10000)
public void enroll_whenSmsCodeRequiredFalse_onSmsCodeSentReturnsFalse() throws InterruptedException {
    mCountDownLatch = new CountDownLatch(2);
    String cardNumber = UNIONPAY_SMS_NOT_REQUIRED;
    final UnionPayCardBuilder unionPayCardBuilder = new UnionPayCardBuilder().cardNumber(cardNumber).expirationMonth("12").expirationYear("2019").mobileCountryCode("62").mobilePhoneNumber("11111111111");
    mBraintreeFragment.addListener(new UnionPayListener() {

        @Override
        public void onCapabilitiesFetched(UnionPayCapabilities capabilities) {
            assertTrue(capabilities.isUnionPay());
            assertTrue(capabilities.isSupported());
            UnionPay.enroll(mBraintreeFragment, unionPayCardBuilder);
            mCountDownLatch.countDown();
        }

        @Override
        public void onSmsCodeSent(String enrollmentId, boolean smsCodeRequired) {
            assertNotNull(enrollmentId);
            assertFalse(smsCodeRequired);
            mCountDownLatch.countDown();
        }
    });
    mBraintreeFragment.addListener(new BraintreeErrorListener() {

        @Override
        public void onError(Exception error) {
            fail("Not expecting error");
        }
    });
    UnionPay.fetchCapabilities(mBraintreeFragment, cardNumber);
    mCountDownLatch.await();
}
Also used : UnionPayListener(com.braintreepayments.api.interfaces.UnionPayListener) UnionPayCardBuilder(com.braintreepayments.api.models.UnionPayCardBuilder) UnionPayCapabilities(com.braintreepayments.api.models.UnionPayCapabilities) CountDownLatch(java.util.concurrent.CountDownLatch) BraintreeErrorListener(com.braintreepayments.api.interfaces.BraintreeErrorListener) InvalidArgumentException(com.braintreepayments.api.exceptions.InvalidArgumentException) Test(org.junit.Test)

Example 8 with BraintreeErrorListener

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

the class UnionPayTest method enroll_whenIsUnionPayFalse_willError.

@Test(timeout = 10000)
public void enroll_whenIsUnionPayFalse_willError() throws InterruptedException {
    String cardNumber = CardNumber.VISA;
    final UnionPayCardBuilder unionPayCardBuilder = new UnionPayCardBuilder().cardNumber(cardNumber).expirationMonth("12").expirationYear("2019").mobileCountryCode("62").mobilePhoneNumber("11111111111");
    mBraintreeFragment.addListener(new UnionPayListener() {

        @Override
        public void onCapabilitiesFetched(UnionPayCapabilities capabilities) {
            assertFalse(capabilities.isUnionPay());
            UnionPay.enroll(mBraintreeFragment, unionPayCardBuilder);
        }

        @Override
        public void onSmsCodeSent(String enrollmentId, boolean smsCodeRequired) {
            fail("Not expecting onSmsCodeSent");
        }
    });
    mBraintreeFragment.addListener(new BraintreeErrorListener() {

        @Override
        public void onError(Exception error) {
            assertTrue(error instanceof ErrorWithResponse);
            assertEquals("UnionPay Enrollment is invalid", error.getMessage());
            mCountDownLatch.countDown();
        }
    });
    UnionPay.fetchCapabilities(mBraintreeFragment, cardNumber);
    mCountDownLatch.await();
}
Also used : UnionPayListener(com.braintreepayments.api.interfaces.UnionPayListener) ErrorWithResponse(com.braintreepayments.api.exceptions.ErrorWithResponse) UnionPayCardBuilder(com.braintreepayments.api.models.UnionPayCardBuilder) UnionPayCapabilities(com.braintreepayments.api.models.UnionPayCapabilities) BraintreeErrorListener(com.braintreepayments.api.interfaces.BraintreeErrorListener) InvalidArgumentException(com.braintreepayments.api.exceptions.InvalidArgumentException) Test(org.junit.Test)

Example 9 with BraintreeErrorListener

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

the class CardTest method tokenize_failsWithTokenizationKeyAndValidateTrue.

@Test(timeout = 10000)
public void tokenize_failsWithTokenizationKeyAndValidateTrue() throws Exception {
    CardBuilder cardBuilder = new CardBuilder().cardNumber(VISA).expirationDate("08/20").validate(true);
    final CountDownLatch countDownLatch = new CountDownLatch(1);
    BraintreeFragment fragment = setupBraintreeFragment(TOKENIZATION_KEY);
    fragment.addListener(new BraintreeErrorListener() {

        @Override
        public void onError(Exception error) {
            assertTrue(error instanceof AuthorizationException);
            if (mRequestProtocol.equals(GRAPHQL)) {
                assertEquals("Validation is not supported for requests authorized with a tokenization key.", error.getMessage());
            } else {
                assertEquals("Tokenization key authorization not allowed for this endpoint. Please use an " + "authentication method with upgraded permissions", error.getMessage());
            }
            countDownLatch.countDown();
        }
    });
    Card.tokenize(fragment, cardBuilder);
    countDownLatch.await();
}
Also used : CardBuilder(com.braintreepayments.api.models.CardBuilder) AuthorizationException(com.braintreepayments.api.exceptions.AuthorizationException) CountDownLatch(java.util.concurrent.CountDownLatch) BraintreeErrorListener(com.braintreepayments.api.interfaces.BraintreeErrorListener) JSONException(org.json.JSONException) AuthorizationException(com.braintreepayments.api.exceptions.AuthorizationException) Test(org.junit.Test)

Example 10 with BraintreeErrorListener

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

the class CardTest method tokenize_callsErrorCallbackForInvalidCvv.

@Test(timeout = 10000)
public void tokenize_callsErrorCallbackForInvalidCvv() throws Exception {
    CardBuilder cardBuilder = new CardBuilder().cardNumber(VISA).expirationDate("08/20").cvv("200");
    final CountDownLatch countDownLatch = new CountDownLatch(1);
    BraintreeFragment fragment = setupBraintreeFragment(new TestClientTokenBuilder().withCvvVerification().build());
    fragment.addListener(new BraintreeErrorListener() {

        @Override
        public void onError(Exception error) {
            assertEquals("CVV verification failed", ((ErrorWithResponse) error).errorFor("creditCard").getFieldErrors().get(0).getMessage());
            countDownLatch.countDown();
        }
    });
    Card.tokenize(fragment, cardBuilder);
    countDownLatch.await();
}
Also used : CardBuilder(com.braintreepayments.api.models.CardBuilder) TestClientTokenBuilder(com.braintreepayments.api.test.TestClientTokenBuilder) CountDownLatch(java.util.concurrent.CountDownLatch) BraintreeErrorListener(com.braintreepayments.api.interfaces.BraintreeErrorListener) JSONException(org.json.JSONException) AuthorizationException(com.braintreepayments.api.exceptions.AuthorizationException) 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