From 69b62cbda350f703e09dadccf6c2b17560e4645a Mon Sep 17 00:00:00 2001 From: Sarah Koop Date: Mon, 11 Dec 2023 14:04:46 -0600 Subject: [PATCH] Update Venmo with FPTI Analytics Events (#846) * Replace Venmo analytics with FPTI events * Update unit tests * Add new unit tests * Fix unit tests * Convert VenmoAnalytics to class * Remove companion object * Add helper analtyics methods * Update app switch failure analytics * Remove extra analytics event --- .../braintreepayments/api/VenmoAnalytics.kt | 14 +- .../braintreepayments/api/VenmoClient.java | 83 ++++++------ .../api/VenmoAnalyticsUnitTest.kt | 12 +- .../api/VenmoClientUnitTest.java | 125 ++++++++++-------- 4 files changed, 124 insertions(+), 110 deletions(-) diff --git a/Venmo/src/main/java/com/braintreepayments/api/VenmoAnalytics.kt b/Venmo/src/main/java/com/braintreepayments/api/VenmoAnalytics.kt index 8dd26de38b..bf42cd4d0c 100644 --- a/Venmo/src/main/java/com/braintreepayments/api/VenmoAnalytics.kt +++ b/Venmo/src/main/java/com/braintreepayments/api/VenmoAnalytics.kt @@ -1,14 +1,14 @@ package com.braintreepayments.api -internal enum class VenmoAnalytics(@JvmField val event: String) { +internal object VenmoAnalytics { // Conversion Events - TOKENIZE_STARTED("venmo:tokenize:started"), - TOKENIZE_FAILED("venmo:tokenize:failed"), - TOKENIZE_SUCCEEDED("venmo:tokenize:succeeded"), - APP_SWITCH_CANCELED("venmo:tokenize:app-switch:canceled"), + const val TOKENIZE_STARTED = "venmo:tokenize:started" + const val TOKENIZE_FAILED = "venmo:tokenize:failed" + const val TOKENIZE_SUCCEEDED = "venmo:tokenize:succeeded" + const val APP_SWITCH_CANCELED = "venmo:tokenize:app-switch:canceled" // Additional Detail Events - APP_SWITCH_SUCCEEDED("venmo:tokenize:app-switch:succeeded"), - APP_SWITCH_FAILED("venmo:tokenize:app-switch:failed") + const val APP_SWITCH_SUCCEEDED = "venmo:tokenize:app-switch:succeeded" + const val APP_SWITCH_FAILED = "venmo:tokenize:app-switch:failed" } diff --git a/Venmo/src/main/java/com/braintreepayments/api/VenmoClient.java b/Venmo/src/main/java/com/braintreepayments/api/VenmoClient.java index 4077548d4d..7f7399472a 100644 --- a/Venmo/src/main/java/com/braintreepayments/api/VenmoClient.java +++ b/Venmo/src/main/java/com/braintreepayments/api/VenmoClient.java @@ -57,7 +57,6 @@ public VenmoClient(@NonNull Context context, @NonNull String authorization) { * @param activity used to open the Venmo's Google Play Store */ public void showVenmoInGooglePlayStore(@NonNull FragmentActivity activity) { - braintreeClient.sendAnalyticsEvent("android.pay-with-venmo.app-store.invoked"); Intent intent = new Intent(Intent.ACTION_VIEW); intent.setData(Uri.parse( "https://play.google.com/store/apps/details?id=" + VENMO_PACKAGE_NAME)); @@ -80,25 +79,22 @@ public void showVenmoInGooglePlayStore(@NonNull FragmentActivity activity) { public void createPaymentAuthRequest(@NonNull final FragmentActivity activity, @NonNull final VenmoRequest request, @NonNull VenmoPaymentAuthRequestCallback callback) { - braintreeClient.sendAnalyticsEvent("pay-with-venmo.selected"); + braintreeClient.sendAnalyticsEvent(VenmoAnalytics.TOKENIZE_STARTED); braintreeClient.getConfiguration((configuration, error) -> { if (configuration == null && error != null) { - callback.onVenmoPaymentAuthRequest(new VenmoPaymentAuthRequest.Failure(error)); - braintreeClient.sendAnalyticsEvent("pay-with-venmo.app-switch.failed"); + callbackPaymentAuthFailure(callback, new VenmoPaymentAuthRequest.Failure(error)); return; } - String exceptionMessage = null; if (!configuration.isVenmoEnabled()) { - exceptionMessage = "Venmo is not enabled"; - } else if (!deviceInspector.isVenmoAppSwitchAvailable(activity)) { - exceptionMessage = "Venmo is not installed"; + callbackPaymentAuthFailure(callback, + new VenmoPaymentAuthRequest.Failure(new AppSwitchNotAvailableException("Venmo is not enabled"))); + return; } - - if (exceptionMessage != null) { - callback.onVenmoPaymentAuthRequest( - new VenmoPaymentAuthRequest.Failure(new AppSwitchNotAvailableException(exceptionMessage))); - braintreeClient.sendAnalyticsEvent("pay-with-venmo.app-switch.failed"); + if (!deviceInspector.isVenmoAppSwitchAvailable(activity)) { + braintreeClient.sendAnalyticsEvent(VenmoAnalytics.APP_SWITCH_FAILED); + callbackPaymentAuthFailure(callback, + new VenmoPaymentAuthRequest.Failure(new AppSwitchNotAvailableException("Venmo is not installed"))); return; } @@ -107,10 +103,9 @@ public void createPaymentAuthRequest(@NonNull final FragmentActivity activity, if ((request.getCollectCustomerShippingAddress() || request.getCollectCustomerBillingAddress()) && !configuration.getVenmoEnrichedCustomerDataEnabled()) { - callback.onVenmoPaymentAuthRequest(new VenmoPaymentAuthRequest.Failure(new BraintreeException( + callbackPaymentAuthFailure(callback, new VenmoPaymentAuthRequest.Failure(new BraintreeException( "Cannot collect customer data when ECD is disabled. Enable this feature " + "in the Control Panel to collect this data."))); - braintreeClient.sendAnalyticsEvent("pay-with-venmo.app-switch.failed"); return; } @@ -127,8 +122,7 @@ public void createPaymentAuthRequest(@NonNull final FragmentActivity activity, braintreeClient.getAuthorization(), finalVenmoProfileId, paymentContextId, callback); } else { - callback.onVenmoPaymentAuthRequest(new VenmoPaymentAuthRequest.Failure(exception)); - braintreeClient.sendAnalyticsEvent("pay-with-venmo.app-switch.failed"); + callbackPaymentAuthFailure(callback, new VenmoPaymentAuthRequest.Failure(exception)); } }); }); @@ -150,7 +144,6 @@ private void createPaymentAuthRequest( new VenmoPaymentAuthRequestParams(configuration, venmoProfileId, paymentContextId, braintreeClient.getSessionId(), braintreeClient.getIntegrationType()); callback.onVenmoPaymentAuthRequest(new VenmoPaymentAuthRequest.ReadyToLaunch(params)); - braintreeClient.sendAnalyticsEvent("pay-with-venmo.app-switch.started"); } /** @@ -166,7 +159,7 @@ private void createPaymentAuthRequest( public void tokenize(@NonNull final VenmoPaymentAuthResult venmoPaymentAuthResult, @NonNull VenmoTokenizeCallback callback) { if (venmoPaymentAuthResult.getError() == null) { - braintreeClient.sendAnalyticsEvent("pay-with-venmo.app-switch.success"); + braintreeClient.sendAnalyticsEvent(VenmoAnalytics.APP_SWITCH_SUCCEEDED); final boolean isClientTokenAuth = (braintreeClient.getAuthorization() instanceof ClientToken); @@ -181,20 +174,16 @@ public void tokenize(@NonNull final VenmoPaymentAuthResult venmoPaymentAuthResul vaultVenmoAccountNonce(nonce.getString(), (venmoAccountNonce, vaultError) -> { if (venmoAccountNonce != null) { - callback.onVenmoResult(new VenmoResult.Success(venmoAccountNonce)); + callbackSuccess(callback, new VenmoResult.Success(venmoAccountNonce)); } else if (vaultError != null) { - callback.onVenmoResult(new VenmoResult.Failure(vaultError)); + callbackTokenizeFailure(callback, new VenmoResult.Failure(vaultError)); } }); } else { - braintreeClient.sendAnalyticsEvent( - "pay-with-venmo.app-switch.failure"); - callback.onVenmoResult(new VenmoResult.Success(nonce)); + callbackSuccess(callback, new VenmoResult.Success(nonce)); } } else if (error != null) { - braintreeClient.sendAnalyticsEvent( - "pay-with-venmo.app-switch.failure"); - callback.onVenmoResult(new VenmoResult.Failure(error)); + callbackTokenizeFailure(callback, new VenmoResult.Failure(error)); } }); } else { @@ -205,36 +194,30 @@ public void tokenize(@NonNull final VenmoPaymentAuthResult venmoPaymentAuthResul if (shouldVault && isClientTokenAuth) { vaultVenmoAccountNonce(nonce, (venmoAccountNonce, error) -> { if (venmoAccountNonce != null) { - callback.onVenmoResult(new VenmoResult.Success(venmoAccountNonce)); + callbackSuccess(callback, new VenmoResult.Success(venmoAccountNonce)); } else if (error != null) { - callback.onVenmoResult(new VenmoResult.Failure(error)); + callbackTokenizeFailure(callback, new VenmoResult.Failure(error)); } }); } else { String venmoUsername = venmoPaymentAuthResult.getVenmoUsername(); VenmoAccountNonce venmoAccountNonce = new VenmoAccountNonce(nonce, venmoUsername, false); - callback.onVenmoResult(new VenmoResult.Success(venmoAccountNonce)); + callbackSuccess(callback, new VenmoResult.Success(venmoAccountNonce)); } } } else if (venmoPaymentAuthResult.getError() != null) { if (venmoPaymentAuthResult.getError() instanceof UserCanceledException) { - braintreeClient.sendAnalyticsEvent("pay-with-venmo.app-switch.canceled"); + callbackTokenizeCancel(callback); + } else { + callbackTokenizeFailure(callback, new VenmoResult.Failure(venmoPaymentAuthResult.getError())); } - callback.onVenmoResult(VenmoResult.Cancel.INSTANCE); } } private void vaultVenmoAccountNonce(String nonce, final VenmoInternalCallback callback) { - venmoApi.vaultVenmoAccountNonce(nonce, (venmoAccountNonce, error) -> { - if (venmoAccountNonce != null) { - braintreeClient.sendAnalyticsEvent("pay-with-venmo.vault.success"); - } else { - braintreeClient.sendAnalyticsEvent("pay-with-venmo.vault.failed"); - } - callback.onResult(venmoAccountNonce, error); - }); + venmoApi.vaultVenmoAccountNonce(nonce, (venmoAccountNonce, error) -> callback.onResult(venmoAccountNonce, error)); } /** @@ -270,4 +253,24 @@ public void isReadyToPay(final Context context, final VenmoIsReadyToPayCallback } }); } + + private void callbackPaymentAuthFailure(VenmoPaymentAuthRequestCallback callback, VenmoPaymentAuthRequest request) { + braintreeClient.sendAnalyticsEvent(VenmoAnalytics.TOKENIZE_FAILED); + callback.onVenmoPaymentAuthRequest(request); + } + + private void callbackSuccess(VenmoTokenizeCallback callback, VenmoResult venmoResult) { + braintreeClient.sendAnalyticsEvent(VenmoAnalytics.TOKENIZE_SUCCEEDED); + callback.onVenmoResult(venmoResult); + } + + private void callbackTokenizeCancel(VenmoTokenizeCallback callback) { + braintreeClient.sendAnalyticsEvent(VenmoAnalytics.APP_SWITCH_CANCELED); + callback.onVenmoResult(VenmoResult.Cancel.INSTANCE); + } + + private void callbackTokenizeFailure(VenmoTokenizeCallback callback, VenmoResult venmoResult) { + braintreeClient.sendAnalyticsEvent(VenmoAnalytics.TOKENIZE_FAILED); + callback.onVenmoResult(venmoResult); + } } diff --git a/Venmo/src/test/java/com/braintreepayments/api/VenmoAnalyticsUnitTest.kt b/Venmo/src/test/java/com/braintreepayments/api/VenmoAnalyticsUnitTest.kt index 81c9334c34..a8e0a97fa9 100644 --- a/Venmo/src/test/java/com/braintreepayments/api/VenmoAnalyticsUnitTest.kt +++ b/Venmo/src/test/java/com/braintreepayments/api/VenmoAnalyticsUnitTest.kt @@ -9,18 +9,18 @@ class VenmoAnalyticsUnitTest { fun testAnalyticsEvents_sendsExpectedEventNames() { assertEquals( "venmo:tokenize:app-switch:canceled", - VenmoAnalytics.APP_SWITCH_CANCELED.event + VenmoAnalytics.APP_SWITCH_CANCELED ) assertEquals( "venmo:tokenize:app-switch:failed", - VenmoAnalytics.APP_SWITCH_FAILED.event + VenmoAnalytics.APP_SWITCH_FAILED ) assertEquals( "venmo:tokenize:app-switch:succeeded", - VenmoAnalytics.APP_SWITCH_SUCCEEDED.event + VenmoAnalytics.APP_SWITCH_SUCCEEDED ) - assertEquals("venmo:tokenize:failed", VenmoAnalytics.TOKENIZE_FAILED.event) - assertEquals("venmo:tokenize:started", VenmoAnalytics.TOKENIZE_STARTED.event) - assertEquals("venmo:tokenize:succeeded", VenmoAnalytics.TOKENIZE_SUCCEEDED.event) + assertEquals("venmo:tokenize:failed", VenmoAnalytics.TOKENIZE_FAILED) + assertEquals("venmo:tokenize:started", VenmoAnalytics.TOKENIZE_STARTED) + assertEquals("venmo:tokenize:succeeded", VenmoAnalytics.TOKENIZE_SUCCEEDED) } } diff --git a/Venmo/src/test/java/com/braintreepayments/api/VenmoClientUnitTest.java b/Venmo/src/test/java/com/braintreepayments/api/VenmoClientUnitTest.java index 12287c463c..38e5f2e3ae 100644 --- a/Venmo/src/test/java/com/braintreepayments/api/VenmoClientUnitTest.java +++ b/Venmo/src/test/java/com/braintreepayments/api/VenmoClientUnitTest.java @@ -4,7 +4,6 @@ import static org.junit.Assert.assertTrue; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyString; -import static org.mockito.ArgumentMatchers.endsWith; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.ArgumentMatchers.same; import static org.mockito.Mockito.inOrder; @@ -77,19 +76,6 @@ public void showVenmoInGooglePlayStore_opensVenmoAppStoreURL() { "https://play.google.com/store/apps/details?id=com.venmo"); } - @Test - public void showVenmoInGooglePlayStore_sendsAnalyticsEvent() { - VenmoClient sut = - new VenmoClient(braintreeClient, venmoApi, sharedPrefsWriter, deviceInspector); - - sut.showVenmoInGooglePlayStore(activity); - - ArgumentCaptor captor = ArgumentCaptor.forClass(Intent.class); - - verify(activity).startActivity(captor.capture()); - verify(braintreeClient).sendAnalyticsEvent("android.pay-with-venmo.app-store.invoked"); - } - @Test public void createPaymentAuthRequest_whenCreatePaymentContextFails_collectAddressWithEcdDisabled() { BraintreeClient braintreeClient = new MockBraintreeClientBuilder() @@ -117,7 +103,7 @@ public void createPaymentAuthRequest_whenCreatePaymentContextFails_collectAddres sut.createPaymentAuthRequest(activity, request, venmoPaymentAuthRequestCallback); verify(venmoPaymentAuthRequestCallback).onVenmoPaymentAuthRequest(captor.capture()); - verify(braintreeClient).sendAnalyticsEvent("pay-with-venmo.app-switch.failed"); + verify(braintreeClient).sendAnalyticsEvent(VenmoAnalytics.TOKENIZE_FAILED); VenmoPaymentAuthRequest paymentAuthRequest = captor.getValue(); assertTrue(paymentAuthRequest instanceof VenmoPaymentAuthRequest.Failure); assertEquals( @@ -149,12 +135,12 @@ public void createPaymentAuthRequest_whenCreatePaymentContextSucceeds_createsVen sut.createPaymentAuthRequest(activity, request, venmoPaymentAuthRequestCallback); InOrder inOrder = Mockito.inOrder(venmoPaymentAuthRequestCallback, braintreeClient); + inOrder.verify(braintreeClient).sendAnalyticsEvent(VenmoAnalytics.TOKENIZE_STARTED); ArgumentCaptor captor = ArgumentCaptor.forClass(VenmoPaymentAuthRequest.class); inOrder.verify(venmoPaymentAuthRequestCallback).onVenmoPaymentAuthRequest(captor.capture()); - inOrder.verify(braintreeClient).sendAnalyticsEvent("pay-with-venmo.app-switch.started"); VenmoPaymentAuthRequest paymentAuthRequest = captor.getValue(); assertTrue(paymentAuthRequest instanceof VenmoPaymentAuthRequest.ReadyToLaunch); @@ -186,7 +172,7 @@ public void createPaymentAuthRequest_whenConfigurationException_forwardsExceptio VenmoPaymentAuthRequest paymentAuthRequest = captor.getValue(); assertTrue(paymentAuthRequest instanceof VenmoPaymentAuthRequest.Failure); assertEquals("Configuration fetching error", ((VenmoPaymentAuthRequest.Failure) paymentAuthRequest).getError().getMessage()); - verify(braintreeClient).sendAnalyticsEvent("pay-with-venmo.app-switch.failed"); + verify(braintreeClient).sendAnalyticsEvent(VenmoAnalytics.TOKENIZE_FAILED); } @Test @@ -209,7 +195,7 @@ public void createPaymentAuthRequest_whenVenmoNotEnabled_forwardsExceptionToList VenmoPaymentAuthRequest paymentAuthRequest = captor.getValue(); assertTrue(paymentAuthRequest instanceof VenmoPaymentAuthRequest.Failure); assertEquals("Venmo is not enabled", ((VenmoPaymentAuthRequest.Failure) paymentAuthRequest).getError().getMessage()); - verify(braintreeClient).sendAnalyticsEvent("pay-with-venmo.app-switch.failed"); + verify(braintreeClient).sendAnalyticsEvent(VenmoAnalytics.TOKENIZE_FAILED); } @Test @@ -230,13 +216,14 @@ public void createPaymentAuthRequest_whenVenmoNotInstalled_forwardsExceptionToLi verify(deviceInspector).isVenmoAppSwitchAvailable(same(activity)); + verify(braintreeClient).sendAnalyticsEvent(VenmoAnalytics.APP_SWITCH_FAILED); ArgumentCaptor captor = ArgumentCaptor.forClass(VenmoPaymentAuthRequest.class); verify(venmoPaymentAuthRequestCallback).onVenmoPaymentAuthRequest(captor.capture()); VenmoPaymentAuthRequest paymentAuthRequest = captor.getValue(); assertTrue(paymentAuthRequest instanceof VenmoPaymentAuthRequest.Failure); assertEquals("Venmo is not installed", ((VenmoPaymentAuthRequest.Failure) paymentAuthRequest).getError().getMessage()); - verify(braintreeClient).sendAnalyticsEvent("pay-with-venmo.app-switch.failed"); + verify(braintreeClient).sendAnalyticsEvent(VenmoAnalytics.TOKENIZE_FAILED); } @Test @@ -323,32 +310,7 @@ public void createPaymentAuthRequest_sendsAnalyticsEvent() { new VenmoClient(braintreeClient, venmoApi, sharedPrefsWriter, deviceInspector); sut.createPaymentAuthRequest(activity, request, venmoPaymentAuthRequestCallback); - verify(braintreeClient).sendAnalyticsEvent("pay-with-venmo.selected"); - } - - @Test - public void createPaymentAuthRequest_sendsAnalyticsEventWhenStarted() { - BraintreeClient braintreeClient = new MockBraintreeClientBuilder() - .configuration(venmoEnabledConfiguration) - .authorizationSuccess(clientToken) - .build(); - - VenmoApi venmoApi = new MockVenmoApiBuilder() - .createPaymentContextSuccess("venmo-payment-context-id") - .build(); - - VenmoRequest request = new VenmoRequest(VenmoPaymentMethodUsage.SINGLE_USE); - request.setProfileId(null); - request.setShouldVault(false); - - when(deviceInspector.isVenmoAppSwitchAvailable(activity)).thenReturn(true); - - VenmoClient sut = - new VenmoClient(braintreeClient, venmoApi, sharedPrefsWriter, deviceInspector); - sut.createPaymentAuthRequest(activity, request, venmoPaymentAuthRequestCallback); - - verify(braintreeClient).sendAnalyticsEvent("pay-with-venmo.selected"); - verify(braintreeClient).sendAnalyticsEvent("pay-with-venmo.app-switch.started"); + verify(braintreeClient).sendAnalyticsEvent(VenmoAnalytics.TOKENIZE_STARTED); } @Test @@ -453,8 +415,8 @@ public void createPaymentAuthRequest_sendsAnalyticsEventWhenUnavailableAndPostEx assertTrue(paymentAuthRequest instanceof VenmoPaymentAuthRequest.Failure); assertEquals("Venmo is not installed", ((VenmoPaymentAuthRequest.Failure) paymentAuthRequest).getError().getMessage()); - order.verify(braintreeClient).sendAnalyticsEvent("pay-with-venmo.selected"); - order.verify(braintreeClient).sendAnalyticsEvent("pay-with-venmo.app-switch.failed"); + order.verify(braintreeClient).sendAnalyticsEvent(VenmoAnalytics.TOKENIZE_STARTED); + order.verify(braintreeClient).sendAnalyticsEvent(VenmoAnalytics.APP_SWITCH_FAILED); } @Test @@ -482,7 +444,7 @@ public void createPaymentAuthRequest_whenVenmoApiError_forwardsErrorToListener_a VenmoPaymentAuthRequest paymentAuthRequest = captor.getValue(); assertTrue(paymentAuthRequest instanceof VenmoPaymentAuthRequest.Failure); assertEquals(graphQLError, ((VenmoPaymentAuthRequest.Failure) paymentAuthRequest).getError()); - verify(braintreeClient).sendAnalyticsEvent("pay-with-venmo.app-switch.failed"); + verify(braintreeClient).sendAnalyticsEvent(VenmoAnalytics.TOKENIZE_FAILED); } @Test @@ -567,6 +529,55 @@ public void tokenize_withPaymentContextId_requestFromVenmoApi() { verify(venmoApi).createNonceFromPaymentContext(eq("payment-context-id"), any(VenmoInternalCallback.class)); + + verify(braintreeClient).sendAnalyticsEvent(VenmoAnalytics.APP_SWITCH_SUCCEEDED); + } + + @Test + public void tokenize_withPaymentAuthResultError_whenUserCanceledError_returnsCancelAndSendsAnalytics() { + BraintreeClient braintreeClient = new MockBraintreeClientBuilder() + .configuration(venmoEnabledConfiguration) + .authorizationSuccess(clientToken) + .build(); + + VenmoClient sut = + new VenmoClient(braintreeClient, venmoApi, sharedPrefsWriter, deviceInspector); + + VenmoPaymentAuthResult venmoPaymentAuthResult = + new VenmoPaymentAuthResult(null, null, null, new UserCanceledException("User canceled Venmo.")); + sut.tokenize(venmoPaymentAuthResult, venmoTokenizeCallback); + + ArgumentCaptor captor = ArgumentCaptor.forClass(VenmoResult.class); + verify(venmoTokenizeCallback).onVenmoResult(captor.capture()); + + VenmoResult result = captor.getValue(); + assertTrue(result instanceof VenmoResult.Cancel); + verify(braintreeClient).sendAnalyticsEvent(VenmoAnalytics.APP_SWITCH_CANCELED); + + } + + @Test + public void tokenize_withPaymentAuthResultError_returnsErrorAndSendsAnalytics() { + BraintreeClient braintreeClient = new MockBraintreeClientBuilder() + .configuration(venmoEnabledConfiguration) + .authorizationSuccess(clientToken) + .build(); + + VenmoClient sut = + new VenmoClient(braintreeClient, venmoApi, sharedPrefsWriter, deviceInspector); + + BraintreeException error = new BraintreeException("Error"); + VenmoPaymentAuthResult venmoPaymentAuthResult = + new VenmoPaymentAuthResult(null, null, null, error); + sut.tokenize(venmoPaymentAuthResult, venmoTokenizeCallback); + + ArgumentCaptor captor = ArgumentCaptor.forClass(VenmoResult.class); + verify(venmoTokenizeCallback).onVenmoResult(captor.capture()); + + VenmoResult result = captor.getValue(); + assertTrue(result instanceof VenmoResult.Failure); + assertEquals(error, ((VenmoResult.Failure) result).getError()); + verify(braintreeClient).sendAnalyticsEvent(VenmoAnalytics.TOKENIZE_FAILED); } @Test @@ -599,7 +610,7 @@ public void tokenize_onGraphQLPostSuccess_returnsNonceToListener_andSendsAnalyti assertEquals("fake-venmo-nonce", nonce.getString()); assertEquals("venmojoe", nonce.getUsername()); - verify(braintreeClient).sendAnalyticsEvent("pay-with-venmo.app-switch.success"); + verify(braintreeClient).sendAnalyticsEvent(VenmoAnalytics.TOKENIZE_SUCCEEDED); } @Test @@ -629,7 +640,7 @@ public void tokenize_onGraphQLPostFailure_forwardsExceptionToListener_andSendsAn VenmoResult result = captor.getValue(); assertTrue(result instanceof VenmoResult.Failure); assertEquals(graphQLError, ((VenmoResult.Failure) result).getError()); - verify(braintreeClient).sendAnalyticsEvent("pay-with-venmo.app-switch.failure"); + verify(braintreeClient).sendAnalyticsEvent(VenmoAnalytics.TOKENIZE_FAILED); } @Test @@ -685,7 +696,7 @@ public void tokenize_postsPaymentMethodNonceOnSuccess() { } @Test - public void tokenize_sendsAnalyticsEventOnSuccess() { + public void tokenize_sendsAnalyticsEventOnSuccessfulStart() { VenmoClient sut = new VenmoClient(braintreeClient, venmoApi, sharedPrefsWriter, deviceInspector); @@ -694,7 +705,7 @@ public void tokenize_sendsAnalyticsEventOnSuccess() { null); sut.tokenize(venmoPaymentAuthResult, venmoTokenizeCallback); - verify(braintreeClient).sendAnalyticsEvent("pay-with-venmo.app-switch.success"); + verify(braintreeClient).sendAnalyticsEvent(VenmoAnalytics.APP_SWITCH_SUCCEEDED); } @Test @@ -707,7 +718,7 @@ public void tokenize_sendsAnalyticsEventOnCancel() { new UserCanceledException("User canceled Venmo.")); sut.tokenize(venmoPaymentAuthResult, venmoTokenizeCallback); - verify(braintreeClient).sendAnalyticsEvent("pay-with-venmo.app-switch.canceled"); + verify(braintreeClient).sendAnalyticsEvent(VenmoAnalytics.APP_SWITCH_CANCELED); } @Test @@ -814,7 +825,7 @@ public void tokenize_withSuccessfulVaultCall_forwardsResultToActivityResultListe assertTrue(result instanceof VenmoResult.Success); VenmoAccountNonce nonce = ((VenmoResult.Success) result).getNonce(); assertEquals(venmoAccountNonce, nonce); - verify(braintreeClient).sendAnalyticsEvent(endsWith("pay-with-venmo.vault.success")); + verify(braintreeClient).sendAnalyticsEvent(VenmoAnalytics.TOKENIZE_SUCCEEDED); } @Test @@ -854,7 +865,7 @@ public void tokenize_withPaymentContext_withSuccessfulVaultCall_forwardsNonceToC assertTrue(result instanceof VenmoResult.Success); VenmoAccountNonce nonce = ((VenmoResult.Success) result).getNonce(); assertEquals(venmoAccountNonce, nonce); - verify(braintreeClient).sendAnalyticsEvent(endsWith("pay-with-venmo.vault.success")); + verify(braintreeClient).sendAnalyticsEvent(VenmoAnalytics.TOKENIZE_SUCCEEDED); } @Test @@ -887,7 +898,7 @@ public void tokenize_withFailedVaultCall_forwardsErrorToActivityResultListener_a VenmoResult result = captor.getValue(); assertTrue(result instanceof VenmoResult.Failure); assertEquals(error, ((VenmoResult.Failure) result).getError()); - verify(braintreeClient).sendAnalyticsEvent(endsWith("pay-with-venmo.vault.failed")); + verify(braintreeClient).sendAnalyticsEvent(VenmoAnalytics.TOKENIZE_FAILED); } @Test @@ -927,6 +938,6 @@ public void tokenize_withPaymentContext_withFailedVaultCall_forwardsErrorToCallb VenmoResult result = captor.getValue(); assertTrue(result instanceof VenmoResult.Failure); assertEquals(error, ((VenmoResult.Failure) result).getError()); - verify(braintreeClient).sendAnalyticsEvent(endsWith("pay-with-venmo.vault.failed")); + verify(braintreeClient).sendAnalyticsEvent(VenmoAnalytics.TOKENIZE_FAILED); } } \ No newline at end of file