com.braintreepayments.api.interfaces.BraintreeCancelListener Java Examples

The following examples show how to use com.braintreepayments.api.interfaces.BraintreeCancelListener. 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: BraintreeFragmentUnitTest.java    From braintree_android with MIT License 6 votes vote down vote up
@Test
public void postCancelCallback_postsRequestCodeToListener() throws InvalidArgumentException {
    BraintreeFragment fragment = BraintreeFragment.newInstance(mAppCompatActivity, TOKENIZATION_KEY);
    final AtomicBoolean wasCalled = new AtomicBoolean(false);
    fragment.addListener(new BraintreeCancelListener() {
        @Override
        public void onCancel(int requestCode) {
            assertEquals(42, requestCode);
            wasCalled.set(true);
        }
    });

    fragment.postCancelCallback(42);

    assertTrue(wasCalled.get());
}
 
Example #2
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 #3
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 #4
Source File: BraintreeFragmentUnitTest.java    From braintree_android with MIT License 5 votes vote down vote up
@Test
public void addListener_flushesCancelCallback() throws InvalidArgumentException {
    BraintreeFragment fragment = BraintreeFragment.newInstance(mAppCompatActivity, TOKENIZATION_KEY);
    fragment.postCancelCallback(42);

    fragment.addListener(new BraintreeCancelListener() {
        @Override
        public void onCancel(int requestCode) {
            assertEquals(42, requestCode);
            mCalled.set(true);
        }
    });

    assertTrue(mCalled.get());
}
 
Example #5
Source File: BraintreeFragmentUnitTest.java    From braintree_android with MIT License 5 votes vote down vote up
@Test
public void removeListener_noCancelReceived() throws InvalidArgumentException {
    BraintreeFragment fragment = BraintreeFragment.newInstance(mAppCompatActivity, TOKENIZATION_KEY);
    BraintreeCancelListener listener = new BraintreeCancelListener() {
        @Override
        public void onCancel(int requestCode) {
            fail("Listener was called");
        }
    };

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

    fragment.postCancelCallback(42);
}
 
Example #6
Source File: BraintreeFragmentUnitTest.java    From braintree_android with MIT License 5 votes vote down vote up
@Test
public void onActivityResult_postsCancelCallbackWhenResultCodeIsCanceled() throws InvalidArgumentException {
    BraintreeFragment fragment = BraintreeFragment.newInstance(mAppCompatActivity, TOKENIZATION_KEY);
    fragment.addListener(new BraintreeCancelListener() {
        @Override
        public void onCancel(int requestCode) {
            assertEquals(42, requestCode);
            mCalled.set(true);
        }
    });

    fragment.onActivityResult(42, AppCompatActivity.RESULT_CANCELED, null);

    assertTrue(mCalled.get());
}
 
Example #7
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());
}