handleBackApiResponse method

void handleBackApiResponse(
  1. PaymentStatusResponseModel? model, {
  2. bool isClickPaymentContinue = false,
  3. bool isClickBack = false,
})

Implementation

void handleBackApiResponse(PaymentStatusResponseModel? model,
    {bool isClickPaymentContinue = false, bool isClickBack = false}) {
  if (model == null) {
    print('No response from API');
    return;
  }
  BuildContext context = Get.context!;

  try {
    isLoadingMore.value = true;

    if (model.status == "POS200") {
      // paymentResponse = model;
      paymentTransactionId.value = model.data!.transactionId.toString();
      actionType.value = model.data!.merchantId.toString();
      customerID.value = model.data!.customerId.toString();
      var status = model.data?.status ?? "";
      if (status == paymentStatusName) {
        paymentStatus.value = "SUCCESS";
        stopApiPolling();
        // stopScreenTime();
        if (paymentmodestatus == 2) {
          Helper.close();
        } else if (paymentmodestatus == 1) {
          cashPayment(
            context,
            "",
            cart_id.toString(),
            sellThruOrder.value.totalAmountPaid.toString(),
            sellThruOrder.value.localCurrencyGrandTotal.toString(),
            isCashOnDelivery: true,
          );
        }
      } else if (disableCancelButton(status)) {
        //== "FAILURE"
        stopApiPolling();
        // stopScreenTime();
        // errorMessage.value = model.data?.errorMessage ?? "";
        paymentStatus.value = status;
        if (paymentmodestatus == 2) {
          Helper.close();
          goToPaymentPendingSuccessScreen();
        } else if (paymentmodestatus == 1) {
          // showPaymentFailedAlert();
          // Deep link
          goToPaymentPendingSuccessScreen();
        }
      } else if (status.trim().toUpperCase() == "PENDING") {
        //PENDING
        paymentStatus.value = status;
        if (paymentmodestatus == 2) {
          paymentScreenType.value = "Web";
          //Condition based on continue payment alert
          if (isClickPaymentContinue == false && isClickBack == true) {
            stopApiPolling();
            showDialogForPaymentAlert();
          }
        }
      } else {
        //OTHER
        stopApiPolling();
        // stopScreenTime();
        paymentStatus.value = status;
        if (paymentmodestatus == 2) {
          paymentScreenType.value = "Web";
          Helper.close();
          goToPaymentPendingSuccessScreen();
        } else if (paymentmodestatus == 1) {
          // Deep link
          goToPaymentPendingSuccessScreen();
        }
      }
    } else {
      stopApiPolling();
      //  stopScreenTime();
      if (paymentmodestatus == 2) {
        Helper.close();
        goToPaymentPendingSuccessScreen();
      } else if (paymentmodestatus == 1) {
        // Deep link
        goToPaymentPendingSuccessScreen();
      }
    }
  } catch (e) {
    stopApiPolling();
    //stopScreenTime();
    if (paymentmodestatus == 2) {
      Helper.close();
      goToPaymentPendingSuccessScreen();
    } else if (paymentmodestatus == 1) {
      // Deep link
      goToPaymentPendingSuccessScreen();
    }
    // paymentStatus.value = "Failure";
    print('Error handling response: $e');
  }
}