newtonmunene99 / mpesa-dart

A dart wrapper around mpesa daraja api
https://pub.dev/packages/mpesa
MIT License
21 stars 15 forks source link

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

Open waldokhalid opened 1 year ago

waldokhalid commented 1 year ago

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 commented 1 year ago

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.