Search in sources :

Example 11 with BraintreeHttpClient

use of com.braintreepayments.api.internal.BraintreeHttpClient 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 12 with BraintreeHttpClient

use of com.braintreepayments.api.internal.BraintreeHttpClient in project braintree_android by braintree.

the class UnionPayUnitTest method fetchCapabilities_sendsPayloadToEndpoint.

@Test
public void fetchCapabilities_sendsPayloadToEndpoint() {
    BraintreeFragment fragment = new MockFragmentBuilder().configuration(mConfigurationWithUnionPay).build();
    BraintreeHttpClient httpClient = mock(BraintreeHttpClient.class);
    doNothing().when(httpClient).get(anyString(), any(HttpResponseCallback.class));
    when(fragment.getHttpClient()).thenReturn(httpClient);
    UnionPay.fetchCapabilities(fragment, UNIONPAY_CREDIT);
    String expectedUrl = Uri.parse("/v1/payment_methods/credit_cards/capabilities").buildUpon().appendQueryParameter("creditCard[number]", UNIONPAY_CREDIT).build().toString();
    verify(httpClient).get(eq(expectedUrl), any(HttpResponseCallback.class));
}
Also used : 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

BraintreeHttpClient (com.braintreepayments.api.internal.BraintreeHttpClient)12 HttpResponseCallback (com.braintreepayments.api.interfaces.HttpResponseCallback)9 Test (org.junit.Test)8 Matchers.anyString (org.mockito.Matchers.anyString)5 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)5 ConfigurationListener (com.braintreepayments.api.interfaces.ConfigurationListener)4 UnionPayCardBuilder (com.braintreepayments.api.models.UnionPayCardBuilder)4 JSONObject (org.json.JSONObject)4 InvalidArgumentException (com.braintreepayments.api.exceptions.InvalidArgumentException)3 UnexpectedException (com.braintreepayments.api.exceptions.UnexpectedException)3 Configuration (com.braintreepayments.api.models.Configuration)3 SharedPreferencesHelper.writeMockConfiguration (com.braintreepayments.testutils.SharedPreferencesHelper.writeMockConfiguration)3 BraintreeGraphQLHttpClient (com.braintreepayments.api.internal.BraintreeGraphQLHttpClient)1 PaymentMethodNonce (com.braintreepayments.api.models.PaymentMethodNonce)1 TokenizationKey (com.braintreepayments.api.models.TokenizationKey)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 JSONException (org.json.JSONException)1 Before (org.junit.Before)1 Mockito.doAnswer (org.mockito.Mockito.doAnswer)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1