use of com.braintreepayments.api.interfaces.PaymentMethodNoncesUpdatedListener in project braintree_android by braintree.
the class BraintreeFragmentUnitTest method removeListener_noPaymentMethodNoncesUpdatedCallbacksReceived.
@Test
public void removeListener_noPaymentMethodNoncesUpdatedCallbacksReceived() throws InvalidArgumentException {
BraintreeFragment fragment = BraintreeFragment.newInstance(mActivity, TOKENIZATION_KEY);
PaymentMethodNoncesUpdatedListener listener = new PaymentMethodNoncesUpdatedListener() {
@Override
public void onPaymentMethodNoncesUpdated(List<PaymentMethodNonce> paymentMethodNonces) {
fail("Listener was called");
}
};
fragment.addListener(listener);
fragment.removeListener(listener);
fragment.postCallback(new ArrayList<PaymentMethodNonce>());
}
use of com.braintreepayments.api.interfaces.PaymentMethodNoncesUpdatedListener 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.PaymentMethodNoncesUpdatedListener in project braintree_android by braintree.
the class BraintreeFragmentUnitTest method addListener_flushesPaymentMethodNoncesUpdatedCallback.
@Test
public void addListener_flushesPaymentMethodNoncesUpdatedCallback() throws InvalidArgumentException {
BraintreeFragment fragment = BraintreeFragment.newInstance(mActivity, TOKENIZATION_KEY);
fragment.postCallback(new ArrayList<PaymentMethodNonce>());
fragment.addListener(new PaymentMethodNoncesUpdatedListener() {
@Override
public void onPaymentMethodNoncesUpdated(List<PaymentMethodNonce> paymentMethodNonces) {
mCalled.set(true);
}
});
assertTrue(mCalled.get());
}
use of com.braintreepayments.api.interfaces.PaymentMethodNoncesUpdatedListener in project braintree_android by braintree.
the class PaymentMethodTest method getPaymentMethodNonces_getsPaymentMethodsFromServer.
@Test(timeout = 10000)
public void getPaymentMethodNonces_getsPaymentMethodsFromServer() throws InterruptedException, InvalidArgumentException {
final CountDownLatch latch = new CountDownLatch(1);
final String clientToken = new TestClientTokenBuilder().build();
BraintreeFragment fragment = BraintreeFragment.newInstance(mActivity, clientToken);
getInstrumentation().waitForIdleSync();
fragment.addListener(new PaymentMethodNoncesUpdatedListener() {
@Override
public void onPaymentMethodNoncesUpdated(List<PaymentMethodNonce> paymentMethodNonces) {
assertEquals(1, paymentMethodNonces.size());
assertIsANonce(paymentMethodNonces.get(0).getNonce());
assertEquals("11", ((CardNonce) paymentMethodNonces.get(0)).getLastTwo());
latch.countDown();
}
});
fragment.addListener(new BraintreeErrorListener() {
@Override
public void onError(Exception error) {
fail(error.getMessage());
}
});
tokenize(fragment, new CardBuilder().cardNumber(VISA).expirationMonth("04").expirationYear(validExpirationYear()));
PaymentMethod.getPaymentMethodNonces(fragment);
latch.await();
}
use of com.braintreepayments.api.interfaces.PaymentMethodNoncesUpdatedListener in project braintree_android by braintree.
the class PaymentMethodTest method getPaymentMethodNonces_failsWithATokenizationKey.
@Test(timeout = 10000)
public void getPaymentMethodNonces_failsWithATokenizationKey() throws InterruptedException, InvalidArgumentException {
final CountDownLatch latch = new CountDownLatch(1);
BraintreeFragment fragment = BraintreeFragment.newInstance(mActivity, TOKENIZATION_KEY);
getInstrumentation().waitForIdleSync();
fragment.addListener(new PaymentMethodNoncesUpdatedListener() {
@Override
public void onPaymentMethodNoncesUpdated(List<PaymentMethodNonce> paymentMethodNonces) {
fail("getPaymentMethodNonces succeeded");
}
});
fragment.addListener(new BraintreeErrorListener() {
@Override
public void onError(Exception error) {
assertTrue(error instanceof AuthorizationException);
assertEquals("Tokenization key authorization not allowed for this endpoint. Please use an authentication method with upgraded permissions", error.getMessage());
latch.countDown();
}
});
tokenize(fragment, new CardBuilder().cardNumber(VISA).expirationMonth("04").expirationYear(validExpirationYear()));
PaymentMethod.getPaymentMethodNonces(fragment);
latch.await();
}
Aggregations