Search in sources :

Example 66 with Configuration

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

the class VenmoUnitTest method onActivityResult_performsVaultRequestIfRequestPersisted.

@Test
public void onActivityResult_performsVaultRequestIfRequestPersisted() throws InvalidArgumentException, NoSuchAlgorithmException {
    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").build();
    Venmo.authorizeAccount(fragment, true);
    mockStatic(TokenizationClient.class);
    Venmo.onActivityResult(fragment, Activity.RESULT_OK, new Intent());
    verifyStatic();
    TokenizationClient.tokenize(eq(fragment), any(VenmoAccountBuilder.class), any(PaymentMethodNonceCallback.class));
}
Also used : Authorization(com.braintreepayments.api.models.Authorization) VenmoAccountBuilder(com.braintreepayments.api.models.VenmoAccountBuilder) Configuration(com.braintreepayments.api.models.Configuration) PaymentMethodNonceCallback(com.braintreepayments.api.interfaces.PaymentMethodNonceCallback) Intent(android.content.Intent) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 67 with Configuration

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

the class VenmoUnitTest method getLaunchIntent_containsCorrectVenmoExtras.

@Test
public void getLaunchIntent_containsCorrectVenmoExtras() throws JSONException, InvalidArgumentException {
    Configuration configuration = getConfigurationFromFixture();
    BraintreeFragment fragment = new MockFragmentBuilder().authorization(Authorization.fromString(stringFromFixture("client_token.json"))).configuration(configuration).sessionId("session-id").build();
    when(fragment.getIntegrationType()).thenReturn("custom");
    Intent intent = Venmo.getLaunchIntent(configuration.getPayWithVenmo(), configuration.getPayWithVenmo().getMerchantId(), fragment);
    assertEquals(new ComponentName("com.venmo", "com.venmo.controller.SetupMerchantActivity"), intent.getComponent());
    assertEquals("merchant-id", intent.getStringExtra(Venmo.EXTRA_MERCHANT_ID));
    assertEquals("access-token", intent.getStringExtra(Venmo.EXTRA_ACCESS_TOKEN));
    assertEquals("environment", intent.getStringExtra(Venmo.EXTRA_ENVIRONMENT));
    JSONObject braintreeData = new JSONObject(intent.getStringExtra(Venmo.EXTRA_BRAINTREE_DATA));
    JSONObject meta = braintreeData.getJSONObject("_meta");
    assertNotNull(meta);
    assertEquals("session-id", meta.getString("sessionId"));
    assertEquals("custom", meta.getString("integration"));
    assertEquals(BuildConfig.VERSION_NAME, meta.getString("version"));
    assertEquals("android", meta.getString("platform"));
}
Also used : Configuration(com.braintreepayments.api.models.Configuration) JSONObject(org.json.JSONObject) Intent(android.content.Intent) ComponentName(android.content.ComponentName) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 68 with Configuration

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

the class VenmoUnitTest method onActivityResult_doesNotPerformRequestIfTokenizationKeyUsed.

@Test
public void onActivityResult_doesNotPerformRequestIfTokenizationKeyUsed() throws NoSuchAlgorithmException, InvalidArgumentException {
    Configuration configuration = getConfigurationFromFixture();
    mockStatic(TokenizationClient.class);
    BraintreeFragment fragment = new MockFragmentBuilder().context(VenmoInstalledContextFactory.venmoInstalledContext(true, RuntimeEnvironment.application)).configuration(configuration).authorization(Authorization.fromString("sandbox_tk_abcd")).sessionId("another-session-id").build();
    Venmo.authorizeAccount(fragment, true);
    Venmo.onActivityResult(fragment, Activity.RESULT_OK, new Intent());
    verifyStatic(times(0));
    TokenizationClient.tokenize(eq(fragment), any(VenmoAccountBuilder.class), any(PaymentMethodNonceCallback.class));
}
Also used : VenmoAccountBuilder(com.braintreepayments.api.models.VenmoAccountBuilder) Configuration(com.braintreepayments.api.models.Configuration) PaymentMethodNonceCallback(com.braintreepayments.api.interfaces.PaymentMethodNonceCallback) Intent(android.content.Intent) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 69 with Configuration

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

the class VenmoUnitTest method performAppSwitch_sendsAnalyticsEventWhenUnavailableAndPostException.

@Test
public void performAppSwitch_sendsAnalyticsEventWhenUnavailableAndPostException() {
    Configuration configuration = getConfigurationFromFixture();
    BraintreeFragment fragment = new MockFragmentBuilder().configuration(configuration).build();
    Venmo.authorizeAccount(fragment, false);
    ArgumentCaptor<AppSwitchNotAvailableException> captor = ArgumentCaptor.forClass(AppSwitchNotAvailableException.class);
    InOrder order = inOrder(fragment);
    order.verify(fragment).sendAnalyticsEvent("pay-with-venmo.selected");
    order.verify(fragment).sendAnalyticsEvent("pay-with-venmo.app-switch.failed");
    verify(fragment).postCallback(captor.capture());
    assertEquals("Venmo is not installed", captor.getValue().getMessage());
}
Also used : AppSwitchNotAvailableException(com.braintreepayments.api.exceptions.AppSwitchNotAvailableException) InOrder(org.mockito.InOrder) Configuration(com.braintreepayments.api.models.Configuration) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 70 with Configuration

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

the class VenmoUnitTest method authorizeAccount_postsExceptionWhenNotEnabled.

@Test
public void authorizeAccount_postsExceptionWhenNotEnabled() throws JSONException {
    Configuration configuration = new TestConfigurationBuilder().buildConfiguration();
    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 enabled", captor.getValue().getMessage());
}
Also used : AppSwitchNotAvailableException(com.braintreepayments.api.exceptions.AppSwitchNotAvailableException) Configuration(com.braintreepayments.api.models.Configuration) TestConfigurationBuilder(com.braintreepayments.testutils.TestConfigurationBuilder) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) 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