doPayment method

dynamic doPayment(
  1. CFPayment cfPayment
)

Implementation

doPayment(CFPayment cfPayment) {
  if(verifyPayment == null || onError == null) {
    throw CFException(CFExceptionConstants.CALLBACK_NOT_SET);
  }

  CFDropCheckoutPayment dropCheckoutPayment = cfPayment as CFDropCheckoutPayment;
  var data = _convertToMap(dropCheckoutPayment);

  // Create Method channel here
  MethodChannel methodChannel = const MethodChannel('flutter_cashfree_pg_sdk');
  methodChannel.invokeMethod("doPayment", data).then((value) {
    if(value != null) {
      final body = json.decode(value);
      var status = body["status"] as String;
      switch (status) {
        case "exception":
          var data = body["data"] as Map<String, dynamic>;
          _createErrorResponse(data["message"] as String, null, null, null);
          break;
        case "success":
          var data = body["data"] as Map<String, dynamic>;
          verifyPayment!(data["order_id"] as String);
          break;
        case "failed":
          var data = body["data"] as Map<String, dynamic>;
          var errorResponse = CFErrorResponse(
              data["status"] as String, data["message"] as String,
              data["code"] as String, data["type"] as String);
          onError!(errorResponse, data["order_id"] as String);
          break;
      }
    }
  });
}