use of com.braintreepayments.api.interfaces.HttpResponseCallback in project braintree_android by braintree.
the class BraintreeApiHttpClientTest method getRequestSslCertificateSuccessfulInSandbox.
@Test(timeout = 5000)
public void getRequestSslCertificateSuccessfulInSandbox() throws InterruptedException {
final CountDownLatch latch = new CountDownLatch(1);
BraintreeApiHttpClient client = new BraintreeApiHttpClient("https://payments.sandbox.braintree-api.com", null);
client.get("/ping", new HttpResponseCallback() {
@Override
public void success(String responseBody) {
try {
assertEquals("OK", new JSONObject(responseBody).getJSONObject("data").getString("status"));
} catch (JSONException e) {
fail("Response invalid");
}
latch.countDown();
}
@Override
public void failure(Exception exception) {
fail("Request failed");
}
});
latch.await();
}
use of com.braintreepayments.api.interfaces.HttpResponseCallback 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();
}
use of com.braintreepayments.api.interfaces.HttpResponseCallback 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();
}
use of com.braintreepayments.api.interfaces.HttpResponseCallback in project braintree_android by braintree.
the class BraintreeHttpClientTest method assertExceptionIsPosted.
private void assertExceptionIsPosted(BraintreeHttpClient httpClient, final Class<? extends Exception> exceptionType, final String exceptionMessage) throws Exception {
final CountDownLatch countDownLatch = new CountDownLatch(2);
httpClient.get("/", new HttpResponseCallback() {
@Override
public void success(String responseBody) {
fail("Request was successful");
}
@Override
public void failure(Exception exception) {
assertEquals(exceptionType, exception.getClass());
if (exceptionMessage != null) {
assertEquals(exceptionMessage, exception.getMessage());
}
countDownLatch.countDown();
}
});
httpClient.post("/", "{}", new HttpResponseCallback() {
@Override
public void success(String responseBody) {
fail("Request was successful");
}
@Override
public void failure(Exception exception) {
assertEquals(exceptionType, exception.getClass());
if (exceptionMessage != null) {
assertEquals(exceptionMessage, exception.getMessage());
}
countDownLatch.countDown();
}
});
countDownLatch.await();
}
use of com.braintreepayments.api.interfaces.HttpResponseCallback in project braintree_android by braintree.
the class Ideal method fetchIssuingBanks.
/**
* Makes a call to fetch the list of potential issuing banks with which a customer can pay.
*
* @param fragment {@link BraintreeFragment}
* @param listener {@link BraintreeResponseListener} the callback to which a list of issuing banks will be provided.
*/
public static void fetchIssuingBanks(final BraintreeFragment fragment, final BraintreeResponseListener<List<IdealBank>> listener) {
fragment.waitForConfiguration(new ConfigurationListener() {
@Override
public void onConfigurationFetched(final Configuration configuration) {
Exception configException = checkIdealEnabled(configuration);
if (configException != null) {
fragment.postCallback(configException);
return;
}
fragment.getBraintreeApiHttpClient().get("/issuers/ideal", new HttpResponseCallback() {
@Override
public void success(String responseBody) {
fragment.sendAnalyticsEvent("ideal.load.succeeded");
try {
List<IdealBank> banks = IdealBank.fromJson(configuration, responseBody);
if (listener != null) {
listener.onResponse(banks);
}
} catch (JSONException jsonException) {
failure(jsonException);
}
}
@Override
public void failure(Exception exception) {
fragment.sendAnalyticsEvent("ideal.load.failed");
fragment.postCallback(exception);
}
});
}
});
}
Aggregations