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/{inject-style-Cd5D3aj8.cjs → locales-DAKREZkH.cjs} +1 -1
- package/dist/{inject-style-DtFJ9cds.js → locales-DGvDecya.js} +108 -3
- package/dist/react.cjs +1 -1
- package/dist/react.d.ts +6 -0
- package/dist/react.js +245 -223
- package/dist/vue.cjs +1 -1
- package/dist/vue.d.ts +6 -0
- package/dist/vue.js +230 -215
- package/package.json +1 -1
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
|
|
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:
|
|
13
|
-
let
|
|
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" && !
|
|
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
|
-
}),
|
|
37
|
-
e.isConnected ?
|
|
38
|
-
}),
|
|
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
|
-
|
|
40
|
+
z(t);
|
|
41
41
|
}));
|
|
42
42
|
}, []);
|
|
43
|
-
let
|
|
43
|
+
let Ee = async () => {
|
|
44
44
|
try {
|
|
45
|
-
|
|
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
|
-
|
|
48
|
+
let t = e instanceof Error ? e.message : E.walletConnectionFailed;
|
|
49
|
+
w?.(t), v?.(e);
|
|
50
50
|
} finally {
|
|
51
|
-
|
|
51
|
+
L(!1);
|
|
52
52
|
}
|
|
53
|
-
},
|
|
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,
|
|
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
|
-
},
|
|
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}
|
|
68
|
-
},
|
|
69
|
-
|
|
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
|
-
|
|
72
|
+
Ce(De(t)), t <= 0 && (b("expired"), ke());
|
|
73
73
|
};
|
|
74
|
-
t(),
|
|
75
|
-
},
|
|
76
|
-
|
|
74
|
+
t(), G.current = setInterval(t, 1e3);
|
|
75
|
+
}, ke = () => {
|
|
76
|
+
G.current &&= (clearInterval(G.current), null);
|
|
77
77
|
}, Z = useMemo(() => {
|
|
78
|
-
if (!
|
|
79
|
-
let e = parseFloat(
|
|
78
|
+
if (!A || !J) return "0";
|
|
79
|
+
let e = parseFloat(J.price);
|
|
80
80
|
if (isNaN(e) || e === 0) return "0";
|
|
81
|
-
let t =
|
|
82
|
-
return
|
|
81
|
+
let t = Y(A);
|
|
82
|
+
return X((parseFloat(_) / e).toFixed(t), t);
|
|
83
83
|
}, [
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
]),
|
|
84
|
+
_,
|
|
85
|
+
A,
|
|
86
|
+
J
|
|
87
|
+
]), Ae = async () => {
|
|
88
88
|
try {
|
|
89
|
-
|
|
90
|
-
let e = await
|
|
91
|
-
|
|
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
|
-
|
|
93
|
+
let t = e instanceof Error ? e.message : E.loadPaymentNetworkFailed;
|
|
94
|
+
w?.(t), v?.(e);
|
|
95
95
|
}
|
|
96
|
-
},
|
|
97
|
-
if (
|
|
98
|
-
await
|
|
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(
|
|
103
|
+
throw e.code === 4902 ? Error(E.pleaseAddNetwork) : e;
|
|
104
104
|
}
|
|
105
|
-
},
|
|
106
|
-
if (!(!
|
|
105
|
+
}, Me = async () => {
|
|
106
|
+
if (!(!P || !R || !Q.current || !J || !K)) try {
|
|
107
107
|
let e = Q.current;
|
|
108
|
-
await
|
|
108
|
+
await je(K.chainId);
|
|
109
109
|
let t = createWalletClient({
|
|
110
|
-
account:
|
|
111
|
-
transport: custom(
|
|
110
|
+
account: P,
|
|
111
|
+
transport: custom(R)
|
|
112
112
|
});
|
|
113
|
-
|
|
114
|
-
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,
|
|
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,
|
|
133
|
+
value: parseUnits(e.paymentAmount, J.decimals),
|
|
134
134
|
chain: null
|
|
135
|
-
}),
|
|
135
|
+
}), N(void 0);
|
|
136
136
|
} catch (e) {
|
|
137
137
|
console.error("钱包支付失败:", e);
|
|
138
|
-
let t = e instanceof Error ? e.message :
|
|
139
|
-
|
|
138
|
+
let t = e instanceof Error ? e.message : E.walletPaymentFailed;
|
|
139
|
+
w?.(t), v?.(e);
|
|
140
140
|
}
|
|
141
|
-
},
|
|
142
|
-
if (!(!
|
|
141
|
+
}, Ne = async () => {
|
|
142
|
+
if (!(!P || !R || !Q.current || !J || !K)) try {
|
|
143
143
|
let e = Q.current;
|
|
144
|
-
await
|
|
144
|
+
await je(K.chainId);
|
|
145
145
|
let t = createWalletClient({
|
|
146
|
-
account:
|
|
147
|
-
transport: custom(
|
|
146
|
+
account: P,
|
|
147
|
+
transport: custom(R)
|
|
148
148
|
});
|
|
149
|
-
if (!
|
|
149
|
+
if (!J.address) throw Error(E.subscriptionDoesNotSupportNative);
|
|
150
150
|
await t.writeContract({
|
|
151
|
-
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,
|
|
166
|
+
args: [e.spenderAddress, parseUnits(e.approveAmount, J.decimals)],
|
|
167
167
|
chain: null
|
|
168
|
-
}),
|
|
168
|
+
}), N(void 0);
|
|
169
169
|
} catch (e) {
|
|
170
170
|
console.error("钱包授权失败:", e);
|
|
171
|
-
let t = e instanceof Error ? e.message :
|
|
172
|
-
|
|
171
|
+
let t = e instanceof Error ? e.message : E.walletPaymentFailed;
|
|
172
|
+
w?.(t), v?.(e);
|
|
173
173
|
}
|
|
174
|
-
},
|
|
175
|
-
if (!
|
|
176
|
-
let e =
|
|
177
|
-
|
|
174
|
+
}, Pe = async () => {
|
|
175
|
+
if (!P) {
|
|
176
|
+
let e = E.pleaseConnectWallet;
|
|
177
|
+
w?.(e), v?.(Error(e));
|
|
178
178
|
return;
|
|
179
179
|
}
|
|
180
|
-
|
|
181
|
-
}, Q = useRef(null),
|
|
182
|
-
if (!(!
|
|
183
|
-
|
|
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
|
-
|
|
186
|
-
paymentChain:
|
|
187
|
-
paymentToken:
|
|
188
|
-
orderId:
|
|
185
|
+
h === "one-time" ? (Q.current = await T.createOnetimePayment({
|
|
186
|
+
paymentChain: O,
|
|
187
|
+
paymentToken: A,
|
|
188
|
+
orderId: g,
|
|
189
189
|
amount: Z
|
|
190
|
-
}), e = `${
|
|
191
|
-
paymentChain:
|
|
192
|
-
paymentToken:
|
|
193
|
-
orderId:
|
|
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 = `${
|
|
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
|
-
|
|
202
|
+
let t = e instanceof Error ? e.message : E.createPaymentFailed;
|
|
203
|
+
w?.(t), v?.(e);
|
|
204
204
|
}
|
|
205
205
|
}, $ = (e) => {
|
|
206
|
-
|
|
207
|
-
let t = () => defer(() =>
|
|
208
|
-
|
|
209
|
-
(e.status === "paid" || e.status === "approved") && (
|
|
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
|
-
|
|
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
|
-
|
|
218
|
+
W.current?.unsubscribe();
|
|
219
219
|
}
|
|
220
220
|
});
|
|
221
221
|
};
|
|
222
222
|
return useEffect(() => {
|
|
223
|
-
|
|
223
|
+
D.length === 0 && Ae();
|
|
224
224
|
}, []), useEffect(() => {
|
|
225
|
-
|
|
226
|
-
}, [
|
|
227
|
-
|
|
228
|
-
}), [
|
|
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:
|
|
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:
|
|
239
|
+
children: h === "subscription" ? E.authorizationSuccess : E.paymentSuccess
|
|
240
240
|
}),
|
|
241
241
|
/* @__PURE__ */ jsx("p", {
|
|
242
242
|
className: "_cppay-state-message",
|
|
243
|
-
children:
|
|
243
|
+
children: h === "subscription" ? E.subscriptionActivated : E.transactionCompleted
|
|
244
244
|
})
|
|
245
245
|
]
|
|
246
|
-
}) :
|
|
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: () =>
|
|
259
|
-
disabled:
|
|
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
|
-
}) :
|
|
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
|
-
}) :
|
|
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
|
-
}) :
|
|
283
|
-
|
|
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:
|
|
292
|
-
onClick: () =>
|
|
293
|
-
className: `_cppay-select-btn ${
|
|
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:
|
|
309
|
-
onClick: () =>
|
|
310
|
-
className: `_cppay-select-btn ${
|
|
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
|
-
|
|
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
|
-
|
|
335
|
+
A ?? ""
|
|
336
336
|
]
|
|
337
337
|
}), /* @__PURE__ */ jsxs("div", {
|
|
338
338
|
className: "_cppay-price-sub",
|
|
339
|
-
children: ["≈ $",
|
|
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: [
|
|
347
|
+
children: [C && /* @__PURE__ */ jsxs("div", {
|
|
348
348
|
className: "_cppay-error-tooltip-wrapper",
|
|
349
|
-
onMouseEnter: () =>
|
|
350
|
-
onMouseLeave: () =>
|
|
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:
|
|
362
|
-
}),
|
|
361
|
+
}), /* @__PURE__ */ jsx("span", { children: C })]
|
|
362
|
+
}), Te && /* @__PURE__ */ jsx("div", {
|
|
363
363
|
className: "_cppay-error-tooltip-full",
|
|
364
|
-
children:
|
|
364
|
+
children: C
|
|
365
365
|
})]
|
|
366
366
|
}), /* @__PURE__ */ jsx("button", {
|
|
367
|
-
onClick:
|
|
368
|
-
disabled: !
|
|
367
|
+
onClick: Fe,
|
|
368
|
+
disabled: !O || !A || x,
|
|
369
369
|
className: "_cppay-btn _cppay-btn-primary",
|
|
370
|
-
children:
|
|
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:
|
|
379
|
-
src:
|
|
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
|
-
|
|
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:
|
|
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:
|
|
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:
|
|
410
|
+
children: [/* @__PURE__ */ jsx("span", { children: h === "subscription" ? E.authorizationContractAddress : E.paymentAddress }), B && /* @__PURE__ */ jsxs("span", {
|
|
411
411
|
className: "_cppay-countdown",
|
|
412
|
-
children: ["⏰ ",
|
|
412
|
+
children: ["⏰ ", B]
|
|
413
413
|
})]
|
|
414
414
|
}), /* @__PURE__ */ jsxs("div", {
|
|
415
415
|
className: "_cppay-address-row",
|
|
416
|
-
children: [/* @__PURE__ */ jsx("code", { children:
|
|
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 =
|
|
419
|
+
let e = h === "subscription" ? Q.current.spenderAddress : Q.current.receiveAddress;
|
|
420
420
|
if (e) try {
|
|
421
|
-
await navigator.clipboard.writeText(e),
|
|
422
|
-
|
|
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 ${
|
|
429
|
-
title:
|
|
430
|
-
children:
|
|
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
|
-
|
|
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
|
-
|
|
466
|
+
C && /* @__PURE__ */ jsxs("div", {
|
|
467
467
|
className: "_cppay-error-tooltip-wrapper",
|
|
468
|
-
onMouseEnter: () =>
|
|
469
|
-
onMouseLeave: () =>
|
|
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:
|
|
481
|
-
}),
|
|
480
|
+
}), /* @__PURE__ */ jsx("span", { children: C })]
|
|
481
|
+
}), Te && /* @__PURE__ */ jsx("div", {
|
|
482
482
|
className: "_cppay-error-tooltip-full",
|
|
483
|
-
children:
|
|
483
|
+
children: C
|
|
484
484
|
})]
|
|
485
485
|
}),
|
|
486
|
-
!
|
|
486
|
+
!S && /* @__PURE__ */ jsx("div", {
|
|
487
487
|
className: "_cppay-section",
|
|
488
|
-
children:
|
|
489
|
-
onClick:
|
|
490
|
-
disabled:
|
|
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:
|
|
492
|
+
children: x ? h === "subscription" ? E.authorizing : E.processing : h === "subscription" ? `💳 ${E.connectWallet}` : `💳 ${E.walletPay}`
|
|
493
493
|
}), /* @__PURE__ */ jsxs("button", {
|
|
494
|
-
onClick:
|
|
495
|
-
disabled:
|
|
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
|
-
|
|
501
|
+
P.slice(0, 10),
|
|
502
502
|
"...",
|
|
503
|
-
|
|
503
|
+
P.slice(-4)
|
|
504
504
|
]
|
|
505
505
|
}), /* @__PURE__ */ jsx("svg", {
|
|
506
|
-
className: "_cppay-wallet-
|
|
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("
|
|
511
|
+
children: /* @__PURE__ */ jsx("polyline", { points: "6 9 12 15 18 9" })
|
|
512
512
|
})]
|
|
513
513
|
})] }) : /* @__PURE__ */ jsx("button", {
|
|
514
|
-
onClick:
|
|
515
|
-
disabled:
|
|
514
|
+
onClick: Ee,
|
|
515
|
+
disabled: I,
|
|
516
516
|
className: "_cppay-btn _cppay-btn-secondary _cppay-connect-wallet-btn",
|
|
517
|
-
children: /* @__PURE__ */ jsx("span", { children:
|
|
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:
|
|
523
|
-
let [
|
|
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 (
|
|
546
|
+
if (d === "success") {
|
|
526
547
|
let e = setTimeout(() => {
|
|
527
|
-
|
|
548
|
+
m();
|
|
528
549
|
}, 1e3);
|
|
529
550
|
return () => clearTimeout(e);
|
|
530
551
|
}
|
|
531
|
-
}, [
|
|
532
|
-
e || (
|
|
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" && !
|
|
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
|
-
|
|
542
|
-
|
|
562
|
+
f,
|
|
563
|
+
p
|
|
543
564
|
]);
|
|
544
|
-
let
|
|
545
|
-
|
|
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 && !
|
|
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 (
|
|
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:
|
|
568
|
-
disabled:
|
|
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:
|
|
604
|
+
apikey: i,
|
|
584
605
|
ott: n,
|
|
585
|
-
plain:
|
|
586
|
-
orderId:
|
|
587
|
-
amount:
|
|
588
|
-
intervalDays:
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
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,
|
|
606
|
-
|
|
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((
|
|
631
|
+
}, []), c = useCallback(() => {
|
|
632
|
+
r(!1);
|
|
633
|
+
}, []), l = useCallback((e) => {
|
|
612
634
|
i?.onSuccess?.(e), setTimeout(() => r(!1), 1e3);
|
|
613
|
-
}, [i]),
|
|
635
|
+
}, [i]), se = useCallback((e) => {
|
|
614
636
|
i?.onExpired?.(e);
|
|
615
|
-
}, [i]),
|
|
637
|
+
}, [i]), u = useCallback((e) => {
|
|
616
638
|
i?.onFailed?.(e);
|
|
617
|
-
}, [i]),
|
|
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" &&
|
|
645
|
+
e.key === "Escape" && c();
|
|
624
646
|
};
|
|
625
647
|
return document.addEventListener("keydown", e), () => document.removeEventListener("keydown", e);
|
|
626
|
-
}, [n,
|
|
648
|
+
}, [n, c]), /* @__PURE__ */ jsxs(CppayContext.Provider, {
|
|
627
649
|
value: {
|
|
628
|
-
showPayment:
|
|
629
|
-
closePayment:
|
|
650
|
+
showPayment: o,
|
|
651
|
+
closePayment: s
|
|
630
652
|
},
|
|
631
653
|
children: [t, i && /* @__PURE__ */ jsx(PaymentDialog_default, {
|
|
632
654
|
open: n,
|
|
633
|
-
onClose:
|
|
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:
|
|
640
|
-
onExpired:
|
|
641
|
-
onFailed:
|
|
642
|
-
onError:
|
|
661
|
+
onSuccess: l,
|
|
662
|
+
onExpired: se,
|
|
663
|
+
onFailed: u,
|
|
664
|
+
onError: ce
|
|
643
665
|
})]
|
|
644
666
|
});
|
|
645
667
|
}, useCppayPayment = () => {
|