-
Notifications
You must be signed in to change notification settings - Fork 42
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
Migrate PayPalWebClient Analytics Logic Into PayPalWebAnalytics Class #300
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package com.paypal.android.paypalwebpayments | ||
|
||
import com.paypal.android.corepayments.analytics.AnalyticsService | ||
|
||
@Suppress("TooManyFunctions") | ||
internal class PayPalWebAnalytics(private val analyticsService: AnalyticsService) { | ||
|
||
fun notifyCheckoutStarted(orderId: String) { | ||
val eventName = "paypal-web-payments:checkout:started" | ||
analyticsService.sendAnalyticsEvent(eventName, orderId) | ||
} | ||
|
||
fun notifyCheckoutAuthChallengeStarted(orderId: String) { | ||
val eventName = "paypal-web-payments:checkout:auth-challenge-started" | ||
analyticsService.sendAnalyticsEvent(eventName, orderId) | ||
} | ||
|
||
fun notifyCheckoutAuthChallengeSucceeded(orderId: String?) { | ||
val eventName = "paypal-web-payments:checkout:auth-challenge-succeeded" | ||
analyticsService.sendAnalyticsEvent(eventName, orderId) | ||
} | ||
|
||
fun notifyCheckoutAuthChallengeFailed(orderId: String?) { | ||
val eventName = "paypal-web-payments:checkout:auth-challenge-failed" | ||
analyticsService.sendAnalyticsEvent(eventName, orderId) | ||
} | ||
|
||
fun notifyCheckoutAuthChallengeCanceled(orderId: String?) { | ||
val eventName = "paypal-web-payments:checkout:auth-challenge-canceled" | ||
analyticsService.sendAnalyticsEvent(eventName, orderId) | ||
} | ||
|
||
fun notifyVaultStarted(setupTokenId: String) { | ||
val eventName = "paypal-web-payments:vault:started" | ||
analyticsService.sendAnalyticsEvent(eventName, setupTokenId) | ||
} | ||
|
||
fun notifyVaultAuthChallengeStarted(setupTokenId: String) { | ||
val eventName = "paypal-web-payments:vault:auth-challenge-started" | ||
analyticsService.sendAnalyticsEvent(eventName, setupTokenId) | ||
} | ||
|
||
fun notifyVaultAuthChallengeSucceeded(setupTokenId: String?) { | ||
val eventName = "paypal-web-payments:vault:auth-challenge-succeeded" | ||
analyticsService.sendAnalyticsEvent(eventName, setupTokenId) | ||
} | ||
|
||
fun notifyVaultAuthChallengeFailed(setupTokenId: String?) { | ||
val eventName = "paypal-web-payments:vault:auth-challenge-failed" | ||
analyticsService.sendAnalyticsEvent(eventName, setupTokenId) | ||
} | ||
|
||
fun notifyVaultAuthChallengeCanceled(setupTokenId: String?) { | ||
val eventName = "paypal-web-payments:vault:auth-challenge-canceled" | ||
analyticsService.sendAnalyticsEvent(eventName, setupTokenId) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,6 @@ import android.content.Intent | |
import android.util.Log | ||
import androidx.activity.ComponentActivity | ||
import com.paypal.android.corepayments.CoreConfig | ||
import com.paypal.android.corepayments.PayPalSDKError | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How come you don't need this now? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks like this import was only used in a function declaration e.g. private fun notifyWebCheckoutFailure(error: PayPalSDKError, orderId: String?) {} We removed those methods and the import got flagged by There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it not needed because the launcher imports |
||
import com.paypal.android.corepayments.analytics.AnalyticsService | ||
|
||
// NEXT MAJOR VERSION: consider renaming this module to PayPalWebClient since | ||
|
@@ -15,7 +14,7 @@ import com.paypal.android.corepayments.analytics.AnalyticsService | |
* Use this client to approve an order with a [PayPalWebCheckoutRequest]. | ||
*/ | ||
class PayPalWebCheckoutClient internal constructor( | ||
private val analyticsService: AnalyticsService, | ||
private val analytics: PayPalWebAnalytics, | ||
private val payPalWebLauncher: PayPalWebLauncher | ||
) { | ||
|
||
|
@@ -27,7 +26,7 @@ class PayPalWebCheckoutClient internal constructor( | |
* @param urlScheme the custom URl scheme used to return to your app from a browser switch flow | ||
*/ | ||
constructor(context: Context, configuration: CoreConfig, urlScheme: String) : this( | ||
AnalyticsService(context.applicationContext, configuration), | ||
PayPalWebAnalytics(AnalyticsService(context.applicationContext, configuration)), | ||
PayPalWebLauncher(urlScheme, configuration), | ||
) | ||
|
||
|
@@ -50,16 +49,16 @@ class PayPalWebCheckoutClient internal constructor( | |
activity: ComponentActivity, | ||
request: PayPalWebCheckoutRequest | ||
): PayPalPresentAuthChallengeResult { | ||
analyticsService.sendAnalyticsEvent("paypal-web-payments:started", request.orderId) | ||
analytics.notifyCheckoutStarted(request.orderId) | ||
val result = payPalWebLauncher.launchPayPalWebCheckout(activity, request) | ||
when (result) { | ||
is PayPalPresentAuthChallengeResult.Failure -> { | ||
notifyWebCheckoutFailure(result.error, request.orderId) | ||
analytics.notifyCheckoutAuthChallengeFailed(request.orderId) | ||
listener?.onPayPalWebFailure(result.error) | ||
} | ||
|
||
is PayPalPresentAuthChallengeResult.Success -> { | ||
// TODO: track success with analytics | ||
} | ||
is PayPalPresentAuthChallengeResult.Success -> | ||
analytics.notifyCheckoutAuthChallengeStarted(request.orderId) | ||
} | ||
return result | ||
} | ||
|
@@ -73,72 +72,64 @@ class PayPalWebCheckoutClient internal constructor( | |
activity: ComponentActivity, | ||
request: PayPalWebVaultRequest | ||
): PayPalPresentAuthChallengeResult { | ||
analyticsService.sendAnalyticsEvent("paypal-web-payments:vault-wo-purchase:started") | ||
analytics.notifyVaultStarted(request.setupTokenId) | ||
val result = payPalWebLauncher.launchPayPalWebVault(activity, request) | ||
when (result) { | ||
is PayPalPresentAuthChallengeResult.Failure -> { | ||
notifyVaultFailure(result.error) | ||
analytics.notifyVaultAuthChallengeFailed(request.setupTokenId) | ||
vaultListener?.onPayPalWebVaultFailure(result.error) | ||
} | ||
|
||
is PayPalPresentAuthChallengeResult.Success -> { | ||
// TODO: track success with analytics | ||
} | ||
is PayPalPresentAuthChallengeResult.Success -> | ||
analytics.notifyVaultAuthChallengeStarted(request.setupTokenId) | ||
} | ||
return result | ||
} | ||
|
||
fun completeAuthChallenge(intent: Intent, authState: String): PayPalWebStatus { | ||
val status = payPalWebLauncher.completeAuthRequest(intent, authState) | ||
when (status) { | ||
is PayPalWebStatus.CheckoutSuccess -> notifyWebCheckoutSuccess(status.result) | ||
is PayPalWebStatus.CheckoutError -> status.run { | ||
notifyWebCheckoutFailure(error, orderId) | ||
is PayPalWebStatus.CheckoutSuccess -> { | ||
analytics.notifyCheckoutAuthChallengeSucceeded(status.result.orderId) | ||
listener?.onPayPalWebSuccess(status.result) | ||
} | ||
|
||
is PayPalWebStatus.CheckoutError -> { | ||
analytics.notifyCheckoutAuthChallengeFailed(status.orderId) | ||
listener?.onPayPalWebFailure(status.error) | ||
} | ||
|
||
is PayPalWebStatus.CheckoutCanceled -> { | ||
analytics.notifyCheckoutAuthChallengeCanceled(status.orderId) | ||
listener?.onPayPalWebCanceled() | ||
} | ||
|
||
is PayPalWebStatus.CheckoutCanceled -> notifyWebCheckoutCancelation(status.orderId) | ||
is PayPalWebStatus.VaultSuccess -> notifyVaultSuccess(status.result) | ||
is PayPalWebStatus.VaultError -> notifyVaultFailure(status.error) | ||
PayPalWebStatus.VaultCanceled -> notifyVaultCancelation() | ||
is PayPalWebStatus.VaultSuccess -> { | ||
// TODO: see if we can get setup token id from somewhere | ||
analytics.notifyVaultAuthChallengeSucceeded(null) | ||
vaultListener?.onPayPalWebVaultSuccess(status.result) | ||
} | ||
is PayPalWebStatus.VaultError -> { | ||
// TODO: see if we can get setup token id from somewhere | ||
analytics.notifyVaultAuthChallengeFailed(null) | ||
vaultListener?.onPayPalWebVaultFailure(status.error) | ||
} | ||
PayPalWebStatus.VaultCanceled -> { | ||
// TODO: see if we can get setup token id from somewhere | ||
analytics.notifyVaultAuthChallengeCanceled(null) | ||
vaultListener?.onPayPalWebVaultCanceled() | ||
} | ||
is PayPalWebStatus.UnknownError -> { | ||
Log.d("PayPalSDK", "An unknown error occurred: ${status.error.message}") | ||
} | ||
|
||
PayPalWebStatus.NoResult -> { | ||
// ignore | ||
} | ||
} | ||
return status | ||
} | ||
|
||
private fun notifyWebCheckoutSuccess(result: PayPalWebCheckoutResult) { | ||
analyticsService.sendAnalyticsEvent("paypal-web-payments:succeeded", result.orderId) | ||
listener?.onPayPalWebSuccess(result) | ||
} | ||
|
||
private fun notifyWebCheckoutFailure(error: PayPalSDKError, orderId: String?) { | ||
analyticsService.sendAnalyticsEvent("paypal-web-payments:failed", orderId) | ||
listener?.onPayPalWebFailure(error) | ||
} | ||
|
||
private fun notifyWebCheckoutCancelation(orderId: String?) { | ||
analyticsService.sendAnalyticsEvent("paypal-web-payments:browser-login:canceled", orderId) | ||
listener?.onPayPalWebCanceled() | ||
} | ||
|
||
private fun notifyVaultSuccess(result: PayPalWebVaultResult) { | ||
analyticsService.sendAnalyticsEvent("paypal-web-payments:vault-wo-purchase:succeeded") | ||
vaultListener?.onPayPalWebVaultSuccess(result) | ||
} | ||
|
||
private fun notifyVaultFailure(error: PayPalSDKError) { | ||
analyticsService.sendAnalyticsEvent("paypal-web-payments:vault-wo-purchase:failed") | ||
vaultListener?.onPayPalWebVaultFailure(error) | ||
} | ||
|
||
private fun notifyVaultCancelation() { | ||
analyticsService.sendAnalyticsEvent("paypal-web-payments:vault-wo-purchase:canceled") | ||
vaultListener?.onPayPalWebVaultCanceled() | ||
} | ||
|
||
/** | ||
* Call this method at the end of the web checkout flow to clear out all observers and listeners | ||
*/ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Marking analytics related classes
internal
. I forgot to add this in the previous PR so adding it here now.