refundCapturedPayment method

Future<Refund> refundCapturedPayment(
  1. String captureId,
  2. RefundRequest request, {
  3. String? payPalRequestId,
  4. String? payPalAuthAssertion,
})

Refunds a captured payment, by ID. For a full refund, include an empty payload in the JSON request body. For a partial refund, include an amount object in the JSON request body.

Parameter captureId: The PayPal-generated ID for the captured payment to refund.

Parameter request: The refund request details

Parameter payPalRequestId: The server stores keys for 45 days.

Parameter payPalAuthAssertion: An API-caller-provided JSON Web Token (JWT) assertion that identifies the merchant. For details, see PayPal-Auth-Assertion.

Note:For three party transactions in which a partner is managing the API calls on behalf of a merchant, the partner must identify the merchant using either a PayPal-Auth-Assertion header or an access token with target_subject.

Implementation

Future<Refund> refundCapturedPayment(String captureId, RefundRequest request,
    {String? payPalRequestId, String? payPalAuthAssertion}) async {
  var url = _payPalHttpClient.getUrl(
    '/v2/payments/captures/$captureId/refund',
  );

  Map<String, String> headers = {};

  if (payPalAuthAssertion != null) {
    headers['PayPal-Auth-Assertion'] = payPalAuthAssertion;
  }

  if (payPalRequestId != null) {
    headers['PayPal-Request-Id'] = payPalRequestId;
  }

  var body = jsonEncode(request.toJson());
  var response =
      await _payPalHttpClient.post(url, headers: headers, body: body);
  return Refund.fromJson(jsonDecode(response.body));
}