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

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
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";
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";
@@ -9,10 +9,10 @@ import { createAppKit } from "@reown/appkit";
9
9
  import { EthersAdapter } from "@reown/appkit-adapter-ethers";
10
10
  import { createContext, useCallback, useContext, useEffect, useMemo, useRef, useState } from "react";
11
11
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
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);
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" && !H.current && (H.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,24 +33,24 @@ var PaymentContent_default = ({ apikey: t, ott: n, plain: m, orderId: h, amount:
33
33
  icons: ["https://cppay.com/icon.png"]
34
34
  },
35
35
  features: { analytics: !1 }
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) => {
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
- L(t);
40
+ z(t);
41
41
  }));
42
42
  }, []);
43
- let we = async () => {
43
+ let Ee = async () => {
44
44
  try {
45
- F(!0), C?.(void 0), H.current && await H.current.open();
45
+ L(!0), w?.(void 0), U.current && await U.current.open();
46
46
  } catch (e) {
47
47
  console.error("钱包连接失败:", e);
48
- let t = e instanceof Error ? e.message : "钱包连接失败";
49
- C?.(t), _?.(e);
48
+ let t = e instanceof Error ? e.message : E.walletConnectionFailed;
49
+ w?.(t), v?.(e);
50
50
  } finally {
51
- F(!1);
51
+ L(!1);
52
52
  }
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) => [
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) => [
54
54
  "USDT",
55
55
  "USDC",
56
56
  "BUSD",
@@ -58,60 +58,60 @@ var PaymentContent_default = ({ apikey: t, ott: n, plain: m, orderId: h, amount:
58
58
  "TUSD",
59
59
  "USDD",
60
60
  "FDUSD"
61
- ].includes(e.toUpperCase()) ? 2 : 6, Y = (e, t) => {
61
+ ].includes(e.toUpperCase()) ? 2 : 6, X = (e, t) => {
62
62
  let n = parseFloat(e);
63
63
  return isNaN(n) ? "0" : n.toFixed(t).replace(/\.?0+$/, "");
64
- }, Te = (e) => {
65
- if (e <= 0) return "已过期";
64
+ }, De = (e) => {
65
+ if (e <= 0) return E.expired;
66
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);
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
70
  let t = () => {
71
71
  let t = e - Math.floor(Date.now() / 1e3);
72
- Se(Te(t)), t <= 0 && (y("expired"), Ee());
72
+ Ce(De(t)), t <= 0 && (b("expired"), ke());
73
73
  };
74
- t(), W.current = setInterval(t, 1e3);
75
- }, Ee = () => {
76
- W.current &&= (clearInterval(W.current), null);
74
+ t(), G.current = setInterval(t, 1e3);
75
+ }, ke = () => {
76
+ G.current &&= (clearInterval(G.current), null);
77
77
  }, Z = useMemo(() => {
78
- if (!O || !q) return "0";
79
- let e = parseFloat(q.price);
78
+ if (!A || !J) return "0";
79
+ let e = parseFloat(J.price);
80
80
  if (isNaN(e) || e === 0) return "0";
81
- let t = J(O);
82
- return Y((parseFloat(g) / e).toFixed(t), t);
81
+ let t = Y(A);
82
+ return X((parseFloat(_) / e).toFixed(t), t);
83
83
  }, [
84
- g,
85
- O,
86
- q
87
- ]), De = async () => {
84
+ _,
85
+ A,
86
+ J
87
+ ]), Ae = async () => {
88
88
  try {
89
- C?.(void 0);
90
- let e = await w.getSupportedChains();
91
- xe(e), e.length > 0 && D(e[0].chain);
89
+ w?.(void 0);
90
+ let e = await T.getSupportedChains();
91
+ Se(e), e.length > 0 && k(e[0].chain);
92
92
  } catch (e) {
93
- let t = e instanceof Error ? e.message : "加载支付网络失败";
94
- C?.(t), _?.(e);
93
+ let t = e instanceof Error ? e.message : E.loadPaymentNetworkFailed;
94
+ w?.(t), v?.(e);
95
95
  }
96
- }, Oe = async (e) => {
97
- if (I) try {
98
- await I.request({
96
+ }, je = async (e) => {
97
+ if (R) try {
98
+ await R.request({
99
99
  method: "wallet_switchEthereumChain",
100
100
  params: [{ chainId: `0x${e.toString(16)}` }]
101
101
  });
102
102
  } catch (e) {
103
- throw e.code === 4902 ? Error("请在钱包中添加该网络") : e;
103
+ throw e.code === 4902 ? Error(E.pleaseAddNetwork) : e;
104
104
  }
105
- }, ke = async () => {
106
- if (!(!M || !I || !Q.current || !q || !G)) try {
105
+ }, Me = async () => {
106
+ if (!(!P || !R || !Q.current || !J || !K)) try {
107
107
  let e = Q.current;
108
- await Oe(G.chainId);
108
+ await je(K.chainId);
109
109
  let t = createWalletClient({
110
- account: M,
111
- transport: custom(I)
110
+ account: P,
111
+ transport: custom(R)
112
112
  });
113
- q.address ? await t.writeContract({
114
- address: q.address,
113
+ J.address ? await t.writeContract({
114
+ address: J.address,
115
115
  abi: [{
116
116
  name: "transfer",
117
117
  type: "function",
@@ -126,29 +126,29 @@ var PaymentContent_default = ({ apikey: t, ott: n, plain: m, orderId: h, amount:
126
126
  outputs: [{ type: "bool" }]
127
127
  }],
128
128
  functionName: "transfer",
129
- args: [e.receiveAddress, parseUnits(e.paymentAmount, q.decimals)],
129
+ args: [e.receiveAddress, parseUnits(e.paymentAmount, J.decimals)],
130
130
  chain: null
131
131
  }) : await t.sendTransaction({
132
132
  to: e.receiveAddress,
133
- value: parseUnits(e.paymentAmount, q.decimals),
133
+ value: parseUnits(e.paymentAmount, J.decimals),
134
134
  chain: null
135
- }), j(void 0);
135
+ }), N(void 0);
136
136
  } catch (e) {
137
137
  console.error("钱包支付失败:", e);
138
- let t = e instanceof Error ? e.message : "钱包支付失败";
139
- C?.(t), _?.(e);
138
+ let t = e instanceof Error ? e.message : E.walletPaymentFailed;
139
+ w?.(t), v?.(e);
140
140
  }
141
- }, Ae = async () => {
142
- if (!(!M || !I || !Q.current || !q || !G)) try {
141
+ }, Ne = async () => {
142
+ if (!(!P || !R || !Q.current || !J || !K)) try {
143
143
  let e = Q.current;
144
- await Oe(G.chainId);
144
+ await je(K.chainId);
145
145
  let t = createWalletClient({
146
- account: M,
147
- transport: custom(I)
146
+ account: P,
147
+ transport: custom(R)
148
148
  });
149
- if (!q.address) throw Error("订阅支付不支持原生代币");
149
+ if (!J.address) throw Error(E.subscriptionDoesNotSupportNative);
150
150
  await t.writeContract({
151
- address: q.address,
151
+ address: J.address,
152
152
  abi: [{
153
153
  name: "approve",
154
154
  type: "function",
@@ -163,71 +163,71 @@ var PaymentContent_default = ({ apikey: t, ott: n, plain: m, orderId: h, amount:
163
163
  outputs: [{ type: "bool" }]
164
164
  }],
165
165
  functionName: "approve",
166
- args: [e.spenderAddress, parseUnits(e.approveAmount, q.decimals)],
166
+ args: [e.spenderAddress, parseUnits(e.approveAmount, J.decimals)],
167
167
  chain: null
168
- }), j(void 0);
168
+ }), N(void 0);
169
169
  } catch (e) {
170
170
  console.error("钱包授权失败:", e);
171
- let t = e instanceof Error ? e.message : "钱包授权失败";
172
- C?.(t), _?.(e);
171
+ let t = e instanceof Error ? e.message : E.walletPaymentFailed;
172
+ w?.(t), v?.(e);
173
173
  }
174
- }, je = async () => {
175
- if (!M) {
176
- let e = "请先连接钱包";
177
- C?.(e), _?.(Error(e));
174
+ }, Pe = async () => {
175
+ if (!P) {
176
+ let e = E.pleaseConnectWallet;
177
+ w?.(e), v?.(Error(e));
178
178
  return;
179
179
  }
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);
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);
184
184
  let e = "";
185
- m === "one-time" ? (Q.current = await w.createOnetimePayment({
186
- paymentChain: E,
187
- paymentToken: O,
188
- orderId: h,
185
+ h === "one-time" ? (Q.current = await T.createOnetimePayment({
186
+ paymentChain: O,
187
+ paymentToken: A,
188
+ orderId: g,
189
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,
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
194
  amountOfUsd: Z,
195
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, {
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, {
197
197
  width: 200,
198
198
  margin: 2,
199
199
  errorCorrectionLevel: "H"
200
200
  }));
201
201
  } catch (e) {
202
- let t = e instanceof Error ? e.message : "创建支付失败";
203
- C?.(t), _?.(e);
202
+ let t = e instanceof Error ? e.message : E.createPaymentFailed;
203
+ w?.(t), v?.(e);
204
204
  }
205
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));
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
210
  })).subscribe({
211
211
  error: (e) => {
212
212
  if (Q.current) {
213
- let t = e instanceof Error ? e.message : "检查支付状态失败";
214
- y("error"), C?.(t), _?.(e);
213
+ let t = e instanceof Error ? e.message : E.checkPaymentStatusFailed;
214
+ b("error"), w?.(t), v?.(e);
215
215
  }
216
216
  },
217
217
  complete: () => {
218
- U.current?.unsubscribe();
218
+ W.current?.unsubscribe();
219
219
  }
220
220
  });
221
221
  };
222
222
  return useEffect(() => {
223
- T.length === 0 && De();
223
+ D.length === 0 && Ae();
224
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", {
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
229
  className: "_cppay-content",
230
- children: v === "success" ? /* @__PURE__ */ jsxs("div", {
230
+ children: y === "success" ? /* @__PURE__ */ jsxs("div", {
231
231
  className: "_cppay-state-container",
232
232
  children: [
233
233
  /* @__PURE__ */ jsx("div", {
@@ -236,14 +236,14 @@ var PaymentContent_default = ({ apikey: t, ott: n, plain: m, orderId: h, amount:
236
236
  }),
237
237
  /* @__PURE__ */ jsx("h3", {
238
238
  className: "_cppay-state-title",
239
- children: m === "subscription" ? "授权成功!" : "支付成功!"
239
+ children: h === "subscription" ? E.authorizationSuccess : E.paymentSuccess
240
240
  }),
241
241
  /* @__PURE__ */ jsx("p", {
242
242
  className: "_cppay-state-message",
243
- children: m === "subscription" ? "订阅已激活" : "交易已完成"
243
+ children: h === "subscription" ? E.subscriptionActivated : E.transactionCompleted
244
244
  })
245
245
  ]
246
- }) : v === "expired" ? /* @__PURE__ */ jsxs("div", {
246
+ }) : y === "expired" ? /* @__PURE__ */ jsxs("div", {
247
247
  className: "_cppay-state-container",
248
248
  children: [
249
249
  /* @__PURE__ */ jsx("div", {
@@ -252,45 +252,45 @@ var PaymentContent_default = ({ apikey: t, ott: n, plain: m, orderId: h, amount:
252
252
  }),
253
253
  /* @__PURE__ */ jsx("h3", {
254
254
  className: "_cppay-state-title",
255
- children: "支付已过期,请重选创建支付订单"
255
+ children: E.paymentExpired
256
256
  }),
257
257
  /* @__PURE__ */ jsx("button", {
258
- onClick: () => y("select"),
259
- disabled: b || x,
258
+ onClick: () => b("select"),
259
+ disabled: x || S,
260
260
  className: "_cppay-btn _cppay-btn-text",
261
- children: "返回"
261
+ children: E.returnButton
262
262
  })
263
263
  ]
264
- }) : v === "error" ? /* @__PURE__ */ jsxs("div", {
264
+ }) : y === "error" ? /* @__PURE__ */ jsxs("div", {
265
265
  className: "_cppay-state-container",
266
266
  children: [/* @__PURE__ */ jsx("div", {
267
267
  className: "_cppay-state-icon",
268
268
  children: "❌"
269
269
  }), /* @__PURE__ */ jsx("h3", {
270
270
  className: "_cppay-state-title",
271
- children: "检查订单支付状态失败!"
271
+ children: C || E.error
272
272
  })]
273
- }) : v === "failed" ? /* @__PURE__ */ jsxs("div", {
273
+ }) : y === "failed" ? /* @__PURE__ */ jsxs("div", {
274
274
  className: "_cppay-state-container",
275
275
  children: [/* @__PURE__ */ jsx("div", {
276
276
  className: "_cppay-state-icon",
277
277
  children: "❌"
278
278
  }), /* @__PURE__ */ jsx("h3", {
279
279
  className: "_cppay-state-title",
280
- children: "订单支付失败!"
280
+ children: E.paymentFailed
281
281
  })]
282
- }) : v === "select" ? /* @__PURE__ */ jsxs("div", { children: [
283
- be?.ChooseTop,
282
+ }) : y === "select" ? /* @__PURE__ */ jsxs("div", { children: [
283
+ xe?.ChooseTop,
284
284
  /* @__PURE__ */ jsxs("div", {
285
285
  className: "_cppay-section",
286
286
  children: [/* @__PURE__ */ jsx("label", {
287
287
  className: "_cppay-label",
288
- children: "支付网络"
288
+ children: E.paymentNetwork
289
289
  }), /* @__PURE__ */ jsx("div", {
290
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" : ""}`,
291
+ children: D.map((e) => /* @__PURE__ */ jsxs("button", {
292
+ onClick: () => k(e.chain),
293
+ className: `_cppay-select-btn ${O === e.chain ? "_cppay-selected" : ""}`,
294
294
  children: [e.icon && /* @__PURE__ */ jsx("img", {
295
295
  src: e.icon,
296
296
  alt: e.chain
@@ -302,12 +302,12 @@ var PaymentContent_default = ({ apikey: t, ott: n, plain: m, orderId: h, amount:
302
302
  className: "_cppay-section",
303
303
  children: [/* @__PURE__ */ jsx("label", {
304
304
  className: "_cppay-label",
305
- children: "支付代币"
305
+ children: E.paymentToken
306
306
  }), /* @__PURE__ */ jsx("div", {
307
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" : ""}`,
308
+ children: q.map((e) => /* @__PURE__ */ jsxs("button", {
309
+ onClick: () => j(e.symbol),
310
+ className: `_cppay-select-btn ${A === e.symbol ? "_cppay-selected" : ""}`,
311
311
  children: [e.icon && /* @__PURE__ */ jsx("img", {
312
312
  src: e.icon,
313
313
  alt: e.symbol
@@ -315,7 +315,7 @@ var PaymentContent_default = ({ apikey: t, ott: n, plain: m, orderId: h, amount:
315
315
  }, e.symbol))
316
316
  })]
317
317
  }),
318
- be?.ChooseBottom,
318
+ xe?.ChooseBottom,
319
319
  /* @__PURE__ */ jsx("div", {
320
320
  className: "_cppay-section",
321
321
  children: /* @__PURE__ */ jsx("div", {
@@ -324,7 +324,7 @@ var PaymentContent_default = ({ apikey: t, ott: n, plain: m, orderId: h, amount:
324
324
  className: "_cppay-price-row",
325
325
  children: [/* @__PURE__ */ jsx("span", {
326
326
  className: "_cppay-price-label",
327
- children: "支付金额"
327
+ children: E.paymentAmount
328
328
  }), /* @__PURE__ */ jsxs("div", {
329
329
  className: "_cppay-price-amount",
330
330
  children: [/* @__PURE__ */ jsxs("div", {
@@ -332,11 +332,11 @@ var PaymentContent_default = ({ apikey: t, ott: n, plain: m, orderId: h, amount:
332
332
  children: [
333
333
  Z ?? "-",
334
334
  " ",
335
- O ?? ""
335
+ A ?? ""
336
336
  ]
337
337
  }), /* @__PURE__ */ jsxs("div", {
338
338
  className: "_cppay-price-sub",
339
- children: ["≈ $", g]
339
+ children: ["≈ $", _]
340
340
  })]
341
341
  })]
342
342
  })
@@ -344,10 +344,10 @@ var PaymentContent_default = ({ apikey: t, ott: n, plain: m, orderId: h, amount:
344
344
  }),
345
345
  /* @__PURE__ */ jsxs("div", {
346
346
  className: "_cppay-section",
347
- children: [S && /* @__PURE__ */ jsxs("div", {
347
+ children: [C && /* @__PURE__ */ jsxs("div", {
348
348
  className: "_cppay-error-tooltip-wrapper",
349
- onMouseEnter: () => V(!0),
350
- onMouseLeave: () => V(!1),
349
+ onMouseEnter: () => H(!0),
350
+ onMouseLeave: () => H(!1),
351
351
  children: [/* @__PURE__ */ jsxs("div", {
352
352
  className: "_cppay-error-tooltip",
353
353
  children: [/* @__PURE__ */ jsx("svg", {
@@ -358,16 +358,16 @@ var PaymentContent_default = ({ apikey: t, ott: n, plain: m, orderId: h, amount:
358
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
359
  clipRule: "evenodd"
360
360
  })
361
- }), /* @__PURE__ */ jsx("span", { children: S })]
362
- }), Ce && /* @__PURE__ */ jsx("div", {
361
+ }), /* @__PURE__ */ jsx("span", { children: C })]
362
+ }), Te && /* @__PURE__ */ jsx("div", {
363
363
  className: "_cppay-error-tooltip-full",
364
- children: S
364
+ children: C
365
365
  })]
366
366
  }), /* @__PURE__ */ jsx("button", {
367
- onClick: Me,
368
- disabled: !E || !O || b,
367
+ onClick: Fe,
368
+ disabled: !O || !A || x,
369
369
  className: "_cppay-btn _cppay-btn-primary",
370
- children: b ? "处理中..." : "继续支付"
370
+ children: x ? E.processing : E.continuePayment
371
371
  })]
372
372
  })
373
373
  ] }) : /* @__PURE__ */ jsxs("div", { children: [
@@ -375,8 +375,8 @@ var PaymentContent_default = ({ apikey: t, ott: n, plain: m, orderId: h, amount:
375
375
  className: "_cppay-qr-container",
376
376
  children: /* @__PURE__ */ jsx("div", {
377
377
  className: "_cppay-qr-code",
378
- children: A && /* @__PURE__ */ jsx("img", {
379
- src: A,
378
+ children: M && /* @__PURE__ */ jsx("img", {
379
+ src: M,
380
380
  alt: "Payment QR Code",
381
381
  className: "_cppay-qr-image"
382
382
  })
@@ -385,7 +385,7 @@ var PaymentContent_default = ({ apikey: t, ott: n, plain: m, orderId: h, amount:
385
385
  /* @__PURE__ */ jsxs("div", {
386
386
  className: "_cppay-section",
387
387
  children: [
388
- q && /* @__PURE__ */ jsx("div", {
388
+ J && /* @__PURE__ */ jsx("div", {
389
389
  className: "_cppay-info-box",
390
390
  children: /* @__PURE__ */ jsx("div", {
391
391
  className: "_cppay-info-flex-container",
@@ -393,10 +393,10 @@ var PaymentContent_default = ({ apikey: t, ott: n, plain: m, orderId: h, amount:
393
393
  className: "_cppay-info-flex-child",
394
394
  children: [/* @__PURE__ */ jsx("div", {
395
395
  className: "_cppay-info-label",
396
- children: m === "subscription" ? "授权金额" : "支付金额"
396
+ children: h === "subscription" ? E.authorizationAmount : E.paymentAmount
397
397
  }), /* @__PURE__ */ jsxs("div", {
398
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] })]
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
400
  })]
401
401
  })
402
402
  })
@@ -407,27 +407,27 @@ var PaymentContent_default = ({ apikey: t, ott: n, plain: m, orderId: h, amount:
407
407
  className: "_cppay-info-flex-child",
408
408
  children: [/* @__PURE__ */ jsxs("div", {
409
409
  className: "_cppay-info-label _cppay-info-label-flex",
410
- children: [/* @__PURE__ */ jsx("span", { children: m === "subscription" ? "授权合约地址" : "支付地址" }), R && /* @__PURE__ */ jsxs("span", {
410
+ children: [/* @__PURE__ */ jsx("span", { children: h === "subscription" ? E.authorizationContractAddress : E.paymentAddress }), B && /* @__PURE__ */ jsxs("span", {
411
411
  className: "_cppay-countdown",
412
- children: ["⏰ ", R]
412
+ children: ["⏰ ", B]
413
413
  })]
414
414
  }), /* @__PURE__ */ jsxs("div", {
415
415
  className: "_cppay-address-row",
416
- children: [/* @__PURE__ */ jsx("code", { children: m === "subscription" ? Q.current.spenderAddress : Q.current.receiveAddress }), /* @__PURE__ */ jsx("button", {
416
+ children: [/* @__PURE__ */ jsx("code", { children: h === "subscription" ? Q.current.spenderAddress : Q.current.receiveAddress }), /* @__PURE__ */ jsx("button", {
417
417
  onClick: async () => {
418
418
  if (!Q.current) return;
419
- let e = m === "subscription" ? Q.current.spenderAddress : Q.current.receiveAddress;
419
+ let e = h === "subscription" ? Q.current.spenderAddress : Q.current.receiveAddress;
420
420
  if (e) try {
421
- await navigator.clipboard.writeText(e), B(!0), setTimeout(() => {
422
- B(!1);
421
+ await navigator.clipboard.writeText(e), we(!0), setTimeout(() => {
422
+ we(!1);
423
423
  }, 2e3);
424
424
  } catch (e) {
425
425
  console.error("复制失败:", e);
426
426
  }
427
427
  },
428
- className: `_cppay-copy-btn ${z ? "_cppay-copy-success" : ""}`,
429
- title: z ? "已复制!" : "复制地址",
430
- children: z ? /* @__PURE__ */ jsx("svg", {
428
+ className: `_cppay-copy-btn ${V ? "_cppay-copy-success" : ""}`,
429
+ title: V ? E.copied : E.copyAddress,
430
+ children: V ? /* @__PURE__ */ jsx("svg", {
431
431
  className: "_cppay-copy-icon",
432
432
  viewBox: "0 0 24 24",
433
433
  fill: "currentColor",
@@ -451,22 +451,22 @@ var PaymentContent_default = ({ apikey: t, ott: n, plain: m, orderId: h, amount:
451
451
  })]
452
452
  })
453
453
  }),
454
- m === "subscription" && /* @__PURE__ */ jsxs("div", {
454
+ h === "subscription" && /* @__PURE__ */ jsxs("div", {
455
455
  className: "_cppay-info-box _cppay-subscription-box",
456
456
  children: [/* @__PURE__ */ jsx("div", {
457
457
  className: "_cppay-info-label _cppay-subscription-label",
458
- children: "📌 订阅说明"
458
+ children: E.subscriptionNotice
459
459
  }), /* @__PURE__ */ jsx("div", {
460
460
  className: "_cppay-info-value _cppay-subscription-message",
461
- children: "订阅支付需要授权代币给合约地址,系统将按周期自动扣款。授权后无需每次手动支付。"
461
+ children: E.subscriptionNoticeMessage
462
462
  })]
463
463
  })
464
464
  ]
465
465
  }),
466
- S && /* @__PURE__ */ jsxs("div", {
466
+ C && /* @__PURE__ */ jsxs("div", {
467
467
  className: "_cppay-error-tooltip-wrapper",
468
- onMouseEnter: () => V(!0),
469
- onMouseLeave: () => V(!1),
468
+ onMouseEnter: () => H(!0),
469
+ onMouseLeave: () => H(!1),
470
470
  children: [/* @__PURE__ */ jsxs("div", {
471
471
  className: "_cppay-error-tooltip",
472
472
  children: [/* @__PURE__ */ jsx("svg", {
@@ -477,76 +477,97 @@ var PaymentContent_default = ({ apikey: t, ott: n, plain: m, orderId: h, amount:
477
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
478
  clipRule: "evenodd"
479
479
  })
480
- }), /* @__PURE__ */ jsx("span", { children: S })]
481
- }), Ce && /* @__PURE__ */ jsx("div", {
480
+ }), /* @__PURE__ */ jsx("span", { children: C })]
481
+ }), Te && /* @__PURE__ */ jsx("div", {
482
482
  className: "_cppay-error-tooltip-full",
483
- children: S
483
+ children: C
484
484
  })]
485
485
  }),
486
- !x && /* @__PURE__ */ jsx("div", {
486
+ !S && /* @__PURE__ */ jsx("div", {
487
487
  className: "_cppay-section",
488
- children: M ? /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("button", {
489
- onClick: je,
490
- disabled: b,
488
+ children: P ? /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("button", {
489
+ onClick: Pe,
490
+ disabled: x,
491
491
  className: "_cppay-btn _cppay-btn-primary",
492
- children: b ? m === "subscription" ? "授权中..." : "支付中..." : m === "subscription" ? "💳 钱包授权" : "💳 钱包支付"
492
+ children: x ? h === "subscription" ? E.authorizing : E.processing : h === "subscription" ? `💳 ${E.connectWallet}` : `💳 ${E.walletPay}`
493
493
  }), /* @__PURE__ */ jsxs("button", {
494
- onClick: we,
495
- disabled: b,
494
+ onClick: Ee,
495
+ disabled: x,
496
496
  className: "_cppay-btn _cppay-wallet-address-btn",
497
- title: "点击修改或查看钱包状态",
497
+ title: E.clickToModifyWallet,
498
498
  children: [/* @__PURE__ */ jsxs("span", {
499
499
  className: "_cppay-wallet-address-text",
500
500
  children: [
501
- M.slice(0, 10),
501
+ P.slice(0, 10),
502
502
  "...",
503
- M.slice(-4)
503
+ P.slice(-4)
504
504
  ]
505
505
  }), /* @__PURE__ */ jsx("svg", {
506
- className: "_cppay-wallet-icon",
506
+ className: "_cppay-wallet-arrow",
507
507
  viewBox: "0 0 24 24",
508
508
  fill: "none",
509
509
  stroke: "currentColor",
510
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" })
511
+ children: /* @__PURE__ */ jsx("polyline", { points: "6 9 12 15 18 9" })
512
512
  })]
513
513
  })] }) : /* @__PURE__ */ jsx("button", {
514
- onClick: we,
515
- disabled: P,
514
+ onClick: Ee,
515
+ disabled: I,
516
516
  className: "_cppay-btn _cppay-btn-secondary _cppay-connect-wallet-btn",
517
- children: /* @__PURE__ */ jsx("span", { children: P ? "连接中..." : "💳 连接钱包" })
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
518
539
  })
519
540
  })
520
541
  ] })
521
542
  });
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();
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();
524
545
  useEffect(() => {
525
- if (l === "success") {
546
+ if (d === "success") {
526
547
  let e = setTimeout(() => {
527
- p();
548
+ m();
528
549
  }, 1e3);
529
550
  return () => clearTimeout(e);
530
551
  }
531
- }, [l]), useEffect(() => {
532
- e || (fe("select"), f(void 0), pe(!1), me(!1));
552
+ }, [d]), useEffect(() => {
553
+ e || (de("select"), he(void 0), fe(!1), pe(!1));
533
554
  }, [e]), useEffect(() => {
534
555
  if (!e) return;
535
556
  let t = (e) => {
536
- e.key === "Escape" && !u && !d && p();
557
+ e.key === "Escape" && !f && !p && m();
537
558
  };
538
559
  return window.addEventListener("keydown", t), () => window.removeEventListener("keydown", t);
539
560
  }, [
540
561
  e,
541
- u,
542
- d
562
+ f,
563
+ p
543
564
  ]);
544
- let p = () => {
545
- u || d || t();
546
- };
565
+ let m = () => {
566
+ f || p || t();
567
+ }, h = useMemo(() => getLocaleMessages(l), [l]);
547
568
  return e ? /* @__PURE__ */ jsx("div", {
548
569
  className: "_cppay-overlay",
549
- onClick: (e) => e.target === e.currentTarget && !u && !d && p(),
570
+ onClick: (e) => e.target === e.currentTarget && !f && !p && m(),
550
571
  children: /* @__PURE__ */ jsxs("div", {
551
572
  className: "_cppay-dialog",
552
573
  children: [/* @__PURE__ */ jsxs("div", {
@@ -554,18 +575,18 @@ var PaymentContent_default = ({ apikey: t, ott: n, plain: m, orderId: h, amount:
554
575
  children: [/* @__PURE__ */ jsx("h2", {
555
576
  className: "_cppay-title",
556
577
  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 "选择支付方式";
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;
564
585
  }
565
586
  })()
566
587
  }), /* @__PURE__ */ jsx("button", {
567
- onClick: p,
568
- disabled: u || d,
588
+ onClick: m,
589
+ disabled: f || p,
569
590
  className: "_cppay-close-btn",
570
591
  children: /* @__PURE__ */ jsx("svg", {
571
592
  fill: "none",
@@ -580,66 +601,67 @@ var PaymentContent_default = ({ apikey: t, ott: n, plain: m, orderId: h, amount:
580
601
  })
581
602
  })]
582
603
  }), /* @__PURE__ */ jsx(PaymentContent_default, {
583
- apikey: r,
604
+ apikey: i,
584
605
  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
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
600
622
  })]
601
623
  })
602
624
  }) : null;
603
625
  }, CppayContext = createContext(null);
604
626
  const CppayProvider = ({ apikey: e, children: t }) => {
605
- let [n, r] = useState(!1), [i, ce] = useState(null), a = useCallback((e) => {
606
- ce(e), r(!0);
607
- }, []), o = useCallback(() => {
608
- r(!1);
627
+ let [n, r] = useState(!1), [i, a] = useState(null), o = useCallback((e) => {
628
+ a(e), r(!0);
609
629
  }, []), s = useCallback(() => {
610
630
  r(!1);
611
- }, []), c = useCallback((e) => {
631
+ }, []), c = useCallback(() => {
632
+ r(!1);
633
+ }, []), l = useCallback((e) => {
612
634
  i?.onSuccess?.(e), setTimeout(() => r(!1), 1e3);
613
- }, [i]), le = useCallback((e) => {
635
+ }, [i]), se = useCallback((e) => {
614
636
  i?.onExpired?.(e);
615
- }, [i]), ue = useCallback((e) => {
637
+ }, [i]), u = useCallback((e) => {
616
638
  i?.onFailed?.(e);
617
- }, [i]), de = useCallback((e) => {
639
+ }, [i]), ce = useCallback((e) => {
618
640
  i?.onError?.(e);
619
641
  }, [i]);
620
642
  return useEffect(() => {
621
643
  if (!n) return;
622
644
  let e = (e) => {
623
- e.key === "Escape" && s();
645
+ e.key === "Escape" && c();
624
646
  };
625
647
  return document.addEventListener("keydown", e), () => document.removeEventListener("keydown", e);
626
- }, [n, s]), /* @__PURE__ */ jsxs(CppayContext.Provider, {
648
+ }, [n, c]), /* @__PURE__ */ jsxs(CppayContext.Provider, {
627
649
  value: {
628
- showPayment: a,
629
- closePayment: o
650
+ showPayment: o,
651
+ closePayment: s
630
652
  },
631
653
  children: [t, i && /* @__PURE__ */ jsx(PaymentDialog_default, {
632
654
  open: n,
633
- onClose: s,
655
+ onClose: c,
634
656
  apikey: e,
635
657
  plain: i.plain,
636
658
  orderId: i.orderId,
637
659
  amount: i.amount,
638
660
  intervalDays: i.intervalDays,
639
- onSuccess: c,
640
- onExpired: le,
641
- onFailed: ue,
642
- onError: de
661
+ onSuccess: l,
662
+ onExpired: se,
663
+ onFailed: u,
664
+ onError: ce
643
665
  })]
644
666
  });
645
667
  }, useCppayPayment = () => {