use of com.braintreepayments.api.exceptions.ErrorWithResponse 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.exceptions.ErrorWithResponse in project braintree_android by braintree.
the class ThreeDSecure method onActivityResult.
protected static void onActivityResult(BraintreeFragment fragment, int resultCode, Intent data) {
if (resultCode == Activity.RESULT_OK) {
ThreeDSecureAuthenticationResponse authenticationResponse;
Uri resultUri = data.getData();
if (resultUri != null) {
authenticationResponse = ThreeDSecureAuthenticationResponse.fromJson(resultUri.getQueryParameter("auth_response"));
} else {
authenticationResponse = data.getParcelableExtra(ThreeDSecureWebViewActivity.EXTRA_THREE_D_SECURE_RESULT);
}
if (authenticationResponse.isSuccess()) {
fragment.postCallback(authenticationResponse.getCardNonce());
} else if (authenticationResponse.getException() != null) {
fragment.postCallback(new BraintreeException(authenticationResponse.getException()));
} else {
fragment.postCallback(new ErrorWithResponse(422, authenticationResponse.getErrors()));
}
}
}
use of com.braintreepayments.api.exceptions.ErrorWithResponse in project braintree_android by braintree.
the class CardUnitTest method mockFailureCallback.
private void mockFailureCallback() {
mockStatic(TokenizationClient.class);
doAnswer(new Answer<Void>() {
@Override
public Void answer(InvocationOnMock invocation) throws Throwable {
((PaymentMethodNonceCallback) invocation.getArguments()[2]).failure(new ErrorWithResponse(422, ""));
return null;
}
}).when(TokenizationClient.class);
TokenizationClient.tokenize(any(BraintreeFragment.class), any(PaymentMethodBuilder.class), any(PaymentMethodNonceCallback.class));
}
use of com.braintreepayments.api.exceptions.ErrorWithResponse in project braintree_android by braintree.
the class BraintreeFragmentUnitTest method addListener_flushesErrorWithResponseCallback.
@Test
public void addListener_flushesErrorWithResponseCallback() throws InvalidArgumentException {
BraintreeFragment fragment = BraintreeFragment.newInstance(mActivity, TOKENIZATION_KEY);
fragment.postCallback(new ErrorWithResponse(422, ""));
fragment.addListener(new BraintreeErrorListener() {
@Override
public void onError(Exception error) {
assertTrue(error instanceof ErrorWithResponse);
assertEquals(422, ((ErrorWithResponse) error).getStatusCode());
mCalled.set(true);
}
});
assertTrue(mCalled.get());
}
use of com.braintreepayments.api.exceptions.ErrorWithResponse in project braintree_android by braintree.
the class BraintreeFragmentUnitTest method removeListener_noErrorCallbacksReceived.
@Test
public void removeListener_noErrorCallbacksReceived() throws InvalidArgumentException {
BraintreeFragment fragment = BraintreeFragment.newInstance(mActivity, TOKENIZATION_KEY);
BraintreeErrorListener listener = new BraintreeErrorListener() {
@Override
public void onError(Exception error) {
fail("Listener was called");
}
};
fragment.addListener(listener);
fragment.removeListener(listener);
fragment.postCallback(new Exception());
fragment.postCallback(new ErrorWithResponse(400, ""));
}
Aggregations