use of com.braintreepayments.api.exceptions.ConfigurationException in project braintree_android by braintree.
the class BraintreeFragment method fetchConfiguration.
@VisibleForTesting
protected void fetchConfiguration() {
if (getConfiguration() != null || ConfigurationManager.isFetchingConfiguration() || mAuthorization == null || mHttpClient == null) {
return;
}
if (mConfigurationRequestAttempts >= 3) {
postCallback(new ConfigurationException("Configuration retry limit has been exceeded. Create a new " + "BraintreeFragment and try again."));
return;
}
mConfigurationRequestAttempts++;
ConfigurationManager.getConfiguration(this, new ConfigurationListener() {
@Override
public void onConfigurationFetched(Configuration configuration) {
setConfiguration(configuration);
postConfigurationCallback();
flushCallbacks();
}
}, new BraintreeResponseListener<Exception>() {
@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();
}
});
}
use of com.braintreepayments.api.exceptions.ConfigurationException in project braintree_android by braintree.
the class UnionPayUnitTest method enroll_failsIfUnionPayIsDisabled.
@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());
}
use of com.braintreepayments.api.exceptions.ConfigurationException in project braintree_android by braintree.
the class UnionPay method fetchCapabilities.
/**
* Fetches the capabilities of a card. If the card needs to be enrolled use {@link
* UnionPay#enroll(BraintreeFragment, UnionPayCardBuilder)}.
* <p/>
* On completion, returns the {@link UnionPayCapabilities} to
* {@link com.braintreepayments.api.interfaces.UnionPayListener#onCapabilitiesFetched(UnionPayCapabilities)}
* <p/>
* On error, an exception will be passed back to
* {@link com.braintreepayments.api.interfaces.BraintreeErrorListener#onError(Exception)}
*
* @param fragment {@link BraintreeFragment}
* @param cardNumber The card number to check for Union Pay capabilities.
*/
public static void fetchCapabilities(final BraintreeFragment fragment, final String cardNumber) {
fragment.waitForConfiguration(new ConfigurationListener() {
@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");
}
});
}
});
}
use of com.braintreepayments.api.exceptions.ConfigurationException in project braintree_android by braintree.
the class UnionPay method enroll.
/**
* Enrolls a Union Pay card. Only call this method if the card needs to be enrolled. Check {@link
* UnionPay#fetchCapabilities(BraintreeFragment, String)} if your card needs to be enrolled.
* <p/>
* On completion, returns a enrollmentId to
* {@link com.braintreepayments.api.interfaces.UnionPayListener#onSmsCodeSent(String, boolean)}
* This enrollmentId needs to be applied to {@link UnionPayCardBuilder} along with the SMS code
* collected from the merchant before invoking {@link UnionPay#tokenize(BraintreeFragment, UnionPayCardBuilder)}
* <p/>
* On error, an exception will be passed back to
* {@link com.braintreepayments.api.interfaces.BraintreeErrorListener#onError(Exception)}
*
* @param fragment {@link BraintreeFragment}
* @param unionPayCardBuilder {@link UnionPayCardBuilder}
*/
public static void enroll(final BraintreeFragment fragment, final UnionPayCardBuilder unionPayCardBuilder) {
fragment.waitForConfiguration(new ConfigurationListener() {
@Override
public void onConfigurationFetched(Configuration configuration) {
UnionPayConfiguration unionPayConfiguration = configuration.getUnionPay();
if (!unionPayConfiguration.isEnabled()) {
fragment.postCallback(new ConfigurationException("UnionPay is not enabled"));
return;
}
try {
JSONObject enrollmentPayloadJson = unionPayCardBuilder.buildEnrollment();
fragment.getHttpClient().post(UNIONPAY_ENROLLMENT_PATH, enrollmentPayloadJson.toString(), new HttpResponseCallback() {
@Override
public void success(String responseBody) {
try {
JSONObject response = new JSONObject(responseBody);
String enrollmentId = response.getString(UNIONPAY_ENROLLMENT_ID_KEY);
boolean smsCodeRequired = response.getBoolean(UNIONPAY_SMS_REQUIRED_KEY);
fragment.postUnionPayCallback(enrollmentId, smsCodeRequired);
fragment.sendAnalyticsEvent("union-pay.enrollment-succeeded");
} catch (JSONException e) {
failure(e);
}
}
@Override
public void failure(Exception exception) {
fragment.postCallback(exception);
fragment.sendAnalyticsEvent("union-pay.enrollment-failed");
}
});
} catch (JSONException exception) {
fragment.postCallback(exception);
}
}
});
}
Aggregations