Search in sources :

Example 11 with ResponseParsingException

use of com.paypal.android.sdk.onetouch.core.exception.ResponseParsingException in project braintree_android by braintree.

the class AuthorizationRequestUnitTest method parseBrowserSwitchResponse_returnsErrorForMissingPayloadInSuccessResponse.

@Test
public void parseBrowserSwitchResponse_returnsErrorForMissingPayloadInSuccessResponse() {
    Uri uri = Uri.parse("com.braintreepayments.demo.braintree://onetouch/v1/success");
    Result result = mRequest.parseBrowserResponse(mContextInspector, uri);
    assertEquals(ResultType.Error, result.getResultType());
    assertTrue(result.getError() instanceof ResponseParsingException);
    assertEquals("Response incomplete", result.getError().getMessage());
}
Also used : ResponseParsingException(com.paypal.android.sdk.onetouch.core.exception.ResponseParsingException) Uri(android.net.Uri) Test(org.junit.Test)

Example 12 with ResponseParsingException

use of com.paypal.android.sdk.onetouch.core.exception.ResponseParsingException in project braintree_android by braintree.

the class AuthorizationRequestUnitTest method parseBrowserResponse_returnsErrorForUnrecongnizedUri.

@Test
public void parseBrowserResponse_returnsErrorForUnrecongnizedUri() {
    Uri uri = Uri.parse("com.braintreepayments.demo.braintree://onetouch/v1/abort?payload=eyJ0ZXN0IjoidGVzdCJ9");
    Result result = mRequest.parseBrowserResponse(mContextInspector, uri);
    assertEquals(ResultType.Error, result.getResultType());
    assertTrue(result.getError() instanceof ResponseParsingException);
    assertEquals("Response uri invalid", result.getError().getMessage());
}
Also used : ResponseParsingException(com.paypal.android.sdk.onetouch.core.exception.ResponseParsingException) Uri(android.net.Uri) Test(org.junit.Test)

Example 13 with ResponseParsingException

use of com.paypal.android.sdk.onetouch.core.exception.ResponseParsingException 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."));
    }
}
Also used : JSONObject(org.json.JSONObject) ResponseParsingException(com.paypal.android.sdk.onetouch.core.exception.ResponseParsingException) JSONException(org.json.JSONException) BrowserSwitchException(com.paypal.android.sdk.onetouch.core.exception.BrowserSwitchException)

Example 14 with ResponseParsingException

use of com.paypal.android.sdk.onetouch.core.exception.ResponseParsingException in project braintree_android by braintree.

the class AppSwitchHelperUnitTest method parseAppSwitchResponse_returnsErrorWhenResponseCouldNotBeParsed.

@Test
public void parseAppSwitchResponse_returnsErrorWhenResponseCouldNotBeParsed() {
    Request request = mock(AuthorizationRequest.class);
    when(request.validateV1V2Response(any(ContextInspector.class), any(Bundle.class))).thenReturn(false);
    Intent intent = new Intent().putExtra("braintree", "nonce");
    Result result = AppSwitchHelper.parseAppSwitchResponse(mContextInspector, request, intent);
    verify(request).trackFpti(any(Context.class), eq(TrackingPoint.Error), isNull(Protocol.class));
    assertTrue(result.getError() instanceof ResponseParsingException);
    assertEquals("invalid wallet response", result.getError().getMessage());
}
Also used : Context(android.content.Context) ContextInspector(com.paypal.android.sdk.onetouch.core.base.ContextInspector) TestSetupHelper.getMockContextInspector(com.paypal.android.sdk.onetouch.core.test.TestSetupHelper.getMockContextInspector) Bundle(android.os.Bundle) ResponseParsingException(com.paypal.android.sdk.onetouch.core.exception.ResponseParsingException) Request(com.paypal.android.sdk.onetouch.core.Request) AuthorizationRequest(com.paypal.android.sdk.onetouch.core.AuthorizationRequest) CheckoutRequest(com.paypal.android.sdk.onetouch.core.CheckoutRequest) Intent(android.content.Intent) Protocol(com.paypal.android.sdk.onetouch.core.enums.Protocol) Result(com.paypal.android.sdk.onetouch.core.Result) Test(org.junit.Test)

Aggregations

ResponseParsingException (com.paypal.android.sdk.onetouch.core.exception.ResponseParsingException)14 Test (org.junit.Test)11 Uri (android.net.Uri)10 JSONException (org.json.JSONException)3 JSONObject (org.json.JSONObject)3 Result (com.paypal.android.sdk.onetouch.core.Result)2 BrowserSwitchException (com.paypal.android.sdk.onetouch.core.exception.BrowserSwitchException)2 Context (android.content.Context)1 Intent (android.content.Intent)1 Bundle (android.os.Bundle)1 AuthorizationRequest (com.paypal.android.sdk.onetouch.core.AuthorizationRequest)1 CheckoutRequest (com.paypal.android.sdk.onetouch.core.CheckoutRequest)1 Request (com.paypal.android.sdk.onetouch.core.Request)1 ContextInspector (com.paypal.android.sdk.onetouch.core.base.ContextInspector)1 Protocol (com.paypal.android.sdk.onetouch.core.enums.Protocol)1 ResponseType (com.paypal.android.sdk.onetouch.core.enums.ResponseType)1 InvalidEncryptionDataException (com.paypal.android.sdk.onetouch.core.exception.InvalidEncryptionDataException)1 WalletSwitchException (com.paypal.android.sdk.onetouch.core.exception.WalletSwitchException)1 TestSetupHelper.getMockContextInspector (com.paypal.android.sdk.onetouch.core.test.TestSetupHelper.getMockContextInspector)1 InvalidAlgorithmParameterException (java.security.InvalidAlgorithmParameterException)1