Search in sources :

Example 11 with UnionPayCardBuilder

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

the class UnionPayUnitTest method enroll_sendsPayloadToEndpoint.

@Test
public void enroll_sendsPayloadToEndpoint() throws JSONException {
    UnionPayCardBuilder unionPayCardBuilder = new UnionPayCardBuilder().cardNumber("someCardNumber").expirationMonth("expirationMonth").expirationYear("expirationYear").mobileCountryCode("mobileCountryCode").mobilePhoneNumber("mobilePhoneNumber");
    BraintreeHttpClient httpClient = mock(BraintreeHttpClient.class);
    doNothing().when(httpClient).get(anyString(), any(HttpResponseCallback.class));
    when(mBraintreeFragment.getHttpClient()).thenReturn(httpClient);
    ArgumentCaptor<String> argumentCaptor = ArgumentCaptor.forClass(String.class);
    UnionPay.enroll(mBraintreeFragment, unionPayCardBuilder);
    verify(httpClient).post(eq("/v1/union_pay_enrollments"), argumentCaptor.capture(), any(HttpResponseCallback.class));
    JSONObject enrollPayload = new JSONObject(argumentCaptor.getValue());
    JSONObject unionPayEnrollment = enrollPayload.getJSONObject("unionPayEnrollment");
    assertEquals("someCardNumber", unionPayEnrollment.getString("number"));
    assertEquals("expirationMonth", unionPayEnrollment.getString("expirationMonth"));
    assertEquals("expirationYear", unionPayEnrollment.getString("expirationYear"));
    assertEquals("mobileCountryCode", unionPayEnrollment.getString("mobileCountryCode"));
    assertEquals("mobilePhoneNumber", unionPayEnrollment.getString("mobileNumber"));
}
Also used : JSONObject(org.json.JSONObject) UnionPayCardBuilder(com.braintreepayments.api.models.UnionPayCardBuilder) Matchers.anyString(org.mockito.Matchers.anyString) HttpResponseCallback(com.braintreepayments.api.interfaces.HttpResponseCallback) BraintreeHttpClient(com.braintreepayments.api.internal.BraintreeHttpClient) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 12 with UnionPayCardBuilder

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

the class UnionPayUnitTest method tokenize_sendsPayloadToEndpoint.

@Test
public void tokenize_sendsPayloadToEndpoint() throws JSONException {
    UnionPayCardBuilder unionPayCardBuilder = new UnionPayCardBuilder().cardNumber("someCardNumber").expirationMonth("expirationMonth").expirationYear("expirationYear").cvv("cvv").enrollmentId("enrollmentId").smsCode("smsCode").validate(true);
    BraintreeHttpClient httpClient = mock(BraintreeHttpClient.class);
    doNothing().when(httpClient).get(anyString(), any(HttpResponseCallback.class));
    when(mBraintreeFragment.getHttpClient()).thenReturn(httpClient);
    ArgumentCaptor<String> argumentCaptor = ArgumentCaptor.forClass(String.class);
    UnionPay.tokenize(mBraintreeFragment, unionPayCardBuilder);
    verify(httpClient).post(eq("/v1/payment_methods/credit_cards"), argumentCaptor.capture(), any(HttpResponseCallback.class));
    JSONObject tokenizePayload = new JSONObject(argumentCaptor.getValue());
    JSONObject creditCardPayload = tokenizePayload.getJSONObject("creditCard");
    JSONObject optionsPayload = creditCardPayload.getJSONObject("options");
    JSONObject unionPayEnrollmentPayload = optionsPayload.getJSONObject("unionPayEnrollment");
    assertEquals("someCardNumber", creditCardPayload.getString("number"));
    assertEquals("expirationMonth", creditCardPayload.getString("expirationMonth"));
    assertEquals("expirationYear", creditCardPayload.getString("expirationYear"));
    assertEquals("cvv", creditCardPayload.getString("cvv"));
    assertFalse(optionsPayload.has("validate"));
    assertEquals("enrollmentId", unionPayEnrollmentPayload.getString("id"));
    assertEquals("smsCode", unionPayEnrollmentPayload.getString("smsCode"));
}
Also used : JSONObject(org.json.JSONObject) UnionPayCardBuilder(com.braintreepayments.api.models.UnionPayCardBuilder) Matchers.anyString(org.mockito.Matchers.anyString) HttpResponseCallback(com.braintreepayments.api.interfaces.HttpResponseCallback) BraintreeHttpClient(com.braintreepayments.api.internal.BraintreeHttpClient) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 13 with UnionPayCardBuilder

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

the class UnionPayUnitTest method enroll_failsIfUnionPayIsDisabled.

@Test
public void enroll_failsIfUnionPayIsDisabled() throws JSONException {
    UnionPayCardBuilder unionPayCardBuilder = new UnionPayCardBuilder().cardNumber("some-card-number");
    BraintreeFragment fragment = new MockFragmentBuilder().configuration(Configuration.fromJson(stringFromFixture("configuration/configuration.json"))).build();
    UnionPay.enroll(fragment, unionPayCardBuilder);
    ArgumentCaptor<ConfigurationException> argumentCaptor = ArgumentCaptor.forClass(ConfigurationException.class);
    verify(fragment).postCallback(argumentCaptor.capture());
    assertEquals("UnionPay is not enabled", argumentCaptor.getValue().getMessage());
}
Also used : ConfigurationException(com.braintreepayments.api.exceptions.ConfigurationException) UnionPayCardBuilder(com.braintreepayments.api.models.UnionPayCardBuilder) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 14 with UnionPayCardBuilder

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

the class UnionPayUnitTest method enroll_sendsAnalyticsEventOnFailure.

@Test
public void enroll_sendsAnalyticsEventOnFailure() throws JSONException {
    UnionPayCardBuilder unionPayCardBuilder = new UnionPayCardBuilder().cardNumber("some-card-number");
    BraintreeFragment braintreeFragment = new MockFragmentBuilder().configuration(mConfigurationWithUnionPay).errorResponse(new BraintreeException()).build();
    UnionPay.enroll(braintreeFragment, unionPayCardBuilder);
    verify(braintreeFragment).sendAnalyticsEvent("union-pay.enrollment-failed");
}
Also used : UnionPayCardBuilder(com.braintreepayments.api.models.UnionPayCardBuilder) BraintreeException(com.braintreepayments.api.exceptions.BraintreeException) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 15 with UnionPayCardBuilder

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

the class UnionPayTest method tokenize_unionPayCredit_withExpirationMonthAndYear.

@Test(timeout = 30000)
public void tokenize_unionPayCredit_withExpirationMonthAndYear() throws InvalidArgumentException, 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();
}
Also used : UnionPayListener(com.braintreepayments.api.interfaces.UnionPayListener) UnionPayCardBuilder(com.braintreepayments.api.models.UnionPayCardBuilder) UnionPayCapabilities(com.braintreepayments.api.models.UnionPayCapabilities) CardNonce(com.braintreepayments.api.models.CardNonce) PaymentMethodNonceCreatedListener(com.braintreepayments.api.interfaces.PaymentMethodNonceCreatedListener) PaymentMethodNonce(com.braintreepayments.api.models.PaymentMethodNonce) 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