capturePayment method
Captures payment for an order. To successfully capture payment for an order, the buyer must first approve the order or a valid payment_source must be provided in the request. A buyer can approve the order upon being redirected to the rel:approve URL that was returned in the HATEOAS links in the create order response.
Parameter id: The ID of the order for which to authorize.
Parameter paymentSource: The source of payment for the order, which can be a token or a card. Use this object only if you have not redirected the user after order creation to approve the payment. In such cases, the user-selected payment method in the PayPal flow is implicitly used.
Parameter payPalRequestId: The server stores keys for 6 hours. The API callers can request the times to up to 72 hours by speaking to their Account Manager.
Parameter payPalPartnerAttributionId:
Parameter payPalClientMetadataId:
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.
Parameter payPalAuthAssertion: An API-caller-provided JSON Web Token (JWT) assertion that identifies the merchant. For details, see PayPal-Auth-Assertion.
Implementation
Future<Order> capturePayment(
String id, {
PaymentSourceToken? paymentSource,
String? payPalRequestId,
String? payPalAuthAssertion,
String? payPalClientMetadataId,
Prefer? prefer,
}) async {
var uri = _payPalHttpClient.getUrl('/v2/checkout/orders/$id/capture');
var headers = <String, String>{};
if (payPalRequestId != null) {
headers['PayPal-Request-Id'] = payPalRequestId;
}
if (payPalAuthAssertion != null) {
headers['PayPal-Auth-Assertion'] = payPalAuthAssertion;
}
if (payPalClientMetadataId != null) {
headers['PayPal-Client-Metadata-Id'] = payPalClientMetadataId;
}
if (prefer != null) {
headers['Prefer'] = preferTypeEnumMap[prefer]!;
}
var body =
paymentSource != null ? jsonEncode(paymentSource.toJson()) : null;
var response =
await _payPalHttpClient.post(uri, headers: headers, body: body);
return Order.fromJson(jsonDecode(response.body));
}