Search in sources :

Example 11 with BraintreeErrorListener

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

the class IdealTest method startPayment_returnsPendingPayment.

@Test(timeout = 10000)
public void startPayment_returnsPendingPayment() throws InterruptedException {
    IdealRequest builder = new IdealRequest().currency("EUR").amount("10").issuerId("INGBNL2A").orderId(UUID.randomUUID().toString().substring(0, 15));
    Ideal.startPayment(mBraintreeFragment, builder, null);
    String savedId;
    do {
        savedId = BraintreeSharedPreferences.getString(mBraintreeFragment.getApplicationContext(), Ideal.IDEAL_RESULT_ID);
        SystemClock.sleep(500);
    } while (savedId.equals(""));
    Ideal.onActivityResult(mBraintreeFragment, Activity.RESULT_OK);
    mBraintreeFragment.addListener(new BraintreeErrorListener() {

        @Override
        public void onError(Exception error) {
            fail(error.getMessage());
        }
    });
    mBraintreeFragment.addListener(new BraintreePaymentResultListener() {

        @Override
        public void onBraintreePaymentResult(BraintreePaymentResult result) {
            assertTrue(result instanceof IdealResult);
            IdealResult idealResult = (IdealResult) result;
            assertFalse(TextUtils.isEmpty(idealResult.getId()));
            assertFalse(TextUtils.isEmpty(idealResult.getShortId()));
            assertFalse(TextUtils.isEmpty(idealResult.getStatus()));
            mCountDownLatch.countDown();
        }
    });
    mCountDownLatch.await();
}
Also used : BraintreePaymentResult(com.braintreepayments.api.models.BraintreePaymentResult) IdealRequest(com.braintreepayments.api.models.IdealRequest) BraintreeErrorListener(com.braintreepayments.api.interfaces.BraintreeErrorListener) InvalidArgumentException(com.braintreepayments.api.exceptions.InvalidArgumentException) IdealResult(com.braintreepayments.api.models.IdealResult) BraintreePaymentResultListener(com.braintreepayments.api.interfaces.BraintreePaymentResultListener) Test(org.junit.Test)

Example 12 with BraintreeErrorListener

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

the class ThreeDSecureVerificationTest method performVerification_returnsAFailedAuthenticationWhenSignatureVerificationFails.

@Test(timeout = 30000)
public void performVerification_returnsAFailedAuthenticationWhenSignatureVerificationFails() throws InterruptedException {
    BraintreeFragment fragment = getFragment();
    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();
        }
    });
    CardBuilder cardBuilder = new CardBuilder().cardNumber(THREE_D_SECURE_SIGNATURE_VERIFICATION_FAILURE).expirationDate("12/30");
    ThreeDSecure.performVerification(fragment, cardBuilder, TEST_AMOUNT);
    waitForView(withId(android.R.id.widget_frame));
    clickWebViewText("Password:");
    onDevice().pressTab().typeText("1234");
    clickWebViewText("Submit");
    mCountDownLatch.await();
}
Also used : CardBuilder(com.braintreepayments.api.models.CardBuilder) BraintreeErrorListener(com.braintreepayments.api.interfaces.BraintreeErrorListener) AuthorizationException(com.braintreepayments.api.exceptions.AuthorizationException) InvalidArgumentException(com.braintreepayments.api.exceptions.InvalidArgumentException) Test(org.junit.Test)

Example 13 with BraintreeErrorListener

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

the class ThreeDSecureVerificationTest method performVerification_failsWithATokenizationKey.

@Test(timeout = 10000)
public void performVerification_failsWithATokenizationKey() throws InterruptedException {
    String clientToken = new TestClientTokenBuilder().withThreeDSecure().build();
    BraintreeFragment fragment = getFragment(TOKENIZATION_KEY, clientToken);
    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());
            mCountDownLatch.countDown();
        }
    });
    CardBuilder cardBuilder = new CardBuilder().cardNumber(THREE_D_SECURE_VERIFICATON).expirationDate("12/20");
    ThreeDSecure.performVerification(fragment, cardBuilder, TEST_AMOUNT);
    mCountDownLatch.await();
}
Also used : CardBuilder(com.braintreepayments.api.models.CardBuilder) TestClientTokenBuilder(com.braintreepayments.api.test.TestClientTokenBuilder) AuthorizationException(com.braintreepayments.api.exceptions.AuthorizationException) BraintreeErrorListener(com.braintreepayments.api.interfaces.BraintreeErrorListener) AuthorizationException(com.braintreepayments.api.exceptions.AuthorizationException) InvalidArgumentException(com.braintreepayments.api.exceptions.InvalidArgumentException) Test(org.junit.Test)

Example 14 with BraintreeErrorListener

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

the class ThreeDSecureVerificationTest method performVerification_returnsAnErrorWhenCardinalReturnsError.

@Test(timeout = 30000)
public void performVerification_returnsAnErrorWhenCardinalReturnsError() throws InterruptedException {
    BraintreeFragment fragment = getFragment();
    fragment.addListener(new BraintreeErrorListener() {

        @Override
        public void onError(Exception error) {
            assertEquals("An unexpected error occurred", error.getMessage());
            mCountDownLatch.countDown();
        }
    });
    CardBuilder cardBuilder = new CardBuilder().cardNumber(THREE_D_SECURE_MPI_SERVICE_ERROR).expirationDate("12/30");
    ThreeDSecure.performVerification(fragment, cardBuilder, TEST_AMOUNT);
    waitForView(withId(android.R.id.widget_frame));
    clickWebViewText("Password:");
    onDevice().pressTab().typeText("1234");
    clickWebViewText("Submit");
    mCountDownLatch.await();
}
Also used : CardBuilder(com.braintreepayments.api.models.CardBuilder) BraintreeErrorListener(com.braintreepayments.api.interfaces.BraintreeErrorListener) AuthorizationException(com.braintreepayments.api.exceptions.AuthorizationException) InvalidArgumentException(com.braintreepayments.api.exceptions.InvalidArgumentException) Test(org.junit.Test)

Example 15 with BraintreeErrorListener

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

the class BraintreeFragmentUnitTest method addListener_flushesErrorWithResponseCallback.

@Test
public void addListener_flushesErrorWithResponseCallback() throws InvalidArgumentException {
    BraintreeFragment fragment = BraintreeFragment.newInstance(mActivity, TOKENIZATION_KEY);
    fragment.postCallback(new ErrorWithResponse(422, ""));
    fragment.addListener(new BraintreeErrorListener() {

        @Override
        public void onError(Exception error) {
            assertTrue(error instanceof ErrorWithResponse);
            assertEquals(422, ((ErrorWithResponse) error).getStatusCode());
            mCalled.set(true);
        }
    });
    assertTrue(mCalled.get());
}
Also used : ErrorWithResponse(com.braintreepayments.api.exceptions.ErrorWithResponse) BraintreeErrorListener(com.braintreepayments.api.interfaces.BraintreeErrorListener) JSONException(org.json.JSONException) InvalidArgumentException(com.braintreepayments.api.exceptions.InvalidArgumentException) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) 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