use of com.braintreepayments.api.test.TestClientTokenBuilder in project braintree_android by braintree.
the class ThreeDSecureTest method performVerification_acceptsACardBuilderAndPostsAPaymentMethodNonceToListener.
@Test(timeout = 10000)
public void performVerification_acceptsACardBuilderAndPostsAPaymentMethodNonceToListener() throws InterruptedException {
String clientToken = new TestClientTokenBuilder().withThreeDSecure().build();
BraintreeFragment fragment = getFragmentWithAuthorization(mActivity, clientToken);
fragment.addListener(new PaymentMethodNonceCreatedListener() {
@Override
public void onPaymentMethodNonceCreated(PaymentMethodNonce paymentMethodNonce) {
assertIsANonce(paymentMethodNonce.getNonce());
assertEquals("51", ((CardNonce) paymentMethodNonce).getLastTwo());
assertTrue(((CardNonce) paymentMethodNonce).getThreeDSecureInfo().wasVerified());
mCountDownLatch.countDown();
}
});
CardBuilder cardBuilder = new CardBuilder().cardNumber("4000000000000051").expirationDate("12/20");
ThreeDSecure.performVerification(fragment, cardBuilder, "5");
mCountDownLatch.await();
}
use of com.braintreepayments.api.test.TestClientTokenBuilder in project braintree_android by braintree.
the class ThreeDSecureTest method performVerification_acceptsAThreeDSecureRequest_postsPaymentMethodNonceToListenersWhenLookupReturnsACard.
@Test(timeout = 10000)
public void performVerification_acceptsAThreeDSecureRequest_postsPaymentMethodNonceToListenersWhenLookupReturnsACard() throws InterruptedException, InvalidArgumentException {
String clientToken = new TestClientTokenBuilder().withThreeDSecure().build();
BraintreeFragment fragment = getFragmentWithAuthorization(mActivity, clientToken);
String nonce = tokenize(fragment, new CardBuilder().cardNumber("4000000000000051").expirationDate("12/20")).getNonce();
fragment.addListener(new PaymentMethodNonceCreatedListener() {
@Override
public void onPaymentMethodNonceCreated(PaymentMethodNonce paymentMethodNonce) {
assertIsANonce(paymentMethodNonce.getNonce());
assertEquals("51", ((CardNonce) paymentMethodNonce).getLastTwo());
ThreeDSecureInfo threeDSecureInfo = ((CardNonce) paymentMethodNonce).getThreeDSecureInfo();
assertFalse(threeDSecureInfo.isLiabilityShifted());
assertFalse(threeDSecureInfo.isLiabilityShiftPossible());
assertTrue(((CardNonce) paymentMethodNonce).getThreeDSecureInfo().wasVerified());
mCountDownLatch.countDown();
}
});
ThreeDSecureRequest request = new ThreeDSecureRequest().nonce(nonce).amount("5");
ThreeDSecure.performVerification(fragment, request);
mCountDownLatch.await();
}
use of com.braintreepayments.api.test.TestClientTokenBuilder in project braintree_android by braintree.
the class ThreeDSecureTest method performVerification_withInvalidThreeDSecureRequest_postsException.
@Test(timeout = 1000)
public void performVerification_withInvalidThreeDSecureRequest_postsException() throws InterruptedException, InvalidArgumentException {
String clientToken = new TestClientTokenBuilder().withThreeDSecure().build();
BraintreeFragment fragment = getFragmentWithAuthorization(mActivity, clientToken);
fragment.addListener(new BraintreeErrorListener() {
@Override
public void onError(Exception error) {
assertEquals("The ThreeDSecureRequest nonce and amount cannot be null", error.getMessage());
mCountDownLatch.countDown();
}
});
ThreeDSecureRequest request = new ThreeDSecureRequest().amount("5");
ThreeDSecure.performVerification(fragment, request);
mCountDownLatch.await();
}
use of com.braintreepayments.api.test.TestClientTokenBuilder in project braintree_android by braintree.
the class UnionPayTest method setUp.
@Before
public void setUp() throws InvalidArgumentException {
mCountDownLatch = new CountDownLatch(1);
mBraintreeFragment = getFragmentWithAuthorization(mActivityTestRule.getActivity(), new TestClientTokenBuilder().withUnionPay().build());
}
use of com.braintreepayments.api.test.TestClientTokenBuilder in project braintree_android by braintree.
the class AnalyticsSenderTest method sendsCorrectlyFormattedAnalyticsRequest.
@Test(timeout = 10000)
public void sendsCorrectlyFormattedAnalyticsRequest() throws Exception {
final CountDownLatch latch = new CountDownLatch(1);
String authorization = new TestClientTokenBuilder().withAnalytics().build();
final Configuration configuration = Configuration.fromJson(authorization);
AnalyticsEvent event = new AnalyticsEvent(getTargetContext(), "sessionId", "custom", "event.started");
AnalyticsDatabase.getInstance(getTargetContext()).addEvent(event);
BraintreeHttpClient httpClient = new BraintreeHttpClient(Authorization.fromString(authorization)) {
@Override
protected String parseResponse(HttpURLConnection connection) throws Exception {
if (connection.getURL().toString().equals(configuration.getAnalytics().getUrl())) {
assertEquals(200, connection.getResponseCode());
latch.countDown();
}
return "";
}
};
AnalyticsSender.send(getTargetContext(), Authorization.fromString(authorization), httpClient, configuration.getAnalytics().getUrl(), true);
latch.await();
}
Aggregations