use of com.braintreepayments.api.interfaces.ConfigurationListener 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.interfaces.ConfigurationListener 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();
}
use of com.braintreepayments.api.interfaces.ConfigurationListener in project braintree_android by braintree.
the class GooglePaymentTest method getTokenizationParameters_includesATokenizationKeyWhenPresent.
@Test(timeout = 5000)
public void getTokenizationParameters_includesATokenizationKeyWhenPresent() throws Exception {
final BraintreeFragment fragment = getFragment(mActivityTestRule.getActivity(), TOKENIZATION_KEY, mBaseConfiguration.withAnalytics().build());
fragment.waitForConfiguration(new ConfigurationListener() {
@Override
public void onConfigurationFetched(Configuration configuration) {
Bundle tokenizationParameters = GooglePayment.getTokenizationParameters(fragment).getParameters();
assertEquals(TOKENIZATION_KEY, tokenizationParameters.getString("braintree:clientKey"));
mLatch.countDown();
}
});
mLatch.await();
}
use of com.braintreepayments.api.interfaces.ConfigurationListener in project braintree_android by braintree.
the class Ideal method fetchIssuingBanks.
/**
* Makes a call to fetch the list of potential issuing banks with which a customer can pay.
*
* @param fragment {@link BraintreeFragment}
* @param listener {@link BraintreeResponseListener} the callback to which a list of issuing banks will be provided.
*/
public static void fetchIssuingBanks(final BraintreeFragment fragment, final BraintreeResponseListener<List<IdealBank>> listener) {
fragment.waitForConfiguration(new ConfigurationListener() {
@Override
public void onConfigurationFetched(final Configuration configuration) {
Exception configException = checkIdealEnabled(configuration);
if (configException != null) {
fragment.postCallback(configException);
return;
}
fragment.getBraintreeApiHttpClient().get("/issuers/ideal", new HttpResponseCallback() {
@Override
public void success(String responseBody) {
fragment.sendAnalyticsEvent("ideal.load.succeeded");
try {
List<IdealBank> banks = IdealBank.fromJson(configuration, responseBody);
if (listener != null) {
listener.onResponse(banks);
}
} catch (JSONException jsonException) {
failure(jsonException);
}
}
@Override
public void failure(Exception exception) {
fragment.sendAnalyticsEvent("ideal.load.failed");
fragment.postCallback(exception);
}
});
}
});
}
use of com.braintreepayments.api.interfaces.ConfigurationListener in project braintree_android by braintree.
the class Ideal method startPayment.
/**
* Initiates the payment flow by opening a browser where the customer can authenticate with their bank.
*
* @param fragment {@link BraintreeFragment}
* @param builder {@link IdealRequest} with the payment details.
* @param listener {@link BraintreeResponseListener} the callback to which the {@link IdealResult} will be sent
* with a status of `PENDING` before the flow starts. This result contains the iDEAL payment ID.
*/
public static void startPayment(final BraintreeFragment fragment, final IdealRequest builder, final BraintreeResponseListener<IdealResult> listener) {
fragment.waitForConfiguration(new ConfigurationListener() {
@Override
public void onConfigurationFetched(Configuration configuration) {
fragment.sendAnalyticsEvent("ideal.start-payment.selected");
Exception configException = checkIdealEnabled(configuration);
if (configException != null) {
fragment.postCallback(configException);
fragment.sendAnalyticsEvent("ideal.start-payment.invalid-configuration");
return;
}
String redirectUrl = URI.create(configuration.getIdealConfiguration().getAssetsUrl() + ASSET_SERVER_REDIRECT_PATH + fragment.getReturnUrlScheme() + "://").toString();
fragment.getBraintreeApiHttpClient().post("/ideal-payments", builder.build(redirectUrl, configuration.getIdealConfiguration().getRouteId()), new HttpResponseCallback() {
@Override
public void success(String responseBody) {
try {
IdealResult idealResult = IdealResult.fromJson(responseBody);
BraintreeSharedPreferences.putString(fragment.getApplicationContext(), IDEAL_RESULT_ID, idealResult.getId());
if (listener != null) {
listener.onResponse(idealResult);
}
JSONObject responseJson = new JSONObject(responseBody);
String approvalUrl = responseJson.getJSONObject("data").getString("approval_url");
fragment.browserSwitch(BraintreeRequestCodes.IDEAL, approvalUrl);
fragment.sendAnalyticsEvent("ideal.webswitch.initiate.succeeded");
} catch (JSONException jsonException) {
failure(jsonException);
}
}
@Override
public void failure(Exception exception) {
fragment.sendAnalyticsEvent("ideal.webswitch.initiate.failed");
fragment.postCallback(exception);
}
});
}
});
}
Aggregations