/** * Determines if the Venmo flow is available to be used. This can be used to determine * if UI components should be shown or hidden. * * @param context A context to access the {@link PackageManager} * @return boolean if Venmo is enabled, and available to be used */ public boolean isEnabled(Context context) { return isAccessTokenValid() && Venmo.isVenmoInstalled(context); }
public AnalyticsEvent(Context context, String sessionId, String integration, String event) { this.event = "android." + integration + "." + event; this.timestamp = System.currentTimeMillis() / 1000; metadata = new JSONObject(); try { metadata.put(SESSION_ID_KEY, sessionId) .put(DEVICE_NETWORK_TYPE_KEY, getNetworkType(context)) .put(USER_INTERFACE_ORIENTATION_KEY, getUserOrientation(context)) .put(MERCHANT_APP_VERSION_KEY, getAppVersion(context)) .put(PAYPAL_INSTALLED_KEY, isPayPalInstalled(context)) .put(VENMO_INSTALLED_KEY, Venmo.isVenmoInstalled(context)); } catch (JSONException ignored) {} }
@Test public void createAnalyticsRequest_setsPropertiesCorrectly() throws JSONException { AnalyticsEvent analyticsEvent = new AnalyticsEvent(RuntimeEnvironment.application, "sessionId", "custom", "card.nonce-received"); assertEquals("android.custom.card.nonce-received", analyticsEvent.event); assertTrue(analyticsEvent.timestamp > 0); assertEquals("sessionId", analyticsEvent.metadata.getString("sessionId")); assertNotNull(analyticsEvent.metadata.getString("deviceNetworkType")); assertNotNull(analyticsEvent.metadata.getString("userInterfaceOrientation")); assertEquals(BuildConfig.VERSION_NAME, analyticsEvent.metadata.getString("merchantAppVersion")); assertEquals(PayPalOneTouchCore.isWalletAppInstalled(RuntimeEnvironment.application), analyticsEvent.metadata.getBoolean("paypalInstalled")); assertEquals(Venmo.isVenmoInstalled(RuntimeEnvironment.application), analyticsEvent.metadata.getBoolean("venmoInstalled")); } }
@Test public void isVenmoInstalled_returnsTrueWhenInstalled() { disableSignatureVerification(); assertTrue(Venmo.isVenmoInstalled(VenmoInstalledContextFactory.venmoInstalledContext(true))); }
assertEquals(PayPalOneTouchCore.isWalletAppInstalled(RuntimeEnvironment.application), meta.getBoolean("paypalInstalled")); assertEquals(Venmo.isVenmoInstalled(RuntimeEnvironment.application), meta.getBoolean("venmoInstalled"));
@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"); } } });