Search in sources :

Example 1 with AuthorizationException

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());
}
Also used : Authorization(com.braintreepayments.api.models.Authorization) Configuration(com.braintreepayments.api.models.Configuration) AuthorizationException(com.braintreepayments.api.exceptions.AuthorizationException) Intent(android.content.Intent) AppSwitchNotAvailableException(com.braintreepayments.api.exceptions.AppSwitchNotAvailableException) JSONException(org.json.JSONException) InvalidArgumentException(com.braintreepayments.api.exceptions.InvalidArgumentException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) AuthorizationException(com.braintreepayments.api.exceptions.AuthorizationException) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 2 with AuthorizationException

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());
    }
}
Also used : HttpURLConnection(java.net.HttpURLConnection) AuthorizationException(com.braintreepayments.api.exceptions.AuthorizationException) Test(org.junit.Test)

Example 3 with AuthorizationException

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();
}
Also used : CardBuilder(com.braintreepayments.api.models.CardBuilder) AuthorizationException(com.braintreepayments.api.exceptions.AuthorizationException) CountDownLatch(java.util.concurrent.CountDownLatch) BraintreeErrorListener(com.braintreepayments.api.interfaces.BraintreeErrorListener) JSONException(org.json.JSONException) AuthorizationException(com.braintreepayments.api.exceptions.AuthorizationException) Test(org.junit.Test)

Example 4 with AuthorizationException

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();
}
Also used : CardBuilder(com.braintreepayments.api.models.CardBuilder) TestClientTokenBuilder(com.braintreepayments.api.test.TestClientTokenBuilder) AuthorizationException(com.braintreepayments.api.exceptions.AuthorizationException) BraintreeErrorListener(com.braintreepayments.api.interfaces.BraintreeErrorListener) AuthorizationException(com.braintreepayments.api.exceptions.AuthorizationException) InvalidArgumentException(com.braintreepayments.api.exceptions.InvalidArgumentException) Test(org.junit.Test)

Example 5 with AuthorizationException

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"));
}
Also used : Authorization(com.braintreepayments.api.models.Authorization) Configuration(com.braintreepayments.api.models.Configuration) AuthorizationException(com.braintreepayments.api.exceptions.AuthorizationException) Intent(android.content.Intent) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

AuthorizationException (com.braintreepayments.api.exceptions.AuthorizationException)9 Test (org.junit.Test)8 InvalidArgumentException (com.braintreepayments.api.exceptions.InvalidArgumentException)5 JSONException (org.json.JSONException)4 BraintreeErrorListener (com.braintreepayments.api.interfaces.BraintreeErrorListener)3 CardBuilder (com.braintreepayments.api.models.CardBuilder)3 Intent (android.content.Intent)2 HttpResponseCallback (com.braintreepayments.api.interfaces.HttpResponseCallback)2 Authorization (com.braintreepayments.api.models.Authorization)2 Configuration (com.braintreepayments.api.models.Configuration)2 IOException (java.io.IOException)2 MalformedURLException (java.net.MalformedURLException)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)2 AppSwitchNotAvailableException (com.braintreepayments.api.exceptions.AppSwitchNotAvailableException)1 UnexpectedException (com.braintreepayments.api.exceptions.UnexpectedException)1 PaymentMethodNoncesUpdatedListener (com.braintreepayments.api.interfaces.PaymentMethodNoncesUpdatedListener)1 PaymentMethodNonce (com.braintreepayments.api.models.PaymentMethodNonce)1 TestClientTokenBuilder (com.braintreepayments.api.test.TestClientTokenBuilder)1 HttpURLConnection (java.net.HttpURLConnection)1