Search in sources :

Example 1 with AndroidPayCardNonce

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

the class BraintreeFragmentUnitTest method postCallback_onlyAllowsOneAndroidPayCardNonceToBePresent.

@Test
public void postCallback_onlyAllowsOneAndroidPayCardNonceToBePresent() throws InvalidArgumentException {
    BraintreeFragment fragment = BraintreeFragment.newInstance(mActivity, TOKENIZATION_KEY);
    assertEquals(0, fragment.getCachedPaymentMethodNonces().size());
    fragment.postCallback(new CardNonce());
    fragment.postCallback(new AndroidPayCardNonce());
    fragment.postCallback(new AndroidPayCardNonce());
    assertEquals(2, fragment.getCachedPaymentMethodNonces().size());
    assertTrue(fragment.getCachedPaymentMethodNonces().get(0) instanceof AndroidPayCardNonce);
}
Also used : AndroidPayCardNonce(com.braintreepayments.api.models.AndroidPayCardNonce) AndroidPayCardNonce(com.braintreepayments.api.models.AndroidPayCardNonce) CardNonce(com.braintreepayments.api.models.CardNonce) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 2 with AndroidPayCardNonce

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

the class BraintreeFragment method postCallback.

protected void postCallback(final PaymentMethodNonce paymentMethodNonce) {
    if (paymentMethodNonce instanceof AndroidPayCardNonce) {
        for (PaymentMethodNonce cachedPaymentMethodNonce : new ArrayList<>(mCachedPaymentMethodNonces)) {
            if (cachedPaymentMethodNonce instanceof AndroidPayCardNonce) {
                mCachedPaymentMethodNonces.remove(cachedPaymentMethodNonce);
            }
        }
    }
    mCachedPaymentMethodNonces.add(0, paymentMethodNonce);
    postOrQueueCallback(new QueuedCallback() {

        @Override
        public boolean shouldRun() {
            return mPaymentMethodNonceCreatedListener != null;
        }

        @Override
        public void run() {
            mPaymentMethodNonceCreatedListener.onPaymentMethodNonceCreated(paymentMethodNonce);
        }
    });
}
Also used : AndroidPayCardNonce(com.braintreepayments.api.models.AndroidPayCardNonce) ArrayList(java.util.ArrayList) PaymentMethodNonce(com.braintreepayments.api.models.PaymentMethodNonce) QueuedCallback(com.braintreepayments.api.interfaces.QueuedCallback)

Example 3 with AndroidPayCardNonce

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

the class BraintreeFragmentUnitTest method postCallback_doesNotRemoveAndroidPayCardNonceWhenAnotherNonceIsAdded.

@Test
public void postCallback_doesNotRemoveAndroidPayCardNonceWhenAnotherNonceIsAdded() throws InvalidArgumentException {
    BraintreeFragment fragment = BraintreeFragment.newInstance(mActivity, TOKENIZATION_KEY);
    assertEquals(0, fragment.getCachedPaymentMethodNonces().size());
    fragment.postCallback(new AndroidPayCardNonce());
    fragment.postCallback(new CardNonce());
    assertEquals(2, fragment.getCachedPaymentMethodNonces().size());
}
Also used : AndroidPayCardNonce(com.braintreepayments.api.models.AndroidPayCardNonce) AndroidPayCardNonce(com.braintreepayments.api.models.AndroidPayCardNonce) CardNonce(com.braintreepayments.api.models.CardNonce) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 4 with AndroidPayCardNonce

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

the class AndroidPayTest method changePaymentMethod_sendsAnalyticsEvent.

@Test
public void changePaymentMethod_sendsAnalyticsEvent() {
    BraintreeFragment fragment = getSetupFragment();
    doNothing().when(fragment).startActivityForResult(any(Intent.class), anyInt());
    AndroidPayCardNonce androidPayCardNonce = mock(AndroidPayCardNonce.class);
    when(androidPayCardNonce.getGoogleTransactionId()).thenReturn("google-transaction-id");
    AndroidPay.changePaymentMethod(fragment, androidPayCardNonce);
    verify(fragment).sendAnalyticsEvent("android-pay.change-masked-wallet");
}
Also used : AndroidPayCardNonce(com.braintreepayments.api.models.AndroidPayCardNonce) Intent(android.content.Intent) Test(org.junit.Test)

Example 5 with AndroidPayCardNonce

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

the class AndroidPayTest method changePaymentMethod_startsActivity.

@Test
public void changePaymentMethod_startsActivity() {
    BraintreeFragment fragment = getSetupFragment();
    doNothing().when(fragment).startActivityForResult(any(Intent.class), anyInt());
    AndroidPayCardNonce androidPayCardNonce = mock(AndroidPayCardNonce.class);
    when(androidPayCardNonce.getGoogleTransactionId()).thenReturn("google-transaction-id");
    Cart cart = Cart.newBuilder().build();
    when(androidPayCardNonce.getCart()).thenReturn(cart);
    AndroidPay.changePaymentMethod(fragment, androidPayCardNonce);
    ArgumentCaptor<Intent> captor = ArgumentCaptor.forClass(Intent.class);
    verify(fragment).startActivityForResult(captor.capture(), eq(BraintreeRequestCodes.ANDROID_PAY));
    Intent intent = captor.getValue();
    assertEquals(AndroidPayActivity.class.getName(), intent.getComponent().getClassName());
    assertEquals(CHANGE_PAYMENT_METHOD, intent.getIntExtra(EXTRA_REQUEST_TYPE, -1));
    assertEquals(WalletConstants.ENVIRONMENT_TEST, intent.getIntExtra(EXTRA_ENVIRONMENT, -1));
    assertEquals("google-transaction-id", intent.getStringExtra(EXTRA_GOOGLE_TRANSACTION_ID));
    assertEquals(cart, intent.getParcelableExtra(EXTRA_CART));
}
Also used : AndroidPayCardNonce(com.braintreepayments.api.models.AndroidPayCardNonce) Intent(android.content.Intent) Cart(com.google.android.gms.wallet.Cart) Test(org.junit.Test)

Aggregations

AndroidPayCardNonce (com.braintreepayments.api.models.AndroidPayCardNonce)5 Test (org.junit.Test)4 Intent (android.content.Intent)2 CardNonce (com.braintreepayments.api.models.CardNonce)2 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)2 QueuedCallback (com.braintreepayments.api.interfaces.QueuedCallback)1 PaymentMethodNonce (com.braintreepayments.api.models.PaymentMethodNonce)1 Cart (com.google.android.gms.wallet.Cart)1 ArrayList (java.util.ArrayList)1