Search in sources :

Example 6 with UnionPayCardBuilder

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

the class UnionPayUnitTest method enroll_sendsAnalyticsEventOnSuccess.

@Test
public void enroll_sendsAnalyticsEventOnSuccess() throws JSONException {
    UnionPayCardBuilder unionPayCardBuilder = new UnionPayCardBuilder().cardNumber("some-card-number");
    JSONObject successObject = new JSONObject().put("unionPayEnrollmentId", "unionPayEnrollmentId").put("smsCodeRequired", true);
    BraintreeFragment braintreeFragment = new MockFragmentBuilder().configuration(mConfigurationWithUnionPay).successResponse(successObject.toString()).build();
    UnionPay.enroll(braintreeFragment, unionPayCardBuilder);
    verify(braintreeFragment).sendAnalyticsEvent("union-pay.enrollment-succeeded");
}
Also used : JSONObject(org.json.JSONObject) UnionPayCardBuilder(com.braintreepayments.api.models.UnionPayCardBuilder) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 7 with UnionPayCardBuilder

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

use of com.braintreepayments.api.models.UnionPayCardBuilder 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)

Example 9 with UnionPayCardBuilder

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

the class UnionPayTest method enroll_whenIsUnionPayFalse_willError.

@Test(timeout = 10000)
public void enroll_whenIsUnionPayFalse_willError() throws InterruptedException {
    String cardNumber = CardNumber.VISA;
    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) {
            assertFalse(capabilities.isUnionPay());
            UnionPay.enroll(mBraintreeFragment, unionPayCardBuilder);
        }

        @Override
        public void onSmsCodeSent(String enrollmentId, boolean smsCodeRequired) {
            fail("Not expecting onSmsCodeSent");
        }
    });
    mBraintreeFragment.addListener(new BraintreeErrorListener() {

        @Override
        public void onError(Exception error) {
            assertTrue(error instanceof ErrorWithResponse);
            assertEquals("UnionPay Enrollment is invalid", error.getMessage());
            mCountDownLatch.countDown();
        }
    });
    UnionPay.fetchCapabilities(mBraintreeFragment, cardNumber);
    mCountDownLatch.await();
}
Also used : UnionPayListener(com.braintreepayments.api.interfaces.UnionPayListener) ErrorWithResponse(com.braintreepayments.api.exceptions.ErrorWithResponse) UnionPayCardBuilder(com.braintreepayments.api.models.UnionPayCardBuilder) UnionPayCapabilities(com.braintreepayments.api.models.UnionPayCapabilities) BraintreeErrorListener(com.braintreepayments.api.interfaces.BraintreeErrorListener) InvalidArgumentException(com.braintreepayments.api.exceptions.InvalidArgumentException) Test(org.junit.Test)

Example 10 with UnionPayCardBuilder

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

the class UnionPayUnitTest method enroll_callsListenerWithUnionPayEnrollmentIdAdded.

@Test
public void enroll_callsListenerWithUnionPayEnrollmentIdAdded() throws JSONException {
    String expectedEnrollmentId = "some-enrollment-id";
    boolean expectedSmsCodeRequired = true;
    JSONObject response = new JSONObject();
    response.put("unionPayEnrollmentId", expectedEnrollmentId);
    response.put("smsCodeRequired", expectedSmsCodeRequired);
    BraintreeFragment fragment = new MockFragmentBuilder().configuration(mConfigurationWithUnionPay).successResponse(response.toString()).build();
    UnionPayCardBuilder unionPayCardBuilder = new UnionPayCardBuilder();
    UnionPay.enroll(fragment, unionPayCardBuilder);
    verify(fragment).postUnionPayCallback(expectedEnrollmentId, expectedSmsCodeRequired);
}
Also used : JSONObject(org.json.JSONObject) UnionPayCardBuilder(com.braintreepayments.api.models.UnionPayCardBuilder) Matchers.anyString(org.mockito.Matchers.anyString) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

UnionPayCardBuilder (com.braintreepayments.api.models.UnionPayCardBuilder)18 Test (org.junit.Test)15 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)9 JSONObject (org.json.JSONObject)7 UnionPayListener (com.braintreepayments.api.interfaces.UnionPayListener)5 UnionPayCapabilities (com.braintreepayments.api.models.UnionPayCapabilities)5 Matchers.anyString (org.mockito.Matchers.anyString)5 HttpResponseCallback (com.braintreepayments.api.interfaces.HttpResponseCallback)4 BraintreeHttpClient (com.braintreepayments.api.internal.BraintreeHttpClient)4 CardNonce (com.braintreepayments.api.models.CardNonce)3 InvalidArgumentException (com.braintreepayments.api.exceptions.InvalidArgumentException)2 BraintreeErrorListener (com.braintreepayments.api.interfaces.BraintreeErrorListener)2 PaymentMethodNonceCreatedListener (com.braintreepayments.api.interfaces.PaymentMethodNonceCreatedListener)2 PaymentMethodNonce (com.braintreepayments.api.models.PaymentMethodNonce)2 BraintreeException (com.braintreepayments.api.exceptions.BraintreeException)1 ConfigurationException (com.braintreepayments.api.exceptions.ConfigurationException)1 ErrorWithResponse (com.braintreepayments.api.exceptions.ErrorWithResponse)1 PaymentMethodNonceCallback (com.braintreepayments.api.interfaces.PaymentMethodNonceCallback)1 CardBuilder (com.braintreepayments.api.models.CardBuilder)1 PayPalAccountBuilder (com.braintreepayments.api.models.PayPalAccountBuilder)1