79471924

Date: 2025-02-27 07:55:59
Score: 2
Natty:
Report link

You can update the code as follows to prevents the payment screen opening multiple times. Please let me know if this works.

bool _isPaymentProcessing = false;

void openCheckout(int varTotalValue, String? razorpayOrderId) async {
  if (_isPaymentProcessing) return; // Prevent multiple triggers
  _isPaymentProcessing = true; // Set flag early

  try {
    String varUserLoginValue =
        await Utils().funcGetSession(ConstantSession.KeyUserLoginValue);
    log("varTotalValue ==: $varTotalValue");

    bool isUserLoggedInThroughEmailId =
        Validations.isValidEmail(varUserLoginValue);
    String emailId = _userController.userResponseModel.data?.email ?? varUserLoginValue;
    String name = _userController.userResponseModel.data?.firstName ?? varUserLoginValue;
    String contactNo = _userController.userResponseModel.data?.contactNo ?? varUserLoginValue;

    var options = {
      'key': varWebRazorPayKey,
      'amount': ((varTotalValue) * 100).toInt(),
      'send_sms_hash': true,
      'name': name.capitalizeFirstofEach,
      'description': '',
      'order_id': razorpayOrderId,
      'theme': {'color': '#FFC300'},
      'prefill': {'contact': contactNo, 'email': emailId},
      "notify": {"sms": true, "email": true},
    };

    _razorpay?.open(options);
    log('_razorpayPayments');
  } catch (e) {
    debugPrint('Error: $e');
    _isPaymentProcessing = false; // Reset flag if Razorpay fails
  }
}

// Reset flag in event handlers
void _handlePaymentSuccess(PaymentSuccessResponse response) {
  log("Payment Successful: ${response.paymentId}");
  _isPaymentProcessing = false;
}

void _handlePaymentError(PaymentFailureResponse response) {
  log("Payment Failed: ${response.message}");
  _isPaymentProcessing = false;
}

void _handleExternalWallet(ExternalWalletResponse response) {
  log("External Wallet Selected: ${response.walletName}");
  _isPaymentProcessing = false;
}

Key Fixes in This Code

Reasons:
  • RegEx Blacklisted phrase (2.5): Please let me know
  • Long answer (-1):
  • Has code block (-0.5):
  • Low reputation (1):
Posted by: Jeban_antony