use of com.braintreepayments.api.exceptions.BrowserSwitchException in project braintree_android by braintree.
the class PayPal method onActivityResult.
/**
* The result from PayPal's request.
*
* @param fragment A {@link BraintreeFragment} used to process the request.
* @param data Data associated with the result.
*/
protected static void onActivityResult(final BraintreeFragment fragment, int resultCode, Intent data) {
Request request = getPersistedRequest(fragment.getApplicationContext());
if (resultCode == Activity.RESULT_OK && data != null && request != null) {
boolean isAppSwitch = isAppSwitch(data);
Result result = PayPalOneTouchCore.parseResponse(fragment.getApplicationContext(), request, data);
switch(result.getResultType()) {
case Error:
fragment.postCallback(new BrowserSwitchException(result.getError().getMessage()));
sendAnalyticsEventForSwitchResult(fragment, request, isAppSwitch, "failed");
break;
case Cancel:
sendAnalyticsEventForSwitchResult(fragment, request, isAppSwitch, "canceled");
fragment.postCancelCallback(BraintreeRequestCodes.PAYPAL);
break;
case Success:
onSuccess(fragment, data, request, result);
sendAnalyticsEventForSwitchResult(fragment, request, isAppSwitch, "succeeded");
break;
}
} else {
String type;
if (request != null) {
type = request.getClass().getSimpleName().toLowerCase();
} else {
type = "unknown";
}
fragment.sendAnalyticsEvent("paypal." + type + ".canceled");
if (resultCode != Activity.RESULT_CANCELED) {
fragment.postCancelCallback(BraintreeRequestCodes.PAYPAL);
}
}
}
Aggregations