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);
}
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);
}
});
}
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());
}
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");
}
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));
}
Aggregations