use of com.braintreepayments.api.interfaces.HttpResponseCallback in project braintree_android by braintree.
the class PaymentMethod method getPaymentMethodNonces.
/**
* Retrieves the current list of {@link PaymentMethodNonce}s for the current customer.
* <p/>
* When finished, the {@link java.util.List} of {@link PaymentMethodNonce}s will be sent to {@link
* PaymentMethodNoncesUpdatedListener#onPaymentMethodNoncesUpdated(List)}.
*
* @param fragment {@link BraintreeFragment}
* @param defaultFirst when {@code true} the customer's default payment method will be first in the list, otherwise
* payment methods will be ordered my most recently used.
*/
public static void getPaymentMethodNonces(final BraintreeFragment fragment, boolean defaultFirst) {
final Uri uri = Uri.parse(TokenizationClient.versionedPath(TokenizationClient.PAYMENT_METHOD_ENDPOINT)).buildUpon().appendQueryParameter("default_first", String.valueOf(defaultFirst)).appendQueryParameter("session_id", fragment.getSessionId()).build();
fragment.waitForConfiguration(new ConfigurationListener() {
@Override
public void onConfigurationFetched(Configuration configuration) {
fragment.getHttpClient().get(uri.toString(), new HttpResponseCallback() {
@Override
public void success(String responseBody) {
try {
fragment.postCallback(PaymentMethodNonce.parsePaymentMethodNonces(responseBody));
fragment.sendAnalyticsEvent("get-payment-methods.succeeded");
} catch (JSONException e) {
fragment.postCallback(e);
fragment.sendAnalyticsEvent("get-payment-methods.failed");
}
}
@Override
public void failure(Exception exception) {
fragment.postCallback(exception);
fragment.sendAnalyticsEvent("get-payment-methods.failed");
}
});
}
});
}
use of com.braintreepayments.api.interfaces.HttpResponseCallback 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.interfaces.HttpResponseCallback 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);
}
}
});
}
use of com.braintreepayments.api.interfaces.HttpResponseCallback in project braintree_android by braintree.
the class AnalyticsSender method send.
public static void send(Context context, Authorization authorization, BraintreeHttpClient httpClient, String analyticsUrl, boolean synchronous) {
final AnalyticsDatabase db = AnalyticsDatabase.getInstance(context);
List<List<AnalyticsEvent>> events = db.getPendingRequests();
try {
JSONObject analyticsRequest;
for (final List<AnalyticsEvent> innerEvents : events) {
analyticsRequest = serializeEvents(context, authorization, innerEvents);
try {
if (synchronous) {
httpClient.post(analyticsUrl, analyticsRequest.toString());
db.removeEvents(innerEvents);
} else {
httpClient.post(analyticsUrl, analyticsRequest.toString(), new HttpResponseCallback() {
@Override
public void success(String responseBody) {
db.removeEvents(innerEvents);
}
@Override
public void failure(Exception exception) {
}
});
}
} catch (Exception ignored) {
}
}
} catch (JSONException ignored) {
}
}
Aggregations