Search in sources :

Example 71 with Configuration

use of com.braintreepayments.api.models.Configuration in project braintree_android by braintree.

the class VenmoUnitTest method onActivityResult_withFailedVaultCall_sendsAnalyticsEvent.

@Test
public void onActivityResult_withFailedVaultCall_sendsAnalyticsEvent() throws InvalidArgumentException {
    Configuration configuration = getConfigurationFromFixture();
    Authorization clientToken = Authorization.fromString(stringFromFixture("base_64_client_token.txt"));
    disableSignatureVerification();
    BraintreeFragment fragment = new MockFragmentBuilder().context(VenmoInstalledContextFactory.venmoInstalledContext(true, RuntimeEnvironment.application)).configuration(configuration).authorization(clientToken).sessionId("session-id").errorResponse(new AuthorizationException("Bad fingerprint")).build();
    Venmo.authorizeAccount(fragment, true);
    Intent responseIntent = new Intent().putExtra(Venmo.EXTRA_PAYMENT_METHOD_NONCE, "nonce");
    Venmo.onActivityResult(fragment, Activity.RESULT_OK, responseIntent);
    verify(fragment).sendAnalyticsEvent(endsWith("pay-with-venmo.vault.failed"));
}
Also used : Authorization(com.braintreepayments.api.models.Authorization) Configuration(com.braintreepayments.api.models.Configuration) AuthorizationException(com.braintreepayments.api.exceptions.AuthorizationException) Intent(android.content.Intent) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 72 with Configuration

use of com.braintreepayments.api.models.Configuration in project braintree_android by braintree.

the class VenmoUnitTest method performAppSwitch_whenProfileIdIsSpecified_appSwitchesWithProfileIdAndAccessToken.

@Test
public void performAppSwitch_whenProfileIdIsSpecified_appSwitchesWithProfileIdAndAccessToken() throws InvalidArgumentException, JSONException {
    Configuration configuration = getConfigurationFromFixture();
    Authorization clientToken = Authorization.fromString(stringFromFixture("base_64_client_token.txt"));
    disableSignatureVerification();
    BraintreeFragment fragment = new MockFragmentBuilder().context(VenmoInstalledContextFactory.venmoInstalledContext(true, RuntimeEnvironment.application)).authorization(clientToken).configuration(configuration).build();
    when(fragment.getSessionId()).thenReturn("a-session-id");
    when(fragment.getIntegrationType()).thenReturn("custom");
    Venmo.authorizeAccount(fragment, false, "second-pwv-profile-id");
    ArgumentCaptor<Intent> captor = ArgumentCaptor.forClass(Intent.class);
    verify(fragment).startActivityForResult(captor.capture(), eq(BraintreeRequestCodes.VENMO));
    assertEquals("com.venmo/com.venmo.controller.SetupMerchantActivity", captor.getValue().getComponent().flattenToString());
    Bundle extras = captor.getValue().getExtras();
    assertEquals("second-pwv-profile-id", extras.getString(Venmo.EXTRA_MERCHANT_ID));
    assertEquals("access-token", extras.getString(Venmo.EXTRA_ACCESS_TOKEN));
}
Also used : Authorization(com.braintreepayments.api.models.Authorization) Configuration(com.braintreepayments.api.models.Configuration) Bundle(android.os.Bundle) Intent(android.content.Intent) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 73 with Configuration

use of com.braintreepayments.api.models.Configuration in project braintree_android by braintree.

the class VenmoUnitTest method authorizeAccount_postsExceptionWhenNotInstalled.

@Test
public void authorizeAccount_postsExceptionWhenNotInstalled() {
    Configuration configuration = getConfigurationFromFixture();
    BraintreeFragment fragment = new MockFragmentBuilder().configuration(configuration).build();
    Venmo.authorizeAccount(fragment, false);
    ArgumentCaptor<AppSwitchNotAvailableException> captor = ArgumentCaptor.forClass(AppSwitchNotAvailableException.class);
    verify(fragment).postCallback(captor.capture());
    assertEquals("Venmo is not installed", captor.getValue().getMessage());
}
Also used : AppSwitchNotAvailableException(com.braintreepayments.api.exceptions.AppSwitchNotAvailableException) Configuration(com.braintreepayments.api.models.Configuration) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 74 with Configuration

use of com.braintreepayments.api.models.Configuration in project braintree_android by braintree.

