Skip to content

Commit

Permalink
Moved dropin configuration mapping into dto mapper
Browse files Browse the repository at this point in the history
  • Loading branch information
Robert-SD committed Oct 16, 2023
1 parent 1569dd6 commit 8f0b6ab
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 99 deletions.
11 changes: 9 additions & 2 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,11 @@ class _MyAppState extends State<MyApp> {
final CashAppPayConfiguration cashAppPayConfiguration =
await _createCashAppPayConfiguration();

final ApplePayConfiguration applePayConfiguration = ApplePayConfiguration(
merchantId: Config.merchantAccount,
merchantName: Config.merchantName,
);

final DropInConfiguration dropInConfiguration = DropInConfiguration(
environment: Environment.test,
clientKey: Config.clientKey,
Expand All @@ -115,6 +120,7 @@ class _MyAppState extends State<MyApp> {
cardsConfiguration: cardsConfiguration,
storedPaymentMethodConfiguration: storedPaymentMethodConfiguration,
cashAppPayConfiguration: cashAppPayConfiguration,
applePayConfiguration: applePayConfiguration,
);

return await _adyenCheckout.startPayment(
Expand All @@ -129,8 +135,9 @@ class _MyAppState extends State<MyApp> {
final String paymentMethodsResponse =
await _adyenSessionRepository.fetchPaymentMethods();

final CardsConfiguration cardsConfiguration =
CardsConfiguration(showStorePaymentField: true);
final CardsConfiguration cardsConfiguration = CardsConfiguration(
showStorePaymentField: true,
);

final ApplePayConfiguration applePayConfiguration = ApplePayConfiguration(
merchantId: Config.merchantAccount,
Expand Down
1 change: 1 addition & 0 deletions lib/adyen_checkout.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ export 'src/models/payment_method_configurations/cash_app_pay_configuration.dart
export 'src/models/payment_method_configurations/google_pay_configuration.dart';
export 'src/models/payment_result.dart';
export 'src/models/session.dart';
export 'src/models/stored_payment_method_configuration.dart';
61 changes: 2 additions & 59 deletions lib/src/adyen_checkout.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import 'dart:async';
import 'dart:io';

import 'package:adyen_checkout/adyen_checkout.dart';
import 'package:adyen_checkout/src/adyen_checkout_interface.dart';
Expand Down Expand Up @@ -48,36 +47,9 @@ class AdyenCheckout implements AdyenCheckoutInterface {
DropInSession dropInSession) async {
_adyenLogger.print("Start Drop-in session");
final dropInSessionCompleter = Completer<PaymentResultDTO>();
DropInConfigurationDTO dropInConfiguration = DropInConfigurationDTO(
environment: dropInSession.dropInConfiguration.environment,
clientKey: dropInSession.dropInConfiguration.clientKey,
countryCode: dropInSession.dropInConfiguration.countryCode,
amount: dropInSession.dropInConfiguration.amount.toDTO(),
shopperLocale: dropInSession.dropInConfiguration.shopperLocale ??
Platform.localeName,
cardsConfigurationDTO:
dropInSession.dropInConfiguration.cardsConfiguration?.toDTO(),
applePayConfigurationDTO:
dropInSession.dropInConfiguration.applePayConfiguration?.toDTO(),
googlePayConfigurationDTO:
dropInSession.dropInConfiguration.googlePayConfiguration?.toDTO(),
cashAppPayConfigurationDTO:
dropInSession.dropInConfiguration.cashAppPayConfiguration?.toDTO(),
analyticsOptionsDTO:
dropInSession.dropInConfiguration.analyticsOptions?.toDTO(),
isRemoveStoredPaymentMethodEnabled:
isRemoveStoredPaymentMethodEnabled(dropInSession.dropInConfiguration),
showPreselectedStoredPaymentMethod: dropInSession
.dropInConfiguration
.storedPaymentMethodConfiguration
?.showPreselectedStoredPaymentMethod ??
true,
skipListWhenSinglePaymentMethod:
dropInSession.dropInConfiguration.skipListWhenSinglePaymentMethod,
);
AdyenCheckoutPlatformInterface.instance.startDropInSessionPayment(
session: dropInSession.session.toDTO(),
dropInConfiguration: dropInConfiguration,
dropInConfiguration: dropInSession.dropInConfiguration.toDTO(),
);

_resultApi.dropInSessionPlatformCommunicationStream =
Expand Down Expand Up @@ -124,39 +96,10 @@ class AdyenCheckout implements AdyenCheckoutInterface {
DropInAdvancedFlow dropInAdvancedFlow) async {
_adyenLogger.print("Start Drop-in advanced flow");
final dropInAdvancedFlowCompleter = Completer<PaymentResultDTO>();
DropInConfigurationDTO dropInConfiguration = DropInConfigurationDTO(
environment: dropInAdvancedFlow.dropInConfiguration.environment,
clientKey: dropInAdvancedFlow.dropInConfiguration.clientKey,
countryCode: dropInAdvancedFlow.dropInConfiguration.countryCode,
amount: dropInAdvancedFlow.dropInConfiguration.amount.toDTO(),
shopperLocale: dropInAdvancedFlow.dropInConfiguration.shopperLocale ??
Platform.localeName,
cardsConfigurationDTO:
dropInAdvancedFlow.dropInConfiguration.cardsConfiguration?.toDTO(),
applePayConfigurationDTO:
dropInAdvancedFlow.dropInConfiguration.applePayConfiguration?.toDTO(),
googlePayConfigurationDTO: dropInAdvancedFlow
.dropInConfiguration.googlePayConfiguration
?.toDTO(),
cashAppPayConfigurationDTO: dropInAdvancedFlow
.dropInConfiguration.cashAppPayConfiguration
?.toDTO(),
analyticsOptionsDTO:
dropInAdvancedFlow.dropInConfiguration.analyticsOptions?.toDTO(),
showPreselectedStoredPaymentMethod: dropInAdvancedFlow
.dropInConfiguration
.storedPaymentMethodConfiguration
?.showPreselectedStoredPaymentMethod ??
true,
isRemoveStoredPaymentMethodEnabled: isRemoveStoredPaymentMethodEnabled(
dropInAdvancedFlow.dropInConfiguration),
skipListWhenSinglePaymentMethod: dropInAdvancedFlow
.dropInConfiguration.skipListWhenSinglePaymentMethod,
);

AdyenCheckoutPlatformInterface.instance.startDropInAdvancedFlowPayment(
paymentMethodsResponse: dropInAdvancedFlow.paymentMethodsResponse,
dropInConfiguration: dropInConfiguration,
dropInConfiguration: dropInAdvancedFlow.dropInConfiguration.toDTO(),
);

_resultApi.dropInAdvancedFlowPlatformCommunicationStream =
Expand Down
12 changes: 0 additions & 12 deletions lib/src/models/drop_in_configuration.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,3 @@ class DropInConfiguration {
this.skipListWhenSinglePaymentMethod = false,
});
}

class StoredPaymentMethodConfiguration {
final bool showPreselectedStoredPaymentMethod;
final bool isRemoveStoredPaymentMethodEnabled;
final Future<bool> Function(String)? deleteStoredPaymentMethodCallback;

StoredPaymentMethodConfiguration({
this.showPreselectedStoredPaymentMethod = true,
this.isRemoveStoredPaymentMethodEnabled = false,
this.deleteStoredPaymentMethodCallback,
});
}
11 changes: 11 additions & 0 deletions lib/src/models/stored_payment_method_configuration.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class StoredPaymentMethodConfiguration {
final bool showPreselectedStoredPaymentMethod;
final bool isRemoveStoredPaymentMethodEnabled;
final Future<bool> Function(String)? deleteStoredPaymentMethodCallback;

StoredPaymentMethodConfiguration({
this.showPreselectedStoredPaymentMethod = true,
this.isRemoveStoredPaymentMethodEnabled = false,
this.deleteStoredPaymentMethodCallback,
});
}
56 changes: 30 additions & 26 deletions lib/src/utils/dto_mapper.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'dart:io';

import 'package:adyen_checkout/adyen_checkout.dart';
import 'package:adyen_checkout/src/generated/platform_api.g.dart';
import 'package:adyen_checkout/src/models/analytics_options.dart';
Expand All @@ -9,6 +11,34 @@ extension AnalyticsOptionsMapper on AnalyticsOptions {
);
}

extension DropInConfigurationMapper on DropInConfiguration {
DropInConfigurationDTO toDTO() => DropInConfigurationDTO(
environment: environment,
clientKey: clientKey,
countryCode: countryCode.toUpperCase(),
amount: amount.toDTO(),
shopperLocale: shopperLocale ?? Platform.localeName,
cardsConfigurationDTO: cardsConfiguration?.toDTO(),
applePayConfigurationDTO: applePayConfiguration?.toDTO(),
googlePayConfigurationDTO: googlePayConfiguration?.toDTO(),
cashAppPayConfigurationDTO: cashAppPayConfiguration?.toDTO(),
analyticsOptionsDTO: analyticsOptions?.toDTO(),
isRemoveStoredPaymentMethodEnabled: _isRemoveStoredPaymentMethodEnabled(
storedPaymentMethodConfiguration),
showPreselectedStoredPaymentMethod: storedPaymentMethodConfiguration
?.showPreselectedStoredPaymentMethod ??
true,
skipListWhenSinglePaymentMethod: skipListWhenSinglePaymentMethod,
);

bool _isRemoveStoredPaymentMethodEnabled(
StoredPaymentMethodConfiguration? storedPaymentMethodConfiguration) =>
storedPaymentMethodConfiguration?.deleteStoredPaymentMethodCallback !=
null &&
storedPaymentMethodConfiguration?.isRemoveStoredPaymentMethodEnabled ==
true;
}

extension CardsConfigurationMapper on CardsConfiguration {
CardsConfigurationDTO toDTO() => CardsConfigurationDTO(
holderNameRequired: holderNameRequired,
Expand Down Expand Up @@ -75,29 +105,3 @@ extension OrderResponseMapper on OrderResponseDTO {
orderData: orderData,
);
}

extension CardsConfigurationDTOCopy on CardsConfigurationDTO {
CardsConfigurationDTO copyWith({
bool? holderNameRequired,
AddressMode? addressMode,
bool? showStorePaymentField,
bool? showCvcForStoredCard,
bool? showCvc,
FieldVisibility? kcpFieldVisibility,
FieldVisibility? socialSecurityNumberFieldVisibility,
List<String?>? supportedCardTypes,
}) =>
CardsConfigurationDTO(
holderNameRequired: holderNameRequired ?? this.holderNameRequired,
addressMode: addressMode ?? this.addressMode,
showStorePaymentField:
showStorePaymentField ?? this.showStorePaymentField,
showCvcForStoredCard: showCvcForStoredCard ?? this.showCvcForStoredCard,
showCvc: showCvc ?? this.showCvc,
kcpFieldVisibility: kcpFieldVisibility ?? this.kcpFieldVisibility,
socialSecurityNumberFieldVisibility:
socialSecurityNumberFieldVisibility ??
this.socialSecurityNumberFieldVisibility,
supportedCardTypes: supportedCardTypes ?? this.supportedCardTypes,
);
}

0 comments on commit 8f0b6ab

Please sign in to comment.