doPayment method

void doPayment(
  1. dynamic arguments
)

WEB

Implementation

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

  print(window.navigator.userAgent);

  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 = "340px";
  sdkDiv.style.minHeight = "350px";
  sdkDiv.style.maxWidth = "100%";
  sdkDiv.style.transform = "translate(-50%, -50%)";
  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 orderToken = session["order_token"] as String;

  var paymentComponents = arguments["paymentComponents"] as dynamic;
  var components = paymentComponents["components"] as List<dynamic>;
  List<String> componentsToSend = [];
  for(int i = 0; i < components.length; i++) {
    if(components[i] == "order_details") {
      componentsToSend.add("order-details");
    } else 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/1.0.26/dropinClient.sandbox.js";
  } else {
    script.src =
    "https://sdk.cashfree.com/js/flutter/1.0.26/dropinClient.prod.js";
  }
  script.onLoad.first.then((value) {
    var c = Cashfree();

    var element = document.getElementById("cf-flutter-placeholder") as Element;
    var os = allowInterop(onSuccess);
    var of = allowInterop(onFailure);
    final isWebMobile = kIsWeb &&
        (defaultTargetPlatform == TargetPlatform.iOS ||
            defaultTargetPlatform == TargetPlatform.android);
    var deviceType = "d"; // desktop
    if(isWebMobile) {
      deviceType = "m";
    }

    var cfConfig = CFConfig(components: componentsToSend, orderToken: orderToken, pluginName: "flutter-d-0.0.1-3.3.1-$deviceType-x-x-x-x", onFailure: of, onSuccess: os, style: style);
    c.initialiseDropin(element, cfConfig);
  });
  document.querySelector("body")?.children.add(script);
}