use of com.braintreepayments.api.models.PaymentMethodNonce 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.models.PaymentMethodNonce in project braintree_android by braintree.
the class CardTest method tokenize_tokenizesCvvOnly.
@Test(timeout = 10000)
public void tokenize_tokenizesCvvOnly() throws Exception {
final CountDownLatch countDownLatch = new CountDownLatch(1);
BraintreeFragment fragment = setupBraintreeFragment(TOKENIZATION_KEY);
fragment.addListener(new PaymentMethodNonceCreatedListener() {
@Override
public void onPaymentMethodNonceCreated(PaymentMethodNonce paymentMethodNonce) {
CardNonce cardNonce = (CardNonce) paymentMethodNonce;
assertNotNull(cardNonce.getBinData());
assertEquals("Unknown", cardNonce.getCardType());
assertEquals("", cardNonce.getLastFour());
assertEquals("", cardNonce.getLastTwo());
assertNotNull(cardNonce.getThreeDSecureInfo());
assertFalse(cardNonce.isDefault());
assertEquals("", cardNonce.getDescription());
assertNotNull(cardNonce.getNonce());
countDownLatch.countDown();
}
});
CardBuilder cardBuilder = new CardBuilder().cvv("123");
Card.tokenize(fragment, cardBuilder);
countDownLatch.await();
}
use of com.braintreepayments.api.models.PaymentMethodNonce in project braintree_android by braintree.
the class CardTest method assertTokenizationSuccessful.
private void assertTokenizationSuccessful(String authorization, CardBuilder cardBuilder) throws Exception {
final CountDownLatch countDownLatch = new CountDownLatch(1);
BraintreeFragment fragment = setupBraintreeFragment(authorization);
fragment.addListener(new PaymentMethodNonceCreatedListener() {
@Override
public void onPaymentMethodNonceCreated(PaymentMethodNonce paymentMethodNonce) {
CardNonce cardNonce = (CardNonce) paymentMethodNonce;
assertNotNull(cardNonce.getNonce());
assertEquals("Visa", cardNonce.getCardType());
assertEquals("1111", cardNonce.getLastFour());
assertEquals("11", cardNonce.getLastTwo());
assertEquals(BinData.UNKNOWN, cardNonce.getBinData().getPrepaid());
assertEquals(BinData.UNKNOWN, cardNonce.getBinData().getHealthcare());
assertEquals(BinData.UNKNOWN, cardNonce.getBinData().getDebit());
assertEquals(BinData.UNKNOWN, cardNonce.getBinData().getDurbinRegulated());
assertEquals(BinData.UNKNOWN, cardNonce.getBinData().getCommercial());
assertEquals(BinData.UNKNOWN, cardNonce.getBinData().getPayroll());
assertEquals(BinData.UNKNOWN, cardNonce.getBinData().getIssuingBank());
assertEquals(BinData.UNKNOWN, cardNonce.getBinData().getCountryOfIssuance());
assertEquals(BinData.UNKNOWN, cardNonce.getBinData().getProductId());
assertFalse(cardNonce.getThreeDSecureInfo().wasVerified());
countDownLatch.countDown();
}
});
Card.tokenize(fragment, cardBuilder);
countDownLatch.await();
}
use of com.braintreepayments.api.models.PaymentMethodNonce 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.models.PaymentMethodNonce 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