static Intent getLaunchIntent(VenmoConfiguration venmoConfiguration, String profileId, BraintreeFragment fragment) { Intent venmoIntent = getVenmoIntent() .putExtra(EXTRA_MERCHANT_ID, profileId) .putExtra(EXTRA_ACCESS_TOKEN, venmoConfiguration.getAccessToken()) .putExtra(EXTRA_ENVIRONMENT, venmoConfiguration.getEnvironment()); try { JSONObject braintreeData = new JSONObject(); JSONObject meta = new MetadataBuilder() .sessionId(fragment.getSessionId()) .integration(fragment.getIntegrationType()) .version() .build(); braintreeData.put(META_KEY, meta); venmoIntent.putExtra(EXTRA_BRAINTREE_DATA, braintreeData.toString()); } catch (JSONException ignored) {} return venmoIntent; }
.put("integration", fragment.getIntegrationType()) .put("sessionId", fragment.getSessionId()); payload.put("_meta", metaData);
@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")); }
@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")); }
@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)); }
.sessionId(fragment.getSessionId()) .source("client") .integration(fragment.getIntegrationType()) .build());
@Test public void performAppSwitch_whenProfileIdIsNull_appSwitchesWithMerchantId() 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, null); 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)); }
@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)); }