use of com.braintreepayments.api.models.UnionPayCapabilities in project braintree_android by braintree.
the class UnionPayUnitTest method fetchCapabilities_callsListenerWithCapabilitiesOnSuccess.
@Test
public void fetchCapabilities_callsListenerWithCapabilitiesOnSuccess() throws JSONException {
BraintreeFragment fragment = new MockFragmentBuilder().configuration(mConfigurationWithUnionPay).successResponse(stringFromFixture("unionpay_capabilities_success_response.json")).build();
UnionPay.fetchCapabilities(fragment, UNIONPAY_CREDIT);
ArgumentCaptor<UnionPayCapabilities> argumentCaptor = ArgumentCaptor.forClass(UnionPayCapabilities.class);
verify(fragment).postCallback(argumentCaptor.capture());
UnionPayCapabilities capabilities = argumentCaptor.getValue();
assertNotNull(capabilities);
assertTrue(capabilities.isUnionPay());
assertFalse(capabilities.isDebit());
assertTrue(capabilities.supportsTwoStepAuthAndCapture());
assertTrue(capabilities.isSupported());
}
use of com.braintreepayments.api.models.UnionPayCapabilities in project braintree_android by braintree.
the class BraintreeFragmentUnitTest method addAndRemoveListenersAddAndRemoveAllListeners.
@Test
public void addAndRemoveListenersAddAndRemoveAllListeners() throws InvalidArgumentException {
BraintreeFragment fragment = BraintreeFragment.newInstance(mActivity, TOKENIZATION_KEY);
ConfigurationListener configurationListener = new ConfigurationListener() {
@Override
public void onConfigurationFetched(Configuration configuration) {
}
};
BraintreeErrorListener braintreeErrorListener = new BraintreeErrorListener() {
@Override
public void onError(Exception error) {
}
};
PaymentMethodNoncesUpdatedListener paymentMethodNoncesUpdatedListener = new PaymentMethodNoncesUpdatedListener() {
@Override
public void onPaymentMethodNoncesUpdated(List<PaymentMethodNonce> paymentMethodNonces) {
}
};
PaymentMethodNonceCreatedListener paymentMethodNonceCreatedListener = new PaymentMethodNonceCreatedListener() {
@Override
public void onPaymentMethodNonceCreated(PaymentMethodNonce paymentMethodNonce) {
}
};
BraintreeCancelListener braintreeCancelListener = new BraintreeCancelListener() {
@Override
public void onCancel(int requestCode) {
}
};
UnionPayListener unionPayListener = new UnionPayListener() {
@Override
public void onCapabilitiesFetched(UnionPayCapabilities capabilities) {
}
@Override
public void onSmsCodeSent(String enrollmentId, boolean smsCodeRequired) {
}
};
AmericanExpressListener americanExpressListener = new AmericanExpressListener() {
@Override
public void onRewardsBalanceFetched(AmericanExpressRewardsBalance rewardsBalance) {
}
};
BraintreePaymentResultListener braintreePaymentResultListener = new BraintreePaymentResultListener() {
@Override
public void onBraintreePaymentResult(BraintreePaymentResult result) {
}
};
fragment.addListener(configurationListener);
fragment.addListener(braintreeErrorListener);
fragment.addListener(paymentMethodNoncesUpdatedListener);
fragment.addListener(paymentMethodNonceCreatedListener);
fragment.addListener(braintreeCancelListener);
fragment.addListener(unionPayListener);
fragment.addListener(americanExpressListener);
fragment.addListener(braintreePaymentResultListener);
assertEquals(8, fragment.getListeners().size());
fragment.removeListener(configurationListener);
fragment.removeListener(braintreeErrorListener);
fragment.removeListener(paymentMethodNoncesUpdatedListener);
fragment.removeListener(paymentMethodNonceCreatedListener);
fragment.removeListener(braintreeCancelListener);
fragment.removeListener(unionPayListener);
fragment.removeListener(americanExpressListener);
fragment.removeListener(braintreePaymentResultListener);
assertEquals(0, fragment.getListeners().size());
}
use of com.braintreepayments.api.models.UnionPayCapabilities 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.UnionPayCapabilities in project braintree_android by braintree.
the class UnionPayTest method assertSupported.
private void assertSupported(final String cardNumber, final boolean expected) throws InterruptedException {
final CountDownLatch countDownLatch = new CountDownLatch(1);
mBraintreeFragment.addListener(new UnionPayListener() {
@Override
public void onCapabilitiesFetched(UnionPayCapabilities capabilities) {
boolean actual = capabilities.isSupported();
String message = String.format("Expected %s to be supported? %b, but was %b", cardNumber, expected, actual);
assertEquals(message, expected, actual);
countDownLatch.countDown();
}
@Override
public void onSmsCodeSent(String enrollmentId, boolean smsCodeRequired) {
fail("Not expecting onSmsCodeSent");
}
});
UnionPay.fetchCapabilities(mBraintreeFragment, cardNumber);
countDownLatch.await();
}
use of com.braintreepayments.api.models.UnionPayCapabilities 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();
}
Aggregations