From fbdcdb5b3e64871a1e7b920fc61707056ad8427b Mon Sep 17 00:00:00 2001 From: Robert Schulze Dieckhoff Date: Mon, 17 Feb 2025 16:08:18 +0100 Subject: [PATCH] Updated latest changes --- .../flutter/dropIn/DropInPlatformApi.kt | 8 ++-- .../dropIn/advanced/AdvancedDropInService.kt | 18 +++++---- .../dropIn/session/SessionDropInService.kt | 14 ++++--- .../checkout/flutter/generated/PlatformApi.kt | 4 +- .../lib/screens/drop_in/drop_in_screen.dart | 16 +++----- ios/Classes/dropIn/DropInPlatformApi.swift | 15 ++++---- ios/Classes/generated/PlatformApi.swift | 2 + .../model/card_callbacks/card_callbacks.dart | 10 ++++- lib/src/common/model/checkout.dart | 5 --- .../card_configuration.dart | 4 +- lib/src/drop_in/drop_in.dart | 38 ++++++++++--------- lib/src/generated/platform_api.g.dart | 2 + 12 files changed, 75 insertions(+), 61 deletions(-) diff --git a/android/src/main/kotlin/com/adyen/checkout/flutter/dropIn/DropInPlatformApi.kt b/android/src/main/kotlin/com/adyen/checkout/flutter/dropIn/DropInPlatformApi.kt index f574d4cd..7ff823cb 100644 --- a/android/src/main/kotlin/com/adyen/checkout/flutter/dropIn/DropInPlatformApi.kt +++ b/android/src/main/kotlin/com/adyen/checkout/flutter/dropIn/DropInPlatformApi.kt @@ -61,8 +61,8 @@ internal class DropInPlatformApi( private var dropInPlatformMessengerJob: Job? = null companion object { - val dropInSessionPlatformMessageFlow = MutableSharedFlow() - val dropInAdvancedPlatformMessageFlow = MutableSharedFlow() + val dropInSessionPlatformMessageFlow = MutableSharedFlow() + val dropInAdvancedPlatformMessageFlow = MutableSharedFlow() } override fun showDropInSession(dropInConfigurationDTO: DropInConfigurationDTO) { @@ -79,7 +79,7 @@ internal class DropInPlatformApi( dropInPlatformMessengerJob = activity.lifecycleScope.launch { dropInSessionPlatformMessageFlow.collect { platformCommunicationModel -> - dropInFlutterApi.onDropInSessionPlatformCommunication(platformCommunicationModel) {} + checkoutFlutter.send(platformCommunicationModel) {} } } @@ -106,7 +106,7 @@ internal class DropInPlatformApi( dropInPlatformMessengerJob = activity.lifecycleScope.launch { dropInAdvancedPlatformMessageFlow.collect { platformCommunicationModel -> - dropInFlutterApi.onDropInAdvancedPlatformCommunication(platformCommunicationModel) {} + checkoutFlutter.send(platformCommunicationModel) {} } } diff --git a/android/src/main/kotlin/com/adyen/checkout/flutter/dropIn/advanced/AdvancedDropInService.kt b/android/src/main/kotlin/com/adyen/checkout/flutter/dropIn/advanced/AdvancedDropInService.kt index be06b3cc..cc1f2528 100644 --- a/android/src/main/kotlin/com/adyen/checkout/flutter/dropIn/advanced/AdvancedDropInService.kt +++ b/android/src/main/kotlin/com/adyen/checkout/flutter/dropIn/advanced/AdvancedDropInService.kt @@ -32,6 +32,8 @@ import com.adyen.checkout.flutter.generated.OrderCancelResultDTO import com.adyen.checkout.flutter.generated.PaymentEventDTO import com.adyen.checkout.flutter.generated.PaymentEventType import com.adyen.checkout.flutter.dropIn.model.toJson +import com.adyen.checkout.flutter.generated.CheckoutEvent +import com.adyen.checkout.flutter.generated.CheckoutEventType import com.adyen.checkout.flutter.utils.Constants import com.adyen.checkout.flutter.utils.Constants.Companion.ADYEN_LOG_TAG import com.adyen.checkout.googlepay.GooglePayComponentState @@ -108,12 +110,12 @@ class AdvancedDropInService : DropInService(), LifecycleOwner { override fun onBinLookup(data: List) { lifecycleScope.launch { try { - val platformCommunicationModel = - PlatformCommunicationModel( - PlatformCommunicationType.BINLOOKUP, + val checkoutEvent = + CheckoutEvent( + CheckoutEventType.BIN_LOOKUP, data = data.toJson() ) - DropInPlatformApi.dropInAdvancedPlatformMessageFlow.emit(platformCommunicationModel) + DropInPlatformApi.dropInAdvancedPlatformMessageFlow.emit(checkoutEvent) } catch (exception: Exception) { Log.d(ADYEN_LOG_TAG, "BinLookupData parsing failed: ${exception.message}") } @@ -122,12 +124,12 @@ class AdvancedDropInService : DropInService(), LifecycleOwner { override fun onBinValue(binValue: String) { lifecycleScope.launch { - val platformCommunicationModel = - PlatformCommunicationModel( - PlatformCommunicationType.BINVALUE, + val checkoutEvent = + CheckoutEvent( + CheckoutEventType.BIN_VALUE, data = binValue ) - DropInPlatformApi.dropInAdvancedPlatformMessageFlow.emit(platformCommunicationModel) + DropInPlatformApi.dropInAdvancedPlatformMessageFlow.emit(checkoutEvent) } } diff --git a/android/src/main/kotlin/com/adyen/checkout/flutter/dropIn/session/SessionDropInService.kt b/android/src/main/kotlin/com/adyen/checkout/flutter/dropIn/session/SessionDropInService.kt index 96e9c66e..6d04bbf0 100644 --- a/android/src/main/kotlin/com/adyen/checkout/flutter/dropIn/session/SessionDropInService.kt +++ b/android/src/main/kotlin/com/adyen/checkout/flutter/dropIn/session/SessionDropInService.kt @@ -19,6 +19,8 @@ import com.adyen.checkout.flutter.dropIn.model.DropInStoredPaymentMethodDeletion import com.adyen.checkout.flutter.dropIn.model.DropInType import com.adyen.checkout.flutter.generated.DeletedStoredPaymentMethodResultDTO import com.adyen.checkout.flutter.dropIn.model.toJson +import com.adyen.checkout.flutter.generated.CheckoutEvent +import com.adyen.checkout.flutter.generated.CheckoutEventType import com.adyen.checkout.flutter.utils.Constants.Companion.ADYEN_LOG_TAG import kotlinx.coroutines.launch @@ -43,10 +45,12 @@ class SessionDropInService : SessionDropInService(), LifecycleOwner { lifecycleScope.launch { try { val binLookupDataJson = data.toJson() - val platformCommunicationModel = PlatformCommunicationModel( - PlatformCommunicationType.BINLOOKUP, - binLookupDataJson) - DropInPlatformApi.dropInSessionPlatformMessageFlow.emit(platformCommunicationModel) + val checkoutEvent = + CheckoutEvent( + CheckoutEventType.BIN_LOOKUP, + binLookupDataJson + ) + DropInPlatformApi.dropInSessionPlatformMessageFlow.emit(checkoutEvent) } catch (exception: Exception) { Log.d(ADYEN_LOG_TAG, "BinLookupData parsing failed: ${exception.message}") } @@ -55,7 +59,7 @@ class SessionDropInService : SessionDropInService(), LifecycleOwner { override fun onBinValue(binValue: String) { lifecycleScope.launch { - val platformCommunicationModel = PlatformCommunicationModel(PlatformCommunicationType.BINVALUE, binValue) + val platformCommunicationModel = CheckoutEvent(CheckoutEventType.BIN_VALUE, binValue) DropInPlatformApi.dropInSessionPlatformMessageFlow.emit(platformCommunicationModel) } } diff --git a/android/src/main/kotlin/com/adyen/checkout/flutter/generated/PlatformApi.kt b/android/src/main/kotlin/com/adyen/checkout/flutter/generated/PlatformApi.kt index 22621377..e9d644cb 100644 --- a/android/src/main/kotlin/com/adyen/checkout/flutter/generated/PlatformApi.kt +++ b/android/src/main/kotlin/com/adyen/checkout/flutter/generated/PlatformApi.kt @@ -138,7 +138,9 @@ enum class CheckoutEventType(val raw: Int) { DELETE_STORED_PAYMENT_METHOD(3), BALANCE_CHECK(4), REQUEST_ORDER(5), - CANCEL_ORDER(6); + CANCEL_ORDER(6), + BIN_LOOKUP(7), + BIN_VALUE(8); companion object { fun ofRaw(raw: Int): CheckoutEventType? { diff --git a/example/lib/screens/drop_in/drop_in_screen.dart b/example/lib/screens/drop_in/drop_in_screen.dart index 9ee2b09c..60a18d46 100644 --- a/example/lib/screens/drop_in/drop_in_screen.dart +++ b/example/lib/screens/drop_in/drop_in_screen.dart @@ -53,11 +53,6 @@ class DropInScreen extends StatelessWidget { configuration: dropInConfiguration, ); - sessionCheckout.cardCallbacks = CardCallbacks( - onBinLookup: _onBinLookup, - onBinValue: _onBinValue, - ); - final PaymentResult paymentResult = await AdyenCheckout.session.startDropIn( dropInConfiguration: dropInConfiguration, @@ -84,10 +79,6 @@ class DropInScreen extends StatelessWidget { onRequestOrder: repository.onRequestOrder, onCancelOrder: repository.onCancelOrder, ), - cardCallbacks: CardCallbacks( - onBinLookup: _onBinLookup, - onBinValue: _onBinValue, - ), ); final paymentResult = await AdyenCheckout.advanced.startDropIn( @@ -105,7 +96,12 @@ class DropInScreen extends StatelessWidget { } Future _createDropInConfiguration() async { - const CardConfiguration cardsConfiguration = CardConfiguration(); + CardConfiguration cardsConfiguration = CardConfiguration( + cardCallbacks: CardCallbacks( + onBinLookup: _onBinLookup, + onBinValue: _onBinValue, + ), + ); ApplePayConfiguration applePayConfiguration = ApplePayConfiguration( merchantId: Config.merchantId, diff --git a/ios/Classes/dropIn/DropInPlatformApi.swift b/ios/Classes/dropIn/DropInPlatformApi.swift index dd1e920b..a866dcae 100644 --- a/ios/Classes/dropIn/DropInPlatformApi.swift +++ b/ios/Classes/dropIn/DropInPlatformApi.swift @@ -57,6 +57,7 @@ class DropInPlatformApi: DropInPlatformInterface { ) dropInComponent.delegate = sessionHolder.session dropInComponent.partialPaymentDelegate = sessionHolder.session + dropInComponent.cardComponentDelegate = self if dropInConfigurationDTO.isRemoveStoredPaymentMethodEnabled { dropInComponent.storedPaymentMethodsDelegate = dropInSessionStoredPaymentMethodsDelegate } @@ -375,12 +376,12 @@ extension DropInPlatformApi: PartialPaymentDelegate { } -extension DropInPlatformApi : CardComponentDelegate { +extension DropInPlatformApi: CardComponentDelegate { func didSubmit(lastFour: String, finalBIN: String, component: Adyen.CardComponent) {} func didChangeBIN(_ value: String, component: Adyen.CardComponent) { - let platformCommunicationModel = PlatformCommunicationModel(type: PlatformCommunicationType.binValue, data: value) - dropInFlutterApi.onDropInAdvancedPlatformCommunication(platformCommunicationModel: platformCommunicationModel, completion: { _ in }) + let checkoutEvent = CheckoutEvent(type: CheckoutEventType.binValue, data: value) + checkoutFlutter.send(event: checkoutEvent, completion: { _ in }) } func didChangeCardBrand(_ value: [Adyen.CardBrand]?, component: Adyen.CardComponent) { @@ -396,10 +397,8 @@ extension DropInPlatformApi : CardComponentDelegate { } let data = try JSONSerialization.data(withJSONObject: binLookupDataList, options: []) - let platformCommunicationModel = PlatformCommunicationModel(type: PlatformCommunicationType.binLookup, data: String(data: data, encoding: .utf8)) - dropInFlutterApi.onDropInAdvancedPlatformCommunication(platformCommunicationModel: platformCommunicationModel, completion: { _ in }) - } catch { - - } + let checkoutEvent = CheckoutEvent(type: CheckoutEventType.binLookup, data: String(data: data, encoding: .utf8)) + checkoutFlutter.send(event: checkoutEvent, completion: { _ in }) + } catch {} } } diff --git a/ios/Classes/generated/PlatformApi.swift b/ios/Classes/generated/PlatformApi.swift index 3f97d88e..9df4fcf1 100644 --- a/ios/Classes/generated/PlatformApi.swift +++ b/ios/Classes/generated/PlatformApi.swift @@ -117,6 +117,8 @@ enum CheckoutEventType: Int { case balanceCheck = 4 case requestOrder = 5 case cancelOrder = 6 + case binLookup = 7 + case binValue = 8 } enum ComponentCommunicationType: Int { diff --git a/lib/src/common/model/card_callbacks/card_callbacks.dart b/lib/src/common/model/card_callbacks/card_callbacks.dart index 1e63504c..155487e5 100644 --- a/lib/src/common/model/card_callbacks/card_callbacks.dart +++ b/lib/src/common/model/card_callbacks/card_callbacks.dart @@ -1,11 +1,19 @@ import 'package:adyen_checkout/src/common/model/card_callbacks/bin_lookup_data.dart'; -class CardCallbacks { +abstract class CardCallbacksInterface { void Function(List)? onBinLookup; void Function(String)? onBinValue; +} +class CardCallbacks implements CardCallbacksInterface { CardCallbacks({ this.onBinLookup, this.onBinValue, }); + + @override + void Function(List)? onBinLookup; + + @override + void Function(String)? onBinValue; } diff --git a/lib/src/common/model/checkout.dart b/lib/src/common/model/checkout.dart index e574ccc3..ff2055ae 100644 --- a/lib/src/common/model/checkout.dart +++ b/lib/src/common/model/checkout.dart @@ -1,4 +1,3 @@ -import 'package:adyen_checkout/src/common/model/card_callbacks/card_callbacks.dart'; import 'package:adyen_checkout/src/common/model/partial_payment/partial_payment.dart'; import 'package:adyen_checkout/src/common/model/payment_event.dart'; @@ -8,13 +7,11 @@ class SessionCheckout extends Checkout { final String id; final String sessionData; final Map paymentMethods; - CardCallbacks? cardCallbacks; SessionCheckout({ required this.id, required this.sessionData, required this.paymentMethods, - this.cardCallbacks, }); } @@ -28,12 +25,10 @@ class AdvancedCheckout extends Checkout { onAdditionalDetails; PartialPayment? partialPayment; - CardCallbacks? cardCallbacks; AdvancedCheckout({ required this.onSubmit, required this.onAdditionalDetails, this.partialPayment, - this.cardCallbacks, }); } diff --git a/lib/src/common/model/payment_method_configurations/card_configuration.dart b/lib/src/common/model/payment_method_configurations/card_configuration.dart index f7f9e6df..9ab85595 100644 --- a/lib/src/common/model/payment_method_configurations/card_configuration.dart +++ b/lib/src/common/model/payment_method_configurations/card_configuration.dart @@ -1,4 +1,4 @@ -import 'package:adyen_checkout/src/generated/platform_api.g.dart'; +import 'package:adyen_checkout/adyen_checkout.dart'; class CardConfiguration { final bool holderNameRequired; @@ -9,6 +9,7 @@ class CardConfiguration { final FieldVisibility kcpFieldVisibility; final FieldVisibility socialSecurityNumberFieldVisibility; final List supportedCardTypes; + final CardCallbacksInterface? cardCallbacks; const CardConfiguration({ this.holderNameRequired = false, @@ -19,5 +20,6 @@ class CardConfiguration { this.kcpFieldVisibility = FieldVisibility.hide, this.socialSecurityNumberFieldVisibility = FieldVisibility.hide, this.supportedCardTypes = const [], + this.cardCallbacks, }); } diff --git a/lib/src/drop_in/drop_in.dart b/lib/src/drop_in/drop_in.dart index 70cd092e..a256e96f 100644 --- a/lib/src/drop_in/drop_in.dart +++ b/lib/src/drop_in/drop_in.dart @@ -50,10 +50,10 @@ class DropIn { event, dropInConfiguration.storedPaymentMethodConfiguration, ); - case PlatformCommunicationType.binLookup: - _handleOnBinLookup(event, sessionCheckout.cardCallbacks); - case PlatformCommunicationType.binValue: - _handleOnBinValue(event, sessionCheckout.cardCallbacks); + case CheckoutEventType.binLookup: + _handleOnBinLookup(event, dropInConfiguration.cardConfiguration); + case CheckoutEventType.binValue: + _handleOnBinValue(event, dropInConfiguration.cardConfiguration); default: } }); @@ -127,10 +127,10 @@ class DropIn { _handleOrderRequest(event, advancedCheckout.partialPayment); case CheckoutEventType.cancelOrder: _handleOrderCancel(event, advancedCheckout.partialPayment); - case PlatformCommunicationType.binLookup: - _handleOnBinLookup(event, advancedCheckout.cardCallbacks); - case PlatformCommunicationType.binValue: - _handleOnBinValue(event, advancedCheckout.cardCallbacks); + case CheckoutEventType.binLookup: + _handleOnBinLookup(event, dropInConfiguration.cardConfiguration); + case CheckoutEventType.binValue: + _handleOnBinValue(event, dropInConfiguration.cardConfiguration); } }); @@ -346,15 +346,16 @@ class DropIn { } void _handleOnBinLookup( - PlatformCommunicationModel event, - CardCallbacks? cardCallbacks, + CheckoutEvent event, + CardConfiguration? cardConfiguration, ) { - if (cardCallbacks == null || cardCallbacks.onBinLookup == null) { + if (cardConfiguration?.cardCallbacks == null || + cardConfiguration?.cardCallbacks?.onBinLookup == null) { adyenLogger.print("onBinLookup callback not provided."); return; } - final encodedBinLookupData = event.data; + final encodedBinLookupData = event.data as String?; if (encodedBinLookupData == null) { adyenLogger.print("BinLookup data is null."); return; @@ -364,24 +365,25 @@ class DropIn { final List binLookupDataList = binLookupDataJson .map((entry) => BinLookupData(brand: entry['brand'])) .toList(); - cardCallbacks.onBinLookup?.call(binLookupDataList); + cardConfiguration?.cardCallbacks?.onBinLookup?.call(binLookupDataList); } void _handleOnBinValue( - PlatformCommunicationModel event, - CardCallbacks? cardCallbacks, + CheckoutEvent event, + CardConfiguration? cardConfiguration, ) { - if (cardCallbacks == null || cardCallbacks.onBinValue == null) { + if (cardConfiguration?.cardCallbacks == null || + cardConfiguration?.cardCallbacks?.onBinValue == null) { adyenLogger.print("onBinValue callback not provided."); return; } - final binValue = event.data; + final binValue = event.data as String?; if (binValue == null) { adyenLogger.print("BinValue is null."); return; } - cardCallbacks.onBinValue?.call(binValue); + cardConfiguration?.cardCallbacks?.onBinValue?.call(binValue); } } diff --git a/lib/src/generated/platform_api.g.dart b/lib/src/generated/platform_api.g.dart index d8cbbc51..4c3437bc 100644 --- a/lib/src/generated/platform_api.g.dart +++ b/lib/src/generated/platform_api.g.dart @@ -76,6 +76,8 @@ enum CheckoutEventType { balanceCheck, requestOrder, cancelOrder, + binLookup, + binValue, } enum ComponentCommunicationType {