Flutterwave/Flutter-v3

TransactionError (One or more required parameters missing)

ComputerMaverick69 opened this issue · 3 comments

On using the recently updated version of Flutterwave payment package for flutter flutterwave_standard: ^1.0.4. The above mentioned error message is thrown when you try to proceed to making payments.

Find attached a gif of the event
flutterwave-bug

Find below my code implementation

//Flutterwave payment implementation
  Future<void> _payUsingFlutterwave(
      BuildContext context,
      String currency,
      double amount,
      String email,
      String phone,
      String pkey,
      String skey,
      String enckey,
      String name,
      String ref) async {
    final style = FlutterwaveStyle(
        appBarText: "Add Funds using Flutterwave",
        appBarTitleTextStyle:
            const TextStyle(color: AppStyles.appSecondaryColor),
        buttonColor: AppStyles.appPrimaryColor,
        appBarIcon: const Icon(Icons.arrow_back_ios_new_outlined,
            color: AppStyles.appSecondaryColor),
        buttonTextStyle: TextStyle(
          color: AppStyles.appSecondaryColor,
          fontWeight: FontWeight.bold,
          fontSize: SizeConfig.font15,
        ),
        appBarColor: AppStyles.appPrimaryColor,
        dialogCancelTextStyle: TextStyle(
          color: Colors.redAccent,
          fontSize: SizeConfig.font15,
        ),
        dialogContinueTextStyle: TextStyle(
          color: Colors.blue,
          fontSize: SizeConfig.font15,
        ));
    final Customer customer =
        Customer(name: name, phoneNumber: phone, email: email);

    final Flutterwave flutterwave = Flutterwave(
        context: context,
        style: style,
        publicKey: pkey,
        currency: currency,
        txRef: ref,
        amount: amount.toString(),
        customer: customer,
        paymentOptions: "ussd, card, barter, payattitude",
        customization: Customization(title: "Pay using Flutterwave"),
        isTestMode: true,
        redirectUrl: '');

    final ChargeResponse response = await flutterwave.charge();
    if (response != null) {
      // print("${response.toJson()}");
      if (response.success!) {
        Future<ResponseModel> verifyFunds(String txnId, String token) async {
          late ResponseModel responseModel;
          //var dio = Dio();
          // print(txnId);

          try {
            var response = await Dio().get(
              'https://api.flutterwave.com/v3/transactions/${txnId}/verify',
              options: Options(headers: {
                "Content-Type": "application/json",
                "Authorization": "Bearer ${token}",
              }),
            );

            if (response.statusCode.toString() == '200' ||
                response.statusMessage.toString() == 'OK') {
              responseModel = ResponseModel(true, 'Funds Verified');
            } else {
              responseModel = ResponseModel(false, response.statusMessage!);
            }
            // print(response.statusCode.toString() +
            //     " & " +
            //     responseModel.message.toString() +
            //     " & " +
            //     response.statusMessage!.toString());
          } catch (e) {
            // print(e);
          }
          // print(responseModel.isSuccess.toString());
          return responseModel;
        }

        // Call the verify transaction endpoint with the transactionID returned in `response.transactionId` to verify transaction before offering value to customer
        if (response.status == 'success' && response.success == true) {
          verifyFunds(response.transactionId!, skey).then((status) {
            if (status.isSuccess) {
              var walletReportAddFund =
                  Get.find<WalletTransactionsController>();
              var message = 'Funds added by you with transactionId-' +
                  response.transactionId!.toString();
              double addAmount = amount;
              AddFundsModel addFundsModel =
                  AddFundsModel(message: message, amount: addAmount);
              // print('Transaction Verified!');
              // print(message);
              walletReportAddFund.addFunds(addFundsModel).then((addStatus) {
                if (addStatus.isSuccess) {
                  Get.back();
                  Get.previousRoute == '/addFunds'
                      ? showSuccessSnackBar("Transaction Successful",
                          title: "Add Funds")
                      : showSuccessSnackBar("Transaction Successful",
                          title: "Payment");
                } else {
                  Get.back();
                  Get.previousRoute == '/addFunds'
                      ? showCustomSnackBar("Transaction Report not stored",
                          title: 'Add Funds')
                      : showCustomSnackBar("Transaction Report not stored",
                          title: 'Payments');
                }
              });
            } else {
              // print('Transaction Could not be verified!');
              Get.back();
              Get.previousRoute == '/addFunds'
                  ? showCustomSnackBar("Transaction Couldn't be verified",
                      title: 'Add Funds')
                  : showCustomSnackBar("Transaction Couldn't be verified",
                      title: 'Payments');
            }
          });
        } else {
          Get.back();
          Get.previousRoute == '/addFunds'
              ? showCustomSnackBar("Something went wrong", title: 'Add Funds')
              : showCustomSnackBar("Something went wrong", title: 'Payments');
        }
      } else {
        // Transaction not successful
        Get.previousRoute == '/addFunds'
            ? showCustomSnackBar("Transaction Not Successful",
                title: "Add Funds")
            : showCustomSnackBar("Transaction Not Successful",
                title: "Payments");
        Get.back();
      }
    } else {
      Get.previousRoute == '/addFunds'
          ? showCustomSnackBar("User Cancelled Transaction", title: "Add Funds")
          : showCustomSnackBar("User Cancelled Transaction", title: "Payments");
      Get.back();
    }
  }

Hello @ComputerMaverick69, please check that you passed the redirect_url when calling the Flutterwave instance

@FredDominant I did pass an empty string as the parameter to the 'redirectUrl' field. If you looked at my code you'd have seen it. Is it necessary to pass an actual URL, considering that i only want to handle the post-payment validation on my own. Since I'd have to verify every payment.

@ComputerMaverick69, it is necessary to pass a non-empty string.