var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  // If the importer is in node compatibility mode or this is not an ESM
  // file that has been converted to a CommonJS file using a Babel-
  // compatible transform (i.e. "__esModule" has not been set), then set
  // "default" to the CommonJS "module.exports" for node compatibility.
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// src/components/pay/toC/PaymentMethods/StripePay/Stripe/Finish/index.tsx
var Finish_exports = {};
__export(Finish_exports, {
  default: () => Finish_default
});
module.exports = __toCommonJS(Finish_exports);
var import_react = require("react");
var import_ahooks = require("ahooks");
var import_NavBar = __toESM(require("../../../../../../NavBar"));
var import_StripeSDK = __toESM(require("../../../../../../StripeSDK"));
var import_Content = __toESM(require("./Content"));
var import_utils = require("../../../../../../../utils/index");
var import_serve = require("./serve");
var import_index = __toESM(require("./index.less"));
var StripePayment = () => {
  var _a;
  const history = useHistory();
  const query = history.location.query;
  const _getStripeKey = (0, import_ahooks.useRequest)(import_serve.getStripeKey, {
    formatResult: (res) => res.data,
    onError: () => {
      goFinish("error");
    }
  });
  const goBack = () => {
    history.replace(`/order/details?id=${query == null ? void 0 : query.order_id}`);
  };
  const goFinish = (status) => {
    if (query == null ? void 0 : query.order_id) {
      let _pathname = "";
      if ((query == null ? void 0 : query.scene) === "wxapp") {
        if (status === "success") {
          _pathname = "/miniapp-payment/success";
        } else {
          _pathname = "/miniapp-payment/fail";
        }
      } else {
        if (status === "success") {
          _pathname = "/payment-finish/success";
        } else {
          _pathname = "/payment-finish/fail";
        }
      }
      history.replace(
        `${_pathname}?order_id=${query == null ? void 0 : query.order_id}&amount=${query.amount}&status=${status}`
      );
    } else {
      history.replace("/");
    }
  };
  const onPaymentChange = (status) => {
    if (status === "succeeded") {
      goFinish("success");
    }
    if (status === "processing") {
      goFinish("success");
    }
    if (status === "requires_payment_method") {
      goFinish("error");
    }
    if (status === "error") {
      goFinish("error");
    }
  };
  const _title = (0, import_react.useMemo)(() => {
    return decodeURIComponent(query.payment_method || "");
  }, [query]);
  return /* @__PURE__ */ React.createElement("div", { className: import_index.default["stripe-payment-page"] }, /* @__PURE__ */ React.createElement(
    import_NavBar.default,
    {
      name: _title,
      onChange: goBack,
      bgColor: "#ffffff",
      nameColor: "rgba(0,0,0,.9)",
      backColor: "rgba(0,0,0,.9)"
    }
  ), (0, import_utils.isWxApp)() ? null : /* @__PURE__ */ React.createElement(import_StripeSDK.default, { public_key: (_a = _getStripeKey.data) == null ? void 0 : _a.publishable_key }, /* @__PURE__ */ React.createElement(import_Content.default, { onChange: onPaymentChange })));
};
var Finish_default = StripePayment;
