getPaymentStatus method

dynamic getPaymentStatus({
  1. required dynamic context,
  2. required String transactionId,
  3. required String merchandUserName,
  4. required String merchandPassword,
  5. required String providerShortTag,
  6. required Function actionAfterProccess,
  7. required String xApiKey,
  8. required String mode,
})

Implementation

getPaymentStatus({
  required context,
  required String transactionId,
  required String merchandUserName,
  required String merchandPassword,
  required String providerShortTag,
  required Function actionAfterProccess,
  required String xApiKey,
  required String mode,
}) async {
  try {
    const time = const Duration(seconds: 4);
    Timer.periodic(time, (Timer timer) async {
      var jsonResponse;
      var url = Uri.parse("${constant.baseUrl}/gateway/paymentstatus/$transactionId");
      log(url.toString());
      var response =
          await http.get(url, headers: getGlobalHeader(xApiKey, "$merchandUserName:$merchandPassword", mode));
      print("This is response status/; ${response.statusCode}");
      print("This is response Mode/; $mode");
      jsonResponse = await jsonDecode(response.body);
      print("This is response status/; $jsonResponse");

      if (jsonResponse['status'] == "SUCCESS") {
        print("Response SUCCESSFUL: $jsonResponse");
        Navigator.pop(context);
        actionAfterProccess(transactionId, "SUCCESS");
        timer.cancel();
      }

      if (jsonResponse['status'] == "FAILED") {
        Navigator.pop(context);
        print("Response FAILED: $jsonResponse");
        actionAfterProccess(transactionId, "FAILED");
        timer.cancel();
      }
    });
  } catch (e) {
    // Navigator.pop(context);
    actionAfterProccess(transactionId, "FAILED");
    showInfoDialog(context, "Something went wrong , please try again or later");
  }
}