Skip to content

Commit

Permalink
Optimized dto mapping
Browse files Browse the repository at this point in the history
  • Loading branch information
Robert-SD committed Feb 20, 2025
1 parent 8ca3c09 commit fc8f05e
Show file tree
Hide file tree
Showing 9 changed files with 229 additions and 180 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ import com.adyen.checkout.dropin.RecurringDropInServiceResult
import com.adyen.checkout.flutter.dropIn.DropInPlatformApi
import com.adyen.checkout.flutter.dropIn.model.DropInStoredPaymentMethodDeletionModel
import com.adyen.checkout.flutter.dropIn.model.DropInType
import com.adyen.checkout.flutter.generated.BinLookupDataDTO
import com.adyen.checkout.flutter.generated.DeletedStoredPaymentMethodResultDTO
import com.adyen.checkout.flutter.generated.ErrorDTO
import com.adyen.checkout.flutter.generated.OrderCancelResultDTO
import com.adyen.checkout.flutter.generated.PaymentEventDTO
import com.adyen.checkout.flutter.generated.PaymentEventType
import com.adyen.checkout.flutter.dropIn.model.toJson
import com.adyen.checkout.flutter.generated.CheckoutEvent
import com.adyen.checkout.flutter.generated.CheckoutEventType
import com.adyen.checkout.flutter.utils.Constants
Expand Down Expand Up @@ -110,10 +110,11 @@ class AdvancedDropInService : DropInService(), LifecycleOwner {
override fun onBinLookup(data: List<BinLookupData>) {
lifecycleScope.launch {
try {
val binLookupDataList = data.map { BinLookupDataDTO(it.brand) }
val checkoutEvent =
CheckoutEvent(
CheckoutEventType.BIN_LOOKUP,
data = data.toJson()
binLookupDataList
)
DropInPlatformApi.dropInMessageFlow.emit(checkoutEvent)
} catch (exception: Exception) {
Expand All @@ -127,7 +128,7 @@ class AdvancedDropInService : DropInService(), LifecycleOwner {
val checkoutEvent =
CheckoutEvent(
CheckoutEventType.BIN_VALUE,
data = binValue
binValue
)
DropInPlatformApi.dropInMessageFlow.emit(checkoutEvent)
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ import com.adyen.checkout.flutter.dropIn.advanced.DropInPaymentMethodDeletionPla
import com.adyen.checkout.flutter.dropIn.advanced.DropInPaymentMethodDeletionResultMessenger
import com.adyen.checkout.flutter.dropIn.model.DropInStoredPaymentMethodDeletionModel
import com.adyen.checkout.flutter.dropIn.model.DropInType
import com.adyen.checkout.flutter.generated.BinLookupDataDTO
import com.adyen.checkout.flutter.generated.DeletedStoredPaymentMethodResultDTO
import com.adyen.checkout.flutter.dropIn.model.toJson
import com.adyen.checkout.flutter.generated.CheckoutEvent
import com.adyen.checkout.flutter.generated.CheckoutEventType
import com.adyen.checkout.flutter.utils.Constants.Companion.ADYEN_LOG_TAG
Expand All @@ -44,11 +44,11 @@ class SessionDropInService : SessionDropInService(), LifecycleOwner {
override fun onBinLookup(data: List<BinLookupData>) {
lifecycleScope.launch {
try {
val binLookupDataJson = data.toJson()
val binLookupDataList = data.map { BinLookupDataDTO(it.brand) }
val checkoutEvent =
CheckoutEvent(
CheckoutEventType.BIN_LOOKUP,
binLookupDataJson
binLookupDataList
)
DropInPlatformApi.dropInMessageFlow.emit(checkoutEvent)
} catch (exception: Exception) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1193,6 +1193,25 @@ data class OrderCancelResultDTO (
)
}
}

/** Generated class from Pigeon that represents data sent in messages. */
data class BinLookupDataDTO (
val brand: String

) {
companion object {
@Suppress("LocalVariableName")
fun fromList(__pigeon_list: List<Any?>): BinLookupDataDTO {
val brand = __pigeon_list[0] as String
return BinLookupDataDTO(brand)
}
}
fun toList(): List<Any?> {
return listOf(
brand,
)
}
}
private object PlatformApiPigeonCodec : StandardMessageCodec() {
override fun readValueOfType(type: Byte, buffer: ByteBuffer): Any? {
return when (type) {
Expand Down Expand Up @@ -1342,91 +1361,96 @@ private object PlatformApiPigeonCodec : StandardMessageCodec() {
}
}
158.toByte() -> {
return (readValue(buffer) as? List<Any?>)?.let {
BinLookupDataDTO.fromList(it)
}
}
159.toByte() -> {
return (readValue(buffer) as Int?)?.let {
Environment.ofRaw(it)
}
}
159.toByte() -> {
160.toByte() -> {
return (readValue(buffer) as Int?)?.let {
AddressMode.ofRaw(it)
}
}
160.toByte() -> {
161.toByte() -> {
return (readValue(buffer) as Int?)?.let {
CardAuthMethod.ofRaw(it)
}
}
161.toByte() -> {
162.toByte() -> {
return (readValue(buffer) as Int?)?.let {
TotalPriceStatus.ofRaw(it)
}
}
162.toByte() -> {
163.toByte() -> {
return (readValue(buffer) as Int?)?.let {
GooglePayEnvironment.ofRaw(it)
}
}
163.toByte() -> {
164.toByte() -> {
return (readValue(buffer) as Int?)?.let {
CashAppPayEnvironment.ofRaw(it)
}
}
164.toByte() -> {
165.toByte() -> {
return (readValue(buffer) as Int?)?.let {
PaymentResultEnum.ofRaw(it)
}
}
165.toByte() -> {
166.toByte() -> {
return (readValue(buffer) as Int?)?.let {
CheckoutEventType.ofRaw(it)
}
}
166.toByte() -> {
167.toByte() -> {
return (readValue(buffer) as Int?)?.let {
ComponentCommunicationType.ofRaw(it)
}
}
167.toByte() -> {
168.toByte() -> {
return (readValue(buffer) as Int?)?.let {
PaymentEventType.ofRaw(it)
}
}
168.toByte() -> {
169.toByte() -> {
return (readValue(buffer) as Int?)?.let {
FieldVisibility.ofRaw(it)
}
}
169.toByte() -> {
170.toByte() -> {
return (readValue(buffer) as Int?)?.let {
InstantPaymentType.ofRaw(it)
}
}
170.toByte() -> {
171.toByte() -> {
return (readValue(buffer) as Int?)?.let {
ApplePayShippingType.ofRaw(it)
}
}
171.toByte() -> {
172.toByte() -> {
return (readValue(buffer) as Int?)?.let {
ApplePayMerchantCapability.ofRaw(it)
}
}
172.toByte() -> {
173.toByte() -> {
return (readValue(buffer) as Int?)?.let {
ApplePaySummaryItemType.ofRaw(it)
}
}
173.toByte() -> {
174.toByte() -> {
return (readValue(buffer) as Int?)?.let {
CardNumberValidationResultDTO.ofRaw(it)
}
}
174.toByte() -> {
175.toByte() -> {
return (readValue(buffer) as Int?)?.let {
CardExpiryDateValidationResultDTO.ofRaw(it)
}
}
175.toByte() -> {
176.toByte() -> {
return (readValue(buffer) as Int?)?.let {
CardSecurityCodeValidationResultDTO.ofRaw(it)
}
Expand Down Expand Up @@ -1552,76 +1576,80 @@ private object PlatformApiPigeonCodec : StandardMessageCodec() {
stream.write(157)
writeValue(stream, value.toList())
}
is Environment -> {
is BinLookupDataDTO -> {
stream.write(158)
writeValue(stream, value.toList())
}
is Environment -> {
stream.write(159)
writeValue(stream, value.raw)
}
is AddressMode -> {
stream.write(159)
stream.write(160)
writeValue(stream, value.raw)
}
is CardAuthMethod -> {
stream.write(160)
stream.write(161)
writeValue(stream, value.raw)
}
is TotalPriceStatus -> {
stream.write(161)
stream.write(162)
writeValue(stream, value.raw)
}
is GooglePayEnvironment -> {
stream.write(162)
stream.write(163)
writeValue(stream, value.raw)
}
is CashAppPayEnvironment -> {
stream.write(163)
stream.write(164)
writeValue(stream, value.raw)
}
is PaymentResultEnum -> {
stream.write(164)
stream.write(165)
writeValue(stream, value.raw)
}
is CheckoutEventType -> {
stream.write(165)
stream.write(166)
writeValue(stream, value.raw)
}
is ComponentCommunicationType -> {
stream.write(166)
stream.write(167)
writeValue(stream, value.raw)
}
is PaymentEventType -> {
stream.write(167)
stream.write(168)
writeValue(stream, value.raw)
}
is FieldVisibility -> {
stream.write(168)
stream.write(169)
writeValue(stream, value.raw)
}
is InstantPaymentType -> {
stream.write(169)
stream.write(170)
writeValue(stream, value.raw)
}
is ApplePayShippingType -> {
stream.write(170)
stream.write(171)
writeValue(stream, value.raw)
}
is ApplePayMerchantCapability -> {
stream.write(171)
stream.write(172)
writeValue(stream, value.raw)
}
is ApplePaySummaryItemType -> {
stream.write(172)
stream.write(173)
writeValue(stream, value.raw)
}
is CardNumberValidationResultDTO -> {
stream.write(173)
stream.write(174)
writeValue(stream, value.raw)
}
is CardExpiryDateValidationResultDTO -> {
stream.write(174)
stream.write(175)
writeValue(stream, value.raw)
}
is CardSecurityCodeValidationResultDTO -> {
stream.write(175)
stream.write(176)
writeValue(stream, value.raw)
}
else -> super.writeValue(stream, value)
Expand Down Expand Up @@ -2201,12 +2229,12 @@ class ComponentFlutterInterface(private val binaryMessenger: BinaryMessenger, pr
PlatformApiPigeonCodec
}
}
fun _generateCodecForDTOs(cardComponentConfigurationDTOArg: CardComponentConfigurationDTO, sessionDTOArg: SessionDTO, callback: (Result<Unit>) -> Unit)
fun _generateCodecForDTOs(cardComponentConfigurationDTOArg: CardComponentConfigurationDTO, sessionDTOArg: SessionDTO, binLookupDataDTOArg: BinLookupDataDTO, callback: (Result<Unit>) -> Unit)
{
val separatedMessageChannelSuffix = if (messageChannelSuffix.isNotEmpty()) ".$messageChannelSuffix" else ""
val channelName = "dev.flutter.pigeon.adyen_checkout.ComponentFlutterInterface._generateCodecForDTOs$separatedMessageChannelSuffix"
val channel = BasicMessageChannel<Any?>(binaryMessenger, channelName, codec)
channel.send(listOf(cardComponentConfigurationDTOArg, sessionDTOArg)) {
channel.send(listOf(cardComponentConfigurationDTOArg, sessionDTOArg, binLookupDataDTOArg)) {
if (it is List<*>) {
if (it.size > 1) {
callback(Result.failure(AdyenPigeonError(it[0] as String, it[1] as String, it[2] as String?)))
Expand Down
25 changes: 10 additions & 15 deletions ios/Classes/dropIn/DropInPlatformApi.swift
Original file line number Diff line number Diff line change
Expand Up @@ -385,20 +385,15 @@ extension DropInPlatformApi: CardComponentDelegate {
}

func didChangeCardBrand(_ value: [Adyen.CardBrand]?, component: Adyen.CardComponent) {
do {
guard let binLookupData = value else {
return
}
var binLookupDataList: [[String: Any]] = []
for item in binLookupData {
var jsonObject: [String: Any] = [:]
jsonObject[Constants.brandKey] = item.type.rawValue
binLookupDataList.append(jsonObject)
}

let data = try JSONSerialization.data(withJSONObject: binLookupDataList, options: [])
let checkoutEvent = CheckoutEvent(type: CheckoutEventType.binLookup, data: String(data: data, encoding: .utf8))
checkoutFlutter.send(event: checkoutEvent, completion: { _ in })
} catch {}
guard let binLookupData = value else {
return
}

let binLookupDataDtoList: [BinLookupDataDTO] = binLookupData.map { cardBrand in
BinLookupDataDTO(brand: cardBrand.type.rawValue)
}

let checkoutEvent = CheckoutEvent(type: CheckoutEventType.binLookup, data: binLookupDataDtoList)
checkoutFlutter.send(event: checkoutEvent, completion: { _ in })
}
}
Loading

0 comments on commit fc8f05e

Please sign in to comment.