From 11e5be07413262dec60226bde51f824209822537 Mon Sep 17 00:00:00 2001 From: Robert Schulze Dieckhoff Date: Tue, 12 Dec 2023 18:20:45 +0100 Subject: [PATCH] Adjusted dropin to use the generic createSession method instead of requesting a own session. --- .../adyen_checkout/AdyenCheckoutPlugin.kt | 2 +- .../adyen_checkout/CheckoutPlatformApi.kt | 3 +- .../com/adyen/adyen_checkout/PlatformApi.kt | 14 +-- .../dropIn/DropInPlatformApi.kt | 53 ++++------ .../lib/screens/drop_in/drop_in_screen.dart | 7 +- ios/Classes/AdyenCheckoutPlugin.swift | 4 +- ios/Classes/CheckoutPlatformApi.swift | 99 ++++++++++++++----- ios/Classes/PlatformApi.swift | 10 +- ios/Classes/dropIn/DropInPlatformApi.swift | 62 ++++-------- .../DropInSessionsDelegate.swift | 2 +- lib/src/adyen_checkout.dart | 31 +++--- lib/src/drop_in/drop_in.dart | 1 - lib/src/drop_in/drop_in_platform_api.dart | 2 - lib/src/generated/platform_api.g.dart | 9 +- pigeons/platform_api.dart | 1 - 15 files changed, 150 insertions(+), 150 deletions(-) diff --git a/android/src/main/kotlin/com/adyen/adyen_checkout/AdyenCheckoutPlugin.kt b/android/src/main/kotlin/com/adyen/adyen_checkout/AdyenCheckoutPlugin.kt index 647aedfc..6281c86e 100644 --- a/android/src/main/kotlin/com/adyen/adyen_checkout/AdyenCheckoutPlugin.kt +++ b/android/src/main/kotlin/com/adyen/adyen_checkout/AdyenCheckoutPlugin.kt @@ -40,7 +40,7 @@ class AdyenCheckoutPlugin : FlutterPlugin, ActivityAware { //DropIn init dropInFlutterApi = DropInFlutterInterface(flutterPluginBinding.binaryMessenger) - dropInFlutterApi?.let { dropInPlatformApi = DropInPlatformApi(it) } + dropInFlutterApi?.let { dropInPlatformApi = DropInPlatformApi(it, sessionHolder) } DropInPlatformInterface.setUp(flutterPluginBinding.binaryMessenger, dropInPlatformApi) //Component init diff --git a/android/src/main/kotlin/com/adyen/adyen_checkout/CheckoutPlatformApi.kt b/android/src/main/kotlin/com/adyen/adyen_checkout/CheckoutPlatformApi.kt index 65e80b53..b40a1d2a 100644 --- a/android/src/main/kotlin/com/adyen/adyen_checkout/CheckoutPlatformApi.kt +++ b/android/src/main/kotlin/com/adyen/adyen_checkout/CheckoutPlatformApi.kt @@ -9,6 +9,7 @@ import androidx.fragment.app.FragmentActivity import androidx.lifecycle.lifecycleScope import com.adyen.adyen_checkout.session.SessionHolder import com.adyen.adyen_checkout.utils.ConfigurationMapper.mapToAnalyticsConfiguration +import com.adyen.adyen_checkout.utils.ConfigurationMapper.mapToDropInConfiguration import com.adyen.adyen_checkout.utils.ConfigurationMapper.toNativeModel import com.adyen.checkout.components.core.OrderRequest import com.adyen.checkout.components.core.PaymentMethodsApiResponse @@ -66,7 +67,7 @@ class CheckoutPlatformApi( } is DropInConfigurationDTO -> { - //TODO: Add support for DropIn session + return configuration.mapToDropInConfiguration(activity) } } diff --git a/android/src/main/kotlin/com/adyen/adyen_checkout/PlatformApi.kt b/android/src/main/kotlin/com/adyen/adyen_checkout/PlatformApi.kt index ea672f96..82e94567 100644 --- a/android/src/main/kotlin/com/adyen/adyen_checkout/PlatformApi.kt +++ b/android/src/main/kotlin/com/adyen/adyen_checkout/PlatformApi.kt @@ -1003,11 +1003,6 @@ private object DropInPlatformInterfaceCodec : StandardMessageCodec() { PaymentFlowOutcomeDTO.fromList(it) } } - 138.toByte() -> { - return (readValue(buffer) as? List)?.let { - SessionDTO.fromList(it) - } - } else -> super.readValueOfType(type, buffer) } } @@ -1053,10 +1048,6 @@ private object DropInPlatformInterfaceCodec : StandardMessageCodec() { stream.write(137) writeValue(stream, value.toList()) } - is SessionDTO -> { - stream.write(138) - writeValue(stream, value.toList()) - } else -> super.writeValue(stream, value) } } @@ -1064,7 +1055,7 @@ private object DropInPlatformInterfaceCodec : StandardMessageCodec() { /** Generated interface from Pigeon that represents a handler of messages from Flutter. */ interface DropInPlatformInterface { - fun startDropInSessionPayment(dropInConfigurationDTO: DropInConfigurationDTO, session: SessionDTO) + fun startDropInSessionPayment(dropInConfigurationDTO: DropInConfigurationDTO) fun startDropInAdvancedFlowPayment(dropInConfigurationDTO: DropInConfigurationDTO, paymentMethodsResponse: String) fun onPaymentsResult(paymentsResult: PaymentFlowOutcomeDTO) fun onPaymentsDetailsResult(paymentsDetailsResult: PaymentFlowOutcomeDTO) @@ -1085,10 +1076,9 @@ interface DropInPlatformInterface { channel.setMessageHandler { message, reply -> val args = message as List val dropInConfigurationDTOArg = args[0] as DropInConfigurationDTO - val sessionArg = args[1] as SessionDTO var wrapped: List try { - api.startDropInSessionPayment(dropInConfigurationDTOArg, sessionArg) + api.startDropInSessionPayment(dropInConfigurationDTOArg) wrapped = listOf(null) } catch (exception: Throwable) { wrapped = wrapError(exception) diff --git a/android/src/main/kotlin/com/adyen/adyen_checkout/dropIn/DropInPlatformApi.kt b/android/src/main/kotlin/com/adyen/adyen_checkout/dropIn/DropInPlatformApi.kt index b3c87647..3f0e6c23 100644 --- a/android/src/main/kotlin/com/adyen/adyen_checkout/dropIn/DropInPlatformApi.kt +++ b/android/src/main/kotlin/com/adyen/adyen_checkout/dropIn/DropInPlatformApi.kt @@ -11,7 +11,6 @@ import PaymentResultEnum import PaymentResultModelDTO import PlatformCommunicationModel import PlatformCommunicationType -import SessionDTO import androidx.activity.result.ActivityResultLauncher import androidx.fragment.app.FragmentActivity import androidx.lifecycle.lifecycleScope @@ -24,9 +23,10 @@ import com.adyen.adyen_checkout.dropIn.dropInAdvancedFlow.DropInPaymentResultMes import com.adyen.adyen_checkout.dropIn.dropInAdvancedFlow.DropInServiceResultMessenger import com.adyen.adyen_checkout.dropIn.dropInSession.SessionDropInService import com.adyen.adyen_checkout.dropIn.models.DropInFlowType +import com.adyen.adyen_checkout.session.SessionHolder import com.adyen.adyen_checkout.utils.ConfigurationMapper.mapToDropInConfiguration import com.adyen.adyen_checkout.utils.ConfigurationMapper.mapToOrderResponseModel -import com.adyen.adyen_checkout.utils.ConfigurationMapper.mapToSession +import com.adyen.checkout.components.core.Order import com.adyen.checkout.components.core.PaymentMethodsApiResponse import com.adyen.checkout.dropin.DropIn import com.adyen.checkout.dropin.DropInCallback @@ -36,9 +36,7 @@ import com.adyen.checkout.dropin.SessionDropInResult import com.adyen.checkout.dropin.internal.ui.model.DropInResultContractParams import com.adyen.checkout.dropin.internal.ui.model.SessionDropInResultContractParams import com.adyen.checkout.sessions.core.CheckoutSession -import com.adyen.checkout.sessions.core.CheckoutSessionProvider -import com.adyen.checkout.sessions.core.CheckoutSessionResult -import com.adyen.checkout.sessions.core.SessionModel +import com.adyen.checkout.sessions.core.SessionSetupResponse import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch import kotlinx.coroutines.withContext @@ -46,29 +44,22 @@ import org.json.JSONObject class DropInPlatformApi( private val dropInFlutterApi: DropInFlutterInterface, + private val sessionHolder: SessionHolder, ) : DropInPlatformInterface { lateinit var activity: FragmentActivity lateinit var dropInSessionLauncher: ActivityResultLauncher lateinit var dropInAdvancedFlowLauncher: ActivityResultLauncher - override fun startDropInSessionPayment( - dropInConfigurationDTO: DropInConfigurationDTO, - session: SessionDTO, - ) { + override fun startDropInSessionPayment(dropInConfigurationDTO: DropInConfigurationDTO) { setStoredPaymentMethodDeletionObserver() - activity.lifecycleScope.launch(Dispatchers.IO) { - val sessionModel = session.mapToSession() - val dropInConfiguration = dropInConfigurationDTO.mapToDropInConfiguration(activity.applicationContext) - val checkoutSession = createCheckoutSession(sessionModel, dropInConfiguration) - withContext(Dispatchers.Main) { - DropIn.startPayment( - activity.applicationContext, - dropInSessionLauncher, - checkoutSession, - dropInConfiguration, - SessionDropInService::class.java - ) - } - } + val dropInConfiguration = dropInConfigurationDTO.mapToDropInConfiguration(activity.applicationContext) + val checkoutSession = createCheckoutSession(sessionHolder) + DropIn.startPayment( + activity.applicationContext, + dropInSessionLauncher, + checkoutSession, + dropInConfiguration, + SessionDropInService::class.java + ) } override fun startDropInAdvancedFlowPayment( @@ -178,15 +169,10 @@ class DropInPlatformApi( } } - private suspend fun createCheckoutSession( - sessionModel: SessionModel, - dropInConfiguration: com.adyen.checkout.dropin.DropInConfiguration, - ): CheckoutSession { - return when (val checkoutSessionResult = - CheckoutSessionProvider.createSession(sessionModel, dropInConfiguration)) { - is CheckoutSessionResult.Success -> checkoutSessionResult.checkoutSession - is CheckoutSessionResult.Error -> throw checkoutSessionResult.exception - } + private fun createCheckoutSession(sessionHolder: SessionHolder): CheckoutSession { + val sessionSetupResponse = SessionSetupResponse.SERIALIZER.deserialize(sessionHolder.sessionSetupResponse) + val order = sessionHolder.orderResponse?.let { Order.SERIALIZER.deserialize(it) } + return CheckoutSession(sessionSetupResponse = sessionSetupResponse, order = order) } // Gift cards will be supported in a later version @@ -217,7 +203,8 @@ class DropInPlatformApi( PaymentResultEnum.ERROR, reason = sessionDropInResult.reason ) - is SessionDropInResult.Finished -> PaymentResultDTO(PaymentResultEnum.FINISHED, + is SessionDropInResult.Finished -> PaymentResultDTO( + PaymentResultEnum.FINISHED, result = with(sessionDropInResult.result) { PaymentResultModelDTO( sessionId, sessionData, sessionResult, resultCode, order?.mapToOrderResponseModel() diff --git a/example/lib/screens/drop_in/drop_in_screen.dart b/example/lib/screens/drop_in/drop_in_screen.dart index d32fe2e9..c8ea18c7 100644 --- a/example/lib/screens/drop_in/drop_in_screen.dart +++ b/example/lib/screens/drop_in/drop_in_screen.dart @@ -51,10 +51,11 @@ class _DropInScreenState extends State { await widget.repository.fetchSession(); final DropInConfiguration dropInConfiguration = await _createDropInConfiguration(); - final Session session = Session( - id: sessionResponse.id, + + final Session session = await widget.adyenCheckout.createSession( + sessionId: sessionResponse.id, sessionData: sessionResponse.sessionData, - paymentMethodsJson: "", + configuration: dropInConfiguration, ); final PaymentResult paymentResult = await widget.adyenCheckout.startPayment( diff --git a/ios/Classes/AdyenCheckoutPlugin.swift b/ios/Classes/AdyenCheckoutPlugin.swift index ed4613a2..facda95e 100644 --- a/ios/Classes/AdyenCheckoutPlugin.swift +++ b/ios/Classes/AdyenCheckoutPlugin.swift @@ -6,12 +6,12 @@ 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 componentFlutterApi = ComponentFlutterInterface(binaryMessenger: messenger) - let checkoutPlatformApi = CheckoutPlatformApi(componentFlutterApi: componentFlutterApi, sessionHolder: sessionHolder) + let checkoutPlatformApi = CheckoutPlatformApi(dropInFlutterApi: dropInFlutterApi, componentFlutterApi: componentFlutterApi, sessionHolder: sessionHolder) CheckoutPlatformInterfaceSetup.setUp(binaryMessenger: messenger, api: checkoutPlatformApi) // DropIn - let dropInFlutterApi = DropInFlutterInterface(binaryMessenger: messenger) let dropInPlatformApi = DropInPlatformApi(dropInFlutterApi: dropInFlutterApi, sessionHolder: sessionHolder) DropInPlatformInterfaceSetup.setUp(binaryMessenger: messenger, api: dropInPlatformApi) diff --git a/ios/Classes/CheckoutPlatformApi.swift b/ios/Classes/CheckoutPlatformApi.swift index c709737a..a79fd007 100644 --- a/ios/Classes/CheckoutPlatformApi.swift +++ b/ios/Classes/CheckoutPlatformApi.swift @@ -9,17 +9,20 @@ import AdyenNetworking class CheckoutPlatformApi: CheckoutPlatformInterface { private let configurationMapper = ConfigurationMapper() + private let dropInFlutterApi: DropInFlutterInterface private let componentFlutterApi: ComponentFlutterInterface private let sessionHolder: SessionHolder init( + dropInFlutterApi : DropInFlutterInterface, componentFlutterApi: ComponentFlutterInterface, sessionHolder: SessionHolder ) { + self.dropInFlutterApi = dropInFlutterApi self.componentFlutterApi = componentFlutterApi self.sessionHolder = sessionHolder } - + func createSession( sessionId: String, sessionData: String, @@ -28,29 +31,10 @@ class CheckoutPlatformApi: CheckoutPlatformInterface { ) { do { switch configuration { + case is DropInConfigurationDTO: + try createSessionForDropIn(configuration as! DropInConfigurationDTO, sessionId, sessionData, completion) case is CardComponentConfigurationDTO: - let adyenContext = try (configuration as! CardComponentConfigurationDTO).createAdyenContext() - let sessionConfiguration = AdyenSession.Configuration(sessionIdentifier: sessionId, - initialSessionData: sessionData, - context: adyenContext, - actionComponent: .init()) - let sessionDelegate = CardSessionFlowDelegate(componentFlutterApi: componentFlutterApi) - let sessionPresentationDelegate = CardPresentationDelegate(topViewController: getViewController()) - AdyenSession.initialize(with: sessionConfiguration, - delegate: sessionDelegate, - presentationDelegate: sessionPresentationDelegate) - { [weak self] result in - switch result { - case let .success(session): - self?.sessionHolder.setup(session: session, sessionPresentationDelegate: sessionPresentationDelegate, sessionDelegate: sessionDelegate) - // TODO: serialize paymentMethods - completion(Result.success(SessionDTO(id: sessionId, - sessionData: sessionData, - paymentMethodsJson: ""))) - case let .failure(error): - completion(Result.failure(error)) - } - } + try createSessionForCardComponent(configuration as! CardComponentConfigurationDTO, sessionId, sessionData, completion) case .none, .some: completion(Result.failure(PlatformError(errorDescription: "Configuration is not valid"))) } @@ -66,6 +50,75 @@ class CheckoutPlatformApi: CheckoutPlatformInterface { func enableConsoleLogging(loggingEnabled: Bool) { AdyenLogging.isEnabled = loggingEnabled } + + private func createSessionForDropIn( + _ configuration: DropInConfigurationDTO, + _ sessionId: String, + _ sessionData: String, + _ completion: @escaping (Result) -> Void + ) throws { + let adyenContext = try configuration.createAdyenContext() + let sessionDelegate = DropInSessionsDelegate(viewController: getViewController(), dropInFlutterApi: dropInFlutterApi) + let sessionPresentationDelegate = DropInSessionsPresentationDelegate() + requestAndSetSession( + adyenContext, + sessionId, + sessionData, + sessionDelegate, + sessionPresentationDelegate, + completion + ) + } + + private func createSessionForCardComponent( + _ configuration: CardComponentConfigurationDTO, + _ sessionId: String, + _ sessionData: String, + _ completion: @escaping (Result) -> Void + ) throws { + let adyenContext = try configuration.createAdyenContext() + let sessionDelegate = CardSessionFlowDelegate(componentFlutterApi: componentFlutterApi) + let sessionPresentationDelegate = CardPresentationDelegate(topViewController: getViewController()) + requestAndSetSession( + adyenContext, + sessionId, + sessionData, + sessionDelegate, + sessionPresentationDelegate, + completion + ) + } + + private func requestAndSetSession( + _ adyenContext: AdyenContext, + _ sessionId: String, + _ sessionData: String, + _ sessionDelegate: AdyenSessionDelegate, + _ sessionPresentationDelegate : PresentationDelegate, + _ completion: @escaping (Result) -> Void + ) { + let sessionConfiguration = AdyenSession.Configuration(sessionIdentifier: sessionId, + initialSessionData: sessionData, + context: adyenContext, + actionComponent: .init()) + AdyenSession.initialize(with: sessionConfiguration, + delegate: sessionDelegate, + presentationDelegate: sessionPresentationDelegate) + { [weak self] result in + switch result { + case let .success(session): + // TODO: For a later version - We need to return the actual session and removing the session holder when the session is codable. + self?.sessionHolder.setup(session: session, sessionPresentationDelegate: sessionPresentationDelegate, sessionDelegate: sessionDelegate) + // TODO: serialize paymentMethods + completion(Result.success(SessionDTO(id: sessionId, + sessionData: sessionData, + paymentMethodsJson: ""))) + case let .failure(error): + completion(Result.failure(error)) + } + } + } + private func getViewController() -> UIViewController? { var rootViewController = UIApplication.shared.adyen.mainKeyWindow?.rootViewController diff --git a/ios/Classes/PlatformApi.swift b/ios/Classes/PlatformApi.swift index fc1b46de..be69bda4 100644 --- a/ios/Classes/PlatformApi.swift +++ b/ios/Classes/PlatformApi.swift @@ -896,8 +896,6 @@ private class DropInPlatformInterfaceCodecReader: FlutterStandardReader { return GooglePayConfigurationDTO.fromList(self.readValue() as! [Any?]) case 137: return PaymentFlowOutcomeDTO.fromList(self.readValue() as! [Any?]) - case 138: - return SessionDTO.fromList(self.readValue() as! [Any?]) default: return super.readValue(ofType: type) } @@ -936,9 +934,6 @@ private class DropInPlatformInterfaceCodecWriter: FlutterStandardWriter { } else if let value = value as? PaymentFlowOutcomeDTO { super.writeByte(137) super.writeValue(value.toList()) - } else if let value = value as? SessionDTO { - super.writeByte(138) - super.writeValue(value.toList()) } else { super.writeValue(value) } @@ -961,7 +956,7 @@ class DropInPlatformInterfaceCodec: FlutterStandardMessageCodec { /// Generated protocol from Pigeon that represents a handler of messages from Flutter. protocol DropInPlatformInterface { - func startDropInSessionPayment(dropInConfigurationDTO: DropInConfigurationDTO, session: SessionDTO) throws + func startDropInSessionPayment(dropInConfigurationDTO: DropInConfigurationDTO) throws func startDropInAdvancedFlowPayment(dropInConfigurationDTO: DropInConfigurationDTO, paymentMethodsResponse: String) throws func onPaymentsResult(paymentsResult: PaymentFlowOutcomeDTO) throws func onPaymentsDetailsResult(paymentsDetailsResult: PaymentFlowOutcomeDTO) throws @@ -980,9 +975,8 @@ class DropInPlatformInterfaceSetup { startDropInSessionPaymentChannel.setMessageHandler { message, reply in let args = message as! [Any?] let dropInConfigurationDTOArg = args[0] as! DropInConfigurationDTO - let sessionArg = args[1] as! SessionDTO do { - try api.startDropInSessionPayment(dropInConfigurationDTO: dropInConfigurationDTOArg, session: sessionArg) + try api.startDropInSessionPayment(dropInConfigurationDTO: dropInConfigurationDTOArg) reply(wrapResult(nil)) } catch { reply(wrapError(error)) diff --git a/ios/Classes/dropIn/DropInPlatformApi.swift b/ios/Classes/dropIn/DropInPlatformApi.swift index c570c38e..b84cd4c7 100644 --- a/ios/Classes/dropIn/DropInPlatformApi.swift +++ b/ios/Classes/dropIn/DropInPlatformApi.swift @@ -8,11 +8,9 @@ class DropInPlatformApi: DropInPlatformInterface { private let sessionHolder: SessionHolder private let configurationMapper = ConfigurationMapper() private var viewController: UIViewController? - private var dropInSessionDelegate: AdyenSessionDelegate? - private var dropInAdvancedFlowDelegate: DropInAdvancedFlowDelegate? private var dropInSessionStoredPaymentMethodsDelegate: DropInSessionsStoredPaymentMethodsDelegate? + private var dropInAdvancedFlowDelegate: DropInAdvancedFlowDelegate? private var dropInAdvancedFlowStoredPaymentMethodsDelegate: DropInAdvancedFlowStoredPaymentMethodsDelegate? - var session: AdyenSession? var dropInComponent: DropInComponent? init( @@ -24,8 +22,7 @@ class DropInPlatformApi: DropInPlatformInterface { } func startDropInSessionPayment( - dropInConfigurationDTO: DropInConfigurationDTO, - session: SessionDTO + dropInConfigurationDTO: DropInConfigurationDTO ) { do { guard let viewController = getViewController() else { @@ -33,42 +30,24 @@ class DropInPlatformApi: DropInPlatformInterface { } self.viewController = viewController - sessionHolder.sessionPresentationDelegate = DropInSessionsPresentationDelegate() - dropInSessionDelegate = DropInSessionsDelegate(viewController: viewController, - dropInFlutterApi: dropInFlutterApi) let adyenContext = try dropInConfigurationDTO.createAdyenContext() - let sessionConfiguration = AdyenSession.Configuration(sessionIdentifier: session.id, - initialSessionData: session.sessionData, - context: adyenContext) - dropInSessionStoredPaymentMethodsDelegate = DropInSessionsStoredPaymentMethodsDelegate(viewController: viewController, - dropInFlutterApi: dropInFlutterApi) - - AdyenSession.initialize(with: sessionConfiguration, - delegate: dropInSessionDelegate!, - presentationDelegate: sessionHolder.sessionPresentationDelegate!) - { [weak self] result in - switch result { - case let .success(session): - do { - self?.session = session - let dropInConfiguration = try self?.configurationMapper.createDropInConfiguration(dropInConfigurationDTO: dropInConfigurationDTO) - let dropInComponent = DropInComponent(paymentMethods: session.sessionContext.paymentMethods, - context: adyenContext, - configuration: dropInConfiguration!) - dropInComponent.delegate = session - dropInComponent.partialPaymentDelegate = session - if dropInConfigurationDTO.isRemoveStoredPaymentMethodEnabled { - dropInComponent.storedPaymentMethodsDelegate = self?.dropInSessionStoredPaymentMethodsDelegate - } - self?.dropInComponent = dropInComponent - self?.viewController?.present(dropInComponent.viewController, animated: true) - } catch { - self?.sendSessionError(error: error) - } - case let .failure(error): - self?.sendSessionError(error: error) - } + dropInSessionStoredPaymentMethodsDelegate = DropInSessionsStoredPaymentMethodsDelegate( + viewController: viewController, + dropInFlutterApi: dropInFlutterApi + ) + let dropInConfiguration = try configurationMapper.createDropInConfiguration(dropInConfigurationDTO: dropInConfigurationDTO) + let dropInComponent = DropInComponent( + paymentMethods: sessionHolder.session!.sessionContext.paymentMethods, + context: adyenContext, + configuration: dropInConfiguration + ) + dropInComponent.delegate = sessionHolder.session + dropInComponent.partialPaymentDelegate = sessionHolder.session + if dropInConfigurationDTO.isRemoveStoredPaymentMethodEnabled { + dropInComponent.storedPaymentMethodsDelegate = self.dropInSessionStoredPaymentMethodsDelegate } + self.dropInComponent = dropInComponent + self.viewController?.present(dropInComponent.viewController, animated: true) } catch { sendSessionError(error: error) } @@ -121,10 +100,7 @@ class DropInPlatformApi: DropInPlatformInterface { } func cleanUpDropIn() { - sessionHolder.sessionPresentationDelegate = nil - sessionHolder.sessionDelegate = nil - sessionHolder.session = nil - dropInSessionDelegate = nil + sessionHolder.reset() dropInSessionStoredPaymentMethodsDelegate = nil dropInAdvancedFlowDelegate?.dropInInteractorDelegate = nil dropInAdvancedFlowDelegate = nil diff --git a/ios/Classes/dropIn/dropInSessions/DropInSessionsDelegate.swift b/ios/Classes/dropIn/dropInSessions/DropInSessionsDelegate.swift index b6edf29e..15c3d34d 100644 --- a/ios/Classes/dropIn/dropInSessions/DropInSessionsDelegate.swift +++ b/ios/Classes/dropIn/dropInSessions/DropInSessionsDelegate.swift @@ -5,7 +5,7 @@ class DropInSessionsDelegate: AdyenSessionDelegate { private let viewController: UIViewController? private let dropInFlutterApi: DropInFlutterInterface - init(viewController: UIViewController, dropInFlutterApi: DropInFlutterInterface) { + init(viewController: UIViewController?, dropInFlutterApi: DropInFlutterInterface) { self.viewController = viewController self.dropInFlutterApi = dropInFlutterApi } diff --git a/lib/src/adyen_checkout.dart b/lib/src/adyen_checkout.dart index ae156d31..9278968c 100644 --- a/lib/src/adyen_checkout.dart +++ b/lib/src/adyen_checkout.dart @@ -52,19 +52,26 @@ class AdyenCheckout implements AdyenCheckoutInterface { final sdkVersionNumber = await _sdkVersionNumberProvider.getSdkVersionNumber(); + SessionDTO sessionDTO = await _adyenCheckoutApi.createSession( + sessionId, + sessionData, + _mapConfiguration(configuration, sdkVersionNumber), + ); + return Session( + id: sessionDTO.id, + sessionData: sessionDTO.sessionData, + paymentMethodsJson: sessionDTO.paymentMethodsJson, + ); + } + + dynamic _mapConfiguration( + BaseConfiguration configuration, + String sdkVersionNumber, + ) { if (configuration is CardComponentConfiguration) { - SessionDTO sessionDTO = await _adyenCheckoutApi.createSession( - sessionId, - sessionData, - configuration.toDTO(sdkVersionNumber), - ); - return Session( - id: sessionDTO.id, - sessionData: sessionDTO.sessionData, - paymentMethodsJson: sessionDTO.paymentMethodsJson, - ); - } else { - throw Exception("Configuration is not valid"); + return configuration.toDTO(sdkVersionNumber); + } else if (configuration is DropInConfiguration) { + return configuration.toDTO(sdkVersionNumber); } } } diff --git a/lib/src/drop_in/drop_in.dart b/lib/src/drop_in/drop_in.dart index e950f7b3..5fe62bba 100644 --- a/lib/src/drop_in/drop_in.dart +++ b/lib/src/drop_in/drop_in.dart @@ -48,7 +48,6 @@ class DropIn { dropInPlatformApi.startDropInSessionPayment( dropInSession.dropInConfiguration.toDTO(sdkVersionNumber), - dropInSession.session.toDTO(), ); dropInFlutterApi.dropInSessionPlatformCommunicationStream = diff --git a/lib/src/drop_in/drop_in_platform_api.dart b/lib/src/drop_in/drop_in_platform_api.dart index 62b93a3c..02ff8ff9 100644 --- a/lib/src/drop_in/drop_in_platform_api.dart +++ b/lib/src/drop_in/drop_in_platform_api.dart @@ -7,11 +7,9 @@ class DropInPlatformApi implements DropInPlatformInterface { @override Future startDropInSessionPayment( DropInConfigurationDTO dropInConfigurationDTO, - SessionDTO session, ) => _dropInPlatformInterface.startDropInSessionPayment( dropInConfigurationDTO, - session, ); @override diff --git a/lib/src/generated/platform_api.g.dart b/lib/src/generated/platform_api.g.dart index edea867d..a0422459 100644 --- a/lib/src/generated/platform_api.g.dart +++ b/lib/src/generated/platform_api.g.dart @@ -998,9 +998,6 @@ class _DropInPlatformInterfaceCodec extends StandardMessageCodec { } else if (value is PaymentFlowOutcomeDTO) { buffer.putUint8(137); writeValue(buffer, value.encode()); - } else if (value is SessionDTO) { - buffer.putUint8(138); - writeValue(buffer, value.encode()); } else { super.writeValue(buffer, value); } @@ -1029,8 +1026,6 @@ class _DropInPlatformInterfaceCodec extends StandardMessageCodec { return GooglePayConfigurationDTO.decode(readValue(buffer)!); case 137: return PaymentFlowOutcomeDTO.decode(readValue(buffer)!); - case 138: - return SessionDTO.decode(readValue(buffer)!); default: return super.readValueOfType(type, buffer); } @@ -1047,7 +1042,7 @@ class DropInPlatformInterface { static const MessageCodec pigeonChannelCodec = _DropInPlatformInterfaceCodec(); - Future startDropInSessionPayment(DropInConfigurationDTO dropInConfigurationDTO, SessionDTO session) async { + Future startDropInSessionPayment(DropInConfigurationDTO dropInConfigurationDTO) async { const String __pigeon_channelName = 'dev.flutter.pigeon.adyen_checkout.DropInPlatformInterface.startDropInSessionPayment'; final BasicMessageChannel __pigeon_channel = BasicMessageChannel( __pigeon_channelName, @@ -1055,7 +1050,7 @@ class DropInPlatformInterface { binaryMessenger: __pigeon_binaryMessenger, ); final List? __pigeon_replyList = - await __pigeon_channel.send([dropInConfigurationDTO, session]) as List?; + await __pigeon_channel.send([dropInConfigurationDTO]) as List?; if (__pigeon_replyList == null) { throw _createConnectionError(__pigeon_channelName); } else if (__pigeon_replyList.length > 1) { diff --git a/pigeons/platform_api.dart b/pigeons/platform_api.dart index 9076c75d..235382e6 100644 --- a/pigeons/platform_api.dart +++ b/pigeons/platform_api.dart @@ -354,7 +354,6 @@ abstract class CheckoutPlatformInterface { abstract class DropInPlatformInterface { void startDropInSessionPayment( DropInConfigurationDTO dropInConfigurationDTO, - SessionDTO session, ); void startDropInAdvancedFlowPayment(