captureAuthorizedPayment method
Future<Capture>
captureAuthorizedPayment(
- String authorizationId,
- CaptureRequest request, {
- String? payPalRequestId,
- Prefer? prefer,
Captures an authorized payment, by ID.
Parameter authorizationId: The PayPal-generated ID for the authorized payment to capture.
Parameter request: Capture request details
Parameter payPalRequestId: The server stores keys for 45 days.
Parameter prefer: 'minimal', The server returns a minimal response to optimize communication between the API caller and the server. A minimal response includes the id, status and HATEOAS links. 'representation', The server returns a complete resource representation, including the current state of the resource.
Implementation
Future<Capture> captureAuthorizedPayment(
String authorizationId,
CaptureRequest request, {
String? payPalRequestId,
Prefer? prefer,
}) async {
var url = _payPalHttpClient.getUrl(
'/v2/payments/authorizations/$authorizationId/capture',
);
Map<String, String> headers = {};
if (prefer != null) {
headers['Prefer'] = preferTypeEnumMap[prefer]!;
}
if (payPalRequestId != null) {
headers['PayPal-Request-Id'] = payPalRequestId;
}
var body = jsonEncode(request.toJson());
var response =
await _payPalHttpClient.post(url, headers: headers, body: body);
return Capture.fromJson(jsonDecode(response.body));
}