doUPIPayment static method

Future<Map?> doUPIPayment(
  1. Map<String, dynamic> inputs
)

Function to initiate UPI Intent

Implementation

static Future<Map<dynamic, dynamic>?> doUPIPayment(Map<String, dynamic> inputs) async {
  Future<Map<dynamic, dynamic>?> response;
  for (String element in _required) {
    if (!inputs.containsKey(element) || inputs[element].toString().isEmpty) {
      return _failureResponse(element + " not provided");
    }
  }

  if(kIsWeb) {
    return _failureResponse("This method does not exist for web platform");
  }
  /// The below checks if there is any pending responses that has to be sent back to the user from the previous transaction
  /// This uses orderId to match the response
  MethodChannel previousResponseChannel = const MethodChannel('cashfree_pg');
  var previousResponse = await previousResponseChannel.invokeMethod('getPendingResponse');
  if(previousResponse != null && previousResponse["orderId"] == inputs["orderId"]) {
    var completer = new Completer<Map<dynamic, dynamic>>();
    completer.complete(previousResponse);
    return completer.future;
  }

  /// The below code establishes a channel to communicate with the native layer for payment invocation
  MethodChannel channel = const MethodChannel('cashfree_pg');
  // ignore: unnecessary_null_comparison
  if(channel != null) {
    response = channel.invokeMapMethod("doUPIPayment", inputs);
  } else {
    response = _failureResponse("Invalid Channel");
  }
  return response;
}