use of com.braintreepayments.api.models.CardNonce in project braintree_android by braintree.
the class UnionPayUnitTest method mockSuccessCallback.
/* helpers */
private void mockSuccessCallback() {
mockStatic(TokenizationClient.class);
doAnswer(new Answer<Void>() {
@Override
public Void answer(InvocationOnMock invocation) throws Throwable {
UnionPayCardBuilder cardBuilder = (UnionPayCardBuilder) invocation.getArguments()[1];
CardNonce cardNonce = mock(CardNonce.class);
boolean hasSmsCode = false;
try {
hasSmsCode = new JSONObject(cardBuilder.build()).getJSONObject("options").has("smsCode");
} catch (JSONException ignored) {
}
if (hasSmsCode) {
when(cardNonce.getNonce()).thenReturn("nonce");
}
((PaymentMethodNonceCallback) invocation.getArguments()[2]).success(cardNonce);
return null;
}
}).when(TokenizationClient.class);
TokenizationClient.tokenize(any(BraintreeFragment.class), any(UnionPayCardBuilder.class), any(PaymentMethodNonceCallback.class));
}
use of com.braintreepayments.api.models.CardNonce in project braintree_android by braintree.
the class BraintreeFragmentUnitTest method postCallback_addsAllPaymentMethodNoncesToCache.
@Test
public void postCallback_addsAllPaymentMethodNoncesToCache() throws InvalidArgumentException {
BraintreeFragment fragment = BraintreeFragment.newInstance(mActivity, TOKENIZATION_KEY);
assertEquals(0, fragment.getCachedPaymentMethodNonces().size());
List<PaymentMethodNonce> paymentMethodNonceList = new ArrayList<>();
paymentMethodNonceList.add(new CardNonce());
paymentMethodNonceList.add(new PayPalAccountNonce());
fragment.postCallback(paymentMethodNonceList);
assertEquals(2, fragment.getCachedPaymentMethodNonces().size());
assertTrue(fragment.getCachedPaymentMethodNonces().get(0) instanceof CardNonce);
assertTrue(fragment.getCachedPaymentMethodNonces().get(1) instanceof PayPalAccountNonce);
}
use of com.braintreepayments.api.models.CardNonce in project braintree_android by braintree.
the class BraintreeFragmentUnitTest method postCallback_onlyAllowsOneAndroidPayCardNonceToBePresent.
@Test
public void postCallback_onlyAllowsOneAndroidPayCardNonceToBePresent() throws InvalidArgumentException {
BraintreeFragment fragment = BraintreeFragment.newInstance(mActivity, TOKENIZATION_KEY);
assertEquals(0, fragment.getCachedPaymentMethodNonces().size());
fragment.postCallback(new CardNonce());
fragment.postCallback(new AndroidPayCardNonce());
fragment.postCallback(new AndroidPayCardNonce());
assertEquals(2, fragment.getCachedPaymentMethodNonces().size());
assertTrue(fragment.getCachedPaymentMethodNonces().get(0) instanceof AndroidPayCardNonce);
}
use of com.braintreepayments.api.models.CardNonce in project braintree_android by braintree.
the class ThreeDSecureTest method performVerification_acceptsACardBuilderAndPostsAPaymentMethodNonceToListener.
@Test(timeout = 10000)
public void performVerification_acceptsACardBuilderAndPostsAPaymentMethodNonceToListener() throws InterruptedException {
String clientToken = new TestClientTokenBuilder().withThreeDSecure().build();
BraintreeFragment fragment = getFragmentWithAuthorization(mActivity, clientToken);
fragment.addListener(new PaymentMethodNonceCreatedListener() {
@Override
public void onPaymentMethodNonceCreated(PaymentMethodNonce paymentMethodNonce) {
assertIsANonce(paymentMethodNonce.getNonce());
assertEquals("51", ((CardNonce) paymentMethodNonce).getLastTwo());
assertTrue(((CardNonce) paymentMethodNonce).getThreeDSecureInfo().wasVerified());
mCountDownLatch.countDown();
}
});
CardBuilder cardBuilder = new CardBuilder().cardNumber("4000000000000051").expirationDate("12/20");
ThreeDSecure.performVerification(fragment, cardBuilder, "5");
mCountDownLatch.await();
}
use of com.braintreepayments.api.models.CardNonce in project braintree_android by braintree.
the class ThreeDSecureTest method performVerification_acceptsAThreeDSecureRequest_postsPaymentMethodNonceToListenersWhenLookupReturnsACard.
@Test(timeout = 10000)
public void performVerification_acceptsAThreeDSecureRequest_postsPaymentMethodNonceToListenersWhenLookupReturnsACard() throws InterruptedException, InvalidArgumentException {
String clientToken = new TestClientTokenBuilder().withThreeDSecure().build();
BraintreeFragment fragment = getFragmentWithAuthorization(mActivity, clientToken);
String nonce = tokenize(fragment, new CardBuilder().cardNumber("4000000000000051").expirationDate("12/20")).getNonce();
fragment.addListener(new PaymentMethodNonceCreatedListener() {
@Override
public void onPaymentMethodNonceCreated(PaymentMethodNonce paymentMethodNonce) {
assertIsANonce(paymentMethodNonce.getNonce());
assertEquals("51", ((CardNonce) paymentMethodNonce).getLastTwo());
ThreeDSecureInfo threeDSecureInfo = ((CardNonce) paymentMethodNonce).getThreeDSecureInfo();
assertFalse(threeDSecureInfo.isLiabilityShifted());
assertFalse(threeDSecureInfo.isLiabilityShiftPossible());
assertTrue(((CardNonce) paymentMethodNonce).getThreeDSecureInfo().wasVerified());
mCountDownLatch.countDown();
}
});
ThreeDSecureRequest request = new ThreeDSecureRequest().nonce(nonce).amount("5");
ThreeDSecure.performVerification(fragment, request);
mCountDownLatch.await();
}
Aggregations