statusCheker method

void statusCheker()

This function handles all the logic behind listening to the addresses for payment progress. A payment can either be: In progress, error, canceled, timeout or success.

Implementation

void statusCheker() {
  timer = Timer.periodic(const Duration(seconds: 30), (timerConst) async {
    await _serviceController.getPaymentDetails(_serviceController.paymentID);

    if (_selectCurrencyController.getStatus() == 'success') {
      Get.offAll(() => const PaymentResponse(message: 'success'));
      //In future upgrades/refactoring, this is where you check if the callback function is null before
      //proceeding to the PaymentResponseScreen.

      timer.cancel();

      debugPrint('This payment was successful! ');
    } else if (_selectCurrencyController.getStatus() == 'error' ||
        countDownValue == 0) {
      //Use Get.off to avoid memory leakage
      Get.offAll(() => const PaymentResponse(message: 'error'));
      Get.snackbar('Payment failed', 'This payment failed due to an error');

      // GlobalizerController.paymentConfig!.callback!(
      //     200,
      //     'payment failed',
      //     'This Payment failed because the time expired or it was cancelled',
      //     Status.error);

      ///runcall back function
      debugPrint(
          'This Payment failed because the time expired or it was cancelled');
      Get.snackbar('Payment failed', 'Time Expired');
      timer.cancel();
    } else if (_selectCurrencyController.getStatus() == 'cancelled') {
      //Use Get.off to avoid memory leakage
      Get.offAll(() => const PaymentResponse(message: 'cancelled'));
      // Get.snackbar('Payment Cancelled', 'This payment was cancelled');

      // GlobalizerController.paymentConfig!.callback(200, 'payment cancelled',
      //     'This payment was cancelled', Status.cancelled);

      ///runcall back function
      debugPrint('This Payment failed because it was Cancelled/cancelled.');
      timer.cancel();
    } else if (_selectCurrencyController.getStatus() == 'in progress') {
      //do nothing
      // debugPrint('This is a periodic ');
    }
  });
}