Search in sources :

Example 11 with PaymentMethodNonceCreatedListener

use of com.braintreepayments.api.interfaces.PaymentMethodNonceCreatedListener 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 12 with PaymentMethodNonceCreatedListener

use of com.braintreepayments.api.interfaces.PaymentMethodNonceCreatedListener 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 13 with PaymentMethodNonceCreatedListener

use of com.braintreepayments.api.interfaces.PaymentMethodNonceCreatedListener 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)

Example 14 with PaymentMethodNonceCreatedListener

use of com.braintreepayments.api.interfaces.PaymentMethodNonceCreatedListener in project braintree_android by braintree.

the class UnionPayTest method tokenize_unionPayCredit_withExpirationMonthAndYear.

@Test(timeout = 30000)
public void tokenize_unionPayCredit_withExpirationMonthAndYear() throws InvalidArgumentException, InterruptedException {
    final UnionPayCardBuilder cardBuilder = new UnionPayCardBuilder().cardNumber(CardNumber.UNIONPAY_CREDIT).expirationMonth("08").expirationYear("20").cvv("123").mobileCountryCode("62").mobilePhoneNumber("1111111111");
    mBraintreeFragment.addListener(new UnionPayListener() {

        @Override
        public void onCapabilitiesFetched(UnionPayCapabilities capabilities) {
        }

        @Override
        public void onSmsCodeSent(String enrollmentId, boolean smsCodeRequired) {
            assertTrue(smsCodeRequired);
            cardBuilder.enrollmentId(enrollmentId);
            cardBuilder.smsCode("12345");
            UnionPay.tokenize(mBraintreeFragment, cardBuilder);
        }
    });
    mBraintreeFragment.addListener(new PaymentMethodNonceCreatedListener() {

        @Override
        public void onPaymentMethodNonceCreated(PaymentMethodNonce paymentMethodNonce) {
            assertIsANonce(paymentMethodNonce.getNonce());
            assertEquals("32", ((CardNonce) paymentMethodNonce).getLastTwo());
            mCountDownLatch.countDown();
        }
    });
    UnionPay.enroll(mBraintreeFragment, cardBuilder);
    mCountDownLatch.await();
}
Also used : UnionPayListener(com.braintreepayments.api.interfaces.UnionPayListener) UnionPayCardBuilder(com.braintreepayments.api.models.UnionPayCardBuilder) UnionPayCapabilities(com.braintreepayments.api.models.UnionPayCapabilities) CardNonce(com.braintreepayments.api.models.CardNonce) PaymentMethodNonceCreatedListener(com.braintreepayments.api.interfaces.PaymentMethodNonceCreatedListener) PaymentMethodNonce(com.braintreepayments.api.models.PaymentMethodNonce) Test(org.junit.Test)

Example 15 with PaymentMethodNonceCreatedListener

use of com.braintreepayments.api.interfaces.PaymentMethodNonceCreatedListener in project braintree_android by braintree.

the class UnionPayTest method tokenize_unionPayCredit_withExpirationDate.

@Test(timeout = 10000)
public void tokenize_unionPayCredit_withExpirationDate() throws InvalidArgumentException, InterruptedException {
    final UnionPayCardBuilder cardBuilder = new UnionPayCardBuilder().cardNumber(CardNumber.UNIONPAY_CREDIT).expirationDate("08/20").cvv("123").mobileCountryCode("62").mobilePhoneNumber("1111111111");
    mBraintreeFragment.addListener(new UnionPayListener() {

        @Override
        public void onCapabilitiesFetched(UnionPayCapabilities capabilities) {
        }

        @Override
        public void onSmsCodeSent(String enrollmentId, boolean smsCodeRequired) {
            assertTrue(smsCodeRequired);
            cardBuilder.enrollmentId(enrollmentId);
            cardBuilder.smsCode("12345");
            UnionPay.tokenize(mBraintreeFragment, cardBuilder);
        }
    });
    mBraintreeFragment.addListener(new PaymentMethodNonceCreatedListener() {

        @Override
        public void onPaymentMethodNonceCreated(PaymentMethodNonce paymentMethodNonce) {
            assertIsANonce(paymentMethodNonce.getNonce());
            assertEquals("32", ((CardNonce) paymentMethodNonce).getLastTwo());
            mCountDownLatch.countDown();
        }
    });
    UnionPay.enroll(mBraintreeFragment, cardBuilder);
    mCountDownLatch.await();
}
Also used : UnionPayListener(com.braintreepayments.api.interfaces.UnionPayListener) UnionPayCardBuilder(com.braintreepayments.api.models.UnionPayCardBuilder) UnionPayCapabilities(com.braintreepayments.api.models.UnionPayCapabilities) CardNonce(com.braintreepayments.api.models.CardNonce) PaymentMethodNonceCreatedListener(com.braintreepayments.api.interfaces.PaymentMethodNonceCreatedListener) PaymentMethodNonce(com.braintreepayments.api.models.PaymentMethodNonce) Test(org.junit.Test)

Aggregations

PaymentMethodNonceCreatedListener (com.braintreepayments.api.interfaces.PaymentMethodNonceCreatedListener)21 PaymentMethodNonce (com.braintreepayments.api.models.PaymentMethodNonce)21 CardNonce (com.braintreepayments.api.models.CardNonce)20 Test (org.junit.Test)19 CardBuilder (com.braintreepayments.api.models.CardBuilder)11 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)4 UnionPayListener (com.braintreepayments.api.interfaces.UnionPayListener)3 AndroidPayCardNonce (com.braintreepayments.api.models.AndroidPayCardNonce)3 UnionPayCapabilities (com.braintreepayments.api.models.UnionPayCapabilities)3 TestClientTokenBuilder (com.braintreepayments.api.test.TestClientTokenBuilder)3 CountDownLatch (java.util.concurrent.CountDownLatch)3 Intent (android.content.Intent)2 UnionPayCardBuilder (com.braintreepayments.api.models.UnionPayCardBuilder)2 TestConfigurationBuilder (com.braintreepayments.testutils.TestConfigurationBuilder)2 Uri (android.net.Uri)1 InvalidArgumentException (com.braintreepayments.api.exceptions.InvalidArgumentException)1 AmericanExpressListener (com.braintreepayments.api.interfaces.AmericanExpressListener)1 BraintreeCancelListener (com.braintreepayments.api.interfaces.BraintreeCancelListener)1 BraintreeErrorListener (com.braintreepayments.api.interfaces.BraintreeErrorListener)1 BraintreePaymentResultListener (com.braintreepayments.api.interfaces.BraintreePaymentResultListener)1