processPayment method
Process payment with selected method via the real payment API.
Implementation
Future<void> processPayment({
required String paymentMethodId,
required Map<String, dynamic> paymentData,
}) async {
try {
setLoading(true);
navigateToScreen(LokotroPayScreenNavigation.processingScreen);
final response = await _httpClient.post<LokotroPayResponse>(
LokotroPayEnv.buildProcessPaymentUrl(),
data: {
'payment_method_id': paymentMethodId,
...paymentData,
},
parser: (data) => LokotroPayResponse.fromJson(data),
);
if (response.isSuccess && response.data != null) {
final paymentResponse = response.data!;
if (paymentResponse.isSuccess) {
setSuccessMessage(
'Payment completed successfully!',
title: 'Payment Successful',
);
navigateToScreen(LokotroPayScreenNavigation.successScreen);
} else {
_handleApiError(response.message);
}
} else {
_handleApiError(response.message);
}
} catch (e) {
_handleError(e);
} finally {
setLoading(false);
}
}