private static ConfigurationException checkIdealEnabled(Configuration configuration) { if (!configuration.getBraintreeApiConfiguration().isEnabled()) { return new ConfigurationException("Your access is restricted and cannot use this part of the Braintree API."); } else if (!configuration.getIdealConfiguration().isEnabled()) { return new ConfigurationException("iDEAL is not enabled for this merchant."); } return null; }
@Test public void fetchCapabilities_failsIfUnionPayIsDisabled() throws JSONException { BraintreeFragment fragment = new MockFragmentBuilder() .configuration(Configuration.fromJson(stringFromFixture("configuration/configuration.json"))) .build(); UnionPay.fetchCapabilities(fragment, UNIONPAY_CREDIT); ArgumentCaptor<ConfigurationException> argumentCaptor = ArgumentCaptor.forClass(ConfigurationException.class); verify(fragment).postCallback(argumentCaptor.capture()); assertEquals("UnionPay is not enabled", argumentCaptor.getValue().getMessage()); }
@Test public void enroll_failsIfUnionPayIsDisabled() throws JSONException { UnionPayCardBuilder unionPayCardBuilder = new UnionPayCardBuilder() .cardNumber("some-card-number"); BraintreeFragment fragment = new MockFragmentBuilder() .configuration(Configuration.fromJson(stringFromFixture("configuration/configuration.json"))) .build(); UnionPay.enroll(fragment, unionPayCardBuilder); ArgumentCaptor<ConfigurationException> argumentCaptor = ArgumentCaptor.forClass(ConfigurationException.class); verify(fragment).postCallback(argumentCaptor.capture()); assertEquals("UnionPay is not enabled", argumentCaptor.getValue().getMessage()); }
@Override public void onResponse(final Exception e) { final ConfigurationException exception = new ConfigurationException("Request for configuration has failed: " + e.getMessage() + ". " + "Future requests will retry up to 3 times", e); postCallback(exception); postOrQueueCallback(new QueuedCallback() { @Override public boolean shouldRun() { return mConfigurationErrorListener != null; } @Override public void run() { mConfigurationErrorListener.onResponse(exception); } }); flushCallbacks(); } });
@Override public void onConfigurationFetched(Configuration configuration) { if (!configuration.getUnionPay().isEnabled()) { fragment.postCallback(new ConfigurationException("UnionPay is not enabled")); return; } String fetchCapabilitiesUrl = Uri.parse(UNIONPAY_CAPABILITIES_PATH) .buildUpon() .appendQueryParameter("creditCard[number]", cardNumber) .build() .toString(); fragment.getHttpClient().get(fetchCapabilitiesUrl, new HttpResponseCallback() { @Override public void success(String responseBody) { fragment.postCallback(UnionPayCapabilities.fromJson(responseBody)); fragment.sendAnalyticsEvent("union-pay.capabilities-received"); } @Override public void failure(Exception exception) { fragment.postCallback(exception); fragment.sendAnalyticsEvent("union-pay.capabilities-failed"); } }); } });
postCallback(new ConfigurationException("Configuration retry limit has been exceeded. Create a new " + "BraintreeFragment and try again.")); return; public void onResponse(final Exception e) { final ConfigurationException exception = new ConfigurationException("Request for configuration has failed: " + e.getMessage() + ". " + "Future requests will retry up to 3 times", e); postCallback(exception);
UnionPayConfiguration unionPayConfiguration = configuration.getUnionPay(); if (!unionPayConfiguration.isEnabled()) { fragment.postCallback(new ConfigurationException("UnionPay is not enabled")); return;
@Override public void onConfigurationFetched(Configuration configuration) { if (!configuration.getPayPal().isEnabled()) { fragment.postCallback(new ConfigurationException("Local payments are not enabled for this merchant.")); return;