Search in sources :

Example 1 with UnionPayCapabilities

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

the class UnionPayUnitTest method fetchCapabilities_callsListenerWithCapabilitiesOnSuccess.

@Test
public void fetchCapabilities_callsListenerWithCapabilitiesOnSuccess() throws JSONException {
    BraintreeFragment fragment = new MockFragmentBuilder().configuration(mConfigurationWithUnionPay).successResponse(stringFromFixture("unionpay_capabilities_success_response.json")).build();
    UnionPay.fetchCapabilities(fragment, UNIONPAY_CREDIT);
    ArgumentCaptor<UnionPayCapabilities> argumentCaptor = ArgumentCaptor.forClass(UnionPayCapabilities.class);
    verify(fragment).postCallback(argumentCaptor.capture());
    UnionPayCapabilities capabilities = argumentCaptor.getValue();
    assertNotNull(capabilities);
    assertTrue(capabilities.isUnionPay());
    assertFalse(capabilities.isDebit());
    assertTrue(capabilities.supportsTwoStepAuthAndCapture());
    assertTrue(capabilities.isSupported());
}
Also used : UnionPayCapabilities(com.braintreepayments.api.models.UnionPayCapabilities) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 2 with UnionPayCapabilities

use of com.braintreepayments.api.models.UnionPayCapabilities 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 3 with UnionPayCapabilities

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

the class UnionPayTest method enroll_whenIsUnionPay_returnsEnrollmentId.

@Test(timeout = 10000)
public void enroll_whenIsUnionPay_returnsEnrollmentId() throws InterruptedException {
    String cardNumber = UNIONPAY_CREDIT;
    final UnionPayCardBuilder unionPayCardBuilder = new UnionPayCardBuilder().cardNumber(cardNumber).expirationMonth("12").expirationYear("2019").mobileCountryCode("62").mobilePhoneNumber("11111111111");
    mBraintreeFragment.addListener(new UnionPayListener() {

        @Override
        public void onCapabilitiesFetched(UnionPayCapabilities unionPayCapabilities) {
            assertTrue(unionPayCapabilities.isUnionPay());
            UnionPay.enroll(mBraintreeFragment, unionPayCardBuilder);
        }

        @Override
        public void onSmsCodeSent(String enrollmentId, boolean smsCodeRequired) {
            assertFalse(TextUtils.isEmpty(enrollmentId));
            assertTrue(smsCodeRequired);
            mCountDownLatch.countDown();
        }
    });
    UnionPay.fetchCapabilities(mBraintreeFragment, cardNumber);
    mCountDownLatch.await();
}
Also used : UnionPayListener(com.braintreepayments.api.interfaces.UnionPayListener) UnionPayCardBuilder(com.braintreepayments.api.models.UnionPayCardBuilder) UnionPayCapabilities(com.braintreepayments.api.models.UnionPayCapabilities) Test(org.junit.Test)

Example 4 with UnionPayCapabilities

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

the class UnionPayTest method assertSupported.

private void assertSupported(final String cardNumber, final boolean expected) throws InterruptedException {
    final CountDownLatch countDownLatch = new CountDownLatch(1);
    mBraintreeFragment.addListener(new UnionPayListener() {

        @Override
        public void onCapabilitiesFetched(UnionPayCapabilities capabilities) {
            boolean actual = capabilities.isSupported();
            String message = String.format("Expected %s to be supported? %b, but was %b", cardNumber, expected, actual);
            assertEquals(message, expected, actual);
            countDownLatch.countDown();
        }

        @Override
        public void onSmsCodeSent(String enrollmentId, boolean smsCodeRequired) {
            fail("Not expecting onSmsCodeSent");
        }
    });
    UnionPay.fetchCapabilities(mBraintreeFragment, cardNumber);
    countDownLatch.await();
}
Also used : UnionPayListener(com.braintreepayments.api.interfaces.UnionPayListener) UnionPayCapabilities(com.braintreepayments.api.models.UnionPayCapabilities) CountDownLatch(java.util.concurrent.CountDownLatch)

