Search in sources :

Example 11 with Configuration

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

the class VenmoUnitTest method onActivityResult_withFailedVaultCall_postsCallbackToErrorListener.

@Test
public void onActivityResult_withFailedVaultCall_postsCallbackToErrorListener() 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();
    ArgumentCaptor<Exception> responseCaptor = ArgumentCaptor.forClass(Exception.class);
    Venmo.authorizeAccount(fragment, true);
    Intent responseIntent = new Intent().putExtra(Venmo.EXTRA_PAYMENT_METHOD_NONCE, "nonce");
    Venmo.onActivityResult(fragment, Activity.RESULT_OK, responseIntent);
    verify(fragment).postCallback(responseCaptor.capture());
    Exception exception = responseCaptor.getValue();
    assertTrue(exception instanceof AuthorizationException);
    assertEquals("Bad fingerprint", exception.getMessage());
}
Also used : Authorization(com.braintreepayments.api.models.Authorization) Configuration(com.braintreepayments.api.models.Configuration) AuthorizationException(com.braintreepayments.api.exceptions.AuthorizationException) Intent(android.content.Intent) AppSwitchNotAvailableException(com.braintreepayments.api.exceptions.AppSwitchNotAvailableException) JSONException(org.json.JSONException) InvalidArgumentException(com.braintreepayments.api.exceptions.InvalidArgumentException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) AuthorizationException(com.braintreepayments.api.exceptions.AuthorizationException) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 12 with Configuration

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

the class VenmoUnitTest method getLaunchIntent_doesNotContainAuthFingerprintWhenUsingTokenziationkey.

@Test
public void getLaunchIntent_doesNotContainAuthFingerprintWhenUsingTokenziationkey() throws JSONException, InvalidArgumentException {
    Configuration configuration = getConfigurationFromFixture();
    Authorization clientToken = Authorization.fromString(TestTokenizationKey.TOKENIZATION_KEY);
    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);
    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("merchant-id", extras.getString(Venmo.EXTRA_MERCHANT_ID));
    assertEquals("access-token", extras.getString(Venmo.EXTRA_ACCESS_TOKEN));
    assertEquals("environment", extras.getString(Venmo.EXTRA_ENVIRONMENT));
    JSONObject braintreeData = new JSONObject(extras.getString(Venmo.EXTRA_BRAINTREE_DATA));
    assertNull(Json.optString(braintreeData, "authorization_fingerprint", null));
}
Also used : Authorization(com.braintreepayments.api.models.Authorization) Configuration(com.braintreepayments.api.models.Configuration) JSONObject(org.json.JSONObject) Bundle(android.os.Bundle) Intent(android.content.Intent) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 13 with Configuration

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

the class VenmoUnitTest method performAppSwitch_persistsFalseIfTokenizationKeyUsed.

@Test
public void performAppSwitch_persistsFalseIfTokenizationKeyUsed() throws InvalidArgumentException {
    Configuration configuration = getConfigurationFromFixture();
    Authorization tokenizationkey = Authorization.fromString("sandbox_tk_abcd");
    disableSignatureVerification();
    BraintreeFragment fragment = new MockFragmentBuilder().context(VenmoInstalledContextFactory.venmoInstalledContext(true, RuntimeEnvironment.application)).configuration(configuration).authorization(tokenizationkey).sessionId("session-id").build();
    Venmo.authorizeAccount(fragment, true);
    SharedPreferences prefs = SharedPreferencesHelper.getSharedPreferences(fragment.getApplicationContext());
    assertFalse(prefs.getBoolean("com.braintreepayments.api.Venmo.VAULT_VENMO_KEY", true));
}
Also used : Authorization(com.braintreepayments.api.models.Authorization) Configuration(com.braintreepayments.api.models.Configuration) SharedPreferencesHelper.clearSharedPreferences(com.braintreepayments.testutils.SharedPreferencesHelper.clearSharedPreferences) SharedPreferences(android.content.SharedPreferences) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 14 with Configuration

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

the class VenmoUnitTest method performAppSwitch_appSwitchesWithVenmoLaunchIntent.

@Test
public void performAppSwitch_appSwitchesWithVenmoLaunchIntent() 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);
    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("merchant-id", extras.getString(Venmo.EXTRA_MERCHANT_ID));
    assertEquals("access-token", extras.getString(Venmo.EXTRA_ACCESS_TOKEN));
    assertEquals("environment", extras.getString(Venmo.EXTRA_ENVIRONMENT));
    JSONObject braintreeData = new JSONObject(extras.getString(Venmo.EXTRA_BRAINTREE_DATA));
    JSONObject meta = braintreeData.getJSONObject("_meta");
    assertNotNull(meta);
    assertEquals(fragment.getSessionId(), meta.getString("sessionId"));
    assertEquals(fragment.getIntegrationType(), meta.getString("integration"));
    assertEquals(BuildConfig.VERSION_NAME, meta.getString("version"));
    assertEquals("android", meta.getString("platform"));
}
Also used : Authorization(com.braintreepayments.api.models.Authorization) Configuration(com.braintreepayments.api.models.Configuration) JSONObject(org.json.JSONObject) Bundle(android.os.Bundle) Intent(android.content.Intent) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 15 with Configuration

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

the class VenmoUnitTest method onActivityResult_withSuccessfulVaultCall_sendsAnalyticsEvent.

@Test
public void onActivityResult_withSuccessfulVaultCall_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").successResponse(stringFromFixture("payment_methods/venmo_account_response.json")).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.success"));
}
Also used : Authorization(com.braintreepayments.api.models.Authorization) Configuration(com.braintreepayments.api.models.Configuration) Intent(android.content.Intent) 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