use of com.braintreepayments.api.models.Configuration 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();
}
use of com.braintreepayments.api.models.Configuration in project braintree_android by braintree.
the class AndroidPayTest method getTokenizationParameters_returnsCorrectParametersInCallback.
@Test(timeout = 5000)
public void getTokenizationParameters_returnsCorrectParametersInCallback() throws Exception {
String config = mBaseConfiguration.androidPay(mBaseConfiguration.androidPay().supportedNetworks(new String[] { "visa", "mastercard", "amex", "discover" })).build();
final Configuration configuration = Configuration.fromJson(config);
BraintreeFragment fragment = getFragment(mActivityTestRule.getActivity(), TOKENIZATION_KEY, config);
AndroidPay.getTokenizationParameters(fragment, new TokenizationParametersListener() {
@Override
public void onResult(PaymentMethodTokenizationParameters parameters, Collection<Integer> allowedCardNetworks) {
assertEquals("braintree", parameters.getParameters().getString("gateway"));
assertEquals(configuration.getMerchantId(), parameters.getParameters().getString("braintree:merchantId"));
assertEquals(configuration.getAndroidPay().getGoogleAuthorizationFingerprint(), parameters.getParameters().getString("braintree:authorizationFingerprint"));
assertEquals("v1", parameters.getParameters().getString("braintree:apiVersion"));
assertEquals(BuildConfig.VERSION_NAME, parameters.getParameters().getString("braintree:sdkVersion"));
try {
JSONObject metadata = new JSONObject(parameters.getParameters().getString("braintree:metadata"));
assertNotNull(metadata);
assertEquals(BuildConfig.VERSION_NAME, metadata.getString("version"));
assertNotNull(metadata.getString("sessionId"));
assertEquals("custom", metadata.getString("integration"));
assertEquals("android", metadata.get("platform"));
} catch (JSONException e) {
fail("Failed to unpack json from tokenization parameters: " + e.getMessage());
}
assertEquals(4, allowedCardNetworks.size());
assertTrue(allowedCardNetworks.contains(CardNetwork.VISA));
assertTrue(allowedCardNetworks.contains(CardNetwork.MASTERCARD));
assertTrue(allowedCardNetworks.contains(CardNetwork.AMEX));
assertTrue(allowedCardNetworks.contains(CardNetwork.DISCOVER));
mLatch.countDown();
}
});
mLatch.await();
}
use of com.braintreepayments.api.models.Configuration in project braintree_android by braintree.
the class BraintreeFragmentTest method fetchConfiguration_worksWithAClientToken.
@Test(timeout = 10000)
public void fetchConfiguration_worksWithAClientToken() throws InterruptedException {
final BraintreeFragment fragment = getFragmentWithAuthorization(mActivity, mClientToken);
fragment.waitForConfiguration(new ConfigurationListener() {
@Override
public void onConfigurationFetched(Configuration configuration) {
assertNotNull(configuration);
mCountDownLatch.countDown();
}
});
mCountDownLatch.await();
}
use of com.braintreepayments.api.models.Configuration in project braintree_android by braintree.
the class CardTest method setupBraintreeFragment.
private BraintreeFragment setupBraintreeFragment(String authorization) throws Exception {
final BraintreeFragment fragment = BraintreeFragment.newInstance(mActivityTestRule.getActivity(), authorization);
final CountDownLatch latch = new CountDownLatch(1);
fragment.waitForConfiguration(new ConfigurationListener() {
@Override
public void onConfigurationFetched(Configuration configuration) {
if (mRequestProtocol.equals(REST)) {
try {
JSONObject configJson = new JSONObject(configuration.toJson());
configJson.remove("graphQL");
fragment.setConfiguration(Configuration.fromJson(configJson.toString()));
} catch (JSONException ignored) {
}
assertFalse(fragment.getConfiguration().getGraphQL().isEnabled());
} else if (mRequestProtocol.equals(GRAPHQL)) {
assertTrue(configuration.getGraphQL().isEnabled());
}
latch.countDown();
}
});
latch.await();
return fragment;
}
use of com.braintreepayments.api.models.Configuration in project braintree_android by braintree.
the class GooglePaymentTest method getAllowedCardNetworks_returnsSupportedNetworks.
@Test(timeout = 5000)
public void getAllowedCardNetworks_returnsSupportedNetworks() throws InterruptedException {
String configuration = mBaseConfiguration.androidPay(mBaseConfiguration.androidPay().supportedNetworks(new String[] { "visa", "mastercard", "amex", "discover" })).build();
final BraintreeFragment fragment = getFragmentWithConfiguration(mActivityTestRule.getActivity(), configuration);
fragment.waitForConfiguration(new ConfigurationListener() {
@Override
public void onConfigurationFetched(Configuration configuration) {
Collection<Integer> allowedCardNetworks = GooglePayment.getAllowedCardNetworks(fragment);
assertEquals(4, allowedCardNetworks.size());
assertTrue(allowedCardNetworks.contains(CardNetwork.VISA));
assertTrue(allowedCardNetworks.contains(CardNetwork.MASTERCARD));
assertTrue(allowedCardNetworks.contains(CardNetwork.AMEX));
assertTrue(allowedCardNetworks.contains(CardNetwork.DISCOVER));
mLatch.countDown();
}
});
mLatch.await();
}
Aggregations