use of com.braintreepayments.api.models.CardNonce in project braintree_android by braintree.
the class BraintreeFragmentTestUtils method tokenize.
public static CardNonce tokenize(BraintreeFragment fragment, CardBuilder cardBuilder) {
final CountDownLatch latch = new CountDownLatch(1);
final CardNonce[] cardNonce = new CardNonce[1];
PaymentMethodNonceCreatedListener listener = new PaymentMethodNonceCreatedListener() {
@Override
public void onPaymentMethodNonceCreated(PaymentMethodNonce paymentMethodNonce) {
cardNonce[0] = (CardNonce) paymentMethodNonce;
latch.countDown();
}
};
fragment.addListener(listener);
Card.tokenize(fragment, cardBuilder);
try {
latch.await();
} catch (InterruptedException ignored) {
}
fragment.removeListener(listener);
return cardNonce[0];
}
use of com.braintreepayments.api.models.CardNonce in project braintree_android by braintree.
the class ThreeDSecureVerificationTest method performVerification_doesALookupAndReturnsACardWhenThereIsALookupError.
@Test(timeout = 10000)
public void performVerification_doesALookupAndReturnsACardWhenThereIsALookupError() throws InterruptedException {
BraintreeFragment fragment = getFragment();
fragment.addListener(new PaymentMethodNonceCreatedListener() {
@Override
public void onPaymentMethodNonceCreated(PaymentMethodNonce paymentMethodNonce) {
assertIsANonce(paymentMethodNonce.getNonce());
CardNonce cardNonce = (CardNonce) paymentMethodNonce;
assertEquals("77", cardNonce.getLastTwo());
assertFalse(cardNonce.getThreeDSecureInfo().isLiabilityShifted());
assertFalse(cardNonce.getThreeDSecureInfo().isLiabilityShiftPossible());
assertTrue(((CardNonce) paymentMethodNonce).getThreeDSecureInfo().wasVerified());
mCountDownLatch.countDown();
}
});
CardBuilder cardBuilder = new CardBuilder().cardNumber(THREE_D_SECURE_LOOKUP_ERROR).expirationDate("12/20");
ThreeDSecure.performVerification(fragment, cardBuilder, TEST_AMOUNT);
mCountDownLatch.await();
}
use of com.braintreepayments.api.models.CardNonce in project braintree_android by braintree.
the class CardUnitTest method mockSuccessCallback.
/* helpers */
private void mockSuccessCallback() {
mockStatic(TokenizationClient.class);
doAnswer(new Answer<Void>() {
@Override
public Void answer(InvocationOnMock invocation) throws Throwable {
((PaymentMethodNonceCallback) invocation.getArguments()[2]).success(new CardNonce());
return null;
}
}).when(TokenizationClient.class);
TokenizationClient.tokenize(any(BraintreeFragment.class), any(PaymentMethodBuilder.class), any(PaymentMethodNonceCallback.class));
}
use of com.braintreepayments.api.models.CardNonce in project braintree_android by braintree.
the class BraintreeFragmentUnitTest method postCallback_postsPaymentMethodNonceToListener.
@Test
public void postCallback_postsPaymentMethodNonceToListener() throws InvalidArgumentException {
BraintreeFragment fragment = BraintreeFragment.newInstance(mActivity, TOKENIZATION_KEY);
final AtomicBoolean wasCalled = new AtomicBoolean(false);
fragment.addListener(new PaymentMethodNonceCreatedListener() {
@Override
public void onPaymentMethodNonceCreated(PaymentMethodNonce paymentMethodNonce) {
assertTrue(paymentMethodNonce instanceof CardNonce);
wasCalled.set(true);
}
});
fragment.postCallback(new CardNonce());
assertTrue(wasCalled.get());
}
use of com.braintreepayments.api.models.CardNonce in project braintree_android by braintree.
the class BraintreeFragmentUnitTest method postCallback_doesNotRemoveAndroidPayCardNonceWhenAnotherNonceIsAdded.
@Test
public void postCallback_doesNotRemoveAndroidPayCardNonceWhenAnotherNonceIsAdded() throws InvalidArgumentException {
BraintreeFragment fragment = BraintreeFragment.newInstance(mActivity, TOKENIZATION_KEY);
assertEquals(0, fragment.getCachedPaymentMethodNonces().size());
fragment.postCallback(new AndroidPayCardNonce());
fragment.postCallback(new CardNonce());
assertEquals(2, fragment.getCachedPaymentMethodNonces().size());
}
Aggregations