diff --git a/android/src/main/kotlin/com/adyen/checkout/flutter/AdyenCheckoutPlugin.kt b/android/src/main/kotlin/com/adyen/checkout/flutter/AdyenCheckoutPlugin.kt index 68e2c48b..5d09b0b1 100644 --- a/android/src/main/kotlin/com/adyen/checkout/flutter/AdyenCheckoutPlugin.kt +++ b/android/src/main/kotlin/com/adyen/checkout/flutter/AdyenCheckoutPlugin.kt @@ -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 @@ -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 @@ -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) } @@ -146,7 +146,7 @@ class AdyenCheckoutPlugin : FlutterPlugin, ActivityAware, PluginRegistry.Activit lifecycleObserver = null dropInPlatformApi = null - dropInFlutterApi = null + checkoutFlutter = null DropInPlatformInterface.setUp(binaryMessenger, null) } diff --git a/android/src/main/kotlin/com/adyen/checkout/flutter/dropIn/DropInPlatformApi.kt b/android/src/main/kotlin/com/adyen/checkout/flutter/dropIn/DropInPlatformApi.kt index f3688e50..6325af8c 100644 --- a/android/src/main/kotlin/com/adyen/checkout/flutter/dropIn/DropInPlatformApi.kt +++ b/android/src/main/kotlin/com/adyen/checkout/flutter/dropIn/DropInPlatformApi.kt @@ -25,11 +25,12 @@ 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 @@ -37,8 +38,6 @@ 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 @@ -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 { @@ -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) {} } } @@ -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) {} } } @@ -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) {} } } @@ -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) {} } } @@ -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) {} } } @@ -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) {} } } @@ -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 = @@ -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) {} } } diff --git a/android/src/main/kotlin/com/adyen/checkout/flutter/generated/PlatformApi.kt b/android/src/main/kotlin/com/adyen/checkout/flutter/generated/PlatformApi.kt index 454ee634..22621377 100644 --- a/android/src/main/kotlin/com/adyen/checkout/flutter/generated/PlatformApi.kt +++ b/android/src/main/kotlin/com/adyen/checkout/flutter/generated/PlatformApi.kt @@ -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), @@ -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 } } } @@ -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): 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): CheckoutEvent { + val type = __pigeon_list[0] as CheckoutEventType + val data = __pigeon_list[1] + return CheckoutEvent(type, data) } } fun toList(): List { return listOf( type, data, - paymentResult, ) } } @@ -1284,7 +1281,7 @@ private object PlatformApiPigeonCodec : StandardMessageCodec() { } 146.toByte() -> { return (readValue(buffer) as? List)?.let { - PlatformCommunicationModel.fromList(it) + CheckoutEvent.fromList(it) } } 147.toByte() -> { @@ -1379,7 +1376,7 @@ private object PlatformApiPigeonCodec : StandardMessageCodec() { } 165.toByte() -> { return (readValue(buffer) as Int?)?.let { - PlatformCommunicationType.ofRaw(it) + CheckoutEventType.ofRaw(it) } } 166.toByte() -> { @@ -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()) } @@ -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) } @@ -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 by lazy { PlatformApiPigeonCodec } } - fun onDropInSessionPlatformCommunication(platformCommunicationModelArg: PlatformCommunicationModel, callback: (Result) -> Unit) -{ - val separatedMessageChannelSuffix = if (messageChannelSuffix.isNotEmpty()) ".$messageChannelSuffix" else "" - val channelName = "dev.flutter.pigeon.adyen_checkout.DropInFlutterInterface.onDropInSessionPlatformCommunication$separatedMessageChannelSuffix" - val channel = BasicMessageChannel(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) + fun send(eventArg: CheckoutEvent, callback: (Result) -> 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(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?))) diff --git a/ios/Classes/AdyenCheckoutPlugin.swift b/ios/Classes/AdyenCheckoutPlugin.swift index f88a87a4..25c5ad0d 100644 --- a/ios/Classes/AdyenCheckoutPlugin.swift +++ b/ios/Classes/AdyenCheckoutPlugin.swift @@ -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 ) @@ -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( diff --git a/ios/Classes/CheckoutPlatformApi.swift b/ios/Classes/CheckoutPlatformApi.swift index 96e51838..579e0938 100644 --- a/ios/Classes/CheckoutPlatformApi.swift +++ b/ios/Classes/CheckoutPlatformApi.swift @@ -8,17 +8,17 @@ import AdyenNetworking // 3) Add AppDelegate redirect class CheckoutPlatformApi: CheckoutPlatformInterface { - private let dropInFlutterApi: DropInFlutterInterface + private let checkoutFlutter: CheckoutFlutterInterface private let componentFlutterApi: ComponentFlutterInterface private let sessionHolder: SessionHolder private let adyenCse: AdyenCSE = .init() init( - dropInFlutterApi: DropInFlutterInterface, + checkoutFlutter: CheckoutFlutterInterface, componentFlutterApi: ComponentFlutterInterface, sessionHolder: SessionHolder ) { - self.dropInFlutterApi = dropInFlutterApi + self.checkoutFlutter = checkoutFlutter self.componentFlutterApi = componentFlutterApi self.sessionHolder = sessionHolder } @@ -103,7 +103,7 @@ class CheckoutPlatformApi: CheckoutPlatformInterface { sessionData: String, completion: @escaping (Result) -> Void ) throws { - let sessionDelegate = DropInSessionsDelegate(viewController: getViewController(), dropInFlutterApi: dropInFlutterApi) + let sessionDelegate = DropInSessionsDelegate(viewController: getViewController(), checkoutFlutter: checkoutFlutter) try requestAndSetSession( adyenContext: adyenContext, sessionId: sessionId, diff --git a/ios/Classes/dropIn/DropInPlatformApi.swift b/ios/Classes/dropIn/DropInPlatformApi.swift index 54ae6ce9..b2e540ad 100644 --- a/ios/Classes/dropIn/DropInPlatformApi.swift +++ b/ios/Classes/dropIn/DropInPlatformApi.swift @@ -4,7 +4,7 @@ import AdyenNetworking class DropInPlatformApi: DropInPlatformInterface { private let jsonDecoder = JSONDecoder() - private let dropInFlutterApi: DropInFlutterInterface + private let checkoutFlutter: CheckoutFlutterInterface private let sessionHolder: SessionHolder private var hostViewController: UIViewController? private var dropInViewController: DropInViewController? @@ -15,10 +15,10 @@ class DropInPlatformApi: DropInPlatformInterface { private var requestOrderHandler: ((Result) -> Void)? init( - dropInFlutterApi: DropInFlutterInterface, + checkoutFlutter: CheckoutFlutterInterface, sessionHolder: SessionHolder ) { - self.dropInFlutterApi = dropInFlutterApi + self.checkoutFlutter = checkoutFlutter self.sessionHolder = sessionHolder } @@ -37,7 +37,7 @@ class DropInPlatformApi: DropInPlatformInterface { let adyenContext = try dropInConfigurationDTO.createAdyenContext() dropInSessionStoredPaymentMethodsDelegate = DropInSessionsStoredPaymentMethodsDelegate( viewController: viewController, - dropInFlutterApi: dropInFlutterApi + checkoutFlutter: checkoutFlutter ) let payment = session.sessionContext.payment ?? adyenContext.payment let dropInConfiguration = try dropInConfigurationDTO.createDropInConfiguration(payment: payment) @@ -94,7 +94,7 @@ class DropInPlatformApi: DropInPlatformInterface { configuration: configuration, title: dropInConfigurationDTO.preselectedPaymentMethodTitle ) - dropInAdvancedFlowDelegate = DropInAdvancedFlowDelegate(dropInFlutterApi: dropInFlutterApi) + dropInAdvancedFlowDelegate = DropInAdvancedFlowDelegate(checkoutFlutter: checkoutFlutter) dropInAdvancedFlowDelegate?.dropInInteractorDelegate = self dropInComponent.delegate = dropInAdvancedFlowDelegate if dropInConfigurationDTO.isPartialPaymentSupported { @@ -103,7 +103,7 @@ class DropInPlatformApi: DropInPlatformInterface { if dropInConfigurationDTO.isRemoveStoredPaymentMethodEnabled == true { dropInAdvancedFlowStoredPaymentMethodsDelegate = DropInAdvancedFlowStoredPaymentMethodsDelegate( viewController: viewController, - dropInFlutterApi: dropInFlutterApi + checkoutFlutter: checkoutFlutter ) dropInComponent.storedPaymentMethodsDelegate = dropInAdvancedFlowStoredPaymentMethodsDelegate } @@ -112,12 +112,12 @@ class DropInPlatformApi: DropInPlatformInterface { self.dropInViewController = dropInViewController self.hostViewController?.present(dropInViewController, animated: false) } catch { - let platformCommunicationModel = PlatformCommunicationModel( - type: PlatformCommunicationType.result, - paymentResult: PaymentResultDTO(type: PaymentResultEnum.error, reason: error.localizedDescription) + let checkoutEvent = CheckoutEvent( + type: CheckoutEventType.result, + data: PaymentResultDTO(type: PaymentResultEnum.error, reason: error.localizedDescription) ) - dropInFlutterApi.onDropInAdvancedPlatformCommunication( - platformCommunicationModel: platformCommunicationModel, + checkoutFlutter.send( + event: checkoutEvent, completion: { _ in } ) } @@ -198,11 +198,9 @@ class DropInPlatformApi: DropInPlatformInterface { result: PaymentResultModelDTO( resultCode: resultCode?.rawValue) ) - self?.dropInFlutterApi.onDropInAdvancedPlatformCommunication( - platformCommunicationModel: PlatformCommunicationModel( - type: PlatformCommunicationType.result, - paymentResult: paymentResult - ), + let checkoutEvent = CheckoutEvent(type: CheckoutEventType.result, data: paymentResult) + self?.checkoutFlutter.send( + event: checkoutEvent, completion: { _ in } ) }) @@ -215,11 +213,9 @@ class DropInPlatformApi: DropInPlatformInterface { dropInViewController?.dropInComponent.handle(result) } catch { let paymentResult = PaymentResultDTO(type: PaymentResultEnum.error, reason: error.localizedDescription) - dropInFlutterApi.onDropInAdvancedPlatformCommunication( - platformCommunicationModel: PlatformCommunicationModel( - type: PlatformCommunicationType.result, - paymentResult: paymentResult - ), + let checkoutEvent = CheckoutEvent(type: CheckoutEventType.result, data: paymentResult) + checkoutFlutter.send( + event: checkoutEvent, completion: { _ in } ) finalizeAndDismiss(success: false) {} @@ -232,11 +228,9 @@ class DropInPlatformApi: DropInPlatformInterface { if paymentEventDTO.error?.dismissDropIn == true || dropInAdvancedFlowDelegate?.isApplePay == true { finalizeAndDismiss(success: false) { [weak self] in let paymentResult = PaymentResultDTO(type: PaymentResultEnum.error, reason: paymentEventDTO.error?.errorMessage) - self?.dropInFlutterApi.onDropInAdvancedPlatformCommunication( - platformCommunicationModel: PlatformCommunicationModel( - type: PlatformCommunicationType.result, - paymentResult: paymentResult - ), + let checkoutEvent = CheckoutEvent(type: CheckoutEventType.result, data: paymentResult) + self?.checkoutFlutter.send( + event: checkoutEvent, completion: { _ in } ) } @@ -288,15 +282,15 @@ class DropInPlatformApi: DropInPlatformInterface { } private func sendSessionError(error: Error) { - let platformCommunicationModel = PlatformCommunicationModel( - type: PlatformCommunicationType.result, - paymentResult: PaymentResultDTO( + let checkoutEvent = CheckoutEvent( + type: CheckoutEventType.result, + data: PaymentResultDTO( type: PaymentResultEnum.error, reason: error.localizedDescription ) ) - dropInFlutterApi.onDropInSessionPlatformCommunication( - platformCommunicationModel: platformCommunicationModel, + checkoutFlutter.send( + event: checkoutEvent, completion: { _ in } ) } @@ -347,11 +341,11 @@ extension DropInPlatformApi: PartialPaymentDelegate { func checkBalance(with data: Adyen.PaymentComponentData, component: any Adyen.Component, completion: @escaping (Result) -> Void) { do { checkBalanceHandler = completion - let platformCommunicationModel = try PlatformCommunicationModel( - type: PlatformCommunicationType.balanceCheck, + let checkoutEvent = try CheckoutEvent( + type: CheckoutEventType.balanceCheck, data: data.jsonObject.toJsonStringRepresentation() ) - dropInFlutterApi.onDropInAdvancedPlatformCommunication(platformCommunicationModel: platformCommunicationModel, completion: { _ in }) + checkoutFlutter.send(event: checkoutEvent, completion: { _ in }) } catch { completion(.failure(error)) } @@ -359,8 +353,8 @@ extension DropInPlatformApi: PartialPaymentDelegate { func requestOrder(for component: any Adyen.Component, completion: @escaping (Result) -> Void) { requestOrderHandler = completion - let platformCommunicationModel = PlatformCommunicationModel(type: PlatformCommunicationType.requestOrder) - dropInFlutterApi.onDropInAdvancedPlatformCommunication(platformCommunicationModel: platformCommunicationModel, completion: { _ in }) + let checkoutEvent = CheckoutEvent(type: CheckoutEventType.requestOrder) + checkoutFlutter.send(event: checkoutEvent, completion: { _ in }) } func cancelOrder(_ order: Adyen.PartialPaymentOrder, component: any Adyen.Component) { @@ -371,8 +365,8 @@ extension DropInPlatformApi: PartialPaymentDelegate { ] let data = try JSONSerialization.data(withJSONObject: cancelOrderData, options: []) let cancelOrderDataString = String(data: data, encoding: .utf8) - let platformCommunicationModel = PlatformCommunicationModel(type: PlatformCommunicationType.cancelOrder, data: cancelOrderDataString) - dropInFlutterApi.onDropInAdvancedPlatformCommunication(platformCommunicationModel: platformCommunicationModel, completion: { _ in }) + let checkoutEvent = CheckoutEvent(type: CheckoutEventType.cancelOrder, data: cancelOrderDataString) + checkoutFlutter.send(event: checkoutEvent, completion: { _ in }) } catch { adyenPrint(error.localizedDescription) } diff --git a/ios/Classes/dropIn/dropInAdvancedFlow/DropInAdvancedFlowDelegate.swift b/ios/Classes/dropIn/dropInAdvancedFlow/DropInAdvancedFlowDelegate.swift index ef6764c8..d74d18de 100644 --- a/ios/Classes/dropIn/dropInAdvancedFlow/DropInAdvancedFlowDelegate.swift +++ b/ios/Classes/dropIn/dropInAdvancedFlow/DropInAdvancedFlowDelegate.swift @@ -2,12 +2,12 @@ import Adyen import AdyenNetworking class DropInAdvancedFlowDelegate: DropInComponentDelegate { - private let dropInFlutterApi: DropInFlutterInterface + private let checkoutFlutter: CheckoutFlutterInterface public weak var dropInInteractorDelegate: DropInInteractorDelegate? var isApplePay: Bool = false - init(dropInFlutterApi: DropInFlutterInterface) { - self.dropInFlutterApi = dropInFlutterApi + init(checkoutFlutter: CheckoutFlutterInterface) { + self.checkoutFlutter = checkoutFlutter } func didSubmit(_ data: PaymentComponentData, from paymentComponent: PaymentComponent, in _: AnyDropInComponent) { @@ -19,12 +19,12 @@ class DropInAdvancedFlowDelegate: DropInComponentDelegate { extra: applePayDetails?.getExtraData() ) let submitDataEncoded = try submitData.toJsonString() - let platformCommunicationModel = PlatformCommunicationModel( - type: PlatformCommunicationType.paymentComponent, + let checkoutEvent = CheckoutEvent( + type: CheckoutEventType.paymentComponent, data: submitDataEncoded ) - dropInFlutterApi.onDropInAdvancedPlatformCommunication( - platformCommunicationModel: platformCommunicationModel, + checkoutFlutter.send( + event: checkoutEvent, completion: { _ in } ) } catch { @@ -39,11 +39,9 @@ class DropInAdvancedFlowDelegate: DropInComponentDelegate { let actionComponentData = ActionComponentDataModel(details: data.details.encodable, paymentData: data.paymentData) let actionComponentDataJson = try JSONEncoder().encode(actionComponentData) let actionComponentDataString = String(data: actionComponentDataJson, encoding: .utf8) - dropInFlutterApi.onDropInAdvancedPlatformCommunication( - platformCommunicationModel: PlatformCommunicationModel( - type: PlatformCommunicationType.additionalDetails, - data: actionComponentDataString - ), + let checkoutEvent = CheckoutEvent(type: CheckoutEventType.additionalDetails, data: actionComponentDataString) + checkoutFlutter.send( + event: checkoutEvent, completion: { _ in } ) } catch { @@ -59,12 +57,12 @@ class DropInAdvancedFlowDelegate: DropInComponentDelegate { type: PaymentResultEnum.finished, result: PaymentResultModelDTO(resultCode: ResultCode.received.rawValue) ) - let platformCommunicationModel = PlatformCommunicationModel( - type: PlatformCommunicationType.result, - paymentResult: paymentResult + let checkoutEvent = CheckoutEvent( + type: CheckoutEventType.result, + data: paymentResult ) - self?.dropInFlutterApi.onDropInAdvancedPlatformCommunication( - platformCommunicationModel: platformCommunicationModel, + self?.checkoutFlutter.send( + event: checkoutEvent, completion: { _ in } ) } @@ -86,15 +84,15 @@ class DropInAdvancedFlowDelegate: DropInComponentDelegate { dropInInteractorDelegate?.finalizeAndDismiss(success: false) { [weak self] in switch error { case ComponentError.cancelled: - let platformCommunicationModel = PlatformCommunicationModel( - type: PlatformCommunicationType.result, - paymentResult: PaymentResultDTO( + let checkoutEvent = CheckoutEvent( + type: CheckoutEventType.result, + data: PaymentResultDTO( type: PaymentResultEnum.cancelledByUser, reason: error.localizedDescription ) ) - self?.dropInFlutterApi.onDropInAdvancedPlatformCommunication( - platformCommunicationModel: platformCommunicationModel, + self?.checkoutFlutter.send( + event: checkoutEvent, completion: { _ in } ) default: @@ -104,13 +102,13 @@ class DropInAdvancedFlowDelegate: DropInComponentDelegate { } private func sendErrorToFlutterLayer(error: Error) { - let platformCommunicationModel = PlatformCommunicationModel( - type: PlatformCommunicationType.result, - paymentResult: PaymentResultDTO( + let checkoutEvent = CheckoutEvent( + type: CheckoutEventType.result, + data: PaymentResultDTO( type: PaymentResultEnum.error, reason: error.localizedDescription ) ) - dropInFlutterApi.onDropInAdvancedPlatformCommunication(platformCommunicationModel: platformCommunicationModel, completion: { _ in }) + checkoutFlutter.send(event: checkoutEvent, completion: { _ in }) } } diff --git a/ios/Classes/dropIn/dropInAdvancedFlow/DropInAdvancedFlowStoredPaymentMethodsDelegate.swift b/ios/Classes/dropIn/dropInAdvancedFlow/DropInAdvancedFlowStoredPaymentMethodsDelegate.swift index 01cc61bf..12583df3 100644 --- a/ios/Classes/dropIn/dropInAdvancedFlow/DropInAdvancedFlowStoredPaymentMethodsDelegate.swift +++ b/ios/Classes/dropIn/dropInAdvancedFlow/DropInAdvancedFlowStoredPaymentMethodsDelegate.swift @@ -2,23 +2,23 @@ import Adyen class DropInAdvancedFlowStoredPaymentMethodsDelegate: StoredPaymentMethodsDelegate { - private let dropInFlutterApi: DropInFlutterInterface + private let checkoutFlutter: CheckoutFlutterInterface private let viewController: UIViewController private var completionHandler: ((Bool) -> Void)? - init(viewController: UIViewController, dropInFlutterApi: DropInFlutterInterface) { - self.dropInFlutterApi = dropInFlutterApi + init(viewController: UIViewController, checkoutFlutter: CheckoutFlutterInterface) { + self.checkoutFlutter = checkoutFlutter self.viewController = viewController } func disable(storedPaymentMethod: StoredPaymentMethod, completion: @escaping (Bool) -> Void) { completionHandler = completion - let platformCommunicationModel = PlatformCommunicationModel( - type: PlatformCommunicationType.deleteStoredPaymentMethod, + let checkoutEvent = CheckoutEvent( + type: CheckoutEventType.deleteStoredPaymentMethod, data: storedPaymentMethod.identifier ) - dropInFlutterApi.onDropInAdvancedPlatformCommunication( - platformCommunicationModel: platformCommunicationModel, + checkoutFlutter.send( + event: checkoutEvent, completion: { _ in } ) } diff --git a/ios/Classes/dropIn/dropInSessions/DropInSessionsDelegate.swift b/ios/Classes/dropIn/dropInSessions/DropInSessionsDelegate.swift index c1277119..6c7bc947 100644 --- a/ios/Classes/dropIn/dropInSessions/DropInSessionsDelegate.swift +++ b/ios/Classes/dropIn/dropInSessions/DropInSessionsDelegate.swift @@ -3,60 +3,60 @@ import AdyenNetworking class DropInSessionsDelegate: AdyenSessionDelegate { private let viewController: UIViewController? - private let dropInFlutterApi: DropInFlutterInterface + private let checkoutFlutter: CheckoutFlutterInterface - init(viewController: UIViewController?, dropInFlutterApi: DropInFlutterInterface) { + init(viewController: UIViewController?, checkoutFlutter: CheckoutFlutterInterface) { self.viewController = viewController - self.dropInFlutterApi = dropInFlutterApi + self.checkoutFlutter = checkoutFlutter } func didComplete(with result: Adyen.AdyenSessionResult, component _: Adyen.Component, session: Adyen.AdyenSession) { - viewController?.dismiss(animated: true, completion: { + viewController?.dismiss(animated: true, completion: { [weak self] in let paymentResult = PaymentResultModelDTO( sessionId: session.sessionContext.identifier, sessionData: session.sessionContext.data, sessionResult: result.encodedResult, resultCode: result.resultCode.rawValue ) - let platformCommunicationModel = PlatformCommunicationModel( - type: PlatformCommunicationType.result, - paymentResult: PaymentResultDTO( + let checkoutEvent = CheckoutEvent( + type: CheckoutEventType.result, + data: PaymentResultDTO( type: PaymentResultEnum.finished, result: paymentResult ) ) - self.dropInFlutterApi.onDropInSessionPlatformCommunication( - platformCommunicationModel: platformCommunicationModel, + self?.checkoutFlutter.send( + event: checkoutEvent, completion: { _ in } ) }) } func didFail(with error: Error, from _: Component, session _: AdyenSession) { - viewController?.dismiss(animated: true, completion: { + viewController?.dismiss(animated: true, completion: { [weak self] in switch error { case ComponentError.cancelled: - let platformCommunicationModel = PlatformCommunicationModel( - type: PlatformCommunicationType.result, - paymentResult: PaymentResultDTO( + let checkoutEvent = CheckoutEvent( + type: CheckoutEventType.result, + data: PaymentResultDTO( type: PaymentResultEnum.cancelledByUser, reason: error.localizedDescription ) ) - self.dropInFlutterApi.onDropInSessionPlatformCommunication( - platformCommunicationModel: platformCommunicationModel, + self?.checkoutFlutter.send( + event: checkoutEvent, completion: { _ in } ) default: - let platformCommunicationModel = PlatformCommunicationModel( - type: PlatformCommunicationType.result, - paymentResult: PaymentResultDTO( + let checkoutEvent = CheckoutEvent( + type: CheckoutEventType.result, + data: PaymentResultDTO( type: PaymentResultEnum.error, reason: error.localizedDescription ) ) - self.dropInFlutterApi.onDropInSessionPlatformCommunication( - platformCommunicationModel: platformCommunicationModel, + self?.checkoutFlutter.send( + event: checkoutEvent, completion: { _ in } ) } diff --git a/ios/Classes/dropIn/dropInSessions/DropInSessionsStoredPaymentMethodsDelegate.swift b/ios/Classes/dropIn/dropInSessions/DropInSessionsStoredPaymentMethodsDelegate.swift index 95e17011..0ea5ce13 100644 --- a/ios/Classes/dropIn/dropInSessions/DropInSessionsStoredPaymentMethodsDelegate.swift +++ b/ios/Classes/dropIn/dropInSessions/DropInSessionsStoredPaymentMethodsDelegate.swift @@ -2,23 +2,23 @@ import Adyen class DropInSessionsStoredPaymentMethodsDelegate: StoredPaymentMethodsDelegate { - private let dropInFlutterApi: DropInFlutterInterface + private let checkoutFlutter: CheckoutFlutterInterface private let viewController: UIViewController private var completionHandler: ((Bool) -> Void)? - init(viewController: UIViewController, dropInFlutterApi: DropInFlutterInterface) { - self.dropInFlutterApi = dropInFlutterApi + init(viewController: UIViewController, checkoutFlutter: CheckoutFlutterInterface) { + self.checkoutFlutter = checkoutFlutter self.viewController = viewController } func disable(storedPaymentMethod: StoredPaymentMethod, completion: @escaping (Bool) -> Void) { completionHandler = completion - let platformCommunicationModel = PlatformCommunicationModel( - type: PlatformCommunicationType.deleteStoredPaymentMethod, + let checkoutEvent = CheckoutEvent( + type: CheckoutEventType.deleteStoredPaymentMethod, data: storedPaymentMethod.identifier ) - dropInFlutterApi.onDropInSessionPlatformCommunication( - platformCommunicationModel: platformCommunicationModel, + checkoutFlutter.send( + event: checkoutEvent, completion: { _ in } ) } diff --git a/ios/Classes/generated/PlatformApi.swift b/ios/Classes/generated/PlatformApi.swift index db6fedb7..3f97d88e 100644 --- a/ios/Classes/generated/PlatformApi.swift +++ b/ios/Classes/generated/PlatformApi.swift @@ -109,7 +109,7 @@ enum PaymentResultEnum: Int { case finished = 2 } -enum PlatformCommunicationType: Int { +enum CheckoutEventType: Int { case paymentComponent = 0 case additionalDetails = 1 case result = 2 @@ -869,29 +869,25 @@ struct OrderResponseDTO { } /// Generated class from Pigeon that represents data sent in messages. -struct PlatformCommunicationModel { - var type: PlatformCommunicationType - var data: String? - var paymentResult: PaymentResultDTO? +struct CheckoutEvent { + var type: CheckoutEventType + var data: Any? // swift-format-ignore: AlwaysUseLowerCamelCase - static func fromList(_ __pigeon_list: [Any?]) -> PlatformCommunicationModel? { - let type = __pigeon_list[0] as! PlatformCommunicationType - let data: String? = nilOrValue(__pigeon_list[1]) - let paymentResult: PaymentResultDTO? = nilOrValue(__pigeon_list[2]) + static func fromList(_ __pigeon_list: [Any?]) -> CheckoutEvent? { + let type = __pigeon_list[0] as! CheckoutEventType + let data: Any? = __pigeon_list[1] - return PlatformCommunicationModel( + return CheckoutEvent( type: type, - data: data, - paymentResult: paymentResult + data: data ) } func toList() -> [Any?] { [ type, - data, - paymentResult + data ] } } @@ -1298,7 +1294,7 @@ private class PlatformApiPigeonCodecReader: FlutterStandardReader { case 145: return OrderResponseDTO.fromList(self.readValue() as! [Any?]) case 146: - return PlatformCommunicationModel.fromList(self.readValue() as! [Any?]) + return CheckoutEvent.fromList(self.readValue() as! [Any?]) case 147: return ComponentCommunicationModel.fromList(self.readValue() as! [Any?]) case 148: @@ -1371,10 +1367,10 @@ private class PlatformApiPigeonCodecReader: FlutterStandardReader { } return enumResult case 165: - var enumResult: PlatformCommunicationType? = nil + var enumResult: CheckoutEventType? = nil let enumResultAsInt: Int? = nilOrValue(self.readValue() as? Int) if let enumResultAsInt { - enumResult = PlatformCommunicationType(rawValue: enumResultAsInt) + enumResult = CheckoutEventType(rawValue: enumResultAsInt) } return enumResult case 166: @@ -1506,7 +1502,7 @@ private class PlatformApiPigeonCodecWriter: FlutterStandardWriter { } else if let value = value as? OrderResponseDTO { super.writeByte(145) super.writeValue(value.toList()) - } else if let value = value as? PlatformCommunicationModel { + } else if let value = value as? CheckoutEvent { super.writeByte(146) super.writeValue(value.toList()) } else if let value = value as? ComponentCommunicationModel { @@ -1563,7 +1559,7 @@ private class PlatformApiPigeonCodecWriter: FlutterStandardWriter { } else if let value = value as? PaymentResultEnum { super.writeByte(164) super.writeValue(value.rawValue) - } else if let value = value as? PlatformCommunicationType { + } else if let value = value as? CheckoutEventType { super.writeByte(165) super.writeValue(value.rawValue) } else if let value = value as? ComponentCommunicationType { @@ -1941,12 +1937,11 @@ class DropInPlatformInterfaceSetup { } /// Generated protocol from Pigeon that represents Flutter messages that can be called from Swift. -protocol DropInFlutterInterfaceProtocol { - func onDropInSessionPlatformCommunication(platformCommunicationModel platformCommunicationModelArg: PlatformCommunicationModel, completion: @escaping (Result) -> Void) - func onDropInAdvancedPlatformCommunication(platformCommunicationModel platformCommunicationModelArg: PlatformCommunicationModel, completion: @escaping (Result) -> Void) +protocol CheckoutFlutterInterfaceProtocol { + func send(event eventArg: CheckoutEvent, completion: @escaping (Result) -> Void) } -class DropInFlutterInterface: DropInFlutterInterfaceProtocol { +class CheckoutFlutterInterface: CheckoutFlutterInterfaceProtocol { private let binaryMessenger: FlutterBinaryMessenger private let messageChannelSuffix: String init(binaryMessenger: FlutterBinaryMessenger, messageChannelSuffix: String = "") { @@ -1958,29 +1953,10 @@ class DropInFlutterInterface: DropInFlutterInterfaceProtocol { PlatformApiPigeonCodec.shared } - func onDropInSessionPlatformCommunication(platformCommunicationModel platformCommunicationModelArg: PlatformCommunicationModel, completion: @escaping (Result) -> Void) { - let channelName = "dev.flutter.pigeon.adyen_checkout.DropInFlutterInterface.onDropInSessionPlatformCommunication\(messageChannelSuffix)" - let channel = FlutterBasicMessageChannel(name: channelName, binaryMessenger: binaryMessenger, codec: codec) - channel.sendMessage([platformCommunicationModelArg] as [Any?]) { response in - guard let listResponse = response as? [Any?] else { - completion(.failure(createConnectionError(withChannelName: channelName))) - return - } - if listResponse.count > 1 { - let code: String = listResponse[0] as! String - let message: String? = nilOrValue(listResponse[1]) - let details: String? = nilOrValue(listResponse[2]) - completion(.failure(AdyenPigeonError(code: code, message: message, details: details))) - } else { - completion(.success(())) - } - } - } - - func onDropInAdvancedPlatformCommunication(platformCommunicationModel platformCommunicationModelArg: PlatformCommunicationModel, completion: @escaping (Result) -> Void) { - let channelName = "dev.flutter.pigeon.adyen_checkout.DropInFlutterInterface.onDropInAdvancedPlatformCommunication\(messageChannelSuffix)" + func send(event eventArg: CheckoutEvent, completion: @escaping (Result) -> Void) { + let channelName = "dev.flutter.pigeon.adyen_checkout.CheckoutFlutterInterface.send\(messageChannelSuffix)" let channel = FlutterBasicMessageChannel(name: channelName, binaryMessenger: binaryMessenger, codec: codec) - channel.sendMessage([platformCommunicationModelArg] as [Any?]) { response in + channel.sendMessage([eventArg] as [Any?]) { response in guard let listResponse = response as? [Any?] else { completion(.failure(createConnectionError(withChannelName: channelName))) return diff --git a/lib/src/adyen_checkout.dart b/lib/src/adyen_checkout.dart index bd51ed0e..9c4ac123 100644 --- a/lib/src/adyen_checkout.dart +++ b/lib/src/adyen_checkout.dart @@ -7,7 +7,7 @@ import 'package:adyen_checkout/src/common/adyen_checkout_api.dart'; import 'package:adyen_checkout/src/common/adyen_checkout_session.dart'; import 'package:adyen_checkout/src/components/action_handling/action_component.dart'; import 'package:adyen_checkout/src/drop_in/drop_in.dart'; -import 'package:adyen_checkout/src/drop_in/drop_in_flutter_api.dart'; +import 'package:adyen_checkout/src/drop_in/drop_in_flutter.dart'; import 'package:adyen_checkout/src/drop_in/drop_in_platform_api.dart'; import 'package:adyen_checkout/src/generated/platform_api.g.dart'; import 'package:adyen_checkout/src/logging/adyen_logger.dart'; @@ -22,7 +22,7 @@ class AdyenCheckout implements AdyenCheckoutInterface { static final AdyenCheckoutApi _adyenCheckoutApi = AdyenCheckoutApi(); static final DropIn _dropIn = DropIn( SdkVersionNumberProvider.instance, - DropInFlutterApi(), + DropInFlutter(), DropInPlatformApi(), ); diff --git a/lib/src/drop_in/drop_in.dart b/lib/src/drop_in/drop_in.dart index c404ad4e..b03e1909 100644 --- a/lib/src/drop_in/drop_in.dart +++ b/lib/src/drop_in/drop_in.dart @@ -2,7 +2,7 @@ import 'dart:async'; import 'dart:convert'; import 'package:adyen_checkout/adyen_checkout.dart'; -import 'package:adyen_checkout/src/drop_in/drop_in_flutter_api.dart'; +import 'package:adyen_checkout/src/drop_in/drop_in_flutter.dart'; import 'package:adyen_checkout/src/drop_in/drop_in_platform_api.dart'; import 'package:adyen_checkout/src/generated/platform_api.g.dart'; import 'package:adyen_checkout/src/logging/adyen_logger.dart'; @@ -14,16 +14,16 @@ import 'package:adyen_checkout/src/util/sdk_version_number_provider.dart'; class DropIn { DropIn( this.sdkVersionNumberProvider, - this.dropInFlutterApi, + this.dropInFlutter, this.dropInPlatformApi, ) { - DropInFlutterInterface.setUp(dropInFlutterApi); + CheckoutFlutterInterface.setUp(dropInFlutter); } final PaymentEventHandler _paymentEventHandler = PaymentEventHandler(); final AdyenLogger adyenLogger = AdyenLogger.instance; final SdkVersionNumberProvider sdkVersionNumberProvider; - final DropInFlutterApi dropInFlutterApi; + final DropInFlutter dropInFlutter; final DropInPlatformApi dropInPlatformApi; Future startDropInSessionsPayment( @@ -39,15 +39,13 @@ class DropIn { dropInConfiguration.toDTO(sdkVersionNumber, true), ); - dropInFlutterApi.dropInSessionPlatformCommunicationStream = - StreamController.broadcast(); - dropInFlutterApi.dropInSessionPlatformCommunicationStream.stream - .asBroadcastStream() - .listen((event) async { + dropInFlutter.platformEventStream = StreamController(); + final platformEventSubscription = + dropInFlutter.platformEventStream?.stream.listen((event) async { switch (event.type) { - case PlatformCommunicationType.result: - dropInSessionCompleter.complete(event.paymentResult); - case PlatformCommunicationType.deleteStoredPaymentMethod: + case CheckoutEventType.result: + _handleResult(dropInSessionCompleter, event); + case CheckoutEventType.deleteStoredPaymentMethod: _onDeleteStoredPaymentMethodCallback( event, dropInConfiguration.storedPaymentMethodConfiguration, @@ -56,28 +54,28 @@ class DropIn { } }); - return dropInSessionCompleter.future.then((paymentResultDTO) { + return dropInSessionCompleter.future.then((paymentResultDTO) async { dropInPlatformApi.cleanUpDropIn(); - dropInFlutterApi.dropInSessionPlatformCommunicationStream.close(); + await platformEventSubscription?.cancel(); + dropInFlutter.platformEventStream?.close(); + dropInFlutter.platformEventStream = null; adyenLogger .print("Drop-in session result type: ${paymentResultDTO.type.name}"); adyenLogger.print( "Drop-in session result code: ${paymentResultDTO.result?.resultCode}"); - switch (paymentResultDTO.type) { - case PaymentResultEnum.cancelledByUser: - return PaymentCancelledByUser(); - case PaymentResultEnum.error: - return PaymentError(reason: paymentResultDTO.reason); - case PaymentResultEnum.finished: - return PaymentSessionFinished( + return switch (paymentResultDTO.type) { + PaymentResultEnum.cancelledByUser => PaymentCancelledByUser(), + PaymentResultEnum.error => + PaymentError(reason: paymentResultDTO.reason), + PaymentResultEnum.finished => PaymentSessionFinished( sessionId: paymentResultDTO.result?.sessionId ?? "", sessionData: paymentResultDTO.result?.sessionData ?? "", sessionResult: paymentResultDTO.result?.sessionResult ?? "", resultCode: paymentResultDTO.result?.toResultCode() ?? ResultCode.unknown, order: paymentResultDTO.result?.order?.fromDTO(), - ); - } + ) + }; }); } @@ -104,61 +102,67 @@ class DropIn { encodedPaymentMethodsResponse, ); - dropInFlutterApi.dropInAdvancedFlowPlatformCommunicationStream = - StreamController.broadcast(); - dropInFlutterApi.dropInAdvancedFlowPlatformCommunicationStream.stream - .asBroadcastStream() - .listen((event) async { + dropInFlutter.platformEventStream = StreamController(); + final platformEventSubscription = + dropInFlutter.platformEventStream?.stream.listen((event) async { switch (event.type) { - case PlatformCommunicationType.paymentComponent: + case CheckoutEventType.paymentComponent: await _handlePaymentComponent(event, advancedCheckout); - case PlatformCommunicationType.additionalDetails: + case CheckoutEventType.additionalDetails: await _handleAdditionalDetails(event, advancedCheckout); - case PlatformCommunicationType.result: + case CheckoutEventType.result: _handleResult(dropInAdvancedFlowCompleter, event); - case PlatformCommunicationType.deleteStoredPaymentMethod: + case CheckoutEventType.deleteStoredPaymentMethod: _onDeleteStoredPaymentMethodCallback( event, dropInConfiguration.storedPaymentMethodConfiguration, ); - case PlatformCommunicationType.balanceCheck: + case CheckoutEventType.balanceCheck: _handleBalanceCheck(event, advancedCheckout.partialPayment); - case PlatformCommunicationType.requestOrder: + case CheckoutEventType.requestOrder: _handleOrderRequest(event, advancedCheckout.partialPayment); - case PlatformCommunicationType.cancelOrder: + case CheckoutEventType.cancelOrder: _handleOrderCancel(event, advancedCheckout.partialPayment); } }); - return dropInAdvancedFlowCompleter.future.then((paymentResultDTO) { + return dropInAdvancedFlowCompleter.future.then((paymentResultDTO) async { dropInPlatformApi.cleanUpDropIn(); - dropInFlutterApi.dropInAdvancedFlowPlatformCommunicationStream.close(); + await platformEventSubscription?.cancel(); + await dropInFlutter.platformEventStream?.close(); + dropInFlutter.platformEventStream = null; adyenLogger.print( "Drop-in advanced flow result type: ${paymentResultDTO.type.name}"); adyenLogger.print( "Drop-in advanced flow result code: ${paymentResultDTO.result?.resultCode}"); - switch (paymentResultDTO.type) { - case PaymentResultEnum.cancelledByUser: - return PaymentCancelledByUser(); - case PaymentResultEnum.error: - return PaymentError(reason: paymentResultDTO.reason); - case PaymentResultEnum.finished: - return PaymentAdvancedFinished( - resultCode: paymentResultDTO.result?.toResultCode() ?? - ResultCode.unknown); - } + return switch (paymentResultDTO.type) { + PaymentResultEnum.cancelledByUser => PaymentCancelledByUser(), + PaymentResultEnum.error => + PaymentError(reason: paymentResultDTO.reason), + PaymentResultEnum.finished => PaymentAdvancedFinished( + resultCode: + paymentResultDTO.result?.toResultCode() ?? ResultCode.unknown) + }; }); } void _handleResult( - Completer dropInAdvancedFlowCompleter, - PlatformCommunicationModel event, + Completer completer, + CheckoutEvent event, ) { - dropInAdvancedFlowCompleter.complete(event.paymentResult); + switch (event.data) { + case PaymentResultDTO paymentResultDTO: + completer.complete(paymentResultDTO); + default: + completer.complete(PaymentResultDTO( + type: PaymentResultEnum.error, + reason: "Missing payment result data", + )); + } } Future _handlePaymentComponent( - PlatformCommunicationModel event, + CheckoutEvent event, Checkout advancedCheckout, ) async { try { @@ -186,7 +190,7 @@ class DropIn { } Future _handleAdditionalDetails( - PlatformCommunicationModel event, + CheckoutEvent event, Checkout advancedCheckout, ) async { try { @@ -214,15 +218,15 @@ class DropIn { } Future _onDeleteStoredPaymentMethodCallback( - PlatformCommunicationModel event, + CheckoutEvent event, StoredPaymentMethodConfiguration? storedPaymentMethodConfiguration, ) async { - final String? storedPaymentMethodId = event.data; final deletionCallback = storedPaymentMethodConfiguration?.deleteStoredPaymentMethodCallback; - if (storedPaymentMethodId != null && deletionCallback != null) { + if (deletionCallback != null) { try { + final String storedPaymentMethodId = event.data as String; final bool result = await deletionCallback(storedPaymentMethodId); dropInPlatformApi.onDeleteStoredPaymentMethodResult( DeletedStoredPaymentMethodResultDTO( @@ -233,7 +237,7 @@ class DropIn { adyenLogger.print(error.toString()); dropInPlatformApi.onDeleteStoredPaymentMethodResult( DeletedStoredPaymentMethodResultDTO( - storedPaymentMethodId: storedPaymentMethodId, + storedPaymentMethodId: "", isSuccessfullyRemoved: false, )); } @@ -241,7 +245,7 @@ class DropIn { } Future _getOnSubmitPaymentEvent( - PlatformCommunicationModel event, Checkout advancedCheckout) async { + CheckoutEvent event, Checkout advancedCheckout) async { final String submitData = (event.data as String); final Map submitDataDecoded = jsonDecode(submitData); switch (advancedCheckout) { @@ -272,7 +276,7 @@ class DropIn { } Future _getOnAdditionalDetailsPaymentEvent( - PlatformCommunicationModel event, Checkout advancedCheckout) async { + CheckoutEvent event, Checkout advancedCheckout) async { switch (advancedCheckout) { case AdvancedCheckout it: final additionalDetails = jsonDecode(event.data as String); @@ -283,7 +287,7 @@ class DropIn { } void _handleBalanceCheck( - PlatformCommunicationModel event, + CheckoutEvent event, PartialPayment? partialPayment, ) async { try { @@ -301,7 +305,7 @@ class DropIn { } void _handleOrderRequest( - PlatformCommunicationModel event, + CheckoutEvent event, PartialPayment? partialPayment, ) async { try { @@ -313,7 +317,7 @@ class DropIn { } void _handleOrderCancel( - PlatformCommunicationModel event, + CheckoutEvent event, PartialPayment? partialPayment, ) async { try { diff --git a/lib/src/drop_in/drop_in_flutter.dart b/lib/src/drop_in/drop_in_flutter.dart new file mode 100644 index 00000000..54887f1b --- /dev/null +++ b/lib/src/drop_in/drop_in_flutter.dart @@ -0,0 +1,10 @@ +import 'dart:async'; + +import 'package:adyen_checkout/src/generated/platform_api.g.dart'; + +class DropInFlutter implements CheckoutFlutterInterface { + StreamController? platformEventStream; + + @override + void send(CheckoutEvent event) => platformEventStream?.sink.add(event); +} diff --git a/lib/src/drop_in/drop_in_flutter_api.dart b/lib/src/drop_in/drop_in_flutter_api.dart deleted file mode 100644 index c5caf85d..00000000 --- a/lib/src/drop_in/drop_in_flutter_api.dart +++ /dev/null @@ -1,18 +0,0 @@ -import 'dart:async'; - -import 'package:adyen_checkout/src/generated/platform_api.g.dart'; - -class DropInFlutterApi implements DropInFlutterInterface { - var dropInSessionPlatformCommunicationStream = - StreamController(); - var dropInAdvancedFlowPlatformCommunicationStream = - StreamController(); - - @override - void onDropInSessionPlatformCommunication(PlatformCommunicationModel data) => - dropInSessionPlatformCommunicationStream.sink.add(data); - - @override - void onDropInAdvancedPlatformCommunication(PlatformCommunicationModel data) => - dropInAdvancedFlowPlatformCommunicationStream.sink.add(data); -} diff --git a/lib/src/generated/platform_api.g.dart b/lib/src/generated/platform_api.g.dart index db4335b0..d8cbbc51 100644 --- a/lib/src/generated/platform_api.g.dart +++ b/lib/src/generated/platform_api.g.dart @@ -15,7 +15,8 @@ PlatformException _createConnectionError(String channelName) { ); } -List wrapResponse({Object? result, PlatformException? error, bool empty = false}) { +List wrapResponse( + {Object? result, PlatformException? error, bool empty = false}) { if (empty) { return []; } @@ -67,7 +68,7 @@ enum PaymentResultEnum { finished, } -enum PlatformCommunicationType { +enum CheckoutEventType { paymentComponent, additionalDetails, result, @@ -315,7 +316,8 @@ class DropInConfigurationDTO { skipListWhenSinglePaymentMethod: result[11]! as bool, isRemoveStoredPaymentMethodEnabled: result[12]! as bool, preselectedPaymentMethodTitle: result[13] as String?, - paymentMethodNames: (result[14] as Map?)?.cast(), + paymentMethodNames: + (result[14] as Map?)?.cast(), isPartialPaymentSupported: result[15]! as bool, ); } @@ -448,14 +450,18 @@ class ApplePayConfigurationDTO { merchantId: result[0]! as String, merchantName: result[1]! as String, allowOnboarding: result[2] as bool?, - summaryItems: (result[3] as List?)?.cast(), - requiredBillingContactFields: (result[4] as List?)?.cast(), + summaryItems: + (result[3] as List?)?.cast(), + requiredBillingContactFields: + (result[4] as List?)?.cast(), billingContact: result[5] as ApplePayContactDTO?, - requiredShippingContactFields: (result[6] as List?)?.cast(), + requiredShippingContactFields: + (result[6] as List?)?.cast(), shippingContact: result[7] as ApplePayContactDTO?, applePayShippingType: result[8] as ApplePayShippingType?, allowShippingContactEditing: result[9] as bool?, - shippingMethods: (result[10] as List?)?.cast(), + shippingMethods: + (result[10] as List?)?.cast(), applicationData: result[11] as String?, supportedCountries: (result[12] as List?)?.cast(), merchantCapability: result[13] as ApplePayMerchantCapability?, @@ -929,33 +935,28 @@ class OrderResponseDTO { } } -class PlatformCommunicationModel { - PlatformCommunicationModel({ +class CheckoutEvent { + CheckoutEvent({ required this.type, this.data, - this.paymentResult, }); - PlatformCommunicationType type; - - String? data; + CheckoutEventType type; - PaymentResultDTO? paymentResult; + Object? data; Object encode() { return [ type, data, - paymentResult, ]; } - static PlatformCommunicationModel decode(Object result) { + static CheckoutEvent decode(Object result) { result as List; - return PlatformCommunicationModel( - type: result[0]! as PlatformCommunicationType, - data: result[1] as String?, - paymentResult: result[2] as PaymentResultDTO?, + return CheckoutEvent( + type: result[0]! as CheckoutEventType, + data: result[1], ); } } @@ -1365,13 +1366,14 @@ class OrderCancelResultDTO { static OrderCancelResultDTO decode(Object result) { result as List; return OrderCancelResultDTO( - orderCancelResponseBody: (result[0] as Map?)!.cast(), - updatedPaymentMethodsResponseBody: (result[1] as Map?)?.cast(), + orderCancelResponseBody: + (result[0] as Map?)!.cast(), + updatedPaymentMethodsResponseBody: + (result[1] as Map?)?.cast(), ); } } - class _PigeonCodec extends StandardMessageCodec { const _PigeonCodec(); @override @@ -1379,142 +1381,142 @@ class _PigeonCodec extends StandardMessageCodec { if (value is SessionDTO) { buffer.putUint8(129); writeValue(buffer, value.encode()); - } else if (value is AmountDTO) { + } else if (value is AmountDTO) { buffer.putUint8(130); writeValue(buffer, value.encode()); - } else if (value is AnalyticsOptionsDTO) { + } else if (value is AnalyticsOptionsDTO) { buffer.putUint8(131); writeValue(buffer, value.encode()); - } else if (value is DropInConfigurationDTO) { + } else if (value is DropInConfigurationDTO) { buffer.putUint8(132); writeValue(buffer, value.encode()); - } else if (value is CardConfigurationDTO) { + } else if (value is CardConfigurationDTO) { buffer.putUint8(133); writeValue(buffer, value.encode()); - } else if (value is ApplePayConfigurationDTO) { + } else if (value is ApplePayConfigurationDTO) { buffer.putUint8(134); writeValue(buffer, value.encode()); - } else if (value is ApplePayContactDTO) { + } else if (value is ApplePayContactDTO) { buffer.putUint8(135); writeValue(buffer, value.encode()); - } else if (value is ApplePayShippingMethodDTO) { + } else if (value is ApplePayShippingMethodDTO) { buffer.putUint8(136); writeValue(buffer, value.encode()); - } else if (value is ApplePaySummaryItemDTO) { + } else if (value is ApplePaySummaryItemDTO) { buffer.putUint8(137); writeValue(buffer, value.encode()); - } else if (value is GooglePayConfigurationDTO) { + } else if (value is GooglePayConfigurationDTO) { buffer.putUint8(138); writeValue(buffer, value.encode()); - } else if (value is MerchantInfoDTO) { + } else if (value is MerchantInfoDTO) { buffer.putUint8(139); writeValue(buffer, value.encode()); - } else if (value is ShippingAddressParametersDTO) { + } else if (value is ShippingAddressParametersDTO) { buffer.putUint8(140); writeValue(buffer, value.encode()); - } else if (value is BillingAddressParametersDTO) { + } else if (value is BillingAddressParametersDTO) { buffer.putUint8(141); writeValue(buffer, value.encode()); - } else if (value is CashAppPayConfigurationDTO) { + } else if (value is CashAppPayConfigurationDTO) { buffer.putUint8(142); writeValue(buffer, value.encode()); - } else if (value is PaymentResultDTO) { + } else if (value is PaymentResultDTO) { buffer.putUint8(143); writeValue(buffer, value.encode()); - } else if (value is PaymentResultModelDTO) { + } else if (value is PaymentResultModelDTO) { buffer.putUint8(144); writeValue(buffer, value.encode()); - } else if (value is OrderResponseDTO) { + } else if (value is OrderResponseDTO) { buffer.putUint8(145); writeValue(buffer, value.encode()); - } else if (value is PlatformCommunicationModel) { + } else if (value is CheckoutEvent) { buffer.putUint8(146); writeValue(buffer, value.encode()); - } else if (value is ComponentCommunicationModel) { + } else if (value is ComponentCommunicationModel) { buffer.putUint8(147); writeValue(buffer, value.encode()); - } else if (value is PaymentEventDTO) { + } else if (value is PaymentEventDTO) { buffer.putUint8(148); writeValue(buffer, value.encode()); - } else if (value is ErrorDTO) { + } else if (value is ErrorDTO) { buffer.putUint8(149); writeValue(buffer, value.encode()); - } else if (value is DeletedStoredPaymentMethodResultDTO) { + } else if (value is DeletedStoredPaymentMethodResultDTO) { buffer.putUint8(150); writeValue(buffer, value.encode()); - } else if (value is CardComponentConfigurationDTO) { + } else if (value is CardComponentConfigurationDTO) { buffer.putUint8(151); writeValue(buffer, value.encode()); - } else if (value is InstantPaymentConfigurationDTO) { + } else if (value is InstantPaymentConfigurationDTO) { buffer.putUint8(152); writeValue(buffer, value.encode()); - } else if (value is InstantPaymentSetupResultDTO) { + } else if (value is InstantPaymentSetupResultDTO) { buffer.putUint8(153); writeValue(buffer, value.encode()); - } else if (value is UnencryptedCardDTO) { + } else if (value is UnencryptedCardDTO) { buffer.putUint8(154); writeValue(buffer, value.encode()); - } else if (value is EncryptedCardDTO) { + } else if (value is EncryptedCardDTO) { buffer.putUint8(155); writeValue(buffer, value.encode()); - } else if (value is ActionComponentConfigurationDTO) { + } else if (value is ActionComponentConfigurationDTO) { buffer.putUint8(156); writeValue(buffer, value.encode()); - } else if (value is OrderCancelResultDTO) { + } else if (value is OrderCancelResultDTO) { buffer.putUint8(157); writeValue(buffer, value.encode()); - } else if (value is Environment) { + } else if (value is Environment) { buffer.putUint8(158); writeValue(buffer, value.index); - } else if (value is AddressMode) { + } else if (value is AddressMode) { buffer.putUint8(159); writeValue(buffer, value.index); - } else if (value is CardAuthMethod) { + } else if (value is CardAuthMethod) { buffer.putUint8(160); writeValue(buffer, value.index); - } else if (value is TotalPriceStatus) { + } else if (value is TotalPriceStatus) { buffer.putUint8(161); writeValue(buffer, value.index); - } else if (value is GooglePayEnvironment) { + } else if (value is GooglePayEnvironment) { buffer.putUint8(162); writeValue(buffer, value.index); - } else if (value is CashAppPayEnvironment) { + } else if (value is CashAppPayEnvironment) { buffer.putUint8(163); writeValue(buffer, value.index); - } else if (value is PaymentResultEnum) { + } else if (value is PaymentResultEnum) { buffer.putUint8(164); writeValue(buffer, value.index); - } else if (value is PlatformCommunicationType) { + } else if (value is CheckoutEventType) { buffer.putUint8(165); writeValue(buffer, value.index); - } else if (value is ComponentCommunicationType) { + } else if (value is ComponentCommunicationType) { buffer.putUint8(166); writeValue(buffer, value.index); - } else if (value is PaymentEventType) { + } else if (value is PaymentEventType) { buffer.putUint8(167); writeValue(buffer, value.index); - } else if (value is FieldVisibility) { + } else if (value is FieldVisibility) { buffer.putUint8(168); writeValue(buffer, value.index); - } else if (value is InstantPaymentType) { + } else if (value is InstantPaymentType) { buffer.putUint8(169); writeValue(buffer, value.index); - } else if (value is ApplePayShippingType) { + } else if (value is ApplePayShippingType) { buffer.putUint8(170); writeValue(buffer, value.index); - } else if (value is ApplePayMerchantCapability) { + } else if (value is ApplePayMerchantCapability) { buffer.putUint8(171); writeValue(buffer, value.index); - } else if (value is ApplePaySummaryItemType) { + } else if (value is ApplePaySummaryItemType) { buffer.putUint8(172); writeValue(buffer, value.index); - } else if (value is CardNumberValidationResultDTO) { + } else if (value is CardNumberValidationResultDTO) { buffer.putUint8(173); writeValue(buffer, value.index); - } else if (value is CardExpiryDateValidationResultDTO) { + } else if (value is CardExpiryDateValidationResultDTO) { buffer.putUint8(174); writeValue(buffer, value.index); - } else if (value is CardSecurityCodeValidationResultDTO) { + } else if (value is CardSecurityCodeValidationResultDTO) { buffer.putUint8(175); writeValue(buffer, value.index); } else { @@ -1525,118 +1527,124 @@ class _PigeonCodec extends StandardMessageCodec { @override Object? readValueOfType(int type, ReadBuffer buffer) { switch (type) { - case 129: + case 129: return SessionDTO.decode(readValue(buffer)!); - case 130: + case 130: return AmountDTO.decode(readValue(buffer)!); - case 131: + case 131: return AnalyticsOptionsDTO.decode(readValue(buffer)!); - case 132: + case 132: return DropInConfigurationDTO.decode(readValue(buffer)!); - case 133: + case 133: return CardConfigurationDTO.decode(readValue(buffer)!); - case 134: + case 134: return ApplePayConfigurationDTO.decode(readValue(buffer)!); - case 135: + case 135: return ApplePayContactDTO.decode(readValue(buffer)!); - case 136: + case 136: return ApplePayShippingMethodDTO.decode(readValue(buffer)!); - case 137: + case 137: return ApplePaySummaryItemDTO.decode(readValue(buffer)!); - case 138: + case 138: return GooglePayConfigurationDTO.decode(readValue(buffer)!); - case 139: + case 139: return MerchantInfoDTO.decode(readValue(buffer)!); - case 140: + case 140: return ShippingAddressParametersDTO.decode(readValue(buffer)!); - case 141: + case 141: return BillingAddressParametersDTO.decode(readValue(buffer)!); - case 142: + case 142: return CashAppPayConfigurationDTO.decode(readValue(buffer)!); - case 143: + case 143: return PaymentResultDTO.decode(readValue(buffer)!); - case 144: + case 144: return PaymentResultModelDTO.decode(readValue(buffer)!); - case 145: + case 145: return OrderResponseDTO.decode(readValue(buffer)!); - case 146: - return PlatformCommunicationModel.decode(readValue(buffer)!); - case 147: + case 146: + return CheckoutEvent.decode(readValue(buffer)!); + case 147: return ComponentCommunicationModel.decode(readValue(buffer)!); - case 148: + case 148: return PaymentEventDTO.decode(readValue(buffer)!); - case 149: + case 149: return ErrorDTO.decode(readValue(buffer)!); - case 150: + case 150: return DeletedStoredPaymentMethodResultDTO.decode(readValue(buffer)!); - case 151: + case 151: return CardComponentConfigurationDTO.decode(readValue(buffer)!); - case 152: + case 152: return InstantPaymentConfigurationDTO.decode(readValue(buffer)!); - case 153: + case 153: return InstantPaymentSetupResultDTO.decode(readValue(buffer)!); - case 154: + case 154: return UnencryptedCardDTO.decode(readValue(buffer)!); - case 155: + case 155: return EncryptedCardDTO.decode(readValue(buffer)!); - case 156: + case 156: return ActionComponentConfigurationDTO.decode(readValue(buffer)!); - case 157: + case 157: return OrderCancelResultDTO.decode(readValue(buffer)!); - case 158: + case 158: final int? value = readValue(buffer) as int?; return value == null ? null : Environment.values[value]; - case 159: + case 159: final int? value = readValue(buffer) as int?; return value == null ? null : AddressMode.values[value]; - case 160: + case 160: final int? value = readValue(buffer) as int?; return value == null ? null : CardAuthMethod.values[value]; - case 161: + case 161: final int? value = readValue(buffer) as int?; return value == null ? null : TotalPriceStatus.values[value]; - case 162: + case 162: final int? value = readValue(buffer) as int?; return value == null ? null : GooglePayEnvironment.values[value]; - case 163: + case 163: final int? value = readValue(buffer) as int?; return value == null ? null : CashAppPayEnvironment.values[value]; - case 164: + case 164: final int? value = readValue(buffer) as int?; return value == null ? null : PaymentResultEnum.values[value]; - case 165: + case 165: final int? value = readValue(buffer) as int?; - return value == null ? null : PlatformCommunicationType.values[value]; - case 166: + return value == null ? null : CheckoutEventType.values[value]; + case 166: final int? value = readValue(buffer) as int?; return value == null ? null : ComponentCommunicationType.values[value]; - case 167: + case 167: final int? value = readValue(buffer) as int?; return value == null ? null : PaymentEventType.values[value]; - case 168: + case 168: final int? value = readValue(buffer) as int?; return value == null ? null : FieldVisibility.values[value]; - case 169: + case 169: final int? value = readValue(buffer) as int?; return value == null ? null : InstantPaymentType.values[value]; - case 170: + case 170: final int? value = readValue(buffer) as int?; return value == null ? null : ApplePayShippingType.values[value]; - case 171: + case 171: final int? value = readValue(buffer) as int?; return value == null ? null : ApplePayMerchantCapability.values[value]; - case 172: + case 172: final int? value = readValue(buffer) as int?; return value == null ? null : ApplePaySummaryItemType.values[value]; - case 173: + case 173: final int? value = readValue(buffer) as int?; - return value == null ? null : CardNumberValidationResultDTO.values[value]; - case 174: + return value == null + ? null + : CardNumberValidationResultDTO.values[value]; + case 174: final int? value = readValue(buffer) as int?; - return value == null ? null : CardExpiryDateValidationResultDTO.values[value]; - case 175: + return value == null + ? null + : CardExpiryDateValidationResultDTO.values[value]; + case 175: final int? value = readValue(buffer) as int?; - return value == null ? null : CardSecurityCodeValidationResultDTO.values[value]; + return value == null + ? null + : CardSecurityCodeValidationResultDTO.values[value]; default: return super.readValueOfType(type, buffer); } @@ -1647,9 +1655,11 @@ class CheckoutPlatformInterface { /// Constructor for [CheckoutPlatformInterface]. The [binaryMessenger] named argument is /// available for dependency injection. If it is left null, the default /// BinaryMessenger will be used which routes to the host platform. - CheckoutPlatformInterface({BinaryMessenger? binaryMessenger, String messageChannelSuffix = ''}) + CheckoutPlatformInterface( + {BinaryMessenger? binaryMessenger, String messageChannelSuffix = ''}) : __pigeon_binaryMessenger = binaryMessenger, - __pigeon_messageChannelSuffix = messageChannelSuffix.isNotEmpty ? '.$messageChannelSuffix' : ''; + __pigeon_messageChannelSuffix = + messageChannelSuffix.isNotEmpty ? '.$messageChannelSuffix' : ''; final BinaryMessenger? __pigeon_binaryMessenger; static const MessageCodec pigeonChannelCodec = _PigeonCodec(); @@ -1657,8 +1667,10 @@ class CheckoutPlatformInterface { final String __pigeon_messageChannelSuffix; Future getReturnUrl() async { - final String __pigeon_channelName = 'dev.flutter.pigeon.adyen_checkout.CheckoutPlatformInterface.getReturnUrl$__pigeon_messageChannelSuffix'; - final BasicMessageChannel __pigeon_channel = BasicMessageChannel( + final String __pigeon_channelName = + 'dev.flutter.pigeon.adyen_checkout.CheckoutPlatformInterface.getReturnUrl$__pigeon_messageChannelSuffix'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( __pigeon_channelName, pigeonChannelCodec, binaryMessenger: __pigeon_binaryMessenger, @@ -1683,15 +1695,19 @@ class CheckoutPlatformInterface { } } - Future createSession(String sessionId, String sessionData, Object? configuration) async { - final String __pigeon_channelName = 'dev.flutter.pigeon.adyen_checkout.CheckoutPlatformInterface.createSession$__pigeon_messageChannelSuffix'; - final BasicMessageChannel __pigeon_channel = BasicMessageChannel( + Future createSession( + String sessionId, String sessionData, Object? configuration) async { + final String __pigeon_channelName = + 'dev.flutter.pigeon.adyen_checkout.CheckoutPlatformInterface.createSession$__pigeon_messageChannelSuffix'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( __pigeon_channelName, pigeonChannelCodec, binaryMessenger: __pigeon_binaryMessenger, ); - final List? __pigeon_replyList = - await __pigeon_channel.send([sessionId, sessionData, configuration]) as List?; + final List? __pigeon_replyList = await __pigeon_channel + .send([sessionId, sessionData, configuration]) + as List?; if (__pigeon_replyList == null) { throw _createConnectionError(__pigeon_channelName); } else if (__pigeon_replyList.length > 1) { @@ -1711,8 +1727,10 @@ class CheckoutPlatformInterface { } Future clearSession() async { - final String __pigeon_channelName = 'dev.flutter.pigeon.adyen_checkout.CheckoutPlatformInterface.clearSession$__pigeon_messageChannelSuffix'; - final BasicMessageChannel __pigeon_channel = BasicMessageChannel( + final String __pigeon_channelName = + 'dev.flutter.pigeon.adyen_checkout.CheckoutPlatformInterface.clearSession$__pigeon_messageChannelSuffix'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( __pigeon_channelName, pigeonChannelCodec, binaryMessenger: __pigeon_binaryMessenger, @@ -1732,15 +1750,18 @@ class CheckoutPlatformInterface { } } - Future encryptCard(UnencryptedCardDTO unencryptedCardDTO, String publicKey) async { - final String __pigeon_channelName = 'dev.flutter.pigeon.adyen_checkout.CheckoutPlatformInterface.encryptCard$__pigeon_messageChannelSuffix'; - final BasicMessageChannel __pigeon_channel = BasicMessageChannel( + Future encryptCard( + UnencryptedCardDTO unencryptedCardDTO, String publicKey) async { + final String __pigeon_channelName = + 'dev.flutter.pigeon.adyen_checkout.CheckoutPlatformInterface.encryptCard$__pigeon_messageChannelSuffix'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( __pigeon_channelName, pigeonChannelCodec, binaryMessenger: __pigeon_binaryMessenger, ); - final List? __pigeon_replyList = - await __pigeon_channel.send([unencryptedCardDTO, publicKey]) as List?; + final List? __pigeon_replyList = await __pigeon_channel + .send([unencryptedCardDTO, publicKey]) as List?; if (__pigeon_replyList == null) { throw _createConnectionError(__pigeon_channelName); } else if (__pigeon_replyList.length > 1) { @@ -1760,14 +1781,16 @@ class CheckoutPlatformInterface { } Future encryptBin(String bin, String publicKey) async { - final String __pigeon_channelName = 'dev.flutter.pigeon.adyen_checkout.CheckoutPlatformInterface.encryptBin$__pigeon_messageChannelSuffix'; - final BasicMessageChannel __pigeon_channel = BasicMessageChannel( + final String __pigeon_channelName = + 'dev.flutter.pigeon.adyen_checkout.CheckoutPlatformInterface.encryptBin$__pigeon_messageChannelSuffix'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( __pigeon_channelName, pigeonChannelCodec, binaryMessenger: __pigeon_binaryMessenger, ); - final List? __pigeon_replyList = - await __pigeon_channel.send([bin, publicKey]) as List?; + final List? __pigeon_replyList = await __pigeon_channel + .send([bin, publicKey]) as List?; if (__pigeon_replyList == null) { throw _createConnectionError(__pigeon_channelName); } else if (__pigeon_replyList.length > 1) { @@ -1786,15 +1809,18 @@ class CheckoutPlatformInterface { } } - Future validateCardNumber(String cardNumber, bool enableLuhnCheck) async { - final String __pigeon_channelName = 'dev.flutter.pigeon.adyen_checkout.CheckoutPlatformInterface.validateCardNumber$__pigeon_messageChannelSuffix'; - final BasicMessageChannel __pigeon_channel = BasicMessageChannel( + Future validateCardNumber( + String cardNumber, bool enableLuhnCheck) async { + final String __pigeon_channelName = + 'dev.flutter.pigeon.adyen_checkout.CheckoutPlatformInterface.validateCardNumber$__pigeon_messageChannelSuffix'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( __pigeon_channelName, pigeonChannelCodec, binaryMessenger: __pigeon_binaryMessenger, ); - final List? __pigeon_replyList = - await __pigeon_channel.send([cardNumber, enableLuhnCheck]) as List?; + final List? __pigeon_replyList = await __pigeon_channel + .send([cardNumber, enableLuhnCheck]) as List?; if (__pigeon_replyList == null) { throw _createConnectionError(__pigeon_channelName); } else if (__pigeon_replyList.length > 1) { @@ -1813,15 +1839,18 @@ class CheckoutPlatformInterface { } } - Future validateCardExpiryDate(String expiryMonth, String expiryYear) async { - final String __pigeon_channelName = 'dev.flutter.pigeon.adyen_checkout.CheckoutPlatformInterface.validateCardExpiryDate$__pigeon_messageChannelSuffix'; - final BasicMessageChannel __pigeon_channel = BasicMessageChannel( + Future validateCardExpiryDate( + String expiryMonth, String expiryYear) async { + final String __pigeon_channelName = + 'dev.flutter.pigeon.adyen_checkout.CheckoutPlatformInterface.validateCardExpiryDate$__pigeon_messageChannelSuffix'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( __pigeon_channelName, pigeonChannelCodec, binaryMessenger: __pigeon_binaryMessenger, ); - final List? __pigeon_replyList = - await __pigeon_channel.send([expiryMonth, expiryYear]) as List?; + final List? __pigeon_replyList = await __pigeon_channel + .send([expiryMonth, expiryYear]) as List?; if (__pigeon_replyList == null) { throw _createConnectionError(__pigeon_channelName); } else if (__pigeon_replyList.length > 1) { @@ -1840,15 +1869,18 @@ class CheckoutPlatformInterface { } } - Future validateCardSecurityCode(String securityCode, String? cardBrand) async { - final String __pigeon_channelName = 'dev.flutter.pigeon.adyen_checkout.CheckoutPlatformInterface.validateCardSecurityCode$__pigeon_messageChannelSuffix'; - final BasicMessageChannel __pigeon_channel = BasicMessageChannel( + Future validateCardSecurityCode( + String securityCode, String? cardBrand) async { + final String __pigeon_channelName = + 'dev.flutter.pigeon.adyen_checkout.CheckoutPlatformInterface.validateCardSecurityCode$__pigeon_messageChannelSuffix'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( __pigeon_channelName, pigeonChannelCodec, binaryMessenger: __pigeon_binaryMessenger, ); - final List? __pigeon_replyList = - await __pigeon_channel.send([securityCode, cardBrand]) as List?; + final List? __pigeon_replyList = await __pigeon_channel + .send([securityCode, cardBrand]) as List?; if (__pigeon_replyList == null) { throw _createConnectionError(__pigeon_channelName); } else if (__pigeon_replyList.length > 1) { @@ -1868,14 +1900,16 @@ class CheckoutPlatformInterface { } Future enableConsoleLogging(bool loggingEnabled) async { - final String __pigeon_channelName = 'dev.flutter.pigeon.adyen_checkout.CheckoutPlatformInterface.enableConsoleLogging$__pigeon_messageChannelSuffix'; - final BasicMessageChannel __pigeon_channel = BasicMessageChannel( + final String __pigeon_channelName = + 'dev.flutter.pigeon.adyen_checkout.CheckoutPlatformInterface.enableConsoleLogging$__pigeon_messageChannelSuffix'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( __pigeon_channelName, pigeonChannelCodec, binaryMessenger: __pigeon_binaryMessenger, ); - final List? __pigeon_replyList = - await __pigeon_channel.send([loggingEnabled]) as List?; + final List? __pigeon_replyList = await __pigeon_channel + .send([loggingEnabled]) as List?; if (__pigeon_replyList == null) { throw _createConnectionError(__pigeon_channelName); } else if (__pigeon_replyList.length > 1) { @@ -1894,24 +1928,29 @@ class DropInPlatformInterface { /// Constructor for [DropInPlatformInterface]. The [binaryMessenger] named argument is /// available for dependency injection. If it is left null, the default /// BinaryMessenger will be used which routes to the host platform. - DropInPlatformInterface({BinaryMessenger? binaryMessenger, String messageChannelSuffix = ''}) + DropInPlatformInterface( + {BinaryMessenger? binaryMessenger, String messageChannelSuffix = ''}) : __pigeon_binaryMessenger = binaryMessenger, - __pigeon_messageChannelSuffix = messageChannelSuffix.isNotEmpty ? '.$messageChannelSuffix' : ''; + __pigeon_messageChannelSuffix = + messageChannelSuffix.isNotEmpty ? '.$messageChannelSuffix' : ''; final BinaryMessenger? __pigeon_binaryMessenger; static const MessageCodec pigeonChannelCodec = _PigeonCodec(); final String __pigeon_messageChannelSuffix; - Future showDropInSession(DropInConfigurationDTO dropInConfigurationDTO) async { - final String __pigeon_channelName = 'dev.flutter.pigeon.adyen_checkout.DropInPlatformInterface.showDropInSession$__pigeon_messageChannelSuffix'; - final BasicMessageChannel __pigeon_channel = BasicMessageChannel( + Future showDropInSession( + DropInConfigurationDTO dropInConfigurationDTO) async { + final String __pigeon_channelName = + 'dev.flutter.pigeon.adyen_checkout.DropInPlatformInterface.showDropInSession$__pigeon_messageChannelSuffix'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( __pigeon_channelName, pigeonChannelCodec, binaryMessenger: __pigeon_binaryMessenger, ); - final List? __pigeon_replyList = - await __pigeon_channel.send([dropInConfigurationDTO]) as List?; + final List? __pigeon_replyList = await __pigeon_channel + .send([dropInConfigurationDTO]) as List?; if (__pigeon_replyList == null) { throw _createConnectionError(__pigeon_channelName); } else if (__pigeon_replyList.length > 1) { @@ -1925,15 +1964,19 @@ class DropInPlatformInterface { } } - Future showDropInAdvanced(DropInConfigurationDTO dropInConfigurationDTO, String paymentMethodsResponse) async { - final String __pigeon_channelName = 'dev.flutter.pigeon.adyen_checkout.DropInPlatformInterface.showDropInAdvanced$__pigeon_messageChannelSuffix'; - final BasicMessageChannel __pigeon_channel = BasicMessageChannel( + Future showDropInAdvanced(DropInConfigurationDTO dropInConfigurationDTO, + String paymentMethodsResponse) async { + final String __pigeon_channelName = + 'dev.flutter.pigeon.adyen_checkout.DropInPlatformInterface.showDropInAdvanced$__pigeon_messageChannelSuffix'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( __pigeon_channelName, pigeonChannelCodec, binaryMessenger: __pigeon_binaryMessenger, ); - final List? __pigeon_replyList = - await __pigeon_channel.send([dropInConfigurationDTO, paymentMethodsResponse]) as List?; + final List? __pigeon_replyList = await __pigeon_channel + .send([dropInConfigurationDTO, paymentMethodsResponse]) + as List?; if (__pigeon_replyList == null) { throw _createConnectionError(__pigeon_channelName); } else if (__pigeon_replyList.length > 1) { @@ -1948,14 +1991,16 @@ class DropInPlatformInterface { } Future onPaymentsResult(PaymentEventDTO paymentsResult) async { - final String __pigeon_channelName = 'dev.flutter.pigeon.adyen_checkout.DropInPlatformInterface.onPaymentsResult$__pigeon_messageChannelSuffix'; - final BasicMessageChannel __pigeon_channel = BasicMessageChannel( + final String __pigeon_channelName = + 'dev.flutter.pigeon.adyen_checkout.DropInPlatformInterface.onPaymentsResult$__pigeon_messageChannelSuffix'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( __pigeon_channelName, pigeonChannelCodec, binaryMessenger: __pigeon_binaryMessenger, ); - final List? __pigeon_replyList = - await __pigeon_channel.send([paymentsResult]) as List?; + final List? __pigeon_replyList = await __pigeon_channel + .send([paymentsResult]) as List?; if (__pigeon_replyList == null) { throw _createConnectionError(__pigeon_channelName); } else if (__pigeon_replyList.length > 1) { @@ -1969,15 +2014,18 @@ class DropInPlatformInterface { } } - Future onPaymentsDetailsResult(PaymentEventDTO paymentsDetailsResult) async { - final String __pigeon_channelName = 'dev.flutter.pigeon.adyen_checkout.DropInPlatformInterface.onPaymentsDetailsResult$__pigeon_messageChannelSuffix'; - final BasicMessageChannel __pigeon_channel = BasicMessageChannel( + Future onPaymentsDetailsResult( + PaymentEventDTO paymentsDetailsResult) async { + final String __pigeon_channelName = + 'dev.flutter.pigeon.adyen_checkout.DropInPlatformInterface.onPaymentsDetailsResult$__pigeon_messageChannelSuffix'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( __pigeon_channelName, pigeonChannelCodec, binaryMessenger: __pigeon_binaryMessenger, ); - final List? __pigeon_replyList = - await __pigeon_channel.send([paymentsDetailsResult]) as List?; + final List? __pigeon_replyList = await __pigeon_channel + .send([paymentsDetailsResult]) as List?; if (__pigeon_replyList == null) { throw _createConnectionError(__pigeon_channelName); } else if (__pigeon_replyList.length > 1) { @@ -1991,15 +2039,19 @@ class DropInPlatformInterface { } } - Future onDeleteStoredPaymentMethodResult(DeletedStoredPaymentMethodResultDTO deleteStoredPaymentMethodResultDTO) async { - final String __pigeon_channelName = 'dev.flutter.pigeon.adyen_checkout.DropInPlatformInterface.onDeleteStoredPaymentMethodResult$__pigeon_messageChannelSuffix'; - final BasicMessageChannel __pigeon_channel = BasicMessageChannel( + Future onDeleteStoredPaymentMethodResult( + DeletedStoredPaymentMethodResultDTO + deleteStoredPaymentMethodResultDTO) async { + final String __pigeon_channelName = + 'dev.flutter.pigeon.adyen_checkout.DropInPlatformInterface.onDeleteStoredPaymentMethodResult$__pigeon_messageChannelSuffix'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( __pigeon_channelName, pigeonChannelCodec, binaryMessenger: __pigeon_binaryMessenger, ); - final List? __pigeon_replyList = - await __pigeon_channel.send([deleteStoredPaymentMethodResultDTO]) as List?; + final List? __pigeon_replyList = await __pigeon_channel + .send([deleteStoredPaymentMethodResultDTO]) as List?; if (__pigeon_replyList == null) { throw _createConnectionError(__pigeon_channelName); } else if (__pigeon_replyList.length > 1) { @@ -2014,14 +2066,16 @@ class DropInPlatformInterface { } Future onBalanceCheckResult(String balanceCheckResponse) async { - final String __pigeon_channelName = 'dev.flutter.pigeon.adyen_checkout.DropInPlatformInterface.onBalanceCheckResult$__pigeon_messageChannelSuffix'; - final BasicMessageChannel __pigeon_channel = BasicMessageChannel( + final String __pigeon_channelName = + 'dev.flutter.pigeon.adyen_checkout.DropInPlatformInterface.onBalanceCheckResult$__pigeon_messageChannelSuffix'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( __pigeon_channelName, pigeonChannelCodec, binaryMessenger: __pigeon_binaryMessenger, ); - final List? __pigeon_replyList = - await __pigeon_channel.send([balanceCheckResponse]) as List?; + final List? __pigeon_replyList = await __pigeon_channel + .send([balanceCheckResponse]) as List?; if (__pigeon_replyList == null) { throw _createConnectionError(__pigeon_channelName); } else if (__pigeon_replyList.length > 1) { @@ -2036,14 +2090,16 @@ class DropInPlatformInterface { } Future onOrderRequestResult(String orderRequestResponse) async { - final String __pigeon_channelName = 'dev.flutter.pigeon.adyen_checkout.DropInPlatformInterface.onOrderRequestResult$__pigeon_messageChannelSuffix'; - final BasicMessageChannel __pigeon_channel = BasicMessageChannel( + final String __pigeon_channelName = + 'dev.flutter.pigeon.adyen_checkout.DropInPlatformInterface.onOrderRequestResult$__pigeon_messageChannelSuffix'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( __pigeon_channelName, pigeonChannelCodec, binaryMessenger: __pigeon_binaryMessenger, ); - final List? __pigeon_replyList = - await __pigeon_channel.send([orderRequestResponse]) as List?; + final List? __pigeon_replyList = await __pigeon_channel + .send([orderRequestResponse]) as List?; if (__pigeon_replyList == null) { throw _createConnectionError(__pigeon_channelName); } else if (__pigeon_replyList.length > 1) { @@ -2057,15 +2113,18 @@ class DropInPlatformInterface { } } - Future onOrderCancelResult(OrderCancelResultDTO orderCancelResult) async { - final String __pigeon_channelName = 'dev.flutter.pigeon.adyen_checkout.DropInPlatformInterface.onOrderCancelResult$__pigeon_messageChannelSuffix'; - final BasicMessageChannel __pigeon_channel = BasicMessageChannel( + Future onOrderCancelResult( + OrderCancelResultDTO orderCancelResult) async { + final String __pigeon_channelName = + 'dev.flutter.pigeon.adyen_checkout.DropInPlatformInterface.onOrderCancelResult$__pigeon_messageChannelSuffix'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( __pigeon_channelName, pigeonChannelCodec, binaryMessenger: __pigeon_binaryMessenger, ); - final List? __pigeon_replyList = - await __pigeon_channel.send([orderCancelResult]) as List?; + final List? __pigeon_replyList = await __pigeon_channel + .send([orderCancelResult]) as List?; if (__pigeon_replyList == null) { throw _createConnectionError(__pigeon_channelName); } else if (__pigeon_replyList.length > 1) { @@ -2080,8 +2139,10 @@ class DropInPlatformInterface { } Future cleanUpDropIn() async { - final String __pigeon_channelName = 'dev.flutter.pigeon.adyen_checkout.DropInPlatformInterface.cleanUpDropIn$__pigeon_messageChannelSuffix'; - final BasicMessageChannel __pigeon_channel = BasicMessageChannel( + final String __pigeon_channelName = + 'dev.flutter.pigeon.adyen_checkout.DropInPlatformInterface.cleanUpDropIn$__pigeon_messageChannelSuffix'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( __pigeon_channelName, pigeonChannelCodec, binaryMessenger: __pigeon_binaryMessenger, @@ -2102,61 +2163,42 @@ class DropInPlatformInterface { } } -abstract class DropInFlutterInterface { +abstract class CheckoutFlutterInterface { static const MessageCodec pigeonChannelCodec = _PigeonCodec(); - void onDropInSessionPlatformCommunication(PlatformCommunicationModel platformCommunicationModel); - - void onDropInAdvancedPlatformCommunication(PlatformCommunicationModel platformCommunicationModel); + void send(CheckoutEvent event); - static void setUp(DropInFlutterInterface? api, {BinaryMessenger? binaryMessenger, String messageChannelSuffix = '',}) { - messageChannelSuffix = messageChannelSuffix.isNotEmpty ? '.$messageChannelSuffix' : ''; + static void setUp( + CheckoutFlutterInterface? api, { + BinaryMessenger? binaryMessenger, + String messageChannelSuffix = '', + }) { + messageChannelSuffix = + messageChannelSuffix.isNotEmpty ? '.$messageChannelSuffix' : ''; { - final BasicMessageChannel __pigeon_channel = BasicMessageChannel( - 'dev.flutter.pigeon.adyen_checkout.DropInFlutterInterface.onDropInSessionPlatformCommunication$messageChannelSuffix', pigeonChannelCodec, + final BasicMessageChannel __pigeon_channel = BasicMessageChannel< + Object?>( + 'dev.flutter.pigeon.adyen_checkout.CheckoutFlutterInterface.send$messageChannelSuffix', + pigeonChannelCodec, binaryMessenger: binaryMessenger); if (api == null) { __pigeon_channel.setMessageHandler(null); } else { __pigeon_channel.setMessageHandler((Object? message) async { assert(message != null, - 'Argument for dev.flutter.pigeon.adyen_checkout.DropInFlutterInterface.onDropInSessionPlatformCommunication was null.'); + 'Argument for dev.flutter.pigeon.adyen_checkout.CheckoutFlutterInterface.send was null.'); final List args = (message as List?)!; - final PlatformCommunicationModel? arg_platformCommunicationModel = (args[0] as PlatformCommunicationModel?); - assert(arg_platformCommunicationModel != null, - 'Argument for dev.flutter.pigeon.adyen_checkout.DropInFlutterInterface.onDropInSessionPlatformCommunication was null, expected non-null PlatformCommunicationModel.'); + final CheckoutEvent? arg_event = (args[0] as CheckoutEvent?); + assert(arg_event != null, + 'Argument for dev.flutter.pigeon.adyen_checkout.CheckoutFlutterInterface.send was null, expected non-null CheckoutEvent.'); try { - api.onDropInSessionPlatformCommunication(arg_platformCommunicationModel!); + api.send(arg_event!); return wrapResponse(empty: true); } on PlatformException catch (e) { return wrapResponse(error: e); - } catch (e) { - return wrapResponse(error: PlatformException(code: 'error', message: e.toString())); - } - }); - } - } - { - final BasicMessageChannel __pigeon_channel = BasicMessageChannel( - 'dev.flutter.pigeon.adyen_checkout.DropInFlutterInterface.onDropInAdvancedPlatformCommunication$messageChannelSuffix', pigeonChannelCodec, - binaryMessenger: binaryMessenger); - if (api == null) { - __pigeon_channel.setMessageHandler(null); - } else { - __pigeon_channel.setMessageHandler((Object? message) async { - assert(message != null, - 'Argument for dev.flutter.pigeon.adyen_checkout.DropInFlutterInterface.onDropInAdvancedPlatformCommunication was null.'); - final List args = (message as List?)!; - final PlatformCommunicationModel? arg_platformCommunicationModel = (args[0] as PlatformCommunicationModel?); - assert(arg_platformCommunicationModel != null, - 'Argument for dev.flutter.pigeon.adyen_checkout.DropInFlutterInterface.onDropInAdvancedPlatformCommunication was null, expected non-null PlatformCommunicationModel.'); - try { - api.onDropInAdvancedPlatformCommunication(arg_platformCommunicationModel!); - return wrapResponse(empty: true); - } on PlatformException catch (e) { - return wrapResponse(error: e); - } catch (e) { - return wrapResponse(error: PlatformException(code: 'error', message: e.toString())); + } catch (e) { + return wrapResponse( + error: PlatformException(code: 'error', message: e.toString())); } }); } @@ -2168,9 +2210,11 @@ class ComponentPlatformInterface { /// Constructor for [ComponentPlatformInterface]. The [binaryMessenger] named argument is /// available for dependency injection. If it is left null, the default /// BinaryMessenger will be used which routes to the host platform. - ComponentPlatformInterface({BinaryMessenger? binaryMessenger, String messageChannelSuffix = ''}) + ComponentPlatformInterface( + {BinaryMessenger? binaryMessenger, String messageChannelSuffix = ''}) : __pigeon_binaryMessenger = binaryMessenger, - __pigeon_messageChannelSuffix = messageChannelSuffix.isNotEmpty ? '.$messageChannelSuffix' : ''; + __pigeon_messageChannelSuffix = + messageChannelSuffix.isNotEmpty ? '.$messageChannelSuffix' : ''; final BinaryMessenger? __pigeon_binaryMessenger; static const MessageCodec pigeonChannelCodec = _PigeonCodec(); @@ -2178,8 +2222,10 @@ class ComponentPlatformInterface { final String __pigeon_messageChannelSuffix; Future updateViewHeight(int viewId) async { - final String __pigeon_channelName = 'dev.flutter.pigeon.adyen_checkout.ComponentPlatformInterface.updateViewHeight$__pigeon_messageChannelSuffix'; - final BasicMessageChannel __pigeon_channel = BasicMessageChannel( + final String __pigeon_channelName = + 'dev.flutter.pigeon.adyen_checkout.ComponentPlatformInterface.updateViewHeight$__pigeon_messageChannelSuffix'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( __pigeon_channelName, pigeonChannelCodec, binaryMessenger: __pigeon_binaryMessenger, @@ -2199,15 +2245,18 @@ class ComponentPlatformInterface { } } - Future onPaymentsResult(String componentId, PaymentEventDTO paymentsResult) async { - final String __pigeon_channelName = 'dev.flutter.pigeon.adyen_checkout.ComponentPlatformInterface.onPaymentsResult$__pigeon_messageChannelSuffix'; - final BasicMessageChannel __pigeon_channel = BasicMessageChannel( + Future onPaymentsResult( + String componentId, PaymentEventDTO paymentsResult) async { + final String __pigeon_channelName = + 'dev.flutter.pigeon.adyen_checkout.ComponentPlatformInterface.onPaymentsResult$__pigeon_messageChannelSuffix'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( __pigeon_channelName, pigeonChannelCodec, binaryMessenger: __pigeon_binaryMessenger, ); - final List? __pigeon_replyList = - await __pigeon_channel.send([componentId, paymentsResult]) as List?; + final List? __pigeon_replyList = await __pigeon_channel + .send([componentId, paymentsResult]) as List?; if (__pigeon_replyList == null) { throw _createConnectionError(__pigeon_channelName); } else if (__pigeon_replyList.length > 1) { @@ -2221,15 +2270,18 @@ class ComponentPlatformInterface { } } - Future onPaymentsDetailsResult(String componentId, PaymentEventDTO paymentsDetailsResult) async { - final String __pigeon_channelName = 'dev.flutter.pigeon.adyen_checkout.ComponentPlatformInterface.onPaymentsDetailsResult$__pigeon_messageChannelSuffix'; - final BasicMessageChannel __pigeon_channel = BasicMessageChannel( + Future onPaymentsDetailsResult( + String componentId, PaymentEventDTO paymentsDetailsResult) async { + final String __pigeon_channelName = + 'dev.flutter.pigeon.adyen_checkout.ComponentPlatformInterface.onPaymentsDetailsResult$__pigeon_messageChannelSuffix'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( __pigeon_channelName, pigeonChannelCodec, binaryMessenger: __pigeon_binaryMessenger, ); - final List? __pigeon_replyList = - await __pigeon_channel.send([componentId, paymentsDetailsResult]) as List?; + final List? __pigeon_replyList = await __pigeon_channel + .send([componentId, paymentsDetailsResult]) as List?; if (__pigeon_replyList == null) { throw _createConnectionError(__pigeon_channelName); } else if (__pigeon_replyList.length > 1) { @@ -2243,15 +2295,24 @@ class ComponentPlatformInterface { } } - Future isInstantPaymentSupportedByPlatform(InstantPaymentConfigurationDTO instantPaymentConfigurationDTO, String paymentMethodResponse, String componentId) async { - final String __pigeon_channelName = 'dev.flutter.pigeon.adyen_checkout.ComponentPlatformInterface.isInstantPaymentSupportedByPlatform$__pigeon_messageChannelSuffix'; - final BasicMessageChannel __pigeon_channel = BasicMessageChannel( + Future isInstantPaymentSupportedByPlatform( + InstantPaymentConfigurationDTO instantPaymentConfigurationDTO, + String paymentMethodResponse, + String componentId) async { + final String __pigeon_channelName = + 'dev.flutter.pigeon.adyen_checkout.ComponentPlatformInterface.isInstantPaymentSupportedByPlatform$__pigeon_messageChannelSuffix'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( __pigeon_channelName, pigeonChannelCodec, binaryMessenger: __pigeon_binaryMessenger, ); - final List? __pigeon_replyList = - await __pigeon_channel.send([instantPaymentConfigurationDTO, paymentMethodResponse, componentId]) as List?; + final List? __pigeon_replyList = await __pigeon_channel + .send([ + instantPaymentConfigurationDTO, + paymentMethodResponse, + componentId + ]) as List?; if (__pigeon_replyList == null) { throw _createConnectionError(__pigeon_channelName); } else if (__pigeon_replyList.length > 1) { @@ -2270,15 +2331,24 @@ class ComponentPlatformInterface { } } - Future onInstantPaymentPressed(InstantPaymentConfigurationDTO instantPaymentConfigurationDTO, String encodedPaymentMethod, String componentId) async { - final String __pigeon_channelName = 'dev.flutter.pigeon.adyen_checkout.ComponentPlatformInterface.onInstantPaymentPressed$__pigeon_messageChannelSuffix'; - final BasicMessageChannel __pigeon_channel = BasicMessageChannel( + Future onInstantPaymentPressed( + InstantPaymentConfigurationDTO instantPaymentConfigurationDTO, + String encodedPaymentMethod, + String componentId) async { + final String __pigeon_channelName = + 'dev.flutter.pigeon.adyen_checkout.ComponentPlatformInterface.onInstantPaymentPressed$__pigeon_messageChannelSuffix'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( __pigeon_channelName, pigeonChannelCodec, binaryMessenger: __pigeon_binaryMessenger, ); - final List? __pigeon_replyList = - await __pigeon_channel.send([instantPaymentConfigurationDTO, encodedPaymentMethod, componentId]) as List?; + final List? __pigeon_replyList = await __pigeon_channel + .send([ + instantPaymentConfigurationDTO, + encodedPaymentMethod, + componentId + ]) as List?; if (__pigeon_replyList == null) { throw _createConnectionError(__pigeon_channelName); } else if (__pigeon_replyList.length > 1) { @@ -2292,15 +2362,24 @@ class ComponentPlatformInterface { } } - Future handleAction(ActionComponentConfigurationDTO actionComponentConfiguration, String componentId, Map? actionResponse) async { - final String __pigeon_channelName = 'dev.flutter.pigeon.adyen_checkout.ComponentPlatformInterface.handleAction$__pigeon_messageChannelSuffix'; - final BasicMessageChannel __pigeon_channel = BasicMessageChannel( + Future handleAction( + ActionComponentConfigurationDTO actionComponentConfiguration, + String componentId, + Map? actionResponse) async { + final String __pigeon_channelName = + 'dev.flutter.pigeon.adyen_checkout.ComponentPlatformInterface.handleAction$__pigeon_messageChannelSuffix'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( __pigeon_channelName, pigeonChannelCodec, binaryMessenger: __pigeon_binaryMessenger, ); - final List? __pigeon_replyList = - await __pigeon_channel.send([actionComponentConfiguration, componentId, actionResponse]) as List?; + final List? __pigeon_replyList = await __pigeon_channel + .send([ + actionComponentConfiguration, + componentId, + actionResponse + ]) as List?; if (__pigeon_replyList == null) { throw _createConnectionError(__pigeon_channelName); } else if (__pigeon_replyList.length > 1) { @@ -2315,8 +2394,10 @@ class ComponentPlatformInterface { } Future onDispose(String componentId) async { - final String __pigeon_channelName = 'dev.flutter.pigeon.adyen_checkout.ComponentPlatformInterface.onDispose$__pigeon_messageChannelSuffix'; - final BasicMessageChannel __pigeon_channel = BasicMessageChannel( + final String __pigeon_channelName = + 'dev.flutter.pigeon.adyen_checkout.ComponentPlatformInterface.onDispose$__pigeon_messageChannelSuffix'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( __pigeon_channelName, pigeonChannelCodec, binaryMessenger: __pigeon_binaryMessenger, @@ -2340,52 +2421,69 @@ class ComponentPlatformInterface { abstract class ComponentFlutterInterface { static const MessageCodec pigeonChannelCodec = _PigeonCodec(); - void _generateCodecForDTOs(CardComponentConfigurationDTO cardComponentConfigurationDTO, SessionDTO sessionDTO); + void _generateCodecForDTOs( + CardComponentConfigurationDTO cardComponentConfigurationDTO, + SessionDTO sessionDTO); - void onComponentCommunication(ComponentCommunicationModel componentCommunicationModel); + void onComponentCommunication( + ComponentCommunicationModel componentCommunicationModel); - static void setUp(ComponentFlutterInterface? api, {BinaryMessenger? binaryMessenger, String messageChannelSuffix = '',}) { - messageChannelSuffix = messageChannelSuffix.isNotEmpty ? '.$messageChannelSuffix' : ''; + static void setUp( + ComponentFlutterInterface? api, { + BinaryMessenger? binaryMessenger, + String messageChannelSuffix = '', + }) { + messageChannelSuffix = + messageChannelSuffix.isNotEmpty ? '.$messageChannelSuffix' : ''; { - final BasicMessageChannel __pigeon_channel = BasicMessageChannel( - 'dev.flutter.pigeon.adyen_checkout.ComponentFlutterInterface._generateCodecForDTOs$messageChannelSuffix', pigeonChannelCodec, + final BasicMessageChannel __pigeon_channel = BasicMessageChannel< + Object?>( + 'dev.flutter.pigeon.adyen_checkout.ComponentFlutterInterface._generateCodecForDTOs$messageChannelSuffix', + pigeonChannelCodec, binaryMessenger: binaryMessenger); if (api == null) { __pigeon_channel.setMessageHandler(null); } else { __pigeon_channel.setMessageHandler((Object? message) async { assert(message != null, - 'Argument for dev.flutter.pigeon.adyen_checkout.ComponentFlutterInterface._generateCodecForDTOs was null.'); + 'Argument for dev.flutter.pigeon.adyen_checkout.ComponentFlutterInterface._generateCodecForDTOs was null.'); final List args = (message as List?)!; - final CardComponentConfigurationDTO? arg_cardComponentConfigurationDTO = (args[0] as CardComponentConfigurationDTO?); + final CardComponentConfigurationDTO? + arg_cardComponentConfigurationDTO = + (args[0] as CardComponentConfigurationDTO?); assert(arg_cardComponentConfigurationDTO != null, 'Argument for dev.flutter.pigeon.adyen_checkout.ComponentFlutterInterface._generateCodecForDTOs was null, expected non-null CardComponentConfigurationDTO.'); final SessionDTO? arg_sessionDTO = (args[1] as SessionDTO?); assert(arg_sessionDTO != null, 'Argument for dev.flutter.pigeon.adyen_checkout.ComponentFlutterInterface._generateCodecForDTOs was null, expected non-null SessionDTO.'); try { - api._generateCodecForDTOs(arg_cardComponentConfigurationDTO!, arg_sessionDTO!); + api._generateCodecForDTOs( + arg_cardComponentConfigurationDTO!, arg_sessionDTO!); return wrapResponse(empty: true); } on PlatformException catch (e) { return wrapResponse(error: e); - } catch (e) { - return wrapResponse(error: PlatformException(code: 'error', message: e.toString())); + } catch (e) { + return wrapResponse( + error: PlatformException(code: 'error', message: e.toString())); } }); } } { - final BasicMessageChannel __pigeon_channel = BasicMessageChannel( - 'dev.flutter.pigeon.adyen_checkout.ComponentFlutterInterface.onComponentCommunication$messageChannelSuffix', pigeonChannelCodec, + final BasicMessageChannel __pigeon_channel = BasicMessageChannel< + Object?>( + 'dev.flutter.pigeon.adyen_checkout.ComponentFlutterInterface.onComponentCommunication$messageChannelSuffix', + pigeonChannelCodec, binaryMessenger: binaryMessenger); if (api == null) { __pigeon_channel.setMessageHandler(null); } else { __pigeon_channel.setMessageHandler((Object? message) async { assert(message != null, - 'Argument for dev.flutter.pigeon.adyen_checkout.ComponentFlutterInterface.onComponentCommunication was null.'); + 'Argument for dev.flutter.pigeon.adyen_checkout.ComponentFlutterInterface.onComponentCommunication was null.'); final List args = (message as List?)!; - final ComponentCommunicationModel? arg_componentCommunicationModel = (args[0] as ComponentCommunicationModel?); + final ComponentCommunicationModel? arg_componentCommunicationModel = + (args[0] as ComponentCommunicationModel?); assert(arg_componentCommunicationModel != null, 'Argument for dev.flutter.pigeon.adyen_checkout.ComponentFlutterInterface.onComponentCommunication was null, expected non-null ComponentCommunicationModel.'); try { @@ -2393,8 +2491,9 @@ abstract class ComponentFlutterInterface { return wrapResponse(empty: true); } on PlatformException catch (e) { return wrapResponse(error: e); - } catch (e) { - return wrapResponse(error: PlatformException(code: 'error', message: e.toString())); + } catch (e) { + return wrapResponse( + error: PlatformException(code: 'error', message: e.toString())); } }); } diff --git a/pigeons/platform_api.dart b/pigeons/platform_api.dart index 175cd954..b0e1e576 100644 --- a/pigeons/platform_api.dart +++ b/pigeons/platform_api.dart @@ -56,7 +56,7 @@ enum PaymentResultEnum { finished, } -enum PlatformCommunicationType { +enum CheckoutEventType { paymentComponent, additionalDetails, result, @@ -436,15 +436,13 @@ class OrderResponseDTO { }); } -class PlatformCommunicationModel { - final PlatformCommunicationType type; - final String? data; - final PaymentResultDTO? paymentResult; +class CheckoutEvent { + final CheckoutEventType type; + final Object? data; - PlatformCommunicationModel({ + CheckoutEvent({ required this.type, this.data, - this.paymentResult, }); } @@ -678,12 +676,8 @@ abstract class DropInPlatformInterface { } @FlutterApi() -abstract class DropInFlutterInterface { - void onDropInSessionPlatformCommunication( - PlatformCommunicationModel platformCommunicationModel); - - void onDropInAdvancedPlatformCommunication( - PlatformCommunicationModel platformCommunicationModel); +abstract class CheckoutFlutterInterface { + void send(CheckoutEvent event); } @HostApi()