the class BraintreeFragmentTest method fetchConfiguration_worksWithATokenizationKey.

@Test(timeout = 10000)
public void fetchConfiguration_worksWithATokenizationKey() throws InterruptedException {
    final BraintreeFragment fragment = getFragmentWithAuthorization(mActivity, TOKENIZATION_KEY);
    fragment.waitForConfiguration(new ConfigurationListener() {

        @Override
        public void onConfigurationFetched(Configuration configuration) {
            assertNotNull(configuration);
            mCountDownLatch.countDown();
        }
    });
    mCountDownLatch.await();
}
Also used : ConfigurationListener(com.braintreepayments.api.interfaces.ConfigurationListener) Configuration(com.braintreepayments.api.models.Configuration) Test(org.junit.Test)

Example 75 with Configuration

use of com.braintreepayments.api.models.Configuration in project braintree_android by braintree.

the class GooglePaymentTest method getTokenizationParameters_returnsCorrectParameters.

@Test(timeout = 5000)
public void getTokenizationParameters_returnsCorrectParameters() throws Exception {
    String config = mBaseConfiguration.withAnalytics().build();
    final BraintreeFragment fragment = getFragment(mActivityTestRule.getActivity(), TOKENIZATION_KEY, config);
    fragment.waitForConfiguration(new ConfigurationListener() {

        @Override
        public void onConfigurationFetched(Configuration configuration) {
            Bundle tokenizationParameters = GooglePayment.getTokenizationParameters(fragment).getParameters();
            assertEquals("braintree", tokenizationParameters.getString("gateway"));
            assertEquals(configuration.getMerchantId(), tokenizationParameters.getString("braintree:merchantId"));
            assertEquals(configuration.getAndroidPay().getGoogleAuthorizationFingerprint(), tokenizationParameters.getString("braintree:authorizationFingerprint"));
            assertEquals("v1", tokenizationParameters.getString("braintree:apiVersion"));
            assertEquals(BuildConfig.VERSION_NAME, tokenizationParameters.getString("braintree:sdkVersion"));
            mLatch.countDown();
        }
    });
    mLatch.await();
}
Also used : ConfigurationListener(com.braintreepayments.api.interfaces.ConfigurationListener) BraintreeFragmentTestUtils.getFragmentWithConfiguration(com.braintreepayments.api.BraintreeFragmentTestUtils.getFragmentWithConfiguration) BraintreeFragmentTestUtils.getMockFragmentWithConfiguration(com.braintreepayments.api.BraintreeFragmentTestUtils.getMockFragmentWithConfiguration) Configuration(com.braintreepayments.api.models.Configuration) Bundle(android.os.Bundle) Test(org.junit.Test)

Aggregations

Configuration (com.braintreepayments.api.models.Configuration)84 Test (org.junit.Test)66 ConfigurationListener (com.braintreepayments.api.interfaces.ConfigurationListener)36 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)35 InvalidArgumentException (com.braintreepayments.api.exceptions.InvalidArgumentException)19 JSONException (org.json.JSONException)19 Authorization (com.braintreepayments.api.models.Authorization)14 Intent (android.content.Intent)13 HttpResponseCallback (com.braintreepayments.api.interfaces.HttpResponseCallback)13 TestConfigurationBuilder (com.braintreepayments.testutils.TestConfigurationBuilder)12 AuthorizationRequest (com.paypal.android.sdk.onetouch.core.AuthorizationRequest)11 BillingAgreementRequest (com.paypal.android.sdk.onetouch.core.BillingAgreementRequest)11 CheckoutRequest (com.paypal.android.sdk.onetouch.core.CheckoutRequest)11 JSONObject (org.json.JSONObject)11 UnexpectedException (com.braintreepayments.api.exceptions.UnexpectedException)10 SharedPreferencesHelper.writeMockConfiguration (com.braintreepayments.testutils.SharedPreferencesHelper.writeMockConfiguration)10 Request (com.paypal.android.sdk.onetouch.core.Request)10 Bundle (android.os.Bundle)9 BraintreeFragmentTestUtils.getMockFragmentWithConfiguration (com.braintreepayments.api.BraintreeFragmentTestUtils.getMockFragmentWithConfiguration)6 BraintreeFragmentTestUtils.getFragmentWithConfiguration (com.braintreepayments.api.BraintreeFragmentTestUtils.getFragmentWithConfiguration)5