Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Venmo with FPTI Analytics Events #846

Merged
merged 9 commits into from
Dec 11, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 20 additions & 21 deletions Venmo/src/main/java/com/braintreepayments/api/VenmoClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,25 +80,26 @@ 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.event);
braintreeClient.getConfiguration((configuration, error) -> {
if (configuration == null && error != null) {
callback.onVenmoPaymentAuthRequest(new VenmoPaymentAuthRequest.Failure(error));
braintreeClient.sendAnalyticsEvent("pay-with-venmo.app-switch.failed");
braintreeClient.sendAnalyticsEvent(VenmoAnalytics.TOKENIZE_FAILED.event);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We used "app-switch" failed more previously, but to be more accurate, I updated this to only be "app switch failed" for errors returned from actual app switching, or if Venmo is not installed.

return;
}

String exceptionMessage = null;
if (!configuration.isVenmoEnabled()) {
exceptionMessage = "Venmo is not enabled";
braintreeClient.sendAnalyticsEvent(VenmoAnalytics.TOKENIZE_FAILED.event);
} else if (!deviceInspector.isVenmoAppSwitchAvailable(activity)) {
exceptionMessage = "Venmo is not installed";
braintreeClient.sendAnalyticsEvent(VenmoAnalytics.APP_SWITCH_FAILED.event);
}

if (exceptionMessage != null) {
callback.onVenmoPaymentAuthRequest(
new VenmoPaymentAuthRequest.Failure(new AppSwitchNotAvailableException(exceptionMessage)));
braintreeClient.sendAnalyticsEvent("pay-with-venmo.app-switch.failed");
return;
}

Expand All @@ -110,7 +111,7 @@ public void createPaymentAuthRequest(@NonNull final FragmentActivity activity,
callback.onVenmoPaymentAuthRequest(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");
braintreeClient.sendAnalyticsEvent(VenmoAnalytics.TOKENIZE_FAILED.event);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
braintreeClient.sendAnalyticsEvent(VenmoAnalytics.TOKENIZE_FAILED.event);
braintreeClient.sendAnalyticsEvent(VenmoAnalytics.TOKENIZE_FAILED);

nit: Would it be better to convert VenmoAnalytics.TOKENIZE_FAILED to a String and remove the .event property access?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could rename the "event" property in this enum, or what you're describing sounds like a class with a companion object filled with string constants rather than an enum - do you think that would be better?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I'd go companion const val to reduce some of the boilerplate. If we were performing a switch / when on it i'd keep it an enum, but for braintreeClient.sendAnalyticsEvent() a plain string value is equally sufficient.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool - updated 👍

return;
}

Expand All @@ -128,7 +129,7 @@ public void createPaymentAuthRequest(@NonNull final FragmentActivity activity,
paymentContextId, callback);
} else {
callback.onVenmoPaymentAuthRequest(new VenmoPaymentAuthRequest.Failure(exception));
braintreeClient.sendAnalyticsEvent("pay-with-venmo.app-switch.failed");
braintreeClient.sendAnalyticsEvent(VenmoAnalytics.TOKENIZE_FAILED.event);
}
});
});
Expand All @@ -150,7 +151,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");
}

/**
Expand All @@ -166,7 +166,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.event);

final boolean isClientTokenAuth = (braintreeClient.getAuthorization() instanceof ClientToken);

Expand All @@ -181,19 +181,19 @@ public void tokenize(@NonNull final VenmoPaymentAuthResult venmoPaymentAuthResul
vaultVenmoAccountNonce(nonce.getString(),
(venmoAccountNonce, vaultError) -> {
if (venmoAccountNonce != null) {
braintreeClient.sendAnalyticsEvent(VenmoAnalytics.TOKENIZE_SUCCEEDED.event);
callback.onVenmoResult(new VenmoResult.Success(venmoAccountNonce));
} else if (vaultError != null) {
braintreeClient.sendAnalyticsEvent(VenmoAnalytics.TOKENIZE_FAILED.event);
callback.onVenmoResult(new VenmoResult.Failure(vaultError));
}
});
} else {
braintreeClient.sendAnalyticsEvent(
"pay-with-venmo.app-switch.failure");
braintreeClient.sendAnalyticsEvent(VenmoAnalytics.TOKENIZE_SUCCEEDED.event);
callback.onVenmoResult(new VenmoResult.Success(nonce));
}
} else if (error != null) {
braintreeClient.sendAnalyticsEvent(
"pay-with-venmo.app-switch.failure");
braintreeClient.sendAnalyticsEvent(VenmoAnalytics.TOKENIZE_FAILED.event);
callback.onVenmoResult(new VenmoResult.Failure(error));
}
});
Expand All @@ -205,36 +205,35 @@ public void tokenize(@NonNull final VenmoPaymentAuthResult venmoPaymentAuthResul
if (shouldVault && isClientTokenAuth) {
vaultVenmoAccountNonce(nonce, (venmoAccountNonce, error) -> {
if (venmoAccountNonce != null) {
braintreeClient.sendAnalyticsEvent(VenmoAnalytics.TOKENIZE_SUCCEEDED.event);
callback.onVenmoResult(new VenmoResult.Success(venmoAccountNonce));
} else if (error != null) {
braintreeClient.sendAnalyticsEvent(VenmoAnalytics.TOKENIZE_FAILED.event);
callback.onVenmoResult(new VenmoResult.Failure(error));
}
});
} else {
String venmoUsername = venmoPaymentAuthResult.getVenmoUsername();
VenmoAccountNonce venmoAccountNonce =
new VenmoAccountNonce(nonce, venmoUsername, false);
braintreeClient.sendAnalyticsEvent(VenmoAnalytics.TOKENIZE_SUCCEEDED.event);
callback.onVenmoResult(new VenmoResult.Success(venmoAccountNonce));
}

}
} else if (venmoPaymentAuthResult.getError() != null) {
if (venmoPaymentAuthResult.getError() instanceof UserCanceledException) {
braintreeClient.sendAnalyticsEvent("pay-with-venmo.app-switch.canceled");
braintreeClient.sendAnalyticsEvent(VenmoAnalytics.APP_SWITCH_CANCELED.event);
callback.onVenmoResult(VenmoResult.Cancel.INSTANCE);
} else {
braintreeClient.sendAnalyticsEvent(VenmoAnalytics.TOKENIZE_FAILED.event);
callback.onVenmoResult(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));
}

/**
Expand Down
Loading
Loading