Search in sources :

Example 1 with TestClientTokenBuilder

use of com.braintreepayments.api.test.TestClientTokenBuilder in project braintree_android by braintree.

the class ThreeDSecureTest method performVerification_acceptsACardBuilderAndPostsAPaymentMethodNonceToListener.

@Test(timeout = 10000)
public void performVerification_acceptsACardBuilderAndPostsAPaymentMethodNonceToListener() throws InterruptedException {
    String clientToken = new TestClientTokenBuilder().withThreeDSecure().build();
    BraintreeFragment fragment = getFragmentWithAuthorization(mActivity, clientToken);
    fragment.addListener(new PaymentMethodNonceCreatedListener() {

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

Example 2 with TestClientTokenBuilder

use of com.braintreepayments.api.test.TestClientTokenBuilder in project braintree_android by braintree.

the class ThreeDSecureTest method performVerification_acceptsAThreeDSecureRequest_postsPaymentMethodNonceToListenersWhenLookupReturnsACard.

@Test(timeout = 10000)
public void performVerification_acceptsAThreeDSecureRequest_postsPaymentMethodNonceToListenersWhenLookupReturnsACard() throws InterruptedException, InvalidArgumentException {
    String clientToken = new TestClientTokenBuilder().withThreeDSecure().build();
    BraintreeFragment fragment = getFragmentWithAuthorization(mActivity, clientToken);
    String nonce = tokenize(fragment, new CardBuilder().cardNumber("4000000000000051").expirationDate("12/20")).getNonce();
    fragment.addListener(new PaymentMethodNonceCreatedListener() {

        @Override
        public void onPaymentMethodNonceCreated(PaymentMethodNonce paymentMethodNonce) {
            assertIsANonce(paymentMethodNonce.getNonce());
            assertEquals("51", ((CardNonce) paymentMethodNonce).getLastTwo());
            ThreeDSecureInfo threeDSecureInfo = ((CardNonce) paymentMethodNonce).getThreeDSecureInfo();
            assertFalse(threeDSecureInfo.isLiabilityShifted());
            assertFalse(threeDSecureInfo.isLiabilityShiftPossible());
            assertTrue(((CardNonce) paymentMethodNonce).getThreeDSecureInfo().wasVerified());
            mCountDownLatch.countDown();
        }
    });
    ThreeDSecureRequest request = new ThreeDSecureRequest().nonce(nonce).amount("5");
    ThreeDSecure.performVerification(fragment, request);
    mCountDownLatch.await();
}
Also used : ThreeDSecureRequest(com.braintreepayments.api.models.ThreeDSecureRequest) CardBuilder(com.braintreepayments.api.models.CardBuilder) TestClientTokenBuilder(com.braintreepayments.api.test.TestClientTokenBuilder) ThreeDSecureInfo(com.braintreepayments.api.models.ThreeDSecureInfo) CardNonce(com.braintreepayments.api.models.CardNonce) PaymentMethodNonceCreatedListener(com.braintreepayments.api.interfaces.PaymentMethodNonceCreatedListener) PaymentMethodNonce(com.braintreepayments.api.models.PaymentMethodNonce) Test(org.junit.Test)

Example 3 with TestClientTokenBuilder

use of com.braintreepayments.api.test.TestClientTokenBuilder in project braintree_android by braintree.

the class ThreeDSecureTest method performVerification_withInvalidThreeDSecureRequest_postsException.

@Test(timeout = 1000)
public void performVerification_withInvalidThreeDSecureRequest_postsException() throws InterruptedException, InvalidArgumentException {
    String clientToken = new TestClientTokenBuilder().withThreeDSecure().build();
    BraintreeFragment fragment = getFragmentWithAuthorization(mActivity, clientToken);
    fragment.addListener(new BraintreeErrorListener() {

        @Override
        public void onError(Exception error) {
            assertEquals("The ThreeDSecureRequest nonce and amount cannot be null", error.getMessage());
            mCountDownLatch.countDown();
        }
    });
    ThreeDSecureRequest request = new ThreeDSecureRequest().amount("5");
    ThreeDSecure.performVerification(fragment, request);
    mCountDownLatch.await();
}
Also used : ThreeDSecureRequest(com.braintreepayments.api.models.ThreeDSecureRequest) TestClientTokenBuilder(com.braintreepayments.api.test.TestClientTokenBuilder) BraintreeErrorListener(com.braintreepayments.api.interfaces.BraintreeErrorListener) JSONException(org.json.JSONException) InvalidArgumentException(com.braintreepayments.api.exceptions.InvalidArgumentException) Test(org.junit.Test)

Example 4 with TestClientTokenBuilder

use of com.braintreepayments.api.test.TestClientTokenBuilder in project braintree_android by braintree.

the class UnionPayTest method setUp.

@Before
public void setUp() throws InvalidArgumentException {
    mCountDownLatch = new CountDownLatch(1);
    mBraintreeFragment = getFragmentWithAuthorization(mActivityTestRule.getActivity(), new TestClientTokenBuilder().withUnionPay().build());
}
Also used : TestClientTokenBuilder(com.braintreepayments.api.test.TestClientTokenBuilder) CountDownLatch(java.util.concurrent.CountDownLatch) Before(org.junit.Before)

Example 5 with TestClientTokenBuilder

use of com.braintreepayments.api.test.TestClientTokenBuilder in project braintree_android by braintree.

the class AnalyticsSenderTest method sendsCorrectlyFormattedAnalyticsRequest.

@Test(timeout = 10000)
public void sendsCorrectlyFormattedAnalyticsRequest() throws Exception {
    final CountDownLatch latch = new CountDownLatch(1);
    String authorization = new TestClientTokenBuilder().withAnalytics().build();
    final Configuration configuration = Configuration.fromJson(authorization);
    AnalyticsEvent event = new AnalyticsEvent(getTargetContext(), "sessionId", "custom", "event.started");
    AnalyticsDatabase.getInstance(getTargetContext()).addEvent(event);
    BraintreeHttpClient httpClient = new BraintreeHttpClient(Authorization.fromString(authorization)) {

        @Override
        protected String parseResponse(HttpURLConnection connection) throws Exception {
            if (connection.getURL().toString().equals(configuration.getAnalytics().getUrl())) {
                assertEquals(200, connection.getResponseCode());
                latch.countDown();
            }
            return "";
        }
    };
    AnalyticsSender.send(getTargetContext(), Authorization.fromString(authorization), httpClient, configuration.getAnalytics().getUrl(), true);
    latch.await();
}
Also used : TestClientTokenBuilder(com.braintreepayments.api.test.TestClientTokenBuilder) HttpURLConnection(java.net.HttpURLConnection) Configuration(com.braintreepayments.api.models.Configuration) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Aggregations

TestClientTokenBuilder (com.braintreepayments.api.test.TestClientTokenBuilder)19 Test (org.junit.Test)16 CardBuilder (com.braintreepayments.api.models.CardBuilder)14 CountDownLatch (java.util.concurrent.CountDownLatch)7 BraintreeErrorListener (com.braintreepayments.api.interfaces.BraintreeErrorListener)5 AuthorizationException (com.braintreepayments.api.exceptions.AuthorizationException)4 CardNonce (com.braintreepayments.api.models.CardNonce)4 PaymentMethodNonce (com.braintreepayments.api.models.PaymentMethodNonce)4 InvalidArgumentException (com.braintreepayments.api.exceptions.InvalidArgumentException)3 PaymentMethodNonceCreatedListener (com.braintreepayments.api.interfaces.PaymentMethodNonceCreatedListener)3 JSONException (org.json.JSONException)3 Before (org.junit.Before)3 ThreeDSecureRequest (com.braintreepayments.api.models.ThreeDSecureRequest)2 ErrorWithResponse (com.braintreepayments.api.exceptions.ErrorWithResponse)1 PaymentMethodNoncesUpdatedListener (com.braintreepayments.api.interfaces.PaymentMethodNoncesUpdatedListener)1 Configuration (com.braintreepayments.api.models.Configuration)1 ThreeDSecureInfo (com.braintreepayments.api.models.ThreeDSecureInfo)1 HttpURLConnection (java.net.HttpURLConnection)1