Search in sources :

Example 11 with Authorization

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

the class VenmoUnitTest method performAppSwitch_persistsIfVaultFalse.

@Test
public void performAppSwitch_persistsIfVaultFalse() 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).build();
    Venmo.authorizeAccount(fragment, false);
    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 12 with Authorization

use of com.braintreepayments.api.models.Authorization 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 13 with Authorization

use of com.braintreepayments.api.models.Authorization 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 14 with Authorization

use of com.braintreepayments.api.models.Authorization 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 15 with Authorization

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

the class BraintreeFragmentTestUtils method setConfiguration.

public static void setConfiguration(String authorization, String configuration) throws InvalidArgumentException {
    Authorization auth = Authorization.fromString(authorization);
    writeMockConfiguration(getTargetContext(), auth.getConfigUrl(), auth.getBearer(), configuration);
}
Also used : Authorization(com.braintreepayments.api.models.Authorization)

Aggregations

Authorization (com.braintreepayments.api.models.Authorization)17 Configuration (com.braintreepayments.api.models.Configuration)14 Test (org.junit.Test)12 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)12 Intent (android.content.Intent)9 Bundle (android.os.Bundle)5 InvalidArgumentException (com.braintreepayments.api.exceptions.InvalidArgumentException)4 SharedPreferences (android.content.SharedPreferences)3 SharedPreferencesHelper.clearSharedPreferences (com.braintreepayments.testutils.SharedPreferencesHelper.clearSharedPreferences)3 AuthorizationException (com.braintreepayments.api.exceptions.AuthorizationException)2 JSONException (org.json.JSONException)2 JSONObject (org.json.JSONObject)2 FragmentManager (android.app.FragmentManager)1 Context (android.content.Context)1 AppSwitchNotAvailableException (com.braintreepayments.api.exceptions.AppSwitchNotAvailableException)1 PaymentMethodNonceCallback (com.braintreepayments.api.interfaces.PaymentMethodNonceCallback)1 PaymentMethodNonce (com.braintreepayments.api.models.PaymentMethodNonce)1 VenmoAccountBuilder (com.braintreepayments.api.models.VenmoAccountBuilder)1 VenmoAccountNonce (com.braintreepayments.api.models.VenmoAccountNonce)1 TestConfigurationBuilder (com.braintreepayments.testutils.TestConfigurationBuilder)1