com.braintreepayments.api.interfaces.PaymentMethodNonceCreatedListener Java Examples

The following examples show how to use com.braintreepayments.api.interfaces.PaymentMethodNonceCreatedListener. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Braintree.java    From react-native-braintree-android with MIT License 6 votes vote down vote up
@ReactMethod
public void setup(final String token, final Callback successCallback, final Callback errorCallback) {
  try {
    this.mBraintreeFragment = BraintreeFragment.newInstance(getCurrentActivity(), token);
    this.mBraintreeFragment.addListener(new PaymentMethodNonceCreatedListener() {
      @Override
      public void onPaymentMethodNonceCreated(PaymentMethodNonce paymentMethodNonce) {
        nonceCallback(paymentMethodNonce.getNonce());
      }
    });
    this.setToken(token);
    successCallback.invoke(this.getToken());
  } catch (InvalidArgumentException e) {
    errorCallback.invoke(e.getMessage());
  }
}
 
Example #2
Source File: ThreeDSecureVerificationTest.java    From braintree_android with MIT License 6 votes vote down vote up
@Test(timeout = 10000)
public void performVerification_doesALookupAndReturnsACardWhenAuthenticationIsUnavailable()
        throws InterruptedException {
    BraintreeFragment fragment = getFragment();
    fragment.addListener(new PaymentMethodNonceCreatedListener() {
        @Override
        public void onPaymentMethodNonceCreated(PaymentMethodNonce paymentMethodNonce) {
            assertIsANonce(paymentMethodNonce.getNonce());
            CardNonce cardNonce = (CardNonce) paymentMethodNonce;

            assertEquals("69", cardNonce.getLastTwo());
            assertFalse(cardNonce.getThreeDSecureInfo().isLiabilityShifted());
            assertFalse(cardNonce.getThreeDSecureInfo().isLiabilityShiftPossible());
            assertTrue(((CardNonce) paymentMethodNonce).getThreeDSecureInfo().wasVerified());

            mCountDownLatch.countDown();
        }
    });
    CardBuilder cardBuilder = new CardBuilder()
            .cardNumber(THREE_D_SECURE_AUTHENTICATION_UNAVAILABLE)
            .expirationDate("12/20");

    ThreeDSecure.performVerification(fragment, cardBuilder, TEST_AMOUNT);

    mCountDownLatch.await();
}
 
Example #3
Source File: ThreeDSecureVerificationTest.java    From braintree_android with MIT License 6 votes vote down vote up
@Test(timeout = 10000)
public void performVerification_doesALookupAndReturnsACardAndANullACSUrlWhenAuthenticationIsNotRequired()
        throws InterruptedException {
    BraintreeFragment fragment = getFragment();
    fragment.addListener(new PaymentMethodNonceCreatedListener() {
        @Override
        public void onPaymentMethodNonceCreated(PaymentMethodNonce paymentMethodNonce) {
            assertIsANonce(paymentMethodNonce.getNonce());
            CardNonce cardNonce = (CardNonce) paymentMethodNonce;

            assertEquals("51", cardNonce.getLastTwo());
            assertFalse(cardNonce.getThreeDSecureInfo().isLiabilityShifted());
            assertFalse(cardNonce.getThreeDSecureInfo().isLiabilityShiftPossible());
            assertTrue(((CardNonce) paymentMethodNonce).getThreeDSecureInfo().wasVerified());

            mCountDownLatch.countDown();
        }
    });
    CardBuilder cardBuilder = new CardBuilder()
            .cardNumber(THREE_D_SECURE_VERIFICATON_NOT_REQUIRED)
            .expirationDate("12/20");

    ThreeDSecure.performVerification(fragment, cardBuilder, TEST_AMOUNT);

    mCountDownLatch.await();
}
 
Example #4
Source File: BraintreeFragmentUnitTest.java    From braintree_android with MIT License 6 votes vote down vote up
@Test
public void postCallback_postsPaymentMethodNonceToListener() throws InvalidArgumentException {
    BraintreeFragment fragment = BraintreeFragment.newInstance(mAppCompatActivity, TOKENIZATION_KEY);
    final AtomicBoolean wasCalled = new AtomicBoolean(false);
    fragment.addListener(new PaymentMethodNonceCreatedListener() {
        @Override
        public void onPaymentMethodNonceCreated(PaymentMethodNonce paymentMethodNonce) {
            assertTrue(paymentMethodNonce instanceof CardNonce);
            wasCalled.set(true);
        }
    });

    fragment.postCallback(new CardNonce());

    assertTrue(wasCalled.get());
}
 
