payWithMobileMoney method

Future<ChargeResponse> payWithMobileMoney(
  1. MobileMoneyRequest mobileMoneyRequest,
  2. Client client
)

Initiates payments via Mobile Money returns an instance of ChargeResponse or throws an error

Implementation

Future<ChargeResponse> payWithMobileMoney(
    MobileMoneyRequest mobileMoneyRequest, http.Client client) async {
  final requestBody = mobileMoneyRequest.toJson();

  final url = FlutterwaveURLS.getBaseUrl(this.isDebugMode) +
      FlutterwaveURLS.getMobileMoneyUrl(this.currency);
  final uri = Uri.parse(url);
  try {
    final http.Response response = await client.post(uri,
        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()));
  }
}