processPaymentWith3DS method
Future<LokotroPayOnResponse>
processPaymentWith3DS({
- required MastercardPaymentRequest paymentRequest,
Process payment with 3DS authentication
Implementation
Future<LokotroPayOnResponse> processPaymentWith3DS({
required MastercardPaymentRequest paymentRequest,
}) async {
if (!isInitialized) {
return _createErrorResponse(
'Service not initialized',
'Please initialize the service first',
paymentRequest.amount,
paymentRequest.currency,
paymentRequest.orderId,
);
}
try {
// Step 1: Initiate 3DS authentication
final authResponse = await _backendProxy!.initiate3DSAuthentication(
orderId: paymentRequest.orderId,
amount: paymentRequest.amount,
currency: paymentRequest.currency,
userId: _currentUserId!,
sessionToken: _currentSessionToken,
);
// Step 2: Handle 3DS redirect if required
if (authResponse['requires_redirect'] == true) {
// In a real implementation, you would show a WebView
// For now, simulate successful authentication
final authId = authResponse['authentication_id'] as String;
// Wait for authentication completion
await Future.delayed(const Duration(seconds: 2));
// Complete authentication
return await _backendProxy!.complete3DSAuthentication(
authenticationId: authId,
paRes: 'simulated_pa_res', // This would come from WebView
userId: _currentUserId!,
sessionToken: _currentSessionToken,
);
}
// Step 3: Process payment directly if no 3DS required
return await processPayment(paymentRequest: paymentRequest);
} catch (e) {
return _createErrorResponse(
'3DS Authentication Error',
'Failed to process 3DS payment: $e',
paymentRequest.amount,
paymentRequest.currency,
paymentRequest.orderId,
);
}
}