verifyStatus method

Future<VerifyTransactionRes?> verifyStatus({
  1. required bool isDev,
  2. required dynamic onError(
    1. bool,
    2. Object
    )?,
  3. required dynamic onSuccess(
    1. VerifyTransactionRes
    )?,
})

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;
}