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