Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upon calling the api, I get no response. #5

Open
waldokhalid opened this issue Mar 30, 2023 · 1 comment
Open

Upon calling the api, I get no response. #5

waldokhalid opened this issue Mar 30, 2023 · 1 comment

Comments

@waldokhalid
Copy link

Method:

  Future mPesaPaymentInAction() async {
    dynamic resultss;
    print("mpesa in action!");
    try {
      Mpesa mpesa = Mpesa(
        clientKey: myClientKey, //
        clientSecret: myClientSecret, //
        passKey: myPassKey, //
        environment: myEnvironment, //
      );

      try {
        print("BEFORE mpesa in action!");
        print(
            "phoneNumberForPayment: ${phoneNumberForPayment.text.toString()}");
        await mpesa.lipaNaMpesa(
          amount: 1.0, //
          phoneNumber: phoneNumberForPayment.text.toString(), //
          businessShortCode: myBusinessShortCode, //
          transactionDescription: transactionDescription,
          callbackUrl: callBackUrl, //
        )
            .then((result) async {
          print(result);

          // Let user know to be ready to enter mpesa pin
          ScaffoldMessenger.of(context).showSnackBar(SnackBar(
            duration: const Duration(seconds: 5),
            backgroundColor: Colors.greenAccent,
            content: Text(
              "Mpesa Pin request sent by Safaricom, Please wait.",
              textAlign: TextAlign.center,
              style: GoogleFonts.lato(
                fontSize: 14,
              ),
            ),
          ));
          // Check api response for positive response
          if (result.ResponseCode.toString() == "0" &&
              result.CustomerMessage.toString() ==
                  "Success. Request accepted for processing" &&
              result.ResponseDescription ==
                  "Success. Request accepted for processing") {
            // If api response positive store transaction
            await storeTransactionsInDB(result.CheckoutRequestID.toString());
            //:
            //:
            print("mpesa done!");
            print(result.CheckoutRequestID);
            print(result.MerchantRequestID);
            print("mpesa done!");
            print("mpesa done!");
            print("mpesa done!");
          } else {
            // Else throw error
            throw Error();
          }
        }).catchError((error) {
          print("MyError: $resultss");
          setState(() {
            loadingScreen = false;
          });
        });
      } catch (e) {
        print("GOT THE ERROR: ${e.toString()}");
        print("RESULT: ${resultss}");
      }
      // await freeMemoryAfterPay();
    } catch (e) {
      ScaffoldMessenger.of(context).showSnackBar(SnackBar(
        duration: const Duration(seconds: 5),
        backgroundColor: Colors.redAccent,
        content: Text(
          "Please try again.",
          textAlign: TextAlign.center,
          style: GoogleFonts.lato(
            fontSize: 14,
          ),
        ),
      ));
      if (kDebugMode) {
        print("Was inside mpesa in action:- ${e.toString()}");
      }
    }
  }

output:


I/flutter (16242): mpesa in action!   
I/flutter (16242): BEFORE mpesa in action!
I/flutter (16242): phoneNumberForPayment: <my number was here>
I/flutter (16242): MyError: null 

This worked up until this morning. I have to say this is my first time working with the mpesa api, so I'm still learning.
Any chance you could help out with this issue?

@newtonmunene99
Copy link
Owner

Hi @waldokhalid , due to time restrictions and other obligations, I am no longer able to maintain this package. The Mpesa API has also changed significantly. I would not advise you to keep using this package. I am currently looking for a maintainer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants