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 {
    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) {
          // callSubmitCouponApi(paymentCreateTransactionId.value,
          //     selectedAmount.value.toString());
          // 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();
        } else if (paymentmodestatus == 1) {
          // showPaymentFailedAlert();
        }
      } else if (status.trim().toUpperCase() == "PENDING" ||
          status.trim().toUpperCase() == "INITIATED") {
        //PENDING
        paymentStatus.value = status;
        if (paymentmodestatus == 2) {
          paymentScreenType.value = "Web";
          //Condition based on continue payment alert
          if (isClickBack == true) {
            stopApiPolling();
            showDialogForPaymentAlert();
          }
        }
      } else {
        //OTHER
        stopApiPolling();
        // stopScreenTime();
        paymentStatus.value = status;
        if (paymentmodestatus == 2) {
          paymentScreenType.value = "Web";
          Helper.close();
        } else if (paymentmodestatus == 1) {
          // showPaymentFailedAlert();
        }
      }
    } else {
      stopApiPolling();
      //  stopScreenTime();
      if (paymentmodestatus == 2) {
        Helper.close();
      } else if (paymentmodestatus == 1) {
        // showPaymentFailedAlert();
      }
    }
  } catch (e) {
    stopApiPolling();
    //stopScreenTime();
    if (paymentmodestatus == 2) {
      Helper.close();
    } else if (paymentmodestatus == 1) {
      // showPaymentFailedAlert();
    }
    // paymentStatus.value = "Failure";
    print('Error handling response: $e');
  }
}