use of com.paypal.android.sdk.onetouch.core.exception.BrowserSwitchException in project braintree_android by braintree.
the class AuthorizationRequestUnitTest method parseBrowserSwitchResponse_parsesSuccessResponseAndReturnsErrorWhenErrorIsPresent.
@Test
public void parseBrowserSwitchResponse_parsesSuccessResponseAndReturnsErrorWhenErrorIsPresent() throws NoSuchFieldException, IllegalAccessException {
setField("mMsgGuid", mRequest, "19342c28-c6d3-4948-a989-8ee1d40dae5c");
setField("mEncryptionKey", mRequest, EncryptionUtils.hexStringToByteArray("96BF26A3851D0127AF474CC556D9C296A9A02171CD319EE5249C4B3033FC7BB6"));
Uri uri = Uri.parse("com.braintreepayments.demo.braintree://onetouch/v1/success?payloadEnc=9kuRyRmR8PpMoc3umclWyuGeibf4%2FIWdDyF9ehFL0TWI33GJ83iAHC7NdZszNRXrsa5uvO20N6BpGCKm3M%2F%2FjXzI5XrkxHhpKnH4j96mLNlTjDI2012cUZ7hotqm8rahnFkobykEwfI6OTGu3Zk%2Bc6FQ4Vi44nEeIw7Ocs%2Fiw%2BwzXGaZz3LgJajediKcwL%2BrDJIRgoZTnjzT2aM2No7wvORpAk%2FBRmAp1QxZkzTor0zcYgPEia%2B%2FivuEDRFKDUIC%2BC4GRulZB70Bzo7FBSvSOyy1rldRjaLg9W8bhBd8WOXjyg%2F0gLryjIqppmA%2FWFwUH7nBrbqpOyCyp5hskE5NZSNFZEokUEh4oOHI%2BMQshZETuivdWEjNrvbWq8bp2JHv5fnM9NjqmHY%2Bu23sEHQoJQ%3D%3D&payload=eyJ2ZXJzaW9uIjozLCJtc2dfR1VJRCI6IjE5MzQyYzI4LWM2ZDMtNDk0OC1hOTg5LThlZTFkNDBkYWU1YyIsImVycm9yIjoiVGhlcmUgd2FzIGFuIGVycm9yIn0=");
Result result = mRequest.parseBrowserResponse(mContextInspector, uri);
assertEquals(ResultType.Error, result.getResultType());
assertTrue(result.getError() instanceof BrowserSwitchException);
assertEquals("There was an error", result.getError().getMessage());
}
use of com.paypal.android.sdk.onetouch.core.exception.BrowserSwitchException in project braintree_android by braintree.
the class AuthorizationRequest method parseBrowserResponse.
@Override
public Result parseBrowserResponse(ContextInspector contextInspector, Uri uri) {
String status = uri.getLastPathSegment();
String payloadEnc = uri.getQueryParameter("payloadEnc");
JSONObject payload;
try {
payload = new JSONObject(new String(Base64.decode(uri.getQueryParameter("payload"), Base64.DEFAULT)));
} catch (NullPointerException | IllegalArgumentException | JSONException e) {
payload = new JSONObject();
}
if (Uri.parse(getSuccessUrl()).getLastPathSegment().equals(status)) {
if (!payload.has("msg_GUID")) {
return new Result(new ResponseParsingException("Response incomplete"));
}
if (TextUtils.isEmpty(payloadEnc) || !isValidResponse(Json.optString(payload, "msg_GUID", ""))) {
return new Result(new ResponseParsingException("Response invalid"));
}
try {
JSONObject decryptedPayloadEnc = getDecryptedPayload(payloadEnc);
String error = Json.optString(payload, "error", "");
// the string 'null' is coming back in production
if (!TextUtils.isEmpty(error) && !"null".equals(error)) {
return new Result(new BrowserSwitchException(error));
}
return new Result(Json.optString(payload, "environment", ""), ResponseType.authorization_code, new JSONObject().put("code", decryptedPayloadEnc.getString("payment_code")), decryptedPayloadEnc.getString("email"));
} catch (JSONException | InvalidAlgorithmParameterException | NoSuchAlgorithmException | IllegalBlockSizeException | BadPaddingException | NoSuchPaddingException | InvalidKeyException | InvalidEncryptionDataException | IllegalArgumentException e) {
return new Result(new ResponseParsingException(e));
}
} else if (Uri.parse(getCancelUrl()).getLastPathSegment().equals(status)) {
String error = Json.optString(payload, "error", "");
// the string 'null' is coming back in production
if (!TextUtils.isEmpty(error) && !"null".equals(error)) {
return new Result(new BrowserSwitchException(error));
} else {
return new Result();
}
} else {
return new Result(new ResponseParsingException("Response uri invalid"));
}
}
use of com.paypal.android.sdk.onetouch.core.exception.BrowserSwitchException in project braintree_android by braintree.
the class AuthorizationRequestUnitTest method parseBrowserResponse_parsesErrorsFromCancelResponses.
@Test
public void parseBrowserResponse_parsesErrorsFromCancelResponses() throws JSONException {
Uri uri = Uri.parse("com.braintreepayments.demo.braintree://onetouch/v1/cancel?payload=eyJ2ZXJzaW9uIjozLCJtc2dfR1VJRCI6bnVsbCwicmVzcG9uc2VfdHlwZSI6bnVsbCwiZW52aXJvbm1lbnQiOiJtb2NrIiwiZXJyb3IiOnsiZGVidWdfaWQiOm51bGwsIm1lc3NhZ2UiOiJFbmNyeXB0ZWQgcGF5bG9hZCBoYXMgZXhwaXJlZCJ9LCJsYW5ndWFnZSI6bnVsbH0=");
Result result = mRequest.parseBrowserResponse(mContextInspector, uri);
assertEquals(ResultType.Error, result.getResultType());
assertTrue(result.getError() instanceof BrowserSwitchException);
JSONAssert.assertEquals("{\"debug_id\":null,\"message\":\"Encrypted payload has expired\"}", result.getError().getMessage(), JSONCompareMode.NON_EXTENSIBLE);
}
use of com.paypal.android.sdk.onetouch.core.exception.BrowserSwitchException in project braintree_android by braintree.
the class CheckoutRequest method parseBrowserResponse.
@Override
public Result parseBrowserResponse(ContextInspector contextInspector, Uri uri) {
String status = uri.getLastPathSegment();
if (!Uri.parse(getSuccessUrl()).getLastPathSegment().equals(status)) {
// return cancel result
return new Result();
}
String requestXoToken = Uri.parse(mApprovalUrl).getQueryParameter(mTokenQueryParamKey);
String responseXoToken = uri.getQueryParameter(mTokenQueryParamKey);
if (responseXoToken != null && TextUtils.equals(requestXoToken, responseXoToken)) {
try {
JSONObject response = new JSONObject();
response.put("webURL", uri.toString());
return new Result(null, /*don't know the environment here*/
ResponseType.web, response, null);
} catch (JSONException e) {
return new Result(new ResponseParsingException(e));
}
} else {
return new Result(new BrowserSwitchException("The response contained inconsistent data."));
}
}
Aggregations