cppay-sdk 0.0.2-beta.30 → 0.0.2-beta.32

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/react.js CHANGED
@@ -1,5 +1,5 @@
1
- import { t as cppay_default } from "./cppay-CCxKnEWz.js";
2
- import { n as payment_dialog_default, t as injectStyle } from "./inject-style-CWza6SKp.js";
1
+ import { t as cppay_default } from "./cppay-C_gp2ZZ3.js";
2
+ import { n as payment_dialog_default, t as injectStyle } from "./inject-style-DtFJ9cds.js";
3
3
  import * as QRCode from "qrcode";
4
4
  import { EMPTY, defer, timer } from "rxjs";
5
5
  import { expand, retry, switchMap, tap, timeout } from "rxjs/operators";
@@ -7,12 +7,12 @@ import { createWalletClient, custom, parseUnits } from "viem";
7
7
  import { arbitrum, base, bsc, mainnet, optimism, polygon } from "viem/chains";
8
8
  import { createAppKit } from "@reown/appkit";
9
9
  import { EthersAdapter } from "@reown/appkit-adapter-ethers";
10
- import React, { createContext, useCallback, useContext, useEffect, useMemo, useRef, useState } from "react";
10
+ import { createContext, useCallback, useContext, useEffect, useMemo, useRef, useState } from "react";
11
11
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
12
- var PaymentDialog_default = React.memo(({ open: t, onClose: n, apikey: a, plain: o, orderId: s, amount: c, intervalDays: l, onExpired: u, onSuccess: d, onFailed: f, onError: p }) => {
13
- let m = useMemo(() => new cppay_default(a), [a]), [h, g] = useState("select"), [_, v] = useState(!1), [y, b] = useState(!1), [x, S] = useState(), [C, w] = useState(!1), [T, E] = useState([]), [D, O] = useState(), [k, A] = useState(), [j, M] = useState(), [N, P] = useState(), [F, I] = useState(!1), [L, R] = useState(), z = useRef(null), B = useRef(null);
12
+ var PaymentContent_default = ({ apikey: t, ott: n, plain: m, orderId: h, amount: g, intervalDays: ge, onSuccess: _e, onExpired: ve, onFailed: ye, onError: _, Slots: be, paymentStep: v, onPaymentStepChange: y, loading: b = !1, isCheckingPayment: x = !1, error: S, onErrorChange: C }) => {
13
+ let w = useMemo(() => new cppay_default(t, n), [t, n]), [T, xe] = useState([]), [E, D] = useState(), [O, k] = useState(), [A, j] = useState(), [M, N] = useState(), [P, F] = useState(!1), [I, L] = useState(), [R, Se] = useState(""), [z, B] = useState(!1), [Ce, V] = useState(!1), H = useRef(null), U = useRef(null), W = useRef(null);
14
14
  useEffect(() => {
15
- typeof window < "u" && !z.current && (z.current = createAppKit({
15
+ typeof window < "u" && !H.current && (H.current = createAppKit({
16
16
  debug: !1,
17
17
  enableNetworkSwitch: !1,
18
18
  adapters: [new EthersAdapter()],
@@ -33,22 +33,24 @@ var PaymentDialog_default = React.memo(({ open: t, onClose: n, apikey: a, plain:
33
33
  icons: ["https://cppay.com/icon.png"]
34
34
  },
35
35
  features: { analytics: !1 }
36
- }), P(z.current.getAddress()), R(z.current.getProvider("eip155")), z.current.subscribeAccount((e) => {
37
- e.isConnected ? P(e.address) : (P(void 0), R(void 0));
38
- }), z.current.subscribeProviders((e) => {
36
+ }), N(H.current.getAddress()), L(H.current.getProvider("eip155")), H.current.subscribeAccount((e) => {
37
+ e.isConnected ? N(e.address) : (N(void 0), L(void 0));
38
+ }), H.current.subscribeProviders((e) => {
39
39
  let t = e?.eip155;
40
- R(t);
40
+ L(t);
41
41
  }));
42
42
  }, []);
43
- let V = async () => {
43
+ let we = async () => {
44
44
  try {
45
- I(!0), S(void 0), z.current && await z.current.open();
45
+ F(!0), C?.(void 0), H.current && await H.current.open();
46
46
  } catch (e) {
47
- console.error("钱包连接失败:", e), S(e instanceof Error ? e.message : "钱包连接失败"), p?.(e);
47
+ console.error("钱包连接失败:", e);
48
+ let t = e instanceof Error ? e.message : "钱包连接失败";
49
+ C?.(t), _?.(e);
48
50
  } finally {
49
- I(!1);
51
+ F(!1);
50
52
  }
51
- }, H = useMemo(() => T.find((e) => e.chain === D), [T, D]), U = useMemo(() => H?.tokens || [], [H]), W = useMemo(() => U.find((e) => e.symbol === k), [U, k]), G = (e) => [
53
+ }, G = useMemo(() => T.find((e) => e.chain === E), [T, E]), K = useMemo(() => G?.tokens || [], [G]), q = useMemo(() => K.find((e) => e.symbol === O), [K, O]), J = (e) => [
52
54
  "USDT",
53
55
  "USDC",
54
56
  "BUSD",
@@ -56,92 +58,97 @@ var PaymentDialog_default = React.memo(({ open: t, onClose: n, apikey: a, plain:
56
58
  "TUSD",
57
59
  "USDD",
58
60
  "FDUSD"
59
- ].includes(e.toUpperCase()) ? 2 : 6, K = (e, t) => {
61
+ ].includes(e.toUpperCase()) ? 2 : 6, Y = (e, t) => {
60
62
  let n = parseFloat(e);
61
63
  return isNaN(n) ? "0" : n.toFixed(t).replace(/\.?0+$/, "");
62
- }, q = useMemo(() => {
63
- if (!k || !W) return "0";
64
- let e = parseFloat(W.price);
64
+ }, Te = (e) => {
65
+ if (e <= 0) return "已过期";
66
+ let t = Math.floor(e / 3600), n = Math.floor(e % 3600 / 60), r = e % 60;
67
+ return t > 0 ? `${t}时${n}分${r}秒` : `${n}分${r}秒`;
68
+ }, X = (e) => {
69
+ W.current && clearInterval(W.current);
70
+ let t = () => {
71
+ let t = e - Math.floor(Date.now() / 1e3);
72
+ Se(Te(t)), t <= 0 && (y("expired"), Ee());
73
+ };
74
+ t(), W.current = setInterval(t, 1e3);
75
+ }, Ee = () => {
76
+ W.current &&= (clearInterval(W.current), null);
77
+ }, Z = useMemo(() => {
78
+ if (!O || !q) return "0";
79
+ let e = parseFloat(q.price);
65
80
  if (isNaN(e) || e === 0) return "0";
66
- let t = G(k);
67
- return K((parseFloat(c) / e).toFixed(t), t);
81
+ let t = J(O);
82
+ return Y((parseFloat(g) / e).toFixed(t), t);
68
83
  }, [
69
- c,
70
- k,
71
- W
72
- ]), Te = async () => {
84
+ g,
85
+ O,
86
+ q
87
+ ]), De = async () => {
73
88
  try {
74
- v(!0), S(void 0);
75
- let e = await m.getSupportedChains();
76
- E(e), e.length > 0 && O(e[0].chain);
89
+ C?.(void 0);
90
+ let e = await w.getSupportedChains();
91
+ xe(e), e.length > 0 && D(e[0].chain);
77
92
  } catch (e) {
78
- S(e instanceof Error ? e.message : "加载支付网络失败"), p?.(e);
79
- } finally {
80
- v(!1);
93
+ let t = e instanceof Error ? e.message : "加载支付网络失败";
94
+ C?.(t), _?.(e);
81
95
  }
82
- }, J = async (e) => {
83
- if (L) try {
84
- await L.request({
96
+ }, Oe = async (e) => {
97
+ if (I) try {
98
+ await I.request({
85
99
  method: "wallet_switchEthereumChain",
86
100
  params: [{ chainId: `0x${e.toString(16)}` }]
87
101
  });
88
102
  } catch (e) {
89
103
  throw e.code === 4902 ? Error("请在钱包中添加该网络") : e;
90
104
  }
91
- }, Ee = async () => {
92
- if (!(!N || !L || !Y.current || !W || !H)) try {
93
- v(!0);
94
- let e = Y.current;
95
- await J(H.chainId);
105
+ }, ke = async () => {
106
+ if (!(!M || !I || !Q.current || !q || !G)) try {
107
+ let e = Q.current;
108
+ await Oe(G.chainId);
96
109
  let t = createWalletClient({
97
- account: N,
98
- transport: custom(L)
110
+ account: M,
111
+ transport: custom(I)
99
112
  });
100
- if (W.address) {
101
- let n = await t.writeContract({
102
- address: W.address,
103
- abi: [{
104
- name: "transfer",
105
- type: "function",
106
- stateMutability: "nonpayable",
107
- inputs: [{
108
- name: "to",
109
- type: "address"
110
- }, {
111
- name: "amount",
112
- type: "uint256"
113
- }],
114
- outputs: [{ type: "bool" }]
113
+ q.address ? await t.writeContract({
114
+ address: q.address,
115
+ abi: [{
116
+ name: "transfer",
117
+ type: "function",
118
+ stateMutability: "nonpayable",
119
+ inputs: [{
120
+ name: "to",
121
+ type: "address"
122
+ }, {
123
+ name: "amount",
124
+ type: "uint256"
115
125
  }],
116
- functionName: "transfer",
117
- args: [e.receiveAddress, parseUnits(e.paymentAmount, W.decimals)],
118
- chain: null
119
- });
120
- console.log("转账交易哈希:", n);
121
- } else {
122
- let n = await t.sendTransaction({
123
- to: e.receiveAddress,
124
- value: parseUnits(e.paymentAmount, W.decimals),
125
- chain: null
126
- });
127
- console.log("转账交易哈希:", n);
128
- }
129
- v(!1), b(!0), Z(e.paymentId);
126
+ outputs: [{ type: "bool" }]
127
+ }],
128
+ functionName: "transfer",
129
+ args: [e.receiveAddress, parseUnits(e.paymentAmount, q.decimals)],
130
+ chain: null
131
+ }) : await t.sendTransaction({
132
+ to: e.receiveAddress,
133
+ value: parseUnits(e.paymentAmount, q.decimals),
134
+ chain: null
135
+ }), j(void 0);
130
136
  } catch (e) {
131
- console.error("钱包支付失败:", e), S(e instanceof Error ? e.message : "钱包支付失败"), p?.(e), v(!1);
137
+ console.error("钱包支付失败:", e);
138
+ let t = e instanceof Error ? e.message : "钱包支付失败";
139
+ C?.(t), _?.(e);
132
140
  }
133
- }, De = async () => {
134
- if (!(!N || !L || !Y.current || !W || !H)) try {
135
- v(!0);
136
- let e = Y.current;
137
- await J(H.chainId);
141
+ }, Ae = async () => {
142
+ if (!(!M || !I || !Q.current || !q || !G)) try {
143
+ let e = Q.current;
144
+ await Oe(G.chainId);
138
145
  let t = createWalletClient({
139
- account: N,
140
- transport: custom(L)
146
+ account: M,
147
+ transport: custom(I)
141
148
  });
142
- if (!W.address) throw Error("订阅支付不支持原生代币");
143
- let n = await t.writeContract({
144
- address: W.address,
149
+ if (!q.address) throw Error("订阅支付不支持原生代币");
150
+ await t.writeContract({
151
+ address: q.address,
145
152
  abi: [{
146
153
  name: "approve",
147
154
  type: "function",
@@ -156,89 +163,409 @@ var PaymentDialog_default = React.memo(({ open: t, onClose: n, apikey: a, plain:
156
163
  outputs: [{ type: "bool" }]
157
164
  }],
158
165
  functionName: "approve",
159
- args: [e.spenderAddress, parseUnits(e.approveAmount, W.decimals)],
166
+ args: [e.spenderAddress, parseUnits(e.approveAmount, q.decimals)],
160
167
  chain: null
161
- });
162
- console.log("授权交易哈希:", n), v(!1), b(!0), Z(e.subscriptionId);
168
+ }), j(void 0);
163
169
  } catch (e) {
164
- console.error("钱包授权失败:", e), S(e instanceof Error ? e.message : "钱包授权失败"), p?.(e), v(!1);
170
+ console.error("钱包授权失败:", e);
171
+ let t = e instanceof Error ? e.message : "钱包授权失败";
172
+ C?.(t), _?.(e);
165
173
  }
166
- }, Oe = async () => {
167
- if (!N) {
174
+ }, je = async () => {
175
+ if (!M) {
168
176
  let e = "请先连接钱包";
169
- S(e), p?.(Error(e));
177
+ C?.(e), _?.(Error(e));
170
178
  return;
171
179
  }
172
- o === "one-time" ? await Ee() : o === "subscription" && await De();
173
- }, Y = useRef(null), X = async () => {
174
- if (!(!D || !k)) try {
175
- v(!0), S(void 0);
180
+ m === "one-time" ? await ke() : m === "subscription" && await Ae();
181
+ }, Q = useRef(null), Me = async () => {
182
+ if (!(!E || !O)) try {
183
+ C?.(void 0);
176
184
  let e = "";
177
- o === "one-time" ? (Y.current = await m.createOnetimePayment({
178
- paymentChain: D,
179
- paymentToken: k,
180
- orderId: s,
181
- amount: q
182
- }), e = `${D.toLowerCase()}:${Y.current.receiveAddress}?amount=${Y.current.paymentAmount}`) : o === "subscription" && (Y.current = await m.createSubscriptionPayment({
183
- paymentChain: D,
184
- paymentToken: k,
185
- orderId: s,
186
- amountOfUsd: q,
187
- intervalDays: l || 30
188
- }), e = `${D.toLowerCase()}:${Y.current.spenderAddress}?amount=${Y.current.approveAmount}`), g("payment"), M(await QRCode.toDataURL(e, {
185
+ m === "one-time" ? (Q.current = await w.createOnetimePayment({
186
+ paymentChain: E,
187
+ paymentToken: O,
188
+ orderId: h,
189
+ amount: Z
190
+ }), e = `${E.toLowerCase()}:${Q.current.receiveAddress}?amount=${Q.current.paymentAmount}`, X(Q.current.expireAt), $({ paymentId: Q.current.paymentId })) : m === "subscription" && (Q.current = await w.createSubscriptionPayment({
191
+ paymentChain: E,
192
+ paymentToken: O,
193
+ orderId: h,
194
+ amountOfUsd: Z,
195
+ intervalDays: ge || 30
196
+ }), e = `${E.toLowerCase()}:${Q.current.spenderAddress}?amount=${Q.current.approveAmount}`, X(Q.current.expireAt), $({ subscriptionId: Q.current.subscriptionId })), y("payment"), j(await QRCode.toDataURL(e, {
189
197
  width: 200,
190
198
  margin: 2,
191
199
  errorCorrectionLevel: "H"
192
200
  }));
193
201
  } catch (e) {
194
- S(e instanceof Error ? e.message : "创建支付失败"), p?.(e);
195
- } finally {
196
- v(!1);
197
- }
198
- }, ke = async () => {
199
- if (Y.current) try {
200
- b(!0), S(void 0), o === "one-time" ? Z(Y.current.paymentId) : o === "subscription" && Z(Y.current.subscriptionId);
201
- } catch (e) {
202
- console.error("支付状态检查错误:", e), S(e instanceof Error ? e.message : "检查支付状态失败"), p?.(e), b(!1);
202
+ let t = e instanceof Error ? e.message : "创建支付失败";
203
+ C?.(t), _?.(e);
203
204
  }
204
- }, Z = (e) => {
205
- let t = () => defer(() => o === "subscription" ? m.checkSubscriptionPaymentStatus({ subscriptionId: e }) : m.checkOnetimePaymentStatus({ paymentId: e })).pipe(timeout(15e3), retry({
206
- count: 3,
207
- delay: 2e3
208
- }));
209
- B.current?.unsubscribe(), B.current = t().pipe(expand((e) => e.status === "pending" ? timer(2e3).pipe(switchMap(() => t())) : EMPTY), tap((e) => {
210
- e.status === "expired" && (b(!1), u?.(e)), e.status === "paid" && (b(!1), g("success"), d?.(e)), e.status === "failed" && (b(!1), f?.(e)), e.status === "approved" && (b(!1), g("success"), d?.(e));
211
- })).subscribe({ error: (e) => {
212
- console.error("支付状态检查错误:", e), S(e instanceof Error ? e.message : "检查支付状态失败"), b(!1), p?.(e);
213
- } });
214
- }, Q = async () => {
215
- if (!Y.current) return;
216
- let e = o === "subscription" ? Y.current.spenderAddress : Y.current.receiveAddress;
217
- e && await navigator.clipboard.writeText(e);
218
- }, $ = () => {
219
- _ || y || (n(), setTimeout(() => {
220
- g("select"), S(void 0), Y.current = null;
221
- }, 300));
205
+ }, $ = (e) => {
206
+ U.current?.unsubscribe();
207
+ let t = () => defer(() => m === "subscription" ? w.checkSubscriptionPaymentStatus(e) : w.checkOnetimePaymentStatus(e)).pipe(timeout(15e3), retry({ delay: 2e3 }));
208
+ U.current = t().pipe(expand((e) => e.status === "pending" ? timer(2e3).pipe(switchMap(() => t())) : EMPTY), tap((e) => {
209
+ (e.status === "paid" || e.status === "approved") && (y("success"), _e?.(e)), e.status === "expired" && (y("expired"), ve?.(e)), e.status === "failed" && (y("failed"), ye?.(e));
210
+ })).subscribe({
211
+ error: (e) => {
212
+ if (Q.current) {
213
+ let t = e instanceof Error ? e.message : "检查支付状态失败";
214
+ y("error"), C?.(t), _?.(e);
215
+ }
216
+ },
217
+ complete: () => {
218
+ U.current?.unsubscribe();
219
+ }
220
+ });
222
221
  };
223
222
  return useEffect(() => {
224
- t && T.length === 0 && Te();
225
- }, [t]), useEffect(() => {
226
- U.length > 0 && A(U[0].symbol);
227
- }, [U]), useEffect(() => () => {
228
- B.current?.unsubscribe();
229
- }, []), t ? /* @__PURE__ */ jsx("div", {
223
+ T.length === 0 && De();
224
+ }, []), useEffect(() => {
225
+ K.length > 0 && k(K[0].symbol);
226
+ }, [K]), useEffect(() => (h && $({ orderId: h }), () => {
227
+ U.current?.unsubscribe(), Ee();
228
+ }), [h]), /* @__PURE__ */ jsx("div", {
229
+ className: "_cppay-content",
230
+ children: v === "success" ? /* @__PURE__ */ jsxs("div", {
231
+ className: "_cppay-state-container",
232
+ children: [
233
+ /* @__PURE__ */ jsx("div", {
234
+ className: "_cppay-state-icon",
235
+ children: "✅"
236
+ }),
237
+ /* @__PURE__ */ jsx("h3", {
238
+ className: "_cppay-state-title",
239
+ children: m === "subscription" ? "授权成功!" : "支付成功!"
240
+ }),
241
+ /* @__PURE__ */ jsx("p", {
242
+ className: "_cppay-state-message",
243
+ children: m === "subscription" ? "订阅已激活" : "交易已完成"
244
+ })
245
+ ]
246
+ }) : v === "expired" ? /* @__PURE__ */ jsxs("div", {
247
+ className: "_cppay-state-container",
248
+ children: [
249
+ /* @__PURE__ */ jsx("div", {
250
+ className: "_cppay-state-icon",
251
+ children: "⏰"
252
+ }),
253
+ /* @__PURE__ */ jsx("h3", {
254
+ className: "_cppay-state-title",
255
+ children: "支付已过期,请重选创建支付订单"
256
+ }),
257
+ /* @__PURE__ */ jsx("button", {
258
+ onClick: () => y("select"),
259
+ disabled: b || x,
260
+ className: "_cppay-btn _cppay-btn-text",
261
+ children: "返回"
262
+ })
263
+ ]
264
+ }) : v === "error" ? /* @__PURE__ */ jsxs("div", {
265
+ className: "_cppay-state-container",
266
+ children: [/* @__PURE__ */ jsx("div", {
267
+ className: "_cppay-state-icon",
268
+ children: "❌"
269
+ }), /* @__PURE__ */ jsx("h3", {
270
+ className: "_cppay-state-title",
271
+ children: "检查订单支付状态失败!"
272
+ })]
273
+ }) : v === "failed" ? /* @__PURE__ */ jsxs("div", {
274
+ className: "_cppay-state-container",
275
+ children: [/* @__PURE__ */ jsx("div", {
276
+ className: "_cppay-state-icon",
277
+ children: "❌"
278
+ }), /* @__PURE__ */ jsx("h3", {
279
+ className: "_cppay-state-title",
280
+ children: "订单支付失败!"
281
+ })]
282
+ }) : v === "select" ? /* @__PURE__ */ jsxs("div", { children: [
283
+ be?.ChooseTop,
284
+ /* @__PURE__ */ jsxs("div", {
285
+ className: "_cppay-section",
286
+ children: [/* @__PURE__ */ jsx("label", {
287
+ className: "_cppay-label",
288
+ children: "支付网络"
289
+ }), /* @__PURE__ */ jsx("div", {
290
+ className: "_cppay-grid",
291
+ children: T.map((e) => /* @__PURE__ */ jsxs("button", {
292
+ onClick: () => D(e.chain),
293
+ className: `_cppay-select-btn ${E === e.chain ? "_cppay-selected" : ""}`,
294
+ children: [e.icon && /* @__PURE__ */ jsx("img", {
295
+ src: e.icon,
296
+ alt: e.chain
297
+ }), /* @__PURE__ */ jsx("span", { children: e.chain })]
298
+ }, e.chain))
299
+ })]
300
+ }),
301
+ /* @__PURE__ */ jsxs("div", {
302
+ className: "_cppay-section",
303
+ children: [/* @__PURE__ */ jsx("label", {
304
+ className: "_cppay-label",
305
+ children: "支付代币"
306
+ }), /* @__PURE__ */ jsx("div", {
307
+ className: "_cppay-grid",
308
+ children: K.map((e) => /* @__PURE__ */ jsxs("button", {
309
+ onClick: () => k(e.symbol),
310
+ className: `_cppay-select-btn ${O === e.symbol ? "_cppay-selected" : ""}`,
311
+ children: [e.icon && /* @__PURE__ */ jsx("img", {
312
+ src: e.icon,
313
+ alt: e.symbol
314
+ }), /* @__PURE__ */ jsx("span", { children: e.symbol })]
315
+ }, e.symbol))
316
+ })]
317
+ }),
318
+ be?.ChooseBottom,
319
+ /* @__PURE__ */ jsx("div", {
320
+ className: "_cppay-section",
321
+ children: /* @__PURE__ */ jsx("div", {
322
+ className: "_cppay-price-box",
323
+ children: /* @__PURE__ */ jsxs("div", {
324
+ className: "_cppay-price-row",
325
+ children: [/* @__PURE__ */ jsx("span", {
326
+ className: "_cppay-price-label",
327
+ children: "支付金额"
328
+ }), /* @__PURE__ */ jsxs("div", {
329
+ className: "_cppay-price-amount",
330
+ children: [/* @__PURE__ */ jsxs("div", {
331
+ className: "_cppay-price-main",
332
+ children: [
333
+ Z ?? "-",
334
+ " ",
335
+ O ?? ""
336
+ ]
337
+ }), /* @__PURE__ */ jsxs("div", {
338
+ className: "_cppay-price-sub",
339
+ children: ["≈ $", g]
340
+ })]
341
+ })]
342
+ })
343
+ })
344
+ }),
345
+ /* @__PURE__ */ jsxs("div", {
346
+ className: "_cppay-section",
347
+ children: [S && /* @__PURE__ */ jsxs("div", {
348
+ className: "_cppay-error-tooltip-wrapper",
349
+ onMouseEnter: () => V(!0),
350
+ onMouseLeave: () => V(!1),
351
+ children: [/* @__PURE__ */ jsxs("div", {
352
+ className: "_cppay-error-tooltip",
353
+ children: [/* @__PURE__ */ jsx("svg", {
354
+ viewBox: "0 0 20 20",
355
+ fill: "currentColor",
356
+ children: /* @__PURE__ */ jsx("path", {
357
+ fillRule: "evenodd",
358
+ d: "M10 18a8 8 0 100-16 8 8 0 000 16zM8.707 7.293a1 1 0 00-1.414 1.414L8.586 10l-1.293 1.293a1 1 0 101.414 1.414L10 11.414l1.293 1.293a1 1 0 001.414-1.414L11.414 10l1.293-1.293a1 1 0 00-1.414-1.414L10 8.586 8.707 7.293z",
359
+ clipRule: "evenodd"
360
+ })
361
+ }), /* @__PURE__ */ jsx("span", { children: S })]
362
+ }), Ce && /* @__PURE__ */ jsx("div", {
363
+ className: "_cppay-error-tooltip-full",
364
+ children: S
365
+ })]
366
+ }), /* @__PURE__ */ jsx("button", {
367
+ onClick: Me,
368
+ disabled: !E || !O || b,
369
+ className: "_cppay-btn _cppay-btn-primary",
370
+ children: b ? "处理中..." : "继续支付"
371
+ })]
372
+ })
373
+ ] }) : /* @__PURE__ */ jsxs("div", { children: [
374
+ /* @__PURE__ */ jsx("div", {
375
+ className: "_cppay-qr-container",
376
+ children: /* @__PURE__ */ jsx("div", {
377
+ className: "_cppay-qr-code",
378
+ children: A && /* @__PURE__ */ jsx("img", {
379
+ src: A,
380
+ alt: "Payment QR Code",
381
+ className: "_cppay-qr-image"
382
+ })
383
+ })
384
+ }),
385
+ /* @__PURE__ */ jsxs("div", {
386
+ className: "_cppay-section",
387
+ children: [
388
+ q && /* @__PURE__ */ jsx("div", {
389
+ className: "_cppay-info-box",
390
+ children: /* @__PURE__ */ jsx("div", {
391
+ className: "_cppay-info-flex-container",
392
+ children: /* @__PURE__ */ jsxs("div", {
393
+ className: "_cppay-info-flex-child",
394
+ children: [/* @__PURE__ */ jsx("div", {
395
+ className: "_cppay-info-label",
396
+ children: m === "subscription" ? "授权金额" : "支付金额"
397
+ }), /* @__PURE__ */ jsxs("div", {
398
+ className: "_cppay-info-value _cppay-info-value-flex",
399
+ children: [/* @__PURE__ */ jsx("span", { children: m === "subscription" ? `${Y(Q.current.approveAmount, J(q.symbol))} ${q.symbol}` : `${Y(Q.current.paymentAmount, J(q.symbol))} ${q.symbol}` }), /* @__PURE__ */ jsxs("span", { children: ["≈ $", g] })]
400
+ })]
401
+ })
402
+ })
403
+ }),
404
+ /* @__PURE__ */ jsx("div", {
405
+ className: "_cppay-info-box",
406
+ children: /* @__PURE__ */ jsxs("div", {
407
+ className: "_cppay-info-flex-child",
408
+ children: [/* @__PURE__ */ jsxs("div", {
409
+ className: "_cppay-info-label _cppay-info-label-flex",
410
+ children: [/* @__PURE__ */ jsx("span", { children: m === "subscription" ? "授权合约地址" : "支付地址" }), R && /* @__PURE__ */ jsxs("span", {
411
+ className: "_cppay-countdown",
412
+ children: ["⏰ ", R]
413
+ })]
414
+ }), /* @__PURE__ */ jsxs("div", {
415
+ className: "_cppay-address-row",
416
+ children: [/* @__PURE__ */ jsx("code", { children: m === "subscription" ? Q.current.spenderAddress : Q.current.receiveAddress }), /* @__PURE__ */ jsx("button", {
417
+ onClick: async () => {
418
+ if (!Q.current) return;
419
+ let e = m === "subscription" ? Q.current.spenderAddress : Q.current.receiveAddress;
420
+ if (e) try {
421
+ await navigator.clipboard.writeText(e), B(!0), setTimeout(() => {
422
+ B(!1);
423
+ }, 2e3);
424
+ } catch (e) {
425
+ console.error("复制失败:", e);
426
+ }
427
+ },
428
+ className: `_cppay-copy-btn ${z ? "_cppay-copy-success" : ""}`,
429
+ title: z ? "已复制!" : "复制地址",
430
+ children: z ? /* @__PURE__ */ jsx("svg", {
431
+ className: "_cppay-copy-icon",
432
+ viewBox: "0 0 24 24",
433
+ fill: "currentColor",
434
+ children: /* @__PURE__ */ jsx("path", { d: "M9 16.17L4.83 12l-1.42 1.41L9 19 21 7l-1.41-1.41z" })
435
+ }) : /* @__PURE__ */ jsxs("svg", {
436
+ className: "_cppay-copy-icon",
437
+ viewBox: "0 0 24 24",
438
+ fill: "none",
439
+ stroke: "currentColor",
440
+ strokeWidth: "2",
441
+ children: [/* @__PURE__ */ jsx("path", { d: "M16 4h2a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2V6a2 2 0 0 1 2-2h2" }), /* @__PURE__ */ jsx("rect", {
442
+ x: "8",
443
+ y: "2",
444
+ width: "8",
445
+ height: "4",
446
+ rx: "1",
447
+ ry: "1"
448
+ })]
449
+ })
450
+ })]
451
+ })]
452
+ })
453
+ }),
454
+ m === "subscription" && /* @__PURE__ */ jsxs("div", {
455
+ className: "_cppay-info-box _cppay-subscription-box",
456
+ children: [/* @__PURE__ */ jsx("div", {
457
+ className: "_cppay-info-label _cppay-subscription-label",
458
+ children: "📌 订阅说明"
459
+ }), /* @__PURE__ */ jsx("div", {
460
+ className: "_cppay-info-value _cppay-subscription-message",
461
+ children: "订阅支付需要授权代币给合约地址,系统将按周期自动扣款。授权后无需每次手动支付。"
462
+ })]
463
+ })
464
+ ]
465
+ }),
466
+ S && /* @__PURE__ */ jsxs("div", {
467
+ className: "_cppay-error-tooltip-wrapper",
468
+ onMouseEnter: () => V(!0),
469
+ onMouseLeave: () => V(!1),
470
+ children: [/* @__PURE__ */ jsxs("div", {
471
+ className: "_cppay-error-tooltip",
472
+ children: [/* @__PURE__ */ jsx("svg", {
473
+ viewBox: "0 0 20 20",
474
+ fill: "currentColor",
475
+ children: /* @__PURE__ */ jsx("path", {
476
+ fillRule: "evenodd",
477
+ d: "M10 18a8 8 0 100-16 8 8 0 000 16zM8.707 7.293a1 1 0 00-1.414 1.414L8.586 10l-1.293 1.293a1 1 0 101.414 1.414L10 11.414l1.293 1.293a1 1 0 001.414-1.414L11.414 10l1.293-1.293a1 1 0 00-1.414-1.414L10 8.586 8.707 7.293z",
478
+ clipRule: "evenodd"
479
+ })
480
+ }), /* @__PURE__ */ jsx("span", { children: S })]
481
+ }), Ce && /* @__PURE__ */ jsx("div", {
482
+ className: "_cppay-error-tooltip-full",
483
+ children: S
484
+ })]
485
+ }),
486
+ !x && /* @__PURE__ */ jsx("div", {
487
+ className: "_cppay-section",
488
+ children: M ? /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("button", {
489
+ onClick: je,
490
+ disabled: b,
491
+ className: "_cppay-btn _cppay-btn-primary",
492
+ children: b ? m === "subscription" ? "授权中..." : "支付中..." : m === "subscription" ? "💳 钱包授权" : "💳 钱包支付"
493
+ }), /* @__PURE__ */ jsxs("button", {
494
+ onClick: we,
495
+ disabled: b,
496
+ className: "_cppay-btn _cppay-wallet-address-btn",
497
+ title: "点击修改或查看钱包状态",
498
+ children: [/* @__PURE__ */ jsxs("span", {
499
+ className: "_cppay-wallet-address-text",
500
+ children: [
501
+ M.slice(0, 10),
502
+ "...",
503
+ M.slice(-4)
504
+ ]
505
+ }), /* @__PURE__ */ jsx("svg", {
506
+ className: "_cppay-wallet-icon",
507
+ viewBox: "0 0 24 24",
508
+ fill: "none",
509
+ stroke: "currentColor",
510
+ strokeWidth: "2",
511
+ children: /* @__PURE__ */ jsx("path", { d: "M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm0 18c-4.41 0-8-3.59-8-8s3.59-8 8-8 8 3.59 8 8-3.59 8-8 8zm3.5-9c.83 0 1.5-.67 1.5-1.5S16.33 8 15.5 8 14 8.67 14 9.5s.67 1.5 1.5 1.5zm-7 0c.83 0 1.5-.67 1.5-1.5S9.33 8 8.5 8 7 8.67 7 9.5 7.67 11 8.5 11zm3.5 6.5c2.33 0 4.31-1.46 5.11-3.5H6.89c.8 2.04 2.78 3.5 5.11 3.5z" })
512
+ })]
513
+ })] }) : /* @__PURE__ */ jsx("button", {
514
+ onClick: we,
515
+ disabled: P,
516
+ className: "_cppay-btn _cppay-btn-secondary _cppay-connect-wallet-btn",
517
+ children: /* @__PURE__ */ jsx("span", { children: P ? "连接中..." : "💳 连接钱包" })
518
+ })
519
+ })
520
+ ] })
521
+ });
522
+ }, PaymentDialog_default = ({ open: e, onClose: t, ott: n, apikey: r, plain: i, orderId: ce, amount: a, intervalDays: o, onExpired: s, onSuccess: c, onFailed: le, onError: ue, Slots: de }) => {
523
+ let [l, fe] = useState("select"), [u, pe] = useState(!1), [d, me] = useState(!1), [he, f] = useState();
524
+ useEffect(() => {
525
+ if (l === "success") {
526
+ let e = setTimeout(() => {
527
+ p();
528
+ }, 1e3);
529
+ return () => clearTimeout(e);
530
+ }
531
+ }, [l]), useEffect(() => {
532
+ e || (fe("select"), f(void 0), pe(!1), me(!1));
533
+ }, [e]), useEffect(() => {
534
+ if (!e) return;
535
+ let t = (e) => {
536
+ e.key === "Escape" && !u && !d && p();
537
+ };
538
+ return window.addEventListener("keydown", t), () => window.removeEventListener("keydown", t);
539
+ }, [
540
+ e,
541
+ u,
542
+ d
543
+ ]);
544
+ let p = () => {
545
+ u || d || t();
546
+ };
547
+ return e ? /* @__PURE__ */ jsx("div", {
230
548
  className: "_cppay-overlay",
231
- onClick: (e) => e.target === e.currentTarget && !_ && !y && $(),
549
+ onClick: (e) => e.target === e.currentTarget && !u && !d && p(),
232
550
  children: /* @__PURE__ */ jsxs("div", {
233
551
  className: "_cppay-dialog",
234
552
  children: [/* @__PURE__ */ jsxs("div", {
235
553
  className: "_cppay-header",
236
554
  children: [/* @__PURE__ */ jsx("h2", {
237
555
  className: "_cppay-title",
238
- children: h === "select" ? "选择支付方式" : "完成支付"
556
+ children: (() => {
557
+ switch (l) {
558
+ case "success": return "支付结果";
559
+ case "expired": return "支付已过期";
560
+ case "failed": return "支付失败";
561
+ case "error": return "出错";
562
+ case "payment": return "完成支付";
563
+ default: return "选择支付方式";
564
+ }
565
+ })()
239
566
  }), /* @__PURE__ */ jsx("button", {
240
- onClick: $,
241
- disabled: _ || y,
567
+ onClick: p,
568
+ disabled: u || d,
242
569
  className: "_cppay-close-btn",
243
570
  children: /* @__PURE__ */ jsx("svg", {
244
571
  fill: "none",
@@ -252,310 +579,67 @@ var PaymentDialog_default = React.memo(({ open: t, onClose: n, apikey: a, plain:
252
579
  })
253
580
  })
254
581
  })]
255
- }), /* @__PURE__ */ jsx("div", {
256
- className: "_cppay-content",
257
- children: h === "success" ? /* @__PURE__ */ jsxs("div", {
258
- style: {
259
- textAlign: "center",
260
- padding: "2rem 0"
261
- },
262
- children: [
263
- /* @__PURE__ */ jsx("div", {
264
- style: {
265
- fontSize: "64px",
266
- marginBottom: "1rem"
267
- },
268
- children: "✅"
269
- }),
270
- /* @__PURE__ */ jsx("h3", {
271
- style: {
272
- fontSize: "1.5rem",
273
- fontWeight: 600,
274
- color: "#10b981",
275
- margin: "0 0 0.5rem 0"
276
- },
277
- children: o === "subscription" ? "授权成功!" : "支付成功!"
278
- }),
279
- /* @__PURE__ */ jsx("p", {
280
- style: {
281
- color: "#6b7280",
282
- margin: 0
283
- },
284
- children: o === "subscription" ? "订阅已激活" : "交易已完成"
285
- })
286
- ]
287
- }) : h === "select" ? /* @__PURE__ */ jsxs("div", { children: [
288
- /* @__PURE__ */ jsxs("div", {
289
- className: "_cppay-section",
290
- children: [/* @__PURE__ */ jsx("label", {
291
- className: "_cppay-label",
292
- children: "支付网络"
293
- }), /* @__PURE__ */ jsx("div", {
294
- className: "_cppay-grid",
295
- children: T.map((e) => /* @__PURE__ */ jsxs("button", {
296
- onClick: () => O(e.chain),
297
- className: `_cppay-select-btn ${D === e.chain ? "_cppay-selected" : ""}`,
298
- children: [e.icon && /* @__PURE__ */ jsx("img", {
299
- src: e.icon,
300
- alt: e.chain
301
- }), /* @__PURE__ */ jsx("span", { children: e.chain })]
302
- }, e.chain))
303
- })]
304
- }),
305
- /* @__PURE__ */ jsxs("div", {
306
- className: "_cppay-section",
307
- children: [/* @__PURE__ */ jsx("label", {
308
- className: "_cppay-label",
309
- children: "支付代币"
310
- }), /* @__PURE__ */ jsx("div", {
311
- className: "_cppay-grid",
312
- children: U.map((e) => /* @__PURE__ */ jsxs("button", {
313
- onClick: () => A(e.symbol),
314
- className: `_cppay-select-btn ${k === e.symbol ? "_cppay-selected" : ""}`,
315
- children: [e.icon && /* @__PURE__ */ jsx("img", {
316
- src: e.icon,
317
- alt: e.symbol
318
- }), /* @__PURE__ */ jsx("span", { children: e.symbol })]
319
- }, e.symbol))
320
- })]
321
- }),
322
- /* @__PURE__ */ jsx("div", {
323
- className: "_cppay-section",
324
- children: /* @__PURE__ */ jsx("div", {
325
- className: "_cppay-price-box",
326
- children: /* @__PURE__ */ jsxs("div", {
327
- className: "_cppay-price-row",
328
- children: [/* @__PURE__ */ jsx("span", {
329
- className: "_cppay-price-label",
330
- children: "支付金额"
331
- }), /* @__PURE__ */ jsxs("div", {
332
- className: "_cppay-price-amount",
333
- children: [/* @__PURE__ */ jsxs("div", {
334
- className: "_cppay-price-main",
335
- children: [
336
- q ?? "-",
337
- " ",
338
- k ?? ""
339
- ]
340
- }), /* @__PURE__ */ jsxs("div", {
341
- className: "_cppay-price-sub",
342
- children: ["≈ $", c]
343
- })]
344
- })]
345
- })
346
- })
347
- }),
348
- /* @__PURE__ */ jsxs("div", {
349
- className: "_cppay-section",
350
- children: [x && /* @__PURE__ */ jsxs("div", {
351
- className: "_cppay-error-tooltip-wrapper",
352
- onMouseEnter: () => w(!0),
353
- onMouseLeave: () => w(!1),
354
- children: [/* @__PURE__ */ jsxs("div", {
355
- className: "_cppay-error-tooltip",
356
- children: [/* @__PURE__ */ jsx("svg", {
357
- viewBox: "0 0 20 20",
358
- fill: "currentColor",
359
- children: /* @__PURE__ */ jsx("path", {
360
- fillRule: "evenodd",
361
- d: "M10 18a8 8 0 100-16 8 8 0 000 16zM8.707 7.293a1 1 0 00-1.414 1.414L8.586 10l-1.293 1.293a1 1 0 101.414 1.414L10 11.414l1.293 1.293a1 1 0 001.414-1.414L11.414 10l1.293-1.293a1 1 0 00-1.414-1.414L10 8.586 8.707 7.293z",
362
- clipRule: "evenodd"
363
- })
364
- }), /* @__PURE__ */ jsx("span", { children: x })]
365
- }), C && /* @__PURE__ */ jsx("div", {
366
- className: "_cppay-error-tooltip-full",
367
- children: x
368
- })]
369
- }), /* @__PURE__ */ jsx("button", {
370
- onClick: X,
371
- disabled: !D || !k || _,
372
- className: "_cppay-btn _cppay-btn-primary",
373
- children: _ ? "处理中..." : "继续支付"
374
- })]
375
- })
376
- ] }) : /* @__PURE__ */ jsxs("div", { children: [
377
- /* @__PURE__ */ jsx("div", {
378
- className: "_cppay-qr-container",
379
- children: /* @__PURE__ */ jsx("div", {
380
- className: "_cppay-qr-code",
381
- children: j && /* @__PURE__ */ jsx("img", {
382
- src: j,
383
- alt: "Payment QR Code",
384
- style: {
385
- width: "160px",
386
- height: "160px",
387
- display: "block"
388
- }
389
- })
390
- })
391
- }),
392
- /* @__PURE__ */ jsxs("div", {
393
- className: "_cppay-section",
394
- children: [
395
- k && /* @__PURE__ */ jsxs("div", {
396
- className: "_cppay-info-box",
397
- children: [/* @__PURE__ */ jsx("div", {
398
- className: "_cppay-info-label",
399
- children: o === "subscription" ? "授权金额" : "支付金额"
400
- }), /* @__PURE__ */ jsx("div", {
401
- className: "_cppay-info-value",
402
- children: o === "subscription" ? `${K(Y.current.approveAmount, G(k))} ${k}` : `${K(Y.current.paymentAmount, G(k))} ${k}`
403
- })]
404
- }),
405
- /* @__PURE__ */ jsxs("div", {
406
- className: "_cppay-info-box",
407
- children: [/* @__PURE__ */ jsx("div", {
408
- className: "_cppay-info-label",
409
- children: o === "subscription" ? "授权合约地址" : "支付地址"
410
- }), /* @__PURE__ */ jsxs("div", {
411
- className: "_cppay-address-row",
412
- children: [/* @__PURE__ */ jsx("code", { children: o === "subscription" ? Y.current.spenderAddress : Y.current.receiveAddress }), /* @__PURE__ */ jsx("button", {
413
- onClick: Q,
414
- className: "_cppay-copy-btn",
415
- title: "复制地址",
416
- children: /* @__PURE__ */ jsx("svg", {
417
- fill: "none",
418
- stroke: "currentColor",
419
- viewBox: "0 0 24 24",
420
- children: /* @__PURE__ */ jsx("path", {
421
- strokeLinecap: "round",
422
- strokeLinejoin: "round",
423
- strokeWidth: 2,
424
- d: "M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z"
425
- })
426
- })
427
- })]
428
- })]
429
- }),
430
- o === "subscription" && /* @__PURE__ */ jsxs("div", {
431
- className: "_cppay-info-box",
432
- style: {
433
- background: "#fff3cd",
434
- borderColor: "#ffc107"
435
- },
436
- children: [/* @__PURE__ */ jsx("div", {
437
- className: "_cppay-info-label",
438
- style: { color: "#856404" },
439
- children: "📌 订阅说明"
440
- }), /* @__PURE__ */ jsx("div", {
441
- className: "_cppay-info-value",
442
- style: {
443
- fontSize: "12px",
444
- color: "#856404"
445
- },
446
- children: "订阅支付需要授权代币给合约地址,系统将按周期自动扣款。授权后无需每次手动支付。"
447
- })]
448
- })
449
- ]
450
- }),
451
- x && /* @__PURE__ */ jsxs("div", {
452
- className: "_cppay-error-tooltip-wrapper",
453
- onMouseEnter: () => w(!0),
454
- onMouseLeave: () => w(!1),
455
- children: [/* @__PURE__ */ jsxs("div", {
456
- className: "_cppay-error-tooltip",
457
- children: [/* @__PURE__ */ jsx("svg", {
458
- viewBox: "0 0 20 20",
459
- fill: "currentColor",
460
- children: /* @__PURE__ */ jsx("path", {
461
- fillRule: "evenodd",
462
- d: "M10 18a8 8 0 100-16 8 8 0 000 16zM8.707 7.293a1 1 0 00-1.414 1.414L8.586 10l-1.293 1.293a1 1 0 101.414 1.414L10 11.414l1.293 1.293a1 1 0 001.414-1.414L11.414 10l1.293-1.293a1 1 0 00-1.414-1.414L10 8.586 8.707 7.293z",
463
- clipRule: "evenodd"
464
- })
465
- }), /* @__PURE__ */ jsx("span", { children: x })]
466
- }), C && /* @__PURE__ */ jsx("div", {
467
- className: "_cppay-error-tooltip-full",
468
- children: x
469
- })]
470
- }),
471
- !y && /* @__PURE__ */ jsx("div", {
472
- className: "_cppay-section",
473
- children: N ? /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsxs("div", {
474
- className: "_cppay-btn-container",
475
- children: [/* @__PURE__ */ jsx("button", {
476
- onClick: Oe,
477
- disabled: _,
478
- className: "_cppay-btn _cppay-btn-primary",
479
- children: _ ? o === "subscription" ? "授权中..." : "支付中..." : o === "subscription" ? "💳 钱包授权" : "💳 钱包支付"
480
- }), /* @__PURE__ */ jsx("button", {
481
- onClick: V,
482
- disabled: _,
483
- className: "_cppay-btn _cppay-btn-primary",
484
- children: "💰钱包状态"
485
- })]
486
- }), /* @__PURE__ */ jsxs("div", {
487
- style: {
488
- textAlign: "center",
489
- marginTop: "8px",
490
- fontSize: "12px",
491
- color: "#666"
492
- },
493
- children: [
494
- "已连接: ",
495
- N.slice(0, 6),
496
- "...",
497
- N.slice(-4)
498
- ]
499
- })] }) : /* @__PURE__ */ jsx("button", {
500
- onClick: V,
501
- disabled: F,
502
- className: "_cppay-btn _cppay-btn-secondary",
503
- style: {
504
- display: "flex",
505
- alignItems: "center",
506
- justifyContent: "center",
507
- gap: "0.5rem",
508
- padding: "0.75rem 1rem",
509
- width: "100%"
510
- },
511
- children: /* @__PURE__ */ jsx("span", { children: F ? "连接中..." : "💳 连接钱包" })
512
- })
513
- }),
514
- /* @__PURE__ */ jsx("div", {
515
- className: "_cppay-section",
516
- children: /* @__PURE__ */ jsx("button", {
517
- onClick: ke,
518
- disabled: y,
519
- className: "_cppay-btn _cppay-btn-primary",
520
- children: y ? "检查中..." : "我已完成支付"
521
- })
522
- }),
523
- /* @__PURE__ */ jsx("div", {
524
- className: "_cppay-section",
525
- children: /* @__PURE__ */ jsx("button", {
526
- onClick: () => g("select"),
527
- disabled: _ || y,
528
- className: "_cppay-btn _cppay-btn-text",
529
- children: "更改支付方式"
530
- })
531
- })
532
- ] })
582
+ }), /* @__PURE__ */ jsx(PaymentContent_default, {
583
+ apikey: r,
584
+ ott: n,
585
+ plain: i,
586
+ orderId: ce,
587
+ amount: a,
588
+ intervalDays: o,
589
+ onSuccess: c,
590
+ onExpired: s,
591
+ onFailed: le,
592
+ onError: ue,
593
+ Slots: de,
594
+ paymentStep: l,
595
+ onPaymentStepChange: fe,
596
+ loading: u,
597
+ isCheckingPayment: d,
598
+ error: he,
599
+ onErrorChange: f
533
600
  })]
534
601
  })
535
602
  }) : null;
536
- }), CppayContext = createContext(null);
603
+ }, CppayContext = createContext(null);
537
604
  const CppayProvider = ({ apikey: e, children: t }) => {
538
- let [n, r] = useState(!1), [i, be] = useState(null), xe = useCallback((e) => {
539
- be(e), r(!0);
540
- }, []), Se = useCallback(() => {
605
+ let [n, r] = useState(!1), [i, ce] = useState(null), a = useCallback((e) => {
606
+ ce(e), r(!0);
607
+ }, []), o = useCallback(() => {
608
+ r(!1);
609
+ }, []), s = useCallback(() => {
541
610
  r(!1);
542
- }, []), Ce = useCallback((e) => {
543
- i?.onSuccess?.(e), r(!1);
544
- }, [i]), we = useCallback((e) => {
611
+ }, []), c = useCallback((e) => {
612
+ i?.onSuccess?.(e), setTimeout(() => r(!1), 1e3);
613
+ }, [i]), le = useCallback((e) => {
614
+ i?.onExpired?.(e);
615
+ }, [i]), ue = useCallback((e) => {
616
+ i?.onFailed?.(e);
617
+ }, [i]), de = useCallback((e) => {
545
618
  i?.onError?.(e);
546
619
  }, [i]);
547
- return /* @__PURE__ */ jsxs(CppayContext.Provider, {
548
- value: { showPayment: xe },
620
+ return useEffect(() => {
621
+ if (!n) return;
622
+ let e = (e) => {
623
+ e.key === "Escape" && s();
624
+ };
625
+ return document.addEventListener("keydown", e), () => document.removeEventListener("keydown", e);
626
+ }, [n, s]), /* @__PURE__ */ jsxs(CppayContext.Provider, {
627
+ value: {
628
+ showPayment: a,
629
+ closePayment: o
630
+ },
549
631
  children: [t, i && /* @__PURE__ */ jsx(PaymentDialog_default, {
550
632
  open: n,
551
- onClose: Se,
633
+ onClose: s,
552
634
  apikey: e,
553
635
  plain: i.plain,
554
636
  orderId: i.orderId,
555
637
  amount: i.amount,
556
638
  intervalDays: i.intervalDays,
557
- onSuccess: Ce,
558
- onError: we
639
+ onSuccess: c,
640
+ onExpired: le,
641
+ onFailed: ue,
642
+ onError: de
559
643
  })]
560
644
  });
561
645
  }, useCppayPayment = () => {
@@ -564,4 +648,4 @@ const CppayProvider = ({ apikey: e, children: t }) => {
564
648
  return e;
565
649
  };
566
650
  injectStyle(payment_dialog_default);
567
- export { CppayProvider, PaymentDialog_default as PaymentDialog, useCppayPayment };
651
+ export { CppayProvider, PaymentContent_default as PaymentContent, PaymentDialog_default as PaymentDialog, useCppayPayment };