Search in sources :

Example 11 with InvalidArgumentException

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

the class BraintreeGraphQLHttpClientTest method getRequestSslCertificateSuccessfulInProduction.

@Test(timeout = 5000)
public void getRequestSslCertificateSuccessfulInProduction() throws InterruptedException, InvalidArgumentException {
    BraintreeGraphQLHttpClient httpClient = new BraintreeGraphQLHttpClient("https://payments.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 12 with InvalidArgumentException

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

the class BraintreeHttpClientTest method getRequestBadCertificateCheck.

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

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

        @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) 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)

Example 13 with InvalidArgumentException

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

the class IdealActivity method onBraintreePaymentResult.

@Override
public void onBraintreePaymentResult(BraintreePaymentResult result) {
    super.onBraintreePaymentResult(result);
    IdealResult idealResult = (IdealResult) result;
    if (!mIsPolling && !("COMPLETE".equals(idealResult.getStatus()))) {
        try {
            Ideal.pollForCompletion(mBraintreeFragment, idealResult.getId(), 1, 1000);
            mIsPolling = true;
        } catch (InvalidArgumentException e) {
            onError(e);
        }
    } else {
        Intent intent = new Intent().putExtra(MainActivity.EXTRA_PAYMENT_RESULT, result);
        setResult(Activity.RESULT_OK, intent);
        finish();
    }
}
Also used : InvalidArgumentException(com.braintreepayments.api.exceptions.InvalidArgumentException) Intent(android.content.Intent) IdealResult(com.braintreepayments.api.models.IdealResult)

Example 14 with InvalidArgumentException

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

the class IdealUnitTest method fetchIssuingBanks_postsConfigurationExceptionWhenIdealNotEnabled.

@Test
public void fetchIssuingBanks_postsConfigurationExceptionWhenIdealNotEnabled() throws InvalidArgumentException {
    Configuration configuration = new TestConfigurationBuilder().braintreeApi(new TestBraintreeApiConfigurationBuilder().accessToken("access-token").url("http://api.braintree.com")).buildConfiguration();
    BraintreeFragment fragment = getMockFragment(stringFromFixture("client_token.json"), configuration);
    Ideal.fetchIssuingBanks(fragment, new BraintreeResponseListener<List<IdealBank>>() {

        @Override
        public void onResponse(List<IdealBank> idealBanks) {
            fail("Success listener called");
        }
    });
    ArgumentCaptor<Exception> captor = ArgumentCaptor.forClass(Exception.class);
    verify(fragment).postCallback(captor.capture());
    Exception e = captor.getValue();
    assertEquals("iDEAL is not enabled for this merchant.", e.getMessage());
}
Also used : TestBraintreeApiConfigurationBuilder(com.braintreepayments.testutils.TestConfigurationBuilder.TestBraintreeApiConfigurationBuilder) Configuration(com.braintreepayments.api.models.Configuration) IdealBank(com.braintreepayments.api.models.IdealBank) List(java.util.List) TestConfigurationBuilder(com.braintreepayments.testutils.TestConfigurationBuilder) JSONException(org.json.JSONException) IOException(java.io.IOException) InvalidArgumentException(com.braintreepayments.api.exceptions.InvalidArgumentException) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 15 with InvalidArgumentException

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

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