Example 5 with UnionPayCapabilities

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

the class UnionPayTest method enroll_whenSmsCodeRequiredFalse_onSmsCodeSentReturnsFalse.

@Test(timeout = 10000)
public void enroll_whenSmsCodeRequiredFalse_onSmsCodeSentReturnsFalse() throws InterruptedException {
    mCountDownLatch = new CountDownLatch(2);
    String cardNumber = UNIONPAY_SMS_NOT_REQUIRED;
    final UnionPayCardBuilder unionPayCardBuilder = new UnionPayCardBuilder().cardNumber(cardNumber).expirationMonth("12").expirationYear("2019").mobileCountryCode("62").mobilePhoneNumber("11111111111");
    mBraintreeFragment.addListener(new UnionPayListener() {

        @Override
        public void onCapabilitiesFetched(UnionPayCapabilities capabilities) {
            assertTrue(capabilities.isUnionPay());
            assertTrue(capabilities.isSupported());
            UnionPay.enroll(mBraintreeFragment, unionPayCardBuilder);
            mCountDownLatch.countDown();
        }

        @Override
        public void onSmsCodeSent(String enrollmentId, boolean smsCodeRequired) {
            assertNotNull(enrollmentId);
            assertFalse(smsCodeRequired);
            mCountDownLatch.countDown();
        }
    });
    mBraintreeFragment.addListener(new BraintreeErrorListener() {

        @Override
        public void onError(Exception error) {
            fail("Not expecting error");
        }
    });
    UnionPay.fetchCapabilities(mBraintreeFragment, cardNumber);
    mCountDownLatch.await();
}
Also used : UnionPayListener(com.braintreepayments.api.interfaces.UnionPayListener) UnionPayCardBuilder(com.braintreepayments.api.models.UnionPayCardBuilder) UnionPayCapabilities(com.braintreepayments.api.models.UnionPayCapabilities) CountDownLatch(java.util.concurrent.CountDownLatch) BraintreeErrorListener(com.braintreepayments.api.interfaces.BraintreeErrorListener) InvalidArgumentException(com.braintreepayments.api.exceptions.InvalidArgumentException) Test(org.junit.Test)

Aggregations

UnionPayCapabilities (com.braintreepayments.api.models.UnionPayCapabilities)11 UnionPayListener (com.braintreepayments.api.interfaces.UnionPayListener)10 Test (org.junit.Test)10 UnionPayCardBuilder (com.braintreepayments.api.models.UnionPayCardBuilder)5 InvalidArgumentException (com.braintreepayments.api.exceptions.InvalidArgumentException)3 BraintreeErrorListener (com.braintreepayments.api.interfaces.BraintreeErrorListener)3 PaymentMethodNonceCreatedListener (com.braintreepayments.api.interfaces.PaymentMethodNonceCreatedListener)3 PaymentMethodNonce (com.braintreepayments.api.models.PaymentMethodNonce)3 CardNonce (com.braintreepayments.api.models.CardNonce)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)2 ErrorWithResponse (com.braintreepayments.api.exceptions.ErrorWithResponse)1 AmericanExpressListener (com.braintreepayments.api.interfaces.AmericanExpressListener)1 BraintreeCancelListener (com.braintreepayments.api.interfaces.BraintreeCancelListener)1 BraintreePaymentResultListener (com.braintreepayments.api.interfaces.BraintreePaymentResultListener)1 ConfigurationListener (com.braintreepayments.api.interfaces.ConfigurationListener)1 PaymentMethodNoncesUpdatedListener (com.braintreepayments.api.interfaces.PaymentMethodNoncesUpdatedListener)1 AmericanExpressRewardsBalance (com.braintreepayments.api.models.AmericanExpressRewardsBalance)1 BraintreePaymentResult (com.braintreepayments.api.models.BraintreePaymentResult)1 Configuration (com.braintreepayments.api.models.Configuration)1