use of com.braintreepayments.api.exceptions.AuthorizationException 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();
}
use of com.braintreepayments.api.exceptions.AuthorizationException 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();
}
use of com.braintreepayments.api.exceptions.AuthorizationException in project braintree_android by braintree.
the class BraintreeHttpClientTest method getRequestSslCertificateSuccessfulInProduction.
@Test(timeout = 5000)
public void getRequestSslCertificateSuccessfulInProduction() throws InterruptedException, InvalidArgumentException {
BraintreeHttpClient httpClient = new BraintreeHttpClient(TokenizationKey.fromString(TOKENIZATION_KEY));
httpClient.setBaseUrl("https://api.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();
}
use of com.braintreepayments.api.exceptions.AuthorizationException in project braintree_android by braintree.
the class BraintreeGraphQLHttpClient method parseResponse.
@Override
protected String parseResponse(HttpURLConnection connection) throws Exception {
String response = super.parseResponse(connection);
JSONArray errors = new JSONObject(response).optJSONArray(ErrorWithResponse.GRAPHQL_ERRORS_KEY);
if (errors != null) {
for (int i = 0; i < errors.length(); i++) {
JSONObject error = errors.getJSONObject(i);
JSONObject extensions = error.optJSONObject("extensions");
if (extensions == null) {
throw new UnexpectedException("An unexpected error occurred");
}
if (Json.optString(extensions, "legacyCode", "").equals("50000")) {
throw new AuthorizationException(error.getString("message"));
} else if (!Json.optString(extensions, "errorType", "").equals("user_error")) {
throw new UnexpectedException("An unexpected error occurred");
}
}
throw ErrorWithResponse.fromGraphQLJson(response);
}
return response;
}
Aggregations