-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/adjust configuration #35
Commits on Sep 18, 2023
-
Added configuration class for the different payment flows
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 bd858f6..000294f 100644 --- a/android/src/main/kotlin/com/adyen/adyen_checkout/CheckoutPlatformApi.kt +++ b/android/src/main/kotlin/com/adyen/adyen_checkout/CheckoutPlatformApi.kt @@ -2,7 +2,7 @@ package com.adyen.adyen_checkout import CheckoutFlutterApi import CheckoutPlatformInterface -import DropInConfiguration +import Configuration import DropInResult import DropInResultType import PlatformCommunicationModel @@ -49,7 +49,7 @@ class CheckoutPlatformApi(private val checkoutFlutterApi: CheckoutFlutterApi?) : } override fun startDropInSessionPayment( - dropInConfiguration: DropInConfiguration, + dropInConfiguration: Configuration, session: Session, ) { checkForFlutterFragmentActivity() @@ -70,7 +70,7 @@ class CheckoutPlatformApi(private val checkoutFlutterApi: CheckoutFlutterApi?) : } override fun startDropInAdvancedFlowPayment( - dropInConfiguration: DropInConfiguration, + dropInConfiguration: Configuration, paymentMethodsResponse: String, ) { checkForFlutterFragmentActivity() 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 2957598..9de91a5 100644 --- a/android/src/main/kotlin/com/adyen/adyen_checkout/PlatformApi.kt +++ b/android/src/main/kotlin/com/adyen/adyen_checkout/PlatformApi.kt @@ -138,12 +138,12 @@ data class Amount ( } /** Generated class from Pigeon that represents data sent in messages. */ -data class DropInConfiguration ( +data class Configuration ( val environment: Environment, val clientKey: String, val amount: Amount, val countryCode: String, - val isAnalyticsEnabled: Boolean? = null, + val analytics: AnalyticsOptions? = null, val showPreselectedStoredPaymentMethod: Boolean? = null, val skipListWhenSinglePaymentMethod: Boolean? = null, val isRemovingStoredPaymentMethodsEnabled: Boolean? = null, @@ -152,17 +152,19 @@ data class DropInConfiguration ( ) { companion object { @Suppress("UNCHECKED_CAST") - fun fromList(list: List<Any?>): DropInConfiguration { + fun fromList(list: List<Any?>): Configuration { val environment = Environment.ofRaw(list[0] as Int)!! val clientKey = list[1] as String val amount = Amount.fromList(list[2] as List<Any?>) val countryCode = list[3] as String - val isAnalyticsEnabled = list[4] as Boolean? + val analytics: AnalyticsOptions? = (list[4] as List<Any?>?)?.let { + AnalyticsOptions.fromList(it) + } val showPreselectedStoredPaymentMethod = list[5] as Boolean? val skipListWhenSinglePaymentMethod = list[6] as Boolean? val isRemovingStoredPaymentMethodsEnabled = list[7] as Boolean? val additionalDataForDropInService = list[8] as String? - return DropInConfiguration(environment, clientKey, amount, countryCode, isAnalyticsEnabled, showPreselectedStoredPaymentMethod, skipListWhenSinglePaymentMethod, isRemovingStoredPaymentMethodsEnabled, additionalDataForDropInService) + return Configuration(environment, clientKey, amount, countryCode, analytics, showPreselectedStoredPaymentMethod, skipListWhenSinglePaymentMethod, isRemovingStoredPaymentMethodsEnabled, additionalDataForDropInService) } } fun toList(): List<Any?> { @@ -171,7 +173,7 @@ data class DropInConfiguration ( clientKey, amount.toList(), countryCode, - isAnalyticsEnabled, + analytics?.toList(), showPreselectedStoredPaymentMethod, skipListWhenSinglePaymentMethod, isRemovingStoredPaymentMethodsEnabled, @@ -180,6 +182,28 @@ data class DropInConfiguration ( } } +/** Generated class from Pigeon that represents data sent in messages. */ +data class AnalyticsOptions ( + val enabled: Boolean? = null, + val payload: String? = null + +) { + companion object { + @Suppress("UNCHECKED_CAST") + fun fromList(list: List<Any?>): AnalyticsOptions { + val enabled = list[0] as Boolean? + val payload = list[1] as String? + return AnalyticsOptions(enabled, payload) + } + } + fun toList(): List<Any?> { + return listOf<Any?>( + enabled, + payload, + ) + } +} + /** Generated class from Pigeon that represents data sent in messages. */ data class PaymentResult ( val type: PaymentResultEnum, @@ -362,20 +386,25 @@ private object CheckoutPlatformInterfaceCodec : StandardMessageCodec() { } 129.toByte() -> { return (readValue(buffer) as? List<Any?>)?.let { - DropInConfiguration.fromList(it) + AnalyticsOptions.fromList(it) } } 130.toByte() -> { return (readValue(buffer) as? List<Any?>)?.let { - DropInError.fromList(it) + Configuration.fromList(it) } } 131.toByte() -> { return (readValue(buffer) as? List<Any?>)?.let { - DropInResult.fromList(it) + DropInError.fromList(it) } } 132.toByte() -> { + return (readValue(buffer) as? List<Any?>)?.let { + DropInResult.fromList(it) + } + } + 133.toByte() -> { return (readValue(buffer) as? List<Any?>)?.let { Session.fromList(it) } @@ -389,22 +418,26 @@ private object CheckoutPlatformInterfaceCodec : StandardMessageCodec() { stream.write(128) writeValue(stream, value.toList()) } - is DropInConfiguration -> { + is AnalyticsOptions -> { stream.write(129) writeValue(stream, value.toList()) } - is DropInError -> { + is Configuration -> { stream.write(130) writeValue(stream, value.toList()) } - is DropInResult -> { + is DropInError -> { stream.write(131) writeValue(stream, value.toList()) } - is Session -> { + is DropInResult -> { stream.write(132) writeValue(stream, value.toList()) } + is Session -> { + stream.write(133) + writeValue(stream, value.toList()) + } else -> super.writeValue(stream, value) } } @@ -414,8 +447,8 @@ private object CheckoutPlatformInterfaceCodec : StandardMessageCodec() { interface CheckoutPlatformInterface { fun getPlatformVersion(callback: (Result<String>) -> Unit) fun getReturnUrl(callback: (Result<String>) -> Unit) - fun startDropInSessionPayment(dropInConfiguration: DropInConfiguration, session: Session) - fun startDropInAdvancedFlowPayment(dropInConfiguration: DropInConfiguration, paymentMethodsResponse: String) + fun startDropInSessionPayment(dropInConfiguration: Configuration, session: Session) + fun startDropInAdvancedFlowPayment(dropInConfiguration: Configuration, paymentMethodsResponse: String) fun onPaymentsResult(paymentsResult: DropInResult) fun onPaymentsDetailsResult(paymentsDetailsResult: DropInResult) @@ -468,7 +501,7 @@ interface CheckoutPlatformInterface { if (api != null) { channel.setMessageHandler { message, reply -> val args = message as List<Any?> - val dropInConfigurationArg = args[0] as DropInConfiguration + val dropInConfigurationArg = args[0] as Configuration val sessionArg = args[1] as Session var wrapped: List<Any?> try { @@ -488,7 +521,7 @@ interface CheckoutPlatformInterface { if (api != null) { channel.setMessageHandler { message, reply -> val args = message as List<Any?> - val dropInConfigurationArg = args[0] as DropInConfiguration + val dropInConfigurationArg = args[0] as Configuration val paymentMethodsResponseArg = args[1] as String var wrapped: List<Any?> try { diff --git a/android/src/main/kotlin/com/adyen/adyen_checkout/utils/Mapper.kt b/android/src/main/kotlin/com/adyen/adyen_checkout/utils/Mapper.kt index 8e347a5..f6cfa5a 100644 --- a/android/src/main/kotlin/com/adyen/adyen_checkout/utils/Mapper.kt +++ b/android/src/main/kotlin/com/adyen/adyen_checkout/utils/Mapper.kt @@ -1,7 +1,7 @@ package com.adyen.adyen_checkout.utils import Amount -import DropInConfiguration +import Configuration import Environment import OrderResponseModel import Session @@ -15,7 +15,7 @@ object Mapper { return com.adyen.checkout.sessions.core.SessionModel(this.id, this.sessionData) } - fun DropInConfiguration.mapToDropInConfiguration(context: Context): com.adyen.checkout.dropin.DropInConfiguration { + fun Configuration.mapToDropInConfiguration(context: Context): com.adyen.checkout.dropin.DropInConfiguration { val amount = this.amount.mapToAmount() return com.adyen.checkout.dropin.DropInConfiguration.Builder( context, diff --git a/example/lib/config.dart b/example/lib/config.dart index 7450b70..97628c3 100644 --- a/example/lib/config.dart +++ b/example/lib/config.dart @@ -1,4 +1,5 @@ -import 'package:adyen_checkout/platform_api.g.dart'; + +import 'package:adyen_checkout/adyen_checkout.dart'; class Config { /* diff --git a/example/lib/main.dart b/example/lib/main.dart index f50458d..b61b38c 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -1,7 +1,6 @@ import 'dart:async'; import 'package:adyen_checkout/adyen_checkout.dart'; -import 'package:adyen_checkout/platform_api.g.dart'; import 'package:adyen_checkout_example/config.dart'; import 'package:adyen_checkout_example/network/service.dart'; import 'package:adyen_checkout_example/repositories/adyen_sessions_repository.dart'; diff --git a/example/lib/network/service.dart b/example/lib/network/service.dart index 430dc35..9dcee71 100644 --- a/example/lib/network/service.dart +++ b/example/lib/network/service.dart @@ -1,6 +1,6 @@ import 'dart:convert'; -import 'package:adyen_checkout/platform_api.g.dart'; +import 'package:adyen_checkout/adyen_checkout.dart'; import 'package:adyen_checkout_example/config.dart'; import 'package:adyen_checkout_example/network/models/payment_methods_request_network_model.dart'; import 'package:adyen_checkout_example/network/models/session_request_network_model.dart'; diff --git a/example/lib/repositories/adyen_sessions_repository.dart b/example/lib/repositories/adyen_sessions_repository.dart index 84c2c4c..ebf5644 100644 --- a/example/lib/repositories/adyen_sessions_repository.dart +++ b/example/lib/repositories/adyen_sessions_repository.dart @@ -2,7 +2,6 @@ import 'dart:convert'; import 'dart:io'; import 'package:adyen_checkout/adyen_checkout.dart'; -import 'package:adyen_checkout/platform_api.g.dart'; import 'package:adyen_checkout_example/config.dart'; import 'package:adyen_checkout_example/network/models/amount_network_model.dart'; import 'package:adyen_checkout_example/network/models/payment_methods_request_network_model.dart'; diff --git a/example/lib/repositories/drop_in_outcome_handler.dart b/example/lib/repositories/drop_in_outcome_handler.dart index b803df6..b04fccd 100644 --- a/example/lib/repositories/drop_in_outcome_handler.dart +++ b/example/lib/repositories/drop_in_outcome_handler.dart @@ -1,5 +1,4 @@ import 'package:adyen_checkout/adyen_checkout.dart'; -import 'package:adyen_checkout/platform_api.g.dart'; class DropInOutcomeHandler { //DropIn results diff --git a/ios/Classes/CheckoutPlatformApi.swift b/ios/Classes/CheckoutPlatformApi.swift index 5922e52..db95029 100644 --- a/ios/Classes/CheckoutPlatformApi.swift +++ b/ios/Classes/CheckoutPlatformApi.swift @@ -28,7 +28,7 @@ class CheckoutPlatformApi : CheckoutPlatformInterface { completion(Result.success(systemVersion)) } - func startDropInSessionPayment(dropInConfiguration: DropInConfiguration, session: Session) { + func startDropInSessionPayment(dropInConfiguration: Configuration, session: Session) { do { guard let viewController = getViewController() else { return @@ -64,7 +64,7 @@ class CheckoutPlatformApi : CheckoutPlatformInterface { } } - func startDropInAdvancedFlowPayment(dropInConfiguration: DropInConfiguration, paymentMethodsResponse: String) { + func startDropInAdvancedFlowPayment(dropInConfiguration: Configuration, paymentMethodsResponse: String) { do { guard let viewController = getViewController() else { return @@ -117,7 +117,7 @@ class CheckoutPlatformApi : CheckoutPlatformInterface { return rootViewController } - private func createAdyenContext(dropInConfiguration: DropInConfiguration) throws -> AdyenContext { + private func createAdyenContext(dropInConfiguration: Configuration) throws -> AdyenContext { let environment = mapToEnvironment(environment: dropInConfiguration.environment) let apiContext = try APIContext(environment: environment, clientKey: dropInConfiguration.clientKey) let value = Int(dropInConfiguration.amount.value) diff --git a/ios/Classes/PlatformApi.swift b/ios/Classes/PlatformApi.swift index 0cace8a..a7ddfe1 100644 --- a/ios/Classes/PlatformApi.swift +++ b/ios/Classes/PlatformApi.swift @@ -110,34 +110,37 @@ struct Amount { } /// Generated class from Pigeon that represents data sent in messages. -struct DropInConfiguration { +struct Configuration { var environment: Environment var clientKey: String var amount: Amount var countryCode: String - var isAnalyticsEnabled: Bool? = nil + var analytics: AnalyticsOptions? = nil var showPreselectedStoredPaymentMethod: Bool? = nil var skipListWhenSinglePaymentMethod: Bool? = nil var isRemovingStoredPaymentMethodsEnabled: Bool? = nil var additionalDataForDropInService: String? = nil - static func fromList(_ list: [Any?]) -> DropInConfiguration? { + static func fromList(_ list: [Any?]) -> Configuration? { let environment = Environment(rawValue: list[0] as! Int)! let clientKey = list[1] as! String let amount = Amount.fromList(list[2] as! [Any?])! let countryCode = list[3] as! String - let isAnalyticsEnabled: Bool? = nilOrValue(list[4]) + var analytics: AnalyticsOptions? = nil + if let analyticsList: [Any?] = nilOrValue(list[4]) { + analytics = AnalyticsOptions.fromList(analyticsList) + } let showPreselectedStoredPaymentMethod: Bool? = nilOrValue(list[5]) let skipListWhenSinglePaymentMethod: Bool? = nilOrValue(list[6]) let isRemovingStoredPaymentMethodsEnabled: Bool? = nilOrValue(list[7]) let additionalDataForDropInService: String? = nilOrValue(list[8]) - return DropInConfiguration( + return Configuration( environment: environment, clientKey: clientKey, amount: amount, countryCode: countryCode, - isAnalyticsEnabled: isAnalyticsEnabled, + analytics: analytics, showPreselectedStoredPaymentMethod: showPreselectedStoredPaymentMethod, skipListWhenSinglePaymentMethod: skipListWhenSinglePaymentMethod, isRemovingStoredPaymentMethodsEnabled: isRemovingStoredPaymentMethodsEnabled, @@ -150,7 +153,7 @@ struct DropInConfiguration { clientKey, amount.toList(), countryCode, - isAnalyticsEnabled, + analytics?.toList(), showPreselectedStoredPaymentMethod, skipListWhenSinglePaymentMethod, isRemovingStoredPaymentMethodsEnabled, @@ -159,6 +162,28 @@ struct DropInConfiguration { } } +/// Generated class from Pigeon that represents data sent in messages. +struct AnalyticsOptions { + var enabled: Bool? = nil + var payload: String? = nil + + static func fromList(_ list: [Any?]) -> AnalyticsOptions? { + let enabled: Bool? = nilOrValue(list[0]) + let payload: String? = nilOrValue(list[1]) + + return AnalyticsOptions( + enabled: enabled, + payload: payload + ) + } + func toList() -> [Any?] { + return [ + enabled, + payload, + ] + } +} + /// Generated class from Pigeon that represents data sent in messages. struct PaymentResult { var type: PaymentResultEnum @@ -351,12 +376,14 @@ private class CheckoutPlatformInterfaceCodecReader: FlutterStandardReader { case 128: return Amount.fromList(self.readValue() as! [Any?]) case 129: - return DropInConfiguration.fromList(self.readValue() as! [Any?]) + return AnalyticsOptions.fromList(self.readValue() as! [Any?]) case 130: - return DropInError.fromList(self.readValue() as! [Any?]) + return Configuration.fromList(self.readValue() as! [Any?]) case 131: - return DropInResult.fromList(self.readValue() as! [Any?]) + return DropInError.fromList(self.readValue() as! [Any?]) case 132: + return DropInResult.fromList(self.readValue() as! [Any?]) + case 133: return Session.fromList(self.readValue() as! [Any?]) default: return super.readValue(ofType: type) @@ -369,18 +396,21 @@ private class CheckoutPlatformInterfaceCodecWriter: FlutterStandardWriter { if let value = value as? Amount { super.writeByte(128) super.writeValue(value.toList()) - } else if let value = value as? DropInConfiguration { + } else if let value = value as? AnalyticsOptions { super.writeByte(129) super.writeValue(value.toList()) - } else if let value = value as? DropInError { + } else if let value = value as? Configuration { super.writeByte(130) super.writeValue(value.toList()) - } else if let value = value as? DropInResult { + } else if let value = value as? DropInError { super.writeByte(131) super.writeValue(value.toList()) - } else if let value = value as? Session { + } else if let value = value as? DropInResult { super.writeByte(132) super.writeValue(value.toList()) + } else if let value = value as? Session { + super.writeByte(133) + super.writeValue(value.toList()) } else { super.writeValue(value) } @@ -405,8 +435,8 @@ class CheckoutPlatformInterfaceCodec: FlutterStandardMessageCodec { protocol CheckoutPlatformInterface { func getPlatformVersion(completion: @escaping (Result<String, Error>) -> Void) func getReturnUrl(completion: @escaping (Result<String, Error>) -> Void) - func startDropInSessionPayment(dropInConfiguration: DropInConfiguration, session: Session) throws - func startDropInAdvancedFlowPayment(dropInConfiguration: DropInConfiguration, paymentMethodsResponse: String) throws + func startDropInSessionPayment(dropInConfiguration: Configuration, session: Session) throws + func startDropInAdvancedFlowPayment(dropInConfiguration: Configuration, paymentMethodsResponse: String) throws func onPaymentsResult(paymentsResult: DropInResult) throws func onPaymentsDetailsResult(paymentsDetailsResult: DropInResult) throws } @@ -451,7 +481,7 @@ class CheckoutPlatformInterfaceSetup { if let api = api { startDropInSessionPaymentChannel.setMessageHandler { message, reply in let args = message as! [Any?] - let dropInConfigurationArg = args[0] as! DropInConfiguration + let dropInConfigurationArg = args[0] as! Configuration let sessionArg = args[1] as! Session do { try api.startDropInSessionPayment(dropInConfiguration: dropInConfigurationArg, session: sessionArg) @@ -467,7 +497,7 @@ class CheckoutPlatformInterfaceSetup { if let api = api { startDropInAdvancedFlowPaymentChannel.setMessageHandler { message, reply in let args = message as! [Any?] - let dropInConfigurationArg = args[0] as! DropInConfiguration + let dropInConfigurationArg = args[0] as! Configuration let paymentMethodsResponseArg = args[1] as! String do { try api.startDropInAdvancedFlowPayment(dropInConfiguration: dropInConfigurationArg, paymentMethodsResponse: paymentMethodsResponseArg) diff --git a/lib/adyen_checkout.dart b/lib/adyen_checkout.dart index f193b68..9eb7f89 100644 --- a/lib/adyen_checkout.dart +++ b/lib/adyen_checkout.dart @@ -1,3 +1,12 @@ export 'src/adyen_checkout.dart'; +export 'src/generated/platform_api.g.dart' + show + PaymentResult, + Amount, + Environment, + Session, + OrderResponseModel, + AnalyticsOptions; +export 'src/models/adyen_configuration.dart'; export 'src/models/drop_in_outcome.dart'; export 'src/models/payment_flow.dart'; diff --git a/lib/src/adyen_checkout.dart b/lib/src/adyen_checkout.dart index 52d098b..c9bfbea 100644 --- a/lib/src/adyen_checkout.dart +++ b/lib/src/adyen_checkout.dart @@ -1,9 +1,8 @@ import 'dart:async'; -import 'package:adyen_checkout/platform_api.g.dart'; +import 'package:adyen_checkout/adyen_checkout.dart'; import 'package:adyen_checkout/src/adyen_checkout_interface.dart'; -import 'package:adyen_checkout/src/models/drop_in_outcome.dart'; -import 'package:adyen_checkout/src/models/payment_flow.dart'; +import 'package:adyen_checkout/src/generated/platform_api.g.dart'; import 'package:adyen_checkout/src/platform/adyen_checkout_platform_interface.dart'; import 'package:adyen_checkout/src/platform/adyen_checkout_result_api.dart'; @@ -35,9 +34,15 @@ class AdyenCheckout implements AdyenCheckoutInterface { Future<PaymentResult> _startDropInSessionsPayment( DropInSession dropInSession) async { _resultApi.dropInSessionResultStream = StreamController<PaymentResult>(); + Configuration dropInConfiguration = Configuration( + environment: dropInSession.dropInConfiguration.environment, + clientKey: dropInSession.dropInConfiguration.clientKey, + amount: dropInSession.dropInConfiguration.amount, + countryCode: dropInSession.dropInConfiguration.countryCode, + ); AdyenCheckoutPlatformInterface.instance.startDropInSessionPayment( dropInSession.session, - dropInSession.dropInConfiguration, + dropInConfiguration, ); final sessionDropInResultModel = await _resultApi.dropInSessionResultStream.stream.first; @@ -48,9 +53,15 @@ class AdyenCheckout implements AdyenCheckoutInterface { Future<PaymentResult> _startDropInAdvancedFlowPayment( DropInAdvancedFlow dropInAdvancedFlow) async { final dropInAdvancedFlowCompleter = Completer<PaymentResult>(); + Configuration dropInConfiguration = Configuration( + environment: dropInAdvancedFlow.dropInConfiguration.environment, + clientKey: dropInAdvancedFlow.dropInConfiguration.clientKey, + amount: dropInAdvancedFlow.dropInConfiguration.amount, + countryCode: dropInAdvancedFlow.dropInConfiguration.countryCode, + ); AdyenCheckoutPlatformInterface.instance.startDropInAdvancedFlowPayment( dropInAdvancedFlow.paymentMethodsResponse, - dropInAdvancedFlow.dropInConfiguration, + dropInConfiguration, ); _resultApi.dropInAdvancedFlowPlatformCommunicationStream = diff --git a/lib/src/adyen_checkout_interface.dart b/lib/src/adyen_checkout_interface.dart index f231b9c..e5a570e 100644 --- a/lib/src/adyen_checkout_interface.dart +++ b/lib/src/adyen_checkout_interface.dart @@ -1,5 +1,4 @@ import 'package:adyen_checkout/adyen_checkout.dart'; -import 'package:adyen_checkout/platform_api.g.dart'; abstract class AdyenCheckoutInterface { Future<String> getPlatformVersion(); diff --git a/lib/platform_api.g.dart b/lib/src/generated/platform_api.g.dart similarity index 93% rename from lib/platform_api.g.dart rename to lib/src/generated/platform_api.g.dart index 5512b87..73f99c4 100644 --- a/lib/platform_api.g.dart +++ b/lib/src/generated/platform_api.g.dart @@ -87,13 +87,13 @@ class Amount { } } -class DropInConfiguration { - DropInConfiguration({ +class Configuration { + Configuration({ required this.environment, required this.clientKey, required this.amount, required this.countryCode, - this.isAnalyticsEnabled, + this.analytics, this.showPreselectedStoredPaymentMethod, this.skipListWhenSinglePaymentMethod, this.isRemovingStoredPaymentMethodsEnabled, @@ -108,7 +108,7 @@ class DropInConfiguration { String countryCode; - bool? isAnalyticsEnabled; + AnalyticsOptions? analytics; bool? showPreselectedStoredPaymentMethod; @@ -124,7 +124,7 @@ class DropInConfiguration { clientKey, amount.encode(), countryCode, - isAnalyticsEnabled, + analytics?.encode(), showPreselectedStoredPaymentMethod, skipListWhenSinglePaymentMethod, isRemovingStoredPaymentMethodsEnabled, @@ -132,14 +132,16 @@ class DropInConfiguration { ]; } - static DropInConfiguration decode(Object result) { + static Configuration decode(Object result) { result as List<Object?>; - return DropInConfiguration( + return Configuration( environment: Environment.values[result[0]! as int], clientKey: result[1]! as String, amount: Amount.decode(result[2]! as List<Object?>), countryCode: result[3]! as String, - isAnalyticsEnabled: result[4] as bool?, + analytics: result[4] != null + ? AnalyticsOptions.decode(result[4]! as List<Object?>) + : null, showPreselectedStoredPaymentMethod: result[5] as bool?, skipListWhenSinglePaymentMethod: result[6] as bool?, isRemovingStoredPaymentMethodsEnabled: result[7] as bool?, @@ -148,6 +150,32 @@ class DropInConfiguration { } } +class AnalyticsOptions { + AnalyticsOptions({ + this.enabled, + this.payload, + }); + + bool? enabled; + + String? payload; + + Object encode() { + return <Object?>[ + enabled, + payload, + ]; + } + + static AnalyticsOptions decode(Object result) { + result as List<Object?>; + return AnalyticsOptions( + enabled: result[0] as bool?, + payload: result[1] as String?, + ); + } +} + class PaymentResult { PaymentResult({ required this.type, @@ -368,18 +396,21 @@ class _CheckoutPlatformInterfaceCodec extends StandardMessageCodec { if (value is Amount) { buffer.putUint8(128); writeValue(buffer, value.encode()); - } else if (value is DropInConfiguration) { + } else if (value is AnalyticsOptions) { buffer.putUint8(129); writeValue(buffer, value.encode()); - } else if (value is DropInError) { + } else if (value is Configuration) { buffer.putUint8(130); writeValue(buffer, value.encode()); - } else if (value is DropInResult) { + } else if (value is DropInError) { buffer.putUint8(131); writeValue(buffer, value.encode()); - } else if (value is Session) { + } else if (value is DropInResult) { buffer.putUint8(132); writeValue(buffer, value.encode()); + } else if (value is Session) { + buffer.putUint8(133); + writeValue(buffer, value.encode()); } else { super.writeValue(buffer, value); } @@ -391,12 +422,14 @@ class _CheckoutPlatformInterfaceCodec extends StandardMessageCodec { case 128: return Amount.decode(readValue(buffer)!); case 129: - return DropInConfiguration.decode(readValue(buffer)!); + return AnalyticsOptions.decode(readValue(buffer)!); case 130: - return DropInError.decode(readValue(buffer)!); + return Configuration.decode(readValue(buffer)!); case 131: - return DropInResult.decode(readValue(buffer)!); + return DropInError.decode(readValue(buffer)!); case 132: + return DropInResult.decode(readValue(buffer)!); + case 133: return Session.decode(readValue(buffer)!); default: return super.readValueOfType(type, buffer); @@ -468,7 +501,7 @@ class CheckoutPlatformInterface { } } - Future<void> startDropInSessionPayment(DropInConfiguration arg_dropInConfiguration, Session arg_session) async { + Future<void> startDropInSessionPayment(Configuration arg_dropInConfiguration, Session arg_session) async { final BasicMessageChannel<Object?> channel = BasicMessageChannel<Object?>( 'dev.flutter.pigeon.adyen_checkout.CheckoutPlatformInterface.startDropInSessionPayment', codec, binaryMessenger: _binaryMessenger); @@ -490,7 +523,7 @@ class CheckoutPlatformInterface { } } - Future<void> startDropInAdvancedFlowPayment(DropInConfiguration arg_dropInConfiguration, String arg_paymentMethodsResponse) async { + Future<void> startDropInAdvancedFlowPayment(Configuration arg_dropInConfiguration, String arg_paymentMethodsResponse) async { final BasicMessageChannel<Object?> channel = BasicMessageChannel<Object?>( 'dev.flutter.pigeon.adyen_checkout.CheckoutPlatformInterface.startDropInAdvancedFlowPayment', codec, binaryMessenger: _binaryMessenger); diff --git a/lib/src/models/adyen_configuration.dart b/lib/src/models/adyen_configuration.dart new file mode 100644 index 0000000..ca88fe2 --- /dev/null +++ b/lib/src/models/adyen_configuration.dart @@ -0,0 +1,129 @@ +import 'package:adyen_checkout/src/generated/platform_api.g.dart'; + +sealed class AdyenConfiguration { + final Environment environment; + final String clientKey; + final Amount amount; + final String countryCode; + final AnalyticsOptions? analytics; + + AdyenConfiguration({ + required this.environment, + required this.clientKey, + required this.amount, + required this.countryCode, + required this.analytics, + }); +} + +class DropInConfiguration extends AdyenConfiguration { + final bool showPreselectedStoredPaymentMethod; + final bool skipListWhenSinglePaymentMethod; + + DropInConfiguration({ + required super.environment, + required super.clientKey, + required super.amount, + required super.countryCode, + super.analytics, + this.showPreselectedStoredPaymentMethod = false, + this.skipListWhenSinglePaymentMethod = false, + }); +} + +class CardsConfiguration extends AdyenConfiguration { + final bool holderNameRequired; + final AddressMode addressVisibility; + final bool showStorePaymentField; + final bool hideCvcStoredCard; + final bool hideCvc; + final bool kcpVisible; + final bool socialSecurityVisible; + final List<String> supportedCardTypes; + + CardsConfiguration({ + required super.environment, + required super.clientKey, + required super.amount, + required super.countryCode, + super.analytics, + this.holderNameRequired = false, + this.addressVisibility = AddressMode.none, + this.showStorePaymentField = false, + this.hideCvcStoredCard = false, + this.hideCvc = false, + this.kcpVisible = false, + this.socialSecurityVisible = false, + this.supportedCardTypes = const [], + }); +} + +enum AddressMode { + full, + postalCode, + none, +} + +class ApplePayConfiguration extends AdyenConfiguration { + final String merchantId; + final String merchantName; + final bool allowOnboarding; + + ApplePayConfiguration({ + required super.environment, + required super.clientKey, + required super.amount, + required super.countryCode, + required super.analytics, + required this.merchantId, + required this.merchantName, + this.allowOnboarding = false, + }); +} + +class GooglePayConfiguration extends AdyenConfiguration { + final String merchantAccount; + final List<String> allowedCardNetworks; + final List<CardAuthMethod> allowedAuthMethods; + final TotalPriceStatus totalPriceStatus; + final bool allowPrepaidCards; + final bool billingAddressRequired; + final bool emailRequired; + final bool shippingAddressRequired; + final bool existingPaymentMethodRequired; + final GooglePayEnvironment googlePayEnvironment; + + GooglePayConfiguration({ + required super.environment, + required super.clientKey, + required super.amount, + required super.countryCode, + required super.analytics, + required this.totalPriceStatus, + required this.googlePayEnvironment, + this.merchantAccount = "", + this.allowedCardNetworks = const [], + this.allowedAuthMethods = const [], + this.allowPrepaidCards = true, + this.billingAddressRequired = false, + this.emailRequired = false, + this.shippingAddressRequired = false, + this.existingPaymentMethodRequired = false, + }); +} + +enum CardAuthMethod { + panOnly, + cryptogram3DS, +} + +enum TotalPriceStatus { + notCurrentlyKnown, + estimated, + finalPrice, +} + +enum GooglePayEnvironment { + test, + production, +} diff --git a/lib/src/models/payment_flow.dart b/lib/src/models/payment_flow.dart index df1dacb..b48dcc8 100644 --- a/lib/src/models/payment_flow.dart +++ b/lib/src/models/payment_flow.dart @@ -1,4 +1,5 @@ -import 'package:adyen_checkout/platform_api.g.dart'; +import 'package:adyen_checkout/src/generated/platform_api.g.dart'; +import 'package:adyen_checkout/src/models/adyen_configuration.dart'; import 'package:adyen_checkout/src/models/drop_in_outcome.dart'; sealed class PaymentFlow {} diff --git a/lib/src/platform/adyen_checkout_api.dart b/lib/src/platform/adyen_checkout_api.dart index a282882..f06e960 100644 --- a/lib/src/platform/adyen_checkout_api.dart +++ b/lib/src/platform/adyen_checkout_api.dart @@ -1,4 +1,4 @@ -import 'package:adyen_checkout/platform_api.g.dart'; +import 'package:adyen_checkout/src/generated/platform_api.g.dart'; import 'package:adyen_checkout/src/platform/adyen_checkout_platform_interface.dart'; class AdyenCheckoutApi implements AdyenCheckoutPlatformInterface { @@ -10,7 +10,7 @@ class AdyenCheckoutApi implements AdyenCheckoutPlatformInterface { @OverRide void startDropInSessionPayment( Session session, - DropInConfiguration dropInConfiguration, + Configuration dropInConfiguration, ) => checkoutApi.startDropInSessionPayment( dropInConfiguration, @@ -20,7 +20,7 @@ class AdyenCheckoutApi implements AdyenCheckoutPlatformInterface { @OverRide void startDropInAdvancedFlowPayment( String paymentMethodsResponse, - DropInConfiguration dropInConfiguration, + Configuration dropInConfiguration, ) => checkoutApi.startDropInAdvancedFlowPayment( dropInConfiguration, diff --git a/lib/src/platform/adyen_checkout_platform_interface.dart b/lib/src/platform/adyen_checkout_platform_interface.dart index ad0db9f..ca03c14 100644 --- a/lib/src/platform/adyen_checkout_platform_interface.dart +++ b/lib/src/platform/adyen_checkout_platform_interface.dart @@ -1,4 +1,4 @@ -import 'package:adyen_checkout/platform_api.g.dart'; +import 'package:adyen_checkout/src/generated/platform_api.g.dart'; import 'package:adyen_checkout/src/platform/adyen_checkout_api.dart'; import 'package:plugin_platform_interface/plugin_platform_interface.dart'; @@ -21,12 +21,12 @@ abstract class AdyenCheckoutPlatformInterface extends PlatformInterface { void startDropInSessionPayment( Session session, - DropInConfiguration dropInConfiguration, + Configuration dropInConfiguration, ); void startDropInAdvancedFlowPayment( String paymentMethodsResponse, - DropInConfiguration dropInConfiguration, + Configuration dropInConfiguration, ); void onPaymentsResult(DropInResult paymentsResult); diff --git a/lib/src/platform/adyen_checkout_result_api.dart b/lib/src/platform/adyen_checkout_result_api.dart index eb6b8ad..c9e168a 100644 --- a/lib/src/platform/adyen_checkout_result_api.dart +++ b/lib/src/platform/adyen_checkout_result_api.dart @@ -1,6 +1,7 @@ import 'dart:async'; -import 'package:adyen_checkout/platform_api.g.dart'; +import 'package:adyen_checkout/src/generated/platform_api.g.dart'; + class AdyenCheckoutResultApi implements CheckoutFlutterApi { var dropInSessionResultStream = StreamController<PaymentResult>(); diff --git a/pigeons/platform_api.dart b/pigeons/platform_api.dart index a2fb8fa..236bf28 100644 --- a/pigeons/platform_api.dart +++ b/pigeons/platform_api.dart @@ -2,7 +2,7 @@ import 'package:pigeon/pigeon.dart'; //dart run pigeon --input pigeons/platform_api.dart @ConfigurePigeon(PigeonOptions( - dartOut: 'lib/platform_api.g.dart', + dartOut: 'lib/src/generated/platform_api.g.dart', dartOptions: DartOptions(), kotlinOut: 'android/src/main/kotlin/com/adyen/adyen_checkout/PlatformApi.kt', kotlinOptions: KotlinOptions(), @@ -39,22 +39,34 @@ class Amount { }); } -class DropInConfiguration { +//Use sealed classes when they are supported by pigeon +class Configuration { final Environment environment; final String clientKey; final Amount amount; final String countryCode; - bool? isAnalyticsEnabled; + final AnalyticsOptions? analytics; bool? showPreselectedStoredPaymentMethod; bool? skipListWhenSinglePaymentMethod; bool? isRemovingStoredPaymentMethodsEnabled; String? additionalDataForDropInService; - DropInConfiguration({ + Configuration({ required this.environment, required this.clientKey, required this.amount, required this.countryCode, + this.analytics, + }); +} + +class AnalyticsOptions { + final bool? enabled; + final String? payload; + + AnalyticsOptions({ + this.enabled, + this.payload, }); } @@ -164,12 +176,12 @@ abstract class CheckoutPlatformInterface { String getReturnUrl(); void startDropInSessionPayment( - DropInConfiguration dropInConfiguration, + Configuration dropInConfiguration, Session session, ); void startDropInAdvancedFlowPayment( - DropInConfiguration dropInConfiguration, + Configuration dropInConfiguration, String paymentMethodsResponse, ); diff --git a/test/adyen_checkout_test.dart b/test/adyen_checkout_test.dart index 826f8a7..4f6261b 100644 --- a/test/adyen_checkout_test.dart +++ b/test/adyen_checkout_test.dart @@ -1,5 +1,5 @@ -import 'package:adyen_checkout/platform_api.g.dart'; import 'package:adyen_checkout/src/adyen_checkout.dart'; +import 'package:adyen_checkout/src/generated/platform_api.g.dart'; import 'package:adyen_checkout/src/platform/adyen_checkout_platform_interface.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:plugin_platform_interface/plugin_platform_interface.dart'; @@ -13,7 +13,7 @@ class MockAdyenCheckoutPlatform @OverRide Future<void> startDropInSessionPayment( Session sessionModel, - DropInConfiguration dropInConfiguration, + Configuration dropInConfiguration, ) => Future.value(null); @@ -25,7 +25,7 @@ class MockAdyenCheckoutPlatform @OverRide Future<String> startDropInAdvancedFlowPayment( String paymentMethodsResponse, - DropInConfiguration dropInConfiguration, + Configuration dropInConfiguration, ) => Future.value("Result");
Configuration menu - View commit details
-
Copy full SHA for 227013b - Browse repository at this point
Copy the full SHA 227013bView commit details -
Configuration menu - View commit details
-
Copy full SHA for 854a1c5 - Browse repository at this point
Copy the full SHA 854a1c5View commit details -
Added usage of DropInConfigurationDTO for iOS
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 000294f..1d746d6 100644 --- a/android/src/main/kotlin/com/adyen/adyen_checkout/CheckoutPlatformApi.kt +++ b/android/src/main/kotlin/com/adyen/adyen_checkout/CheckoutPlatformApi.kt @@ -2,7 +2,7 @@ package com.adyen.adyen_checkout import CheckoutFlutterApi import CheckoutPlatformInterface -import Configuration +import DropInConfigurationDTO import DropInResult import DropInResultType import PlatformCommunicationModel @@ -49,7 +49,7 @@ class CheckoutPlatformApi(private val checkoutFlutterApi: CheckoutFlutterApi?) : } override fun startDropInSessionPayment( - dropInConfiguration: Configuration, + dropInConfiguration: DropInConfigurationDTO, session: Session, ) { checkForFlutterFragmentActivity() @@ -70,7 +70,7 @@ class CheckoutPlatformApi(private val checkoutFlutterApi: CheckoutFlutterApi?) : } override fun startDropInAdvancedFlowPayment( - dropInConfiguration: Configuration, + dropInConfiguration: DropInConfigurationDTO, paymentMethodsResponse: String, ) { checkForFlutterFragmentActivity() 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 9de91a5..8fd536d 100644 --- a/android/src/main/kotlin/com/adyen/adyen_checkout/PlatformApi.kt +++ b/android/src/main/kotlin/com/adyen/adyen_checkout/PlatformApi.kt @@ -57,6 +57,18 @@ enum class Environment(val raw: Int) { } } +enum class AddressMode(val raw: Int) { + FULL(0), + POSTALCODE(1), + NONE(2); + + companion object { + fun ofRaw(raw: Int): AddressMode? { + return values().firstOrNull { it.raw == raw } + } + } +} + enum class PaymentResultEnum(val raw: Int) { CANCELLEDBYUSER(0), ERROR(1), @@ -138,46 +150,85 @@ data class Amount ( } /** Generated class from Pigeon that represents data sent in messages. */ -data class Configuration ( +data class DropInConfigurationDTO ( val environment: Environment, val clientKey: String, - val amount: Amount, val countryCode: String, - val analytics: AnalyticsOptions? = null, + val amount: Amount, + val analyticsOptions: AnalyticsOptions? = null, val showPreselectedStoredPaymentMethod: Boolean? = null, val skipListWhenSinglePaymentMethod: Boolean? = null, - val isRemovingStoredPaymentMethodsEnabled: Boolean? = null, - val additionalDataForDropInService: String? = null + val cardsConfiguration: CardsConfigurationDTO? = null ) { companion object { @Suppress("UNCHECKED_CAST") - fun fromList(list: List<Any?>): Configuration { + fun fromList(list: List<Any?>): DropInConfigurationDTO { val environment = Environment.ofRaw(list[0] as Int)!! val clientKey = list[1] as String - val amount = Amount.fromList(list[2] as List<Any?>) - val countryCode = list[3] as String - val analytics: AnalyticsOptions? = (list[4] as List<Any?>?)?.let { + val countryCode = list[2] as String + val amount = Amount.fromList(list[3] as List<Any?>) + val analyticsOptions: AnalyticsOptions? = (list[4] as List<Any?>?)?.let { AnalyticsOptions.fromList(it) } val showPreselectedStoredPaymentMethod = list[5] as Boolean? val skipListWhenSinglePaymentMethod = list[6] as Boolean? - val isRemovingStoredPaymentMethodsEnabled = list[7] as Boolean? - val additionalDataForDropInService = list[8] as String? - return Configuration(environment, clientKey, amount, countryCode, analytics, showPreselectedStoredPaymentMethod, skipListWhenSinglePaymentMethod, isRemovingStoredPaymentMethodsEnabled, additionalDataForDropInService) + val cardsConfiguration: CardsConfigurationDTO? = (list[7] as List<Any?>?)?.let { + CardsConfigurationDTO.fromList(it) + } + return DropInConfigurationDTO(environment, clientKey, countryCode, amount, analyticsOptions, showPreselectedStoredPaymentMethod, skipListWhenSinglePaymentMethod, cardsConfiguration) } } fun toList(): List<Any?> { return listOf<Any?>( environment.raw, clientKey, - amount.toList(), countryCode, - analytics?.toList(), + amount.toList(), + analyticsOptions?.toList(), showPreselectedStoredPaymentMethod, skipListWhenSinglePaymentMethod, - isRemovingStoredPaymentMethodsEnabled, - additionalDataForDropInService, + cardsConfiguration?.toList(), + ) + } +} + +/** Generated class from Pigeon that represents data sent in messages. */ +data class CardsConfigurationDTO ( + val holderNameRequired: Boolean, + val addressMode: AddressMode, + val showStorePaymentField: Boolean, + val hideCvcStoredCard: Boolean, + val hideCvc: Boolean, + val kcpVisible: Boolean, + val socialSecurityVisible: Boolean, + val supportedCardTypes: List<String?> + +) { + companion object { + @Suppress("UNCHECKED_CAST") + fun fromList(list: List<Any?>): CardsConfigurationDTO { + val holderNameRequired = list[0] as Boolean + val addressMode = AddressMode.ofRaw(list[1] as Int)!! + val showStorePaymentField = list[2] as Boolean + val hideCvcStoredCard = list[3] as Boolean + val hideCvc = list[4] as Boolean + val kcpVisible = list[5] as Boolean + val socialSecurityVisible = list[6] as Boolean + val supportedCardTypes = list[7] as List<String?> + return CardsConfigurationDTO(holderNameRequired, addressMode, showStorePaymentField, hideCvcStoredCard, hideCvc, kcpVisible, socialSecurityVisible, supportedCardTypes) + } + } + fun toList(): List<Any?> { + return listOf<Any?>( + holderNameRequired, + addressMode.raw, + showStorePaymentField, + hideCvcStoredCard, + hideCvc, + kcpVisible, + socialSecurityVisible, + supportedCardTypes, ) } } @@ -391,20 +442,25 @@ private object CheckoutPlatformInterfaceCodec : StandardMessageCodec() { } 130.toByte() -> { return (readValue(buffer) as? List<Any?>)?.let { - Configuration.fromList(it) + CardsConfigurationDTO.fromList(it) } } 131.toByte() -> { return (readValue(buffer) as? List<Any?>)?.let { - DropInError.fromList(it) + DropInConfigurationDTO.fromList(it) } } 132.toByte() -> { return (readValue(buffer) as? List<Any?>)?.let { - DropInResult.fromList(it) + DropInError.fromList(it) } } 133.toByte() -> { + return (readValue(buffer) as? List<Any?>)?.let { + DropInResult.fromList(it) + } + } + 134.toByte() -> { return (readValue(buffer) as? List<Any?>)?.let { Session.fromList(it) } @@ -422,22 +478,26 @@ private object CheckoutPlatformInterfaceCodec : StandardMessageCodec() { stream.write(129) writeValue(stream, value.toList()) } - is Configuration -> { + is CardsConfigurationDTO -> { stream.write(130) writeValue(stream, value.toList()) } - is DropInError -> { + is DropInConfigurationDTO -> { stream.write(131) writeValue(stream, value.toList()) } - is DropInResult -> { + is DropInError -> { stream.write(132) writeValue(stream, value.toList()) } - is Session -> { + is DropInResult -> { stream.write(133) writeValue(stream, value.toList()) } + is Session -> { + stream.write(134) + writeValue(stream, value.toList()) + } else -> super.writeValue(stream, value) } } @@ -447,8 +507,8 @@ private object CheckoutPlatformInterfaceCodec : StandardMessageCodec() { interface CheckoutPlatformInterface { fun getPlatformVersion(callback: (Result<String>) -> Unit) fun getReturnUrl(callback: (Result<String>) -> Unit) - fun startDropInSessionPayment(dropInConfiguration: Configuration, session: Session) - fun startDropInAdvancedFlowPayment(dropInConfiguration: Configuration, paymentMethodsResponse: String) + fun startDropInSessionPayment(dropInConfiguration: DropInConfigurationDTO, session: Session) + fun startDropInAdvancedFlowPayment(dropInConfiguration: DropInConfigurationDTO, paymentMethodsResponse: String) fun onPaymentsResult(paymentsResult: DropInResult) fun onPaymentsDetailsResult(paymentsDetailsResult: DropInResult) @@ -501,7 +561,7 @@ interface CheckoutPlatformInterface { if (api != null) { channel.setMessageHandler { message, reply -> val args = message as List<Any?> - val dropInConfigurationArg = args[0] as Configuration + val dropInConfigurationArg = args[0] as DropInConfigurationDTO val sessionArg = args[1] as Session var wrapped: List<Any?> try { @@ -521,7 +581,7 @@ interface CheckoutPlatformInterface { if (api != null) { channel.setMessageHandler { message, reply -> val args = message as List<Any?> - val dropInConfigurationArg = args[0] as Configuration + val dropInConfigurationArg = args[0] as DropInConfigurationDTO val paymentMethodsResponseArg = args[1] as String var wrapped: List<Any?> try { diff --git a/android/src/main/kotlin/com/adyen/adyen_checkout/utils/Mapper.kt b/android/src/main/kotlin/com/adyen/adyen_checkout/utils/Mapper.kt index f6cfa5a..ec0c484 100644 --- a/android/src/main/kotlin/com/adyen/adyen_checkout/utils/Mapper.kt +++ b/android/src/main/kotlin/com/adyen/adyen_checkout/utils/Mapper.kt @@ -1,11 +1,17 @@ package com.adyen.adyen_checkout.utils +import AddressMode import Amount -import Configuration +import DropInConfigurationDTO import Environment import OrderResponseModel import Session import android.content.Context +import com.adyen.checkout.card.AddressConfiguration +import com.adyen.checkout.card.CardConfiguration +import com.adyen.checkout.card.CardType +import com.adyen.checkout.card.KCPAuthVisibility +import com.adyen.checkout.card.SocialSecurityNumberVisibility import com.adyen.checkout.components.core.OrderResponse import com.adyen.checkout.core.Environment as SDKEnvironment @@ -15,13 +21,67 @@ object Mapper { return com.adyen.checkout.sessions.core.SessionModel(this.id, this.sessionData) } - fun Configuration.mapToDropInConfiguration(context: Context): com.adyen.checkout.dropin.DropInConfiguration { + fun DropInConfigurationDTO.mapToDropInConfiguration(context: Context): com.adyen.checkout.dropin.DropInConfiguration { + val environment = this.environment.mapToEnvironment() + val cardConfiguration = CardConfiguration.Builder( + context = context, + environment = environment, + clientKey = this.clientKey + ) + .setShowStorePaymentField(cardsConfiguration?.showStorePaymentField ?: false) + .setAddressConfiguration(cardsConfiguration?.addressMode?.mapToAddressConfiguration() + ?: AddressConfiguration.None) + .setShowStorePaymentField(cardsConfiguration?.showStorePaymentField ?: false) + .setHideCvcStoredCard(cardsConfiguration?.hideCvcStoredCard ?: false) + .setHideCvc(cardsConfiguration?.hideCvc ?: false) + .setKcpAuthVisibility(determineKcpAuthVisibility(cardsConfiguration?.kcpVisible)) + .setSocialSecurityNumberVisibility(determineSocialSecurityNumberVisibility(cardsConfiguration?.socialSecurityVisible)) + .setSupportedCardTypes(*mapToSupportedCardTypes(cardsConfiguration?.supportedCardTypes)) + .setHolderNameRequired(cardsConfiguration?.holderNameRequired ?: false) + .build() val amount = this.amount.mapToAmount() return com.adyen.checkout.dropin.DropInConfiguration.Builder( context, this.environment.mapToEnvironment(), clientKey, ).setAmount(amount).build() + context, + this.environment.mapToEnvironment(), + clientKey + ).setAmount(amount).addCardConfiguration(cardConfiguration).build(); + } + + private fun AddressMode.mapToAddressConfiguration(): AddressConfiguration { + return when (this) { + AddressMode.FULL -> AddressConfiguration.FullAddress() + AddressMode.POSTALCODE -> AddressConfiguration.PostalCode() + AddressMode.NONE -> AddressConfiguration.None + } + } + + private fun determineKcpAuthVisibility(visible: Boolean?): KCPAuthVisibility { + return when (visible) { + true -> KCPAuthVisibility.SHOW + else -> KCPAuthVisibility.HIDE + } + } + + private fun determineSocialSecurityNumberVisibility(visible: Boolean?): SocialSecurityNumberVisibility { + return when (visible) { + true -> SocialSecurityNumberVisibility.SHOW + else -> SocialSecurityNumberVisibility.HIDE + } + } + + private fun mapToSupportedCardTypes(cardTypes: List<String?>?): Array<CardType> { + if (cardTypes == null) { + return emptyArray() + } + + val mappedCardTypes = cardTypes.map { cardBrandName -> + cardBrandName?.let { CardType.getByBrandName(it.lowercase()) } + } + return mappedCardTypes.filterNotNull().toTypedArray() ?: emptyArray() } private fun Environment.mapToEnvironment(): com.adyen.checkout.core.Environment { @@ -45,10 +105,10 @@ object Mapper { fun OrderResponse.mapToOrderResponseModel(): OrderResponseModel { return OrderResponseModel( - pspReference = pspReference, - orderData = orderData, - amount = amount?.mapTopAmount(), - remainingAmount = remainingAmount?.mapTopAmount(), + pspReference = pspReference, + orderData = orderData, + amount = amount?.mapTopAmount(), + remainingAmount = remainingAmount?.mapTopAmount(), ) } } diff --git a/example/lib/main.dart b/example/lib/main.dart index f252a38..67a037e 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -109,7 +109,7 @@ class _MyAppState extends State<MyApp> { await _adyenSessionRepository.fetchPaymentMethods(); final CardsConfiguration cardsConfiguration = CardsConfiguration( - holderNameRequired: true + holderNameRequired: true, ); final DropInConfiguration dropInConfiguration = DropInConfiguration( diff --git a/ios/Classes/CheckoutPlatformApi.swift b/ios/Classes/CheckoutPlatformApi.swift index 4540dfc..5302352 100644 --- a/ios/Classes/CheckoutPlatformApi.swift +++ b/ios/Classes/CheckoutPlatformApi.swift @@ -47,7 +47,7 @@ class CheckoutPlatformApi : CheckoutPlatformInterface { switch result { case let .success(session): self?.session = session - let dropInConfiguration = self?.createDropInConfiguration() + let dropInConfiguration = self?.createDropInConfiguration(dropInConfiguration: dropInConfiguration) let dropInComponent = DropInComponent(paymentMethods: session.sessionContext.paymentMethods, context: adyenContext, configuration: dropInConfiguration!) @@ -74,7 +74,7 @@ class CheckoutPlatformApi : CheckoutPlatformInterface { let adyenContext = try createAdyenContext(dropInConfiguration: dropInConfiguration) let paymentMethods = try jsonDecoder.decode(PaymentMethods.self, from:Data(paymentMethodsResponse.utf8)) let paymentMethodsWithoutGiftCards = removeGiftCardPaymentMethods(paymentMethods: paymentMethods) - let configuration = createDropInConfiguration() + let configuration = createDropInConfiguration(dropInConfiguration: dropInConfiguration) let dropInComponent = DropInComponent(paymentMethods: paymentMethodsWithoutGiftCards, context: adyenContext, configuration: configuration) @@ -145,10 +145,74 @@ class CheckoutPlatformApi : CheckoutPlatformInterface { } } - private func createDropInConfiguration() -> DropInComponent.Configuration { - return DropInComponent.Configuration() + private func createDropInConfiguration(dropInConfiguration: DropInConfigurationDTO) -> DropInComponent.Configuration { + let koreanAuthenticationMode = determineFieldVisibility(visible: dropInConfiguration.cardsConfiguration?.kcpVisible) + let socialSecurityNumberMode = determineFieldVisibility(visible: dropInConfiguration.cardsConfiguration?.socialSecurityVisible) + let storedCardConfiguration = createStoredCardConfiguration(hideCvcStoredCard: dropInConfiguration.cardsConfiguration?.hideCvcStoredCard) + let allowedCardTypes = determineAllowedCardTypes(cardTypes: dropInConfiguration.cardsConfiguration?.supportedCardTypes) + let billingAddressConfiguration = determineBillingAddressConfiguration(addressMode: dropInConfiguration.cardsConfiguration?.addressMode) + let cardConfiguration = DropInComponent.Card.init( + showsHolderNameField: dropInConfiguration.cardsConfiguration?.holderNameRequired ?? false, + showsStorePaymentMethodField: dropInConfiguration.cardsConfiguration?.showStorePaymentField ?? true, + showsSecurityCodeField: dropInConfiguration.cardsConfiguration?.hideCvc == false, + koreanAuthenticationMode: koreanAuthenticationMode, + socialSecurityNumberMode: socialSecurityNumberMode, + storedCardConfiguration: storedCardConfiguration, + allowedCardTypes: allowedCardTypes, + billingAddress: billingAddressConfiguration + ) + + let dropInConfiguration = DropInComponent.Configuration(allowsSkippingPaymentList: dropInConfiguration.skipListWhenSinglePaymentMethod ?? false, + allowPreselectedPaymentView: dropInConfiguration.showPreselectedStoredPaymentMethod ?? false) + dropInConfiguration.card = cardConfiguration + + return dropInConfiguration + } + + private func determineFieldVisibility(visible: Bool?) -> CardComponent.FieldVisibility { + if (visible == true) { + return .show + } else { + return .hide + } + } + + private func createStoredCardConfiguration(hideCvcStoredCard: Bool?) -> StoredCardConfiguration { + var storedCardConfiguration = StoredCardConfiguration() + storedCardConfiguration.showsSecurityCodeField = hideCvcStoredCard ?? true + return storedCardConfiguration; + } + + private func determineAllowedCardTypes(cardTypes: [String?]?) -> [CardType]? { + guard let mappedCardTypes = cardTypes else { + return nil + } + + if mappedCardTypes.isEmpty { + return nil + } + + return mappedCardTypes.compactMap{$0}.map { CardType(rawValue: $0.lowercased()) } } + private func determineBillingAddressConfiguration(addressMode: AddressMode?) -> BillingAddressConfiguration { + var billingAddressConfiguration = BillingAddressConfiguration.init() + switch addressMode { + case .full: + billingAddressConfiguration.mode = CardComponent.AddressFormType.full + case .postalCode: + billingAddressConfiguration.mode = CardComponent.AddressFormType.postalCode + case .none?: + billingAddressConfiguration.mode = CardComponent.AddressFormType.none + default: + billingAddressConfiguration.mode = CardComponent.AddressFormType.none + } + + return billingAddressConfiguration + } + + + private func handleDropInResult(dropInResult: DropInResult) { do { switch dropInResult.dropInResultType { diff --git a/lib/adyen_checkout.dart b/lib/adyen_checkout.dart index 3037b2a..9e688e7 100644 --- a/lib/adyen_checkout.dart +++ b/lib/adyen_checkout.dart @@ -7,7 +7,6 @@ export 'src/generated/platform_api.g.dart' Session, OrderResponseModel, AnalyticsOptions, - CardsConfiguration, AddressMode; export 'src/models/adyen_configuration.dart'; export 'src/models/drop_in_outcome.dart';
Configuration menu - View commit details
-
Copy full SHA for 21d940e - Browse repository at this point
Copy the full SHA 21d940eView commit details -
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 1d746d6..3e93754 100644 --- a/android/src/main/kotlin/com/adyen/adyen_checkout/CheckoutPlatformApi.kt +++ b/android/src/main/kotlin/com/adyen/adyen_checkout/CheckoutPlatformApi.kt @@ -34,7 +34,7 @@ import org.json.JSONObject @Suppress("NAME_SHADOWING") class CheckoutPlatformApi(private val checkoutFlutterApi: CheckoutFlutterApi?) : - CheckoutPlatformInterface { + CheckoutPlatformInterface { lateinit var activity: FragmentActivity lateinit var dropInSessionLauncher: ActivityResultLauncher<SessionDropInResultContractParams> @@ -48,18 +48,18 @@ class CheckoutPlatformApi(private val checkoutFlutterApi: CheckoutFlutterApi?) : callback(Result.success(RedirectComponent.getReturnUrl(activity.applicationContext))) } - override fun startDropInSessionPayment( - dropInConfiguration: DropInConfigurationDTO, + override fun startDropInSessionPayment( + dropInConfigurationDTO: DropInConfigurationDTO, session: Session, - ) { - checkForFlutterFragmentActivity() - activity.lifecycleScope.launch(Dispatchers.IO) { - val sessionModel = session.mapToSession() - val dropInConfiguration = - dropInConfiguration.mapToDropInConfiguration(activity.applicationContext) - val checkoutSession = createCheckoutSession(sessionModel, dropInConfiguration) - withContext(Dispatchers.Main) { - DropIn.startPayment( + ) { + checkForFlutterFragmentActivity() + 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, @@ -69,31 +69,31 @@ class CheckoutPlatformApi(private val checkoutFlutterApi: CheckoutFlutterApi?) : } } - override fun startDropInAdvancedFlowPayment( - dropInConfiguration: DropInConfigurationDTO, + override fun startDropInAdvancedFlowPayment( + dropInConfigurationDTO: DropInConfigurationDTO, paymentMethodsResponse: String, - ) { - checkForFlutterFragmentActivity() - setAdvancedFlowDropInServiceObserver() - activity.lifecycleScope.launch(Dispatchers.IO) { - val paymentMethodsApiResponse = PaymentMethodsApiResponse.SERIALIZER.deserialize( + ) { + checkForFlutterFragmentActivity() + setAdvancedFlowDropInServiceObserver() + activity.lifecycleScope.launch(Dispatchers.IO) { + val paymentMethodsApiResponse = PaymentMethodsApiResponse.SERIALIZER.deserialize( JSONObject(paymentMethodsResponse), - ) - val paymentMethodsWithoutGiftCards = + ) + val paymentMethodsWithoutGiftCards = removeGiftCardPaymentMethods(paymentMethodsApiResponse) - val dropInConfiguration = - dropInConfiguration.mapToDropInConfiguration(activity.applicationContext) - withContext(Dispatchers.Main) { - DropIn.startPayment( + val dropInConfiguration = + dropInConfigurationDTO.mapToDropInConfiguration(activity.applicationContext) + withContext(Dispatchers.Main) { + DropIn.startPayment( activity.applicationContext, dropInAdvancedFlowLauncher, paymentMethodsWithoutGiftCards, dropInConfiguration, AdvancedFlowDropInService::class.java, - ) - } + ) } } + } override fun onPaymentsResult(paymentsResult: DropInResult) { if (paymentsResult.dropInResultType == DropInResultType.ACTION) { 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 8fd536d..ee56861 100644 --- a/android/src/main/kotlin/com/adyen/adyen_checkout/PlatformApi.kt +++ b/android/src/main/kotlin/com/adyen/adyen_checkout/PlatformApi.kt @@ -155,10 +155,11 @@ data class DropInConfigurationDTO ( val clientKey: String, val countryCode: String, val amount: Amount, - val analyticsOptions: AnalyticsOptions? = null, + val analyticsOptionsDTO: AnalyticsOptionsDTO? = null, val showPreselectedStoredPaymentMethod: Boolean? = null, val skipListWhenSinglePaymentMethod: Boolean? = null, - val cardsConfiguration: CardsConfigurationDTO? = null + val cardsConfigurationDTO: CardsConfigurationDTO? = null, + val applePayConfigurationDTO: ApplePayConfigurationDTO? = null ) { companion object { @@ -168,15 +169,18 @@ data class DropInConfigurationDTO ( val clientKey = list[1] as String val countryCode = list[2] as String val amount = Amount.fromList(list[3] as List<Any?>) - val analyticsOptions: AnalyticsOptions? = (list[4] as List<Any?>?)?.let { - AnalyticsOptions.fromList(it) + val analyticsOptionsDTO: AnalyticsOptionsDTO? = (list[4] as List<Any?>?)?.let { + AnalyticsOptionsDTO.fromList(it) } val showPreselectedStoredPaymentMethod = list[5] as Boolean? val skipListWhenSinglePaymentMethod = list[6] as Boolean? - val cardsConfiguration: CardsConfigurationDTO? = (list[7] as List<Any?>?)?.let { + val cardsConfigurationDTO: CardsConfigurationDTO? = (list[7] as List<Any?>?)?.let { CardsConfigurationDTO.fromList(it) } - return DropInConfigurationDTO(environment, clientKey, countryCode, amount, analyticsOptions, showPreselectedStoredPaymentMethod, skipListWhenSinglePaymentMethod, cardsConfiguration) + val applePayConfigurationDTO: ApplePayConfigurationDTO? = (list[8] as List<Any?>?)?.let { + ApplePayConfigurationDTO.fromList(it) + } + return DropInConfigurationDTO(environment, clientKey, countryCode, amount, analyticsOptionsDTO, showPreselectedStoredPaymentMethod, skipListWhenSinglePaymentMethod, cardsConfigurationDTO, applePayConfigurationDTO) } } fun toList(): List<Any?> { @@ -185,10 +189,11 @@ data class DropInConfigurationDTO ( clientKey, countryCode, amount.toList(), - analyticsOptions?.toList(), + analyticsOptionsDTO?.toList(), showPreselectedStoredPaymentMethod, skipListWhenSinglePaymentMethod, - cardsConfiguration?.toList(), + cardsConfigurationDTO?.toList(), + applePayConfigurationDTO?.toList(), ) } } @@ -234,17 +239,17 @@ data class CardsConfigurationDTO ( } /** Generated class from Pigeon that represents data sent in messages. */ -data class AnalyticsOptions ( +data class AnalyticsOptionsDTO ( val enabled: Boolean? = null, val payload: String? = null ) { companion object { @Suppress("UNCHECKED_CAST") - fun fromList(list: List<Any?>): AnalyticsOptions { + fun fromList(list: List<Any?>): AnalyticsOptionsDTO { val enabled = list[0] as Boolean? val payload = list[1] as String? - return AnalyticsOptions(enabled, payload) + return AnalyticsOptionsDTO(enabled, payload) } } fun toList(): List<Any?> { @@ -255,6 +260,31 @@ data class AnalyticsOptions ( } } +/** Generated class from Pigeon that represents data sent in messages. */ +data class ApplePayConfigurationDTO ( + val merchantId: String, + val merchantName: String, + val allowOnboarding: Boolean + +) { + companion object { + @Suppress("UNCHECKED_CAST") + fun fromList(list: List<Any?>): ApplePayConfigurationDTO { + val merchantId = list[0] as String + val merchantName = list[1] as String + val allowOnboarding = list[2] as Boolean + return ApplePayConfigurationDTO(merchantId, merchantName, allowOnboarding) + } + } + fun toList(): List<Any?> { + return listOf<Any?>( + merchantId, + merchantName, + allowOnboarding, + ) + } +} + /** Generated class from Pigeon that represents data sent in messages. */ data class PaymentResult ( val type: PaymentResultEnum, @@ -437,30 +467,35 @@ private object CheckoutPlatformInterfaceCodec : StandardMessageCodec() { } 129.toByte() -> { return (readValue(buffer) as? List<Any?>)?.let { - AnalyticsOptions.fromList(it) + AnalyticsOptionsDTO.fromList(it) } } 130.toByte() -> { return (readValue(buffer) as? List<Any?>)?.let { - CardsConfigurationDTO.fromList(it) + ApplePayConfigurationDTO.fromList(it) } } 131.toByte() -> { return (readValue(buffer) as? List<Any?>)?.let { - DropInConfigurationDTO.fromList(it) + CardsConfigurationDTO.fromList(it) } } 132.toByte() -> { return (readValue(buffer) as? List<Any?>)?.let { - DropInError.fromList(it) + DropInConfigurationDTO.fromList(it) } } 133.toByte() -> { return (readValue(buffer) as? List<Any?>)?.let { - DropInResult.fromList(it) + DropInError.fromList(it) } } 134.toByte() -> { + return (readValue(buffer) as? List<Any?>)?.let { + DropInResult.fromList(it) + } + } + 135.toByte() -> { return (readValue(buffer) as? List<Any?>)?.let { Session.fromList(it) } @@ -474,30 +509,34 @@ private object CheckoutPlatformInterfaceCodec : StandardMessageCodec() { stream.write(128) writeValue(stream, value.toList()) } - is AnalyticsOptions -> { + is AnalyticsOptionsDTO -> { stream.write(129) writeValue(stream, value.toList()) } - is CardsConfigurationDTO -> { + is ApplePayConfigurationDTO -> { stream.write(130) writeValue(stream, value.toList()) } - is DropInConfigurationDTO -> { + is CardsConfigurationDTO -> { stream.write(131) writeValue(stream, value.toList()) } - is DropInError -> { + is DropInConfigurationDTO -> { stream.write(132) writeValue(stream, value.toList()) } - is DropInResult -> { + is DropInError -> { stream.write(133) writeValue(stream, value.toList()) } - is Session -> { + is DropInResult -> { stream.write(134) writeValue(stream, value.toList()) } + is Session -> { + stream.write(135) + writeValue(stream, value.toList()) + } else -> super.writeValue(stream, value) } } @@ -507,8 +546,8 @@ private object CheckoutPlatformInterfaceCodec : StandardMessageCodec() { interface CheckoutPlatformInterface { fun getPlatformVersion(callback: (Result<String>) -> Unit) fun getReturnUrl(callback: (Result<String>) -> Unit) - fun startDropInSessionPayment(dropInConfiguration: DropInConfigurationDTO, session: Session) - fun startDropInAdvancedFlowPayment(dropInConfiguration: DropInConfigurationDTO, paymentMethodsResponse: String) + fun startDropInSessionPayment(dropInConfigurationDTO: DropInConfigurationDTO, session: Session) + fun startDropInAdvancedFlowPayment(dropInConfigurationDTO: DropInConfigurationDTO, paymentMethodsResponse: String) fun onPaymentsResult(paymentsResult: DropInResult) fun onPaymentsDetailsResult(paymentsDetailsResult: DropInResult) @@ -561,11 +600,11 @@ interface CheckoutPlatformInterface { if (api != null) { channel.setMessageHandler { message, reply -> val args = message as List<Any?> - val dropInConfigurationArg = args[0] as DropInConfigurationDTO + val dropInConfigurationDTOArg = args[0] as DropInConfigurationDTO val sessionArg = args[1] as Session var wrapped: List<Any?> try { - api.startDropInSessionPayment(dropInConfigurationArg, sessionArg) + api.startDropInSessionPayment(dropInConfigurationDTOArg, sessionArg) wrapped = listOf<Any?>(null) } catch (exception: Throwable) { wrapped = wrapError(exception) @@ -581,11 +620,11 @@ interface CheckoutPlatformInterface { if (api != null) { channel.setMessageHandler { message, reply -> val args = message as List<Any?> - val dropInConfigurationArg = args[0] as DropInConfigurationDTO + val dropInConfigurationDTOArg = args[0] as DropInConfigurationDTO val paymentMethodsResponseArg = args[1] as String var wrapped: List<Any?> try { - api.startDropInAdvancedFlowPayment(dropInConfigurationArg, paymentMethodsResponseArg) + api.startDropInAdvancedFlowPayment(dropInConfigurationDTOArg, paymentMethodsResponseArg) wrapped = listOf<Any?>(null) } catch (exception: Throwable) { wrapped = wrapError(exception) diff --git a/android/src/main/kotlin/com/adyen/adyen_checkout/utils/Mapper.kt b/android/src/main/kotlin/com/adyen/adyen_checkout/utils/Mapper.kt index ec0c484..7890a12 100644 --- a/android/src/main/kotlin/com/adyen/adyen_checkout/utils/Mapper.kt +++ b/android/src/main/kotlin/com/adyen/adyen_checkout/utils/Mapper.kt @@ -28,16 +28,16 @@ object Mapper { environment = environment, clientKey = this.clientKey ) - .setShowStorePaymentField(cardsConfiguration?.showStorePaymentField ?: false) - .setAddressConfiguration(cardsConfiguration?.addressMode?.mapToAddressConfiguration() + .setShowStorePaymentField(cardsConfigurationDTO?.showStorePaymentField ?: false) + .setAddressConfiguration(cardsConfigurationDTO?.addressMode?.mapToAddressConfiguration() ?: AddressConfiguration.None) - .setShowStorePaymentField(cardsConfiguration?.showStorePaymentField ?: false) - .setHideCvcStoredCard(cardsConfiguration?.hideCvcStoredCard ?: false) - .setHideCvc(cardsConfiguration?.hideCvc ?: false) - .setKcpAuthVisibility(determineKcpAuthVisibility(cardsConfiguration?.kcpVisible)) - .setSocialSecurityNumberVisibility(determineSocialSecurityNumberVisibility(cardsConfiguration?.socialSecurityVisible)) - .setSupportedCardTypes(*mapToSupportedCardTypes(cardsConfiguration?.supportedCardTypes)) - .setHolderNameRequired(cardsConfiguration?.holderNameRequired ?: false) + .setShowStorePaymentField(cardsConfigurationDTO?.showStorePaymentField ?: false) + .setHideCvcStoredCard(cardsConfigurationDTO?.hideCvcStoredCard ?: false) + .setHideCvc(cardsConfigurationDTO?.hideCvc ?: false) + .setKcpAuthVisibility(determineKcpAuthVisibility(cardsConfigurationDTO?.kcpVisible)) + .setSocialSecurityNumberVisibility(determineSocialSecurityNumberVisibility(cardsConfigurationDTO?.socialSecurityVisible)) + .setSupportedCardTypes(*mapToSupportedCardTypes(cardsConfigurationDTO?.supportedCardTypes)) + .setHolderNameRequired(cardsConfigurationDTO?.holderNameRequired ?: false) .build() val amount = this.amount.mapToAmount() return com.adyen.checkout.dropin.DropInConfiguration.Builder( diff --git a/ios/Classes/CheckoutPlatformApi.swift b/ios/Classes/CheckoutPlatformApi.swift index 5302352..0ffd1fd 100644 --- a/ios/Classes/CheckoutPlatformApi.swift +++ b/ios/Classes/CheckoutPlatformApi.swift @@ -2,6 +2,7 @@ import Foundation @_spi(AdyenInternal) import Adyen import AdyenNetworking +import PassKit //TODO: Add config: // 1) Add Info.plist for adding photo library usage description @@ -28,7 +29,7 @@ class CheckoutPlatformApi : CheckoutPlatformInterface { completion(Result.success(systemVersion)) } - func startDropInSessionPayment(dropInConfiguration: DropInConfigurationDTO, session: Session) { + func startDropInSessionPayment(dropInConfigurationDTO: DropInConfigurationDTO, session: Session) { do { guard let viewController = getViewController() else { return @@ -37,7 +38,7 @@ class CheckoutPlatformApi : CheckoutPlatformInterface { self.viewController = viewController dropInSessionDelegate = DropInSessionsDelegate(viewController: viewController, checkoutFlutterApi: checkoutFlutterApi) dropInSessionPresentationDelegate = DropInSessionsPresentationDelegate() - let adyenContext = try createAdyenContext(dropInConfiguration: dropInConfiguration) + let adyenContext = try createAdyenContext(dropInConfiguration: dropInConfigurationDTO) let sessionConfiguration = AdyenSession.Configuration(sessionIdentifier: session.id, initialSessionData: session.sessionData, context: adyenContext) @@ -46,15 +47,19 @@ class CheckoutPlatformApi : CheckoutPlatformInterface { presentationDelegate: dropInSessionPresentationDelegate!) { [weak self] result in switch result { case let .success(session): - self?.session = session - let dropInConfiguration = self?.createDropInConfiguration(dropInConfiguration: dropInConfiguration) - let dropInComponent = DropInComponent(paymentMethods: session.sessionContext.paymentMethods, - context: adyenContext, - configuration: dropInConfiguration!) - dropInComponent.delegate = session - dropInComponent.partialPaymentDelegate = session - self?.dropInComponent = dropInComponent - self?.viewController?.present(dropInComponent.viewController, animated: true) + do { + self?.session = session + let dropInConfiguration = try self?.createDropInConfiguration(dropInConfigurationDTO: dropInConfigurationDTO) + let dropInComponent = DropInComponent(paymentMethods: session.sessionContext.paymentMethods, + context: adyenContext, + configuration: dropInConfiguration!) + dropInComponent.delegate = session + dropInComponent.partialPaymentDelegate = session + self?.dropInComponent = dropInComponent + self?.viewController?.present(dropInComponent.viewController, animated: true) + } catch let error { + self?.checkoutFlutterApi.onDropInSessionResult(sessionPaymentResult: PaymentResult(type: PaymentResultEnum.error, reason: error.localizedDescription)) {} + } case let .failure(error): self?.checkoutFlutterApi.onDropInSessionResult(sessionPaymentResult: PaymentResult(type: PaymentResultEnum.error, reason: error.localizedDescription)) {} } @@ -64,17 +69,17 @@ class CheckoutPlatformApi : CheckoutPlatformInterface { } } - func startDropInAdvancedFlowPayment(dropInConfiguration: DropInConfigurationDTO, paymentMethodsResponse: String) { + func startDropInAdvancedFlowPayment(dropInConfigurationDTO: DropInConfigurationDTO, paymentMethodsResponse: String) { do { guard let viewController = getViewController() else { return } self.viewController = viewController - let adyenContext = try createAdyenContext(dropInConfiguration: dropInConfiguration) + let adyenContext = try createAdyenContext(dropInConfiguration: dropInConfigurationDTO) let paymentMethods = try jsonDecoder.decode(PaymentMethods.self, from:Data(paymentMethodsResponse.utf8)) let paymentMethodsWithoutGiftCards = removeGiftCardPaymentMethods(paymentMethods: paymentMethods) - let configuration = createDropInConfiguration(dropInConfiguration: dropInConfiguration) + let configuration = try createDropInConfiguration(dropInConfigurationDTO: dropInConfigurationDTO) let dropInComponent = DropInComponent(paymentMethods: paymentMethodsWithoutGiftCards, context: adyenContext, configuration: configuration) @@ -145,26 +150,33 @@ class CheckoutPlatformApi : CheckoutPlatformInterface { } } - private func createDropInConfiguration(dropInConfiguration: DropInConfigurationDTO) -> DropInComponent.Configuration { - let koreanAuthenticationMode = determineFieldVisibility(visible: dropInConfiguration.cardsConfiguration?.kcpVisible) - let socialSecurityNumberMode = determineFieldVisibility(visible: dropInConfiguration.cardsConfiguration?.socialSecurityVisible) - let storedCardConfiguration = createStoredCardConfiguration(hideCvcStoredCard: dropInConfiguration.cardsConfiguration?.hideCvcStoredCard) - let allowedCardTypes = determineAllowedCardTypes(cardTypes: dropInConfiguration.cardsConfiguration?.supportedCardTypes) - let billingAddressConfiguration = determineBillingAddressConfiguration(addressMode: dropInConfiguration.cardsConfiguration?.addressMode) - let cardConfiguration = DropInComponent.Card.init( - showsHolderNameField: dropInConfiguration.cardsConfiguration?.holderNameRequired ?? false, - showsStorePaymentMethodField: dropInConfiguration.cardsConfiguration?.showStorePaymentField ?? true, - showsSecurityCodeField: dropInConfiguration.cardsConfiguration?.hideCvc == false, - koreanAuthenticationMode: koreanAuthenticationMode, - socialSecurityNumberMode: socialSecurityNumberMode, - storedCardConfiguration: storedCardConfiguration, - allowedCardTypes: allowedCardTypes, - billingAddress: billingAddressConfiguration - ) + private func createDropInConfiguration(dropInConfigurationDTO: DropInConfigurationDTO) throws -> DropInComponent.Configuration { + let dropInConfiguration = DropInComponent.Configuration(allowsSkippingPaymentList: dropInConfigurationDTO.skipListWhenSinglePaymentMethod ?? false, + allowPreselectedPaymentView: dropInConfigurationDTO.showPreselectedStoredPaymentMethod ?? false) - let dropInConfiguration = DropInComponent.Configuration(allowsSkippingPaymentList: dropInConfiguration.skipListWhenSinglePaymentMethod ?? false, - allowPreselectedPaymentView: dropInConfiguration.showPreselectedStoredPaymentMethod ?? false) - dropInConfiguration.card = cardConfiguration + if let cardsConfigurationDTO = dropInConfigurationDTO.cardsConfigurationDTO { + let koreanAuthenticationMode = determineFieldVisibility(visible: cardsConfigurationDTO.kcpVisible) + let socialSecurityNumberMode = determineFieldVisibility(visible: cardsConfigurationDTO.socialSecurityVisible) + let storedCardConfiguration = createStoredCardConfiguration(hideCvcStoredCard: cardsConfigurationDTO.hideCvcStoredCard) + let allowedCardTypes = determineAllowedCardTypes(cardTypes: cardsConfigurationDTO.supportedCardTypes) + let billingAddressConfiguration = determineBillingAddressConfiguration(addressMode: cardsConfigurationDTO.addressMode) + let cardConfiguration = DropInComponent.Card.init( + showsHolderNameField: cardsConfigurationDTO.holderNameRequired, + showsStorePaymentMethodField: cardsConfigurationDTO.showStorePaymentField, + showsSecurityCodeField: cardsConfigurationDTO.hideCvc == false, + koreanAuthenticationMode: koreanAuthenticationMode, + socialSecurityNumberMode: socialSecurityNumberMode, + storedCardConfiguration: storedCardConfiguration, + allowedCardTypes: allowedCardTypes, + billingAddress: billingAddressConfiguration + ) + + dropInConfiguration.card = cardConfiguration + } + + if let appleConfigurationDTO = dropInConfigurationDTO.applePayConfigurationDTO { + let appleConfiguration = try buildApplePayConfiguration(dropInConfigurationDTO: dropInConfigurationDTO) + } return dropInConfiguration } @@ -211,7 +223,24 @@ class CheckoutPlatformApi : CheckoutPlatformInterface { return billingAddressConfiguration } - + private func buildApplePayConfiguration(dropInConfigurationDTO: DropInConfigurationDTO) throws -> Adyen.ApplePayComponent.Configuration { + let value = Int(dropInConfigurationDTO.amount.value) + guard let currencyCode : String = dropInConfigurationDTO.amount.currency else { + throw BalanceChecker.Error.unexpectedCurrencyCode + } + + let amount = AmountFormatter.decimalAmount(value, + currencyCode: currencyCode, + localeIdentifier: nil) + + let applePayPayment = try ApplePayPayment.init(countryCode: dropInConfigurationDTO.countryCode, + currencyCode: currencyCode, + summaryItems: [PKPaymentSummaryItem(label: dropInConfigurationDTO.applePayConfigurationDTO!.merchantName, amount: amount)]) + + return ApplePayComponent.Configuration.init(payment: applePayPayment, + merchantIdentifier: dropInConfigurationDTO.applePayConfigurationDTO!.merchantId) + } + private func handleDropInResult(dropInResult: DropInResult) { do { diff --git a/ios/Classes/PlatformApi.swift b/ios/Classes/PlatformApi.swift index 2d3ec03..751a5c2 100644 --- a/ios/Classes/PlatformApi.swift +++ b/ios/Classes/PlatformApi.swift @@ -121,25 +121,30 @@ struct DropInConfigurationDTO { var clientKey: String var countryCode: String var amount: Amount - var analyticsOptions: AnalyticsOptions? = nil + var analyticsOptionsDTO: AnalyticsOptionsDTO? = nil var showPreselectedStoredPaymentMethod: Bool? = nil var skipListWhenSinglePaymentMethod: Bool? = nil - var cardsConfiguration: CardsConfigurationDTO? = nil + var cardsConfigurationDTO: CardsConfigurationDTO? = nil + var applePayConfigurationDTO: ApplePayConfigurationDTO? = nil static func fromList(_ list: [Any?]) -> DropInConfigurationDTO? { let environment = Environment(rawValue: list[0] as! Int)! let clientKey = list[1] as! String let countryCode = list[2] as! String let amount = Amount.fromList(list[3] as! [Any?])! - var analyticsOptions: AnalyticsOptions? = nil - if let analyticsOptionsList: [Any?] = nilOrValue(list[4]) { - analyticsOptions = AnalyticsOptions.fromList(analyticsOptionsList) + var analyticsOptionsDTO: AnalyticsOptionsDTO? = nil + if let analyticsOptionsDTOList: [Any?] = nilOrValue(list[4]) { + analyticsOptionsDTO = AnalyticsOptionsDTO.fromList(analyticsOptionsDTOList) } let showPreselectedStoredPaymentMethod: Bool? = nilOrValue(list[5]) let skipListWhenSinglePaymentMethod: Bool? = nilOrValue(list[6]) - var cardsConfiguration: CardsConfigurationDTO? = nil - if let cardsConfigurationList: [Any?] = nilOrValue(list[7]) { - cardsConfiguration = CardsConfigurationDTO.fromList(cardsConfigurationList) + var cardsConfigurationDTO: CardsConfigurationDTO? = nil + if let cardsConfigurationDTOList: [Any?] = nilOrValue(list[7]) { + cardsConfigurationDTO = CardsConfigurationDTO.fromList(cardsConfigurationDTOList) + } + var applePayConfigurationDTO: ApplePayConfigurationDTO? = nil + if let applePayConfigurationDTOList: [Any?] = nilOrValue(list[8]) { + applePayConfigurationDTO = ApplePayConfigurationDTO.fromList(applePayConfigurationDTOList) } return DropInConfigurationDTO( @@ -147,10 +152,11 @@ struct DropInConfigurationDTO { clientKey: clientKey, countryCode: countryCode, amount: amount, - analyticsOptions: analyticsOptions, + analyticsOptionsDTO: analyticsOptionsDTO, showPreselectedStoredPaymentMethod: showPreselectedStoredPaymentMethod, skipListWhenSinglePaymentMethod: skipListWhenSinglePaymentMethod, - cardsConfiguration: cardsConfiguration + cardsConfigurationDTO: cardsConfigurationDTO, + applePayConfigurationDTO: applePayConfigurationDTO ) } func toList() -> [Any?] { @@ -159,10 +165,11 @@ struct DropInConfigurationDTO { clientKey, countryCode, amount.toList(), - analyticsOptions?.toList(), + analyticsOptionsDTO?.toList(), showPreselectedStoredPaymentMethod, skipListWhenSinglePaymentMethod, - cardsConfiguration?.toList(), + cardsConfigurationDTO?.toList(), + applePayConfigurationDTO?.toList(), ] } } @@ -214,15 +221,15 @@ struct CardsConfigurationDTO { } /// Generated class from Pigeon that represents data sent in messages. -struct AnalyticsOptions { +struct AnalyticsOptionsDTO { var enabled: Bool? = nil var payload: String? = nil - static func fromList(_ list: [Any?]) -> AnalyticsOptions? { + static func fromList(_ list: [Any?]) -> AnalyticsOptionsDTO? { let enabled: Bool? = nilOrValue(list[0]) let payload: String? = nilOrValue(list[1]) - return AnalyticsOptions( + return AnalyticsOptionsDTO( enabled: enabled, payload: payload ) @@ -235,6 +242,32 @@ struct AnalyticsOptions { } } +/// Generated class from Pigeon that represents data sent in messages. +struct ApplePayConfigurationDTO { + var merchantId: String + var merchantName: String + var allowOnboarding: Bool + + static func fromList(_ list: [Any?]) -> ApplePayConfigurationDTO? { + let merchantId = list[0] as! String + let merchantName = list[1] as! String + let allowOnboarding = list[2] as! Bool + + return ApplePayConfigurationDTO( + merchantId: merchantId, + merchantName: merchantName, + allowOnboarding: allowOnboarding + ) + } + func toList() -> [Any?] { + return [ + merchantId, + merchantName, + allowOnboarding, + ] + } +} + /// Generated class from Pigeon that represents data sent in messages. struct PaymentResult { var type: PaymentResultEnum @@ -427,16 +460,18 @@ private class CheckoutPlatformInterfaceCodecReader: FlutterStandardReader { case 128: return Amount.fromList(self.readValue() as! [Any?]) case 129: - return AnalyticsOptions.fromList(self.readValue() as! [Any?]) + return AnalyticsOptionsDTO.fromList(self.readValue() as! [Any?]) case 130: - return CardsConfigurationDTO.fromList(self.readValue() as! [Any?]) + return ApplePayConfigurationDTO.fromList(self.readValue() as! [Any?]) case 131: - return DropInConfigurationDTO.fromList(self.readValue() as! [Any?]) + return CardsConfigurationDTO.fromList(self.readValue() as! [Any?]) case 132: - return DropInError.fromList(self.readValue() as! [Any?]) + return DropInConfigurationDTO.fromList(self.readValue() as! [Any?]) case 133: - return DropInResult.fromList(self.readValue() as! [Any?]) + return DropInError.fromList(self.readValue() as! [Any?]) case 134: + return DropInResult.fromList(self.readValue() as! [Any?]) + case 135: return Session.fromList(self.readValue() as! [Any?]) default: return super.readValue(ofType: type) @@ -449,24 +484,27 @@ private class CheckoutPlatformInterfaceCodecWriter: FlutterStandardWriter { if let value = value as? Amount { super.writeByte(128) super.writeValue(value.toList()) - } else if let value = value as? AnalyticsOptions { + } else if let value = value as? AnalyticsOptionsDTO { super.writeByte(129) super.writeValue(value.toList()) - } else if let value = value as? CardsConfigurationDTO { + } else if let value = value as? ApplePayConfigurationDTO { super.writeByte(130) super.writeValue(value.toList()) - } else if let value = value as? DropInConfigurationDTO { + } else if let value = value as? CardsConfigurationDTO { super.writeByte(131) super.writeValue(value.toList()) - } else if let value = value as? DropInError { + } else if let value = value as? DropInConfigurationDTO { super.writeByte(132) super.writeValue(value.toList()) - } else if let value = value as? DropInResult { + } else if let value = value as? DropInError { super.writeByte(133) super.writeValue(value.toList()) - } else if let value = value as? Session { + } else if let value = value as? DropInResult { super.writeByte(134) super.writeValue(value.toList()) + } else if let value = value as? Session { + super.writeByte(135) + super.writeValue(value.toList()) } else { super.writeValue(value) } @@ -491,8 +529,8 @@ class CheckoutPlatformInterfaceCodec: FlutterStandardMessageCodec { protocol CheckoutPlatformInterface { func getPlatformVersion(completion: @escaping (Result<String, Error>) -> Void) func getReturnUrl(completion: @escaping (Result<String, Error>) -> Void) - func startDropInSessionPayment(dropInConfiguration: DropInConfigurationDTO, session: Session) throws - func startDropInAdvancedFlowPayment(dropInConfiguration: DropInConfigurationDTO, paymentMethodsResponse: String) throws + func startDropInSessionPayment(dropInConfigurationDTO: DropInConfigurationDTO, session: Session) throws + func startDropInAdvancedFlowPayment(dropInConfigurationDTO: DropInConfigurationDTO, paymentMethodsResponse: String) throws func onPaymentsResult(paymentsResult: DropInResult) throws func onPaymentsDetailsResult(paymentsDetailsResult: DropInResult) throws } @@ -537,10 +575,10 @@ class CheckoutPlatformInterfaceSetup { if let api = api { startDropInSessionPaymentChannel.setMessageHandler { message, reply in let args = message as! [Any?] - let dropInConfigurationArg = args[0] as! DropInConfigurationDTO + let dropInConfigurationDTOArg = args[0] as! DropInConfigurationDTO let sessionArg = args[1] as! Session do { - try api.startDropInSessionPayment(dropInConfiguration: dropInConfigurationArg, session: sessionArg) + try api.startDropInSessionPayment(dropInConfigurationDTO: dropInConfigurationDTOArg, session: sessionArg) reply(wrapResult(nil)) } catch { reply(wrapError(error)) @@ -553,10 +591,10 @@ class CheckoutPlatformInterfaceSetup { if let api = api { startDropInAdvancedFlowPaymentChannel.setMessageHandler { message, reply in let args = message as! [Any?] - let dropInConfigurationArg = args[0] as! DropInConfigurationDTO + let dropInConfigurationDTOArg = args[0] as! DropInConfigurationDTO let paymentMethodsResponseArg = args[1] as! String do { - try api.startDropInAdvancedFlowPayment(dropInConfiguration: dropInConfigurationArg, paymentMethodsResponse: paymentMethodsResponseArg) + try api.startDropInAdvancedFlowPayment(dropInConfigurationDTO: dropInConfigurationDTOArg, paymentMethodsResponse: paymentMethodsResponseArg) reply(wrapResult(nil)) } catch { reply(wrapError(error)) diff --git a/lib/adyen_checkout.dart b/lib/adyen_checkout.dart index 9e688e7..6c70703 100644 --- a/lib/adyen_checkout.dart +++ b/lib/adyen_checkout.dart @@ -6,7 +6,6 @@ export 'src/generated/platform_api.g.dart' Environment, Session, OrderResponseModel, - AnalyticsOptions, AddressMode; export 'src/models/adyen_configuration.dart'; export 'src/models/drop_in_outcome.dart'; diff --git a/lib/src/adyen_checkout.dart b/lib/src/adyen_checkout.dart index e2a51e1..a81fbc7 100644 --- a/lib/src/adyen_checkout.dart +++ b/lib/src/adyen_checkout.dart @@ -39,7 +39,7 @@ class AdyenCheckout implements AdyenCheckoutInterface { clientKey: dropInSession.dropInConfiguration.clientKey, countryCode: dropInSession.dropInConfiguration.countryCode, amount: dropInSession.dropInConfiguration.amount, - cardsConfiguration: dropInSession.dropInConfiguration.cardsConfiguration, + cardsConfigurationDTO: dropInSession.dropInConfiguration.cardsConfigurationDTO, ); AdyenCheckoutPlatformInterface.instance.startDropInSessionPayment( dropInSession.session, @@ -59,8 +59,8 @@ class AdyenCheckout implements AdyenCheckoutInterface { clientKey: dropInAdvancedFlow.dropInConfiguration.clientKey, countryCode: dropInAdvancedFlow.dropInConfiguration.countryCode, amount: dropInAdvancedFlow.dropInConfiguration.amount, - cardsConfiguration: - dropInAdvancedFlow.dropInConfiguration.cardsConfiguration, + cardsConfigurationDTO: + dropInAdvancedFlow.dropInConfiguration.cardsConfigurationDTO, ); AdyenCheckoutPlatformInterface.instance.startDropInAdvancedFlowPayment( dropInAdvancedFlow.paymentMethodsResponse, diff --git a/lib/src/generated/platform_api.g.dart b/lib/src/generated/platform_api.g.dart index 6d3b9be..1e620ca 100644 --- a/lib/src/generated/platform_api.g.dart +++ b/lib/src/generated/platform_api.g.dart @@ -99,10 +99,11 @@ class DropInConfigurationDTO { required this.clientKey, required this.countryCode, required this.amount, - this.analyticsOptions, + this.analyticsOptionsDTO, this.showPreselectedStoredPaymentMethod, this.skipListWhenSinglePaymentMethod, - this.cardsConfiguration, + this.cardsConfigurationDTO, + this.applePayConfigurationDTO, }); Environment environment; @@ -113,13 +114,15 @@ class DropInConfigurationDTO { Amount amount; - AnalyticsOptions? analyticsOptions; + AnalyticsOptionsDTO? analyticsOptionsDTO; bool? showPreselectedStoredPaymentMethod; bool? skipListWhenSinglePaymentMethod; - CardsConfigurationDTO? cardsConfiguration; + CardsConfigurationDTO? cardsConfigurationDTO; + + ApplePayConfigurationDTO? applePayConfigurationDTO; Object encode() { return <Object?>[ @@ -127,10 +130,11 @@ class DropInConfigurationDTO { clientKey, countryCode, amount.encode(), - analyticsOptions?.encode(), + analyticsOptionsDTO?.encode(), showPreselectedStoredPaymentMethod, skipListWhenSinglePaymentMethod, - cardsConfiguration?.encode(), + cardsConfigurationDTO?.encode(), + applePayConfigurationDTO?.encode(), ]; } @@ -141,14 +145,17 @@ class DropInConfigurationDTO { clientKey: result[1]! as String, countryCode: result[2]! as String, amount: Amount.decode(result[3]! as List<Object?>), - analyticsOptions: result[4] != null - ? AnalyticsOptions.decode(result[4]! as List<Object?>) + analyticsOptionsDTO: result[4] != null + ? AnalyticsOptionsDTO.decode(result[4]! as List<Object?>) : null, showPreselectedStoredPaymentMethod: result[5] as bool?, skipListWhenSinglePaymentMethod: result[6] as bool?, - cardsConfiguration: result[7] != null + cardsConfigurationDTO: result[7] != null ? CardsConfigurationDTO.decode(result[7]! as List<Object?>) : null, + applePayConfigurationDTO: result[8] != null + ? ApplePayConfigurationDTO.decode(result[8]! as List<Object?>) + : null, ); } } @@ -209,8 +216,8 @@ class CardsConfigurationDTO { } } -class AnalyticsOptions { - AnalyticsOptions({ +class AnalyticsOptionsDTO { + AnalyticsOptionsDTO({ this.enabled, this.payload, }); @@ -226,15 +233,46 @@ class AnalyticsOptions { ]; } - static AnalyticsOptions decode(Object result) { + static AnalyticsOptionsDTO decode(Object result) { result as List<Object?>; - return AnalyticsOptions( + return AnalyticsOptionsDTO( enabled: result[0] as bool?, payload: result[1] as String?, ); } } +class ApplePayConfigurationDTO { + ApplePayConfigurationDTO({ + required this.merchantId, + required this.merchantName, + required this.allowOnboarding, + }); + + String merchantId; + + String merchantName; + + bool allowOnboarding; + + Object encode() { + return <Object?>[ + merchantId, + merchantName, + allowOnboarding, + ]; + } + + static ApplePayConfigurationDTO decode(Object result) { + result as List<Object?>; + return ApplePayConfigurationDTO( + merchantId: result[0]! as String, + merchantName: result[1]! as String, + allowOnboarding: result[2]! as bool, + ); + } +} + class PaymentResult { PaymentResult({ required this.type, @@ -455,24 +493,27 @@ class _CheckoutPlatformInterfaceCodec extends StandardMessageCodec { if (value is Amount) { buffer.putUint8(128); writeValue(buffer, value.encode()); - } else if (value is AnalyticsOptions) { + } else if (value is AnalyticsOptionsDTO) { buffer.putUint8(129); writeValue(buffer, value.encode()); - } else if (value is CardsConfigurationDTO) { + } else if (value is ApplePayConfigurationDTO) { buffer.putUint8(130); writeValue(buffer, value.encode()); - } else if (value is DropInConfigurationDTO) { + } else if (value is CardsConfigurationDTO) { buffer.putUint8(131); writeValue(buffer, value.encode()); - } else if (value is DropInError) { + } else if (value is DropInConfigurationDTO) { buffer.putUint8(132); writeValue(buffer, value.encode()); - } else if (value is DropInResult) { + } else if (value is DropInError) { buffer.putUint8(133); writeValue(buffer, value.encode()); - } else if (value is Session) { + } else if (value is DropInResult) { buffer.putUint8(134); writeValue(buffer, value.encode()); + } else if (value is Session) { + buffer.putUint8(135); + writeValue(buffer, value.encode()); } else { super.writeValue(buffer, value); } @@ -484,16 +525,18 @@ class _CheckoutPlatformInterfaceCodec extends StandardMessageCodec { case 128: return Amount.decode(readValue(buffer)!); case 129: - return AnalyticsOptions.decode(readValue(buffer)!); + return AnalyticsOptionsDTO.decode(readValue(buffer)!); case 130: - return CardsConfigurationDTO.decode(readValue(buffer)!); + return ApplePayConfigurationDTO.decode(readValue(buffer)!); case 131: - return DropInConfigurationDTO.decode(readValue(buffer)!); + return CardsConfigurationDTO.decode(readValue(buffer)!); case 132: - return DropInError.decode(readValue(buffer)!); + return DropInConfigurationDTO.decode(readValue(buffer)!); case 133: - return DropInResult.decode(readValue(buffer)!); + return DropInError.decode(readValue(buffer)!); case 134: + return DropInResult.decode(readValue(buffer)!); + case 135: return Session.decode(readValue(buffer)!); default: return super.readValueOfType(type, buffer); @@ -565,12 +608,12 @@ class CheckoutPlatformInterface { } } - Future<void> startDropInSessionPayment(DropInConfigurationDTO arg_dropInConfiguration, Session arg_session) async { + Future<void> startDropInSessionPayment(DropInConfigurationDTO arg_dropInConfigurationDTO, Session arg_session) async { final BasicMessageChannel<Object?> channel = BasicMessageChannel<Object?>( 'dev.flutter.pigeon.adyen_checkout.CheckoutPlatformInterface.startDropInSessionPayment', codec, binaryMessenger: _binaryMessenger); final List<Object?>? replyList = - await channel.send(<Object?>[arg_dropInConfiguration, arg_session]) as List<Object?>?; + await channel.send(<Object?>[arg_dropInConfigurationDTO, arg_session]) as List<Object?>?; if (replyList == null) { throw PlatformException( code: 'channel-error', @@ -587,12 +630,12 @@ class CheckoutPlatformInterface { } } - Future<void> startDropInAdvancedFlowPayment(DropInConfigurationDTO arg_dropInConfiguration, String arg_paymentMethodsResponse) async { + Future<void> startDropInAdvancedFlowPayment(DropInConfigurationDTO arg_dropInConfigurationDTO, String arg_paymentMethodsResponse) async { final BasicMessageChannel<Object?> channel = BasicMessageChannel<Object?>( 'dev.flutter.pigeon.adyen_checkout.CheckoutPlatformInterface.startDropInAdvancedFlowPayment', codec, binaryMessenger: _binaryMessenger); final List<Object?>? replyList = - await channel.send(<Object?>[arg_dropInConfiguration, arg_paymentMethodsResponse]) as List<Object?>?; + await channel.send(<Object?>[arg_dropInConfigurationDTO, arg_paymentMethodsResponse]) as List<Object?>?; if (replyList == null) { throw PlatformException( code: 'channel-error', diff --git a/lib/src/models/adyen_configuration.dart b/lib/src/models/adyen_configuration.dart index 94abcca..11ba85c 100644 --- a/lib/src/models/adyen_configuration.dart +++ b/lib/src/models/adyen_configuration.dart @@ -1,6 +1,6 @@ import 'package:adyen_checkout/src/generated/platform_api.g.dart'; -abstract class AdyenConfiguration { +sealed class AdyenConfiguration { final Environment environment; final String clientKey; final String countryCode; @@ -22,27 +22,62 @@ class DropInConfiguration extends DropInConfigurationDTO required super.countryCode, required super.amount, CardsConfiguration? cardsConfiguration, + ApplePayConfiguration? applePayConfiguration, AnalyticsOptions? analyticsOptions, bool showPreselectedStoredPaymentMethod = false, bool skipListWhenSinglePaymentMethod = false, }) : super( - analyticsOptions: analyticsOptions, + cardsConfigurationDTO: _toCardsConfigurationDTO(cardsConfiguration), + applePayConfigurationDTO: + _toApplePayConfigurationDTO(applePayConfiguration), + analyticsOptionsDTO: _toAnalyticsOptionsDTO(analyticsOptions), showPreselectedStoredPaymentMethod: showPreselectedStoredPaymentMethod, skipListWhenSinglePaymentMethod: skipListWhenSinglePaymentMethod, - cardsConfiguration: CardsConfigurationDTO( - holderNameRequired: cardsConfiguration?.holderNameRequired ?? false, - addressMode: cardsConfiguration?.addressMode ?? AddressMode.none, - showStorePaymentField: - cardsConfiguration?.showStorePaymentField ?? false, - hideCvcStoredCard: cardsConfiguration?.hideCvcStoredCard ?? false, - hideCvc: cardsConfiguration?.hideCvc ?? false, - kcpVisible: cardsConfiguration?.kcpVisible ?? false, - socialSecurityVisible: - cardsConfiguration?.socialSecurityVisible ?? false, - supportedCardTypes: cardsConfiguration?.supportedCardTypes ?? [], - ), ); + + static CardsConfigurationDTO? _toCardsConfigurationDTO( + CardsConfiguration? cardsConfiguration) { + if (cardsConfiguration == null) { + return null; + } + + return CardsConfigurationDTO( + holderNameRequired: cardsConfiguration.holderNameRequired, + addressMode: cardsConfiguration.addressMode, + showStorePaymentField: cardsConfiguration.showStorePaymentField, + hideCvcStoredCard: cardsConfiguration.hideCvcStoredCard, + hideCvc: cardsConfiguration.hideCvc, + kcpVisible: cardsConfiguration.kcpVisible, + socialSecurityVisible: cardsConfiguration.socialSecurityVisible, + supportedCardTypes: cardsConfiguration.supportedCardTypes, + ); + } + + static ApplePayConfigurationDTO? _toApplePayConfigurationDTO( + ApplePayConfiguration? applePayConfiguration) { + if (applePayConfiguration == null) { + return null; + } + + return ApplePayConfigurationDTO( + merchantId: applePayConfiguration.merchantId, + merchantName: applePayConfiguration.merchantName, + allowOnboarding: applePayConfiguration.allowOnboarding, + ); + } + + static AnalyticsOptionsDTO? _toAnalyticsOptionsDTO( + AnalyticsOptions? analyticsOptions) { + if (analyticsOptions == null) { + return null; + } + + return AnalyticsOptionsDTO( + enabled: analyticsOptions.enabled, + payload: analyticsOptions.payload, + ); + } } class CardsConfiguration extends CardsConfigurationDTO { @@ -67,23 +102,29 @@ class CardsConfiguration extends CardsConfigurationDTO { ); } -class ApplePayConfiguration extends AdyenConfiguration { +class AnalyticsOptions { + final bool? enabled; + final String? payload; + + AnalyticsOptions({ + this.enabled, + this.payload, + }); +} + +class ApplePayConfiguration { final String merchantId; final String merchantName; final bool allowOnboarding; - ApplePayConfiguration( - super.environment, - super.clientKey, - super.countryCode, - super.amount, { + ApplePayConfiguration({ required this.merchantId, required this.merchantName, this.allowOnboarding = false, }); } -class GooglePayConfiguration extends AdyenConfiguration { +class GooglePayConfiguration { final String merchantAccount; final List<String> allowedCardNetworks; final List<CardAuthMethod> allowedAuthMethods; @@ -95,11 +136,7 @@ class GooglePayConfiguration extends AdyenConfiguration { final bool existingPaymentMethodRequired; final GooglePayEnvironment googlePayEnvironment; - GooglePayConfiguration( - super.environment, - super.clientKey, - super.countryCode, - super.amount, { + GooglePayConfiguration({ required this.totalPriceStatus, required this.googlePayEnvironment, this.merchantAccount = "", diff --git a/pigeons/platform_api.dart b/pigeons/platform_api.dart index f2b3630..f2da266 100644 --- a/pigeons/platform_api.dart +++ b/pigeons/platform_api.dart @@ -44,20 +44,22 @@ class DropInConfigurationDTO { final String clientKey; final String countryCode; final Amount amount; - final AnalyticsOptions? analyticsOptions; + final AnalyticsOptionsDTO? analyticsOptionsDTO; final bool? showPreselectedStoredPaymentMethod; final bool? skipListWhenSinglePaymentMethod; - final CardsConfigurationDTO? cardsConfiguration; + final CardsConfigurationDTO? cardsConfigurationDTO; + final ApplePayConfigurationDTO? applePayConfigurationDTO; DropInConfigurationDTO( this.environment, this.clientKey, this.countryCode, this.amount, - this.analyticsOptions, - this.cardsConfiguration, + this.analyticsOptionsDTO, + this.cardsConfigurationDTO, this.showPreselectedStoredPaymentMethod, this.skipListWhenSinglePaymentMethod, + this.applePayConfigurationDTO, ); } @@ -89,14 +91,26 @@ enum AddressMode { none, } -class AnalyticsOptions { +class AnalyticsOptionsDTO { final bool? enabled; final String? payload; - AnalyticsOptions({ + AnalyticsOptionsDTO( this.enabled, this.payload, - }); + ); +} + +class ApplePayConfigurationDTO { + final String merchantId; + final String merchantName; + final bool allowOnboarding; + + ApplePayConfigurationDTO( + this.merchantId, + this.merchantName, + this.allowOnboarding, + ); } class PaymentResult { @@ -205,12 +219,12 @@ abstract class CheckoutPlatformInterface { String getReturnUrl(); void startDropInSessionPayment( - DropInConfigurationDTO dropInConfiguration, + DropInConfigurationDTO dropInConfigurationDTO, Session session, ); void startDropInAdvancedFlowPayment( - DropInConfigurationDTO dropInConfiguration, + DropInConfigurationDTO dropInConfigurationDTO, String paymentMethodsResponse, );
Configuration menu - View commit details
-
Copy full SHA for ef8d540 - Browse repository at this point
Copy the full SHA ef8d540View commit details -
Configuration menu - View commit details
-
Copy full SHA for 90576c6 - Browse repository at this point
Copy the full SHA 90576c6View commit details -
Configuration menu - View commit details
-
Copy full SHA for 6aaa00a - Browse repository at this point
Copy the full SHA 6aaa00aView commit details -
Configuration menu - View commit details
-
Copy full SHA for bef8253 - Browse repository at this point
Copy the full SHA bef8253View commit details
Commits on Sep 19, 2023
-
Configuration menu - View commit details
-
Copy full SHA for 4861aa2 - Browse repository at this point
Copy the full SHA 4861aa2View commit details
Commits on Sep 20, 2023
-
Configuration menu - View commit details
-
Copy full SHA for 8daacb1 - Browse repository at this point
Copy the full SHA 8daacb1View commit details -
Configuration menu - View commit details
-
Copy full SHA for 14ee502 - Browse repository at this point
Copy the full SHA 14ee502View commit details -
Configuration menu - View commit details
-
Copy full SHA for 74fca87 - Browse repository at this point
Copy the full SHA 74fca87View commit details -
Configuration menu - View commit details
-
Copy full SHA for 04346bf - Browse repository at this point
Copy the full SHA 04346bfView commit details -
Configuration menu - View commit details
-
Copy full SHA for aa93c3e - Browse repository at this point
Copy the full SHA aa93c3eView commit details
Commits on Sep 21, 2023
-
Configuration menu - View commit details
-
Copy full SHA for 5cb2c61 - Browse repository at this point
Copy the full SHA 5cb2c61View commit details -
Configuration menu - View commit details
-
Copy full SHA for 240aab2 - Browse repository at this point
Copy the full SHA 240aab2View commit details -
Update ios/Classes/utils/ConfigurationMapper.swift
Co-authored-by: Alex Guretzki <[email protected]>
Configuration menu - View commit details
-
Copy full SHA for 50355ec - Browse repository at this point
Copy the full SHA 50355ecView commit details -
Update ios/Classes/utils/ConfigurationMapper.swift
Co-authored-by: Alex Guretzki <[email protected]>
Configuration menu - View commit details
-
Copy full SHA for 62a215e - Browse repository at this point
Copy the full SHA 62a215eView commit details -
Update ios/Classes/utils/ConfigurationMapper.swift
Co-authored-by: Alex Guretzki <[email protected]>
Configuration menu - View commit details
-
Copy full SHA for aecb7ab - Browse repository at this point
Copy the full SHA aecb7abView commit details -
Update ios/Classes/utils/ConfigurationMapper.swift
Co-authored-by: Alex Guretzki <[email protected]>
Configuration menu - View commit details
-
Copy full SHA for 0e406a3 - Browse repository at this point
Copy the full SHA 0e406a3View commit details -
Update ios/Classes/utils/ConfigurationMapper.swift
Co-authored-by: Alex Guretzki <[email protected]>
Configuration menu - View commit details
-
Copy full SHA for 7df3b9e - Browse repository at this point
Copy the full SHA 7df3b9eView commit details -
Configuration menu - View commit details
-
Copy full SHA for 8b83bd3 - Browse repository at this point
Copy the full SHA 8b83bd3View commit details