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

Merged platform communication for Drop-in into one single stream. #353

Merged
merged 7 commits into from
Feb 11, 2025
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 @@ -7,10 +7,10 @@ import androidx.lifecycle.LifecycleEventObserver
import com.adyen.checkout.dropin.DropIn
import com.adyen.checkout.flutter.components.ComponentPlatformApi
import com.adyen.checkout.flutter.dropIn.DropInPlatformApi
import com.adyen.checkout.flutter.generated.CheckoutFlutterInterface
import com.adyen.checkout.flutter.generated.CheckoutPlatformInterface
import com.adyen.checkout.flutter.generated.ComponentFlutterInterface
import com.adyen.checkout.flutter.generated.ComponentPlatformInterface
import com.adyen.checkout.flutter.generated.DropInFlutterInterface
import com.adyen.checkout.flutter.generated.DropInPlatformInterface
import com.adyen.checkout.flutter.session.SessionHolder
import com.adyen.checkout.flutter.utils.Constants.Companion.WRONG_FLUTTER_ACTIVITY_USAGE_ERROR_MESSAGE
Expand All @@ -26,7 +26,7 @@ class AdyenCheckoutPlugin : FlutterPlugin, ActivityAware, PluginRegistry.Activit
private var flutterPluginBinding: FlutterPluginBinding? = null
private var activityPluginBinding: ActivityPluginBinding? = null
private var checkoutPlatformApi: CheckoutPlatformApi? = null
private var dropInFlutterApi: DropInFlutterInterface? = null
private var checkoutFlutter: CheckoutFlutterInterface? = null
private var dropInPlatformApi: DropInPlatformApi? = null
private var componentFlutterApi: ComponentFlutterInterface? = null
private var componentPlatformApi: ComponentPlatformApi? = null
Expand Down Expand Up @@ -79,8 +79,8 @@ class AdyenCheckoutPlugin : FlutterPlugin, ActivityAware, PluginRegistry.Activit
fragmentActivity: FragmentActivity,
binaryMessenger: BinaryMessenger,
) {
dropInFlutterApi =
DropInFlutterInterface(binaryMessenger).apply {
checkoutFlutter =
CheckoutFlutterInterface(binaryMessenger).apply {
dropInPlatformApi = DropInPlatformApi(this, fragmentActivity, sessionHolder)
DropInPlatformInterface.setUp(binaryMessenger, dropInPlatformApi)
}
Expand Down Expand Up @@ -146,7 +146,7 @@ class AdyenCheckoutPlugin : FlutterPlugin, ActivityAware, PluginRegistry.Activit

lifecycleObserver = null
dropInPlatformApi = null
dropInFlutterApi = null
checkoutFlutter = null
DropInPlatformInterface.setUp(binaryMessenger, null)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,19 @@ import com.adyen.checkout.flutter.dropIn.advanced.DropInPaymentMethodDeletionPla
import com.adyen.checkout.flutter.dropIn.advanced.DropInPaymentMethodDeletionResultMessenger
import com.adyen.checkout.flutter.dropIn.advanced.DropInPaymentResultMessenger
import com.adyen.checkout.flutter.dropIn.advanced.DropInServiceResultMessenger
import com.adyen.checkout.flutter.dropIn.model.DropInType
import com.adyen.checkout.flutter.dropIn.session.SessionDropInService
import com.adyen.checkout.flutter.generated.CheckoutEvent
import com.adyen.checkout.flutter.generated.CheckoutEventType
import com.adyen.checkout.flutter.generated.CheckoutFlutterInterface
import com.adyen.checkout.flutter.generated.DeletedStoredPaymentMethodResultDTO
import com.adyen.checkout.flutter.generated.DropInConfigurationDTO
import com.adyen.checkout.flutter.generated.DropInFlutterInterface
import com.adyen.checkout.flutter.generated.DropInPlatformInterface
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.generated.PaymentResultDTO
import com.adyen.checkout.flutter.generated.PaymentResultEnum
import com.adyen.checkout.flutter.generated.PaymentResultModelDTO
import com.adyen.checkout.flutter.generated.PlatformCommunicationModel
import com.adyen.checkout.flutter.generated.PlatformCommunicationType
import com.adyen.checkout.flutter.session.SessionHolder
import com.adyen.checkout.flutter.utils.ConfigurationMapper.mapToDropInConfiguration
import com.adyen.checkout.flutter.utils.ConfigurationMapper.mapToEnvironment
Expand All @@ -51,7 +50,7 @@ import kotlinx.coroutines.withContext
import org.json.JSONObject

class DropInPlatformApi(
private val dropInFlutterApi: DropInFlutterInterface,
private val checkoutFlutter: CheckoutFlutterInterface,
private val activity: FragmentActivity,
private val sessionHolder: SessionHolder,
) : DropInPlatformInterface {
Expand Down Expand Up @@ -154,12 +153,12 @@ class DropInPlatformApi(
return@observe
}

val model =
PlatformCommunicationModel(
PlatformCommunicationType.PAYMENT_COMPONENT,
data = message.contentIfNotHandled.toString(),
val checkoutEvent =
CheckoutEvent(
CheckoutEventType.PAYMENT_COMPONENT,
data = message.contentIfNotHandled.toString()
)
dropInFlutterApi.onDropInAdvancedPlatformCommunication(model) {}
checkoutFlutter.send(checkoutEvent) {}
}
}

Expand All @@ -171,25 +170,13 @@ class DropInPlatformApi(
}

val dropInStoredPaymentMethodDeletionModel = message.contentIfNotHandled
val platformCommunicationModel =
PlatformCommunicationModel(
PlatformCommunicationType.DELETE_STORED_PAYMENT_METHOD,
val checkoutEvent =
CheckoutEvent(
CheckoutEventType.DELETE_STORED_PAYMENT_METHOD,
data = dropInStoredPaymentMethodDeletionModel?.storedPaymentMethodId,
)

when (dropInStoredPaymentMethodDeletionModel?.dropInFlowType) {
DropInType.SESSION ->
dropInFlutterApi.onDropInSessionPlatformCommunication(
platformCommunicationModel
) {}

DropInType.ADVANCED_FLOW ->
dropInFlutterApi.onDropInAdvancedPlatformCommunication(
platformCommunicationModel
) {}

null -> return@observe
}
checkoutFlutter.send(checkoutEvent) {}
}
}

Expand All @@ -200,13 +187,13 @@ class DropInPlatformApi(
return@observe
}

val platformCommunicationModel =
PlatformCommunicationModel(
PlatformCommunicationType.ADDITIONAL_DETAILS,
val checkoutEvent =
CheckoutEvent(
CheckoutEventType.ADDITIONAL_DETAILS,
data = message.contentIfNotHandled.toString(),
)

dropInFlutterApi.onDropInAdvancedPlatformCommunication(platformCommunicationModel) {}
checkoutFlutter.send(checkoutEvent) {}
}
}