Example #5
Source File: BraintreeFragmentTestUtils.java    From braintree_android with MIT License 6 votes vote down vote up
public static CardNonce tokenize(BraintreeFragment fragment, CardBuilder cardBuilder) {
    final CountDownLatch latch = new CountDownLatch(1);
    final CardNonce[] cardNonce = new CardNonce[1];
    PaymentMethodNonceCreatedListener listener = new PaymentMethodNonceCreatedListener() {
        @Override
        public void onPaymentMethodNonceCreated(PaymentMethodNonce paymentMethodNonce) {
            cardNonce[0] = (CardNonce) paymentMethodNonce;
            latch.countDown();
        }
    };
    fragment.addListener(listener);

    Card.tokenize(fragment, cardBuilder);

    try {
        latch.await();
    } catch (InterruptedException ignored) {}

    fragment.removeListener(listener);
    return cardNonce[0];
}
 
Example #6
Source File: ThreeDSecureTest.java    From braintree_android with MIT License 6 votes vote down vote up
@Test(timeout = 10000)
public void performVerification_acceptsACardBuilderAndPostsAPaymentMethodNonceToListener()
        throws InterruptedException {
    BraintreeFragment fragment = getFragmentWithAuthorization(mActivity,
            new TestClientTokenBuilder().build());
    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();
}
 
Example #7
Source File: ThreeDSecureTest.java    From braintree_android with MIT License 6 votes vote down vote up
@Test(timeout = 10000)
public void performVerification_postsPaymentMethodNonceToListenersWhenLookupReturnsACard()
        throws InterruptedException {
    String clientToken = new TestClientTokenBuilder().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();
}
 
Example #8
Source File: ThreeDSecureVerificationTest.java    From braintree_android with MIT License 5 votes vote down vote up
@Test(timeout = 10000)
public void performVerification_doesALookupAndReturnsACardWhenThereIsAMPILookupError() throws InterruptedException {
    BraintreeFragment fragment = getFragment();
    fragment.addListener(new PaymentMethodNonceCreatedListener() {
        @Override
        public void onPaymentMethodNonceCreated(PaymentMethodNonce paymentMethodNonce) {
            assertIsANonce(paymentMethodNonce.getNonce());
            CardNonce cardNonce = (CardNonce) paymentMethodNonce;

            assertEquals("85", cardNonce.getLastTwo());
            assertFalse(cardNonce.getThreeDSecureInfo().isLiabilityShifted());
            assertFalse(cardNonce.getThreeDSecureInfo().isLiabilityShiftPossible());
            assertTrue(((CardNonce) paymentMethodNonce).getThreeDSecureInfo().wasVerified());

            mCountDownLatch.countDown();
        }
    });

    fragment.addListener(new BraintreeErrorListener() {
        @Override
        public void onError(Exception error) {
            fail(error.getMessage());
        }
    });

    CardBuilder cardBuilder = new CardBuilder()
            .cardNumber(THREE_D_SECURE_MPI_LOOKUP_ERROR)
            .expirationDate("12/20");

    ThreeDSecure.performVerification(fragment, cardBuilder, TEST_AMOUNT);

    mCountDownLatch.await();
}
 
Example #9
Source File: ThreeDSecureVerificationTest.java    From braintree_android with MIT License 5 votes vote down vote up
@Test(timeout = 10000)
public void performVerification_doesALookupAndReturnsACardWhenThereIsALookupError() throws InterruptedException {
    BraintreeFragment fragment = getFragment();
    fragment.addListener(new PaymentMethodNonceCreatedListener() {
        @Override
        public void onPaymentMethodNonceCreated(PaymentMethodNonce paymentMethodNonce) {
            assertIsANonce(paymentMethodNonce.getNonce());
            CardNonce cardNonce = (CardNonce) paymentMethodNonce;

            assertEquals("77", cardNonce.getLastTwo());
            assertFalse(cardNonce.getThreeDSecureInfo().isLiabilityShifted());
            assertFalse(cardNonce.getThreeDSecureInfo().isLiabilityShiftPossible());
            assertTrue(((CardNonce) paymentMethodNonce).getThreeDSecureInfo().wasVerified());

            mCountDownLatch.countDown();
        }
    });

    fragment.addListener(new BraintreeErrorListener() {
        @Override
        public void onError(Exception error) {
            fail(error.getMessage());
        }
    });

    CardBuilder cardBuilder = new CardBuilder()
            .cardNumber(THREE_D_SECURE_LOOKUP_ERROR)
            .expirationDate("12/20");

    ThreeDSecure.performVerification(fragment, cardBuilder, TEST_AMOUNT);

    mCountDownLatch.await();
}
 
