diff --git a/paymentsheet/src/main/java/com/stripe/android/common/analytics/AnalyticsKtx.kt b/paymentsheet/src/main/java/com/stripe/android/common/analytics/AnalyticsKtx.kt index 85a4660fdaf..da94b9893d2 100644 --- a/paymentsheet/src/main/java/com/stripe/android/common/analytics/AnalyticsKtx.kt +++ b/paymentsheet/src/main/java/com/stripe/android/common/analytics/AnalyticsKtx.kt @@ -70,3 +70,11 @@ internal fun List.toAnalyticsValue(): String? { internal fun PaymentSheet.Configuration.getExternalPaymentMethodsAnalyticsValue(): List? { return this.externalPaymentMethods.takeIf { it.isNotEmpty() }?.take(PaymentSheetEvent.MAX_EXTERNAL_PAYMENT_METHODS) } + +internal fun PaymentSheet.PaymentMethodLayout.toAnalyticsValue(): String { + return when (this) { + PaymentSheet.PaymentMethodLayout.Horizontal -> "horizontal" + PaymentSheet.PaymentMethodLayout.Vertical -> "vertical" + PaymentSheet.PaymentMethodLayout.Automatic -> "automatic" + } +} diff --git a/paymentsheet/src/main/java/com/stripe/android/paymentsheet/analytics/PaymentSheetEvent.kt b/paymentsheet/src/main/java/com/stripe/android/paymentsheet/analytics/PaymentSheetEvent.kt index c80aa5e71e7..817a8b9c8ab 100644 --- a/paymentsheet/src/main/java/com/stripe/android/paymentsheet/analytics/PaymentSheetEvent.kt +++ b/paymentsheet/src/main/java/com/stripe/android/paymentsheet/analytics/PaymentSheetEvent.kt @@ -146,6 +146,7 @@ internal sealed class PaymentSheetEvent : AnalyticsEvent { ), FIELD_PREFERRED_NETWORKS to configuration.preferredNetworks.toAnalyticsValue(), FIELD_EXTERNAL_PAYMENT_METHODS to configuration.getExternalPaymentMethodsAnalyticsValue(), + FIELD_PAYMENT_METHOD_LAYOUT to configuration.paymentMethodLayout.toAnalyticsValue(), ) return mapOf( FIELD_MOBILE_PAYMENT_ELEMENT_CONFIGURATION to configurationMap, @@ -495,6 +496,7 @@ internal sealed class PaymentSheetEvent : AnalyticsEvent { const val FIELD_SELECTED_CARD_BRAND = "selected_card_brand" const val FIELD_LINK_CONTEXT = "link_context" const val FIELD_EXTERNAL_PAYMENT_METHODS = "external_payment_methods" + const val FIELD_PAYMENT_METHOD_LAYOUT = "payment_method_layout" const val FIELD_COMPOSE = "compose" const val FIELD_INTENT_TYPE = "intent_type" const val FIELD_LINK_MODE = "link_mode" diff --git a/paymentsheet/src/test/java/com/stripe/android/paymentsheet/analytics/PaymentSheetEventTest.kt b/paymentsheet/src/test/java/com/stripe/android/paymentsheet/analytics/PaymentSheetEventTest.kt index 927f31dd152..85091965085 100644 --- a/paymentsheet/src/test/java/com/stripe/android/paymentsheet/analytics/PaymentSheetEventTest.kt +++ b/paymentsheet/src/test/java/com/stripe/android/paymentsheet/analytics/PaymentSheetEventTest.kt @@ -77,6 +77,7 @@ class PaymentSheetEventTest { ), "preferred_networks" to null, "external_payment_methods" to null, + "payment_method_layout" to "horizontal", ) assertThat(event.params).run { @@ -138,6 +139,70 @@ class PaymentSheetEventTest { ), "preferred_networks" to null, "external_payment_methods" to listOf("external_paypal", "external_fawry"), + "payment_method_layout" to "horizontal", + ) + + assertThat(event.params).run { + containsEntry("link_enabled", false) + containsEntry("google_pay_enabled", false) + containsEntry("is_decoupled", false) + containsEntry("mpe_config", expectedConfig) + } + } + + @Test + fun `Init event with vertical mode should return expected params`() { + val event = PaymentSheetEvent.Init( + mode = EventReporter.Mode.Complete, + configuration = PaymentSheetFixtures.CONFIG_CUSTOMER + .copy(paymentMethodLayout = PaymentSheet.PaymentMethodLayout.Vertical), + isDeferred = false, + linkEnabled = false, + googlePaySupported = false, + ) + + assertThat( + event.eventName + ).isEqualTo( + "mc_complete_init_customer" + ) + + val expectedConfig = mapOf( + "customer" to true, + "customer_access_provider" to "legacy", + "googlepay" to false, + "primary_button_color" to false, + "default_billing_details" to false, + "allows_delayed_payment_methods" to false, + "appearance" to mapOf( + "colorsLight" to false, + "colorsDark" to false, + "corner_radius" to false, + "border_width" to false, + "font" to false, + "size_scale_factor" to false, + "primary_button" to mapOf( + "colorsLight" to false, + "colorsDark" to false, + "corner_radius" to false, + "border_width" to false, + "font" to false, + ), + "usage" to false, + ), + "payment_method_order" to listOf(), + "allows_payment_methods_requiring_shipping_address" to false, + "allows_removal_of_last_saved_payment_method" to true, + "billing_details_collection_configuration" to mapOf( + "attach_defaults" to false, + "name" to "Automatic", + "email" to "Automatic", + "phone" to "Automatic", + "address" to "Automatic", + ), + "preferred_networks" to null, + "external_payment_methods" to null, + "payment_method_layout" to "vertical", ) assertThat(event.params).run { @@ -199,6 +264,7 @@ class PaymentSheetEventTest { ), "preferred_networks" to null, "external_payment_methods" to null, + "payment_method_layout" to "horizontal", ) assertThat(event.params).run { @@ -262,6 +328,7 @@ class PaymentSheetEventTest { ), "preferred_networks" to "cartes_bancaires, visa", "external_payment_methods" to null, + "payment_method_layout" to "horizontal", ) assertThat(event.params).run { @@ -1231,6 +1298,7 @@ class PaymentSheetEventTest { "billing_details_collection_configuration" to expectedBillingDetailsCollection, "preferred_networks" to null, "external_payment_methods" to null, + "payment_method_layout" to "horizontal", ) assertThat( PaymentSheetEvent.Init( @@ -1290,6 +1358,7 @@ class PaymentSheetEventTest { "billing_details_collection_configuration" to expectedBillingDetailsCollection, "preferred_networks" to null, "external_payment_methods" to null, + "payment_method_layout" to "horizontal", ) assertThat( PaymentSheetEvent.Init(