use of com.braintreepayments.api.models.UnionPayCardBuilder in project braintree_android by braintree.
the class UnionPayUnitTest method enroll_sendsAnalyticsEventOnSuccess.
@Test
public void enroll_sendsAnalyticsEventOnSuccess() throws JSONException {
UnionPayCardBuilder unionPayCardBuilder = new UnionPayCardBuilder().cardNumber("some-card-number");
JSONObject successObject = new JSONObject().put("unionPayEnrollmentId", "unionPayEnrollmentId").put("smsCodeRequired", true);
BraintreeFragment braintreeFragment = new MockFragmentBuilder().configuration(mConfigurationWithUnionPay).successResponse(successObject.toString()).build();
UnionPay.enroll(braintreeFragment, unionPayCardBuilder);
verify(braintreeFragment).sendAnalyticsEvent("union-pay.enrollment-succeeded");
}
use of com.braintreepayments.api.models.UnionPayCardBuilder in project braintree_android by braintree.
the class UnionPayTest method enroll_whenIsUnionPay_returnsEnrollmentId.
@Test(timeout = 10000)
public void enroll_whenIsUnionPay_returnsEnrollmentId() throws InterruptedException {
String cardNumber = UNIONPAY_CREDIT;
final UnionPayCardBuilder unionPayCardBuilder = new UnionPayCardBuilder().cardNumber(cardNumber).expirationMonth("12").expirationYear("2019").mobileCountryCode("62").mobilePhoneNumber("11111111111");
mBraintreeFragment.addListener(new UnionPayListener() {
@Override
public void onCapabilitiesFetched(UnionPayCapabilities unionPayCapabilities) {
assertTrue(unionPayCapabilities.isUnionPay());
UnionPay.enroll(mBraintreeFragment, unionPayCardBuilder);
}
@Override
public void onSmsCodeSent(String enrollmentId, boolean smsCodeRequired) {
assertFalse(TextUtils.isEmpty(enrollmentId));
assertTrue(smsCodeRequired);
mCountDownLatch.countDown();
}
});
UnionPay.fetchCapabilities(mBraintreeFragment, cardNumber);
mCountDownLatch.await();
}
use of com.braintreepayments.api.models.UnionPayCardBuilder in project braintree_android by braintree.
the class UnionPayTest method enroll_whenSmsCodeRequiredFalse_onSmsCodeSentReturnsFalse.
@Test(timeout = 10000)
public void enroll_whenSmsCodeRequiredFalse_onSmsCodeSentReturnsFalse() throws InterruptedException {
mCountDownLatch = new CountDownLatch(2);
String cardNumber = UNIONPAY_SMS_NOT_REQUIRED;
final UnionPayCardBuilder unionPayCardBuilder = new UnionPayCardBuilder().cardNumber(cardNumber).expirationMonth("12").expirationYear("2019").mobileCountryCode("62").mobilePhoneNumber("11111111111");
mBraintreeFragment.addListener(new UnionPayListener() {
@Override
public void onCapabilitiesFetched(UnionPayCapabilities capabilities) {
assertTrue(capabilities.isUnionPay());
assertTrue(capabilities.isSupported());
UnionPay.enroll(mBraintreeFragment, unionPayCardBuilder);
mCountDownLatch.countDown();
}
@Override
public void onSmsCodeSent(String enrollmentId, boolean smsCodeRequired) {
assertNotNull(enrollmentId);
assertFalse(smsCodeRequired);
mCountDownLatch.countDown();
}
});
mBraintreeFragment.addListener(new BraintreeErrorListener() {
@Override
public void onError(Exception error) {
fail("Not expecting error");
}
});
UnionPay.fetchCapabilities(mBraintreeFragment, cardNumber);
mCountDownLatch.await();
}
use of com.braintreepayments.api.models.UnionPayCardBuilder in project braintree_android by braintree.
the class UnionPayTest method enroll_whenIsUnionPayFalse_willError.
@Test(timeout = 10000)
public void enroll_whenIsUnionPayFalse_willError() throws InterruptedException {
String cardNumber = CardNumber.VISA;
final UnionPayCardBuilder unionPayCardBuilder = new UnionPayCardBuilder().cardNumber(cardNumber).expirationMonth("12").expirationYear("2019").mobileCountryCode("62").mobilePhoneNumber("11111111111");
mBraintreeFragment.addListener(new UnionPayListener() {
@Override
public void onCapabilitiesFetched(UnionPayCapabilities capabilities) {
assertFalse(capabilities.isUnionPay());
UnionPay.enroll(mBraintreeFragment, unionPayCardBuilder);
}
@Override
public void onSmsCodeSent(String enrollmentId, boolean smsCodeRequired) {
fail("Not expecting onSmsCodeSent");
}
});
mBraintreeFragment.addListener(new BraintreeErrorListener() {
@Override
public void onError(Exception error) {
assertTrue(error instanceof ErrorWithResponse);
assertEquals("UnionPay Enrollment is invalid", error.getMessage());
mCountDownLatch.countDown();
}
});
UnionPay.fetchCapabilities(mBraintreeFragment, cardNumber);
mCountDownLatch.await();
}
use of com.braintreepayments.api.models.UnionPayCardBuilder in project braintree_android by braintree.
the class UnionPayUnitTest method enroll_callsListenerWithUnionPayEnrollmentIdAdded.
@Test
public void enroll_callsListenerWithUnionPayEnrollmentIdAdded() throws JSONException {
String expectedEnrollmentId = "some-enrollment-id";
boolean expectedSmsCodeRequired = true;
JSONObject response = new JSONObject();
response.put("unionPayEnrollmentId", expectedEnrollmentId);
response.put("smsCodeRequired", expectedSmsCodeRequired);
BraintreeFragment fragment = new MockFragmentBuilder().configuration(mConfigurationWithUnionPay).successResponse(response.toString()).build();
UnionPayCardBuilder unionPayCardBuilder = new UnionPayCardBuilder();
UnionPay.enroll(fragment, unionPayCardBuilder);
verify(fragment).postUnionPayCallback(expectedEnrollmentId, expectedSmsCodeRequired);
}
Aggregations