registerStateEffect method

  1. @override
void registerStateEffect(
  1. BuildContext currentContext
)
override

Implementation

@override
void registerStateEffect(BuildContext currentContext) {
  // final arg = Get.arguments;
  // if (arg is PaymentMethodArg) {
  //   args = arg;
  //   _controller.checkout = arg.checkout;
  // }

  ever(_controller.ccState, (ViewData<CheckoutPayment> state) {
    ObserverState(
      state: state,
      onLoading: () {
        Get.dialog(
          barrierDismissible: false,
          PopScope(canPop: false, child: AppLoading()),
        );
      },
      onError: (message, error) {
        Get.back();
        goodieErrorCallback(
          msg: message,
          errorPage: ErrorPaymentTemplates.checkout,
          callback: (error) {
            if (onError != null) {
              onError!(error);
            } else {
              showDTSnackBarError(currentContext, error);
            }
          },
        );
      },
      onLoaded: (data) async {
        Get.back();
        if (state.data?.checkoutUrl.isNotEmpty != true) {
          if (onError != null) {
            onError!("failed_get_url".tl);
          } else {
            showDTSnackBarError(currentContext, "failed_get_url".tl);
          }
          return;
        }

        PurchasePaymentMethod paymentMethod = PurchasePaymentMethod.instant;
        if (data.reqChannelCode.toLowerCase().contains("deb")) {
          paymentMethod = PurchasePaymentMethod.debit;
        } else if (data.reqChannelCode.toLowerCase().contains("cc")) {
          paymentMethod = PurchasePaymentMethod.cc;
        }
        if (onProcess != null) {
          onProcess?.call(data.copyWith(type: PaymentPageType.webview));
        } else {
          Get.toNamed(
            IncommeConstants.appRoute.purchaseWebview,
            arguments: PurchaseWebArgs(
              url: Uri.tryParse(state.data?.checkoutUrl ?? ""),
              onPaymentProcessCompleted: onCompleted,
              callBackRouteName: callBackRouteName,
              // returnUrl: Uri.parse(state.data?.parameter.returnUrl ?? ""),
              method: paymentMethod,
              orderGroupID: state.data?.parameter.merchantTranId ?? "",
              model: data,
              onResultPaymentClosePressed: onResultPaymentClosePressed,
              onRetryPaymentPressed: onRetryPaymentPressed,
              onChangePaymentPressed: onChangePaymentPressed,
            ),
          );
        }
        // if (result is bool && result == true) {
        //   final email = data.parameter.custEmail.isEmpty
        //       ? data.parameter.customerEmail
        //       : data.parameter.custEmail;
        //   Get.toNamed(
        //     IncommeConstants.appRoute.purchaseResult,
        //     arguments: PurchaseResultArgs(
        //       orderGroupId: orderGroupID,
        //       // fromCheckout: false,
        //       // paymentZero:
        //       //     (int.tryParse(
        //       //           _controller.viewState.value.data?.totalPrice ?? "",
        //       //         ) ??
        //       //         0) ==
        //       //     0,
        //       onClosePressed: onResultPaymentClosePressed,
        //       onRetryPaymentPressed: onRetryPaymentPressed,
        //       email: email,
        //       onChangePaymentPressed: onChangePaymentPressed,
        //     ),
        //   );
        // }
      },
    );
  }).addTo(disposables);

  ever(_controller.viewState, (ViewData<SortedPaymentMethod> state) {
    ObserverState(
      state: state,
      onError: (message, error) {
        showDTSnackBarError(currentContext, state.message);
      },
      // onLoaded: (data) {
      //   if ((int.tryParse(data.totalPrice) ?? 0) == 0) {
      //     onProcess?.call(CheckoutPayment());
      //     Get.toNamed(
      //       IncommeConstants.appRoute.purchaseResult,
      //       arguments: PurchaseResultArgs(
      //         orderGroupId: orderGroupID,
      //         // fromCheckout: false,
      //         paymentZero: true,
      //         onClosePressed: onResultPaymentClosePressed,
      //         onRetryPaymentPressed: onRetryPaymentPressed,
      //       ),
      //     );
      //   }
      // },
    );
  }).addTo(disposables);

  ever(_controller.vaState, (ViewData<CheckoutPayment> state) {
    ObserverState(
      state: state,
      onLoading: () {
        Get.dialog(
          barrierDismissible: false,
          const PopScope(canPop: false, child: PackageCircullar()),
        );
      },
      onError: (message, error) {
        Get.back();
        if (onError != null) {
          onError!(message);
        } else {
          goodieErrorCallback(
            msg: message,
            errorPage: ErrorPaymentTemplates.checkout,
            callback: (error) {
              showDTSnackBarError(currentContext, error);
            },
          );
        }
      },
      onLoaded: (CheckoutPayment data) {
        Get.back();
        if (onProcess != null) {
          onProcess!(data.copyWith(type: PaymentPageType.va));
        } else {
          Get.toNamed(
            IncommeConstants.appRoute.purchaseDetail,
            arguments: PaymentVaArg(
              orderGroupID: orderGroupID,
              paymentResult: data,
              onPaymentFailed: onError,
              callBackRouteName: callBackRouteName,
              onPaymentProcessCompleted: onCompleted,
              onResultPaymentClosePressed: onResultPaymentClosePressed,
              onRetryPaymentPressed: onRetryPaymentPressed,
            ),
          );
        }
      },
    );
  }).addTo(disposables);

  ever(_controller.qrisState, (ViewData<CheckoutPayment> state) {
    ObserverState(
      state: state,
      onLoading: () {
        Get.dialog(
          barrierDismissible: false,
          const PopScope(canPop: false, child: PackageCircullar()),
        );
      },
      onError: (message, error) {
        Get.back();

        Get.back();
        if (onError != null) {
          onError!(message);
        } else {
          goodieErrorCallback(
            msg: message,
            errorPage: ErrorPaymentTemplates.checkout,
            callback: (error) {
              showDTSnackBarError(currentContext, error);
            },
          );
        }
      },
      onLoaded: (CheckoutPayment data) async {
        Get.back();
        if (onProcess != null) {
          onProcess!(data.copyWith(type: PaymentPageType.qr));
        } else {
          Get.toNamed(
            IncommeConstants.appRoute.purchaseQr,
            arguments: PurchaseQrArg(
              // totalPay: data.parameter.doubleAmount,
              // orderLists: _controller.checkout.orderLists,
              // priceDetail: _controller.checkout.priceDetail,
              // totalPointValued: usePoint?.toDouble() ?? 0,
              // totalPointValued: 0,
              callBackRouteName: callBackRouteName,
              checkoutPayment: data,
              orderGroupID: data.parameter.merchantTranId,
              onResultPaymentClosePressed: onResultPaymentClosePressed,
              onRetryPaymentPressed: onRetryPaymentPressed,
              onPaymentProcessCompleted: onCompleted,
            ),
          );
        }
        // if (result is bool && result == true) {
        //   // _controller.reload(orderGroupID);
        //   final email = data.parameter.custEmail.isEmpty
        //       ? data.parameter.customerEmail
        //       : data.parameter.custEmail;
        //   Get.toNamed(
        //     IncommeConstants.appRoute.purchaseResult,
        //     arguments: PurchaseResultArgs(
        //       orderGroupId: orderGroupID,
        //       // paymentZero:
        //       //     (int.tryParse(
        //       //           _controller.viewState.value.data?.totalPrice ?? "",
        //       //         ) ??
        //       //         0) ==
        //       //     0,
        //       onClosePressed: onResultPaymentClosePressed,
        //       onRetryPaymentPressed: onRetryPaymentPressed,
        //       email: email,
        //       onChangePaymentPressed: onChangePaymentPressed,
        //     ),
        //   );
        // }
      },
    );
  }).addTo(disposables);

  ever(_controller.inPersonState, (ViewData<CheckoutPayment> state) {
    ObserverState(
      state: state,
      onLoading: () {
        Get.dialog(
          barrierDismissible: false,
          const PopScope(canPop: false, child: PackageCircullar()),
        );
      },
      onError: (message, error) {
        Get.back();
        if (onError != null) {
          onError!(message);
        } else {
          goodieErrorCallback(
            msg: message,
            errorPage: ErrorPaymentTemplates.checkout,
            callback: (error) {
              showDTSnackBarError(currentContext, error);
            },
          );
        }
      },
      onLoaded: (CheckoutPayment data) {
        final email =
            data.parameter.custEmail.isEmpty
                ? data.parameter.customerEmail
                : data.parameter.custEmail;
        Get.back();
        if (onProcess != null) {
          onProcess!(data.copyWith(type: PaymentPageType.complete));
        } else if (onCompleted != null) {
          onCompleted!(
            IncommePaymentStatus(orderGroupId: orderGroupID, email: email),
          );
        } else {
          Get.toNamed(
            IncommeConstants.appRoute.purchaseResult,
            arguments: PurchaseResultArgs(
              callBackRouteName: callBackRouteName,
              orderGroupId: orderGroupID,
              sequenceRouteChangePayment: 1,
              // paymentZero:
              //     (int.tryParse(
              //           _controller.viewState.value.data?.totalPrice ?? "",
              //         ) ??
              //         0) ==
              //     0,
              onClosePressed: onResultPaymentClosePressed,
              onRetryPaymentPressed: onRetryPaymentPressed,
              email: email,
              onChangePaymentPressed: onChangePaymentPressed,
            ),
          );
        }
      },
    );
  }).addTo(disposables);

  super.registerStateEffect(currentContext);
}