doPayment method

void doPayment(
  1. dynamic arguments
)

WEB

Implementation

void doPayment(dynamic arguments) async {
  var window = html.window;
  var document = window.document;

  window.onHashChange.first.then((value) {
    _userCancelledTransaction();
  });

  var session = arguments["session"] as dynamic;
  var orderId = session["order_id"] as String;
  _order_id = orderId;


  /// Adding this outer div for opaque background
  DivElement outerDiv = DivElement();
  outerDiv.id = "cf-outer-div";
  outerDiv.style.position = "fixed";
  outerDiv.style.width = "100%";
  outerDiv.style.height = "100%";
  outerDiv.style.top = "0";
  outerDiv.style.left = "0";
  outerDiv.style.background = "#6b6c7b80";
  outerDiv.style.zIndex = "9999";

  /// This div element has the js sdk
  DivElement sdkDiv = DivElement();
  sdkDiv.id = "cf-flutter-placeholder";
  sdkDiv.style.position = "fixed";
  sdkDiv.style.left = "50%";
  sdkDiv.style.top = "50%";
  sdkDiv.style.width = "400px";
  // sdkDiv.style.minHeight = "350px";
  sdkDiv.style.height = "100%";
  sdkDiv.style.maxWidth = "100%";
  sdkDiv.style.transform = "translate(-50%, -50%)";
  sdkDiv.style.overflow = "auto";
  outerDiv.append(sdkDiv);

  /// This div element has the cross mark to close the sdk
  DivElement closeButton = DivElement();
  closeButton.text = "X";
  closeButton.style.position = "fixed";
  closeButton.style.right = "10px";
  closeButton.style.top = "10px";
  closeButton.style.fontSize = "24px";
  closeButton.style.color = "#ff0000";
  sdkDiv.append(closeButton);
  closeButton.onClick.listen((event) {
    _userCancelledTransaction();
  });

  document
      .querySelector("body")
      ?.children
      .add(outerDiv);

  /// Taking an instance of outer div to close it later
  _outerDiv = outerDiv;

  _onError = CFPaymentGatewayService.onError;
  _verifyPayment = CFPaymentGatewayService.verifyPayment;

  String environment = session["environment"] as String;
  String paymentSessionId = session["payment_session_id"] as String;

  var paymentComponents = arguments["paymentComponents"] as dynamic;
  var components = paymentComponents["components"] as List<dynamic>;
  List<String> componentsToSend = [];
  componentsToSend.add("order-details");
  for(int i = 0; i < components.length; i++) {
    if(components[i] == "wallet") {
      componentsToSend.add("app");
    } else if(components[i] == "emi") {
      componentsToSend.add("creditcardemi");
      componentsToSend.add("cardlessemi");
    } else {
      componentsToSend.add(components[i].toString());
    }
  }

  var theme = arguments["theme"] as dynamic;
  String backgroundColor = theme["navigationBarBackgroundColor"] as String;
  String color = theme["navigationBarTextColor"] as String;
  String font = theme ["primaryFont"] as String;

  var style = {
    "backgroundColor": backgroundColor,
    "color": color,
    "fontFamily": font,
    "fontSize": "14px",
    "errorColor": "#ff0000",
    "theme": "light"
  };

  var script = document.createElement("SCRIPT") as ScriptElement;
  if(environment == "SANDBOX") {
    script.src =
    "https://sdk.cashfree.com/js/flutter/2.0.0/cashfree.sandbox.js ";
  } else {
    script.src =
    "https://sdk.cashfree.com/js/flutter/2.0.0/cashfree.prod.js";
  }
  script.onLoad.first.then((value) {
    var c = Cashfree(paymentSessionId);

    var element = document.getElementById("cf-flutter-placeholder") as Element;
    var os = allowInterop(onSuccess);
    var of = allowInterop(onFailure);

    var cfConfig = CFConfig(components: componentsToSend, pluginName: "jflt-d-2.0.10-3.3.10", onFailure: of, onSuccess: os, style: style);
    c.drop(element, cfConfig);
  });
  document.querySelector("body")?.children.add(script);
}