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

Remove Google Pay launcher init events #9553

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,9 @@ import androidx.compose.ui.platform.LocalContext
import androidx.fragment.app.Fragment
import androidx.lifecycle.compose.LocalLifecycleOwner
import androidx.lifecycle.lifecycleScope
import com.stripe.android.PaymentConfiguration
import com.stripe.android.core.networking.AnalyticsRequestExecutor
import com.stripe.android.core.networking.DefaultAnalyticsRequestExecutor
import com.stripe.android.googlepaylauncher.GooglePayLauncher.Result
import com.stripe.android.model.PaymentIntent
import com.stripe.android.model.SetupIntent
import com.stripe.android.networking.PaymentAnalyticsEvent
import com.stripe.android.networking.PaymentAnalyticsRequestFactory
import com.stripe.android.payments.core.analytics.ErrorReporter
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.flow.first
Expand All @@ -41,8 +36,6 @@ class GooglePayLauncher internal constructor(
private val readyCallback: ReadyCallback,
private val activityResultLauncher: ActivityResultLauncher<GooglePayLauncherContract.Args>,
private val googlePayRepositoryFactory: (GooglePayEnvironment) -> GooglePayRepository,
paymentAnalyticsRequestFactory: PaymentAnalyticsRequestFactory,
analyticsRequestExecutor: AnalyticsRequestExecutor
) {
private var isReady = false

Expand Down Expand Up @@ -86,12 +79,6 @@ class GooglePayLauncher internal constructor(
)
)
},
PaymentAnalyticsRequestFactory(
activity,
PaymentConfiguration.getInstance(activity).publishableKey,
setOf(PRODUCT_USAGE)
),
DefaultAnalyticsRequestExecutor()
)

