use of com.braintreepayments.api.exceptions.AuthorizationException in project braintree_android by braintree.
the class VenmoUnitTest method onActivityResult_withFailedVaultCall_postsCallbackToErrorListener.
@Test
public void onActivityResult_withFailedVaultCall_postsCallbackToErrorListener() throws InvalidArgumentException {
Configuration configuration = getConfigurationFromFixture();
Authorization clientToken = Authorization.fromString(stringFromFixture("base_64_client_token.txt"));
disableSignatureVerification();
BraintreeFragment fragment = new MockFragmentBuilder().context(VenmoInstalledContextFactory.venmoInstalledContext(true, RuntimeEnvironment.application)).configuration(configuration).authorization(clientToken).sessionId("session-id").errorResponse(new AuthorizationException("Bad fingerprint")).build();
ArgumentCaptor<Exception> responseCaptor = ArgumentCaptor.forClass(Exception.class);
Venmo.authorizeAccount(fragment, true);
Intent responseIntent = new Intent().putExtra(Venmo.EXTRA_PAYMENT_METHOD_NONCE, "nonce");
Venmo.onActivityResult(fragment, Activity.RESULT_OK, responseIntent);
verify(fragment).postCallback(responseCaptor.capture());
Exception exception = responseCaptor.getValue();
assertTrue(exception instanceof AuthorizationException);
assertEquals("Bad fingerprint", exception.getMessage());
}
use of com.braintreepayments.api.exceptions.AuthorizationException in project braintree_android by braintree.
the class BraintreeGraphQLHttpClientTest method parseResponseFailsWithValidationNotAllowed.
@Test
public void parseResponseFailsWithValidationNotAllowed() throws Exception {
String baseUrl = "http://example.com/graphql";
HttpClient httpClient = new BraintreeGraphQLHttpClient(baseUrl, TOKENIZATION_KEY);
httpClient = HttpClientTestUtils.stubResponse(httpClient, 200, FixturesHelper.stringFromFixture("errors/graphql/validation_not_allowed_error.json"));
HttpURLConnection connection = httpClient.init(baseUrl);
try {
httpClient.parseResponse(connection);
fail("No exception was thrown");
} catch (AuthorizationException e) {
assertEquals("Validation is not supported for requests authorized with a tokenization key.", e.getMessage());
}
}
use of com.braintreepayments.api.exceptions.AuthorizationException in project braintree_android by braintree.
the class CardTest method tokenize_failsWithTokenizationKeyAndValidateTrue.
@Test(timeout = 10000)
public void tokenize_failsWithTokenizationKeyAndValidateTrue() throws Exception {
CardBuilder cardBuilder = new CardBuilder().cardNumber(VISA).expirationDate("08/20").validate(true);
final CountDownLatch countDownLatch = new CountDownLatch(1);
BraintreeFragment fragment = setupBraintreeFragment(TOKENIZATION_KEY);
fragment.addListener(new BraintreeErrorListener() {
@Override
public void onError(Exception error) {
assertTrue(error instanceof AuthorizationException);
if (mRequestProtocol.equals(GRAPHQL)) {
assertEquals("Validation is not supported for requests authorized with a tokenization key.", error.getMessage());
} else {
assertEquals("Tokenization key authorization not allowed for this endpoint. Please use an " + "authentication method with upgraded permissions", error.getMessage());
}
countDownLatch.countDown();
}
});
Card.tokenize(fragment, cardBuilder);
countDownLatch.await();
}
use of com.braintreepayments.api.exceptions.AuthorizationException in project braintree_android by braintree.
the class ThreeDSecureVerificationTest method performVerification_failsWithATokenizationKey.
@Test(timeout = 10000)
public void performVerification_failsWithATokenizationKey() throws InterruptedException {
String clientToken = new TestClientTokenBuilder().withThreeDSecure().build();
BraintreeFragment fragment = getFragment(TOKENIZATION_KEY, clientToken);
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());
mCountDownLatch.countDown();
}
});
CardBuilder cardBuilder = new CardBuilder().cardNumber(THREE_D_SECURE_VERIFICATON).expirationDate("12/20");
ThreeDSecure.performVerification(fragment, cardBuilder, TEST_AMOUNT);
mCountDownLatch.await();
}
use of com.braintreepayments.api.exceptions.AuthorizationException in project braintree_android by braintree.
the class VenmoUnitTest method onActivityResult_withFailedVaultCall_sendsAnalyticsEvent.
@Test
public void onActivityResult_withFailedVaultCall_sendsAnalyticsEvent() throws InvalidArgumentException {
Configuration configuration = getConfigurationFromFixture();
Authorization clientToken = Authorization.fromString(stringFromFixture("base_64_client_token.txt"));
disableSignatureVerification();
BraintreeFragment fragment = new MockFragmentBuilder().context(VenmoInstalledContextFactory.venmoInstalledContext(true, RuntimeEnvironment.application)).configuration(configuration).authorization(clientToken).sessionId("session-id").errorResponse(new AuthorizationException("Bad fingerprint")).build();
Venmo.authorizeAccount(fragment, true);
Intent responseIntent = new Intent().putExtra(Venmo.EXTRA_PAYMENT_METHOD_NONCE, "nonce");
Venmo.onActivityResult(fragment, Activity.RESULT_OK, responseIntent);
verify(fragment).sendAnalyticsEvent(endsWith("pay-with-venmo.vault.failed"));
}
Aggregations