Search in sources :

Example 1 with AuthorizationRequest

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

the class AppSwitchHelperUnitTest method buildAppSwitchIntent_buildsIntentForAuthorizationRequest.

@Test
public void buildAppSwitchIntent_buildsIntentForAuthorizationRequest() {
    AuthorizationRequest request = mock(AuthorizationRequest.class);
    when(request.getEnvironment()).thenReturn("test");
    when(request.getScopeString()).thenReturn("scope-string");
    when(request.getPrivacyUrl()).thenReturn("privacy-url");
    when(request.getUserAgreementUrl()).thenReturn("agreement-url");
    Intent intent = AppSwitchHelper.getAppSwitchIntent(mContextInspector, mConfigManager, request, getMockRecipe(2));
    assertEquals("scope-string", intent.getStringExtra("scope"));
    assertEquals("code", intent.getStringExtra("response_type"));
    assertEquals("privacy-url", intent.getStringExtra("privacy_url"));
    assertEquals("agreement-url", intent.getStringExtra("agreement_url"));
}
Also used : AuthorizationRequest(com.paypal.android.sdk.onetouch.core.AuthorizationRequest) Intent(android.content.Intent) Test(org.junit.Test)

Example 2 with AuthorizationRequest

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

the class AppSwitchHelper method getAppSwitchIntent.

public static Intent getAppSwitchIntent(ContextInspector contextInspector, ConfigManager configManager, Request request, Recipe recipe) {
    Intent intent = createBaseIntent(recipe.getTargetIntentAction(), WALLET_APP_PACKAGE).putExtra("version", recipe.getProtocol().getVersion()).putExtra("app_guid", InstallationIdentifier.getInstallationGUID(contextInspector.getContext())).putExtra("client_metadata_id", request.getClientMetadataId()).putExtra("client_id", request.getClientId()).putExtra("app_name", DeviceInspector.getApplicationInfoName(contextInspector.getContext())).putExtra("environment", request.getEnvironment()).putExtra("environment_url", EnvironmentManager.getEnvironmentUrl(request.getEnvironment()));
    if (request instanceof AuthorizationRequest) {
        AuthorizationRequest authorizationRequest = (AuthorizationRequest) request;
        intent.putExtra("scope", authorizationRequest.getScopeString()).putExtra("response_type", "code").putExtra("privacy_url", authorizationRequest.getPrivacyUrl()).putExtra("agreement_url", authorizationRequest.getUserAgreementUrl());
    } else {
        CheckoutRequest checkoutRequest = (CheckoutRequest) request;
        String webURL = checkoutRequest.getBrowserSwitchUrl(contextInspector.getContext(), configManager.getConfig());
        intent.putExtra("response_type", "web").putExtra("webURL", webURL);
    }
    return intent;
}
Also used : AuthorizationRequest(com.paypal.android.sdk.onetouch.core.AuthorizationRequest) CheckoutRequest(com.paypal.android.sdk.onetouch.core.CheckoutRequest) Intent(android.content.Intent)

Example 3 with AuthorizationRequest

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

the class PayPalRequestUnitTest method getAuthorizationRequest_containsCorrectValues.

@Test
public void getAuthorizationRequest_containsCorrectValues() throws JSONException, InvalidArgumentException {
    Configuration configuration = Configuration.fromJson(stringFromFixture("configuration/with_offline_paypal.json"));
    BraintreeFragment fragment = mMockFragmentBuilder.authorization(Authorization.fromString(TOKENIZATION_KEY)).configuration(configuration).build();
    AuthorizationRequest request = PayPal.getAuthorizationRequest(fragment);
    assertEquals(EnvironmentManager.MOCK, request.getEnvironment());
    assertEquals("com.braintreepayments.api.braintree://onetouch/v1/cancel", request.getCancelUrl());
    assertEquals("com.braintreepayments.api.braintree://onetouch/v1/success", request.getSuccessUrl());
    assertEquals("paypal_client_id", request.getClientId());
    assertEquals(configuration.getPayPal().getPrivacyUrl(), request.getPrivacyUrl());
    assertEquals(configuration.getPayPal().getUserAgreementUrl(), request.getUserAgreementUrl());
    String[] scopes = request.getScopeString().split(" ");
    Arrays.sort(scopes);
    assertEquals(2, scopes.length);
    assertEquals("email", scopes[0]);
    assertEquals("https://uri.paypal.com/services/payments/futurepayments", scopes[1]);
}
Also used : AuthorizationRequest(com.paypal.android.sdk.onetouch.core.AuthorizationRequest) Configuration(com.braintreepayments.api.models.Configuration) Test(org.junit.Test)

Example 4 with AuthorizationRequest

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

the class PayPalUnitTest method authorizeAccount_whenSuccessful_sendsAnalyticsEvents.

