postFormData<T> method
Future<Response<T> >
postFormData<T>(
- Map<
String, dynamic> params, { - required FromJsonFactory<
T> fromJsonFactory, - required FormData formData,
- void callback(
- RazorpayApiException?,
- Response<
T> ?
Implementation
Future<Response<T>> postFormData<T>(
Map<String, dynamic> params, {
required FromJsonFactory<T> fromJsonFactory,
required FormData formData, // Pass FormData directly
void Function(RazorpayApiException?, Response<T>?)? callback,
}) async {
try {
final rawResponse = await client.post<Map<String, dynamic>>(
getEntityUrl(params),
data: formData, // Use the provided FormData
options: Options(
contentType: 'multipart/form-data', // Ensure correct content type
),
);
if (rawResponse.data == null) {
throw StateError(
'API response data was null for POST (FormData) request to ${getEntityUrl(params)}',
);
}
final resultData = fromJsonFactory(rawResponse.data!);
final typedResponse = Response<T>(
data: resultData,
requestOptions: rawResponse.requestOptions,
statusCode: rawResponse.statusCode,
statusMessage: rawResponse.statusMessage,
isRedirect: rawResponse.isRedirect,
redirects: rawResponse.redirects,
extra: rawResponse.extra,
headers: rawResponse.headers,
);
callback?.call(null, typedResponse);
return typedResponse;
} on DioException catch (error) {
final normalizedError = _normalizeError(error);
callback?.call(normalizedError, null);
throw normalizedError;
} catch (error) {
final exception =
RazorpayApiException(message: 'An unexpected error occurred: $error');
callback?.call(exception, null);
throw exception;
}
}