Search in sources :

Example 1 with UnionPayCardBuilder

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

the class TokenizationClientUnitTest method tokenize_tokenizesNonCardPaymentMethodsWithRestWhenGraphQLIsEnabled.

@Test
public void tokenize_tokenizesNonCardPaymentMethodsWithRestWhenGraphQLIsEnabled() {
    BraintreeFragment fragment = new MockFragmentBuilder().configuration(new TestConfigurationBuilder().graphQL().build()).build();
    TokenizationClient.tokenize(fragment, new PayPalAccountBuilder(), null);
    TokenizationClient.tokenize(fragment, new UnionPayCardBuilder(), null);
    TokenizationClient.tokenize(fragment, new VenmoAccountBuilder(), null);
    verifyZeroInteractions(fragment.getGraphQLHttpClient());
}
Also used : VenmoAccountBuilder(com.braintreepayments.api.models.VenmoAccountBuilder) PayPalAccountBuilder(com.braintreepayments.api.models.PayPalAccountBuilder) UnionPayCardBuilder(com.braintreepayments.api.models.UnionPayCardBuilder) TestConfigurationBuilder(com.braintreepayments.testutils.TestConfigurationBuilder) Test(org.junit.Test)

Example 2 with UnionPayCardBuilder

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

the class UnionPayUnitTest method tokenize_optionalSmsCode_sendsPayloadToEndpoint.

@Test
public void tokenize_optionalSmsCode_sendsPayloadToEndpoint() throws JSONException {
    UnionPayCardBuilder unionPayCardBuilder = new UnionPayCardBuilder().cardNumber("someCardNumber").expirationMonth("expirationMonth").expirationYear("expirationYear").cvv("cvv").enrollmentId("enrollmentId").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"));
    assertFalse(unionPayEnrollmentPayload.has("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 3 with UnionPayCardBuilder

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

the class UnionPayUnitTest method mockSuccessCallback.

/* helpers */
private void mockSuccessCallback() {
    mockStatic(TokenizationClient.class);
    doAnswer(new Answer<Void>() {

        @Override
        public Void answer(InvocationOnMock invocation) throws Throwable {
            UnionPayCardBuilder cardBuilder = (UnionPayCardBuilder) invocation.getArguments()[1];
            CardNonce cardNonce = mock(CardNonce.class);
            boolean hasSmsCode = false;
            try {
                hasSmsCode = new JSONObject(cardBuilder.build()).getJSONObject("options").has("smsCode");
            } catch (JSONException ignored) {
            }
            if (hasSmsCode) {
                when(cardNonce.getNonce()).thenReturn("nonce");
            }
            ((PaymentMethodNonceCallback) invocation.getArguments()[2]).success(cardNonce);
            return null;
        }
    }).when(TokenizationClient.class);
    TokenizationClient.tokenize(any(BraintreeFragment.class), any(UnionPayCardBuilder.class), any(PaymentMethodNonceCallback.class));
}
Also used : Answer(org.mockito.stubbing.Answer) PowerMockito.doAnswer(org.powermock.api.mockito.PowerMockito.doAnswer) JSONObject(org.json.JSONObject) InvocationOnMock(org.mockito.invocation.InvocationOnMock) UnionPayCardBuilder(com.braintreepayments.api.models.UnionPayCardBuilder) PaymentMethodNonceCallback(com.braintreepayments.api.interfaces.PaymentMethodNonceCallback) JSONException(org.json.JSONException) CardNonce(com.braintreepayments.api.models.CardNonce)

Example 4 with UnionPayCardBuilder

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

the class UnionPayUnitTest method tokenize_sendsAnalyticsEventOnTokenizeResult.

@Test
public void tokenize_sendsAnalyticsEventOnTokenizeResult() {
    mockSuccessCallback();
    UnionPayCardBuilder unionPayCardBuilder = new UnionPayCardBuilder();
    UnionPay.tokenize(mBraintreeFragment, unionPayCardBuilder);
    verify(mBraintreeFragment).sendAnalyticsEvent("union-pay.nonce-received");
}
Also used : UnionPayCardBuilder(com.braintreepayments.api.models.UnionPayCardBuilder) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 5 with UnionPayCardBuilder

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

the class UnionPayUnitTest method enroll_doesNotPassCvvToEnrollmentPayloadIfCvvExists.

@Test
public void enroll_doesNotPassCvvToEnrollmentPayloadIfCvvExists() throws JSONException {
    UnionPayCardBuilder unionPayCardBuilder = new UnionPayCardBuilder().cardNumber("some-card-number").cvv("123");
    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 enrollmentPayload = new JSONObject(argumentCaptor.getValue());
    JSONObject unionPayEnrollmentPayload = enrollmentPayload.getJSONObject("unionPayEnrollment");
    assertFalse(unionPayEnrollmentPayload.has("cvv"));
}
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)

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