cppay-sdk 0.0.2-beta.8 → 0.0.2

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,229 +1,904 @@
1
- import { t as cppay_default } from "./cppay-Oxm_gXCa.js";
2
- import { n as payment_dialog_default, t as injectStyle } from "./inject-style-qX_0AjjE.js";
3
- import React, { useEffect, useMemo, useState } from "react";
4
- import { jsx, jsxs } from "react/jsx-runtime";
5
- var PaymentDialog_default = React.memo(({ open: o, onClose: s, apiKey: c, orderId: l, amount: u, onSuccess: d, onError: f }) => {
6
- let p = useMemo(() => new cppay_default(c), [c]), [m, h] = useState("select"), [g, _] = useState(!1), [v, y] = useState([]), [b, x] = useState(""), [S, C] = useState(""), [w, T] = useState(null), E = useMemo(() => v.find((t) => t.chain === b), [v, b]), D = useMemo(() => E?.tokens || [], [E]), O = useMemo(() => D.find((t) => t.symbol === S), [D, S]), k = useMemo(() => S ? (parseFloat(u) / 1).toFixed(6) : "0", [
7
- u,
8
- S,
9
- 1
10
- ]), A = async () => {
1
+ import { t as cppay_default } from "./cppay-Db8t1Cra.js";
2
+ import { n as injectStyle, r as payment_dialog_default, t as getLocaleMessages } from "./locales-BZF2EQ2A.js";
3
+ import * as QRCode from "qrcode";
4
+ import { EMPTY, defer, timer } from "rxjs";
5
+ import { expand, retry, switchMap, tap, timeout } from "rxjs/operators";
6
+ import { createWalletClient, custom, parseUnits } from "viem";
7
+ import { arbitrum, base, bsc, mainnet, optimism, polygon } from "viem/chains";
8
+ import { createAppKit } from "@reown/appkit";
9
+ import { EthersAdapter } from "@reown/appkit-adapter-ethers";
10
+ import { createContext, useCallback, useContext, useEffect, useMemo, useRef, useState } from "react";
11
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
12
+ var PaymentContent_default = ({ apikey: t, ott: n, plain: u, orderId: xe, amount: d, intervalDays: f, remark: Se, locale: Ce, onSuccess: we, onExpired: Te, onFailed: Ee, onError: p, Slots: m, onPaymentStepChange: De }) => {
13
+ let h = useMemo(() => new cppay_default(t, n), [t, n]), g = useMemo(() => getLocaleMessages(Ce), [Ce]), [_, v] = useState("select"), y = useMemo(() => _ === "checking", [_]), [b, x] = useState(!1), [S, C] = useState(), [w, Oe] = useState([]), [T, E] = useState(), [D, O] = useState(), [ke, k] = useState(), [A, j] = useState(), [Ae, je] = useState(!1), [M, N] = useState(), [Me, Ne] = useState(""), [P, F] = useState(!1), [Pe, I] = useState(!1), [L, R] = useState(""), z = useRef(null), B = useRef(null), V = useRef(null), H = useRef(null), U = useRef("");
14
+ useEffect(() => {
15
+ typeof window < "u" && !z.current && (z.current = createAppKit({
16
+ debug: !1,
17
+ enableNetworkSwitch: !1,
18
+ adapters: [new EthersAdapter()],
19
+ projectId: "8d2e1854d3f1782e45aa15fbd8938894",
20
+ allowUnsupportedChain: !0,
21
+ networks: [
22
+ mainnet,
23
+ bsc,
24
+ polygon,
25
+ arbitrum,
26
+ optimism,
27
+ base
28
+ ],
29
+ metadata: {
30
+ name: "Cppay",
31
+ description: "Cppay Payment Gateway",
32
+ url: window.location.origin,
33
+ icons: ["https://cppay.com/icon.png"]
34
+ },
35
+ features: { analytics: !1 }
36
+ }), j(z.current.getAddress()), N(z.current.getProvider("eip155")), z.current.subscribeAccount((e) => {
37
+ e.isConnected ? j(e.address) : (j(void 0), N(void 0));
38
+ }), z.current.subscribeProviders((e) => {
39
+ let t = e?.eip155;
40
+ N(t);
41
+ }));
42
+ }, []), useEffect(() => {
43
+ De?.(_);
44
+ }, [_]);
45
+ let Fe = async () => {
11
46
  try {
12
- _(!0);
13
- let t = await p.getSupportedChains();
14
- y(t), t.length > 0 && x(t[0].chain);
15
- } catch (t) {
16
- f?.(t);
47
+ je(!0), C(void 0), z.current && await z.current.open();
48
+ } catch (e) {
49
+ console.error("钱包连接失败:", e), C(e instanceof Error ? e.message : g.walletConnectionFailed), p?.(e);
17
50
  } finally {
18
- _(!1);
51
+ je(!1);
19
52
  }
20
- }, j = async () => {
21
- if (!(!b || !S)) try {
22
- _(!0);
23
- let t = await p.createPayment({
24
- paymentChain: b,
25
- paymentToken: S,
26
- orderId: l,
27
- amount: k
28
- });
29
- T({
30
- paymentId: t.paymentId,
31
- paymentAmount: t.paymentAmount,
32
- receiveAddress: O?.receiveAddresses[0] || ""
33
- }), h("payment");
34
- } catch (t) {
35
- f?.(t);
53
+ }, W = useMemo(() => w.find((e) => e.chain === T), [w, T]), G = useMemo(() => W?.tokens || [], [W]), K = useMemo(() => G.find((e) => e.symbol === D), [G, D]), q = (e) => [
54
+ "USDT",
55
+ "USDC",
56
+ "BUSD",
57
+ "DAI",
58
+ "TUSD",
59
+ "USDD",
60
+ "FDUSD"
61
+ ].includes(e.toUpperCase()) ? 2 : 6, J = (e, t) => {
62
+ let n = parseFloat(e);
63
+ return isNaN(n) ? "0" : n.toFixed(t).replace(/\.?0+$/, "");
64
+ }, Ie = (e) => {
65
+ if (e <= 0) return g.expired;
66
+ let t = Math.floor(e / 3600), n = Math.floor(e % 3600 / 60), r = e % 60, i = (e) => e.toString().padStart(2, "0");
67
+ return t > 0 ? `${t}:${i(n)}:${i(r)}` : `${n}:${i(r)}`;
68
+ }, Y = (e) => {
69
+ V.current && clearInterval(V.current);
70
+ let t = () => {
71
+ if (_ === "checking") {
72
+ X();
73
+ return;
74
+ }
75
+ let t = e - Math.floor(Date.now() / 1e3);
76
+ Ne(Ie(t)), t <= 0 && X();
77
+ };
78
+ t(), V.current = setInterval(t, 1e3);
79
+ }, X = () => {
80
+ V.current &&= (clearInterval(V.current), null);
81
+ }, Z = useMemo(() => {
82
+ if (!D || !K) return "0";
83
+ let e = parseFloat(K.price);
84
+ if (isNaN(e) || e === 0) return "0";
85
+ let t = q(D);
86
+ return J((parseFloat(d) / e).toFixed(t), t);
87
+ }, [
88
+ d,
89
+ D,
90
+ K
91
+ ]), Le = async () => {
92
+ try {
93
+ x(!0), C(void 0);
94
+ let e = await h.getSupportedChains();
95
+ Oe(e), e.length > 0 && E(e[0].chain);
96
+ } catch (e) {
97
+ C(e instanceof Error ? e.message : g.loadPaymentNetworkFailed), p?.(e);
36
98
  } finally {
37
- _(!1);
99
+ x(!1);
100
+ }
101
+ }, Re = async (e) => {
102
+ if (M) try {
103
+ await M.request({
104
+ method: "wallet_switchEthereumChain",
105
+ params: [{ chainId: `0x${e.toString(16)}` }]
106
+ });
107
+ } catch (e) {
108
+ throw e.code === 4902 ? Error(g.pleaseAddNetwork) : e;
38
109
  }
39
- }, M = async () => {
40
- if (w) try {
41
- _(!0), await p.checkPaymentStatus(w.paymentId), d?.(w.paymentId), P();
42
- } catch (t) {
43
- f?.(t);
110
+ }, ze = async () => {
111
+ if (!(!A || !M || !H.current || !K || !W)) try {
112
+ x(!0);
113
+ let e = H.current;
114
+ await Re(W.chainId);
115
+ let t = createWalletClient({
116
+ account: A,
117
+ transport: custom(M)
118
+ });
119
+ if (K.address) {
120
+ let n = await t.writeContract({
121
+ address: K.address,
122
+ abi: [{
123
+ name: "transfer",
124
+ type: "function",
125
+ stateMutability: "nonpayable",
126
+ inputs: [{
127
+ name: "to",
128
+ type: "address"
129
+ }, {
130
+ name: "amount",
131
+ type: "uint256"
132
+ }],
133
+ outputs: [{ type: "bool" }]
134
+ }],
135
+ functionName: "transfer",
136
+ args: [e.receiveAddress, parseUnits(e.paymentAmount, K.decimals)],
137
+ chain: null
138
+ });
139
+ console.log("转账交易哈希:", n), R(n), U.current = n;
140
+ } else {
141
+ let n = await t.sendTransaction({
142
+ to: e.receiveAddress,
143
+ value: parseUnits(e.paymentAmount, K.decimals),
144
+ chain: null
145
+ });
146
+ console.log("转账交易哈希:", n), R(n), U.current = n;
147
+ }
148
+ x(!1), v("checking"), Q({ paymentId: e.paymentId });
149
+ } catch (e) {
150
+ console.error("钱包支付失败:", e), C(e instanceof Error ? e.message : g.walletPaymentFailed), p?.(e), x(!1);
151
+ }
152
+ }, Be = async () => {
153
+ if (!(!A || !M || !H.current || !K || !W)) try {
154
+ x(!0);
155
+ let e = H.current;
156
+ await Re(W.chainId);
157
+ let t = createWalletClient({
158
+ account: A,
159
+ transport: custom(M)
160
+ });
161
+ if (!K.address) throw Error(g.subscriptionDoesNotSupportNative);
162
+ let n = await t.writeContract({
163
+ address: K.address,
164
+ abi: [{
165
+ name: "approve",
166
+ type: "function",
167
+ stateMutability: "nonpayable",
168
+ inputs: [{
169
+ name: "spender",
170
+ type: "address"
171
+ }, {
172
+ name: "amount",
173
+ type: "uint256"
174
+ }],
175
+ outputs: [{ type: "bool" }]
176
+ }],
177
+ functionName: "approve",
178
+ args: [e.spenderAddress, parseUnits(e.approveAmount, K.decimals)],
179
+ chain: null
180
+ });
181
+ console.log("授权交易哈希:", n), R(n), U.current = n, x(!1), v("checking"), Q({ subscriptionId: e.subscriptionId });
182
+ } catch (e) {
183
+ console.error("钱包授权失败:", e), C(e instanceof Error ? e.message : g.walletPaymentFailed), p?.(e), x(!1);
184
+ }
185
+ }, Ve = async () => {
186
+ if (!A) {
187
+ let e = g.pleaseConnectWallet;
188
+ C(e), p?.(Error(e));
189
+ return;
190
+ }
191
+ u === "instant" ? await ze() : u === "subscription" && await Be();
192
+ }, He = async () => {
193
+ if (!(!T || !D)) try {
194
+ x(!0), C(void 0);
195
+ let e = "";
196
+ if (u === "instant") H.current = await h.createOnetimePayment({
197
+ paymentChain: T,
198
+ paymentToken: D,
199
+ orderId: xe,
200
+ amount: Z,
201
+ remark: Se
202
+ }), e = `${T.toLowerCase()}:${H.current.receiveAddress}?amount=${H.current.paymentAmount}`, Y(H.current.expireAt), Ke(H.current.paymentId, "instant");
203
+ else if (u === "subscription") {
204
+ if (!f) throw Error(`Invalid Renewal Days: ${f ?? ""}`);
205
+ H.current = await h.createSubscriptionPayment({
206
+ paymentChain: T,
207
+ paymentToken: D,
208
+ orderId: xe,
209
+ amountOfUsd: Z,
210
+ intervalDays: f
211
+ }), e = `${T.toLowerCase()}:${H.current.spenderAddress}?amount=${H.current.approveAmount}`, Y(H.current.expireAt), Ke(H.current.subscriptionId, "subscription");
212
+ }
213
+ v("payment"), k(await QRCode.toDataURL(e, {
214
+ width: 200,
215
+ margin: 2,
216
+ errorCorrectionLevel: "H"
217
+ }));
218
+ } catch (e) {
219
+ C(e instanceof Error ? e.message : g.createPaymentFailed), p?.(e);
44
220
  } finally {
45
- _(!1);
221
+ x(!1);
222
+ }
223
+ }, Ue = () => {
224
+ H.current && (v("checking"), C(void 0), u === "instant" ? Q({ paymentId: H.current.paymentId }) : u === "subscription" && Q({ subscriptionId: H.current.subscriptionId }));
225
+ }, Q = (e) => {
226
+ B.current?.unsubscribe();
227
+ let t = () => defer(() => u === "subscription" ? h.checkSubscriptionPaymentStatus(e) : h.checkOnetimePaymentStatus(e)).pipe(timeout(15e3), retry({ delay: 2e3 }));
228
+ B.current = t().pipe(expand((e) => e.status === "pending" ? timer(2e3).pipe(switchMap(() => t())) : EMPTY), tap((e) => {
229
+ if (!H.current && u === "instant") {
230
+ let t = e;
231
+ H.current = {
232
+ paymentId: t.paymentId,
233
+ orderId: t.orderId,
234
+ paymentChain: t.chain,
235
+ paymentToken: t.token,
236
+ paymentAmount: t.payAmount,
237
+ receiveAddress: t.receiveAddress,
238
+ expireAt: t.expireAt
239
+ }, E(t.chain), O(t.token), Y(t.expireAt);
240
+ let n = `${t.chain.toLowerCase()}:${t.receiveAddress}?amount=${t.payAmount}`;
241
+ QRCode.toDataURL(n, {
242
+ width: 200,
243
+ margin: 2,
244
+ errorCorrectionLevel: "H"
245
+ }).then((e) => {
246
+ k(e), v("payment");
247
+ }).catch((e) => {
248
+ console.error("生成二维码失败:", e), v("payment");
249
+ });
250
+ }
251
+ if (!H.current && u === "subscription") {
252
+ let t = e;
253
+ H.current = {
254
+ subscriptionId: t.subscriptionId,
255
+ orderId: t.orderId,
256
+ paymentChain: t.chain,
257
+ paymentToken: t.token,
258
+ approveAmount: t.approveAmount,
259
+ spenderAddress: t.approvedAddress,
260
+ expireAt: t.expireAt,
261
+ intervalDays: 0,
262
+ amountOfUsd: t.amountOfUsd
263
+ }, E(t.chain), O(t.token), Y(t.expireAt);
264
+ let n = `${t.chain.toLowerCase()}:${t.approvedAddress}?amount=${t.approveAmount}`;
265
+ QRCode.toDataURL(n, {
266
+ width: 200,
267
+ margin: 2,
268
+ errorCorrectionLevel: "H"
269
+ }).then((e) => {
270
+ k(e), v("payment");
271
+ }).catch((e) => {
272
+ console.error("生成二维码失败:", e), v("payment");
273
+ });
274
+ }
275
+ (e.status === "paid" || e.status === "approved") && (v("success"), $(), we?.(e)), e.status === "expired" && (v("expired"), $(), Te?.(e)), e.status === "failed" && (v("failed"), $(), Ee?.(e));
276
+ })).subscribe({
277
+ error: (e) => {
278
+ if (H.current) {
279
+ let t = e instanceof Error ? e.message : g.checkPaymentStatusFailed;
280
+ v("error"), C(t), p?.(e);
281
+ }
282
+ },
283
+ complete: () => {
284
+ B.current?.unsubscribe();
285
+ }
286
+ });
287
+ }, We = async () => {
288
+ if (!H.current) return;
289
+ let e = u === "subscription" ? H.current.spenderAddress : H.current.receiveAddress;
290
+ if (e) try {
291
+ await navigator.clipboard.writeText(e), F(!0), setTimeout(() => {
292
+ F(!1);
293
+ }, 2e3);
294
+ } catch (e) {
295
+ console.error("复制失败:", e);
296
+ }
297
+ }, Ge = async () => {
298
+ if (L) try {
299
+ await navigator.clipboard.writeText(L), F(!0), setTimeout(() => {
300
+ F(!1);
301
+ }, 2e3);
302
+ } catch (e) {
303
+ console.error("复制失败:", e);
46
304
  }
47
- }, N = async () => {
48
- w?.receiveAddress && await navigator.clipboard.writeText(w.receiveAddress);
49
- }, P = () => {
50
- s(), setTimeout(() => {
51
- h("select"), T(null);
52
- }, 300);
305
+ }, Ke = (e, t) => {
306
+ if (!n || typeof window > "u") return;
307
+ let r = new URL(window.location.href), i = t === "subscription" ? "subscriptionId" : "paymentId";
308
+ r.searchParams.set(i, e), window.history.replaceState({}, "", r.toString());
309
+ }, $ = () => {
310
+ if (typeof window > "u") return;
311
+ let e = new URL(window.location.href);
312
+ e.searchParams.delete("paymentId"), e.searchParams.delete("subscriptionId"), window.history.replaceState({}, "", e.toString());
53
313
  };
54
314
  return useEffect(() => {
55
- o && v.length === 0 && A();
56
- }, [o]), useEffect(() => {
57
- D.length > 0 && C(D[0].symbol);
58
- }, [D]), o ? /* @__PURE__ */ jsx("div", {
59
- className: "_cppay-overlay",
60
- onClick: (t) => t.target === t.currentTarget && P(),
61
- children: /* @__PURE__ */ jsxs("div", {
62
- className: "_cppay-dialog",
63
- children: [/* @__PURE__ */ jsxs("div", {
64
- className: "_cppay-header",
65
- children: [/* @__PURE__ */ jsx("h2", {
66
- className: "_cppay-title",
67
- children: m === "select" ? "选择支付方式" : "完成支付"
68
- }), /* @__PURE__ */ jsx("button", {
69
- onClick: P,
70
- disabled: g,
71
- className: "_cppay-close-btn",
72
- children: /* @__PURE__ */ jsx("svg", {
73
- fill: "none",
74
- stroke: "currentColor",
75
- viewBox: "0 0 24 24",
76
- children: /* @__PURE__ */ jsx("path", {
77
- strokeLinecap: "round",
78
- strokeLinejoin: "round",
79
- strokeWidth: 2,
80
- d: "M6 18L18 6M6 6l12 12"
315
+ w.length === 0 && Le();
316
+ }, []), useEffect(() => {
317
+ G.length > 0 && O(G[0].symbol);
318
+ }, [G]), useEffect(() => {
319
+ if (typeof window > "u") return;
320
+ let e = new URL(window.location.href);
321
+ if (u === "instant") {
322
+ let t = e.searchParams.get("paymentId");
323
+ t && (v("payment"), Q({ paymentId: t }));
324
+ }
325
+ if (u === "subscription") {
326
+ let t = e.searchParams.get("subscriptionId");
327
+ t && (v("payment"), Q({ subscriptionId: t }));
328
+ }
329
+ }, []), useEffect(() => () => {
330
+ B.current?.unsubscribe(), X();
331
+ }, []), /* @__PURE__ */ jsx("div", {
332
+ className: "_cppay-content",
333
+ children: _ === "success" ? m?.Success ? /* @__PURE__ */ jsx(m.Success, { paymentInfo: H.current }) : /* @__PURE__ */ jsxs("div", {
334
+ className: "_cppay-state-container",
335
+ children: [
336
+ /* @__PURE__ */ jsx("div", {
337
+ className: "_cppay-state-success-bg",
338
+ children: /* @__PURE__ */ jsx("div", {
339
+ className: "_cppay-state-success-icon",
340
+ children: ""
341
+ })
342
+ }),
343
+ /* @__PURE__ */ jsx("h3", {
344
+ className: "_cppay-state-title _cppay-state-title-success",
345
+ children: u === "subscription" ? g.authorizationSuccess : g.paymentSuccess
346
+ }),
347
+ L && /* @__PURE__ */ jsxs("div", {
348
+ className: "_cppay-state-hash-container",
349
+ children: [/* @__PURE__ */ jsx("div", {
350
+ className: "_cppay-state-label",
351
+ children: g.transactionHash
352
+ }), /* @__PURE__ */ jsxs("div", {
353
+ className: "_cppay-hash-row",
354
+ children: [/* @__PURE__ */ jsx("code", {
355
+ className: "_cppay-state-hash",
356
+ children: L
357
+ }), /* @__PURE__ */ jsx("button", {
358
+ onClick: Ge,
359
+ className: "_cppay-state-copy-btn",
360
+ title: g.copyAddress,
361
+ children: /* @__PURE__ */ jsxs("svg", {
362
+ viewBox: "0 0 24 24",
363
+ fill: "none",
364
+ stroke: "currentColor",
365
+ strokeWidth: "2",
366
+ 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", {
367
+ x: "8",
368
+ y: "2",
369
+ width: "8",
370
+ height: "4",
371
+ rx: "1",
372
+ ry: "1"
373
+ })]
374
+ })
375
+ })]
376
+ })]
377
+ }),
378
+ H.current && /* @__PURE__ */ jsxs("div", {
379
+ className: "_cppay-success-details",
380
+ children: [
381
+ /* @__PURE__ */ jsxs("div", {
382
+ className: "_cppay-detail-item",
383
+ children: [/* @__PURE__ */ jsx("span", {
384
+ className: "_cppay-detail-label",
385
+ children: g.orderId
386
+ }), /* @__PURE__ */ jsx("span", {
387
+ className: "_cppay-detail-value",
388
+ children: H.current.orderId
389
+ })]
390
+ }),
391
+ /* @__PURE__ */ jsxs("div", {
392
+ className: "_cppay-detail-item",
393
+ children: [/* @__PURE__ */ jsx("span", {
394
+ className: "_cppay-detail-label",
395
+ children: u === "subscription" ? g.authorizationAmount : g.paymentAmount
396
+ }), /* @__PURE__ */ jsx("span", {
397
+ className: "_cppay-detail-value",
398
+ children: u === "subscription" ? `${J(H.current.approveAmount, q(D))} ${D}` : `${J(H.current.paymentAmount, q(D))} ${D}`
399
+ })]
400
+ }),
401
+ /* @__PURE__ */ jsxs("div", {
402
+ className: "_cppay-detail-item",
403
+ children: [/* @__PURE__ */ jsx("span", {
404
+ className: "_cppay-detail-label",
405
+ children: g.paymentNetwork
406
+ }), /* @__PURE__ */ jsx("span", {
407
+ className: "_cppay-detail-value",
408
+ children: H.current.paymentChain
409
+ })]
410
+ }),
411
+ /* @__PURE__ */ jsxs("div", {
412
+ className: "_cppay-detail-item",
413
+ children: [/* @__PURE__ */ jsx("span", {
414
+ className: "_cppay-detail-label",
415
+ children: g.paymentToken
416
+ }), /* @__PURE__ */ jsx("span", {
417
+ className: "_cppay-detail-value",
418
+ children: H.current.paymentToken
419
+ })]
420
+ }),
421
+ u === "subscription" && /* @__PURE__ */ jsxs("div", {
422
+ className: "_cppay-detail-item",
423
+ children: [/* @__PURE__ */ jsx("span", {
424
+ className: "_cppay-detail-label",
425
+ children: g.renewalInterval
426
+ }), /* @__PURE__ */ jsxs("span", {
427
+ className: "_cppay-detail-value",
428
+ children: [
429
+ H.current.intervalDays,
430
+ " ",
431
+ g.days
432
+ ]
433
+ })]
434
+ }),
435
+ /* @__PURE__ */ jsxs("div", {
436
+ className: "_cppay-detail-item",
437
+ children: [/* @__PURE__ */ jsx("span", {
438
+ className: "_cppay-detail-label",
439
+ children: u === "subscription" ? g.subscriptionId : g.paymentId
440
+ }), /* @__PURE__ */ jsx("span", {
441
+ className: "_cppay-detail-value _cppay-detail-id",
442
+ children: u === "subscription" ? H.current.subscriptionId : H.current.paymentId
443
+ })]
81
444
  })
445
+ ]
446
+ })
447
+ ]
448
+ }) : _ === "expired" ? m?.Expired ? /* @__PURE__ */ jsx(m.Expired, { paymentInfo: H.current }) : /* @__PURE__ */ jsxs("div", {
449
+ className: "_cppay-state-container",
450
+ children: [
451
+ /* @__PURE__ */ jsx("div", {
452
+ className: "_cppay-state-expired-bg",
453
+ children: /* @__PURE__ */ jsx("div", {
454
+ className: "_cppay-state-expired-icon",
455
+ children: "⏰"
456
+ })
457
+ }),
458
+ /* @__PURE__ */ jsx("h3", {
459
+ className: "_cppay-state-title _cppay-state-title-expired",
460
+ children: g.paymentExpired
461
+ }),
462
+ /* @__PURE__ */ jsx("p", {
463
+ className: "_cppay-state-message",
464
+ children: g.pleaseInitiatePaymentAgain
465
+ }),
466
+ /* @__PURE__ */ jsx("button", {
467
+ onClick: () => {
468
+ v("select"), $();
469
+ },
470
+ disabled: b || y,
471
+ className: "_cppay-btn _cppay-btn-primary _cppay-state-btn",
472
+ children: g.returnButton
473
+ })
474
+ ]
475
+ }) : _ === "error" ? m?.Error ? /* @__PURE__ */ jsx(m.Error, { paymentInfo: H.current }) : /* @__PURE__ */ jsxs("div", {
476
+ className: "_cppay-state-container",
477
+ children: [
478
+ /* @__PURE__ */ jsx("div", {
479
+ className: "_cppay-state-error-bg",
480
+ children: /* @__PURE__ */ jsx("div", {
481
+ className: "_cppay-state-error-icon",
482
+ children: "!"
82
483
  })
484
+ }),
485
+ /* @__PURE__ */ jsx("h3", {
486
+ className: "_cppay-state-title _cppay-state-title-error",
487
+ children: S || g.error
488
+ }),
489
+ /* @__PURE__ */ jsx("p", {
490
+ className: "_cppay-state-message",
491
+ children: g.checkStatusFailed
492
+ }),
493
+ /* @__PURE__ */ jsx("button", {
494
+ onClick: () => {
495
+ v("select"), $();
496
+ },
497
+ disabled: b || y,
498
+ className: "_cppay-btn _cppay-btn-primary _cppay-state-btn",
499
+ children: g.returnButton
500
+ })
501
+ ]
502
+ }) : _ === "failed" ? m?.Failed ? /* @__PURE__ */ jsx(m.Failed, { paymentInfo: H.current }) : /* @__PURE__ */ jsxs("div", {
503
+ className: "_cppay-state-container",
504
+ children: [
505
+ /* @__PURE__ */ jsx("div", {
506
+ className: "_cppay-state-failed-bg",
507
+ children: /* @__PURE__ */ jsx("div", {
508
+ className: "_cppay-state-failed-icon",
509
+ children: "✕"
510
+ })
511
+ }),
512
+ /* @__PURE__ */ jsx("h3", {
513
+ className: "_cppay-state-title _cppay-state-title-failed",
514
+ children: g.paymentFailed
515
+ }),
516
+ /* @__PURE__ */ jsx("p", {
517
+ className: "_cppay-state-message",
518
+ children: g.pleaseInitiatePaymentAgain
519
+ }),
520
+ /* @__PURE__ */ jsx("button", {
521
+ onClick: () => {
522
+ v("select"), $();
523
+ },
524
+ disabled: b || y,
525
+ className: "_cppay-btn _cppay-btn-primary _cppay-state-btn",
526
+ children: g.returnButton
527
+ })
528
+ ]
529
+ }) : _ === "select" ? /* @__PURE__ */ jsxs("div", { children: [
530
+ m?.ChooseTop,
531
+ /* @__PURE__ */ jsxs("div", {
532
+ className: "_cppay-section",
533
+ children: [/* @__PURE__ */ jsx("label", {
534
+ className: "_cppay-label",
535
+ children: g.paymentNetwork
536
+ }), /* @__PURE__ */ jsx("div", {
537
+ className: "_cppay-grid",
538
+ children: w.map((e) => /* @__PURE__ */ jsxs("button", {
539
+ onClick: () => E(e.chain),
540
+ className: `_cppay-select-btn ${T === e.chain ? "_cppay-selected" : ""}`,
541
+ children: [e.icon && /* @__PURE__ */ jsx("img", {
542
+ src: e.icon,
543
+ alt: e.chain
544
+ }), /* @__PURE__ */ jsx("span", { children: e.chain })]
545
+ }, e.chain))
83
546
  })]
84
- }), /* @__PURE__ */ jsx("div", {
85
- className: "_cppay-content",
86
- children: m === "select" ? /* @__PURE__ */ jsxs("div", { children: [
87
- /* @__PURE__ */ jsxs("div", {
88
- className: "_cppay-section",
89
- children: [/* @__PURE__ */ jsx("label", {
90
- className: "_cppay-label",
91
- children: "支付网络"
92
- }), /* @__PURE__ */ jsx("div", {
93
- className: "_cppay-grid",
94
- children: v.map((t) => /* @__PURE__ */ jsxs("button", {
95
- onClick: () => x(t.chain),
96
- className: `_cppay-select-btn ${b === t.chain ? "_cppay-selected" : ""}`,
97
- children: [t.icon && /* @__PURE__ */ jsx("img", {
98
- src: t.icon,
99
- alt: t.chain
100
- }), /* @__PURE__ */ jsx("span", { children: t.chain })]
101
- }, t.chain))
102
- })]
103
- }),
104
- /* @__PURE__ */ jsxs("div", {
105
- className: "_cppay-section",
106
- children: [/* @__PURE__ */ jsx("label", {
107
- className: "_cppay-label",
108
- children: "支付代币"
109
- }), /* @__PURE__ */ jsx("div", {
110
- className: "_cppay-grid",
111
- children: D.map((t) => /* @__PURE__ */ jsxs("button", {
112
- onClick: () => C(t.symbol),
113
- className: `_cppay-select-btn ${S === t.symbol ? "_cppay-selected" : ""}`,
114
- children: [t.icon && /* @__PURE__ */ jsx("img", {
115
- src: t.icon,
116
- alt: t.symbol
117
- }), /* @__PURE__ */ jsx("span", { children: t.symbol })]
118
- }, t.symbol))
547
+ }),
548
+ /* @__PURE__ */ jsxs("div", {
549
+ className: "_cppay-section",
550
+ children: [/* @__PURE__ */ jsx("label", {
551
+ className: "_cppay-label",
552
+ children: g.paymentToken
553
+ }), /* @__PURE__ */ jsx("div", {
554
+ className: "_cppay-grid",
555
+ children: G.map((e) => /* @__PURE__ */ jsxs("button", {
556
+ onClick: () => O(e.symbol),
557
+ className: `_cppay-select-btn ${D === e.symbol ? "_cppay-selected" : ""}`,
558
+ children: [e.icon && /* @__PURE__ */ jsx("img", {
559
+ src: e.icon,
560
+ alt: e.symbol
561
+ }), /* @__PURE__ */ jsx("span", { children: e.symbol })]
562
+ }, e.symbol))
563
+ })]
564
+ }),
565
+ m?.ChooseBottom,
566
+ /* @__PURE__ */ jsx("div", {
567
+ className: "_cppay-section",
568
+ children: /* @__PURE__ */ jsx("div", {
569
+ className: "_cppay-price-box",
570
+ children: /* @__PURE__ */ jsxs("div", {
571
+ className: "_cppay-price-row",
572
+ children: [/* @__PURE__ */ jsx("span", {
573
+ className: "_cppay-price-label",
574
+ children: g.paymentAmount
575
+ }), /* @__PURE__ */ jsxs("div", {
576
+ className: "_cppay-price-amount",
577
+ children: [/* @__PURE__ */ jsxs("div", {
578
+ className: "_cppay-price-main",
579
+ children: [
580
+ Z ?? "-",
581
+ " ",
582
+ D ?? ""
583
+ ]
584
+ }), /* @__PURE__ */ jsxs("div", {
585
+ className: "_cppay-price-sub",
586
+ children: ["≈ $", d]
587
+ })]
119
588
  })]
120
- }),
121
- /* @__PURE__ */ jsx("div", {
122
- className: "_cppay-section",
589
+ })
590
+ })
591
+ }),
592
+ /* @__PURE__ */ jsxs("div", {
593
+ className: "_cppay-section",
594
+ children: [S && /* @__PURE__ */ jsxs("div", {
595
+ className: "_cppay-error-tooltip-wrapper",
596
+ onMouseEnter: () => I(!0),
597
+ onMouseLeave: () => I(!1),
598
+ children: [/* @__PURE__ */ jsxs("div", {
599
+ className: "_cppay-error-tooltip",
600
+ children: [/* @__PURE__ */ jsx("svg", {
601
+ viewBox: "0 0 20 20",
602
+ fill: "currentColor",
603
+ children: /* @__PURE__ */ jsx("path", {
604
+ fillRule: "evenodd",
605
+ 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",
606
+ clipRule: "evenodd"
607
+ })
608
+ }), /* @__PURE__ */ jsx("span", { children: S })]
609
+ }), Pe && /* @__PURE__ */ jsx("div", {
610
+ className: "_cppay-error-tooltip-full",
611
+ children: S
612
+ })]
613
+ }), /* @__PURE__ */ jsx("button", {
614
+ onClick: He,
615
+ disabled: !T || !D || b,
616
+ className: "_cppay-btn _cppay-btn-primary",
617
+ children: b ? g.processing : g.continuePayment
618
+ })]
619
+ })
620
+ ] }) : /* @__PURE__ */ jsxs("div", { children: [
621
+ /* @__PURE__ */ jsx("div", {
622
+ className: "_cppay-qr-container",
623
+ children: /* @__PURE__ */ jsx("div", {
624
+ className: "_cppay-qr-code",
625
+ children: ke && /* @__PURE__ */ jsx("img", {
626
+ src: ke,
627
+ alt: "Payment QR Code",
628
+ className: "_cppay-qr-image"
629
+ })
630
+ })
631
+ }),
632
+ /* @__PURE__ */ jsxs("div", {
633
+ className: "_cppay-section",
634
+ children: [
635
+ K && /* @__PURE__ */ jsx("div", {
636
+ className: "_cppay-info-box",
123
637
  children: /* @__PURE__ */ jsx("div", {
124
- className: "_cppay-price-box",
638
+ className: "_cppay-info-flex-container",
125
639
  children: /* @__PURE__ */ jsxs("div", {
126
- className: "_cppay-price-row",
127
- children: [/* @__PURE__ */ jsx("span", {
128
- className: "_cppay-price-label",
129
- children: "支付金额"
640
+ className: "_cppay-info-flex-child",
641
+ children: [/* @__PURE__ */ jsx("div", {
642
+ className: "_cppay-info-label",
643
+ children: u === "subscription" ? g.authorizationAmount : g.paymentAmount
130
644
  }), /* @__PURE__ */ jsxs("div", {
131
- className: "_cppay-price-amount",
132
- children: [/* @__PURE__ */ jsxs("div", {
133
- className: "_cppay-price-main",
134
- children: [
135
- k,
136
- " ",
137
- S
138
- ]
139
- }), /* @__PURE__ */ jsxs("div", {
140
- className: "_cppay-price-sub",
141
- children: ["≈ $", u]
142
- })]
645
+ className: "_cppay-info-value _cppay-info-value-flex",
646
+ children: [H.current && /* @__PURE__ */ jsx("span", { children: u === "subscription" ? `${J(H.current.approveAmount, q(K.symbol))} ${K.symbol}` : `${J(H.current.paymentAmount, q(K.symbol))} ${K.symbol}` }), /* @__PURE__ */ jsxs("span", { children: ["≈ $", d] })]
143
647
  })]
144
648
  })
145
649
  })
146
650
  }),
147
651
  /* @__PURE__ */ jsx("div", {
148
- className: "_cppay-section",
149
- children: /* @__PURE__ */ jsx("button", {
150
- onClick: j,
151
- disabled: !b || !S || g,
152
- className: "_cppay-btn _cppay-btn-primary",
153
- children: g ? "处理中..." : "继续支付"
154
- })
155
- })
156
- ] }) : w && /* @__PURE__ */ jsxs("div", { children: [
157
- /* @__PURE__ */ jsx("div", {
158
- className: "_cppay-qr-container",
159
- children: /* @__PURE__ */ jsx("div", {
160
- className: "_cppay-qr-placeholder",
161
- children: /* @__PURE__ */ jsx("span", { children: "扫码支付" })
162
- })
163
- }),
164
- /* @__PURE__ */ jsxs("div", {
165
- className: "_cppay-section",
166
- children: [/* @__PURE__ */ jsxs("div", {
167
- className: "_cppay-info-box",
168
- children: [/* @__PURE__ */ jsx("div", {
169
- className: "_cppay-info-label",
170
- children: "支付金额"
171
- }), /* @__PURE__ */ jsxs("div", {
172
- className: "_cppay-info-value",
173
- children: [
174
- w.paymentAmount,
175
- " ",
176
- S
177
- ]
178
- })]
179
- }), /* @__PURE__ */ jsxs("div", {
180
- className: "_cppay-info-box",
181
- children: [/* @__PURE__ */ jsx("div", {
182
- className: "_cppay-info-label",
183
- children: "支付地址"
652
+ className: "_cppay-info-box",
653
+ children: /* @__PURE__ */ jsxs("div", {
654
+ className: "_cppay-info-flex-child",
655
+ children: [/* @__PURE__ */ jsxs("div", {
656
+ className: "_cppay-info-label _cppay-info-label-flex",
657
+ children: [/* @__PURE__ */ jsx("span", { children: u === "subscription" ? g.authorizationContractAddress : g.paymentAddress }), Me && /* @__PURE__ */ jsxs("span", {
658
+ className: "_cppay-countdown",
659
+ children: ["⏰ ", Me]
660
+ })]
184
661
  }), /* @__PURE__ */ jsxs("div", {
185
662
  className: "_cppay-address-row",
186
- children: [/* @__PURE__ */ jsx("code", { children: w.receiveAddress }), /* @__PURE__ */ jsx("button", {
187
- onClick: N,
188
- className: "_cppay-copy-btn",
189
- title: "复制地址",
190
- children: /* @__PURE__ */ jsx("svg", {
663
+ children: [H.current && /* @__PURE__ */ jsx("code", { children: u === "subscription" ? H.current.spenderAddress : H.current.receiveAddress }), /* @__PURE__ */ jsx("button", {
664
+ onClick: We,
665
+ className: `_cppay-copy-btn ${P ? "_cppay-copy-success" : ""}`,
666
+ title: P ? g.copied : g.copyAddress,
667
+ children: P ? /* @__PURE__ */ jsx("svg", {
668
+ className: "_cppay-copy-icon",
669
+ viewBox: "0 0 24 24",
670
+ fill: "currentColor",
671
+ children: /* @__PURE__ */ jsx("path", { d: "M9 16.17L4.83 12l-1.42 1.41L9 19 21 7l-1.41-1.41z" })
672
+ }) : /* @__PURE__ */ jsxs("svg", {
673
+ className: "_cppay-copy-icon",
674
+ viewBox: "0 0 24 24",
191
675
  fill: "none",
192
676
  stroke: "currentColor",
193
- viewBox: "0 0 24 24",
194
- children: /* @__PURE__ */ jsx("path", {
195
- strokeLinecap: "round",
196
- strokeLinejoin: "round",
197
- strokeWidth: 2,
198
- 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"
199
- })
677
+ strokeWidth: "2",
678
+ 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", {
679
+ x: "8",
680
+ y: "2",
681
+ width: "8",
682
+ height: "4",
683
+ rx: "1",
684
+ ry: "1"
685
+ })]
200
686
  })
201
687
  })]
202
688
  })]
203
- })]
204
- }),
205
- /* @__PURE__ */ jsx("div", {
206
- className: "_cppay-section",
207
- children: /* @__PURE__ */ jsx("button", {
208
- onClick: M,
209
- disabled: g,
210
- className: "_cppay-btn _cppay-btn-primary",
211
- children: g ? "检查支付状态..." : "我已完成支付"
212
689
  })
213
690
  }),
214
- /* @__PURE__ */ jsx("div", {
215
- className: "_cppay-section",
216
- children: /* @__PURE__ */ jsx("button", {
217
- onClick: () => h("select"),
218
- disabled: g,
219
- className: "_cppay-btn _cppay-btn-secondary",
220
- children: "更改支付方式"
691
+ u === "subscription" && /* @__PURE__ */ jsxs("div", {
692
+ className: "_cppay-info-box _cppay-subscription-box",
693
+ children: [/* @__PURE__ */ jsx("div", {
694
+ className: "_cppay-info-label _cppay-subscription-label",
695
+ children: g.subscriptionNotice
696
+ }), /* @__PURE__ */ jsx("div", {
697
+ className: "_cppay-info-value _cppay-subscription-message",
698
+ children: g.subscriptionNoticeMessage
699
+ })]
700
+ })
701
+ ]
702
+ }),
703
+ S && /* @__PURE__ */ jsxs("div", {
704
+ className: "_cppay-error-tooltip-wrapper",
705
+ onMouseEnter: () => I(!0),
706
+ onMouseLeave: () => I(!1),
707
+ children: [/* @__PURE__ */ jsxs("div", {
708
+ className: "_cppay-error-tooltip",
709
+ children: [/* @__PURE__ */ jsx("svg", {
710
+ viewBox: "0 0 20 20",
711
+ fill: "currentColor",
712
+ children: /* @__PURE__ */ jsx("path", {
713
+ fillRule: "evenodd",
714
+ 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",
715
+ clipRule: "evenodd"
716
+ })
717
+ }), /* @__PURE__ */ jsx("span", { children: S })]
718
+ }), Pe && /* @__PURE__ */ jsx("div", {
719
+ className: "_cppay-error-tooltip-full",
720
+ children: S
721
+ })]
722
+ }),
723
+ !y && /* @__PURE__ */ jsx("div", {
724
+ className: "_cppay-section",
725
+ children: A ? /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("button", {
726
+ onClick: Ve,
727
+ disabled: b,
728
+ className: "_cppay-btn _cppay-btn-primary",
729
+ children: b ? u === "subscription" ? g.authorizing : g.processing : u === "subscription" ? `💳 ${g.connectWallet}` : `💳 ${g.walletPay}`
730
+ }), /* @__PURE__ */ jsxs("button", {
731
+ onClick: Fe,
732
+ disabled: b,
733
+ className: "_cppay-btn _cppay-wallet-address-btn",
734
+ title: g.clickToModifyWallet,
735
+ children: [/* @__PURE__ */ jsxs("span", {
736
+ className: "_cppay-wallet-address-text",
737
+ children: [
738
+ A.slice(0, 10),
739
+ "...",
740
+ A.slice(-4)
741
+ ]
742
+ }), /* @__PURE__ */ jsx("svg", {
743
+ className: "_cppay-wallet-arrow",
744
+ viewBox: "0 0 24 24",
745
+ fill: "none",
746
+ stroke: "currentColor",
747
+ strokeWidth: "2",
748
+ children: /* @__PURE__ */ jsx("polyline", { points: "6 9 12 15 18 9" })
749
+ })]
750
+ })] }) : /* @__PURE__ */ jsx("button", {
751
+ onClick: Fe,
752
+ disabled: Ae,
753
+ className: "_cppay-btn _cppay-btn-secondary _cppay-connect-wallet-btn",
754
+ children: /* @__PURE__ */ jsx("span", { children: Ae ? g.processing : `💳 ${g.connectWallet}` })
755
+ })
756
+ }),
757
+ /* @__PURE__ */ jsx("div", {
758
+ className: "_cppay-section",
759
+ children: /* @__PURE__ */ jsx("button", {
760
+ onClick: Ue,
761
+ disabled: y,
762
+ className: "_cppay-btn _cppay-btn-primary",
763
+ children: y ? /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsxs("svg", {
764
+ className: "_cppay-spinner",
765
+ viewBox: "0 0 24 24",
766
+ fill: "none",
767
+ xmlns: "http://www.w3.org/2000/svg",
768
+ children: [/* @__PURE__ */ jsx("circle", {
769
+ cx: "12",
770
+ cy: "12",
771
+ r: "10",
772
+ stroke: "currentColor",
773
+ strokeWidth: "3",
774
+ strokeOpacity: "0.25"
775
+ }), /* @__PURE__ */ jsx("path", {
776
+ d: "M12 2a10 10 0 0 1 10 10",
777
+ stroke: "currentColor",
778
+ strokeWidth: "3",
779
+ strokeLinecap: "round"
780
+ })]
781
+ }), g.checking] }) : g.completedPayment
782
+ })
783
+ }),
784
+ /* @__PURE__ */ jsx("hr", { className: "_cppay-divider" }),
785
+ /* @__PURE__ */ jsx("div", {
786
+ className: "_cppay-section",
787
+ children: /* @__PURE__ */ jsx("button", {
788
+ onClick: () => {
789
+ v("select"), $();
790
+ },
791
+ disabled: b || y,
792
+ className: "_cppay-btn _cppay-btn-text",
793
+ children: g.changePaymentMethod
794
+ })
795
+ })
796
+ ] })
797
+ });
798
+ }, PaymentDialog_default = ({ open: e, onClose: t, ott: n, apikey: i, plain: ue, orderId: de, amount: fe, intervalDays: pe, remark: me, locale: a, onExpired: he, onSuccess: ge, onFailed: _e, onError: ve, Slots: ye }) => {
799
+ let [o, be] = useState("select"), s = useMemo(() => o !== "checking", [o]);
800
+ useEffect(() => {
801
+ e || be("select");
802
+ }, [e]), useEffect(() => {
803
+ if (!e) return;
804
+ let t = (e) => {
805
+ e.key === "Escape" && s && c();
806
+ };
807
+ return window.addEventListener("keydown", t), () => window.removeEventListener("keydown", t);
808
+ }, [e, s]);
809
+ let c = () => {
810
+ s && t();
811
+ }, l = useMemo(() => getLocaleMessages(a), [a]);
812
+ return e ? /* @__PURE__ */ jsx("div", {
813
+ className: "_cppay-overlay",
814
+ onClick: (e) => e.target === e.currentTarget && c(),
815
+ children: /* @__PURE__ */ jsxs("div", {
816
+ className: "_cppay-dialog",
817
+ children: [/* @__PURE__ */ jsxs("div", {
818
+ className: "_cppay-header",
819
+ children: [/* @__PURE__ */ jsx("h2", {
820
+ className: "_cppay-title",
821
+ children: (() => {
822
+ switch (o) {
823
+ case "success": return l.paymentResult;
824
+ case "expired": return l.paymentExpired;
825
+ case "failed": return l.paymentFailed;
826
+ case "error": return l.error;
827
+ case "payment":
828
+ case "checking": return l.completePayment;
829
+ default: return l.selectPaymentMethod;
830
+ }
831
+ })()
832
+ }), /* @__PURE__ */ jsx("button", {
833
+ onClick: c,
834
+ disabled: !s,
835
+ className: "_cppay-close-btn",
836
+ children: /* @__PURE__ */ jsx("svg", {
837
+ fill: "none",
838
+ stroke: "currentColor",
839
+ viewBox: "0 0 24 24",
840
+ children: /* @__PURE__ */ jsx("path", {
841
+ strokeLinecap: "round",
842
+ strokeLinejoin: "round",
843
+ strokeWidth: 2,
844
+ d: "M6 18L18 6M6 6l12 12"
221
845
  })
222
846
  })
223
- ] })
847
+ })]
848
+ }), /* @__PURE__ */ jsx(PaymentContent_default, {
849
+ apikey: i,
850
+ ott: n,
851
+ plain: ue,
852
+ orderId: de,
853
+ amount: fe,
854
+ intervalDays: pe,
855
+ remark: me,
856
+ locale: a,
857
+ onSuccess: ge,
858
+ onExpired: he,
859
+ onFailed: _e,
860
+ onError: ve,
861
+ Slots: ye,
862
+ onPaymentStepChange: be
224
863
  })]
225
864
  })
226
865
  }) : null;
227
- });
866
+ }, CppayContext = createContext(null);
867
+ const CppayProvider = ({ children: e }) => {
868
+ let [t, n] = useState(!1), [r, i] = useState(null), ue = useCallback((e) => {
869
+ i(e), n(!0);
870
+ }, []), de = useCallback(() => {
871
+ n(!1);
872
+ }, []), fe = useCallback(() => {
873
+ n(!1);
874
+ }, []), pe = useCallback((e) => {
875
+ r?.onSuccess?.(e);
876
+ }, [r]), me = useCallback((e) => {
877
+ r?.onExpired?.(e);
878
+ }, [r]), a = useCallback((e) => {
879
+ r?.onFailed?.(e);
880
+ }, [r]), he = useCallback((e) => {
881
+ r?.onError?.(e);
882
+ }, [r]);
883
+ return /* @__PURE__ */ jsxs(CppayContext.Provider, {
884
+ value: {
885
+ showPayment: ue,
886
+ closePayment: de
887
+ },
888
+ children: [e, r && /* @__PURE__ */ jsx(PaymentDialog_default, {
889
+ open: t,
890
+ onClose: fe,
891
+ ...r,
892
+ onSuccess: pe,
893
+ onExpired: me,
894
+ onFailed: a,
895
+ onError: he
896
+ })]
897
+ });
898
+ }, useCppayPayment = () => {
899
+ let e = useContext(CppayContext);
900
+ if (!e) throw Error("useCppayPayment must be used within CppayProvider");
901
+ return e;
902
+ };
228
903
  injectStyle(payment_dialog_default);
229
- export { PaymentDialog_default as PaymentDialog };
904
+ export { CppayProvider, PaymentContent_default as PaymentContent, PaymentDialog_default as PaymentDialog, useCppayPayment };