processPayment method
Future<LokotroPayOnResponse>
processPayment({
- required MastercardPaymentRequest paymentRequest,
- required String userId,
- String? sessionToken,
Process payment through secure backend
Implementation
Future<LokotroPayOnResponse> processPayment({
required MastercardPaymentRequest paymentRequest,
required String userId,
String? sessionToken,
}) async {
try {
final requestBody = {
'payment_request': paymentRequest.toJson(),
'user_id': userId,
'session_token': sessionToken,
'require_3ds': paymentRequest.require3DS,
'client_info': await _getClientInfo(),
};
final response = await _dio.post(
'/api/v1/payments/mastercard/process',
data: requestBody,
);
return _convertBackendResponse(response.data);
} on DioException catch (e) {
return _handleBackendError(e, paymentRequest);
} catch (e) {
return LokotroPayOnResponse(
title: 'System Error',
message: 'Payment processing failed: $e',
paymentStatus: LokotroPaymentStatus.failed,
apiResponseCode: LokotroPayApiResponseCode.lok007,
amount: paymentRequest.amount,
currency: paymentRequest.currency,
systemRef: DateTime.now().millisecondsSinceEpoch.toString(),
customRef: paymentRequest.orderId,
timestamp: DateTime.now(),
transactionId: null,
);
}
}