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

Feature/prepare telemetry #70

Merged
merged 9 commits into from
Dec 8, 2023
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 @@ -24,6 +24,7 @@ import com.adyen.adyen_checkout.dropInAdvancedFlow.DropInServiceResultMessenger
import com.adyen.adyen_checkout.dropInSession.SessionDropInService
import com.adyen.adyen_checkout.models.DropInFlowType
import com.adyen.adyen_checkout.session.SessionHolder
import com.adyen.adyen_checkout.utils.ConfigurationMapper.mapToAnalyticsConfiguration
import com.adyen.adyen_checkout.utils.ConfigurationMapper.mapToDropInConfiguration
import com.adyen.adyen_checkout.utils.ConfigurationMapper.mapToSession
import com.adyen.adyen_checkout.utils.ConfigurationMapper.toNativeModel
Expand Down Expand Up @@ -90,7 +91,8 @@ class CheckoutPlatformApi(
"${configuration.shopperLocale}",
activity,
configuration.environment.toNativeModel(),
configuration.clientKey
configuration.clientKey,
configuration.analyticsOptionsDTO.mapToAnalyticsConfiguration(),
)
}

Expand Down
58 changes: 34 additions & 24 deletions android/src/main/kotlin/com/adyen/adyen_checkout/PlatformApi.kt
Original file line number Diff line number Diff line change
Expand Up @@ -225,22 +225,22 @@ data class AmountDTO (

/** Generated class from Pigeon that represents data sent in messages. */
data class AnalyticsOptionsDTO (
val enabled: Boolean? = null,
val payload: String? = null
val enabled: Boolean,
val version: String

) {
companion object {
@Suppress("UNCHECKED_CAST")
fun fromList(list: List<Any?>): AnalyticsOptionsDTO {
val enabled = list[0] as Boolean?
val payload = list[1] as String?
return AnalyticsOptionsDTO(enabled, payload)
val enabled = list[0] as Boolean
val version = list[1] as String
return AnalyticsOptionsDTO(enabled, version)
}
}
fun toList(): List<Any?> {
return listOf<Any?>(
enabled,
payload,
version,
)
}
}
Expand All @@ -256,7 +256,7 @@ data class DropInConfigurationDTO (
val applePayConfigurationDTO: ApplePayConfigurationDTO? = null,
val googlePayConfigurationDTO: GooglePayConfigurationDTO? = null,
val cashAppPayConfigurationDTO: CashAppPayConfigurationDTO? = null,
val analyticsOptionsDTO: AnalyticsOptionsDTO? = null,
val analyticsOptionsDTO: AnalyticsOptionsDTO,
val showPreselectedStoredPaymentMethod: Boolean,
val skipListWhenSinglePaymentMethod: Boolean,
val isRemoveStoredPaymentMethodEnabled: Boolean
Expand All @@ -282,9 +282,7 @@ data class DropInConfigurationDTO (
val cashAppPayConfigurationDTO: CashAppPayConfigurationDTO? = (list[8] as List<Any?>?)?.let {
CashAppPayConfigurationDTO.fromList(it)
}
val analyticsOptionsDTO: AnalyticsOptionsDTO? = (list[9] as List<Any?>?)?.let {
AnalyticsOptionsDTO.fromList(it)
}
val analyticsOptionsDTO = AnalyticsOptionsDTO.fromList(list[9] as List<Any?>)
val showPreselectedStoredPaymentMethod = list[10] as Boolean
val skipListWhenSinglePaymentMethod = list[11] as Boolean
val isRemoveStoredPaymentMethodEnabled = list[12] as Boolean
Expand All @@ -302,7 +300,7 @@ data class DropInConfigurationDTO (
applePayConfigurationDTO?.toList(),
googlePayConfigurationDTO?.toList(),
cashAppPayConfigurationDTO?.toList(),
analyticsOptionsDTO?.toList(),
analyticsOptionsDTO.toList(),
showPreselectedStoredPaymentMethod,
skipListWhenSinglePaymentMethod,
isRemoveStoredPaymentMethodEnabled,
Expand Down Expand Up @@ -675,7 +673,8 @@ data class CardComponentConfigurationDTO (
val countryCode: String,
val amount: AmountDTO,
val shopperLocale: String? = null,
val cardConfiguration: CardConfigurationDTO
val cardConfiguration: CardConfigurationDTO,
val analyticsOptionsDTO: AnalyticsOptionsDTO

) {
companion object {
Expand All @@ -687,7 +686,8 @@ data class CardComponentConfigurationDTO (
val amount = AmountDTO.fromList(list[3] as List<Any?>)
val shopperLocale = list[4] as String?
val cardConfiguration = CardConfigurationDTO.fromList(list[5] as List<Any?>)
return CardComponentConfigurationDTO(environment, clientKey, countryCode, amount, shopperLocale, cardConfiguration)
val analyticsOptionsDTO = AnalyticsOptionsDTO.fromList(list[6] as List<Any?>)
return CardComponentConfigurationDTO(environment, clientKey, countryCode, amount, shopperLocale, cardConfiguration, analyticsOptionsDTO)
}
}
fun toList(): List<Any?> {
Expand All @@ -698,6 +698,7 @@ data class CardComponentConfigurationDTO (
amount.toList(),
shopperLocale,
cardConfiguration.toList(),
analyticsOptionsDTO.toList(),
)
}
}
Expand Down Expand Up @@ -1303,30 +1304,35 @@ private object ComponentFlutterInterfaceCodec : StandardMessageCodec() {
}
130.toByte() -> {
return (readValue(buffer) as? List<Any?>)?.let {
CardComponentConfigurationDTO.fromList(it)
AnalyticsOptionsDTO.fromList(it)
}
}
131.toByte() -> {
return (readValue(buffer) as? List<Any?>)?.let {
CardConfigurationDTO.fromList(it)
CardComponentConfigurationDTO.fromList(it)
}
}
132.toByte() -> {
return (readValue(buffer) as? List<Any?>)?.let {
ComponentCommunicationModel.fromList(it)
CardConfigurationDTO.fromList(it)
}
}
133.toByte() -> {
return (readValue(buffer) as? List<Any?>)?.let {
OrderResponseDTO.fromList(it)
ComponentCommunicationModel.fromList(it)
}
}
134.toByte() -> {
return (readValue(buffer) as? List<Any?>)?.let {
PaymentResultModelDTO.fromList(it)
OrderResponseDTO.fromList(it)
}
}
135.toByte() -> {
return (readValue(buffer) as? List<Any?>)?.let {
PaymentResultModelDTO.fromList(it)
}
}
136.toByte() -> {
return (readValue(buffer) as? List<Any?>)?.let {
SessionDTO.fromList(it)
}
Expand All @@ -1344,30 +1350,34 @@ private object ComponentFlutterInterfaceCodec : StandardMessageCodec() {
stream.write(129)
writeValue(stream, value.toList())
}
is CardComponentConfigurationDTO -> {
is AnalyticsOptionsDTO -> {
stream.write(130)
writeValue(stream, value.toList())
}
is CardConfigurationDTO -> {
is CardComponentConfigurationDTO -> {
stream.write(131)
writeValue(stream, value.toList())
}
is ComponentCommunicationModel -> {
is CardConfigurationDTO -> {
stream.write(132)
writeValue(stream, value.toList())
}
is OrderResponseDTO -> {
is ComponentCommunicationModel -> {
stream.write(133)
writeValue(stream, value.toList())
}
is PaymentResultModelDTO -> {
is OrderResponseDTO -> {
stream.write(134)
writeValue(stream, value.toList())
}
is SessionDTO -> {
is PaymentResultModelDTO -> {
stream.write(135)
writeValue(stream, value.toList())
}
is SessionDTO -> {
stream.write(136)
writeValue(stream, value.toList())
}
else -> super.writeValue(stream, value)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import com.adyen.adyen_checkout.components.ComponentErrorMessenger
import com.adyen.adyen_checkout.components.ComponentHeightMessenger
import com.adyen.adyen_checkout.components.ComponentResultMessenger
import com.adyen.adyen_checkout.components.ComponentWrapperView
import com.adyen.adyen_checkout.utils.ConfigurationMapper.mapToAnalyticsConfiguration
import com.adyen.adyen_checkout.utils.ConfigurationMapper.toNativeModel
import com.adyen.checkout.card.CardComponent
import com.adyen.checkout.redirect.RedirectComponent
Expand All @@ -43,7 +44,8 @@ abstract class BaseCardComponent(
"${configuration.shopperLocale}",
context,
environment,
configuration.clientKey
configuration.clientKey,
configuration.analyticsOptionsDTO.mapToAnalyticsConfiguration()
)

lateinit var cardComponent: CardComponent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.adyen.adyen_checkout.utils

import AddressMode
import AmountDTO
import AnalyticsOptionsDTO
import CardConfigurationDTO
import CashAppPayConfigurationDTO
import CashAppPayEnvironment
Expand All @@ -21,6 +22,8 @@ import com.adyen.checkout.card.KCPAuthVisibility
import com.adyen.checkout.card.SocialSecurityNumberVisibility
import com.adyen.checkout.cashapppay.CashAppPayConfiguration
import com.adyen.checkout.components.core.Amount
import com.adyen.checkout.components.core.AnalyticsConfiguration
import com.adyen.checkout.components.core.AnalyticsLevel
import com.adyen.checkout.components.core.OrderResponse
import com.adyen.checkout.dropin.DropInConfiguration
import com.adyen.checkout.googlepay.GooglePayConfiguration
Expand Down Expand Up @@ -50,6 +53,7 @@ object ConfigurationMapper {
val amount = amount.mapToAmount()
val locale = Locale.forLanguageTag(shopperLocale)
val dropInConfiguration = DropInConfiguration.Builder(locale, environment, clientKey)
val analyticsConfiguration = analyticsOptionsDTO.mapToAnalyticsConfiguration()

isRemoveStoredPaymentMethodEnabled.let {
dropInConfiguration.setEnableRemovingStoredPaymentMethods(it)
Expand All @@ -64,19 +68,23 @@ object ConfigurationMapper {
}

if (cardConfigurationDTO != null) {
val cardConfiguration = cardConfigurationDTO.toNativeModel(shopperLocale, context, environment, clientKey)
val cardConfiguration = cardConfigurationDTO.toNativeModel(
shopperLocale,
context,
environment,
clientKey,
analyticsConfiguration,
)
dropInConfiguration.addCardConfiguration(cardConfiguration)
}

if (googlePayConfigurationDTO != null) {
val googlePayConfiguration =
buildGooglePayConfiguration(locale, environment, googlePayConfigurationDTO)
val googlePayConfiguration = buildGooglePayConfiguration(locale, environment, googlePayConfigurationDTO)
dropInConfiguration.addGooglePayConfiguration(googlePayConfiguration)
}

if (cashAppPayConfigurationDTO != null) {
val cashAppPayConfiguration =
buildCashAppPayConfiguration(locale, environment, cashAppPayConfigurationDTO)
val cashAppPayConfiguration = buildCashAppPayConfiguration(locale, environment, cashAppPayConfigurationDTO)
dropInConfiguration.addCashAppPayConfiguration(cashAppPayConfiguration)
}

Expand All @@ -89,25 +97,32 @@ object ConfigurationMapper {
context: Context,
environment: com.adyen.checkout.core.Environment,
clientKey: String,
analyticsConfiguration: AnalyticsConfiguration,
): CardConfiguration {
val locale = Locale.forLanguageTag(shopperLocale)

return CardConfiguration.Builder(
shopperLocale = locale,
environment = environment,
clientKey = clientKey
)
.setAddressConfiguration(addressMode.mapToAddressConfiguration())
.setShowStorePaymentField(showStorePaymentField)
.setHideCvcStoredCard(!showCvcForStoredCard)
.setHideCvc(!showCvc)
.setKcpAuthVisibility(determineKcpAuthVisibility(kcpFieldVisibility))
shopperLocale = locale, environment = environment, clientKey = clientKey
).setAddressConfiguration(addressMode.mapToAddressConfiguration())
.setShowStorePaymentField(showStorePaymentField).setHideCvcStoredCard(!showCvcForStoredCard)
.setHideCvc(!showCvc).setKcpAuthVisibility(determineKcpAuthVisibility(kcpFieldVisibility))
.setSocialSecurityNumberVisibility(
determineSocialSecurityNumberVisibility(socialSecurityNumberFieldVisibility)
)
.setSupportedCardTypes(*mapToSupportedCardTypes(supportedCardTypes))
.setHolderNameRequired(holderNameRequired)
.build()
).setSupportedCardTypes(*mapToSupportedCardTypes(supportedCardTypes))
.setHolderNameRequired(holderNameRequired).setAnalyticsConfiguration(analyticsConfiguration).build()
}


fun AnalyticsOptionsDTO.mapToAnalyticsConfiguration(): AnalyticsConfiguration {
val analyticsLevel = when {
enabled -> AnalyticsLevel.ALL
else -> AnalyticsLevel.NONE
}
// AnalyticsMapper.Companion.overrideForCrossPlatform(
Robert-SD marked this conversation as resolved.
Show resolved Hide resolved
// AnalyticsPlatform.FLUTTER.value,
// version,
// )
return AnalyticsConfiguration(analyticsLevel)
}

private fun DropInConfigurationDTO.buildGooglePayConfiguration(
Expand All @@ -116,9 +131,7 @@ object ConfigurationMapper {
googlePayConfigurationDTO: GooglePayConfigurationDTO
): GooglePayConfiguration {
val googlePayConfigurationBuilder = GooglePayConfiguration.Builder(
shopperLocale,
environment,
clientKey
shopperLocale, environment, clientKey
)
return googlePayConfigurationDTO.mapToGooglePayConfiguration(googlePayConfigurationBuilder)
}
Expand All @@ -129,9 +142,7 @@ object ConfigurationMapper {
cashAppPayConfigurationDTO: CashAppPayConfigurationDTO
): CashAppPayConfiguration {
val cashAppPayConfigurationBuilder = CashAppPayConfiguration.Builder(
shopperLocale,
environment,
clientKey
shopperLocale, environment, clientKey
)
return cashAppPayConfigurationDTO.mapToCashAppPayConfiguration(cashAppPayConfigurationBuilder)
}
Expand Down Expand Up @@ -191,8 +202,7 @@ object ConfigurationMapper {
)
}

private fun GooglePayConfigurationDTO.mapToGooglePayConfiguration(builder: GooglePayConfiguration.Builder):
GooglePayConfiguration {
private fun GooglePayConfigurationDTO.mapToGooglePayConfiguration(builder: GooglePayConfiguration.Builder): GooglePayConfiguration {
if (allowedCardNetworks.isNotEmpty()) {
builder.setAllowedCardNetworks(allowedCardNetworks.filterNotNull())
}
Expand Down Expand Up @@ -232,11 +242,8 @@ object ConfigurationMapper {
}
}

private fun CashAppPayConfigurationDTO.mapToCashAppPayConfiguration(builder: CashAppPayConfiguration.Builder):
CashAppPayConfiguration {
builder
.setCashAppPayEnvironment(cashAppPayEnvironment.mapToCashAppPayEnvironment())
.setReturnUrl(returnUrl)
private fun CashAppPayConfigurationDTO.mapToCashAppPayConfiguration(builder: CashAppPayConfiguration.Builder): CashAppPayConfiguration {
builder.setCashAppPayEnvironment(cashAppPayEnvironment.mapToCashAppPayEnvironment()).setReturnUrl(returnUrl)
return builder.build()
}

Expand Down
Loading