cppay-sdk 0.0.2-beta.36 → 0.0.2-beta.38
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/{cppay-GXgivhbP.cjs → cppay-B52ulQGn.cjs} +1 -1
- package/dist/{cppay-DnoMkyVy.js → cppay-J9nBy01A.js} +2 -2
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.js +1 -1
- package/dist/locales-De6oJnka.js +112 -0
- package/dist/locales-DfK0OLJI.cjs +1 -0
- package/dist/react.cjs +1 -1
- package/dist/react.d.ts +6 -10
- package/dist/react.js +243 -246
- package/dist/vue.cjs +1 -1
- package/dist/vue.d.ts +9 -19
- package/dist/vue.js +245 -255
- package/package.json +1 -1
- package/dist/locales-KW7cSv4d.js +0 -112
- package/dist/locales-mdiXS8LU.cjs +0 -1
package/dist/react.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { t as cppay_default } from "./cppay-
|
|
2
|
-
import { n as injectStyle, r as payment_dialog_default, t as getLocaleMessages } from "./locales-
|
|
1
|
+
import { t as cppay_default } from "./cppay-J9nBy01A.js";
|
|
2
|
+
import { n as injectStyle, r as payment_dialog_default, t as getLocaleMessages } from "./locales-De6oJnka.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,8 +9,8 @@ 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: p, orderId: m, amount: h, intervalDays: ve, locale: g, onSuccess: ye, onExpired: be, onFailed: xe, onError: _, Slots: Se, onPaymentStepChange: Ce }) => {
|
|
13
|
+
let v = useMemo(() => new cppay_default(t, n), [t, n]), y = useMemo(() => getLocaleMessages(g), [g]), [b, x] = useState("select"), S = useMemo(() => b === "checking", [b]), [C, w] = useState(!1), [T, E] = useState(), [D, we] = useState([]), [O, k] = useState(), [A, j] = useState(), [M, Te] = useState(), [N, P] = useState(), [F, I] = useState(!1), [L, R] = useState(), [z, Ee] = useState(""), [B, De] = useState(!1), [Oe, V] = useState(!1), H = useRef(null), U = useRef(null), W = useRef(null), G = useRef(null);
|
|
14
14
|
useEffect(() => {
|
|
15
15
|
typeof window < "u" && !H.current && (H.current = createAppKit({
|
|
16
16
|
debug: !1,
|
|
@@ -33,30 +33,24 @@ var PaymentContent_default = ({ apikey: t, ott: n, plain: h, orderId: g, amount:
|
|
|
33
33
|
icons: ["https://cppay.com/icon.png"]
|
|
34
34
|
},
|
|
35
35
|
features: { analytics: !1 }
|
|
36
|
-
}),
|
|
37
|
-
e.isConnected ?
|
|
36
|
+
}), P(H.current.getAddress()), R(H.current.getProvider("eip155")), H.current.subscribeAccount((e) => {
|
|
37
|
+
e.isConnected ? P(e.address) : (P(void 0), R(void 0));
|
|
38
38
|
}), H.current.subscribeProviders((e) => {
|
|
39
39
|
let t = e?.eip155;
|
|
40
|
-
|
|
40
|
+
R(t);
|
|
41
41
|
}));
|
|
42
42
|
}, []), useEffect(() => {
|
|
43
|
-
|
|
44
|
-
}, [
|
|
45
|
-
|
|
46
|
-
}, [O, xe]), useEffect(() => {
|
|
47
|
-
S?.(k);
|
|
48
|
-
}, [k, S]);
|
|
49
|
-
let G = async () => {
|
|
43
|
+
Ce?.(b);
|
|
44
|
+
}, [b]);
|
|
45
|
+
let ke = async () => {
|
|
50
46
|
try {
|
|
51
|
-
|
|
47
|
+
I(!0), E(void 0), H.current && await H.current.open();
|
|
52
48
|
} catch (e) {
|
|
53
|
-
console.error("钱包连接失败:", e);
|
|
54
|
-
let t = e instanceof Error ? e.message : w.walletConnectionFailed;
|
|
55
|
-
S?.(t), y?.(e);
|
|
49
|
+
console.error("钱包连接失败:", e), E(e instanceof Error ? e.message : y.walletConnectionFailed), _?.(e);
|
|
56
50
|
} finally {
|
|
57
|
-
|
|
51
|
+
I(!1);
|
|
58
52
|
}
|
|
59
|
-
}, K = useMemo(() =>
|
|
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) => [
|
|
60
54
|
"USDT",
|
|
61
55
|
"USDC",
|
|
62
56
|
"BUSD",
|
|
@@ -67,93 +61,105 @@ var PaymentContent_default = ({ apikey: t, ott: n, plain: h, orderId: g, amount:
|
|
|
67
61
|
].includes(e.toUpperCase()) ? 2 : 6, X = (e, t) => {
|
|
68
62
|
let n = parseFloat(e);
|
|
69
63
|
return isNaN(n) ? "0" : n.toFixed(t).replace(/\.?0+$/, "");
|
|
70
|
-
},
|
|
71
|
-
if (e <= 0) return
|
|
64
|
+
}, Ae = (e) => {
|
|
65
|
+
if (e <= 0) return y.expired;
|
|
72
66
|
let t = Math.floor(e / 3600), n = Math.floor(e % 3600 / 60), r = e % 60;
|
|
73
|
-
return t > 0 ? `${t}${
|
|
74
|
-
},
|
|
67
|
+
return t > 0 ? `${t}${y.hours}${n}${y.minutes}${r}${y.seconds}` : `${n}${y.minutes}${r}${y.seconds}`;
|
|
68
|
+
}, je = (e) => {
|
|
75
69
|
W.current && clearInterval(W.current);
|
|
76
70
|
let t = () => {
|
|
71
|
+
if (b === "checking") {
|
|
72
|
+
Z();
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
77
75
|
let t = e - Math.floor(Date.now() / 1e3);
|
|
78
|
-
Ae(
|
|
76
|
+
Ee(Ae(t)), t <= 0 && (x("expired"), Z());
|
|
79
77
|
};
|
|
80
78
|
t(), W.current = setInterval(t, 1e3);
|
|
81
|
-
},
|
|
79
|
+
}, Z = () => {
|
|
82
80
|
W.current &&= (clearInterval(W.current), null);
|
|
83
|
-
},
|
|
84
|
-
if (!
|
|
81
|
+
}, Q = useMemo(() => {
|
|
82
|
+
if (!A || !J) return "0";
|
|
85
83
|
let e = parseFloat(J.price);
|
|
86
84
|
if (isNaN(e) || e === 0) return "0";
|
|
87
|
-
let t = Y(
|
|
88
|
-
return X((parseFloat(
|
|
85
|
+
let t = Y(A);
|
|
86
|
+
return X((parseFloat(h) / e).toFixed(t), t);
|
|
89
87
|
}, [
|
|
90
|
-
|
|
91
|
-
|
|
88
|
+
h,
|
|
89
|
+
A,
|
|
92
90
|
J
|
|
93
|
-
]),
|
|
91
|
+
]), Me = async () => {
|
|
94
92
|
try {
|
|
95
|
-
|
|
96
|
-
let e = await
|
|
97
|
-
|
|
93
|
+
w(!0), E(void 0);
|
|
94
|
+
let e = await v.getSupportedChains();
|
|
95
|
+
we(e), e.length > 0 && k(e[0].chain);
|
|
98
96
|
} catch (e) {
|
|
99
|
-
|
|
100
|
-
|
|
97
|
+
E(e instanceof Error ? e.message : y.loadPaymentNetworkFailed), _?.(e);
|
|
98
|
+
} finally {
|
|
99
|
+
w(!1);
|
|
101
100
|
}
|
|
102
|
-
},
|
|
103
|
-
if (
|
|
104
|
-
await
|
|
101
|
+
}, Ne = async (e) => {
|
|
102
|
+
if (L) try {
|
|
103
|
+
await L.request({
|
|
105
104
|
method: "wallet_switchEthereumChain",
|
|
106
105
|
params: [{ chainId: `0x${e.toString(16)}` }]
|
|
107
106
|
});
|
|
108
107
|
} catch (e) {
|
|
109
|
-
throw e.code === 4902 ? Error(
|
|
108
|
+
throw e.code === 4902 ? Error(y.pleaseAddNetwork) : e;
|
|
110
109
|
}
|
|
111
|
-
},
|
|
112
|
-
if (!(!
|
|
113
|
-
|
|
114
|
-
|
|
110
|
+
}, Pe = async () => {
|
|
111
|
+
if (!(!N || !L || !G.current || !J || !K)) try {
|
|
112
|
+
w(!0);
|
|
113
|
+
let e = G.current;
|
|
114
|
+
await Ne(K.chainId);
|
|
115
115
|
let t = createWalletClient({
|
|
116
|
-
account:
|
|
117
|
-
transport: custom(
|
|
116
|
+
account: N,
|
|
117
|
+
transport: custom(L)
|
|
118
118
|
});
|
|
119
|
-
J.address
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
119
|
+
if (J.address) {
|
|
120
|
+
let n = await t.writeContract({
|
|
121
|
+
address: J.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" }]
|
|
131
134
|
}],
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
135
|
+
functionName: "transfer",
|
|
136
|
+
args: [e.receiveAddress, parseUnits(e.paymentAmount, J.decimals)],
|
|
137
|
+
chain: null
|
|
138
|
+
});
|
|
139
|
+
console.log("转账交易哈希:", n);
|
|
140
|
+
} else {
|
|
141
|
+
let n = await t.sendTransaction({
|
|
142
|
+
to: e.receiveAddress,
|
|
143
|
+
value: parseUnits(e.paymentAmount, J.decimals),
|
|
144
|
+
chain: null
|
|
145
|
+
});
|
|
146
|
+
console.log("转账交易哈希:", n);
|
|
147
|
+
}
|
|
148
|
+
w(!1), x("checking");
|
|
142
149
|
} catch (e) {
|
|
143
|
-
console.error("钱包支付失败:", e);
|
|
144
|
-
let t = e instanceof Error ? e.message : w.walletPaymentFailed;
|
|
145
|
-
S?.(t), y?.(e);
|
|
150
|
+
console.error("钱包支付失败:", e), E(e instanceof Error ? e.message : y.walletPaymentFailed), _?.(e), w(!1);
|
|
146
151
|
}
|
|
147
|
-
},
|
|
148
|
-
if (!(!
|
|
149
|
-
|
|
150
|
-
|
|
152
|
+
}, Fe = async () => {
|
|
153
|
+
if (!(!N || !L || !G.current || !J || !K)) try {
|
|
154
|
+
w(!0);
|
|
155
|
+
let e = G.current;
|
|
156
|
+
await Ne(K.chainId);
|
|
151
157
|
let t = createWalletClient({
|
|
152
|
-
account:
|
|
153
|
-
transport: custom(
|
|
158
|
+
account: N,
|
|
159
|
+
transport: custom(L)
|
|
154
160
|
});
|
|
155
|
-
if (!J.address) throw Error(
|
|
156
|
-
await t.writeContract({
|
|
161
|
+
if (!J.address) throw Error(y.subscriptionDoesNotSupportNative);
|
|
162
|
+
let n = await t.writeContract({
|
|
157
163
|
address: J.address,
|
|
158
164
|
abi: [{
|
|
159
165
|
name: "approve",
|
|
@@ -171,53 +177,55 @@ var PaymentContent_default = ({ apikey: t, ott: n, plain: h, orderId: g, amount:
|
|
|
171
177
|
functionName: "approve",
|
|
172
178
|
args: [e.spenderAddress, parseUnits(e.approveAmount, J.decimals)],
|
|
173
179
|
chain: null
|
|
174
|
-
})
|
|
180
|
+
});
|
|
181
|
+
console.log("授权交易哈希:", n), w(!1), x("checking");
|
|
175
182
|
} catch (e) {
|
|
176
|
-
console.error("钱包授权失败:", e);
|
|
177
|
-
let t = e instanceof Error ? e.message : w.walletPaymentFailed;
|
|
178
|
-
S?.(t), y?.(e);
|
|
183
|
+
console.error("钱包授权失败:", e), E(e instanceof Error ? e.message : y.walletPaymentFailed), _?.(e), w(!1);
|
|
179
184
|
}
|
|
180
|
-
},
|
|
181
|
-
if (!
|
|
182
|
-
let e =
|
|
183
|
-
|
|
185
|
+
}, Ie = async () => {
|
|
186
|
+
if (!N) {
|
|
187
|
+
let e = y.pleaseConnectWallet;
|
|
188
|
+
E(e), _?.(Error(e));
|
|
184
189
|
return;
|
|
185
190
|
}
|
|
186
|
-
|
|
187
|
-
},
|
|
188
|
-
if (!(!
|
|
189
|
-
|
|
191
|
+
p === "instant" ? await Pe() : p === "subscription" && await Fe();
|
|
192
|
+
}, Le = async () => {
|
|
193
|
+
if (!(!O || !A)) try {
|
|
194
|
+
w(!0), E(void 0);
|
|
190
195
|
let e = "";
|
|
191
|
-
|
|
192
|
-
paymentChain:
|
|
193
|
-
paymentToken:
|
|
194
|
-
orderId:
|
|
195
|
-
amount:
|
|
196
|
-
}), e = `${
|
|
197
|
-
paymentChain:
|
|
198
|
-
paymentToken:
|
|
199
|
-
orderId:
|
|
200
|
-
amountOfUsd:
|
|
201
|
-
intervalDays:
|
|
202
|
-
}), e = `${
|
|
196
|
+
p === "instant" ? (G.current = await v.createOnetimePayment({
|
|
197
|
+
paymentChain: O,
|
|
198
|
+
paymentToken: A,
|
|
199
|
+
orderId: m,
|
|
200
|
+
amount: Q
|
|
201
|
+
}), e = `${O.toLowerCase()}:${G.current.receiveAddress}?amount=${G.current.paymentAmount}`, je(G.current.expireAt), $({ paymentId: G.current.paymentId })) : p === "subscription" && (G.current = await v.createSubscriptionPayment({
|
|
202
|
+
paymentChain: O,
|
|
203
|
+
paymentToken: A,
|
|
204
|
+
orderId: m,
|
|
205
|
+
amountOfUsd: Q,
|
|
206
|
+
intervalDays: ve || 30
|
|
207
|
+
}), e = `${O.toLowerCase()}:${G.current.spenderAddress}?amount=${G.current.approveAmount}`, je(G.current.expireAt), $({ subscriptionId: G.current.subscriptionId })), x("payment"), Te(await QRCode.toDataURL(e, {
|
|
203
208
|
width: 200,
|
|
204
209
|
margin: 2,
|
|
205
210
|
errorCorrectionLevel: "H"
|
|
206
211
|
}));
|
|
207
212
|
} catch (e) {
|
|
208
|
-
|
|
209
|
-
|
|
213
|
+
E(e instanceof Error ? e.message : y.createPaymentFailed), _?.(e);
|
|
214
|
+
} finally {
|
|
215
|
+
w(!1);
|
|
210
216
|
}
|
|
217
|
+
}, Re = () => {
|
|
218
|
+
G.current && (x("checking"), E(void 0));
|
|
211
219
|
}, $ = (e) => {
|
|
212
220
|
U.current?.unsubscribe();
|
|
213
|
-
let t = () => defer(() =>
|
|
221
|
+
let t = () => defer(() => p === "subscription" ? v.checkSubscriptionPaymentStatus(e) : v.checkOnetimePaymentStatus(e)).pipe(timeout(15e3), retry({ delay: 2e3 }));
|
|
214
222
|
U.current = t().pipe(expand((e) => e.status === "pending" ? timer(2e3).pipe(switchMap(() => t())) : EMPTY), tap((e) => {
|
|
215
|
-
(e.status === "paid" || e.status === "approved") && (
|
|
223
|
+
(e.status === "paid" || e.status === "approved") && (x("success"), ye?.(e)), e.status === "expired" && (x("expired"), be?.(e)), e.status === "failed" && (x("failed"), xe?.(e));
|
|
216
224
|
})).subscribe({
|
|
217
225
|
error: (e) => {
|
|
218
|
-
if (
|
|
219
|
-
let t = e instanceof Error ? e.message :
|
|
220
|
-
|
|
226
|
+
if (G.current) {
|
|
227
|
+
let t = e instanceof Error ? e.message : y.checkPaymentStatusFailed;
|
|
228
|
+
x("error"), E(t), _?.(e);
|
|
221
229
|
}
|
|
222
230
|
},
|
|
223
231
|
complete: () => {
|
|
@@ -226,14 +234,14 @@ var PaymentContent_default = ({ apikey: t, ott: n, plain: h, orderId: g, amount:
|
|
|
226
234
|
});
|
|
227
235
|
};
|
|
228
236
|
return useEffect(() => {
|
|
229
|
-
|
|
237
|
+
D.length === 0 && Me();
|
|
230
238
|
}, []), useEffect(() => {
|
|
231
|
-
q.length > 0 &&
|
|
232
|
-
}, [q]), useEffect(() => (
|
|
233
|
-
U.current?.unsubscribe(),
|
|
234
|
-
}), [
|
|
239
|
+
q.length > 0 && j(q[0].symbol);
|
|
240
|
+
}, [q]), useEffect(() => (m && $({ orderId: m }), () => {
|
|
241
|
+
U.current?.unsubscribe(), Z();
|
|
242
|
+
}), [m]), /* @__PURE__ */ jsx("div", {
|
|
235
243
|
className: "_cppay-content",
|
|
236
|
-
children:
|
|
244
|
+
children: b === "success" ? /* @__PURE__ */ jsxs("div", {
|
|
237
245
|
className: "_cppay-state-container",
|
|
238
246
|
children: [
|
|
239
247
|
/* @__PURE__ */ jsx("div", {
|
|
@@ -242,14 +250,14 @@ var PaymentContent_default = ({ apikey: t, ott: n, plain: h, orderId: g, amount:
|
|
|
242
250
|
}),
|
|
243
251
|
/* @__PURE__ */ jsx("h3", {
|
|
244
252
|
className: "_cppay-state-title",
|
|
245
|
-
children:
|
|
253
|
+
children: p === "subscription" ? y.authorizationSuccess : y.paymentSuccess
|
|
246
254
|
}),
|
|
247
255
|
/* @__PURE__ */ jsx("p", {
|
|
248
256
|
className: "_cppay-state-message",
|
|
249
|
-
children:
|
|
257
|
+
children: p === "subscription" ? y.subscriptionActivated : y.transactionCompleted
|
|
250
258
|
})
|
|
251
259
|
]
|
|
252
|
-
}) :
|
|
260
|
+
}) : b === "expired" ? /* @__PURE__ */ jsxs("div", {
|
|
253
261
|
className: "_cppay-state-container",
|
|
254
262
|
children: [
|
|
255
263
|
/* @__PURE__ */ jsx("div", {
|
|
@@ -258,47 +266,45 @@ var PaymentContent_default = ({ apikey: t, ott: n, plain: h, orderId: g, amount:
|
|
|
258
266
|
}),
|
|
259
267
|
/* @__PURE__ */ jsx("h3", {
|
|
260
268
|
className: "_cppay-state-title",
|
|
261
|
-
children:
|
|
269
|
+
children: y.paymentExpired
|
|
262
270
|
}),
|
|
263
271
|
/* @__PURE__ */ jsx("button", {
|
|
264
|
-
onClick: () =>
|
|
265
|
-
|
|
266
|
-
},
|
|
267
|
-
disabled: D || O,
|
|
272
|
+
onClick: () => x("select"),
|
|
273
|
+
disabled: C || S,
|
|
268
274
|
className: "_cppay-btn _cppay-btn-text",
|
|
269
|
-
children:
|
|
275
|
+
children: y.returnButton
|
|
270
276
|
})
|
|
271
277
|
]
|
|
272
|
-
}) :
|
|
278
|
+
}) : b === "error" ? /* @__PURE__ */ jsxs("div", {
|
|
273
279
|
className: "_cppay-state-container",
|
|
274
280
|
children: [/* @__PURE__ */ jsx("div", {
|
|
275
281
|
className: "_cppay-state-icon",
|
|
276
282
|
children: "❌"
|
|
277
283
|
}), /* @__PURE__ */ jsx("h3", {
|
|
278
284
|
className: "_cppay-state-title",
|
|
279
|
-
children:
|
|
285
|
+
children: T || y.error
|
|
280
286
|
})]
|
|
281
|
-
}) :
|
|
287
|
+
}) : b === "failed" ? /* @__PURE__ */ jsxs("div", {
|
|
282
288
|
className: "_cppay-state-container",
|
|
283
289
|
children: [/* @__PURE__ */ jsx("div", {
|
|
284
290
|
className: "_cppay-state-icon",
|
|
285
291
|
children: "❌"
|
|
286
292
|
}), /* @__PURE__ */ jsx("h3", {
|
|
287
293
|
className: "_cppay-state-title",
|
|
288
|
-
children:
|
|
294
|
+
children: y.paymentFailed
|
|
289
295
|
})]
|
|
290
|
-
}) :
|
|
291
|
-
|
|
296
|
+
}) : b === "select" ? /* @__PURE__ */ jsxs("div", { children: [
|
|
297
|
+
Se?.ChooseTop,
|
|
292
298
|
/* @__PURE__ */ jsxs("div", {
|
|
293
299
|
className: "_cppay-section",
|
|
294
300
|
children: [/* @__PURE__ */ jsx("label", {
|
|
295
301
|
className: "_cppay-label",
|
|
296
|
-
children:
|
|
302
|
+
children: y.paymentNetwork
|
|
297
303
|
}), /* @__PURE__ */ jsx("div", {
|
|
298
304
|
className: "_cppay-grid",
|
|
299
|
-
children:
|
|
300
|
-
onClick: () =>
|
|
301
|
-
className: `_cppay-select-btn ${
|
|
305
|
+
children: D.map((e) => /* @__PURE__ */ jsxs("button", {
|
|
306
|
+
onClick: () => k(e.chain),
|
|
307
|
+
className: `_cppay-select-btn ${O === e.chain ? "_cppay-selected" : ""}`,
|
|
302
308
|
children: [e.icon && /* @__PURE__ */ jsx("img", {
|
|
303
309
|
src: e.icon,
|
|
304
310
|
alt: e.chain
|
|
@@ -310,12 +316,12 @@ var PaymentContent_default = ({ apikey: t, ott: n, plain: h, orderId: g, amount:
|
|
|
310
316
|
className: "_cppay-section",
|
|
311
317
|
children: [/* @__PURE__ */ jsx("label", {
|
|
312
318
|
className: "_cppay-label",
|
|
313
|
-
children:
|
|
319
|
+
children: y.paymentToken
|
|
314
320
|
}), /* @__PURE__ */ jsx("div", {
|
|
315
321
|
className: "_cppay-grid",
|
|
316
322
|
children: q.map((e) => /* @__PURE__ */ jsxs("button", {
|
|
317
|
-
onClick: () =>
|
|
318
|
-
className: `_cppay-select-btn ${
|
|
323
|
+
onClick: () => j(e.symbol),
|
|
324
|
+
className: `_cppay-select-btn ${A === e.symbol ? "_cppay-selected" : ""}`,
|
|
319
325
|
children: [e.icon && /* @__PURE__ */ jsx("img", {
|
|
320
326
|
src: e.icon,
|
|
321
327
|
alt: e.symbol
|
|
@@ -323,7 +329,7 @@ var PaymentContent_default = ({ apikey: t, ott: n, plain: h, orderId: g, amount:
|
|
|
323
329
|
}, e.symbol))
|
|
324
330
|
})]
|
|
325
331
|
}),
|
|
326
|
-
|
|
332
|
+
Se?.ChooseBottom,
|
|
327
333
|
/* @__PURE__ */ jsx("div", {
|
|
328
334
|
className: "_cppay-section",
|
|
329
335
|
children: /* @__PURE__ */ jsx("div", {
|
|
@@ -332,19 +338,19 @@ var PaymentContent_default = ({ apikey: t, ott: n, plain: h, orderId: g, amount:
|
|
|
332
338
|
className: "_cppay-price-row",
|
|
333
339
|
children: [/* @__PURE__ */ jsx("span", {
|
|
334
340
|
className: "_cppay-price-label",
|
|
335
|
-
children:
|
|
341
|
+
children: y.paymentAmount
|
|
336
342
|
}), /* @__PURE__ */ jsxs("div", {
|
|
337
343
|
className: "_cppay-price-amount",
|
|
338
344
|
children: [/* @__PURE__ */ jsxs("div", {
|
|
339
345
|
className: "_cppay-price-main",
|
|
340
346
|
children: [
|
|
341
|
-
|
|
347
|
+
Q ?? "-",
|
|
342
348
|
" ",
|
|
343
|
-
|
|
349
|
+
A ?? ""
|
|
344
350
|
]
|
|
345
351
|
}), /* @__PURE__ */ jsxs("div", {
|
|
346
352
|
className: "_cppay-price-sub",
|
|
347
|
-
children: ["≈ $",
|
|
353
|
+
children: ["≈ $", h]
|
|
348
354
|
})]
|
|
349
355
|
})]
|
|
350
356
|
})
|
|
@@ -352,7 +358,7 @@ var PaymentContent_default = ({ apikey: t, ott: n, plain: h, orderId: g, amount:
|
|
|
352
358
|
}),
|
|
353
359
|
/* @__PURE__ */ jsxs("div", {
|
|
354
360
|
className: "_cppay-section",
|
|
355
|
-
children: [
|
|
361
|
+
children: [T && /* @__PURE__ */ jsxs("div", {
|
|
356
362
|
className: "_cppay-error-tooltip-wrapper",
|
|
357
363
|
onMouseEnter: () => V(!0),
|
|
358
364
|
onMouseLeave: () => V(!1),
|
|
@@ -366,16 +372,16 @@ var PaymentContent_default = ({ apikey: t, ott: n, plain: h, orderId: g, amount:
|
|
|
366
372
|
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",
|
|
367
373
|
clipRule: "evenodd"
|
|
368
374
|
})
|
|
369
|
-
}), /* @__PURE__ */ jsx("span", { children:
|
|
370
|
-
}),
|
|
375
|
+
}), /* @__PURE__ */ jsx("span", { children: T })]
|
|
376
|
+
}), Oe && /* @__PURE__ */ jsx("div", {
|
|
371
377
|
className: "_cppay-error-tooltip-full",
|
|
372
|
-
children:
|
|
378
|
+
children: T
|
|
373
379
|
})]
|
|
374
380
|
}), /* @__PURE__ */ jsx("button", {
|
|
375
|
-
onClick:
|
|
376
|
-
disabled: !
|
|
381
|
+
onClick: Le,
|
|
382
|
+
disabled: !O || !A || C,
|
|
377
383
|
className: "_cppay-btn _cppay-btn-primary",
|
|
378
|
-
children:
|
|
384
|
+
children: C ? y.processing : y.continuePayment
|
|
379
385
|
})]
|
|
380
386
|
})
|
|
381
387
|
] }) : /* @__PURE__ */ jsxs("div", { children: [
|
|
@@ -383,8 +389,8 @@ var PaymentContent_default = ({ apikey: t, ott: n, plain: h, orderId: g, amount:
|
|
|
383
389
|
className: "_cppay-qr-container",
|
|
384
390
|
children: /* @__PURE__ */ jsx("div", {
|
|
385
391
|
className: "_cppay-qr-code",
|
|
386
|
-
children:
|
|
387
|
-
src:
|
|
392
|
+
children: M && /* @__PURE__ */ jsx("img", {
|
|
393
|
+
src: M,
|
|
388
394
|
alt: "Payment QR Code",
|
|
389
395
|
className: "_cppay-qr-image"
|
|
390
396
|
})
|
|
@@ -401,10 +407,10 @@ var PaymentContent_default = ({ apikey: t, ott: n, plain: h, orderId: g, amount:
|
|
|
401
407
|
className: "_cppay-info-flex-child",
|
|
402
408
|
children: [/* @__PURE__ */ jsx("div", {
|
|
403
409
|
className: "_cppay-info-label",
|
|
404
|
-
children:
|
|
410
|
+
children: p === "subscription" ? y.authorizationAmount : y.paymentAmount
|
|
405
411
|
}), /* @__PURE__ */ jsxs("div", {
|
|
406
412
|
className: "_cppay-info-value _cppay-info-value-flex",
|
|
407
|
-
children: [/* @__PURE__ */ jsx("span", { children:
|
|
413
|
+
children: [/* @__PURE__ */ jsx("span", { children: p === "subscription" ? `${X(G.current.approveAmount, Y(J.symbol))} ${J.symbol}` : `${X(G.current.paymentAmount, Y(J.symbol))} ${J.symbol}` }), /* @__PURE__ */ jsxs("span", { children: ["≈ $", h] })]
|
|
408
414
|
})]
|
|
409
415
|
})
|
|
410
416
|
})
|
|
@@ -415,26 +421,26 @@ var PaymentContent_default = ({ apikey: t, ott: n, plain: h, orderId: g, amount:
|
|
|
415
421
|
className: "_cppay-info-flex-child",
|
|
416
422
|
children: [/* @__PURE__ */ jsxs("div", {
|
|
417
423
|
className: "_cppay-info-label _cppay-info-label-flex",
|
|
418
|
-
children: [/* @__PURE__ */ jsx("span", { children:
|
|
424
|
+
children: [/* @__PURE__ */ jsx("span", { children: p === "subscription" ? y.authorizationContractAddress : y.paymentAddress }), z && /* @__PURE__ */ jsxs("span", {
|
|
419
425
|
className: "_cppay-countdown",
|
|
420
|
-
children: ["⏰ ",
|
|
426
|
+
children: ["⏰ ", z]
|
|
421
427
|
})]
|
|
422
428
|
}), /* @__PURE__ */ jsxs("div", {
|
|
423
429
|
className: "_cppay-address-row",
|
|
424
|
-
children: [/* @__PURE__ */ jsx("code", { children:
|
|
430
|
+
children: [/* @__PURE__ */ jsx("code", { children: p === "subscription" ? G.current.spenderAddress : G.current.receiveAddress }), /* @__PURE__ */ jsx("button", {
|
|
425
431
|
onClick: async () => {
|
|
426
|
-
if (!
|
|
427
|
-
let e =
|
|
432
|
+
if (!G.current) return;
|
|
433
|
+
let e = p === "subscription" ? G.current.spenderAddress : G.current.receiveAddress;
|
|
428
434
|
if (e) try {
|
|
429
|
-
await navigator.clipboard.writeText(e),
|
|
430
|
-
|
|
435
|
+
await navigator.clipboard.writeText(e), De(!0), setTimeout(() => {
|
|
436
|
+
De(!1);
|
|
431
437
|
}, 2e3);
|
|
432
438
|
} catch (e) {
|
|
433
439
|
console.error("复制失败:", e);
|
|
434
440
|
}
|
|
435
441
|
},
|
|
436
442
|
className: `_cppay-copy-btn ${B ? "_cppay-copy-success" : ""}`,
|
|
437
|
-
title: B ?
|
|
443
|
+
title: B ? y.copied : y.copyAddress,
|
|
438
444
|
children: B ? /* @__PURE__ */ jsx("svg", {
|
|
439
445
|
className: "_cppay-copy-icon",
|
|
440
446
|
viewBox: "0 0 24 24",
|
|
@@ -459,19 +465,19 @@ var PaymentContent_default = ({ apikey: t, ott: n, plain: h, orderId: g, amount:
|
|
|
459
465
|
})]
|
|
460
466
|
})
|
|
461
467
|
}),
|
|
462
|
-
|
|
468
|
+
p === "subscription" && /* @__PURE__ */ jsxs("div", {
|
|
463
469
|
className: "_cppay-info-box _cppay-subscription-box",
|
|
464
470
|
children: [/* @__PURE__ */ jsx("div", {
|
|
465
471
|
className: "_cppay-info-label _cppay-subscription-label",
|
|
466
|
-
children:
|
|
472
|
+
children: y.subscriptionNotice
|
|
467
473
|
}), /* @__PURE__ */ jsx("div", {
|
|
468
474
|
className: "_cppay-info-value _cppay-subscription-message",
|
|
469
|
-
children:
|
|
475
|
+
children: y.subscriptionNoticeMessage
|
|
470
476
|
})]
|
|
471
477
|
})
|
|
472
478
|
]
|
|
473
479
|
}),
|
|
474
|
-
|
|
480
|
+
T && /* @__PURE__ */ jsxs("div", {
|
|
475
481
|
className: "_cppay-error-tooltip-wrapper",
|
|
476
482
|
onMouseEnter: () => V(!0),
|
|
477
483
|
onMouseLeave: () => V(!1),
|
|
@@ -485,30 +491,30 @@ var PaymentContent_default = ({ apikey: t, ott: n, plain: h, orderId: g, amount:
|
|
|
485
491
|
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",
|
|
486
492
|
clipRule: "evenodd"
|
|
487
493
|
})
|
|
488
|
-
}), /* @__PURE__ */ jsx("span", { children:
|
|
489
|
-
}),
|
|
494
|
+
}), /* @__PURE__ */ jsx("span", { children: T })]
|
|
495
|
+
}), Oe && /* @__PURE__ */ jsx("div", {
|
|
490
496
|
className: "_cppay-error-tooltip-full",
|
|
491
|
-
children:
|
|
497
|
+
children: T
|
|
492
498
|
})]
|
|
493
499
|
}),
|
|
494
|
-
!
|
|
500
|
+
!S && /* @__PURE__ */ jsx("div", {
|
|
495
501
|
className: "_cppay-section",
|
|
496
|
-
children:
|
|
497
|
-
onClick:
|
|
498
|
-
disabled:
|
|
502
|
+
children: N ? /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("button", {
|
|
503
|
+
onClick: Ie,
|
|
504
|
+
disabled: C,
|
|
499
505
|
className: "_cppay-btn _cppay-btn-primary",
|
|
500
|
-
children:
|
|
506
|
+
children: C ? p === "subscription" ? y.authorizing : y.processing : p === "subscription" ? `💳 ${y.connectWallet}` : `💳 ${y.walletPay}`
|
|
501
507
|
}), /* @__PURE__ */ jsxs("button", {
|
|
502
|
-
onClick:
|
|
503
|
-
disabled:
|
|
508
|
+
onClick: ke,
|
|
509
|
+
disabled: C,
|
|
504
510
|
className: "_cppay-btn _cppay-wallet-address-btn",
|
|
505
|
-
title:
|
|
511
|
+
title: y.clickToModifyWallet,
|
|
506
512
|
children: [/* @__PURE__ */ jsxs("span", {
|
|
507
513
|
className: "_cppay-wallet-address-text",
|
|
508
514
|
children: [
|
|
509
|
-
|
|
515
|
+
N.slice(0, 10),
|
|
510
516
|
"...",
|
|
511
|
-
|
|
517
|
+
N.slice(-4)
|
|
512
518
|
]
|
|
513
519
|
}), /* @__PURE__ */ jsx("svg", {
|
|
514
520
|
className: "_cppay-wallet-arrow",
|
|
@@ -519,58 +525,50 @@ var PaymentContent_default = ({ apikey: t, ott: n, plain: h, orderId: g, amount:
|
|
|
519
525
|
children: /* @__PURE__ */ jsx("polyline", { points: "6 9 12 15 18 9" })
|
|
520
526
|
})]
|
|
521
527
|
})] }) : /* @__PURE__ */ jsx("button", {
|
|
522
|
-
onClick:
|
|
523
|
-
disabled:
|
|
528
|
+
onClick: ke,
|
|
529
|
+
disabled: F,
|
|
524
530
|
className: "_cppay-btn _cppay-btn-secondary _cppay-connect-wallet-btn",
|
|
525
|
-
children: /* @__PURE__ */ jsx("span", { children:
|
|
531
|
+
children: /* @__PURE__ */ jsx("span", { children: F ? y.processing : `💳 ${y.connectWallet}` })
|
|
526
532
|
})
|
|
527
533
|
}),
|
|
528
534
|
/* @__PURE__ */ jsx("div", {
|
|
529
535
|
className: "_cppay-section",
|
|
530
536
|
children: /* @__PURE__ */ jsx("button", {
|
|
531
|
-
onClick:
|
|
532
|
-
|
|
533
|
-
},
|
|
534
|
-
disabled: O,
|
|
537
|
+
onClick: Re,
|
|
538
|
+
disabled: S,
|
|
535
539
|
className: "_cppay-btn _cppay-btn-primary",
|
|
536
|
-
children:
|
|
540
|
+
children: S ? y.checking : y.completedPayment
|
|
537
541
|
})
|
|
538
542
|
}),
|
|
539
543
|
/* @__PURE__ */ jsx("hr", { className: "_cppay-divider" }),
|
|
540
544
|
/* @__PURE__ */ jsx("div", {
|
|
541
545
|
className: "_cppay-section",
|
|
542
546
|
children: /* @__PURE__ */ jsx("button", {
|
|
543
|
-
onClick: () =>
|
|
544
|
-
|
|
545
|
-
},
|
|
546
|
-
disabled: D || O,
|
|
547
|
+
onClick: () => x("select"),
|
|
548
|
+
disabled: C || S,
|
|
547
549
|
className: "_cppay-btn _cppay-btn-text",
|
|
548
|
-
children:
|
|
550
|
+
children: y.changePaymentMethod
|
|
549
551
|
})
|
|
550
552
|
})
|
|
551
553
|
] })
|
|
552
554
|
});
|
|
553
|
-
}, PaymentDialog_default = ({ open: e, onClose: t, ott: n, apikey: i, plain:
|
|
554
|
-
let
|
|
555
|
+
}, PaymentDialog_default = ({ open: e, onClose: t, ott: n, apikey: i, plain: de, orderId: fe, amount: pe, intervalDays: a, locale: o, onExpired: me, onSuccess: he, onFailed: s, onError: ge, Slots: _e }) => {
|
|
556
|
+
let [c, l] = useState("select"), u = useMemo(() => c !== "checking", [c]);
|
|
555
557
|
useEffect(() => {
|
|
556
|
-
e
|
|
558
|
+
e || l("select");
|
|
557
559
|
}, [e]), useEffect(() => {
|
|
558
560
|
if (!e) return;
|
|
559
561
|
let t = (e) => {
|
|
560
|
-
e.key === "Escape" &&
|
|
562
|
+
e.key === "Escape" && u && d();
|
|
561
563
|
};
|
|
562
564
|
return window.addEventListener("keydown", t), () => window.removeEventListener("keydown", t);
|
|
563
|
-
}, [
|
|
564
|
-
|
|
565
|
-
u
|
|
566
|
-
|
|
567
|
-
]);
|
|
568
|
-
let p = () => {
|
|
569
|
-
u || d || t();
|
|
570
|
-
}, m = useMemo(() => getLocaleMessages(c), [c]);
|
|
565
|
+
}, [e, u]);
|
|
566
|
+
let d = () => {
|
|
567
|
+
u && t();
|
|
568
|
+
}, f = useMemo(() => getLocaleMessages(o), [o]);
|
|
571
569
|
return e ? /* @__PURE__ */ jsx("div", {
|
|
572
570
|
className: "_cppay-overlay",
|
|
573
|
-
onClick: (e) => e.target === e.currentTarget &&
|
|
571
|
+
onClick: (e) => e.target === e.currentTarget && d(),
|
|
574
572
|
children: /* @__PURE__ */ jsxs("div", {
|
|
575
573
|
className: "_cppay-dialog",
|
|
576
574
|
children: [/* @__PURE__ */ jsxs("div", {
|
|
@@ -578,18 +576,19 @@ var PaymentContent_default = ({ apikey: t, ott: n, plain: h, orderId: g, amount:
|
|
|
578
576
|
children: [/* @__PURE__ */ jsx("h2", {
|
|
579
577
|
className: "_cppay-title",
|
|
580
578
|
children: (() => {
|
|
581
|
-
switch (
|
|
582
|
-
case "success": return
|
|
583
|
-
case "expired": return
|
|
584
|
-
case "failed": return
|
|
585
|
-
case "error": return
|
|
586
|
-
case "payment":
|
|
587
|
-
|
|
579
|
+
switch (c) {
|
|
580
|
+
case "success": return f.paymentResult;
|
|
581
|
+
case "expired": return f.paymentExpired;
|
|
582
|
+
case "failed": return f.paymentFailed;
|
|
583
|
+
case "error": return f.error;
|
|
584
|
+
case "payment":
|
|
585
|
+
case "checking": return f.completePayment;
|
|
586
|
+
default: return f.selectPaymentMethod;
|
|
588
587
|
}
|
|
589
588
|
})()
|
|
590
589
|
}), /* @__PURE__ */ jsx("button", {
|
|
591
|
-
onClick:
|
|
592
|
-
disabled: u
|
|
590
|
+
onClick: d,
|
|
591
|
+
disabled: !u,
|
|
593
592
|
className: "_cppay-close-btn",
|
|
594
593
|
children: /* @__PURE__ */ jsx("svg", {
|
|
595
594
|
fill: "none",
|
|
@@ -606,62 +605,60 @@ var PaymentContent_default = ({ apikey: t, ott: n, plain: h, orderId: g, amount:
|
|
|
606
605
|
}), /* @__PURE__ */ jsx(PaymentContent_default, {
|
|
607
606
|
apikey: i,
|
|
608
607
|
ott: n,
|
|
609
|
-
plain:
|
|
610
|
-
orderId:
|
|
611
|
-
amount:
|
|
612
|
-
intervalDays:
|
|
613
|
-
locale:
|
|
614
|
-
onSuccess:
|
|
615
|
-
onExpired:
|
|
616
|
-
onFailed:
|
|
617
|
-
onError:
|
|
618
|
-
Slots:
|
|
619
|
-
onPaymentStepChange:
|
|
620
|
-
onLoadingChange: he,
|
|
621
|
-
onIsCheckingPaymentChange: f
|
|
608
|
+
plain: de,
|
|
609
|
+
orderId: fe,
|
|
610
|
+
amount: pe,
|
|
611
|
+
intervalDays: a,
|
|
612
|
+
locale: o,
|
|
613
|
+
onSuccess: he,
|
|
614
|
+
onExpired: me,
|
|
615
|
+
onFailed: s,
|
|
616
|
+
onError: ge,
|
|
617
|
+
Slots: _e,
|
|
618
|
+
onPaymentStepChange: l
|
|
622
619
|
})]
|
|
623
620
|
})
|
|
624
621
|
}) : null;
|
|
625
622
|
}, CppayContext = createContext(null);
|
|
626
623
|
const CppayProvider = ({ apikey: e, children: t }) => {
|
|
627
|
-
let [n, r] = useState(!1), [i,
|
|
628
|
-
|
|
629
|
-
}, []),
|
|
624
|
+
let [n, r] = useState(!1), [i, de] = useState(null), fe = useCallback((e) => {
|
|
625
|
+
de(e), r(!0);
|
|
626
|
+
}, []), pe = useCallback(() => {
|
|
630
627
|
r(!1);
|
|
631
|
-
}, []),
|
|
628
|
+
}, []), a = useCallback(() => {
|
|
632
629
|
r(!1);
|
|
633
|
-
}, []),
|
|
630
|
+
}, []), o = useCallback((e) => {
|
|
634
631
|
i?.onSuccess?.(e), setTimeout(() => r(!1), 1e3);
|
|
635
|
-
}, [i]),
|
|
632
|
+
}, [i]), me = useCallback((e) => {
|
|
636
633
|
i?.onExpired?.(e);
|
|
637
|
-
}, [i]),
|
|
634
|
+
}, [i]), he = useCallback((e) => {
|
|
638
635
|
i?.onFailed?.(e);
|
|
639
|
-
}, [i]),
|
|
636
|
+
}, [i]), s = useCallback((e) => {
|
|
640
637
|
i?.onError?.(e);
|
|
641
638
|
}, [i]);
|
|
642
639
|
return useEffect(() => {
|
|
643
640
|
if (!n) return;
|
|
644
641
|
let e = (e) => {
|
|
645
|
-
e.key === "Escape" &&
|
|
642
|
+
e.key === "Escape" && a();
|
|
646
643
|
};
|
|
647
644
|
return document.addEventListener("keydown", e), () => document.removeEventListener("keydown", e);
|
|
648
|
-
}, [n,
|
|
645
|
+
}, [n, a]), /* @__PURE__ */ jsxs(CppayContext.Provider, {
|
|
649
646
|
value: {
|
|
650
|
-
showPayment:
|
|
651
|
-
closePayment:
|
|
647
|
+
showPayment: fe,
|
|
648
|
+
closePayment: pe
|
|
652
649
|
},
|
|
653
650
|
children: [t, i && /* @__PURE__ */ jsx(PaymentDialog_default, {
|
|
654
651
|
open: n,
|
|
655
|
-
onClose:
|
|
652
|
+
onClose: a,
|
|
656
653
|
apikey: e,
|
|
657
654
|
plain: i.plain,
|
|
658
655
|
orderId: i.orderId,
|
|
659
656
|
amount: i.amount,
|
|
660
657
|
intervalDays: i.intervalDays,
|
|
661
|
-
onSuccess:
|
|
662
|
-
onExpired:
|
|
663
|
-
onFailed:
|
|
664
|
-
onError:
|
|
658
|
+
onSuccess: o,
|
|
659
|
+
onExpired: me,
|
|
660
|
+
onFailed: he,
|
|
661
|
+
onError: s
|
|
665
662
|
})]
|
|
666
663
|
});
|
|
667
664
|
}, useCppayPayment = () => {
|