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