Search in sources :

Example 36 with CardBuilder

use of com.braintreepayments.api.models.CardBuilder in project braintree_android by braintree.

the class ThreeDSecureVerificationTest method performVerification_doesALookupAndReturnsACardAfterATimeout.

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

        @Override
        public void onPaymentMethodNonceCreated(PaymentMethodNonce paymentMethodNonce) {
            assertIsANonce(paymentMethodNonce.getNonce());
            CardNonce cardNonce = (CardNonce) paymentMethodNonce;
            assertEquals("44", cardNonce.getLastTwo());
            assertFalse(cardNonce.getThreeDSecureInfo().isLiabilityShifted());
            assertFalse(cardNonce.getThreeDSecureInfo().isLiabilityShiftPossible());
            assertTrue(((CardNonce) paymentMethodNonce).getThreeDSecureInfo().wasVerified());
            mCountDownLatch.countDown();
        }
    });
    CardBuilder cardBuilder = new CardBuilder().cardNumber(THREE_D_SECURE_LOOKUP_TIMEOUT).expirationDate("12/20");
    ThreeDSecure.performVerification(fragment, cardBuilder, TEST_AMOUNT);
    mCountDownLatch.await();
}
Also used : CardBuilder(com.braintreepayments.api.models.CardBuilder) CardNonce(com.braintreepayments.api.models.CardNonce) PaymentMethodNonceCreatedListener(com.braintreepayments.api.interfaces.PaymentMethodNonceCreatedListener) PaymentMethodNonce(com.braintreepayments.api.models.PaymentMethodNonce) Test(org.junit.Test)

Example 37 with CardBuilder

use of com.braintreepayments.api.models.CardBuilder in project braintree_android by braintree.

the class ThreeDSecureVerificationTest method performVerification_returnsAnErrorWhenAuthenticationFails.

@Test(timeout = 30000)
public void performVerification_returnsAnErrorWhenAuthenticationFails() 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_AUTHENTICATION_FAILED).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 38 with CardBuilder

use of com.braintreepayments.api.models.CardBuilder in project braintree_android by braintree.

the class ThreeDSecureVerificationTest method performVerification_returnsASuccessfulAuthenticationWhenIssuerDoesNotParticipate.

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

        @Override
        public void onPaymentMethodNonceCreated(PaymentMethodNonce paymentMethodNonce) {
            assertIsANonce(paymentMethodNonce.getNonce());
            CardNonce cardNonce = (CardNonce) paymentMethodNonce;
            assertEquals("01", cardNonce.getLastTwo());
            assertTrue(cardNonce.getThreeDSecureInfo().isLiabilityShifted());
            assertTrue(cardNonce.getThreeDSecureInfo().isLiabilityShiftPossible());
            assertTrue(((CardNonce) paymentMethodNonce).getThreeDSecureInfo().wasVerified());
            mCountDownLatch.countDown();
        }
    });
    CardBuilder cardBuilder = new CardBuilder().cardNumber(THREE_D_SECURE_ISSUER_DOES_NOT_PARTICIPATE).expirationDate("12/30");
    ThreeDSecure.performVerification(fragment, cardBuilder, TEST_AMOUNT);
    mCountDownLatch.await();
}
Also used : CardBuilder(com.braintreepayments.api.models.CardBuilder) CardNonce(com.braintreepayments.api.models.CardNonce) PaymentMethodNonceCreatedListener(com.braintreepayments.api.interfaces.PaymentMethodNonceCreatedListener) PaymentMethodNonce(com.braintreepayments.api.models.PaymentMethodNonce) Test(org.junit.Test)

Example 39 with CardBuilder

use of com.braintreepayments.api.models.CardBuilder in project braintree_android by braintree.

the class ThreeDSecureVerificationTest method performVerification_returnsAnUnexpectedErrorWhenIssuerIsDown.

@Test(timeout = 30000)
public void performVerification_returnsAnUnexpectedErrorWhenIssuerIsDown() 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_ISSUER_DOWN).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 40 with CardBuilder

use of com.braintreepayments.api.models.CardBuilder in project braintree_android by braintree.

the class ThreeDSecureVerificationTest method performVerification_doesALookupAndReturnsACardWhenThereIsAMPILookupError.

@Test(timeout = 10000)
public void performVerification_doesALookupAndReturnsACardWhenThereIsAMPILookupError() throws InterruptedException {
    BraintreeFragment fragment = getFragment();
    fragment.addListener(new PaymentMethodNonceCreatedListener() {

        @Override
        public void onPaymentMethodNonceCreated(PaymentMethodNonce paymentMethodNonce) {
            assertIsANonce(paymentMethodNonce.getNonce());
            CardNonce cardNonce = (CardNonce) paymentMethodNonce;
            assertEquals("85", cardNonce.getLastTwo());
            assertFalse(cardNonce.getThreeDSecureInfo().isLiabilityShifted());
            assertFalse(cardNonce.getThreeDSecureInfo().isLiabilityShiftPossible());
            assertTrue(((CardNonce) paymentMethodNonce).getThreeDSecureInfo().wasVerified());
            mCountDownLatch.countDown();
        }
    });
    CardBuilder cardBuilder = new CardBuilder().cardNumber(THREE_D_SECURE_MPI_LOOKUP_ERROR).expirationDate("12/20");
    ThreeDSecure.performVerification(fragment, cardBuilder, TEST_AMOUNT);
    mCountDownLatch.await();
}
Also used : CardBuilder(com.braintreepayments.api.models.CardBuilder) CardNonce(com.braintreepayments.api.models.CardNonce) PaymentMethodNonceCreatedListener(com.braintreepayments.api.interfaces.PaymentMethodNonceCreatedListener) PaymentMethodNonce(com.braintreepayments.api.models.PaymentMethodNonce) Test(org.junit.Test)

Aggregations

CardBuilder (com.braintreepayments.api.models.CardBuilder)41 Test (org.junit.Test)39 PaymentMethodNonce (com.braintreepayments.api.models.PaymentMethodNonce)15 TestClientTokenBuilder (com.braintreepayments.api.test.TestClientTokenBuilder)14 CardNonce (com.braintreepayments.api.models.CardNonce)12 PaymentMethodNonceCreatedListener (com.braintreepayments.api.interfaces.PaymentMethodNonceCreatedListener)11 AuthorizationException (com.braintreepayments.api.exceptions.AuthorizationException)10 BraintreeErrorListener (com.braintreepayments.api.interfaces.BraintreeErrorListener)10 InvalidArgumentException (com.braintreepayments.api.exceptions.InvalidArgumentException)7 UnionPayCardBuilder (com.braintreepayments.api.models.UnionPayCardBuilder)7 CountDownLatch (java.util.concurrent.CountDownLatch)6 JSONException (org.json.JSONException)5 TestConfigurationBuilder (com.braintreepayments.testutils.TestConfigurationBuilder)4 HttpResponseCallback (com.braintreepayments.api.interfaces.HttpResponseCallback)3 Matchers.anyString (org.mockito.Matchers.anyString)3 BraintreeException (com.braintreepayments.api.exceptions.BraintreeException)2 BraintreeCancelListener (com.braintreepayments.api.interfaces.BraintreeCancelListener)2 PaymentMethodNonceCallback (com.braintreepayments.api.interfaces.PaymentMethodNonceCallback)2 PaymentMethodNoncesUpdatedListener (com.braintreepayments.api.interfaces.PaymentMethodNoncesUpdatedListener)2 ErrorWithResponse (com.braintreepayments.api.exceptions.ErrorWithResponse)1