Search in sources :

Example 16 with CardNonce

use of com.braintreepayments.api.models.CardNonce 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();
}
Also used : CardNonce(com.braintreepayments.api.models.CardNonce) PaymentMethodNonceCreatedListener(com.braintreepayments.api.interfaces.PaymentMethodNonceCreatedListener) CountDownLatch(java.util.concurrent.CountDownLatch) PaymentMethodNonce(com.braintreepayments.api.models.PaymentMethodNonce)

Example 17 with CardNonce

use of com.braintreepayments.api.models.CardNonce 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();
}
Also used : PaymentMethodNoncesUpdatedListener(com.braintreepayments.api.interfaces.PaymentMethodNoncesUpdatedListener) CardBuilder(com.braintreepayments.api.models.CardBuilder) TestClientTokenBuilder(com.braintreepayments.api.test.TestClientTokenBuilder) CardNonce(com.braintreepayments.api.models.CardNonce) CountDownLatch(java.util.concurrent.CountDownLatch) PaymentMethodNonce(com.braintreepayments.api.models.PaymentMethodNonce) BraintreeErrorListener(com.braintreepayments.api.interfaces.BraintreeErrorListener) AuthorizationException(com.braintreepayments.api.exceptions.AuthorizationException) InvalidArgumentException(com.braintreepayments.api.exceptions.InvalidArgumentException) Test(org.junit.Test)

Example 18 with CardNonce

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

the class ThreeDSecureTest method onActivityResult_postsPaymentMethodNonceToListener.

@Test(timeout = 2000)
public void onActivityResult_postsPaymentMethodNonceToListener() throws JSONException, InterruptedException {
    BraintreeFragment fragment = getMockFragmentWithConfiguration(mActivity, new TestConfigurationBuilder().build());
    fragment.addListener(new PaymentMethodNonceCreatedListener() {

        @Override
        public void onPaymentMethodNonceCreated(PaymentMethodNonce paymentMethodNonce) {
            assertIsANonce(paymentMethodNonce.getNonce());
            assertEquals("11", ((CardNonce) paymentMethodNonce).getLastTwo());
            assertTrue(((CardNonce) paymentMethodNonce).getThreeDSecureInfo().wasVerified());
            mCountDownLatch.countDown();
        }
    });
    JSONObject authResponse = new JSONObject(stringFromFixture("three_d_secure/authentication_response.json"));
    Intent data = new Intent().putExtra(ThreeDSecureWebViewActivity.EXTRA_THREE_D_SECURE_RESULT, ThreeDSecureAuthenticationResponse.fromJson(authResponse.toString()));
    ThreeDSecure.onActivityResult(fragment, Activity.RESULT_OK, data);
    mCountDownLatch.await();
}
Also used : JSONObject(org.json.JSONObject) CardNonce(com.braintreepayments.api.models.CardNonce) Intent(android.content.Intent) PaymentMethodNonceCreatedListener(com.braintreepayments.api.interfaces.PaymentMethodNonceCreatedListener) TestConfigurationBuilder(com.braintreepayments.testutils.TestConfigurationBuilder) PaymentMethodNonce(com.braintreepayments.api.models.PaymentMethodNonce) Test(org.junit.Test)

Example 19 with CardNonce

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

the class ThreeDSecureTest method performVerification_postsPaymentMethodNonceToListenersWhenLookupReturnsACard.

@Test(timeout = 10000)
public void performVerification_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());
            assertTrue(((CardNonce) paymentMethodNonce).getThreeDSecureInfo().wasVerified());
            mCountDownLatch.countDown();
        }
    });
    ThreeDSecure.performVerification(fragment, nonce, "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 20 with CardNonce

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

the class ThreeDSecureTest method onActivityResult_postsPaymentMethodNonceToListener_fromUri.

@Test(timeout = 1000)
public void onActivityResult_postsPaymentMethodNonceToListener_fromUri() throws JSONException, InterruptedException {
    BraintreeFragment fragment = getMockFragmentWithConfiguration(mActivity, new TestConfigurationBuilder().build());
    fragment.addListener(new PaymentMethodNonceCreatedListener() {

        @Override
        public void onPaymentMethodNonceCreated(PaymentMethodNonce paymentMethodNonce) {
            assertIsANonce(paymentMethodNonce.getNonce());
            assertEquals("11", ((CardNonce) paymentMethodNonce).getLastTwo());
            assertTrue(((CardNonce) paymentMethodNonce).getThreeDSecureInfo().wasVerified());
            mCountDownLatch.countDown();
        }
    });
    Uri responseUri = Uri.parse("http://demo-app.com").buildUpon().appendQueryParameter("auth_response", stringFromFixture("three_d_secure/authentication_response.json")).build();
    Intent data = new Intent().setData(responseUri);
    ThreeDSecure.onActivityResult(fragment, Activity.RESULT_OK, data);
    mCountDownLatch.await();
}
Also used : CardNonce(com.braintreepayments.api.models.CardNonce) Intent(android.content.Intent) PaymentMethodNonceCreatedListener(com.braintreepayments.api.interfaces.PaymentMethodNonceCreatedListener) TestConfigurationBuilder(com.braintreepayments.testutils.TestConfigurationBuilder) PaymentMethodNonce(com.braintreepayments.api.models.PaymentMethodNonce) Uri(android.net.Uri) Test(org.junit.Test)

Aggregations

CardNonce (com.braintreepayments.api.models.CardNonce)29 Test (org.junit.Test)24 PaymentMethodNonce (com.braintreepayments.api.models.PaymentMethodNonce)22 PaymentMethodNonceCreatedListener (com.braintreepayments.api.interfaces.PaymentMethodNonceCreatedListener)20 CardBuilder (com.braintreepayments.api.models.CardBuilder)12 AndroidPayCardNonce (com.braintreepayments.api.models.AndroidPayCardNonce)8 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)8 TestClientTokenBuilder (com.braintreepayments.api.test.TestClientTokenBuilder)4 CountDownLatch (java.util.concurrent.CountDownLatch)4 Intent (android.content.Intent)3 UnionPayCardBuilder (com.braintreepayments.api.models.UnionPayCardBuilder)3 PaymentMethodNonceCallback (com.braintreepayments.api.interfaces.PaymentMethodNonceCallback)2 UnionPayListener (com.braintreepayments.api.interfaces.UnionPayListener)2 PayPalAccountNonce (com.braintreepayments.api.models.PayPalAccountNonce)2 UnionPayCapabilities (com.braintreepayments.api.models.UnionPayCapabilities)2 TestConfigurationBuilder (com.braintreepayments.testutils.TestConfigurationBuilder)2 JSONObject (org.json.JSONObject)2 InvocationOnMock (org.mockito.invocation.InvocationOnMock)2 Answer (org.mockito.stubbing.Answer)2 PowerMockito.doAnswer (org.powermock.api.mockito.PowerMockito.doAnswer)2