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());
}
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"));
}
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));
}
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");
}
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"));
}
Aggregations