Example #10
Source File: BraintreeFragmentUnitTest.java    From braintree_android with MIT License 5 votes vote down vote up
@Test
public void removeListener_noPaymentMethodNonceCreatedReceived() throws InvalidArgumentException {
    BraintreeFragment fragment = BraintreeFragment.newInstance(mAppCompatActivity, TOKENIZATION_KEY);
    PaymentMethodNonceCreatedListener listener = new PaymentMethodNonceCreatedListener() {
        @Override
        public void onPaymentMethodNonceCreated(PaymentMethodNonce paymentMethodNonce) {
            fail("Listener was called");
        }
    };

    fragment.addListener(listener);
    fragment.removeListener(listener);

    fragment.postCallback(new CardNonce());
}
 
Example #11
Source File: BraintreeFragmentUnitTest.java    From braintree_android with MIT License 5 votes vote down vote up
@Test
public void addListener_flushesPaymentMethodNonceCreatedCallback() throws InvalidArgumentException {
    BraintreeFragment fragment = BraintreeFragment.newInstance(mAppCompatActivity, TOKENIZATION_KEY);
    fragment.postCallback(new CardNonce());

    fragment.addListener(new PaymentMethodNonceCreatedListener() {
        @Override
        public void onPaymentMethodNonceCreated(PaymentMethodNonce paymentMethodNonce) {
            mCalled.set(true);
        }
    });

    assertTrue(mCalled.get());
}
 
Example #12
Source File: ThreeDSecureTest.java    From braintree_android with MIT License 5 votes vote down vote up
@Test(timeout = 10000)
public void performVerification_acceptsAThreeDSecureRequest_postsPaymentMethodNonceToListenersWhenLookupReturnsACard()
        throws InterruptedException {
    String clientToken = new TestClientTokenBuilder().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());

            ThreeDSecureInfo threeDSecureInfo = ((CardNonce) paymentMethodNonce).getThreeDSecureInfo();
            assertFalse(threeDSecureInfo.isLiabilityShifted());
            assertFalse(threeDSecureInfo.isLiabilityShiftPossible());
            assertTrue(((CardNonce) paymentMethodNonce).getThreeDSecureInfo().wasVerified());
            mCountDownLatch.countDown();
        }
    });

    ThreeDSecureRequest request = new ThreeDSecureRequest()
            .nonce(nonce)
            .amount("5");

    ThreeDSecure.performVerification(fragment, request);

    mCountDownLatch.await();
}
 
Example #13
Source File: UnionPayTest.java    From braintree_android with MIT License 5 votes vote down vote up
@Ignore("Sample merchant account is not set up for Union Pay")
@Test(timeout = 30000)
public void tokenize_unionPayCredit_withExpirationMonthAndYear() throws 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();
}
 
Example #14
Source File: UnionPayTest.java    From braintree_android with MIT License 5 votes vote down vote up
@Ignore("Sample merchant account is not set up for Union Pay")
@Test(timeout = 10000)
public void tokenize_unionPayCredit_withExpirationDate() throws 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();
}
 
Example #15
Source File: CardTest.java    From braintree_android with MIT License 5 votes vote down vote up
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();
        }
    });
    fragment.addListener(new BraintreeErrorListener() {
        @Override
        public void onError(Exception error) {
            throw new RuntimeException(error);
        }
    });

    Card.tokenize(fragment, cardBuilder);

    countDownLatch.await();
}
 
Example #16
Source File: CardTest.java    From braintree_android with MIT License 5 votes vote down vote up
@Test(timeout = 10000)
public void tokenize_tokenizesCvvOnly() throws Exception {
    final CountDownLatch countDownLatch = new CountDownLatch(1);
    BraintreeFragment fragment = setupBraintreeFragment(TOKENIZATION_KEY);
    fragment.addListener(new PaymentMethodNonceCreatedListener() {
        @Override
        public void onPaymentMethodNonceCreated(PaymentMethodNonce paymentMethodNonce) {
            CardNonce cardNonce = (CardNonce) paymentMethodNonce;

            assertNotNull(cardNonce.getBinData());
            assertEquals("Unknown", cardNonce.getCardType());
            assertEquals("", cardNonce.getLastFour());
            assertEquals("", cardNonce.getLastTwo());
            assertNotNull(cardNonce.getThreeDSecureInfo());
            assertFalse(cardNonce.isDefault());
            assertEquals("", cardNonce.getDescription());
            assertNotNull(cardNonce.getNonce());

            countDownLatch.countDown();
        }
    });

    CardBuilder cardBuilder = new CardBuilder().cvv("123");
    Card.tokenize(fragment, cardBuilder);

    countDownLatch.await();
}
 
Example #17
Source File: BraintreeFragment.java    From braintree_android with MIT License 5 votes vote down vote up
/**
 * Removes a previously added listener.
 *
 * @param listener the listener to remove.
 */
