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());
}
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));
}
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));
}
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"));
}
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"));
}
Aggregations