use of com.paypal.android.sdk.onetouch.core.exception.ResponseParsingException in project braintree_android by braintree.
the class AuthorizationRequestUnitTest method parseBrowserSwitchResponse_returnsErrorForInvalidMsgGUID.
@Test
public void parseBrowserSwitchResponse_returnsErrorForInvalidMsgGUID() {
Uri uri = Uri.parse("com.braintreepayments.demo.braintree://onetouch/v1/success?payload=eyJtc2dfR1VJRCI6Im1zZ19HVUlEIn0=&payloadEnc=encrypteddata");
when(mContextInspector.getStringPreference("com.paypal.otc.msg_guid")).thenReturn("original-msg-guid");
when(mContextInspector.getStringPreference("com.paypal.otc.key")).thenReturn("key");
Result result = mRequest.parseBrowserResponse(mContextInspector, uri);
assertEquals(ResultType.Error, result.getResultType());
assertEquals("Response invalid", result.getError().getMessage());
assertTrue(result.getError() instanceof ResponseParsingException);
}
use of com.paypal.android.sdk.onetouch.core.exception.ResponseParsingException in project braintree_android by braintree.
the class AuthorizationRequestUnitTest method parseBrowserSwitchResponse_parsesSuccessResponsesAndReturnsErrorWhenInvalidPayloadEncIsReturned.
@Test
public void parseBrowserSwitchResponse_parsesSuccessResponsesAndReturnsErrorWhenInvalidPayloadEncIsReturned() throws NoSuchFieldException, IllegalAccessException {
setField("mMsgGuid", mRequest, "19342c28-c6d3-4948-a989-8ee1d40dae5c");
Uri uri = Uri.parse("com.braintreepayments.demo.braintree://onetouch/v1/success?payloadEnc=9kuRy&payload=eyJ2ZXJzaW9uIjozLCJtc2dfR1VJRCI6IjE5MzQyYzI4LWM2ZDMtNDk0OC1hOTg5LThlZTFkNDBkYWU1YyIsInJlc3BvbnNlX3R5cGUiOiJjb2RlIiwiZW52aXJvbm1lbnQiOiJtb2NrIiwiZXJyb3IiOm51bGx9");
Result result = mRequest.parseBrowserResponse(mContextInspector, uri);
assertEquals(ResultType.Error, result.getResultType());
assertTrue(result.getError() instanceof ResponseParsingException);
assertEquals("java.lang.IllegalArgumentException: bad base-64", result.getError().getMessage());
}
use of com.paypal.android.sdk.onetouch.core.exception.ResponseParsingException 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.ResponseParsingException 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));
}
}
}
use of com.paypal.android.sdk.onetouch.core.exception.ResponseParsingException in project braintree_android by braintree.
the class AuthorizationRequestUnitTest method parseBrowserSwitchResponse_returnsErrorForMissingMsgGUIDInPayload.
@Test
public void parseBrowserSwitchResponse_returnsErrorForMissingMsgGUIDInPayload() {
Uri uri = Uri.parse("com.braintreepayments.demo.braintree://onetouch/v1/success?payload=eyJ0ZXN0IjoidGVzdCJ9");
Result result = mRequest.parseBrowserResponse(mContextInspector, uri);
assertEquals(ResultType.Error, result.getResultType());
assertTrue(result.getError() instanceof ResponseParsingException);
assertEquals("Response incomplete", result.getError().getMessage());
}
Aggregations