public <T extends BraintreeListener> void removeListener(T listener) {
    if (listener instanceof ConfigurationListener) {
        mConfigurationListener = null;
    }

    if (listener instanceof BraintreeCancelListener) {
        mCancelListener = null;
    }

    if (listener instanceof PaymentMethodNoncesUpdatedListener) {
        mPaymentMethodNoncesUpdatedListener = null;
    }

    if (listener instanceof PaymentMethodNonceCreatedListener) {
        mPaymentMethodNonceCreatedListener = null;
    }

    if (listener instanceof PaymentMethodNonceDeletedListener) {
        mPaymentMethodNonceDeletedListener = null;
    }

    if (listener instanceof BraintreePaymentResultListener) {
        mBraintreePaymentResultListener = null;
    }

    if (listener instanceof BraintreeErrorListener) {
        mErrorListener = null;
    }

    if (listener instanceof UnionPayListener) {
        mUnionPayListener = null;
    }

    if (listener instanceof AmericanExpressListener) {
        mAmericanExpressListener = null;
    }
}
 
Example #18
Source File: BraintreeFragment.java    From braintree_android with MIT License 5 votes vote down vote up
/**
 * Adds a listener.
 *
 * @param listener the listener to add.
 */
public <T extends BraintreeListener> void addListener(T listener) {
    if (listener instanceof ConfigurationListener) {
        mConfigurationListener = (ConfigurationListener) listener;
    }

    if (listener instanceof BraintreeCancelListener) {
        mCancelListener = (BraintreeCancelListener) listener;
    }

    if (listener instanceof PaymentMethodNoncesUpdatedListener) {
        mPaymentMethodNoncesUpdatedListener = (PaymentMethodNoncesUpdatedListener) listener;
    }

    if (listener instanceof PaymentMethodNonceCreatedListener) {
        mPaymentMethodNonceCreatedListener = (PaymentMethodNonceCreatedListener) listener;
    }

    if (listener instanceof PaymentMethodNonceDeletedListener) {
        mPaymentMethodNonceDeletedListener = (PaymentMethodNonceDeletedListener) listener;
    }

    if (listener instanceof BraintreePaymentResultListener) {
        mBraintreePaymentResultListener = (BraintreePaymentResultListener) listener;
    }

    if (listener instanceof BraintreeErrorListener) {
        mErrorListener = (BraintreeErrorListener) listener;
    }

    if (listener instanceof UnionPayListener) {
        mUnionPayListener = (UnionPayListener) listener;
    }

    if (listener instanceof AmericanExpressListener) {
        mAmericanExpressListener = (AmericanExpressListener) listener;
    }

    flushCallbacks();
}
 
Example #19
Source File: DropInActivity.java    From braintree-android-drop-in with MIT License 5 votes vote down vote up
@Override
public void onPaymentMethodNoncesUpdated(List<PaymentMethodNonce> paymentMethodNonces) {
    if (paymentMethodNonces.size() > 0) {
        mSupportedPaymentMethodsHeader.setText(R.string.bt_other);
        mVaultedPaymentMethodsContainer.setVisibility(View.VISIBLE);
        mVaultedPaymentMethodsView.setAdapter(new VaultedPaymentMethodsAdapter(new PaymentMethodNonceCreatedListener() {
            @Override
            public void onPaymentMethodNonceCreated(PaymentMethodNonce paymentMethodNonce) {
                if (paymentMethodNonce instanceof CardNonce) {
                    mBraintreeFragment.sendAnalyticsEvent("vaulted-card.select");
                }

                DropInActivity.this.onPaymentMethodNonceCreated(paymentMethodNonce);
            }
        }, paymentMethodNonces));

        if (mDropInRequest.isVaultManagerEnabled()) {
            mVaultManagerButton.setVisibility(View.VISIBLE);
        }

        for (PaymentMethodNonce nonce : paymentMethodNonces) {
            if (nonce instanceof CardNonce) {
                mBraintreeFragment.sendAnalyticsEvent("vaulted-card.appear");
                break;
            }
        }

    } else {
        mSupportedPaymentMethodsHeader.setText(R.string.bt_select_payment_method);
        mVaultedPaymentMethodsContainer.setVisibility(View.GONE);
    }
}
 
Example #20
Source File: BraintreeFragmentUnitTest.java    From braintree_android with MIT License 4 votes vote down vote up
@Test
public void addAndRemoveListenersAddAndRemoveAllListeners() throws InvalidArgumentException {
    BraintreeFragment fragment = BraintreeFragment.newInstance(mAppCompatActivity, 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());
}
 
Example #21
Source File: VaultedPaymentMethodsAdapter.java    From braintree-android-drop-in with MIT License 4 votes vote down vote up
public VaultedPaymentMethodsAdapter(PaymentMethodNonceCreatedListener listener,
                                    List<PaymentMethodNonce> paymentMethodNonces) {
    mSelectedListener = listener;
    mPaymentMethodNonces = paymentMethodNonces;
}