use of com.braintreepayments.api.models.UnionPayConfiguration 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