From 1e4def165e240718e818b360cfb450c7c5c508cd Mon Sep 17 00:00:00 2001 From: Robert Schulze Dieckhoff Date: Wed, 5 Mar 2025 09:20:34 +0100 Subject: [PATCH] Added early return for binLookup and binValue --- lib/src/drop_in/drop_in.dart | 36 ++++++++++++++++++++++++++++-------- 1 file changed, 28 insertions(+), 8 deletions(-) diff --git a/lib/src/drop_in/drop_in.dart b/lib/src/drop_in/drop_in.dart index 48302622..bd89810f 100644 --- a/lib/src/drop_in/drop_in.dart +++ b/lib/src/drop_in/drop_in.dart @@ -51,9 +51,15 @@ class DropIn { dropInConfiguration.storedPaymentMethodConfiguration, ); case CheckoutEventType.binLookup: - _handleOnBinLookup(event, dropInConfiguration.cardConfiguration); + _handleOnBinLookup( + event, + dropInConfiguration.cardConfiguration?.cardCallbacks?.onBinLookup, + ); case CheckoutEventType.binValue: - _handleOnBinValue(event, dropInConfiguration.cardConfiguration); + _handleOnBinValue( + event, + dropInConfiguration.cardConfiguration?.cardCallbacks?.onBinValue, + ); default: } }); @@ -128,9 +134,15 @@ class DropIn { case CheckoutEventType.cancelOrder: _handleOrderCancel(event, advancedCheckout.partialPayment); case CheckoutEventType.binLookup: - _handleOnBinLookup(event, dropInConfiguration.cardConfiguration); + _handleOnBinLookup( + event, + dropInConfiguration.cardConfiguration?.cardCallbacks?.onBinLookup, + ); case CheckoutEventType.binValue: - _handleOnBinValue(event, dropInConfiguration.cardConfiguration); + _handleOnBinValue( + event, + dropInConfiguration.cardConfiguration?.cardCallbacks?.onBinValue, + ); } }); @@ -347,23 +359,31 @@ class DropIn { void _handleOnBinLookup( CheckoutEvent event, - CardConfiguration? cardConfiguration, + Function? binLookupCallback, ) { + if (binLookupCallback == null) { + return; + } + if (event.data case List binLookupDataDTOList) { final List binLookupDataList = binLookupDataDTOList .whereType() .map((entry) => BinLookupData(brand: entry.brand)) .toList(); - cardConfiguration?.cardCallbacks?.onBinLookup?.call(binLookupDataList); + binLookupCallback.call(binLookupDataList); } } void _handleOnBinValue( CheckoutEvent event, - CardConfiguration? cardConfiguration, + Function? binValueCallback, ) { + if (binValueCallback == null) { + return; + } + if (event.data case String binValue) { - cardConfiguration?.cardCallbacks?.onBinValue?.call(binValue); + binValueCallback.call(binValue); } } }