initPayment method

Future<ESewaResult> initPayment({
  1. required ESewaPayment payment,
})

This method will take user to the eSewa payment activity and returns Future<ESewaResult> once user is back to app.

It takes ESewaPayment as argument.

Implementation

Future<ESewaResult> initPayment({required ESewaPayment payment}) async {
  Map<String, dynamic> arguments = {
    "config": _eSewaConfiguration.toMap(),
    "payment": payment.toMap()
  };

  final response = await _channel.invokeMethod('initPayment', arguments);

  Map<String, dynamic> responseMap = Map<String, dynamic>.from(response);
  if (!responseMap["isSuccess"]) {
    throw ESewaPaymentException(message: responseMap["message"]);
  } else {
    if (Platform.isAndroid) {
      return ESewaResult.fromMap(json.decode(responseMap["message"]));
    } else {
      Map<String, dynamic> resp =
          Map<String, dynamic>.from(responseMap["message"]);
      return ESewaResult.fromMap(resp);
    }
  }
}