use of com.braintreepayments.api.internal.BraintreeHttpClient 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"));
}
use of com.braintreepayments.api.internal.BraintreeHttpClient 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"));
}
use of com.braintreepayments.api.internal.BraintreeHttpClient in project braintree_android by braintree.
the class ConfigurationManagerUnitTest method isFetchingConfiguration_isTrueWhenFetchingConfiguration.
@Test
public void isFetchingConfiguration_isTrueWhenFetchingConfiguration() throws InterruptedException {
when(mBraintreeFragment.getHttpClient()).thenReturn(new BraintreeHttpClient(mTokenizationKey) {
@Override
public void get(String path, HttpResponseCallback callback) {
mThreadPool.submit(new Runnable() {
@Override
public void run() {
SystemClock.sleep(1000);
}
});
}
});
ConfigurationManager.getConfiguration(mBraintreeFragment, new ConfigurationListener() {
@Override
public void onConfigurationFetched(Configuration configuration) {
}
}, new BraintreeResponseListener<Exception>() {
@Override
public void onResponse(Exception e) {
}
});
assertTrue(ConfigurationManager.isFetchingConfiguration());
}
use of com.braintreepayments.api.internal.BraintreeHttpClient in project braintree_android by braintree.
the class ConfigurationManagerUnitTest method setup.
@Before
public void setup() throws InvalidArgumentException {
clearSharedPreferences(RuntimeEnvironment.application);
ConfigurationManager.sFetchingConfiguration = false;
mTokenizationKey = Authorization.fromString(TestTokenizationKey.TOKENIZATION_KEY);
mCountDownLatch = new CountDownLatch(1);
mBraintreeFragment = mock(BraintreeFragment.class);
when(mBraintreeFragment.getAuthorization()).thenReturn(mTokenizationKey);
when(mBraintreeFragment.getApplicationContext()).thenReturn(RuntimeEnvironment.application);
when(mBraintreeFragment.getHttpClient()).thenReturn(new BraintreeHttpClient(mTokenizationKey));
}
use of com.braintreepayments.api.internal.BraintreeHttpClient in project braintree_android by braintree.
the class ConfigurationManagerUnitTest method stubConfigurationFromGateway.
private void stubConfigurationFromGateway(final String responseString) {
BraintreeHttpClient fakeClient = new BraintreeHttpClient(mBraintreeFragment.getAuthorization()) {
@Override
public void get(String path, HttpResponseCallback callback) {
if (path.contains(mBraintreeFragment.getAuthorization().getConfigUrl())) {
callback.success(responseString);
}
}
};
when(mBraintreeFragment.getHttpClient()).thenReturn(fakeClient);
}
Aggregations