Skip to content

Commit

Permalink
Merge pull request #76 from Adyen/feature/alignConfigurationForDropIn
Browse files Browse the repository at this point in the history
Moved drop-in configuration to a separate parameter
  • Loading branch information
Robert-SD authored Dec 13, 2023
2 parents 7b139ae + 1eb8e14 commit 87e5367
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 15 deletions.
4 changes: 2 additions & 2 deletions example/lib/screens/drop_in/drop_in_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ class _DropInScreenState extends State<DropInScreen> {
);

final PaymentResult paymentResult = await widget.adyenCheckout.startPayment(
dropInConfiguration: dropInConfiguration,
paymentFlow: DropInSessionFlow(
dropInConfiguration: dropInConfiguration,
session: session,
),
);
Expand All @@ -73,8 +73,8 @@ class _DropInScreenState extends State<DropInScreen> {
final dropInConfiguration = await _createDropInConfiguration();

final paymentResult = await widget.adyenCheckout.startPayment(
dropInConfiguration: dropInConfiguration,
paymentFlow: DropInAdvancedFlow(
dropInConfiguration: dropInConfiguration,
paymentMethodsResponse: paymentMethodsResponse,
postPayments: widget.repository.postPayments,
postPaymentsDetails: widget.repository.postPaymentsDetails,
Expand Down
6 changes: 5 additions & 1 deletion lib/src/adyen_checkout.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,13 @@ class AdyenCheckout implements AdyenCheckoutInterface {

@override
Future<PaymentResult> startPayment({
required DropInConfiguration dropInConfiguration,
required DropInPaymentFlow paymentFlow,
}) async =>
_dropIn.startPayment(paymentFlow: paymentFlow);
_dropIn.startPayment(
dropInConfiguration: dropInConfiguration,
paymentFlow: paymentFlow,
);

@override
void enableConsoleLogging({required bool enabled}) {
Expand Down
5 changes: 4 additions & 1 deletion lib/src/adyen_checkout_interface.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ abstract class AdyenCheckoutInterface {
required BaseConfiguration configuration,
});

Future<PaymentResult> startPayment({required DropInPaymentFlow paymentFlow});
Future<PaymentResult> startPayment({
required DropInConfiguration dropInConfiguration,
required DropInPaymentFlow paymentFlow,
});

void enableConsoleLogging({required bool enabled});
}
22 changes: 15 additions & 7 deletions lib/src/drop_in/drop_in.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,25 @@ class DropIn {
final DropInPlatformApi dropInPlatformApi;

Future<PaymentResult> startPayment({
required DropInConfiguration dropInConfiguration,
required DropInPaymentFlow paymentFlow,
}) async {
switch (paymentFlow) {
case DropInSessionFlow():
return await _startDropInSessionsPayment(paymentFlow);
return await _startDropInSessionsPayment(
dropInConfiguration,
paymentFlow,
);
case DropInAdvancedFlow():
return await _startDropInAdvancedFlowPayment(paymentFlow);
return await _startDropInAdvancedFlowPayment(
dropInConfiguration,
paymentFlow,
);
}
}

Future<PaymentResult> _startDropInSessionsPayment(
DropInConfiguration dropInConfiguration,
DropInSessionFlow dropInSession,
) async {
adyenLogger.print("Start Drop-in session");
Expand All @@ -47,7 +55,7 @@ class DropIn {
await sdkVersionNumberProvider.getSdkVersionNumber();

dropInPlatformApi.startDropInSessionPayment(
dropInSession.dropInConfiguration.toDTO(sdkVersionNumber),
dropInConfiguration.toDTO(sdkVersionNumber),
dropInSession.session.toDTO(),
);

Expand All @@ -62,7 +70,7 @@ class DropIn {
case PlatformCommunicationType.deleteStoredPaymentMethod:
_onDeleteStoredPaymentMethodCallback(
event,
dropInSession.dropInConfiguration.storedPaymentMethodConfiguration,
dropInConfiguration.storedPaymentMethodConfiguration,
);
default:
}
Expand Down Expand Up @@ -92,6 +100,7 @@ class DropIn {
}

Future<PaymentResult> _startDropInAdvancedFlowPayment(
DropInConfiguration dropInConfiguration,
DropInAdvancedFlow dropInAdvancedFlow,
) async {
adyenLogger.print("Start Drop-in advanced flow");
Expand All @@ -100,7 +109,7 @@ class DropIn {
await sdkVersionNumberProvider.getSdkVersionNumber();

dropInPlatformApi.startDropInAdvancedFlowPayment(
dropInAdvancedFlow.dropInConfiguration.toDTO(sdkVersionNumber),
dropInConfiguration.toDTO(sdkVersionNumber),
dropInAdvancedFlow.paymentMethodsResponse,
);

Expand All @@ -120,8 +129,7 @@ class DropIn {
case PlatformCommunicationType.deleteStoredPaymentMethod:
_onDeleteStoredPaymentMethodCallback(
event,
dropInAdvancedFlow
.dropInConfiguration.storedPaymentMethodConfiguration,
dropInConfiguration.storedPaymentMethodConfiguration,
);
}
});
Expand Down
4 changes: 0 additions & 4 deletions lib/src/drop_in/models/drop_in_payment_flow.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,20 @@ import 'package:adyen_checkout/adyen_checkout.dart';
sealed class DropInPaymentFlow {}

class DropInSessionFlow extends DropInPaymentFlow {
final DropInConfiguration dropInConfiguration;
final Session session;

DropInSessionFlow({
required this.dropInConfiguration,
required this.session,
});
}

class DropInAdvancedFlow extends DropInPaymentFlow {
final DropInConfiguration dropInConfiguration;
final String paymentMethodsResponse;
Future<PaymentFlowOutcome> Function(String paymentComponentJson) postPayments;
Future<PaymentFlowOutcome> Function(String additionalDetailsJson)
postPaymentsDetails;

DropInAdvancedFlow({
required this.dropInConfiguration,
required this.paymentMethodsResponse,
required this.postPayments,
required this.postPaymentsDetails,
Expand Down

0 comments on commit 87e5367

Please sign in to comment.