callPaymentTransactionStatusApi method

Future<void> callPaymentTransactionStatusApi(
  1. String transaction,
  2. bool externalCheckRequried,
  3. bool isDiscard, {
  4. bool isClickBack = false,
  5. bool isClickPaymentContinue = false,
  6. bool isFromDeepLink = false,
})

Implementation

Future<void> callPaymentTransactionStatusApi(
  String transaction,
  bool externalCheckRequried,
  bool isDiscard, {
  bool isClickBack = false,
  bool isClickPaymentContinue = false,
  bool isFromDeepLink = false,
}) async {
  _isApiResponsePending = true;
  String requestTime = "";
  String responseTime = "";
  try {
    if (isClickBack || isClickPaymentContinue || isFromDeepLink) {
      Helper.progressDialog(Get.context!, "");
    }
    // Perform API call
    final response = await ApiClient(
            baseUrl: ApiConstant.posBFF,
            onFetchRequestTime: (time) {
              requestTime = time;
            },
            onFetchResponseTime: (time) {
              responseTime = time;
            },
            screenName: "stockOrder")
        .getPaymentGatewayTransactionStatus(
      transaction: transaction,
      externalCheckRequried: externalCheckRequried,
      isDiscard:
          false, // making it false to avoid discarding payment, confirmed with BL
    );
    // Handle the response and update UI
    _isApiResponsePending = false;
    Helper.logEvent(
      "RESPONSE_EVENT",
      success: true,
      endPoint: "${Api.paymentGatewayTransactionStatus}/$transaction/status",
      responseDate: responseTime,
      screenName: "stockOrder",
      requestDate: requestTime,
    );

    if (externalCheckRequried == true || isClickBack == true) {
      handleBackApiResponse(
        response,
        isClickPaymentContinue: isClickPaymentContinue,
        isClickBack: isClickBack,
      );
    } else {
      handleApiResponse(response);
    }
    if (isClickBack || isClickPaymentContinue || isFromDeepLink) {
      Helper.close();
    }
  } catch (error) {
    if (isClickBack || isClickPaymentContinue || isFromDeepLink) {
      Helper.close();
    }
    if (error is DioException) {
      UDID.setTraceId(
        error.response?.headers.map[Constants.traceIdKey]?[0] ?? "",
      );
      Helper.logEvent(
        "ERROR_EVENT",
        failure: true,
        requestDate: requestTime,
        endPoint:
            "${Api.paymentGatewayTransactionStatus}/$transaction/status",
        responseDate: DateTime.now().toString(),
        screenName: "stockOrder",
        error: error,
      );
    }
    if (_isTimerExpired) {
      stopApiPolling();
      // stopScreenTime();
      Helper.close();
    }
  }
}