Skip to content

Commit

Permalink
Updated latest changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Robert-SD committed Feb 17, 2025
1 parent 4b96619 commit fbdcdb5
Show file tree
Hide file tree
Showing 12 changed files with 75 additions and 61 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ internal class DropInPlatformApi(
private var dropInPlatformMessengerJob: Job? = null

companion object {
val dropInSessionPlatformMessageFlow = MutableSharedFlow<PlatformCommunicationModel>()
val dropInAdvancedPlatformMessageFlow = MutableSharedFlow<PlatformCommunicationModel>()
val dropInSessionPlatformMessageFlow = MutableSharedFlow<CheckoutEvent>()
val dropInAdvancedPlatformMessageFlow = MutableSharedFlow<CheckoutEvent>()
}

override fun showDropInSession(dropInConfigurationDTO: DropInConfigurationDTO) {
Expand All @@ -79,7 +79,7 @@ internal class DropInPlatformApi(
dropInPlatformMessengerJob =
activity.lifecycleScope.launch {
dropInSessionPlatformMessageFlow.collect { platformCommunicationModel ->
dropInFlutterApi.onDropInSessionPlatformCommunication(platformCommunicationModel) {}
checkoutFlutter.send(platformCommunicationModel) {}
}
}

Expand All @@ -106,7 +106,7 @@ internal class DropInPlatformApi(
dropInPlatformMessengerJob =
activity.lifecycleScope.launch {
dropInAdvancedPlatformMessageFlow.collect { platformCommunicationModel ->
dropInFlutterApi.onDropInAdvancedPlatformCommunication(platformCommunicationModel) {}
checkoutFlutter.send(platformCommunicationModel) {}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -108,12 +110,12 @@ class AdvancedDropInService : DropInService(), LifecycleOwner {
override fun onBinLookup(data: List<BinLookupData>) {
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}")
}
Expand All @@ -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)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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}")
}
Expand All @@ -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)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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? {
Expand Down
16 changes: 6 additions & 10 deletions example/lib/screens/drop_in/drop_in_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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(
Expand All @@ -105,7 +96,12 @@ class DropInScreen extends StatelessWidget {
}

Future<DropInConfiguration> _createDropInConfiguration() async {
const CardConfiguration cardsConfiguration = CardConfiguration();
CardConfiguration cardsConfiguration = CardConfiguration(
cardCallbacks: CardCallbacks(
onBinLookup: _onBinLookup,
onBinValue: _onBinValue,
),
);

ApplePayConfiguration applePayConfiguration = ApplePayConfiguration(
merchantId: Config.merchantId,
Expand Down
15 changes: 7 additions & 8 deletions ios/Classes/dropIn/DropInPlatformApi.swift
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ class DropInPlatformApi: DropInPlatformInterface {
)
dropInComponent.delegate = sessionHolder.session
dropInComponent.partialPaymentDelegate = sessionHolder.session
dropInComponent.cardComponentDelegate = self
if dropInConfigurationDTO.isRemoveStoredPaymentMethodEnabled {
dropInComponent.storedPaymentMethodsDelegate = dropInSessionStoredPaymentMethodsDelegate
}
Expand Down Expand Up @@ -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) {
Expand All @@ -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 {}
}
}
2 changes: 2 additions & 0 deletions ios/Classes/generated/PlatformApi.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
10 changes: 9 additions & 1 deletion lib/src/common/model/card_callbacks/card_callbacks.dart
Original file line number Diff line number Diff line change
@@ -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<BinLookupData>)? onBinLookup;
void Function(String)? onBinValue;
}

class CardCallbacks implements CardCallbacksInterface {
CardCallbacks({
this.onBinLookup,
this.onBinValue,
});

@override
void Function(List<BinLookupData>)? onBinLookup;

@override
void Function(String)? onBinValue;
}
5 changes: 0 additions & 5 deletions lib/src/common/model/checkout.dart
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -8,13 +7,11 @@ class SessionCheckout extends Checkout {
final String id;
final String sessionData;
final Map<String, dynamic> paymentMethods;
CardCallbacks? cardCallbacks;

SessionCheckout({
required this.id,
required this.sessionData,
required this.paymentMethods,
this.cardCallbacks,
});
}

Expand All @@ -28,12 +25,10 @@ class AdvancedCheckout extends Checkout {
onAdditionalDetails;

PartialPayment? partialPayment;
CardCallbacks? cardCallbacks;

AdvancedCheckout({
required this.onSubmit,
required this.onAdditionalDetails,
this.partialPayment,
this.cardCallbacks,
});
}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -9,6 +9,7 @@ class CardConfiguration {
final FieldVisibility kcpFieldVisibility;
final FieldVisibility socialSecurityNumberFieldVisibility;
final List<String?> supportedCardTypes;
final CardCallbacksInterface? cardCallbacks;

const CardConfiguration({
this.holderNameRequired = false,
Expand All @@ -19,5 +20,6 @@ class CardConfiguration {
this.kcpFieldVisibility = FieldVisibility.hide,
this.socialSecurityNumberFieldVisibility = FieldVisibility.hide,
this.supportedCardTypes = const [],
this.cardCallbacks,
});
}
38 changes: 20 additions & 18 deletions lib/src/drop_in/drop_in.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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:
}
});
Expand Down Expand Up @@ -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);
}
});

Expand Down Expand Up @@ -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;
Expand All @@ -364,24 +365,25 @@ class DropIn {
final List<BinLookupData> 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);
}
}
2 changes: 2 additions & 0 deletions lib/src/generated/platform_api.g.dart
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ enum CheckoutEventType {
balanceCheck,
requestOrder,
cancelOrder,
binLookup,
binValue,
}

enum ComponentCommunicationType {
Expand Down

0 comments on commit fbdcdb5

Please sign in to comment.