/**
Expand Down Expand Up @@ -133,19 +120,9 @@ class GooglePayLauncher internal constructor(
)
)
},
paymentAnalyticsRequestFactory = PaymentAnalyticsRequestFactory(
context = fragment.requireContext(),
publishableKey = PaymentConfiguration.getInstance(fragment.requireContext()).publishableKey,
defaultProductUsageTokens = setOf(PRODUCT_USAGE),
),
analyticsRequestExecutor = DefaultAnalyticsRequestExecutor(),
)

init {
analyticsRequestExecutor.executeAsync(
paymentAnalyticsRequestFactory.createRequest(PaymentAnalyticsEvent.GooglePayLauncherInit)
)

lifecycleScope.launch {
val repository = googlePayRepositoryFactory(config.environment)
readyCallback.onReady(
Expand Down Expand Up @@ -389,12 +366,6 @@ fun rememberGooglePayLauncher(
)
)
},
PaymentAnalyticsRequestFactory(
context,
PaymentConfiguration.getInstance(context).publishableKey,
setOf(GooglePayLauncher.PRODUCT_USAGE)
),
DefaultAnalyticsRequestExecutor()
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,8 @@ import androidx.compose.ui.platform.LocalContext
import androidx.fragment.app.Fragment
import androidx.lifecycle.compose.LocalLifecycleOwner
import androidx.lifecycle.lifecycleScope
import com.stripe.android.PaymentConfiguration
import com.stripe.android.core.networking.AnalyticsRequestExecutor
import com.stripe.android.core.networking.DefaultAnalyticsRequestExecutor
import com.stripe.android.googlepaylauncher.GooglePayPaymentMethodLauncher.Result
import com.stripe.android.model.PaymentMethod
import com.stripe.android.networking.PaymentAnalyticsEvent
import com.stripe.android.networking.PaymentAnalyticsRequestFactory
import com.stripe.android.payments.core.analytics.ErrorReporter
import dagger.assisted.Assisted
import dagger.assisted.AssistedInject
Expand All @@ -45,14 +40,7 @@ class GooglePayPaymentMethodLauncher @AssistedInject internal constructor(
@Assisted private val readyCallback: ReadyCallback,
@Assisted private val activityResultLauncher: ActivityResultLauncher<GooglePayPaymentMethodLauncherContractV2.Args>,
@Assisted private val skipReadyCheck: Boolean,
context: Context,
private val googlePayRepositoryFactory: (GooglePayEnvironment) -> GooglePayRepository,
paymentAnalyticsRequestFactory: PaymentAnalyticsRequestFactory = PaymentAnalyticsRequestFactory(
context,
PaymentConfiguration.getInstance(context).publishableKey,
setOf(PRODUCT_USAGE_TOKEN)
),
analyticsRequestExecutor: AnalyticsRequestExecutor = DefaultAnalyticsRequestExecutor(),
) {
private var isReady = false

Expand Down Expand Up @@ -124,7 +112,6 @@ class GooglePayPaymentMethodLauncher @AssistedInject internal constructor(
readyCallback,
activityResultLauncher,
false,
context,
googlePayRepositoryFactory = {
DefaultGooglePayRepository(
context = context,
Expand All @@ -141,10 +128,6 @@ class GooglePayPaymentMethodLauncher @AssistedInject internal constructor(
)

init {
analyticsRequestExecutor.executeAsync(
paymentAnalyticsRequestFactory.createRequest(PaymentAnalyticsEvent.GooglePayPaymentMethodLauncherInit)
)

if (!skipReadyCheck) {
lifecycleScope.launch {
val repository = googlePayRepositoryFactory(config.environment)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,6 @@ internal enum class PaymentAnalyticsEvent(val code: String) : AnalyticsEvent {

RadarSessionCreate("radar_session_create"),

GooglePayLauncherInit("googlepaylauncher_init"),
GooglePayPaymentMethodLauncherInit("googlepaypaymentmethodlauncher_init"),

CardMetadataPublishableKeyAvailable("card_metadata_pk_available"),
CardMetadataPublishableKeyUnavailable("card_metadata_pk_unavailable"),

Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
package com.stripe.android.googlepaylauncher

import androidx.activity.ComponentActivity
import androidx.lifecycle.lifecycleScope
import androidx.test.espresso.intent.rule.IntentsTestRule
import com.google.common.truth.Truth.assertThat
import com.stripe.android.ApiKeyFixtures
import com.stripe.android.googlepaylauncher.utils.LauncherIntegrationType
import com.stripe.android.googlepaylauncher.utils.runGooglePayLauncherTest
import com.stripe.android.networking.PaymentAnalyticsRequestFactory
import org.junit.Rule
import org.junit.runner.RunWith
import org.mockito.kotlin.mock
import org.robolectric.RobolectricTestRunner
import kotlin.test.Test
import kotlin.test.assertFailsWith
Expand All @@ -28,35 +23,6 @@ internal class GooglePayLauncherTest {
}
}

@Test
fun `init should fire expected event`() {
runGooglePayLauncherTest(
integrationTypes = listOf(LauncherIntegrationType.Activity),
expectResult = false,
) { activity, _ ->
val firedEvents = mutableListOf<String>()

// Have to use the internal constructor here to provide a mock request executor
// ¯\_(ツ)_/¯
GooglePayLauncher(
lifecycleScope = activity.lifecycleScope,
config = CONFIG,
readyCallback = mock(),
activityResultLauncher = mock(),
googlePayRepositoryFactory = {
FakeGooglePayRepository(value = true)
},
paymentAnalyticsRequestFactory = PaymentAnalyticsRequestFactory(
context = activity,
publishableKey = ApiKeyFixtures.FAKE_PUBLISHABLE_KEY,
),
analyticsRequestExecutor = { firedEvents += it.params["event"].toString() },
)

assertThat(firedEvents).containsExactly("stripe_android.googlepaylauncher_init")
}
}

@Test
fun `presentForPaymentIntent() should throw IllegalStateException when Google Pay is not available`() {
runGooglePayLauncherTest(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
package com.stripe.android.googlepaylauncher

import androidx.activity.ComponentActivity
import androidx.lifecycle.lifecycleScope
import androidx.test.espresso.intent.rule.IntentsTestRule
import com.google.common.truth.Truth.assertThat
import com.stripe.android.ApiKeyFixtures
import com.stripe.android.googlepaylauncher.utils.LauncherIntegrationType
import com.stripe.android.googlepaylauncher.utils.runGooglePayPaymentMethodLauncherTest
import com.stripe.android.model.PaymentMethodFixtures.CARD_PAYMENT_METHOD
import com.stripe.android.networking.PaymentAnalyticsRequestFactory
import org.junit.Rule
import org.junit.runner.RunWith
import org.mockito.kotlin.mock
import org.robolectric.RobolectricTestRunner
import kotlin.test.Test
import kotlin.test.assertFailsWith
Expand All @@ -33,34 +27,6 @@ class GooglePayPaymentMethodLauncherTest {
}
}

@Test
fun `init should fire expected event`() {
runGooglePayPaymentMethodLauncherTest(
integrationTypes = listOf(LauncherIntegrationType.Activity),
expectResult = false,
) { activity, _ ->
val firedEvents = mutableListOf<String>()

val launcher = GooglePayPaymentMethodLauncher(
lifecycleScope = activity.lifecycleScope,
config = CONFIG,
readyCallback = mock(),
activityResultLauncher = mock(),
skipReadyCheck = true,
context = activity,
googlePayRepositoryFactory = mock(),
paymentAnalyticsRequestFactory = PaymentAnalyticsRequestFactory(
context = activity,
publishableKey = ApiKeyFixtures.FAKE_PUBLISHABLE_KEY,
),
analyticsRequestExecutor = { firedEvents += it.params["event"].toString() },
)
launcher.present(currencyCode = "usd")

assertThat(firedEvents).containsExactly("stripe_android.googlepaypaymentmethodlauncher_init")
}
}

@Test
fun `present() should throw IllegalStateException when Google Pay is not available`() {
runGooglePayPaymentMethodLauncherTest(
Expand Down
Loading