payWithUSSD method

Future<ChargeResponse> payWithUSSD(
  1. USSDRequest ussdRequest,
  2. Client client
)

Initiates payments via USSD Available for only payments with NGN currency returns an instance of ChargeResponse or throws an error

Implementation

Future<ChargeResponse> payWithUSSD(
    USSDRequest ussdRequest, http.Client client) async {
  final requestBody = ussdRequest.toJson();
  final url =
      FlutterwaveURLS.getBaseUrl(isDebugMode) + FlutterwaveURLS.PAY_WITH_USSD;
  try {
    final http.Response response = await client.post(Uri.parse(url),
        headers: {
          HttpHeaders.authorizationHeader: this.publicKey,
          HttpHeaders.contentTypeHeader: "application/json"
        },
        body: jsonEncode(requestBody));

    ChargeResponse chargeResponse =
        ChargeResponse.fromJson(json.decode(response.body));
    return chargeResponse;
  } catch (error) {
    throw (FlutterError(error.toString()));
  } finally {
    client.close();
  }
}