Search in sources :

Example 1 with PaymentMethodNonce

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

the class VenmoUnitTest method onActivityResult_withSuccessfulVaultCall_returnsVenmoAccountNonce.

@Test
public void onActivityResult_withSuccessfulVaultCall_returnsVenmoAccountNonce() throws InvalidArgumentException {
    Configuration configuration = getConfigurationFromFixture();
    Authorization clientToken = Authorization.fromString(stringFromFixture("base_64_client_token.txt"));
    disableSignatureVerification();
    BraintreeFragment fragment = new MockFragmentBuilder().context(VenmoInstalledContextFactory.venmoInstalledContext(true, RuntimeEnvironment.application)).configuration(configuration).authorization(clientToken).sessionId("session-id").successResponse(stringFromFixture("payment_methods/venmo_account_response.json")).build();
    Venmo.authorizeAccount(fragment, true);
    ArgumentCaptor<PaymentMethodNonce> responseCaptor = ArgumentCaptor.forClass(PaymentMethodNonce.class);
    Intent responseIntent = new Intent().putExtra(Venmo.EXTRA_PAYMENT_METHOD_NONCE, "nonce");
    Venmo.onActivityResult(fragment, Activity.RESULT_OK, responseIntent);
    verify(fragment).postCallback(responseCaptor.capture());
    PaymentMethodNonce capturedNonce = responseCaptor.getValue();
    assertTrue(capturedNonce instanceof VenmoAccountNonce);
    VenmoAccountNonce venmoAccountNonce = (VenmoAccountNonce) capturedNonce;
    assertEquals("Venmo", venmoAccountNonce.getTypeLabel());
    assertEquals("fake-venmo-nonce", venmoAccountNonce.getNonce());
    assertEquals("venmojoe", venmoAccountNonce.getUsername());
}
Also used : Authorization(com.braintreepayments.api.models.Authorization) Configuration(com.braintreepayments.api.models.Configuration) VenmoAccountNonce(com.braintreepayments.api.models.VenmoAccountNonce) Intent(android.content.Intent) PaymentMethodNonce(com.braintreepayments.api.models.PaymentMethodNonce) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 2 with PaymentMethodNonce

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

the class BraintreeFragmentUnitTest method postCallback_addsAllPaymentMethodNoncesToCache.

@Test
public void postCallback_addsAllPaymentMethodNoncesToCache() throws InvalidArgumentException {
    BraintreeFragment fragment = BraintreeFragment.newInstance(mActivity, TOKENIZATION_KEY);
    assertEquals(0, fragment.getCachedPaymentMethodNonces().size());
    List<PaymentMethodNonce> paymentMethodNonceList = new ArrayList<>();
    paymentMethodNonceList.add(new CardNonce());
    paymentMethodNonceList.add(new PayPalAccountNonce());
    fragment.postCallback(paymentMethodNonceList);
    assertEquals(2, fragment.getCachedPaymentMethodNonces().size());
    assertTrue(fragment.getCachedPaymentMethodNonces().get(0) instanceof CardNonce);
    assertTrue(fragment.getCachedPaymentMethodNonces().get(1) instanceof PayPalAccountNonce);
}
Also used : ArrayList(java.util.ArrayList) AndroidPayCardNonce(com.braintreepayments.api.models.AndroidPayCardNonce) CardNonce(com.braintreepayments.api.models.CardNonce) PayPalAccountNonce(com.braintreepayments.api.models.PayPalAccountNonce) PaymentMethodNonce(com.braintreepayments.api.models.PaymentMethodNonce) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 3 with PaymentMethodNonce

use of com.braintreepayments.api.models.PaymentMethodNonce 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>());
}
Also used : PaymentMethodNoncesUpdatedListener(com.braintreepayments.api.interfaces.PaymentMethodNoncesUpdatedListener) List(java.util.List) ArrayList(java.util.ArrayList) PaymentMethodNonce(com.braintreepayments.api.models.PaymentMethodNonce) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 4 with PaymentMethodNonce

use of com.braintreepayments.api.models.PaymentMethodNonce 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());
}
Also used : PaymentMethodNoncesUpdatedListener(com.braintreepayments.api.interfaces.PaymentMethodNoncesUpdatedListener) UnionPayListener(com.braintreepayments.api.interfaces.UnionPayListener) Configuration(com.braintreepayments.api.models.Configuration) BraintreeCancelListener(com.braintreepayments.api.interfaces.BraintreeCancelListener) UnionPayCapabilities(com.braintreepayments.api.models.UnionPayCapabilities) BraintreeErrorListener(com.braintreepayments.api.interfaces.BraintreeErrorListener) JSONException(org.json.JSONException) InvalidArgumentException(com.braintreepayments.api.exceptions.InvalidArgumentException) ConfigurationListener(com.braintreepayments.api.interfaces.ConfigurationListener) BraintreePaymentResult(com.braintreepayments.api.models.BraintreePaymentResult) AmericanExpressRewardsBalance(com.braintreepayments.api.models.AmericanExpressRewardsBalance) List(java.util.List) ArrayList(java.util.ArrayList) PaymentMethodNonceCreatedListener(com.braintreepayments.api.interfaces.PaymentMethodNonceCreatedListener) AmericanExpressListener(com.braintreepayments.api.interfaces.AmericanExpressListener) PaymentMethodNonce(com.braintreepayments.api.models.PaymentMethodNonce) BraintreePaymentResultListener(com.braintreepayments.api.interfaces.BraintreePaymentResultListener) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 5 with PaymentMethodNonce

use of com.braintreepayments.api.models.PaymentMethodNonce 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)

Aggregations

PaymentMethodNonce (com.braintreepayments.api.models.PaymentMethodNonce)38 Test (org.junit.Test)31 CardNonce (com.braintreepayments.api.models.CardNonce)22 PaymentMethodNonceCreatedListener (com.braintreepayments.api.interfaces.PaymentMethodNonceCreatedListener)21 CardBuilder (com.braintreepayments.api.models.CardBuilder)15 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)11 PaymentMethodNonceCallback (com.braintreepayments.api.interfaces.PaymentMethodNonceCallback)8 JSONException (org.json.JSONException)7 Intent (android.content.Intent)6 CountDownLatch (java.util.concurrent.CountDownLatch)6 PaymentMethodNoncesUpdatedListener (com.braintreepayments.api.interfaces.PaymentMethodNoncesUpdatedListener)5 AndroidPayCardNonce (com.braintreepayments.api.models.AndroidPayCardNonce)5 PayPalAccountNonce (com.braintreepayments.api.models.PayPalAccountNonce)5 PayPalRequest (com.braintreepayments.api.models.PayPalRequest)4 UnionPayCardBuilder (com.braintreepayments.api.models.UnionPayCardBuilder)4 TestClientTokenBuilder (com.braintreepayments.api.test.TestClientTokenBuilder)4 TestConfigurationBuilder (com.braintreepayments.testutils.TestConfigurationBuilder)4 ArrayList (java.util.ArrayList)4 BraintreeException (com.braintreepayments.api.exceptions.BraintreeException)3 InvalidArgumentException (com.braintreepayments.api.exceptions.InvalidArgumentException)3