doPayment method

dynamic doPayment(
  1. CFPayment cfPayment
)

Implementation

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

  Map<String, dynamic> data = <String, dynamic>{};

  if(cfPayment is CFCardPayment) {
    CFCardPayment cfCardPayment = cfPayment;
    _initiateCardPayment(cfCardPayment);
  } else {
    if (cfPayment is CFDropCheckoutPayment) {
      CFDropCheckoutPayment dropCheckoutPayment = cfPayment;
      data = _convertToMap(dropCheckoutPayment);
    } else if (cfPayment is CFWebCheckoutPayment) {
      CFWebCheckoutPayment webCheckoutPayment = cfPayment;
      data = _convertToWebCheckoutMap(webCheckoutPayment);
    } else if(cfPayment is CFUPIPayment) {
      CFUPIPayment cfupiPayment = cfPayment;
      data = _convertToUPItMap(cfupiPayment);
    } else if (cfPayment is CFNetbankingPayment) {
      CFNetbankingPayment cfNetbankingPayment = cfPayment;
      data = _convertToNetbankingMap(cfNetbankingPayment);
    }

    // Create Method channel here
    MethodChannel methodChannel = const MethodChannel(
        'flutter_cashfree_pg_sdk');
    if (cfPayment is CFDropCheckoutPayment) {
      methodChannel.invokeMethod("doPayment", data).then((value) {
        responseMethod(value);
      });
    } else if (cfPayment is CFWebCheckoutPayment) {
      methodChannel.invokeMethod("doWebPayment", data).then((value) {
        responseMethod(value);
      });
    } else if(cfPayment is CFUPIPayment) {
      if(cfPayment.getUPI().getChannel() == CFUPIChannel.INTENT_WITH_UI) {
        methodChannel.invokeMethod("doUPIPaymentWithUI", data).then((value) {
          responseMethod(value);
        });
      } else {
        methodChannel.invokeMethod("doUPIPayment", data).then((value) {
          responseMethod(value);
        });
      }
    } else if (cfPayment is CFNetbankingPayment) {
      methodChannel.invokeMethod("doNetbankingPayment", data).then((value) {
        responseMethod(value);
      });
    }
  }
}