Search in sources :

Example 1 with WalletSwitchException

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

the class AppSwitchHelperUnitTest method parseAppSwitchResponse_parsesErrorAndReturnsResult.

@Test
public void parseAppSwitchResponse_parsesErrorAndReturnsResult() {
    Request request = mock(AuthorizationRequest.class);
    when(request.validateV1V2Response(any(ContextInspector.class), any(Bundle.class))).thenReturn(true);
    Intent intent = new Intent().putExtra("error", "there was an error");
    Result result = AppSwitchHelper.parseAppSwitchResponse(mContextInspector, request, intent);
    verify(request).trackFpti(any(Context.class), eq(TrackingPoint.Return), isNull(Protocol.class));
    assertTrue(result.getError() instanceof WalletSwitchException);
    assertEquals("there was an error", 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) 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) WalletSwitchException(com.paypal.android.sdk.onetouch.core.exception.WalletSwitchException) Protocol(com.paypal.android.sdk.onetouch.core.enums.Protocol) Result(com.paypal.android.sdk.onetouch.core.Result) Test(org.junit.Test)

Example 2 with WalletSwitchException

use of com.paypal.android.sdk.onetouch.core.exception.WalletSwitchException 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)

Example 3 with WalletSwitchException

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

the class AppSwitchHelperUnitTest method parseAppSwitchResponse_parsesErrorForErrorResponses.

@Test
public void parseAppSwitchResponse_parsesErrorForErrorResponses() {
    Request request = mock(AuthorizationRequest.class);
    when(request.validateV1V2Response(any(ContextInspector.class), any(Bundle.class))).thenReturn(false);
    Intent intent = new Intent().putExtra("error", "there was an error");
    Result result = AppSwitchHelper.parseAppSwitchResponse(mContextInspector, request, intent);
    verify(request).trackFpti(any(Context.class), eq(TrackingPoint.Error), isNull(Protocol.class));
    assertTrue(result.getError() instanceof WalletSwitchException);
    assertEquals("there was an error", 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) 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) WalletSwitchException(com.paypal.android.sdk.onetouch.core.exception.WalletSwitchException) Protocol(com.paypal.android.sdk.onetouch.core.enums.Protocol) Result(com.paypal.android.sdk.onetouch.core.Result) Test(org.junit.Test)

Aggregations

Result (com.paypal.android.sdk.onetouch.core.Result)3 WalletSwitchException (com.paypal.android.sdk.onetouch.core.exception.WalletSwitchException)3 Context (android.content.Context)2 Intent (android.content.Intent)2 Bundle (android.os.Bundle)2 AuthorizationRequest (com.paypal.android.sdk.onetouch.core.AuthorizationRequest)2 CheckoutRequest (com.paypal.android.sdk.onetouch.core.CheckoutRequest)2 Request (com.paypal.android.sdk.onetouch.core.Request)2 ContextInspector (com.paypal.android.sdk.onetouch.core.base.ContextInspector)2 Protocol (com.paypal.android.sdk.onetouch.core.enums.Protocol)2 TestSetupHelper.getMockContextInspector (com.paypal.android.sdk.onetouch.core.test.TestSetupHelper.getMockContextInspector)2 Test (org.junit.Test)2 ResponseType (com.paypal.android.sdk.onetouch.core.enums.ResponseType)1 ResponseParsingException (com.paypal.android.sdk.onetouch.core.exception.ResponseParsingException)1 JSONException (org.json.JSONException)1 JSONObject (org.json.JSONObject)1