getPaymentStatus method

Future<QosicStatus?> getPaymentStatus({
  1. required String transactionReference,
  2. required QosicNetwork network,
  3. required QosicCountry country,
})

Get the current status of a transaction given its transaferRef

Implementation

Future<QosicStatus?> getPaymentStatus({
  required String transactionReference,
  required QosicNetwork network,
  required QosicCountry country,
}) async {
  final baseUrl =
      country == QosicCountry.benin ? Endpoints.bjUrl : Endpoints.tgUrl;
  // ignore: omit_local_variable_types
  QosicStatus? status;
  try {
    await dio.post(
      baseUrl + Endpoints.getTransactionsStatus,
      data: {
        'transref': transactionReference,
        'clientid': network == QosicNetwork.mtn ? mtnKey : moovKey
      },
    ).then((value) {
      switch (value.data['responsemsg'] as String) {
        case 'SUCCESSFUL':
          status = QosicStatus.successfull;
          break;
        case 'PENDING':
          status = QosicStatus.pending;
          break;
        case 'FAILED':
          status = QosicStatus.failed;
          break;
        default:
      }
    });
  } on DioError catch (e) {
    if (enableLog) {
      print(
        'An error occured on [getPaymentStatus]: $e}',
      );
    }
    throw QosicException(
      'An error occured on [getPaymentStatus]',
      responseMsg: e.response!.data['responsemsg'] as String,
      data: e,
    );
  }

  return status;
}