callDiscountCartApi method

Future<void> callDiscountCartApi(
  1. String cartDiscountId
)

Implementation

Future<void> callDiscountCartApi(String cartDiscountId) async {
  BuildContext context = Get.context!;
  Helper.progressDialog(context, "Please wait..");
  var body = {"cartDiscountId": cartDiscountId};
  String requestTime = "";
  String responseTime = "";
  await ApiClient(
    baseUrl: ApiConstant.posBL,
    onFetchRequestTime: (time) {
      requestTime = time;
    },
    onFetchResponseTime: (time) {
      responseTime = time;
    },
    screenName: "scan",
  )
      .discountCart(
    cartDiscountId: body,
    cartId: cartId,
    xRoles: SecureStorageService.readSecureData(
      SecureStorageService.xUserId,
    ),
    xUserId: SecureStorageService.readSecureData(
      SecureStorageService.xUserId,
    ),
  )
      .then((response) {
    Helper.close();
    Helper.logEvent(
      "RESPONSE_EVENT",
      success: true,
      endPoint: "${Api.addToCart}/$cartId",
      responseDate: responseTime,
      screenName: "scan",
      requestDate: requestTime,
      transactionId: cartId,
    );
    cart.CartModel model = response;
    if (model.status == "POS200") {
      discountId.value = cartDiscountId;
      cartId = model.data!.cartId!;
      if (currentScan == ScanType.spotSellThru) {
        updateSpotSellThruOrder(model);
      }
    } else {
      if (model.errors != null) {
        Helper.messageDialog(
            Get.context!,
            model.errors![0].code ?? "Try again!!",
            model.errors![0].localeMessage ?? "Something went wrong");
      }
    }
  }).catchError((error) {
    ConditionalLogs().customLog("$error");
    Helper.close();
    MainController mainController = Get.put(MainController());
    mainController.showErrorPopup();
  });
}