Expand All @@ -217,12 +204,12 @@ class DropInPlatformApi(
return@observe
}

val platformCommunicationModel =
PlatformCommunicationModel(
PlatformCommunicationType.BALANCE_CHECK,
val checkoutEvent =
CheckoutEvent(
CheckoutEventType.BALANCE_CHECK,
data = message.contentIfNotHandled.toString()
)
dropInFlutterApi.onDropInAdvancedPlatformCommunication(platformCommunicationModel) {}
checkoutFlutter.send(checkoutEvent) {}
}
}

Expand All @@ -233,12 +220,12 @@ class DropInPlatformApi(
return@observe
}

val platformCommunicationModel =
PlatformCommunicationModel(
PlatformCommunicationType.REQUEST_ORDER,
val checkoutEvent =
CheckoutEvent(
CheckoutEventType.REQUEST_ORDER,
data = message.contentIfNotHandled.toString()
)
dropInFlutterApi.onDropInAdvancedPlatformCommunication(platformCommunicationModel) {}
checkoutFlutter.send(checkoutEvent) {}
}
}

Expand All @@ -249,12 +236,12 @@ class DropInPlatformApi(
return@observe
}

val platformCommunicationModel =
PlatformCommunicationModel(
PlatformCommunicationType.CANCEL_ORDER,
val checkoutEvent =
CheckoutEvent(
CheckoutEventType.CANCEL_ORDER,
data = message.contentIfNotHandled.toString()
)
dropInFlutterApi.onDropInAdvancedPlatformCommunication(platformCommunicationModel) {}
checkoutFlutter.send(checkoutEvent) {}
}
}