@Test
public void authorizeAccount_whenSuccessful_sendsAnalyticsEvents() throws Exception {
    final AuthorizationRequest request = new AuthorizationRequest(RuntimeEnvironment.application);
    request.environment("test");
    request.successUrl("com.braintreepayments.api.test.braintree", "success");
    setField("mMsgGuid", request, "c862cf00-f878-4e38-bb83-65bcc4b51831");
    setField("mEncryptionKey", request, EncryptionUtils.hexStringToByteArray("0481806100DE4EBB5581163579990EE825737255A81A883B791A1BB6F5A7E81C"));
    doAnswer(new Answer<AuthorizationRequest>() {

        @Override
        public AuthorizationRequest answer(InvocationOnMock invocation) throws Throwable {
            return request;
        }
    }).when(PayPal.class, "getAuthorizationRequest", any(BraintreeFragment.class));
    final BraintreeFragment fragment = mMockFragmentBuilder.build();
    doAnswer(new Answer() {

        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            Intent intent = new Intent().setData(Uri.parse("com.braintreepayments.api.test.braintree://onetouch/v1/success?payloadEnc=k7mNFgzs404Wy8VOReO2E%2FTpfDoC44E1iwjptDooIkjjh1TcAupUCM8812g3zmBruc%2BFeIIwZlEhu6ugAXvLs5u6aHG4KU7FuPPLDS9OO87WAw0v3n7QIPp%2Bd5o%2Bk4VZ047w%2FXiijFuFKb4SRe9fg8kYGAYCtUR1IrK%2BhuvB3VCg7rkLk9V0n2YF3WcvmaLUt8SIYok1dbG8Ou4zDIXaZp7%2ByGalcyjN3MW3OLstaehD2jpuxlP6WDG6dkB6LZ2LEnHDV0X7j2vOtmSrrCtYZuFhlB%2FkKNkgsVhBrbHdqsfsBKyc7sHlsgT0Dz0TXc3BHqjJIWLrOuglt78QOM92%2B7GFM6JL5%2BARzJ4Tp9iI%2BU4QyQLTSkOGTA0LgSBUhr2srF41lWTXw65F4A%3D%3D&payload=eyJ2ZXJzaW9uIjozLCJtc2dfR1VJRCI6ImM4NjJjZjAwLWY4NzgtNGUzOC1iYjgzLTY1YmNjNGI1MTgzMSIsInJlc3BvbnNlX3R5cGUiOiJjb2RlIiwiZW52aXJvbm1lbnQiOiJtb2NrIiwiZXJyb3IiOm51bGx9&x-source=com.braintree.browserswitch"));
            PayPal.onActivityResult(fragment, Activity.RESULT_OK, intent);
            return null;
        }
    }).when(fragment).browserSwitch(eq(BraintreeRequestCodes.PAYPAL), any(Intent.class));
    mockStatic(TokenizationClient.class);
    doAnswer(new Answer<Void>() {

        @Override
        public Void answer(InvocationOnMock invocation) throws Throwable {
            ((PaymentMethodNonceCallback) invocation.getArguments()[2]).success(new PayPalAccountNonce());
            return null;
        }
    }).when(TokenizationClient.class);
    TokenizationClient.tokenize(any(BraintreeFragment.class), any(PaymentMethodBuilder.class), any(PaymentMethodNonceCallback.class));
    PayPal.authorizeAccount(fragment);
    verify(fragment).sendAnalyticsEvent("paypal.future-payments.selected");
    verify(fragment).sendAnalyticsEvent("paypal-future-payments.webswitch.started");
    verify(fragment).sendAnalyticsEvent("paypal-future-payments.webswitch.succeeded");
}
Also used : PowerMockito.doAnswer(org.powermock.api.mockito.PowerMockito.doAnswer) Answer(org.mockito.stubbing.Answer) AuthorizationRequest(com.paypal.android.sdk.onetouch.core.AuthorizationRequest) PaymentMethodBuilder(com.braintreepayments.api.models.PaymentMethodBuilder) InvocationOnMock(org.mockito.invocation.InvocationOnMock) PaymentMethodNonceCallback(com.braintreepayments.api.interfaces.PaymentMethodNonceCallback) JSONObject(org.json.JSONObject) Intent(android.content.Intent) PayPalAccountNonce(com.braintreepayments.api.models.PayPalAccountNonce) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 5 with AuthorizationRequest

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

the class PayPalUnitTest method authorizeAccount_doesNotCallCancelListenerWhenSuccessful.

