use of com.braintreepayments.api.interfaces.PaymentMethodNonceCreatedListener in project braintree_android by braintree.
the class BraintreeFragmentUnitTest method addAndRemoveListenersAddAndRemoveAllListeners.
@Test
public void addAndRemoveListenersAddAndRemoveAllListeners() throws InvalidArgumentException {
BraintreeFragment fragment = BraintreeFragment.newInstance(mActivity, TOKENIZATION_KEY);
ConfigurationListener configurationListener = new ConfigurationListener() {
@Override
public void onConfigurationFetched(Configuration configuration) {
}
};
BraintreeErrorListener braintreeErrorListener = new BraintreeErrorListener() {
@Override
public void onError(Exception error) {
}
};
PaymentMethodNoncesUpdatedListener paymentMethodNoncesUpdatedListener = new PaymentMethodNoncesUpdatedListener() {
@Override
public void onPaymentMethodNoncesUpdated(List<PaymentMethodNonce> paymentMethodNonces) {
}
};
PaymentMethodNonceCreatedListener paymentMethodNonceCreatedListener = new PaymentMethodNonceCreatedListener() {
@Override
public void onPaymentMethodNonceCreated(PaymentMethodNonce paymentMethodNonce) {
}
};
BraintreeCancelListener braintreeCancelListener = new BraintreeCancelListener() {
@Override
public void onCancel(int requestCode) {
}
};
UnionPayListener unionPayListener = new UnionPayListener() {
@Override
public void onCapabilitiesFetched(UnionPayCapabilities capabilities) {
}
@Override
public void onSmsCodeSent(String enrollmentId, boolean smsCodeRequired) {
}
};
AmericanExpressListener americanExpressListener = new AmericanExpressListener() {
@Override
public void onRewardsBalanceFetched(AmericanExpressRewardsBalance rewardsBalance) {
}
};
BraintreePaymentResultListener braintreePaymentResultListener = new BraintreePaymentResultListener() {
@Override
public void onBraintreePaymentResult(BraintreePaymentResult result) {
}
};
fragment.addListener(configurationListener);
fragment.addListener(braintreeErrorListener);
fragment.addListener(paymentMethodNoncesUpdatedListener);
fragment.addListener(paymentMethodNonceCreatedListener);
fragment.addListener(braintreeCancelListener);
fragment.addListener(unionPayListener);
fragment.addListener(americanExpressListener);
fragment.addListener(braintreePaymentResultListener);
assertEquals(8, fragment.getListeners().size());
fragment.removeListener(configurationListener);
fragment.removeListener(braintreeErrorListener);
fragment.removeListener(paymentMethodNoncesUpdatedListener);
fragment.removeListener(paymentMethodNonceCreatedListener);
fragment.removeListener(braintreeCancelListener);
fragment.removeListener(unionPayListener);
fragment.removeListener(americanExpressListener);
fragment.removeListener(braintreePaymentResultListener);
assertEquals(0, fragment.getListeners().size());
}
use of com.braintreepayments.api.interfaces.PaymentMethodNonceCreatedListener 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.interfaces.PaymentMethodNonceCreatedListener 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();
}
use of com.braintreepayments.api.interfaces.PaymentMethodNonceCreatedListener 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.interfaces.PaymentMethodNonceCreatedListener 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();
}
Aggregations