cppay-sdk 0.0.2-beta.31 → 0.0.2-beta.33

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-BPtRBPjB.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 injectStyle, r as payment_dialog_default, t as getLocaleMessages } from "./locales-DGvDecya.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: h, orderId: g, amount: _, intervalDays: ge, locale: _e = "zh-CN", onSuccess: ve, onExpired: ye, onFailed: be, onError: v, Slots: xe, paymentStep: y, onPaymentStepChange: b, loading: x = !1, isCheckingPayment: S = !1, error: C, onErrorChange: w }) => {
13
+ let T = useMemo(() => new cppay_default(t, n), [t, n]), E = useMemo(() => getLocaleMessages(_e), [_e]), [D, Se] = useState([]), [O, k] = useState(), [A, j] = useState(), [M, N] = useState(), [P, F] = useState(), [I, L] = useState(!1), [R, z] = useState(), [B, Ce] = useState(""), [V, we] = useState(!1), [Te, H] = useState(!1), U = useRef(null), W = useRef(null), G = useRef(null);
14
14
  useEffect(() => {
15
- typeof window < "u" && !z.current && (z.current = createAppKit({
15
+ typeof window < "u" && !U.current && (U.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
+ }), F(U.current.getAddress()), z(U.current.getProvider("eip155")), U.current.subscribeAccount((e) => {
37
+ e.isConnected ? F(e.address) : (F(void 0), z(void 0));
38
+ }), U.current.subscribeProviders((e) => {
39
39
  let t = e?.eip155;
40
- R(t);
40
+ z(t);
41
41
  }));
42
42
  }, []);
43
- let V = async () => {
43
+ let Ee = async () => {
44
44
  try {
45
- I(!0), S(void 0), z.current && await z.current.open();
45
+ L(!0), w?.(void 0), U.current && await U.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 : E.walletConnectionFailed;
49
+ w?.(t), v?.(e);
48
50
  } finally {
49
- I(!1);
51
+ L(!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
+ }, K = useMemo(() => D.find((e) => e.chain === O), [D, O]), q = useMemo(() => K?.tokens || [], [K]), J = useMemo(() => q.find((e) => e.symbol === A), [q, A]), Y = (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, X = (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
+ }, De = (e) => {
65
+ if (e <= 0) return E.expired;
66
+ let t = Math.floor(e / 3600), n = Math.floor(e % 3600 / 60), r = e % 60;
67
+ return t > 0 ? `${t}${E.hours}${n}${E.minutes}${r}${E.seconds}` : `${n}${E.minutes}${r}${E.seconds}`;
68
+ }, Oe = (e) => {
69
+ G.current && clearInterval(G.current);
70
+ let t = () => {
71
+ let t = e - Math.floor(Date.now() / 1e3);
72
+ Ce(De(t)), t <= 0 && (b("expired"), ke());
73
+ };
74
+ t(), G.current = setInterval(t, 1e3);
75
+ }, ke = () => {
76
+ G.current &&= (clearInterval(G.current), null);
77
+ }, Z = useMemo(() => {
78
+ if (!A || !J) return "0";
79
+ let e = parseFloat(J.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 = Y(A);
82
+ return X((parseFloat(_) / e).toFixed(t), t);
68
83
  }, [
69
- c,
70
- k,
71
- W
72
- ]), Te = async () => {
84
+ _,
85
+ A,
86
+ J
87
+ ]), Ae = 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
+ w?.(void 0);
90
+ let e = await T.getSupportedChains();
91
+ Se(e), e.length > 0 && k(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 : E.loadPaymentNetworkFailed;
94
+ w?.(t), v?.(e);
81
95
  }
82
- }, J = async (e) => {
83
- if (L) try {
84
- await L.request({
96
+ }, je = async (e) => {
97
+ if (R) try {
98
+ await R.request({
85
99
  method: "wallet_switchEthereumChain",
86
100
  params: [{ chainId: `0x${e.toString(16)}` }]
87
101
  });
88
102
  } catch (e) {
89
- throw e.code === 4902 ? Error("请在钱包中添加该网络") : e;
103
+ throw e.code === 4902 ? Error(E.pleaseAddNetwork) : 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
+ }, Me = async () => {
106
+ if (!(!P || !R || !Q.current || !J || !K)) try {
107
+ let e = Q.current;
108
+ await je(K.chainId);
96
109
  let t = createWalletClient({
97
- account: N,
98
- transport: custom(L)
110
+ account: P,
111
+ transport: custom(R)
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
+ J.address ? await t.writeContract({
114
+ address: J.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, J.decimals)],
130
+ chain: null
131
+ }) : await t.sendTransaction({
132
+ to: e.receiveAddress,
133
+ value: parseUnits(e.paymentAmount, J.decimals),
134
+ chain: null
135
+ }), N(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 : E.walletPaymentFailed;
139
+ w?.(t), v?.(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
+ }, Ne = async () => {
142
+ if (!(!P || !R || !Q.current || !J || !K)) try {
143
+ let e = Q.current;
144
+ await je(K.chainId);
138
145
  let t = createWalletClient({
139
- account: N,
140
- transport: custom(L)
146
+ account: P,
147
+ transport: custom(R)
141
148
  });
142
- if (!W.address) throw Error("订阅支付不支持原生代币");
143
- let n = await t.writeContract({
144
- address: W.address,
149
+ if (!J.address) throw Error(E.subscriptionDoesNotSupportNative);
150
+ await t.writeContract({
151
+ address: J.address,
145
152
  abi: [{
146
153
  name: "approve",
147
154
  type: "function",
@@ -156,89 +163,430 @@ 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, J.decimals)],
160
167
  chain: null
161
- });
162
- console.log("授权交易哈希:", n), v(!1), b(!0), Z(e.subscriptionId);
168
+ }), N(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 : E.walletPaymentFailed;
172
+ w?.(t), v?.(e);
165
173
  }
166
- }, Oe = async () => {
167
- if (!N) {
168
- let e = "请先连接钱包";
169
- S(e), p?.(Error(e));
174
+ }, Pe = async () => {
175
+ if (!P) {
176
+ let e = E.pleaseConnectWallet;
177
+ w?.(e), v?.(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
+ h === "one-time" ? await Me() : h === "subscription" && await Ne();
181
+ }, Q = useRef(null), Fe = async () => {
182
+ if (!(!O || !A)) try {
183
+ w?.(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
+ h === "one-time" ? (Q.current = await T.createOnetimePayment({
186
+ paymentChain: O,
187
+ paymentToken: A,
188
+ orderId: g,
189
+ amount: Z
190
+ }), e = `${O.toLowerCase()}:${Q.current.receiveAddress}?amount=${Q.current.paymentAmount}`, Oe(Q.current.expireAt), $({ paymentId: Q.current.paymentId })) : h === "subscription" && (Q.current = await T.createSubscriptionPayment({
191
+ paymentChain: O,
192
+ paymentToken: A,
193
+ orderId: g,
194
+ amountOfUsd: Z,
195
+ intervalDays: ge || 30
196
+ }), e = `${O.toLowerCase()}:${Q.current.spenderAddress}?amount=${Q.current.approveAmount}`, Oe(Q.current.expireAt), $({ subscriptionId: Q.current.subscriptionId })), b("payment"), N(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);
202
+ let t = e instanceof Error ? e.message : E.createPaymentFailed;
203
+ w?.(t), v?.(e);
197
204
  }
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);
203
- }
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
+ W.current?.unsubscribe();
207
+ let t = () => defer(() => h === "subscription" ? T.checkSubscriptionPaymentStatus(e) : T.checkOnetimePaymentStatus(e)).pipe(timeout(15e3), retry({ delay: 2e3 }));
208
+ W.current = t().pipe(expand((e) => e.status === "pending" ? timer(2e3).pipe(switchMap(() => t())) : EMPTY), tap((e) => {
209
+ (e.status === "paid" || e.status === "approved") && (b("success"), ve?.(e)), e.status === "expired" && (b("expired"), ye?.(e)), e.status === "failed" && (b("failed"), be?.(e));
210
+ })).subscribe({
211
+ error: (e) => {
212
+ if (Q.current) {
213
+ let t = e instanceof Error ? e.message : E.checkPaymentStatusFailed;
214
+ b("error"), w?.(t), v?.(e);
215
+ }
216
+ },
217
+ complete: () => {
218
+ W.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
+ D.length === 0 && Ae();
224
+ }, []), useEffect(() => {
225
+ q.length > 0 && j(q[0].symbol);
226
+ }, [q]), useEffect(() => (g && $({ orderId: g }), () => {
227
+ W.current?.unsubscribe(), ke();
228
+ }), [g]), /* @__PURE__ */ jsx("div", {
229
+ className: "_cppay-content",
230
+ children: y === "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: h === "subscription" ? E.authorizationSuccess : E.paymentSuccess
240
+ }),
241
+ /* @__PURE__ */ jsx("p", {
242
+ className: "_cppay-state-message",
243
+ children: h === "subscription" ? E.subscriptionActivated : E.transactionCompleted
244
+ })
245
+ ]
246
+ }) : y === "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: E.paymentExpired
256
+ }),
257
+ /* @__PURE__ */ jsx("button", {
258
+ onClick: () => b("select"),
259
+ disabled: x || S,
260
+ className: "_cppay-btn _cppay-btn-text",
261
+ children: E.returnButton
262
+ })
263
+ ]
264
+ }) : y === "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: C || E.error
272
+ })]
273
+ }) : y === "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: E.paymentFailed
281
+ })]
282
+ }) : y === "select" ? /* @__PURE__ */ jsxs("div", { children: [
283
+ xe?.ChooseTop,
284
+ /* @__PURE__ */ jsxs("div", {
285
+ className: "_cppay-section",
286
+ children: [/* @__PURE__ */ jsx("label", {
287
+ className: "_cppay-label",
288
+ children: E.paymentNetwork
289
+ }), /* @__PURE__ */ jsx("div", {
290
+ className: "_cppay-grid",
291
+ children: D.map((e) => /* @__PURE__ */ jsxs("button", {
292
+ onClick: () => k(e.chain),
293
+ className: `_cppay-select-btn ${O === 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: E.paymentToken
306
+ }), /* @__PURE__ */ jsx("div", {
307
+ className: "_cppay-grid",
308
+ children: q.map((e) => /* @__PURE__ */ jsxs("button", {
309
+ onClick: () => j(e.symbol),
310
+ className: `_cppay-select-btn ${A === 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
+ xe?.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: E.paymentAmount
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
+ A ?? ""
336
+ ]
337
+ }), /* @__PURE__ */ jsxs("div", {
338
+ className: "_cppay-price-sub",
339
+ children: ["≈ $", _]
340
+ })]
341
+ })]
342
+ })
343
+ })
344
+ }),
345
+ /* @__PURE__ */ jsxs("div", {
346
+ className: "_cppay-section",
347
+ children: [C && /* @__PURE__ */ jsxs("div", {
348
+ className: "_cppay-error-tooltip-wrapper",
349
+ onMouseEnter: () => H(!0),
350
+ onMouseLeave: () => H(!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: C })]
362
+ }), Te && /* @__PURE__ */ jsx("div", {
363
+ className: "_cppay-error-tooltip-full",
364
+ children: C
365
+ })]
366
+ }), /* @__PURE__ */ jsx("button", {
367
+ onClick: Fe,
368
+ disabled: !O || !A || x,
369
+ className: "_cppay-btn _cppay-btn-primary",
370
+ children: x ? E.processing : E.continuePayment
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: M && /* @__PURE__ */ jsx("img", {
379
+ src: M,
380
+ alt: "Payment QR Code",
381
+ className: "_cppay-qr-image"
382
+ })
383
+ })
384
+ }),
385
+ /* @__PURE__ */ jsxs("div", {
386
+ className: "_cppay-section",
387
+ children: [
388
+ J && /* @__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: h === "subscription" ? E.authorizationAmount : E.paymentAmount
397
+ }), /* @__PURE__ */ jsxs("div", {
398
+ className: "_cppay-info-value _cppay-info-value-flex",
399
+ children: [/* @__PURE__ */ jsx("span", { children: h === "subscription" ? `${X(Q.current.approveAmount, Y(J.symbol))} ${J.symbol}` : `${X(Q.current.paymentAmount, Y(J.symbol))} ${J.symbol}` }), /* @__PURE__ */ jsxs("span", { children: ["≈ $", _] })]
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: h === "subscription" ? E.authorizationContractAddress : E.paymentAddress }), B && /* @__PURE__ */ jsxs("span", {
411
+ className: "_cppay-countdown",
412
+ children: ["⏰ ", B]
413
+ })]
414
+ }), /* @__PURE__ */ jsxs("div", {
415
+ className: "_cppay-address-row",
416
+ children: [/* @__PURE__ */ jsx("code", { children: h === "subscription" ? Q.current.spenderAddress : Q.current.receiveAddress }), /* @__PURE__ */ jsx("button", {
417
+ onClick: async () => {
418
+ if (!Q.current) return;
419
+ let e = h === "subscription" ? Q.current.spenderAddress : Q.current.receiveAddress;
420
+ if (e) try {
421
+ await navigator.clipboard.writeText(e), we(!0), setTimeout(() => {
422
+ we(!1);
423
+ }, 2e3);
424
+ } catch (e) {
425
+ console.error("复制失败:", e);
426
+ }
427
+ },
428
+ className: `_cppay-copy-btn ${V ? "_cppay-copy-success" : ""}`,
429
+ title: V ? E.copied : E.copyAddress,
430
+ children: V ? /* @__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
+ h === "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: E.subscriptionNotice
459
+ }), /* @__PURE__ */ jsx("div", {
460
+ className: "_cppay-info-value _cppay-subscription-message",
461
+ children: E.subscriptionNoticeMessage
462
+ })]
463
+ })
464
+ ]
465
+ }),
466
+ C && /* @__PURE__ */ jsxs("div", {
467
+ className: "_cppay-error-tooltip-wrapper",
468
+ onMouseEnter: () => H(!0),
469
+ onMouseLeave: () => H(!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: C })]
481
+ }), Te && /* @__PURE__ */ jsx("div", {
482
+ className: "_cppay-error-tooltip-full",
483
+ children: C
484
+ })]
485
+ }),
486
+ !S && /* @__PURE__ */ jsx("div", {
487
+ className: "_cppay-section",
488
+ children: P ? /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("button", {
489
+ onClick: Pe,
490
+ disabled: x,
491
+ className: "_cppay-btn _cppay-btn-primary",
492
+ children: x ? h === "subscription" ? E.authorizing : E.processing : h === "subscription" ? `💳 ${E.connectWallet}` : `💳 ${E.walletPay}`
493
+ }), /* @__PURE__ */ jsxs("button", {
494
+ onClick: Ee,
495
+ disabled: x,
496
+ className: "_cppay-btn _cppay-wallet-address-btn",
497
+ title: E.clickToModifyWallet,
498
+ children: [/* @__PURE__ */ jsxs("span", {
499
+ className: "_cppay-wallet-address-text",
500
+ children: [
501
+ P.slice(0, 10),
502
+ "...",
503
+ P.slice(-4)
504
+ ]
505
+ }), /* @__PURE__ */ jsx("svg", {
506
+ className: "_cppay-wallet-arrow",
507
+ viewBox: "0 0 24 24",
508
+ fill: "none",
509
+ stroke: "currentColor",
510
+ strokeWidth: "2",
511
+ children: /* @__PURE__ */ jsx("polyline", { points: "6 9 12 15 18 9" })
512
+ })]
513
+ })] }) : /* @__PURE__ */ jsx("button", {
514
+ onClick: Ee,
515
+ disabled: I,
516
+ className: "_cppay-btn _cppay-btn-secondary _cppay-connect-wallet-btn",
517
+ children: /* @__PURE__ */ jsx("span", { children: I ? E.processing : `💳 ${E.connectWallet}` })
518
+ })
519
+ }),
520
+ /* @__PURE__ */ jsx("div", {
521
+ className: "_cppay-section",
522
+ children: /* @__PURE__ */ jsx("button", {
523
+ onClick: () => {
524
+ b("payment");
525
+ },
526
+ disabled: S,
527
+ className: "_cppay-btn _cppay-btn-primary",
528
+ children: S ? E.checking : E.completedPayment
529
+ })
530
+ }),
531
+ /* @__PURE__ */ jsx("hr", { className: "_cppay-divider" }),
532
+ /* @__PURE__ */ jsx("div", {
533
+ className: "_cppay-section",
534
+ children: /* @__PURE__ */ jsx("button", {
535
+ onClick: () => b("select"),
536
+ disabled: x || S,
537
+ className: "_cppay-btn _cppay-btn-text",
538
+ children: E.changePaymentMethod
539
+ })
540
+ })
541
+ ] })
542
+ });
543
+ }, PaymentDialog_default = ({ open: e, onClose: t, ott: n, apikey: i, plain: a, orderId: o, amount: s, intervalDays: c, locale: l, onExpired: se, onSuccess: u, onFailed: ce, onError: le, Slots: ue }) => {
544
+ let [d, de] = useState("select"), [f, fe] = useState(!1), [p, pe] = useState(!1), [me, he] = useState();
545
+ useEffect(() => {
546
+ if (d === "success") {
547
+ let e = setTimeout(() => {
548
+ m();
549
+ }, 1e3);
550
+ return () => clearTimeout(e);
551
+ }
552
+ }, [d]), useEffect(() => {
553
+ e || (de("select"), he(void 0), fe(!1), pe(!1));
554
+ }, [e]), useEffect(() => {
555
+ if (!e) return;
556
+ let t = (e) => {
557
+ e.key === "Escape" && !f && !p && m();
558
+ };
559
+ return window.addEventListener("keydown", t), () => window.removeEventListener("keydown", t);
560
+ }, [
561
+ e,
562
+ f,
563
+ p
564
+ ]);
565
+ let m = () => {
566
+ f || p || t();
567
+ }, h = useMemo(() => getLocaleMessages(l), [l]);
568
+ return e ? /* @__PURE__ */ jsx("div", {
230
569
  className: "_cppay-overlay",
231
- onClick: (e) => e.target === e.currentTarget && !_ && !y && $(),
570
+ onClick: (e) => e.target === e.currentTarget && !f && !p && m(),
232
571
  children: /* @__PURE__ */ jsxs("div", {
233
572
  className: "_cppay-dialog",
234
573
  children: [/* @__PURE__ */ jsxs("div", {
235
574
  className: "_cppay-header",
236
575
  children: [/* @__PURE__ */ jsx("h2", {
237
576
  className: "_cppay-title",
238
- children: h === "select" ? "选择支付方式" : "完成支付"
577
+ children: (() => {
578
+ switch (d) {
579
+ case "success": return h.paymentResult;
580
+ case "expired": return h.paymentExpired;
581
+ case "failed": return h.paymentFailed;
582
+ case "error": return h.error;
583
+ case "payment": return h.completePayment;
584
+ default: return h.selectPaymentMethod;
585
+ }
586
+ })()
239
587
  }), /* @__PURE__ */ jsx("button", {
240
- onClick: $,
241
- disabled: _ || y,
588
+ onClick: m,
589
+ disabled: f || p,
242
590
  className: "_cppay-close-btn",
243
591
  children: /* @__PURE__ */ jsx("svg", {
244
592
  fill: "none",
@@ -252,310 +600,68 @@ var PaymentDialog_default = React.memo(({ open: t, onClose: n, apikey: a, plain:
252
600
  })
253
601
  })
254
602
  })]
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
- ] })
603
+ }), /* @__PURE__ */ jsx(PaymentContent_default, {
604
+ apikey: i,
605
+ ott: n,
606
+ plain: a,
607
+ orderId: o,
608
+ amount: s,
609
+ intervalDays: c,
610
+ locale: l,
611
+ onSuccess: u,
612
+ onExpired: se,
613
+ onFailed: ce,
614
+ onError: le,
615
+ Slots: ue,
616
+ paymentStep: d,
617
+ onPaymentStepChange: de,
618
+ loading: f,
619
+ isCheckingPayment: p,
620
+ error: me,
621
+ onErrorChange: he
533
622
  })]
534
623
  })
535
624
  }) : null;
