capture method

Future<Response<RazorpayPayment>> capture({
  1. required String paymentId,
  2. required dynamic amount,
  3. required String currency,
  4. void callback(
    1. RazorpayApiException?,
    2. Response<RazorpayPayment>?
    )?,
})

Capture payment

@param paymentId - The unique identifier of the payment. @param amount - The amount to be captured (should be equal to the authorised amount, in the smallest unit of the chosen currency). @param currency - ISO code of the currency in which the payment was made.

Implementation

Future<Response<RazorpayPayment>> capture({
  required String paymentId,
  required dynamic amount, // number | string
  required String currency,
  void Function(RazorpayApiException?, Response<RazorpayPayment>?)? callback,
}) async {
  if (paymentId.isEmpty) {
    throw ArgumentError(ID_REQUIRED_MSG);
  }
  // Amount validation happens implicitly via model or API

  final payload = {
    'amount': amount,
    'currency': currency,
  };

  return api.post<RazorpayPayment>(
    {
      'url': '$BASE_URL/$paymentId/capture',
      'data': payload,
    },
    fromJsonFactory: RazorpayPayment.fromJson,
    callback: callback,
  );
}