use of com.braintreepayments.api.exceptions.InvalidArgumentException in project braintree_android by braintree.
the class PaymentMethodTest method getPaymentMethodNonces_getsPaymentMethodsFromServer.
@Test(timeout = 10000)
public void getPaymentMethodNonces_getsPaymentMethodsFromServer() throws InterruptedException, InvalidArgumentException {
final CountDownLatch latch = new CountDownLatch(1);
final String clientToken = new TestClientTokenBuilder().build();
BraintreeFragment fragment = BraintreeFragment.newInstance(mActivity, clientToken);
getInstrumentation().waitForIdleSync();
fragment.addListener(new PaymentMethodNoncesUpdatedListener() {
@Override
public void onPaymentMethodNoncesUpdated(List<PaymentMethodNonce> paymentMethodNonces) {
assertEquals(1, paymentMethodNonces.size());
assertIsANonce(paymentMethodNonces.get(0).getNonce());
assertEquals("11", ((CardNonce) paymentMethodNonces.get(0)).getLastTwo());
latch.countDown();
}
});
fragment.addListener(new BraintreeErrorListener() {
@Override
public void onError(Exception error) {
fail(error.getMessage());
}
});
tokenize(fragment, new CardBuilder().cardNumber(VISA).expirationMonth("04").expirationYear(validExpirationYear()));
PaymentMethod.getPaymentMethodNonces(fragment);
latch.await();
}
use of com.braintreepayments.api.exceptions.InvalidArgumentException 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.InvalidArgumentException in project braintree_android by braintree.
the class BraintreeGraphQLHttpClientTest method getRequestSslCertificateSuccessfulInSandbox.
@Test(timeout = 5000)
public void getRequestSslCertificateSuccessfulInSandbox() throws InterruptedException, InvalidArgumentException {
BraintreeGraphQLHttpClient httpClient = new BraintreeGraphQLHttpClient("https://payments.sandbox.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.exceptions.InvalidArgumentException in project braintree_android by braintree.
the class BraintreeGraphQLHttpClientTest method getRequestBadCertificateCheck.
@Test(timeout = 5000)
public void getRequestBadCertificateCheck() throws InterruptedException, InvalidArgumentException {
if (!BuildConfig.RUN_ALL_TESTS) {
return;
}
String baseUrl = "https://" + EnvironmentHelper.getLocalhostIp() + ":9443";
BraintreeGraphQLHttpClient httpClient = new BraintreeGraphQLHttpClient(baseUrl, TOKENIZATION_KEY);
httpClient.get("/", new HttpResponseCallback() {
@Override
public void success(String responseBody) {
fail("Request was successful");
mCountDownLatch.countDown();
}
@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.exceptions.InvalidArgumentException 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();
}
Aggregations