Search in sources :

Example 21 with InvalidArgumentException

use of com.braintreepayments.api.exceptions.InvalidArgumentException 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 22 with InvalidArgumentException

use of com.braintreepayments.api.exceptions.InvalidArgumentException 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 23 with InvalidArgumentException

use of com.braintreepayments.api.exceptions.InvalidArgumentException in project braintree_android by braintree.

the class BraintreeGraphQLHttpClientTest method getRequestSslCertificateSuccessfulInSandbox.

@Test(timeout = 5000)
public void getRequestSslCertificateSuccessfulInSandbox() throws InterruptedException, InvalidArgumentException {
    BraintreeGraphQLHttpClient httpClient = new BraintreeGraphQLHttpClient("https://payments.sandbox.braintree-api.com/graphql", TOKENIZATION_KEY);
    httpClient.get("/", new HttpResponseCallback() {

        @Override
        public void success(String responseBody) {
            mCountDownLatch.countDown();
        }

        @Override
        public void failure(Exception exception) {
            assertFalse(exception instanceof SSLException);
            mCountDownLatch.countDown();
        }
    });
    mCountDownLatch.await();
}
Also used : HttpResponseCallback(com.braintreepayments.api.interfaces.HttpResponseCallback) SSLException(javax.net.ssl.SSLException) AuthorizationException(com.braintreepayments.api.exceptions.AuthorizationException) UnexpectedException(com.braintreepayments.api.exceptions.UnexpectedException) IOException(java.io.IOException) InvalidArgumentException(com.braintreepayments.api.exceptions.InvalidArgumentException) SSLException(javax.net.ssl.SSLException) Test(org.junit.Test)

Example 24 with InvalidArgumentException

use of com.braintreepayments.api.exceptions.InvalidArgumentException in project braintree_android by braintree.

the class BraintreeGraphQLHttpClientTest method getRequestBadCertificateCheck.

@Test(timeout = 5000)
public void getRequestBadCertificateCheck() throws InterruptedException, InvalidArgumentException {
    if (!BuildConfig.RUN_ALL_TESTS) {
        return;
    }
    String baseUrl = "https://" + EnvironmentHelper.getLocalhostIp() + ":9443";
    BraintreeGraphQLHttpClient httpClient = new BraintreeGraphQLHttpClient(baseUrl, TOKENIZATION_KEY);
    httpClient.get("/", new HttpResponseCallback() {

        @Override
        public void success(String responseBody) {
            fail("Request was successful");
            mCountDownLatch.countDown();
        }

        @Override
        public void failure(Exception exception) {
            assertEquals("java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.", exception.getMessage());
            mCountDownLatch.countDown();
        }
    });
    mCountDownLatch.await();
}
Also used : HttpResponseCallback(com.braintreepayments.api.interfaces.HttpResponseCallback) AuthorizationException(com.braintreepayments.api.exceptions.AuthorizationException) UnexpectedException(com.braintreepayments.api.exceptions.UnexpectedException) IOException(java.io.IOException) InvalidArgumentException(com.braintreepayments.api.exceptions.InvalidArgumentException) SSLException(javax.net.ssl.SSLException) Test(org.junit.Test)

Example 25 with InvalidArgumentException

use of com.braintreepayments.api.exceptions.InvalidArgumentException in project braintree_android by braintree.

the class BraintreeHttpClientTest method getRequestSslCertificateSuccessfulInSandbox.

@Test(timeout = 5000)
public void getRequestSslCertificateSuccessfulInSandbox() throws InterruptedException, InvalidArgumentException {
    BraintreeHttpClient httpClient = new BraintreeHttpClient(TokenizationKey.fromString(TOKENIZATION_KEY));
    httpClient.setBaseUrl("https://api.sandbox.braintreegateway.com");
    httpClient.get("/", new HttpResponseCallback() {

        @Override
        public void success(String responseBody) {
            fail("Request failed");
        }

        @Override
        public void failure(Exception exception) {
            assertTrue(exception instanceof AuthorizationException);
            mCountDownLatch.countDown();
        }
    });
    mCountDownLatch.await();
}
Also used : AuthorizationException(com.braintreepayments.api.exceptions.AuthorizationException) HttpResponseCallback(com.braintreepayments.api.interfaces.HttpResponseCallback) JSONException(org.json.JSONException) AuthorizationException(com.braintreepayments.api.exceptions.AuthorizationException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) InvalidArgumentException(com.braintreepayments.api.exceptions.InvalidArgumentException) Test(org.junit.Test)

Aggregations

InvalidArgumentException (com.braintreepayments.api.exceptions.InvalidArgumentException)31 Test (org.junit.Test)27 JSONException (org.json.JSONException)22 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)14 AuthorizationException (com.braintreepayments.api.exceptions.AuthorizationException)12 BraintreeErrorListener (com.braintreepayments.api.interfaces.BraintreeErrorListener)12 IOException (java.io.IOException)12 HttpResponseCallback (com.braintreepayments.api.interfaces.HttpResponseCallback)10 Configuration (com.braintreepayments.api.models.Configuration)7 MalformedURLException (java.net.MalformedURLException)6 Intent (android.content.Intent)4 UnexpectedException (com.braintreepayments.api.exceptions.UnexpectedException)4 Authorization (com.braintreepayments.api.models.Authorization)4 CountDownLatch (java.util.concurrent.CountDownLatch)4 ErrorWithResponse (com.braintreepayments.api.exceptions.ErrorWithResponse)3 ConfigurationListener (com.braintreepayments.api.interfaces.ConfigurationListener)3 PaymentMethodNoncesUpdatedListener (com.braintreepayments.api.interfaces.PaymentMethodNoncesUpdatedListener)3 IdealBank (com.braintreepayments.api.models.IdealBank)3 PaymentMethodNonce (com.braintreepayments.api.models.PaymentMethodNonce)3 List (java.util.List)3