capturePayment method
Capture authorized payment
Implementation
Future<MastercardPaymentResponse> capturePayment({
required String orderId,
required String authorizationTransactionId,
required double amount,
String? currency,
}) async {
try {
final transactionId = _uuid.v4();
final requestBody = {
'apiOperation': 'CAPTURE',
'transaction': {
'amount': amount.toString(),
'currency': currency ?? config.currency,
'reference': transactionId,
},
};
final response = await _dio.put(
'/order/$orderId/transaction/$transactionId',
data: requestBody,
);
return MastercardPaymentResponse.fromJson(response.data);
} on DioException catch (e) {
throw MastercardException(
'Capture failed: ${e.message}',
statusCode: e.response?.statusCode,
response: e.response?.data,
);
} catch (e) {
throw MastercardException('Capture failed: $e');
}
}