@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")); }
@Override public void onConfigurationFetched(Configuration configuration) { fragment.sendAnalyticsEvent("pay-with-venmo.selected"); String venmoProfileId = profileId; if (TextUtils.isEmpty(venmoProfileId)) { venmoProfileId = configuration.getPayWithVenmo().getMerchantId(); } String exceptionMessage = ""; if (!configuration.getPayWithVenmo().isAccessTokenValid()) { exceptionMessage = "Venmo is not enabled"; } else if (!Venmo.isVenmoInstalled(fragment.getApplicationContext())) { exceptionMessage = "Venmo is not installed"; } if (!TextUtils.isEmpty(exceptionMessage)) { fragment.postCallback(new AppSwitchNotAvailableException(exceptionMessage)); fragment.sendAnalyticsEvent("pay-with-venmo.app-switch.failed"); } else { persistVenmoVaultOption(vault && fragment.getAuthorization() instanceof ClientToken, fragment.getApplicationContext()); fragment.startActivityForResult(getLaunchIntent(configuration.getPayWithVenmo(), venmoProfileId, fragment), BraintreeRequestCodes.VENMO); fragment.sendAnalyticsEvent("pay-with-venmo.app-switch.started"); } } });