use of com.braintreepayments.api.interfaces.BraintreeErrorListener in project braintree_android by braintree.
the class ThreeDSecureTest method onActivityResult_postsUnrecoverableErrorsToListeners.
@Test(timeout = 2000)
public void onActivityResult_postsUnrecoverableErrorsToListeners() throws InterruptedException {
BraintreeFragment fragment = getMockFragmentWithConfiguration(mActivity, new TestConfigurationBuilder().build());
fragment.addListener(new BraintreeErrorListener() {
@Override
public void onError(Exception error) {
assertEquals("Error!", error.getMessage());
mCountDownLatch.countDown();
}
});
ThreeDSecureAuthenticationResponse authResponse = ThreeDSecureAuthenticationResponse.fromException("Error!");
Intent data = new Intent().putExtra(ThreeDSecureWebViewActivity.EXTRA_THREE_D_SECURE_RESULT, authResponse);
ThreeDSecure.onActivityResult(fragment, Activity.RESULT_OK, data);
mCountDownLatch.await();
}
use of com.braintreepayments.api.interfaces.BraintreeErrorListener in project braintree_android by braintree.
the class UnionPayTest method enroll_whenSmsCodeRequiredFalse_onSmsCodeSentReturnsFalse.
@Test(timeout = 10000)
public void enroll_whenSmsCodeRequiredFalse_onSmsCodeSentReturnsFalse() throws InterruptedException {
mCountDownLatch = new CountDownLatch(2);
String cardNumber = UNIONPAY_SMS_NOT_REQUIRED;
final UnionPayCardBuilder unionPayCardBuilder = new UnionPayCardBuilder().cardNumber(cardNumber).expirationMonth("12").expirationYear("2019").mobileCountryCode("62").mobilePhoneNumber("11111111111");
mBraintreeFragment.addListener(new UnionPayListener() {
@Override
public void onCapabilitiesFetched(UnionPayCapabilities capabilities) {
assertTrue(capabilities.isUnionPay());
assertTrue(capabilities.isSupported());
UnionPay.enroll(mBraintreeFragment, unionPayCardBuilder);
mCountDownLatch.countDown();
}
@Override
public void onSmsCodeSent(String enrollmentId, boolean smsCodeRequired) {
assertNotNull(enrollmentId);
assertFalse(smsCodeRequired);
mCountDownLatch.countDown();
}
});
mBraintreeFragment.addListener(new BraintreeErrorListener() {
@Override
public void onError(Exception error) {
fail("Not expecting error");
}
});
UnionPay.fetchCapabilities(mBraintreeFragment, cardNumber);
mCountDownLatch.await();
}
use of com.braintreepayments.api.interfaces.BraintreeErrorListener in project braintree_android by braintree.
the class UnionPayTest method enroll_whenIsUnionPayFalse_willError.
@Test(timeout = 10000)
public void enroll_whenIsUnionPayFalse_willError() throws InterruptedException {
String cardNumber = CardNumber.VISA;
final UnionPayCardBuilder unionPayCardBuilder = new UnionPayCardBuilder().cardNumber(cardNumber).expirationMonth("12").expirationYear("2019").mobileCountryCode("62").mobilePhoneNumber("11111111111");
mBraintreeFragment.addListener(new UnionPayListener() {
@Override
public void onCapabilitiesFetched(UnionPayCapabilities capabilities) {
assertFalse(capabilities.isUnionPay());
UnionPay.enroll(mBraintreeFragment, unionPayCardBuilder);
}
@Override
public void onSmsCodeSent(String enrollmentId, boolean smsCodeRequired) {
fail("Not expecting onSmsCodeSent");
}
});
mBraintreeFragment.addListener(new BraintreeErrorListener() {
@Override
public void onError(Exception error) {
assertTrue(error instanceof ErrorWithResponse);
assertEquals("UnionPay Enrollment is invalid", error.getMessage());
mCountDownLatch.countDown();
}
});
UnionPay.fetchCapabilities(mBraintreeFragment, cardNumber);
mCountDownLatch.await();
}
use of com.braintreepayments.api.interfaces.BraintreeErrorListener 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.interfaces.BraintreeErrorListener in project braintree_android by braintree.
the class CardTest method tokenize_callsErrorCallbackForInvalidCvv.
@Test(timeout = 10000)
public void tokenize_callsErrorCallbackForInvalidCvv() throws Exception {
CardBuilder cardBuilder = new CardBuilder().cardNumber(VISA).expirationDate("08/20").cvv("200");
final CountDownLatch countDownLatch = new CountDownLatch(1);
BraintreeFragment fragment = setupBraintreeFragment(new TestClientTokenBuilder().withCvvVerification().build());
fragment.addListener(new BraintreeErrorListener() {
@Override
public void onError(Exception error) {
assertEquals("CVV verification failed", ((ErrorWithResponse) error).errorFor("creditCard").getFieldErrors().get(0).getMessage());
countDownLatch.countDown();
}
});
Card.tokenize(fragment, cardBuilder);
countDownLatch.await();
}
Aggregations