@Test
public void authorizeAccount_doesNotCallCancelListenerWhenSuccessful() throws Exception {
    final AuthorizationRequest request = new AuthorizationRequest(RuntimeEnvironment.application);
    request.environment("test");
    request.successUrl("com.braintreepayments.api.test.braintree", "success");
    setField("mMsgGuid", request, "c862cf00-f878-4e38-bb83-65bcc4b51831");
    setField("mEncryptionKey", request, EncryptionUtils.hexStringToByteArray("0481806100DE4EBB5581163579990EE825737255A81A883B791A1BB6F5A7E81C"));
    doAnswer(new Answer<AuthorizationRequest>() {

        @Override
        public AuthorizationRequest answer(InvocationOnMock invocation) throws Throwable {
            return request;
        }
    }).when(PayPal.class, "getAuthorizationRequest", any(BraintreeFragment.class));
    final BraintreeFragment fragment = mMockFragmentBuilder.build();
    doAnswer(new Answer() {

        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            Intent intent = new Intent().setData(Uri.parse("com.braintreepayments.api.test.braintree://onetouch/v1/success?payloadEnc=k7mNFgzs404Wy8VOReO2E%2FTpfDoC44E1iwjptDooIkjjh1TcAupUCM8812g3zmBruc%2BFeIIwZlEhu6ugAXvLs5u6aHG4KU7FuPPLDS9OO87WAw0v3n7QIPp%2Bd5o%2Bk4VZ047w%2FXiijFuFKb4SRe9fg8kYGAYCtUR1IrK%2BhuvB3VCg7rkLk9V0n2YF3WcvmaLUt8SIYok1dbG8Ou4zDIXaZp7%2ByGalcyjN3MW3OLstaehD2jpuxlP6WDG6dkB6LZ2LEnHDV0X7j2vOtmSrrCtYZuFhlB%2FkKNkgsVhBrbHdqsfsBKyc7sHlsgT0Dz0TXc3BHqjJIWLrOuglt78QOM92%2B7GFM6JL5%2BARzJ4Tp9iI%2BU4QyQLTSkOGTA0LgSBUhr2srF41lWTXw65F4A%3D%3D&payload=eyJ2ZXJzaW9uIjozLCJtc2dfR1VJRCI6ImM4NjJjZjAwLWY4NzgtNGUzOC1iYjgzLTY1YmNjNGI1MTgzMSIsInJlc3BvbnNlX3R5cGUiOiJjb2RlIiwiZW52aXJvbm1lbnQiOiJtb2NrIiwiZXJyb3IiOm51bGx9&x-source=com.braintree.browserswitch"));
            PayPal.onActivityResult(fragment, Activity.RESULT_OK, intent);
            return null;
        }
    }).when(fragment).startActivity(any(Intent.class));
    mockStatic(TokenizationClient.class);
    doAnswer(new Answer<Void>() {

        @Override
        public Void answer(InvocationOnMock invocation) throws Throwable {
            ((PaymentMethodNonceCallback) invocation.getArguments()[2]).success(new PayPalAccountNonce());
            return null;
        }
    }).when(TokenizationClient.class);
    TokenizationClient.tokenize(any(BraintreeFragment.class), any(PaymentMethodBuilder.class), any(PaymentMethodNonceCallback.class));
    PayPal.authorizeAccount(fragment);
    verify(fragment, never()).postCancelCallback(anyInt());
}
Also used : PowerMockito.doAnswer(org.powermock.api.mockito.PowerMockito.doAnswer) Answer(org.mockito.stubbing.Answer) AuthorizationRequest(com.paypal.android.sdk.onetouch.core.AuthorizationRequest) PaymentMethodBuilder(com.braintreepayments.api.models.PaymentMethodBuilder) InvocationOnMock(org.mockito.invocation.InvocationOnMock) PaymentMethodNonceCallback(com.braintreepayments.api.interfaces.PaymentMethodNonceCallback) JSONObject(org.json.JSONObject) Intent(android.content.Intent) PayPalAccountNonce(com.braintreepayments.api.models.PayPalAccountNonce) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

AuthorizationRequest (com.paypal.android.sdk.onetouch.core.AuthorizationRequest)6 Intent (android.content.Intent)5 Test (org.junit.Test)5 PaymentMethodNonceCallback (com.braintreepayments.api.interfaces.PaymentMethodNonceCallback)3 PayPalAccountNonce (com.braintreepayments.api.models.PayPalAccountNonce)3 PaymentMethodBuilder (com.braintreepayments.api.models.PaymentMethodBuilder)3 JSONObject (org.json.JSONObject)3 InvocationOnMock (org.mockito.invocation.InvocationOnMock)3 Answer (org.mockito.stubbing.Answer)3 PowerMockito.doAnswer (org.powermock.api.mockito.PowerMockito.doAnswer)3 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)3 Configuration (com.braintreepayments.api.models.Configuration)1 CheckoutRequest (com.paypal.android.sdk.onetouch.core.CheckoutRequest)1