fetch method

Future<Response<RazorpayToken>> fetch({
  1. required String tokenId,
  2. void callback(
    1. RazorpayApiException?,
    2. Response<RazorpayToken>?
    )?,
})

Fetch card properties of an existing token (Token HQ)

@param tokenId - The ID of the token to fetch.

Implementation

Future<Response<RazorpayToken>> fetch({
  required String tokenId,
  void Function(RazorpayApiException?, Response<RazorpayToken>?)? callback,
}) async {
  if (tokenId.isEmpty) {
    throw ArgumentError('tokenId is required');
  }
  // Note: JS uses POST for fetch, which is unusual. Following JS implementation.
  return api.post<RazorpayToken>(
    {
      'url': '$BASE_URL/fetch',
      'data': {'id': tokenId}, // Pass ID in the body
    },
    fromJsonFactory: RazorpayToken.fromJson,
    callback: callback,
  );
}