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 new PMs shown, select PM, and form shown analytics for vertical mode #9127

Merged
merged 1 commit into from
Aug 27, 2024
Merged
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 @@ -128,9 +128,9 @@ internal class DefaultEventReporter @Inject internal constructor(
)
}

override fun onShowNewPaymentOptionForm() {
override fun onShowNewPaymentOptions() {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

renamed this function and the corresponding PaymentSheetEvent, because this analytic event is for mc_{complete/custom}_sheet_newpm_show. It's not actually form-specific, that was just the horizontal mode behavior.

fireEvent(
PaymentSheetEvent.ShowNewPaymentOptionForm(
PaymentSheetEvent.ShowNewPaymentOptions(
mode = mode,
linkEnabled = linkEnabled,
googlePaySupported = googlePaySupported,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ internal interface EventReporter {
fun onShowExistingPaymentOptions()

/**
* PaymentSheet is now being displayed and its first screen shows the payment method form.
* PaymentSheet is now being displayed and its first screen shows new payment methods.
*/
fun onShowNewPaymentOptionForm()
fun onShowNewPaymentOptions()

/**
* The customer has selected one of the available payment methods in the payment method form.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,12 @@ internal class PaymentSheetAnalyticsListener(
previouslyShownForm = null
previouslyInteractedForm = null
}
is AddFirstPaymentMethod, is AddAnotherPaymentMethod, is PaymentSheetScreen.VerticalMode -> {
is PaymentSheetScreen.VerticalMode -> {
eventReporter.onShowNewPaymentOptions()
}
is AddFirstPaymentMethod, is AddAnotherPaymentMethod -> {
reportFormShown(currentPaymentMethodTypeProvider())
eventReporter.onShowNewPaymentOptionForm()
eventReporter.onShowNewPaymentOptions()
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ internal sealed class PaymentSheetEvent : AnalyticsEvent {
override val additionalParams: Map<String, Any> = emptyMap()
}

class ShowNewPaymentOptionForm(
class ShowNewPaymentOptions(
mode: EventReporter.Mode,
currency: String?,
override val isDeferred: Boolean,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ internal class DefaultPaymentMethodVerticalLayoutInteractor(
private val onMandateTextUpdated: (ResolvableString?) -> Unit,
private val updateSelection: (PaymentSelection?) -> Unit,
private val isCurrentScreen: StateFlow<Boolean>,
private val reportPaymentMethodTypeSelected: (PaymentMethodCode) -> Unit,
private val reportFormShown: (PaymentMethodCode) -> Unit,
override val isLiveMode: Boolean,
dispatcher: CoroutineContext = Dispatchers.Default,
) : PaymentMethodVerticalLayoutInteractor {
Expand Down Expand Up @@ -146,6 +148,8 @@ internal class DefaultPaymentMethodVerticalLayoutInteractor(
onMandateTextUpdated = {
viewModel.mandateHandler.updateMandateText(mandateText = it, showAbove = true)
},
reportPaymentMethodTypeSelected = viewModel.eventReporter::onSelectPaymentMethod,
reportFormShown = viewModel.eventReporter::onPaymentMethodFormShown,
isLiveMode = paymentMethodMetadata.stripeIntent.isLiveMode,
)
}
Expand Down Expand Up @@ -316,7 +320,10 @@ internal class DefaultPaymentMethodVerticalLayoutInteractor(
override fun handleViewAction(viewAction: ViewAction) {
when (viewAction) {
is ViewAction.PaymentMethodSelected -> {
reportPaymentMethodTypeSelected(viewAction.selectedPaymentMethodCode)

if (requiresFormScreen(viewAction.selectedPaymentMethodCode)) {
reportFormShown(viewAction.selectedPaymentMethodCode)
transitionTo(formScreenFactory(viewAction.selectedPaymentMethodCode))
} else {
updateSelectedPaymentMethod(viewAction.selectedPaymentMethodCode)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ internal class PaymentOptionsViewModelTest {
viewModel.navigationHandler.currentScreen.test {
assertThat(awaitItem()).isInstanceOf<PaymentSheetScreen.AddAnotherPaymentMethod>()

verify(eventReporter).onShowNewPaymentOptionForm()
verify(eventReporter).onShowNewPaymentOptions()

viewModel.handleBackPressed()
assertThat(awaitItem()).isInstanceOf<SelectSavedPaymentMethods>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1521,7 +1521,7 @@ internal class PaymentSheetViewModelTest {
turbineScope {
val receiver = viewModel.navigationHandler.currentScreen.testIn(this)

verify(eventReporter).onShowNewPaymentOptionForm()
verify(eventReporter).onShowNewPaymentOptions()

receiver.cancelAndIgnoreRemainingEvents()
}
Expand All @@ -1543,7 +1543,7 @@ internal class PaymentSheetViewModelTest {
turbineScope {
val receiver = viewModel.navigationHandler.currentScreen.testIn(this)

verify(eventReporter).onShowNewPaymentOptionForm()
verify(eventReporter).onShowNewPaymentOptions()

receiver.cancelAndIgnoreRemainingEvents()
}
Expand All @@ -1565,7 +1565,7 @@ internal class PaymentSheetViewModelTest {
turbineScope {
val receiver = viewModel.navigationHandler.currentScreen.testIn(this)

verify(eventReporter).onShowNewPaymentOptionForm()
verify(eventReporter).onShowNewPaymentOptions()

receiver.cancelAndIgnoreRemainingEvents()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,12 @@ class DefaultEventReporterTest {
}

@Test
fun `onShowNewPaymentOptionForm() should fire analytics request with expected event value`() {
fun `onShowNewPaymentOptions() should fire analytics request with expected event value`() {
val completeEventReporter = createEventReporter(EventReporter.Mode.Complete) {
simulateSuccessfulSetup(linkEnabled = false, googlePayReady = false)
}

completeEventReporter.onShowNewPaymentOptionForm()
completeEventReporter.onShowNewPaymentOptions()

verify(analyticsRequestExecutor).executeAsync(
argWhere { req ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class PaymentSheetAnalyticsListenerTest {
testScheduler.advanceUntilIdle()
}

verify(eventReporter, times(screenTypes.size)).onShowNewPaymentOptionForm()
verify(eventReporter, times(screenTypes.size)).onShowNewPaymentOptions()
// Only once since it didn't change.
verify(eventReporter).onPaymentMethodFormShown(eq("card"))
}
Expand All @@ -94,7 +94,7 @@ class PaymentSheetAnalyticsListenerTest {
fun `debounced analytics are re-emitted after navigating to SelectSavedPaymentMethods`() = runScenario {
currentScreen.value = mock<PaymentSheetScreen.AddAnotherPaymentMethod>()
testScheduler.advanceUntilIdle()
verify(eventReporter).onShowNewPaymentOptionForm()
verify(eventReporter).onShowNewPaymentOptions()
verify(eventReporter).onPaymentMethodFormShown(eq("card"))
analyticsListener.reportFieldInteraction("card")
verify(eventReporter).onPaymentMethodFormInteraction(eq("card"))
Expand All @@ -109,7 +109,7 @@ class PaymentSheetAnalyticsListenerTest {

currentScreen.value = mock<PaymentSheetScreen.AddAnotherPaymentMethod>()
testScheduler.advanceUntilIdle()
verify(eventReporter).onShowNewPaymentOptionForm()
verify(eventReporter).onShowNewPaymentOptions()
verify(eventReporter).onPaymentMethodFormShown(eq("card"))
analyticsListener.reportFieldInteraction("card")
verify(eventReporter).onPaymentMethodFormInteraction(eq("card"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,8 @@ class DefaultPaymentMethodVerticalLayoutInteractorTest {
}
assertThat(selectedPaymentMethodCode).isEqualTo("cashapp")
onFormFieldValuesChangedCalled = true
}
},
reportPaymentMethodTypeSelected = {},
) {
val paymentMethod = interactor.state.value.displayablePaymentMethods.first { it.code == "cashapp" }
paymentMethod.onClick()
Expand Down Expand Up @@ -610,6 +611,8 @@ class DefaultPaymentMethodVerticalLayoutInteractorTest {
fun handleViewAction_PaymentMethodSelected_transitionsToFormScreen_whenFieldsAllowUserInteraction() {
var calledFormScreenFactory = false
var calledTransitionTo = false
var reportedSelectedPaymentMethodType: PaymentMethodCode? = null
var reportFormShownForPm: PaymentMethodCode? = null
runScenario(
formElementsForCode = {
formFieldsWhichRequireUserInteraction
Expand All @@ -620,11 +623,15 @@ class DefaultPaymentMethodVerticalLayoutInteractorTest {
},
transitionTo = {
calledTransitionTo = true
}
},
reportPaymentMethodTypeSelected = { reportedSelectedPaymentMethodType = it },
reportFormShown = { reportFormShownForPm = it }
) {
interactor.handleViewAction(ViewAction.PaymentMethodSelected("card"))
assertThat(calledFormScreenFactory).isTrue()
assertThat(calledTransitionTo).isTrue()
assertThat(reportedSelectedPaymentMethodType).isEqualTo("card")
assertThat(reportFormShownForPm).isEqualTo("card")
}
}

Expand All @@ -642,7 +649,9 @@ class DefaultPaymentMethodVerticalLayoutInteractorTest {
},
transitionTo = {
calledTransitionTo = true
}
},
reportPaymentMethodTypeSelected = {},
reportFormShown = {},
) {
interactor.handleViewAction(ViewAction.PaymentMethodSelected("us_bank_account"))
assertThat(calledFormScreenFactory).isTrue()
Expand All @@ -664,7 +673,9 @@ class DefaultPaymentMethodVerticalLayoutInteractorTest {
},
transitionTo = {
calledTransitionTo = true
}
},
reportPaymentMethodTypeSelected = {},
reportFormShown = {},
) {
interactor.handleViewAction(ViewAction.PaymentMethodSelected("link"))
assertThat(calledFormScreenFactory).isTrue()
Expand All @@ -675,6 +686,7 @@ class DefaultPaymentMethodVerticalLayoutInteractorTest {
@Test
fun handleViewAction_PaymentMethodSelected_updatesSelectedLPM() {
var onFormFieldValuesChangedCalled = false
var reportedSelectedPaymentMethodType: PaymentMethodCode? = null
runScenario(
formElementsForCode = {
listOf()
Expand All @@ -686,10 +698,12 @@ class DefaultPaymentMethodVerticalLayoutInteractorTest {
}
assertThat(selectedPaymentMethodCode).isEqualTo("cashapp")
onFormFieldValuesChangedCalled = true
}
},
reportPaymentMethodTypeSelected = { reportedSelectedPaymentMethodType = it }
) {
interactor.handleViewAction(ViewAction.PaymentMethodSelected("cashapp"))
assertThat(onFormFieldValuesChangedCalled).isTrue()
assertThat(reportedSelectedPaymentMethodType).isEqualTo("cashapp")
}
}

Expand Down Expand Up @@ -724,6 +738,7 @@ class DefaultPaymentMethodVerticalLayoutInteractorTest {
onFormFieldValuesChangedCalled = true
},
onMandateTextUpdated = { mostRecentMandate = it },
reportPaymentMethodTypeSelected = {}
) {
assertThat(mostRecentMandate).isNull()
interactor.handleViewAction(ViewAction.PaymentMethodSelected("cashapp"))
Expand Down Expand Up @@ -755,7 +770,8 @@ class DefaultPaymentMethodVerticalLayoutInteractorTest {
onFormFieldValuesChanged = { _, selectedPaymentMethodCode ->
currentlySelectedPaymentMethodCode = selectedPaymentMethodCode
},
formElementsForCode = { _ -> emptyList() }
formElementsForCode = { _ -> emptyList() },
reportPaymentMethodTypeSelected = {},
) {
interactor.handleViewAction(ViewAction.PaymentMethodSelected("cashapp"))
interactor.state.test {
Expand Down Expand Up @@ -975,6 +991,8 @@ class DefaultPaymentMethodVerticalLayoutInteractorTest {
isFlowController: Boolean = false,
updateSelection: (PaymentSelection?) -> Unit = { notImplemented() },
onMandateTextUpdated: (ResolvableString?) -> Unit = { notImplemented() },
reportPaymentMethodTypeSelected: (PaymentMethodCode) -> Unit = { notImplemented() },
reportFormShown: (PaymentMethodCode) -> Unit = { notImplemented() },
testBlock: suspend TestParams.() -> Unit
) {
val processing: MutableStateFlow<Boolean> = MutableStateFlow(initialProcessing)
Expand Down Expand Up @@ -1009,6 +1027,8 @@ class DefaultPaymentMethodVerticalLayoutInteractorTest {
isCurrentScreen = isCurrentScreen,
dispatcher = dispatcher,
canRemove = canRemove,
reportPaymentMethodTypeSelected = reportPaymentMethodTypeSelected,
reportFormShown = reportFormShown,
isLiveMode = true,
)

Expand Down
Loading