Search in sources :

Example 1 with ResponseType

use of com.paypal.android.sdk.onetouch.core.enums.ResponseType in project braintree_android by braintree.

the class AppSwitchHelper method processResponseIntent.

private static Result processResponseIntent(Bundle bundle) {
    String error = bundle.getString("error");
    if (!TextUtils.isEmpty(error)) {
        return new Result(new WalletSwitchException(error));
    } else {
        String environment = bundle.getString("environment");
        String bundleResponseType = bundle.getString("response_type").toLowerCase(Locale.US);
        ResponseType response_type;
        if ("code".equals(bundleResponseType)) {
            response_type = ResponseType.authorization_code;
        } else {
            response_type = ResponseType.web;
        }
        try {
            if (ResponseType.web == response_type) {
                String webURL = bundle.getString("webURL");
                return new Result(environment, response_type, new JSONObject().put("webURL", webURL), // email not sent back in checkout requests since Hermes doesn't return that info
                null);
            } else {
                String authorization_code = bundle.getString("authorization_code");
                String email = bundle.getString("email");
                return new Result(environment, response_type, new JSONObject().put("code", authorization_code), email);
            }
        } catch (JSONException e) {
            return new Result(new ResponseParsingException(e));
        }
    }
}
Also used : JSONObject(org.json.JSONObject) ResponseParsingException(com.paypal.android.sdk.onetouch.core.exception.ResponseParsingException) JSONException(org.json.JSONException) WalletSwitchException(com.paypal.android.sdk.onetouch.core.exception.WalletSwitchException) Result(com.paypal.android.sdk.onetouch.core.Result) ResponseType(com.paypal.android.sdk.onetouch.core.enums.ResponseType)

Aggregations

Result (com.paypal.android.sdk.onetouch.core.Result)1 ResponseType (com.paypal.android.sdk.onetouch.core.enums.ResponseType)1 ResponseParsingException (com.paypal.android.sdk.onetouch.core.exception.ResponseParsingException)1 WalletSwitchException (com.paypal.android.sdk.onetouch.core.exception.WalletSwitchException)1 JSONException (org.json.JSONException)1 JSONObject (org.json.JSONObject)1