callSubmitCouponApi method

Future<void> callSubmitCouponApi(
  1. String paymentGateWayTransactionId,
  2. String amount
)

Implementation

Future<void> callSubmitCouponApi(
    String paymentGateWayTransactionId, String amount) async {
  BuildContext context = Get.context!;
  var partnerId = SecureStorageService.readSecureData(
        SecureStorageService.partnerIdLogin,
      ) ??
      "";
  var bodyRequest = {
    "paymentGateWayTransactionId": paymentGateWayTransactionId,
    "entityId": partnerId, //dealer Id
  };

  Helper.progressDialog(Get.context!, "");
  String requestTime = "";
  String responseTime = "";
  try {
    await ApiClient(
      baseUrl: ApiConstant.posBFF,
      onFetchRequestTime: (time) {
        requestTime = time;
      },
      onFetchResponseTime: (time) {
        responseTime = time;
      },
      screenName: "stockOrder",
    )
        .getPosSubmitTransaction(
      body: bodyRequest,
      xUserId: SecureStorageService.readSecureData(
        SecureStorageService.xUserId,
      ),
      xUserName: SecureStorageService.readSecureData(
        SecureStorageService.xUserName,
      ),
    )
        .then((response) async {
      SubmitCouponTransactionModel model =
          response; //SubmitCouponTransactionModel.fromJson(submitResponse);

      if (model.status == "POS200") {
        Helper.logEvent(
          "RESPONSE_EVENT",
          success: true,
          endPoint: Api.posCreateTransaction,
          responseDate: responseTime,
          screenName: "stockOrder",
          requestDate: requestTime,
        );
        Helper.close();
        if (model.data != null) {
          var paymentGateWayTransactionId =
              model.data?.paymentGateWayTransactionId ?? "";
          paymentmodestatus = 0;
          Get.to(
            () => WalletSuccessScreen(
              amount: amount.toString(),
              currency: currentWalletCurrency.value,
              transactionId: paymentGateWayTransactionId,
            ),
          );
        }
      } else {
        Helper.close();
        navigateToPaymentPendingSuccess();
      }
      // else {
      //   Helper.close();
      //   Helper.messageDialog(
      //     Get.context!,
      //     model.status ?? localization.translate('tryAgain'),
      //     model.message ?? localization.translate('somethingWrong'),
      //   );
      // }
    }).catchError((error) {
      Helper.close();
      navigateToPaymentPendingSuccess();
      if (error is DioException) {
        UDID.setTraceId(
          error.response?.headers.map[Constants.traceIdKey]?[0] ?? "",
        );
        Helper.logEvent(
          "ERROR_EVENT",
          failure: true,
          requestDate: requestTime,
          endPoint: Api.posCreateTransaction,
          responseDate: DateTime.now().toString(),
          screenName: "stockOrder",
          error: error,
        );
      }
      // Helper.messageDialog(
      //   context,
      //   localization.translate('tryAgain'),
      //   error.toString(),
      // );
    });
  } catch (error, st) {
    Helper.close();
    navigateToPaymentPendingSuccess();
    if (error is DioException) {
      UDID.setTraceId(
        error.response?.headers.map[Constants.traceIdKey]?[0] ?? "",
      );
      Helper.logEvent(
        "ERROR_EVENT",
        failure: true,
        requestDate: requestTime,
        endPoint: Api.posCreateTransaction,
        responseDate: DateTime.now().toString(),
        screenName: "stockOrder",
        error: error,
      );
    }
    print(st);
  }
}