Search in sources :

Example 1 with CardBuilder

use of com.braintreepayments.api.models.CardBuilder in project braintree_android by braintree.

the class CardUnitTest method tokenize_sendsAnalyticsEventOnSuccess.

@Test
public void tokenize_sendsAnalyticsEventOnSuccess() {
    mockSuccessCallback();
    Card.tokenize(mBraintreeFragment, new CardBuilder());
    verify(mBraintreeFragment).sendAnalyticsEvent("card.nonce-received");
}
Also used : CardBuilder(com.braintreepayments.api.models.CardBuilder) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 2 with CardBuilder

use of com.braintreepayments.api.models.CardBuilder 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();
}
Also used : CardBuilder(com.braintreepayments.api.models.CardBuilder) TestClientTokenBuilder(com.braintreepayments.api.test.TestClientTokenBuilder) CardNonce(com.braintreepayments.api.models.CardNonce) PaymentMethodNonceCreatedListener(com.braintreepayments.api.interfaces.PaymentMethodNonceCreatedListener) PaymentMethodNonce(com.braintreepayments.api.models.PaymentMethodNonce) Test(org.junit.Test)

Example 3 with CardBuilder

use of com.braintreepayments.api.models.CardBuilder 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();
}
Also used : ThreeDSecureRequest(com.braintreepayments.api.models.ThreeDSecureRequest) CardBuilder(com.braintreepayments.api.models.CardBuilder) TestClientTokenBuilder(com.braintreepayments.api.test.TestClientTokenBuilder) ThreeDSecureInfo(com.braintreepayments.api.models.ThreeDSecureInfo) CardNonce(com.braintreepayments.api.models.CardNonce) PaymentMethodNonceCreatedListener(com.braintreepayments.api.interfaces.PaymentMethodNonceCreatedListener) PaymentMethodNonce(com.braintreepayments.api.models.PaymentMethodNonce) Test(org.junit.Test)

Example 4 with CardBuilder

use of com.braintreepayments.api.models.CardBuilder in project braintree_android by braintree.

the class CardTest method tokenize_tokenizesACardWithACustomer.

@Test(timeout = 10000)
public void tokenize_tokenizesACardWithACustomer() throws Exception {
    CardBuilder cardBuilder = new CardBuilder().cardNumber(VISA).expirationDate("08/20");
    assertTokenizationSuccessful(new TestClientTokenBuilder().build(), cardBuilder);
}
Also used : CardBuilder(com.braintreepayments.api.models.CardBuilder) TestClientTokenBuilder(com.braintreepayments.api.test.TestClientTokenBuilder) Test(org.junit.Test)

Example 5 with CardBuilder

use of com.braintreepayments.api.models.CardBuilder in project braintree_android by braintree.

the class CardTest method tokenize_tokenizesACardWithPostalCode.

@Test(timeout = 10000)
public void tokenize_tokenizesACardWithPostalCode() throws Exception {
    CardBuilder cardBuilder = new CardBuilder().cardNumber(VISA).expirationDate("08/20").cvv("123");
    assertTokenizationSuccessful(new TestClientTokenBuilder().withPostalCodeVerification().build(), cardBuilder);
}
Also used : CardBuilder(com.braintreepayments.api.models.CardBuilder) TestClientTokenBuilder(com.braintreepayments.api.test.TestClientTokenBuilder) Test(org.junit.Test)

Aggregations

CardBuilder (com.braintreepayments.api.models.CardBuilder)41 Test (org.junit.Test)39 PaymentMethodNonce (com.braintreepayments.api.models.PaymentMethodNonce)15 TestClientTokenBuilder (com.braintreepayments.api.test.TestClientTokenBuilder)14 CardNonce (com.braintreepayments.api.models.CardNonce)12 PaymentMethodNonceCreatedListener (com.braintreepayments.api.interfaces.PaymentMethodNonceCreatedListener)11 AuthorizationException (com.braintreepayments.api.exceptions.AuthorizationException)10 BraintreeErrorListener (com.braintreepayments.api.interfaces.BraintreeErrorListener)10 InvalidArgumentException (com.braintreepayments.api.exceptions.InvalidArgumentException)7 UnionPayCardBuilder (com.braintreepayments.api.models.UnionPayCardBuilder)7 CountDownLatch (java.util.concurrent.CountDownLatch)6 JSONException (org.json.JSONException)5 TestConfigurationBuilder (com.braintreepayments.testutils.TestConfigurationBuilder)4 HttpResponseCallback (com.braintreepayments.api.interfaces.HttpResponseCallback)3 Matchers.anyString (org.mockito.Matchers.anyString)3 BraintreeException (com.braintreepayments.api.exceptions.BraintreeException)2 BraintreeCancelListener (com.braintreepayments.api.interfaces.BraintreeCancelListener)2 PaymentMethodNonceCallback (com.braintreepayments.api.interfaces.PaymentMethodNonceCallback)2 PaymentMethodNoncesUpdatedListener (com.braintreepayments.api.interfaces.PaymentMethodNoncesUpdatedListener)2 ErrorWithResponse (com.braintreepayments.api.exceptions.ErrorWithResponse)1