Expand Down Expand Up @@ -327,14 +314,13 @@ class DropInPlatformApi(
)
}

val platformCommunicationModel =
PlatformCommunicationModel(
PlatformCommunicationType.RESULT,
data = "",
paymentResult = mappedResult
val checkoutEvent =
CheckoutEvent(
CheckoutEventType.RESULT,
mappedResult,
)

dropInFlutterApi.onDropInSessionPlatformCommunication(platformCommunicationModel) {}
checkoutFlutter.send(checkoutEvent) {}
}

val dropInAdvancedFlowCallback =
Expand Down Expand Up @@ -366,12 +352,11 @@ class DropInPlatformApi(
)
}

val platformCommunicationModel =
PlatformCommunicationModel(
PlatformCommunicationType.RESULT,
data = "",
paymentResult = mappedResult
val checkoutEvent =
CheckoutEvent(
CheckoutEventType.RESULT,
mappedResult
)
dropInFlutterApi.onDropInAdvancedPlatformCommunication(platformCommunicationModel) {}
checkoutFlutter.send(checkoutEvent) {}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ enum class PaymentResultEnum(val raw: Int) {
}
}

enum class PlatformCommunicationType(val raw: Int) {
enum class CheckoutEventType(val raw: Int) {
PAYMENT_COMPONENT(0),
ADDITIONAL_DETAILS(1),
RESULT(2),
Expand All @@ -141,7 +141,7 @@ enum class PlatformCommunicationType(val raw: Int) {
CANCEL_ORDER(6);

companion object {
fun ofRaw(raw: Int): PlatformCommunicationType? {
fun ofRaw(raw: Int): CheckoutEventType? {
return values().firstOrNull { it.raw == raw }
}
}
Expand Down Expand Up @@ -854,26 +854,23 @@ data class OrderResponseDTO (
}

/** Generated class from Pigeon that represents data sent in messages. */
data class PlatformCommunicationModel (
val type: PlatformCommunicationType,
val data: String? = null,
val paymentResult: PaymentResultDTO? = null
data class CheckoutEvent (
val type: CheckoutEventType,
val data: Any? = null

) {
companion object {
@Suppress("LocalVariableName")
fun fromList(__pigeon_list: List<Any?>): PlatformCommunicationModel {
val type = __pigeon_list[0] as PlatformCommunicationType
val data = __pigeon_list[1] as String?
val paymentResult = __pigeon_list[2] as PaymentResultDTO?
return PlatformCommunicationModel(type, data, paymentResult)
fun fromList(__pigeon_list: List<Any?>): CheckoutEvent {
val type = __pigeon_list[0] as CheckoutEventType
val data = __pigeon_list[1]
return CheckoutEvent(type, data)
}
}
fun toList(): List<Any?> {
return listOf(
type,
data,
paymentResult,
)
}
}
Expand Down Expand Up @@ -1284,7 +1281,7 @@ private object PlatformApiPigeonCodec : StandardMessageCodec() {
}
146.toByte() -> {
return (readValue(buffer) as? List<Any?>)?.let {
PlatformCommunicationModel.fromList(it)
CheckoutEvent.fromList(it)
}
}
147.toByte() -> {
Expand Down Expand Up @@ -1379,7 +1376,7 @@ private object PlatformApiPigeonCodec : StandardMessageCodec() {
}
165.toByte() -> {
return (readValue(buffer) as Int?)?.let {
PlatformCommunicationType.ofRaw(it)
CheckoutEventType.ofRaw(it)
}
}
166.toByte() -> {
Expand Down Expand Up @@ -1505,7 +1502,7 @@ private object PlatformApiPigeonCodec : StandardMessageCodec() {
stream.write(145)
writeValue(stream, value.toList())
}
is PlatformCommunicationModel -> {
is CheckoutEvent -> {
stream.write(146)
writeValue(stream, value.toList())
}
Expand Down Expand Up @@ -1581,7 +1578,7 @@ private object PlatformApiPigeonCodec : StandardMessageCodec() {
stream.write(164)
writeValue(stream, value.raw)
}
is PlatformCommunicationType -> {
is CheckoutEventType -> {
stream.write(165)
writeValue(stream, value.raw)
}
Expand Down Expand Up @@ -2011,36 +2008,19 @@ interface DropInPlatformInterface {
}
}
/** Generated class from Pigeon that represents Flutter messages that can be called from Kotlin. */
class DropInFlutterInterface(private val binaryMessenger: BinaryMessenger, private val messageChannelSuffix: String = "") {
class CheckoutFlutterInterface(private val binaryMessenger: BinaryMessenger, private val messageChannelSuffix: String = "") {
companion object {
/** The codec used by DropInFlutterInterface. */
/** The codec used by CheckoutFlutterInterface. */
val codec: MessageCodec<Any?> by lazy {
PlatformApiPigeonCodec
}
}
fun onDropInSessionPlatformCommunication(platformCommunicationModelArg: PlatformCommunicationModel, callback: (Result<Unit>) -> Unit)
{
val separatedMessageChannelSuffix = if (messageChannelSuffix.isNotEmpty()) ".$messageChannelSuffix" else ""
val channelName = "dev.flutter.pigeon.adyen_checkout.DropInFlutterInterface.onDropInSessionPlatformCommunication$separatedMessageChannelSuffix"
val channel = BasicMessageChannel<Any?>(binaryMessenger, channelName, codec)
channel.send(listOf(platformCommunicationModelArg)) {
if (it is List<*>) {
if (it.size > 1) {
callback(Result.failure(AdyenPigeonError(it[0] as String, it[1] as String, it[2] as String?)))
} else {
callback(Result.success(Unit))
}
} else {
callback(Result.failure(createConnectionError(channelName)))
}
}
}
fun onDropInAdvancedPlatformCommunication(platformCommunicationModelArg: PlatformCommunicationModel, callback: (Result<Unit>) -> Unit)
fun send(eventArg: CheckoutEvent, callback: (Result<Unit>) -> Unit)
{
val separatedMessageChannelSuffix = if (messageChannelSuffix.isNotEmpty()) ".$messageChannelSuffix" else ""
val channelName = "dev.flutter.pigeon.adyen_checkout.DropInFlutterInterface.onDropInAdvancedPlatformCommunication$separatedMessageChannelSuffix"
val channelName = "dev.flutter.pigeon.adyen_checkout.CheckoutFlutterInterface.send$separatedMessageChannelSuffix"
val channel = BasicMessageChannel<Any?>(binaryMessenger, channelName, codec)
channel.send(listOf(platformCommunicationModelArg)) {
channel.send(listOf(eventArg)) {
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
6 changes: 3 additions & 3 deletions ios/Classes/AdyenCheckoutPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ public class AdyenCheckoutPlugin: NSObject, FlutterPlugin {
public static func register(with registrar: FlutterPluginRegistrar) {
let sessionHolder = SessionHolder()
let messenger: FlutterBinaryMessenger = registrar.messenger()
let dropInFlutterApi = DropInFlutterInterface(binaryMessenger: messenger)
let checkoutFlutter = CheckoutFlutterInterface(binaryMessenger: messenger)
let componentFlutterApi = ComponentFlutterInterface(binaryMessenger: messenger)
let checkoutPlatformApi = CheckoutPlatformApi(
dropInFlutterApi: dropInFlutterApi,
checkoutFlutter: checkoutFlutter,
componentFlutterApi: componentFlutterApi,
sessionHolder: sessionHolder
)
Expand All @@ -18,7 +18,7 @@ public class AdyenCheckoutPlugin: NSObject, FlutterPlugin {
ComponentPlatformInterfaceSetup.setUp(binaryMessenger: messenger, api: componentPlatformApi)
CheckoutPlatformInterfaceSetup.setUp(binaryMessenger: messenger, api: checkoutPlatformApi)

let dropInPlatformApi = DropInPlatformApi(dropInFlutterApi: dropInFlutterApi, sessionHolder: sessionHolder)
let dropInPlatformApi = DropInPlatformApi(checkoutFlutter: checkoutFlutter, sessionHolder: sessionHolder)
DropInPlatformInterfaceSetup.setUp(binaryMessenger: messenger, api: dropInPlatformApi)

let cardComponentAdvancedFactory = CardComponentFactory(
Expand Down
Loading
Loading