vkammerer / ussd_service

A Flutter plugin to make USSD requests
https://pub.dev/packages/ussd_service
BSD 2-Clause "Simplified" License
21 stars 14 forks source link

Can't execute USSD #15

Closed bouarmodskip closed 2 years ago

bouarmodskip commented 2 years ago

Hello I am using your package to send my ussd codes. I am having problems whether it is in the emulator and also with the mobile. Emulator: I get this: ussd_plugin_ussd_response_failed - messege PlatformException (ussd_plugin_ussd_response_failed, USSD_RETURN_FAILURE, null)). Mobile: I get this error: unsupported value '[Ljava.lan.StakTraceElement; @ 6cf835f' of type 'class [Ljava.lan.StakTraceElement;'

vkammerer commented 2 years ago

Regarding the emulator, it is expected that you get this error since it doesn't simulate a Cellular connection. Regarding the other error, It would be better if you gave more details of how / when you are getting it.

bouarmodskip commented 2 years ago

Thank you for your prompt feedback. Yes I understand for the emulator, that's why I had to build my apk to test with a real mobile operator. For the second error I didn't log more on it but I got it when I invoke the makeRequest method that makes an exception. Sorry this is my first flutter app and I'm not comfortable with all of it. Here is the example of the ussd code that my client gave me and that I was using in my code: #145#1300058963214125436.

I continued on my side to test other scenarios by putting my ussd code between code_ussd# => #145#1300058963214125436#. With that I get a message of hope. I will build my app(APK) with this configuration and inform you about the rest.

vkammerer commented 2 years ago

Hello, sorry but it's still unclear to me what your code really does. Could you paste here your dart code? thanks

bouarmodskip commented 2 years ago

My dart code send an ussd code to order mobile money. Here's my dart code: RequestState _requestState; String _responseCode = ""; String _responseMessage = ""; setState(() { _requestState = RequestState.Onegoing; }); PermissionStatus perStat = await Permission.phone.status; if (!(perStat.isGranted)) await Permission.phone.request();
String responseMessage; SimData simData = await SimDataPlugin.getSimData(); if (simData == null) { throw Exception("Donnée da la carte sim est null"); } print(task.patern); //print => #145#1300058963214125436 responseMessage = await UssdService.makeRequest( simData.cards.first.subscriptionId, "${task.patern}#", Duration(seconds: 30), ); print("meg " + responseMessage);

vkammerer commented 2 years ago

sorry but your code is not legible. Could you format it (running dart format .) and then repost it under a code block (using "```dart" as first line and "```" as last line)?

bouarmodskip commented 2 years ago
String _responseCode = "";
String _responseMessage = "";
setState(() {
  _requestState = RequestState.Onegoing;
});
PermissionStatus perStat = await Permission.phone.status;
if (!(perStat.isGranted)) await Permission.phone.request();        
String responseMessage;
SimData simData = await SimDataPlugin.getSimData();
if (simData == null) {
  throw Exception("Donnée da la carte sim est null");
}
print(task.patern); //print => #145#13000589632141*25436
responseMessage = await UssdService.makeRequest(
  simData.cards.first.subscriptionId,
  "*${task.patern}#",
  Duration(seconds: 30),
);
print("meg " + responseMessage);
vkammerer commented 2 years ago

one thing I notice in your code samples is that the String you pass as code always has a part of it in italic . Is it just when you copy paste?

bouarmodskip commented 2 years ago

This's all code of my method:


Future<void> sendUssdRequest() async {
    if (form.validate()) {
      form.save();
        PermissionStatus perStat = await Permission.phone.status;
        var permission;
        if (!(perStat.isGranted)) await Permission.phone.request();
        //2 j'invoke l'API USSD
        String responseMessage;
        SimData simData = await SimDataPlugin.getSimData();
        if (simData == null) {
          throw Exception("Donnée da la carte sim est null");
        }
        print(task.patern);
        responseMessage = await UssdService.makeRequest(
          simData.cards.first.subscriptionId,
          "*${task.patern}#",
          Duration(seconds: 30),
        );
        print("meg " + responseMessage);
        setState(() {
          form.reset();
          _requestState = RequestState.Success;
          _responseMessage = responseMessage;
          form.reset();
          _phoneController.text = "";
          _montantController.text = "";
          selectedValue = "";
        });
        //await UpdateTask(task.id, 3);
      } catch (e) {
        print(e);
      }
    }
  }
vkammerer commented 2 years ago

ok, I don't see any obvious bug in your code. Have you tried passing a hardcoded code to UssdService.makeRequest, just to make sure your "*${task.patern}#" doesn't include any unsupported symbol?

bouarmodskip commented 2 years ago

I made the application by my client. It seems to confirm that it works well. I can take it that the problem is resolved. Thank you for your help

Nivekiba commented 1 year ago

I have a question, does it only works with pattern *code# ? What about this pattern #code#