requestPayment method

Future<void> requestPayment({
  1. Payload? payload,
  2. BootpayDefaultCallback? onError,
  3. BootpayDefaultCallback? onCancel,
  4. BootpayCloseCallback? onClose,
  5. BootpayDefaultCallback? onIssued,
  6. BootpayConfirmCallback? onConfirm,
  7. BootpayAsyncConfirmCallback? onConfirmAsync,
  8. BootpayDefaultCallback? onDone,
})

Implementation

Future<void> requestPayment({
  Payload? payload,
  BootpayDefaultCallback? onError,
  BootpayDefaultCallback? onCancel,
  BootpayCloseCallback? onClose,
  BootpayDefaultCallback? onIssued,
  BootpayConfirmCallback? onConfirm,
  BootpayAsyncConfirmCallback? onConfirmAsync,
  BootpayDefaultCallback? onDone
}) async {



  if(onError != null) this.onError = onError;
  if(onCancel != null) this.onCancel = onCancel;
  if(onClose != null) this.onClose = onClose;
  if(onIssued != null) this.onIssued = onIssued;
  if(onConfirm != null) this.onConfirm = onConfirm;
  if(onConfirmAsync != null) this.onConfirmAsync = onConfirmAsync;
  if(onDone != null) this.onDone = onDone;
  if(payload != null) this.payload = payload;

  // {status: 2.0, receipt_id: 66681d6804ab6d03f274d429, order_id: 1718099301766, status_locale: 입금/승인대기, event: confirm}
  String script = "BootpayWidget.requestPayment(" +
      "${this.payload?.toString()}" +
      ")" +
      ".then( function (res) {" +
      confirmEventHandler +
      issuedEventHandler +
      doneEventHandler +
      "}, function (res) {" +
      errorEventHandler +
      cancelEventHandler +
      "})";

  // print(script);

  bool refresh = false;
  String updateScript = "BootpayWidget.update(${payload.toString()}, ${refresh == true ? 'true' : 'false'});";

  if (BootpayConfig.IS_FORCE_WEB) {
    updateScript += "Bootpay.setVersion('" + BootpayConfig.VERSION + "', 'flutter');";
  } else if (Platform.isAndroid) {
    updateScript += "Bootpay.setDevice('ANDROID');";
    updateScript += "Bootpay.setVersion('" + BootpayConfig.VERSION + "', 'android_flutter');";
  } else if (Platform.isIOS) {
    updateScript += "Bootpay.setDevice('IOS');";
    updateScript += "Bootpay.setVersion('" + BootpayConfig.VERSION + "', 'ios_flutter');";
  }

  //full screen webview 로 이동
  pushInternalWebView();

  //300ms 뒤에 실행
  Future.delayed(Duration(milliseconds: 300), () {
    _controller.runJavaScript(
        updateScript
    ).then((value) => {
      _controller.runJavaScript(
          script
      )
    });
  });
}