doPayment static method
Function to initiate the web checkout flow.
Implementation
static Future<Map<dynamic, dynamic>?> doPayment(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) {
MethodChannel channel = const MethodChannel('cashfree_pg');
response = channel.invokeMethod(
'doPayment', inputs);
return response;
} else {
/// 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.invokeMethod('doPayment', inputs);
} else {
response = _failureResponse('Invalid channel');
}
return response;
}
}