verifyStatus method
Future<VerifyTransactionRes?>
verifyStatus({
- required bool isDev,
- required dynamic onError()?,
- required dynamic onSuccess()?,
This function verifies the status of a transaction and returns the status string.
Args: ref (String): The parameter "ref" is a string that represents a reference ID for a transaction that needs to be verified.
Returns: a [Future<String?>[.
Implementation
Future<VerifyTransactionRes?> verifyStatus({
required bool isDev,
required Function(bool, Object)? onError,
required Function(VerifyTransactionRes)? onSuccess,
}) async {
final baseUrl = isDev ? Constants.devURL : Constants.prodURL;
try {
final response = await http.get(
Uri.parse("$baseUrl/$ref/verify"),
headers: {
'Content-Type': ' application/json',
},
);
if (response.statusCode == 200) {
final data = VerifyTransactionRes.fromJson(
jsonDecode(response.body),
);
if (data.data?.status == 'success') {
// isLoading.value = false;
Future.delayed(const Duration(seconds: 2), () {
onSuccess!(data);
});
}
return data;
} else {
onError!(true, response.body);
}
} catch (e) {
onError!(true, e);
} finally {
// isLoading.value = false;
}
return null;
}