536
- }), CppayContext = createContext(null);
625
+ }, CppayContext = createContext(null);
537
626
  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(() => {
627
+ let [n, r] = useState(!1), [i, a] = useState(null), o = useCallback((e) => {
628
+ a(e), r(!0);
629
+ }, []), s = useCallback(() => {
630
+ r(!1);
631
+ }, []), c = useCallback(() => {
541
632
  r(!1);
542
- }, []), Ce = useCallback((e) => {
543
- i?.onSuccess?.(e), r(!1);
544
- }, [i]), we = useCallback((e) => {
633
+ }, []), l = useCallback((e) => {
634
+ i?.onSuccess?.(e), setTimeout(() => r(!1), 1e3);
635
+ }, [i]), se = useCallback((e) => {
636
+ i?.onExpired?.(e);
637
+ }, [i]), u = useCallback((e) => {
638
+ i?.onFailed?.(e);
639
+ }, [i]), ce = useCallback((e) => {
545
640
  i?.onError?.(e);
546
641
  }, [i]);
547
- return /* @__PURE__ */ jsxs(CppayContext.Provider, {
548
- value: { showPayment: xe },
642
+ return useEffect(() => {
643
+ if (!n) return;
644
+ let e = (e) => {
645
+ e.key === "Escape" && c();
646
+ };
647
+ return document.addEventListener("keydown", e), () => document.removeEventListener("keydown", e);
648
+ }, [n, c]), /* @__PURE__ */ jsxs(CppayContext.Provider, {
649
+ value: {
650
+ showPayment: o,
651
+ closePayment: s
652
+ },
549
653
  children: [t, i && /* @__PURE__ */ jsx(PaymentDialog_default, {
550
654
  open: n,
551
- onClose: Se,
655
+ onClose: c,
552
656
  apikey: e,
553
657
  plain: i.plain,
554
658
  orderId: i.orderId,
555
659
  amount: i.amount,
556
660
  intervalDays: i.intervalDays,
557
- onSuccess: Ce,
558
- onError: we
661
+ onSuccess: l,
662
+ onExpired: se,
663
+ onFailed: u,
664
+ onError: ce
559
665
  })]
560
666
  });
561
667
  }, useCppayPayment = () => {
@@ -564,4 +670,4 @@ const CppayProvider = ({ apikey: e, children: t }) => {
564
670
  return e;
565
671
  };
566
672
  injectStyle(payment_dialog_default);
567
- export { CppayProvider, PaymentDialog_default as PaymentDialog, useCppayPayment };
673
+ export { CppayProvider, PaymentContent_default as PaymentContent, PaymentDialog_default as PaymentDialog, useCppayPayment };