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

PlatformException(ussd_plugin_ussd_execution_failure, USSD_RETURN_FAILURE, null, null) using ussd_service #18

Closed ALI-SAMPSON closed 11 months ago

ALI-SAMPSON commented 11 months ago

I created a prototype to test out how the ussd_service works but it keeps throwing an error: PlatformException(ussd_plugin_ussd_execution_failure, USSD_RETURN_FAILURE, null, null)


// I'm requesting phone permission with this code which works well.
requestPermission() async {
   var status = await Permission.phone.status;
   if (status.isDenied) {
     // We didn't ask for permission yet or the permission has been denied before but not permanently.
     await Permission.phone.request();
   }
   if (await Permission.phone.isRestricted) {
   // The OS restricts access, for example because of parental controls.
   await Permission.phone.request();
   }
   makeRequest();
} 

// initiate ussd request
void makeRequest() async {
   String code = '*920*331#';
   SimData simData = await SimDataPlugin.getSimData();
   var subscriptionId = simData.cards.last.subscriptionId;
   print(simData.cards.last.subscriptionId);
   print(code);

   try {
      String ussdRespMessege = await UssdService.makeRequest(
          subscriptionId, code, const Duration(minutes: 1));
      print('Succes! messege: $ussdRespMessege');
    } catch (err) {
      print('Error: ${err.toString()}');
    }
}
vkammerer commented 11 months ago

The plugin only delegates to Android's sendUssdRequest method, so if you get that error back, it's because Android returns that response. It means the parameters you pass to UssdService.makeRequest trigger that error. Maybe the subscriptionId?

ALI-SAMPSON commented 11 months ago

The plugin only delegates to Android's sendUssdRequest method, so if you get that error back, it's because Android returns that response. It means the parameters you pass to UssdService.makeRequest trigger that error. Maybe the subscriptionId?

Well, I followed their documentation and used a subscription Id of 1 but I still get that same error.

vkammerer commented 11 months ago

their documentation

not sure whose documentation you're referring to.

Again, this plugin is only a wrapper, if you get this response back, it means your parameters are properly passed to Android, so the resolution to your issue doesn't depend on this Flutter plugin.

ALI-SAMPSON commented 11 months ago

their documentation

not sure whose documentation you're referring to.

Again, this plugin is only a wrapper, if you get this response back, it means your parameters are properly passed to Android, so the resolution to your issue doesn't depend on this Flutter plugin.

I meant the ussd_service plugin on pub.dev.

Ok, thank you, sir, but what would you suggest I do?

vkammerer commented 11 months ago

Do you have a dual sim phone? if yes, make sure the code is executing on the right sim card?

vkammerer commented 11 months ago

You can also try with another more common USSD code to see if it works.

ALI-SAMPSON commented 11 months ago

Do you have a dual sim phone? if yes, make sure the code is executing on the right sim card?

Yes, I use a dual sim phone and I am executing it on the first sim, sim one.

ALI-SAMPSON commented 11 months ago

You can also try with another more common USSD code to see if it works.

Great, I'll try that and let you know, but in the meantime, I want to know if I can pass a JSON body to the plugin to execute alongside the ussd code I send.