cppay-sdk 0.0.2-beta.31 → 0.0.2-beta.32
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-DXZVBIDi.cjs → cppay-BYRjTzRF.cjs} +1 -1
- package/dist/{cppay-BPtRBPjB.js → cppay-C_gp2ZZ3.js} +4 -7
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +18 -8
- package/dist/index.js +1 -1
- package/dist/inject-style-Cd5D3aj8.cjs +1 -0
- package/dist/inject-style-DtFJ9cds.js +7 -0
- package/dist/react.cjs +1 -1
- package/dist/react.d.ts +135 -2
- package/dist/react.js +516 -432
- package/dist/vue.cjs +1 -1
- package/dist/vue.d.ts +125 -12
- package/dist/vue.js +438 -350
- package/package.json +1 -1
- package/dist/cppay-sdk.css +0 -2
- package/dist/inject-style-Boo8CMsU.cjs +0 -1
- package/dist/inject-style-CWza6SKp.js +0 -7
package/dist/vue.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { t as cppay_default } from "./cppay-
|
|
2
|
-
import { n as payment_dialog_default, t as injectStyle } from "./inject-style-
|
|
3
|
-
import { Fragment,
|
|
1
|
+
import { t as cppay_default } from "./cppay-C_gp2ZZ3.js";
|
|
2
|
+
import { n as payment_dialog_default, t as injectStyle } from "./inject-style-DtFJ9cds.js";
|
|
3
|
+
import { Fragment, computed, createApp, createCommentVNode, createElementBlock, createElementVNode, createVNode, defineComponent, h, normalizeClass, onMounted, onUnmounted, openBlock, ref, renderList, renderSlot, toDisplayString, watch, withCtx } from "vue";
|
|
4
4
|
import * as QRCode from "qrcode";
|
|
5
5
|
import { EMPTY, defer, timer } from "rxjs";
|
|
6
6
|
import { expand, retry, switchMap, tap, timeout } from "rxjs/operators";
|
|
@@ -8,98 +8,79 @@ import { createWalletClient, custom, parseUnits } from "viem";
|
|
|
8
8
|
import { arbitrum, base, bsc, mainnet, optimism, polygon } from "viem/chains";
|
|
9
9
|
import { createAppKit } from "@reown/appkit";
|
|
10
10
|
import { EthersAdapter } from "@reown/appkit-adapter-ethers";
|
|
11
|
-
var _hoisted_1 = { class: "_cppay-
|
|
11
|
+
var _hoisted_1$1 = { class: "_cppay-content" }, _hoisted_2$1 = {
|
|
12
12
|
key: 0,
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
},
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
margin: "0"
|
|
25
|
-
} }, _hoisted_9 = { key: 1 }, _hoisted_10 = { class: "_cppay-section" }, _hoisted_11 = { class: "_cppay-grid" }, _hoisted_12 = ["onClick"], _hoisted_13 = ["src", "alt"], _hoisted_14 = { class: "_cppay-section" }, _hoisted_15 = { class: "_cppay-grid" }, _hoisted_16 = ["onClick"], _hoisted_17 = ["src", "alt"], _hoisted_18 = { class: "_cppay-section" }, _hoisted_19 = { class: "_cppay-price-box" }, _hoisted_20 = { class: "_cppay-price-row" }, _hoisted_21 = { class: "_cppay-price-amount" }, _hoisted_22 = { class: "_cppay-price-main" }, _hoisted_23 = { class: "_cppay-price-sub" }, _hoisted_24 = { class: "_cppay-section" }, _hoisted_25 = { class: "_cppay-error-tooltip" }, _hoisted_26 = {
|
|
13
|
+
class: "_cppay-state-container"
|
|
14
|
+
}, _hoisted_3$1 = { class: "_cppay-state-title" }, _hoisted_4$1 = { class: "_cppay-state-message" }, _hoisted_5 = {
|
|
15
|
+
key: 1,
|
|
16
|
+
class: "_cppay-state-container"
|
|
17
|
+
}, _hoisted_6 = ["disabled"], _hoisted_7 = {
|
|
18
|
+
key: 2,
|
|
19
|
+
class: "_cppay-state-container"
|
|
20
|
+
}, _hoisted_8 = {
|
|
21
|
+
key: 3,
|
|
22
|
+
class: "_cppay-state-container"
|
|
23
|
+
}, _hoisted_9 = { key: 4 }, _hoisted_10 = { class: "_cppay-section" }, _hoisted_11 = { class: "_cppay-grid" }, _hoisted_12 = ["onClick"], _hoisted_13 = ["src", "alt"], _hoisted_14 = { class: "_cppay-section" }, _hoisted_15 = { class: "_cppay-grid" }, _hoisted_16 = ["onClick"], _hoisted_17 = ["src", "alt"], _hoisted_18 = { class: "_cppay-section" }, _hoisted_19 = { class: "_cppay-price-box" }, _hoisted_20 = { class: "_cppay-price-row" }, _hoisted_21 = { class: "_cppay-price-amount" }, _hoisted_22 = { class: "_cppay-price-main" }, _hoisted_23 = { class: "_cppay-price-sub" }, _hoisted_24 = { class: "_cppay-section" }, _hoisted_25 = { class: "_cppay-error-tooltip" }, _hoisted_26 = {
|
|
26
24
|
key: 0,
|
|
27
25
|
class: "_cppay-error-tooltip-full"
|
|
28
|
-
}, _hoisted_27 = ["disabled"], _hoisted_28 = { key:
|
|
26
|
+
}, _hoisted_27 = ["disabled"], _hoisted_28 = { key: 5 }, _hoisted_29 = { class: "_cppay-qr-container" }, _hoisted_30 = { class: "_cppay-qr-code" }, _hoisted_31 = ["src"], _hoisted_32 = { class: "_cppay-section" }, _hoisted_33 = {
|
|
29
27
|
key: 0,
|
|
30
28
|
class: "_cppay-info-box"
|
|
31
|
-
}, _hoisted_34 = { class: "_cppay-info-
|
|
29
|
+
}, _hoisted_34 = { class: "_cppay-info-flex-container" }, _hoisted_35 = { class: "_cppay-info-flex-child" }, _hoisted_36 = { class: "_cppay-info-label" }, _hoisted_37 = { class: "_cppay-info-value _cppay-info-value-flex" }, _hoisted_38 = { key: 0 }, _hoisted_39 = { class: "_cppay-info-box" }, _hoisted_40 = { class: "_cppay-info-flex-child" }, _hoisted_41 = { class: "_cppay-info-label _cppay-info-label-flex" }, _hoisted_42 = {
|
|
30
|
+
key: 0,
|
|
31
|
+
class: "_cppay-countdown"
|
|
32
|
+
}, _hoisted_43 = { class: "_cppay-address-row" }, _hoisted_44 = { key: 0 }, _hoisted_45 = ["title"], _hoisted_46 = {
|
|
33
|
+
key: 0,
|
|
34
|
+
class: "_cppay-copy-icon",
|
|
35
|
+
viewBox: "0 0 24 24",
|
|
36
|
+
fill: "none",
|
|
37
|
+
stroke: "currentColor",
|
|
38
|
+
"stroke-width": "2"
|
|
39
|
+
}, _hoisted_47 = {
|
|
32
40
|
key: 1,
|
|
33
|
-
class: "_cppay-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
41
|
+
class: "_cppay-copy-icon",
|
|
42
|
+
viewBox: "0 0 24 24",
|
|
43
|
+
fill: "currentColor"
|
|
44
|
+
}, _hoisted_48 = {
|
|
45
|
+
key: 1,
|
|
46
|
+
class: "_cppay-info-box _cppay-subscription-box"
|
|
47
|
+
}, _hoisted_49 = { class: "_cppay-error-tooltip" }, _hoisted_50 = {
|
|
39
48
|
key: 0,
|
|
40
49
|
class: "_cppay-error-tooltip-full"
|
|
41
|
-
},
|
|
50
|
+
}, _hoisted_51 = {
|
|
42
51
|
key: 1,
|
|
43
52
|
class: "_cppay-section"
|
|
44
|
-
},
|
|
45
|
-
|
|
46
|
-
"margin-top": "8px",
|
|
47
|
-
"font-size": "12px",
|
|
48
|
-
color: "#666"
|
|
49
|
-
} }, _hoisted_49 = { class: "_cppay-section" }, _hoisted_50 = ["disabled"], _hoisted_51 = { class: "_cppay-section" }, _hoisted_52 = ["disabled"], PaymentDialog_default = /* @__PURE__ */ ((e, g) => {
|
|
50
|
-
let _ = e.__vccOpts || e;
|
|
51
|
-
for (let [e, v] of g) _[e] = v;
|
|
52
|
-
return _;
|
|
53
|
-
})(/* @__PURE__ */ defineComponent({
|
|
54
|
-
__name: "PaymentDialog",
|
|
53
|
+
}, _hoisted_52 = ["disabled"], _hoisted_53 = ["disabled"], _hoisted_54 = ["disabled"], _hoisted_55 = { class: "_cppay-wallet-address-text" }, PaymentContent_default = /* @__PURE__ */ defineComponent({
|
|
54
|
+
__name: "PaymentContent",
|
|
55
55
|
props: {
|
|
56
|
-
modelValue: { type: Boolean },
|
|
57
56
|
apikey: {},
|
|
58
57
|
orderId: {},
|
|
59
58
|
amount: {},
|
|
60
59
|
plain: { default: "one-time" },
|
|
61
|
-
intervalDays: {
|
|
60
|
+
intervalDays: {},
|
|
61
|
+
paymentStep: {},
|
|
62
|
+
loading: {
|
|
63
|
+
type: Boolean,
|
|
64
|
+
default: !1
|
|
65
|
+
},
|
|
66
|
+
isCheckingPayment: {
|
|
67
|
+
type: Boolean,
|
|
68
|
+
default: !1
|
|
69
|
+
},
|
|
70
|
+
error: {},
|
|
71
|
+
slots: {}
|
|
62
72
|
},
|
|
63
73
|
emits: [
|
|
64
|
-
"update:
|
|
74
|
+
"update:paymentStep",
|
|
65
75
|
"success",
|
|
66
|
-
"
|
|
76
|
+
"expired",
|
|
77
|
+
"failed",
|
|
78
|
+
"error",
|
|
79
|
+
"update:error"
|
|
67
80
|
],
|
|
68
|
-
setup(
|
|
69
|
-
let
|
|
70
|
-
"
|
|
71
|
-
"USDC",
|
|
72
|
-
"BUSD",
|
|
73
|
-
"DAI",
|
|
74
|
-
"TUSD",
|
|
75
|
-
"USDD",
|
|
76
|
-
"FDUSD"
|
|
77
|
-
].includes(e.toUpperCase()) ? 2 : 6, V = (e, g) => {
|
|
78
|
-
let _ = parseFloat(e);
|
|
79
|
-
return isNaN(_) ? "0" : _.toFixed(g).replace(/\.?0+$/, "");
|
|
80
|
-
}, H = computed(() => {
|
|
81
|
-
if (!k.value || !z.value) return "0";
|
|
82
|
-
let e = parseFloat(z.value.price);
|
|
83
|
-
if (isNaN(e) || e === 0) return "0";
|
|
84
|
-
let g = B(k.value);
|
|
85
|
-
return V((parseFloat(y.amount) / e).toFixed(g), g);
|
|
86
|
-
}), U = () => {
|
|
87
|
-
A.value && (T.value = void 0, w.value = !0, y.plain === "one-time" ? Q(A.value.paymentId) : y.plain === "subscription" && Q(A.value.subscriptionId));
|
|
88
|
-
}, W = () => {
|
|
89
|
-
C.value || w.value || (b("update:modelValue", !1), setTimeout(() => {
|
|
90
|
-
S.value = "select", T.value = void 0, A.value = null;
|
|
91
|
-
}, 300));
|
|
92
|
-
}, G = async () => {
|
|
93
|
-
try {
|
|
94
|
-
C.value = !0, T.value = void 0, D.value = await x.getSupportedChains(), D.value.length > 0 && (O.value = D.value[0].chain);
|
|
95
|
-
} catch (e) {
|
|
96
|
-
T.value = e instanceof Error ? e.message : "加载支付网络失败", b("error", e);
|
|
97
|
-
} finally {
|
|
98
|
-
C.value = !1;
|
|
99
|
-
}
|
|
100
|
-
};
|
|
101
|
-
onMounted(() => {
|
|
102
|
-
typeof window < "u" && !I && (I = createAppKit({
|
|
81
|
+
setup(d, { emit: f }) {
|
|
82
|
+
let g = d, _ = f, v = new cppay_default(g.apikey), y = ref([]), S = ref(), C = ref(), w = ref(), T = ref(), E = ref(!1), D = ref(), O = ref(""), k = ref(!1), A = ref(!1), j = ref(null), M = ref(null), N = ref(null), P = ref(null), F = () => {
|
|
83
|
+
typeof window < "u" && !j.value && (j.value = createAppKit({
|
|
103
84
|
debug: !1,
|
|
104
85
|
enableNetworkSwitch: !1,
|
|
105
86
|
adapters: [new EthersAdapter()],
|
|
@@ -120,82 +101,110 @@ var _hoisted_1 = { class: "_cppay-dialog" }, _hoisted_2 = { class: "_cppay-heade
|
|
|
120
101
|
icons: ["https://cppay.com/icon.png"]
|
|
121
102
|
},
|
|
122
103
|
features: { analytics: !1 }
|
|
123
|
-
}),
|
|
124
|
-
|
|
125
|
-
}),
|
|
126
|
-
|
|
104
|
+
}), T.value = j.value.getAddress(), D.value = j.value.getProvider("eip155"), j.value.subscribeAccount((t) => {
|
|
105
|
+
t.isConnected ? T.value = t.address : (T.value = void 0, D.value = void 0);
|
|
106
|
+
}), j.value.subscribeProviders((t) => {
|
|
107
|
+
D.value = t?.eip155;
|
|
127
108
|
}));
|
|
128
|
-
})
|
|
129
|
-
let K = async () => {
|
|
109
|
+
}, I = async () => {
|
|
130
110
|
try {
|
|
131
|
-
|
|
132
|
-
} catch (
|
|
133
|
-
|
|
111
|
+
E.value = !0, _("update:error", void 0), j.value && await j.value.open();
|
|
112
|
+
} catch (t) {
|
|
113
|
+
_("update:error", t instanceof Error ? t.message : "钱包连接失败"), _("error", t);
|
|
134
114
|
} finally {
|
|
135
|
-
|
|
115
|
+
E.value = !1;
|
|
136
116
|
}
|
|
137
|
-
},
|
|
138
|
-
|
|
139
|
-
|
|
117
|
+
}, L = computed(() => y.value.find((t) => t.chain === S.value)), R = computed(() => L.value?.tokens || []), z = computed(() => R.value.find((t) => t.symbol === C.value)), B = (t) => [
|
|
118
|
+
"USDT",
|
|
119
|
+
"USDC",
|
|
120
|
+
"BUSD",
|
|
121
|
+
"DAI",
|
|
122
|
+
"TUSD",
|
|
123
|
+
"USDD",
|
|
124
|
+
"FDUSD"
|
|
125
|
+
].includes(t.toUpperCase()) ? 2 : 6, V = (t, d) => {
|
|
126
|
+
let f = parseFloat(t);
|
|
127
|
+
return isNaN(f) ? "0" : f.toFixed(d).replace(/\.?0+$/, "");
|
|
128
|
+
}, H = (t) => {
|
|
129
|
+
if (t <= 0) return "已过期";
|
|
130
|
+
let d = Math.floor(t / 3600), f = Math.floor(t % 3600 / 60), p = t % 60;
|
|
131
|
+
return d > 0 ? `${d}时${f}分${p}秒` : `${f}分${p}秒`;
|
|
132
|
+
}, U = (t) => {
|
|
133
|
+
N.value && clearInterval(N.value);
|
|
134
|
+
let d = () => {
|
|
135
|
+
let d = t - Math.floor(Date.now() / 1e3);
|
|
136
|
+
O.value = H(d), d <= 0 && (_("update:paymentStep", "expired"), W());
|
|
137
|
+
};
|
|
138
|
+
d(), N.value = setInterval(d, 1e3);
|
|
139
|
+
}, W = () => {
|
|
140
|
+
N.value &&= (clearInterval(N.value), null);
|
|
141
|
+
}, G = computed(() => {
|
|
142
|
+
if (!C.value || !z.value) return "0";
|
|
143
|
+
let t = parseFloat(z.value.price);
|
|
144
|
+
if (isNaN(t) || t === 0) return "0";
|
|
145
|
+
let d = B(C.value);
|
|
146
|
+
return V((parseFloat(g.amount) / t).toFixed(d), d);
|
|
147
|
+
}), K = async () => {
|
|
148
|
+
try {
|
|
149
|
+
_("update:error", void 0);
|
|
150
|
+
let t = await v.getSupportedChains();
|
|
151
|
+
y.value = t, t.length > 0 && (S.value = t[0].chain);
|
|
152
|
+
} catch (t) {
|
|
153
|
+
_("update:error", t instanceof Error ? t.message : "加载支付网络失败"), _("error", t);
|
|
154
|
+
}
|
|
155
|
+
}, q = async (t) => {
|
|
156
|
+
if (D.value) try {
|
|
157
|
+
await D.value.request({
|
|
140
158
|
method: "wallet_switchEthereumChain",
|
|
141
|
-
params: [{ chainId: `0x${
|
|
159
|
+
params: [{ chainId: `0x${t.toString(16)}` }]
|
|
142
160
|
});
|
|
143
|
-
} catch (
|
|
144
|
-
throw
|
|
161
|
+
} catch (t) {
|
|
162
|
+
throw t.code === 4902 ? Error("请在钱包中添加该网络") : t;
|
|
145
163
|
}
|
|
146
164
|
}, J = async () => {
|
|
147
|
-
if (!(!
|
|
148
|
-
|
|
149
|
-
let e = A.value;
|
|
165
|
+
if (!(!T.value || !D.value || !P.value || !z.value || !L.value)) try {
|
|
166
|
+
let t = P.value;
|
|
150
167
|
await q(L.value.chainId);
|
|
151
|
-
let
|
|
152
|
-
account:
|
|
153
|
-
transport: custom(
|
|
168
|
+
let d = createWalletClient({
|
|
169
|
+
account: T.value,
|
|
170
|
+
transport: custom(D.value)
|
|
154
171
|
});
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
type: "uint256"
|
|
168
|
-
}],
|
|
169
|
-
outputs: [{ type: "bool" }]
|
|
172
|
+
z.value.address ? await d.writeContract({
|
|
173
|
+
address: z.value.address,
|
|
174
|
+
abi: [{
|
|
175
|
+
name: "transfer",
|
|
176
|
+
type: "function",
|
|
177
|
+
stateMutability: "nonpayable",
|
|
178
|
+
inputs: [{
|
|
179
|
+
name: "to",
|
|
180
|
+
type: "address"
|
|
181
|
+
}, {
|
|
182
|
+
name: "amount",
|
|
183
|
+
type: "uint256"
|
|
170
184
|
}],
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
}
|
|
184
|
-
C.value = !1, w.value = !0, Q(e.paymentId);
|
|
185
|
-
} catch (e) {
|
|
186
|
-
console.error("钱包支付失败:", e), T.value = e instanceof Error ? e.message : "钱包支付失败", b("error", e), C.value = !1;
|
|
185
|
+
outputs: [{ type: "bool" }]
|
|
186
|
+
}],
|
|
187
|
+
functionName: "transfer",
|
|
188
|
+
args: [t.receiveAddress, parseUnits(t.paymentAmount, z.value.decimals)],
|
|
189
|
+
chain: null
|
|
190
|
+
}) : await d.sendTransaction({
|
|
191
|
+
to: t.receiveAddress,
|
|
192
|
+
value: parseUnits(t.paymentAmount, z.value.decimals),
|
|
193
|
+
chain: null
|
|
194
|
+
}), w.value = void 0;
|
|
195
|
+
} catch (t) {
|
|
196
|
+
_("update:error", t instanceof Error ? t.message : "钱包支付失败"), _("error", t);
|
|
187
197
|
}
|
|
188
198
|
}, Y = async () => {
|
|
189
|
-
if (!(!
|
|
190
|
-
|
|
191
|
-
let e = A.value;
|
|
199
|
+
if (!(!T.value || !D.value || !P.value || !z.value || !L.value)) try {
|
|
200
|
+
let t = P.value;
|
|
192
201
|
await q(L.value.chainId);
|
|
193
|
-
let
|
|
194
|
-
account:
|
|
195
|
-
transport: custom(
|
|
202
|
+
let d = createWalletClient({
|
|
203
|
+
account: T.value,
|
|
204
|
+
transport: custom(D.value)
|
|
196
205
|
});
|
|
197
206
|
if (!z.value.address) throw Error("订阅支付不支持原生代币");
|
|
198
|
-
|
|
207
|
+
await d.writeContract({
|
|
199
208
|
address: z.value.address,
|
|
200
209
|
abi: [{
|
|
201
210
|
name: "approve",
|
|
@@ -211,244 +220,316 @@ var _hoisted_1 = { class: "_cppay-dialog" }, _hoisted_2 = { class: "_cppay-heade
|
|
|
211
220
|
outputs: [{ type: "bool" }]
|
|
212
221
|
}],
|
|
213
222
|
functionName: "approve",
|
|
214
|
-
args: [
|
|
223
|
+
args: [t.spenderAddress, parseUnits(t.approveAmount, z.value.decimals)],
|
|
215
224
|
chain: null
|
|
216
|
-
});
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
console.error("钱包授权失败:", e), T.value = e instanceof Error ? e.message : "钱包授权失败", b("error", e), C.value = !1;
|
|
225
|
+
}), w.value = void 0;
|
|
226
|
+
} catch (t) {
|
|
227
|
+
_("update:error", t instanceof Error ? t.message : "钱包授权失败"), _("error", t);
|
|
220
228
|
}
|
|
221
229
|
}, X = async () => {
|
|
222
|
-
if (!
|
|
223
|
-
|
|
230
|
+
if (!T.value) {
|
|
231
|
+
_("update:error", "请先连接钱包"), _("error", /* @__PURE__ */ Error("请先连接钱包"));
|
|
224
232
|
return;
|
|
225
233
|
}
|
|
226
|
-
|
|
234
|
+
g.plain === "one-time" ? await J() : g.plain === "subscription" && await Y();
|
|
227
235
|
}, Z = async () => {
|
|
228
|
-
if (!(!
|
|
229
|
-
|
|
230
|
-
let
|
|
231
|
-
|
|
232
|
-
paymentChain:
|
|
233
|
-
paymentToken:
|
|
234
|
-
orderId:
|
|
235
|
-
amount:
|
|
236
|
-
}) :
|
|
237
|
-
paymentChain:
|
|
238
|
-
paymentToken:
|
|
239
|
-
orderId:
|
|
240
|
-
amountOfUsd:
|
|
241
|
-
intervalDays:
|
|
242
|
-
})),
|
|
243
|
-
paymentId: e.paymentId || e.subscriptionId,
|
|
244
|
-
paymentAmount: e.paymentAmount || e.approveAmount,
|
|
245
|
-
receiveAddress: e.receiveAddress || e.spenderAddress || ""
|
|
246
|
-
};
|
|
247
|
-
let g = `${O.value.toLowerCase()}:${A.value.receiveAddress}?amount=${A.value.paymentAmount}`;
|
|
248
|
-
j.value = await QRCode.toDataURL(g, {
|
|
236
|
+
if (!(!S.value || !C.value)) try {
|
|
237
|
+
_("update:error", void 0);
|
|
238
|
+
let t = "";
|
|
239
|
+
g.plain === "one-time" ? (P.value = await v.createOnetimePayment({
|
|
240
|
+
paymentChain: S.value,
|
|
241
|
+
paymentToken: C.value,
|
|
242
|
+
orderId: g.orderId,
|
|
243
|
+
amount: G.value
|
|
244
|
+
}), t = `${S.value.toLowerCase()}:${P.value.receiveAddress}?amount=${P.value.paymentAmount}`, U(P.value.expireAt), Q({ paymentId: P.value.paymentId })) : g.plain === "subscription" && (P.value = await v.createSubscriptionPayment({
|
|
245
|
+
paymentChain: S.value,
|
|
246
|
+
paymentToken: C.value,
|
|
247
|
+
orderId: g.orderId,
|
|
248
|
+
amountOfUsd: G.value,
|
|
249
|
+
intervalDays: g.intervalDays || 30
|
|
250
|
+
}), t = `${S.value.toLowerCase()}:${P.value.spenderAddress}?amount=${P.value.approveAmount}`, U(P.value.expireAt), Q({ subscriptionId: P.value.subscriptionId })), _("update:paymentStep", "payment"), w.value = await QRCode.toDataURL(t, {
|
|
249
251
|
width: 200,
|
|
250
252
|
margin: 2,
|
|
251
253
|
errorCorrectionLevel: "H"
|
|
252
|
-
})
|
|
253
|
-
} catch (
|
|
254
|
-
|
|
255
|
-
} finally {
|
|
256
|
-
C.value = !1;
|
|
254
|
+
});
|
|
255
|
+
} catch (t) {
|
|
256
|
+
_("update:error", t instanceof Error ? t.message : "创建支付失败"), _("error", t);
|
|
257
257
|
}
|
|
258
|
-
}, Q = (
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
258
|
+
}, Q = (t) => {
|
|
259
|
+
M.value?.unsubscribe();
|
|
260
|
+
let d = () => defer(() => g.plain === "subscription" ? v.checkSubscriptionPaymentStatus(t) : v.checkOnetimePaymentStatus(t)).pipe(timeout(15e3), retry({ delay: 2e3 }));
|
|
261
|
+
M.value = d().pipe(expand((t) => t.status === "pending" ? timer(2e3).pipe(switchMap(() => d())) : EMPTY), tap((t) => {
|
|
262
|
+
(t.status === "paid" || t.status === "approved") && (_("update:paymentStep", "success"), _("success", t)), t.status === "expired" && (_("update:paymentStep", "expired"), _("expired", t)), t.status === "failed" && (_("update:paymentStep", "failed"), _("failed", t));
|
|
263
|
+
})).subscribe({
|
|
264
|
+
error: (t) => {
|
|
265
|
+
if (P.value) {
|
|
266
|
+
let d = t instanceof Error ? t.message : "检查支付状态失败";
|
|
267
|
+
_("update:paymentStep", "error"), _("update:error", d), _("error", t);
|
|
268
|
+
}
|
|
269
|
+
},
|
|
270
|
+
complete: () => {
|
|
271
|
+
M.value?.unsubscribe();
|
|
272
|
+
}
|
|
273
|
+
});
|
|
268
274
|
}, $ = async () => {
|
|
269
|
-
|
|
275
|
+
if (!P.value) return;
|
|
276
|
+
let t = g.plain === "subscription" ? P.value.spenderAddress : P.value.receiveAddress;
|
|
277
|
+
if (t) try {
|
|
278
|
+
await navigator.clipboard.writeText(t), k.value = !0, setTimeout(() => {
|
|
279
|
+
k.value = !1;
|
|
280
|
+
}, 2e3);
|
|
281
|
+
} catch (t) {
|
|
282
|
+
console.error("复制失败:", t);
|
|
283
|
+
}
|
|
270
284
|
};
|
|
271
|
-
return watch(() =>
|
|
272
|
-
|
|
273
|
-
}), watch(
|
|
274
|
-
|
|
275
|
-
}), watch(
|
|
276
|
-
|
|
285
|
+
return watch(() => g.paymentStep, (t) => {
|
|
286
|
+
t === "select" && y.value.length === 0 && K();
|
|
287
|
+
}, { immediate: !0 }), watch(R, (t) => {
|
|
288
|
+
t.length > 0 && !C.value && (C.value = t[0].symbol);
|
|
289
|
+
}), watch(() => g.orderId, (t) => {
|
|
290
|
+
t && Q({ orderId: t });
|
|
291
|
+
}), onMounted(() => {
|
|
292
|
+
F();
|
|
277
293
|
}), onUnmounted(() => {
|
|
278
|
-
|
|
279
|
-
}), (
|
|
280
|
-
|
|
294
|
+
M.value?.unsubscribe(), W();
|
|
295
|
+
}), (t, f) => (openBlock(), createElementBlock("div", _hoisted_1$1, [d.paymentStep === "success" ? (openBlock(), createElementBlock("div", _hoisted_2$1, [
|
|
296
|
+
f[5] ||= createElementVNode("div", { class: "_cppay-state-icon" }, "✅", -1),
|
|
297
|
+
createElementVNode("h3", _hoisted_3$1, toDisplayString(d.plain === "subscription" ? "授权成功!" : "支付成功!"), 1),
|
|
298
|
+
createElementVNode("p", _hoisted_4$1, toDisplayString(d.plain === "subscription" ? "订阅已激活" : "交易已完成"), 1)
|
|
299
|
+
])) : d.paymentStep === "expired" ? (openBlock(), createElementBlock("div", _hoisted_5, [
|
|
300
|
+
f[6] ||= createElementVNode("div", { class: "_cppay-state-icon" }, "⏰", -1),
|
|
301
|
+
f[7] ||= createElementVNode("h3", { class: "_cppay-state-title" }, "支付已过期,请重选创建支付订单", -1),
|
|
302
|
+
createElementVNode("button", {
|
|
303
|
+
onClick: f[0] ||= (d) => t.$emit("update:paymentStep", "select"),
|
|
304
|
+
disabled: d.loading || d.isCheckingPayment,
|
|
305
|
+
class: "_cppay-btn _cppay-btn-text"
|
|
306
|
+
}, " 返回 ", 8, _hoisted_6)
|
|
307
|
+
])) : d.paymentStep === "error" ? (openBlock(), createElementBlock("div", _hoisted_7, [...f[8] ||= [createElementVNode("div", { class: "_cppay-state-icon" }, "❌", -1), createElementVNode("h3", { class: "_cppay-state-title" }, "检查订单支付状态失败!", -1)]])) : d.paymentStep === "failed" ? (openBlock(), createElementBlock("div", _hoisted_8, [...f[9] ||= [createElementVNode("div", { class: "_cppay-state-icon" }, "❌", -1), createElementVNode("h3", { class: "_cppay-state-title" }, "订单支付失败!", -1)]])) : d.paymentStep === "select" ? (openBlock(), createElementBlock("div", _hoisted_9, [
|
|
308
|
+
renderSlot(t.$slots, "choose-top"),
|
|
309
|
+
createElementVNode("div", _hoisted_10, [f[10] ||= createElementVNode("label", { class: "_cppay-label" }, "支付网络", -1), createElementVNode("div", _hoisted_11, [(openBlock(!0), createElementBlock(Fragment, null, renderList(y.value, (t) => (openBlock(), createElementBlock("button", {
|
|
310
|
+
key: t.chain,
|
|
311
|
+
onClick: (d) => S.value = t.chain,
|
|
312
|
+
class: normalizeClass(["_cppay-select-btn", { "_cppay-selected": S.value === t.chain }])
|
|
313
|
+
}, [t.icon ? (openBlock(), createElementBlock("img", {
|
|
314
|
+
key: 0,
|
|
315
|
+
src: t.icon,
|
|
316
|
+
alt: t.chain
|
|
317
|
+
}, null, 8, _hoisted_13)) : createCommentVNode("", !0), createElementVNode("span", null, toDisplayString(t.chain), 1)], 10, _hoisted_12))), 128))])]),
|
|
318
|
+
createElementVNode("div", _hoisted_14, [f[11] ||= createElementVNode("label", { class: "_cppay-label" }, "支付代币", -1), createElementVNode("div", _hoisted_15, [(openBlock(!0), createElementBlock(Fragment, null, renderList(R.value, (t) => (openBlock(), createElementBlock("button", {
|
|
319
|
+
key: t.symbol,
|
|
320
|
+
onClick: (d) => C.value = t.symbol,
|
|
321
|
+
class: normalizeClass(["_cppay-select-btn", { "_cppay-selected": C.value === t.symbol }])
|
|
322
|
+
}, [t.icon ? (openBlock(), createElementBlock("img", {
|
|
323
|
+
key: 0,
|
|
324
|
+
src: t.icon,
|
|
325
|
+
alt: t.symbol
|
|
326
|
+
}, null, 8, _hoisted_17)) : createCommentVNode("", !0), createElementVNode("span", null, toDisplayString(t.symbol), 1)], 10, _hoisted_16))), 128))])]),
|
|
327
|
+
renderSlot(t.$slots, "choose-bottom"),
|
|
328
|
+
createElementVNode("div", _hoisted_18, [createElementVNode("div", _hoisted_19, [createElementVNode("div", _hoisted_20, [f[12] ||= createElementVNode("span", { class: "_cppay-price-label" }, "支付金额", -1), createElementVNode("div", _hoisted_21, [createElementVNode("div", _hoisted_22, toDisplayString(G.value ?? "-") + " " + toDisplayString(C.value ?? ""), 1), createElementVNode("div", _hoisted_23, "≈ $" + toDisplayString(d.amount), 1)])])])]),
|
|
329
|
+
createElementVNode("div", _hoisted_24, [d.error ? (openBlock(), createElementBlock("div", {
|
|
330
|
+
key: 0,
|
|
331
|
+
class: "_cppay-error-tooltip-wrapper",
|
|
332
|
+
onMouseenter: f[1] ||= (t) => A.value = !0,
|
|
333
|
+
onMouseleave: f[2] ||= (t) => A.value = !1
|
|
334
|
+
}, [createElementVNode("div", _hoisted_25, [f[13] ||= createElementVNode("svg", {
|
|
335
|
+
viewBox: "0 0 20 20",
|
|
336
|
+
fill: "currentColor"
|
|
337
|
+
}, [createElementVNode("path", {
|
|
338
|
+
"fill-rule": "evenodd",
|
|
339
|
+
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",
|
|
340
|
+
"clip-rule": "evenodd"
|
|
341
|
+
})], -1), createElementVNode("span", null, toDisplayString(d.error), 1)]), A.value ? (openBlock(), createElementBlock("div", _hoisted_26, toDisplayString(d.error), 1)) : createCommentVNode("", !0)], 32)) : createCommentVNode("", !0), createElementVNode("button", {
|
|
342
|
+
onClick: Z,
|
|
343
|
+
disabled: !S.value || !C.value || d.loading,
|
|
344
|
+
class: "_cppay-btn _cppay-btn-primary"
|
|
345
|
+
}, toDisplayString(d.loading ? "处理中..." : "继续支付"), 9, _hoisted_27)])
|
|
346
|
+
])) : (openBlock(), createElementBlock("div", _hoisted_28, [
|
|
347
|
+
createElementVNode("div", _hoisted_29, [createElementVNode("div", _hoisted_30, [w.value ? (openBlock(), createElementBlock("img", {
|
|
348
|
+
key: 0,
|
|
349
|
+
src: w.value,
|
|
350
|
+
alt: "Payment QR Code",
|
|
351
|
+
class: "_cppay-qr-image"
|
|
352
|
+
}, null, 8, _hoisted_31)) : createCommentVNode("", !0)])]),
|
|
353
|
+
createElementVNode("div", _hoisted_32, [
|
|
354
|
+
z.value ? (openBlock(), createElementBlock("div", _hoisted_33, [createElementVNode("div", _hoisted_34, [createElementVNode("div", _hoisted_35, [createElementVNode("div", _hoisted_36, toDisplayString(d.plain === "subscription" ? "授权金额" : "支付金额"), 1), createElementVNode("div", _hoisted_37, [P.value ? (openBlock(), createElementBlock("span", _hoisted_38, toDisplayString(d.plain === "subscription" ? `${V(P.value.approveAmount, B(z.value.symbol))} ${z.value.symbol}` : `${V(P.value.paymentAmount, B(z.value.symbol))} ${z.value.symbol}`), 1)) : createCommentVNode("", !0), createElementVNode("span", null, "≈ $" + toDisplayString(d.amount), 1)])])])])) : createCommentVNode("", !0),
|
|
355
|
+
createElementVNode("div", _hoisted_39, [createElementVNode("div", _hoisted_40, [createElementVNode("div", _hoisted_41, [createElementVNode("span", null, toDisplayString(d.plain === "subscription" ? "授权合约地址" : "支付地址"), 1), O.value ? (openBlock(), createElementBlock("span", _hoisted_42, "⏰ " + toDisplayString(O.value), 1)) : createCommentVNode("", !0)]), createElementVNode("div", _hoisted_43, [P.value ? (openBlock(), createElementBlock("code", _hoisted_44, toDisplayString(d.plain === "subscription" ? P.value.spenderAddress : P.value.receiveAddress), 1)) : createCommentVNode("", !0), createElementVNode("button", {
|
|
356
|
+
onClick: $,
|
|
357
|
+
class: normalizeClass(["_cppay-copy-btn", { "_cppay-copy-success": k.value }]),
|
|
358
|
+
title: k.value ? "已复制!" : "复制地址"
|
|
359
|
+
}, [k.value ? (openBlock(), createElementBlock("svg", _hoisted_47, [...f[15] ||= [createElementVNode("path", { d: "M9 16.17L4.83 12l-1.42 1.41L9 19 21 7l-1.41-1.41z" }, null, -1)]])) : (openBlock(), createElementBlock("svg", _hoisted_46, [...f[14] ||= [createElementVNode("path", { d: "M16 4h2a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2V6a2 2 0 0 1 2-2h2" }, null, -1), createElementVNode("rect", {
|
|
360
|
+
x: "8",
|
|
361
|
+
y: "2",
|
|
362
|
+
width: "8",
|
|
363
|
+
height: "4",
|
|
364
|
+
rx: "1",
|
|
365
|
+
ry: "1"
|
|
366
|
+
}, null, -1)]]))], 10, _hoisted_45)])])]),
|
|
367
|
+
d.plain === "subscription" ? (openBlock(), createElementBlock("div", _hoisted_48, [...f[16] ||= [createElementVNode("div", { class: "_cppay-info-label _cppay-subscription-label" }, "📌 订阅说明", -1), createElementVNode("div", { class: "_cppay-info-value _cppay-subscription-message" }, " 订阅支付需要授权代币给合约地址,系统将按周期自动扣款。授权后无需每次手动支付。 ", -1)]])) : createCommentVNode("", !0)
|
|
368
|
+
]),
|
|
369
|
+
d.error ? (openBlock(), createElementBlock("div", {
|
|
281
370
|
key: 0,
|
|
282
|
-
class: "_cppay-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
}, [
|
|
371
|
+
class: "_cppay-error-tooltip-wrapper",
|
|
372
|
+
onMouseenter: f[3] ||= (t) => A.value = !0,
|
|
373
|
+
onMouseleave: f[4] ||= (t) => A.value = !1
|
|
374
|
+
}, [createElementVNode("div", _hoisted_49, [f[17] ||= createElementVNode("svg", {
|
|
375
|
+
viewBox: "0 0 20 20",
|
|
376
|
+
fill: "currentColor"
|
|
377
|
+
}, [createElementVNode("path", {
|
|
378
|
+
"fill-rule": "evenodd",
|
|
379
|
+
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",
|
|
380
|
+
"clip-rule": "evenodd"
|
|
381
|
+
})], -1), createElementVNode("span", null, toDisplayString(d.error), 1)]), A.value ? (openBlock(), createElementBlock("div", _hoisted_50, toDisplayString(d.error), 1)) : createCommentVNode("", !0)], 32)) : createCommentVNode("", !0),
|
|
382
|
+
d.isCheckingPayment ? createCommentVNode("", !0) : (openBlock(), createElementBlock("div", _hoisted_51, [T.value ? (openBlock(), createElementBlock(Fragment, { key: 1 }, [createElementVNode("button", {
|
|
383
|
+
onClick: X,
|
|
384
|
+
disabled: d.loading,
|
|
385
|
+
class: "_cppay-btn _cppay-btn-primary"
|
|
386
|
+
}, toDisplayString(d.loading ? d.plain === "subscription" ? "授权中..." : "支付中..." : d.plain === "subscription" ? "💳 钱包授权" : "💳 钱包支付"), 9, _hoisted_53), createElementVNode("button", {
|
|
387
|
+
onClick: I,
|
|
388
|
+
disabled: d.loading,
|
|
389
|
+
class: "_cppay-btn _cppay-wallet-address-btn",
|
|
390
|
+
title: "点击修改或查看钱包状态"
|
|
391
|
+
}, [createElementVNode("span", _hoisted_55, toDisplayString(T.value.slice(0, 10)) + "..." + toDisplayString(T.value.slice(-4)), 1), f[18] ||= createElementVNode("svg", {
|
|
392
|
+
class: "_cppay-wallet-arrow",
|
|
393
|
+
viewBox: "0 0 24 24",
|
|
289
394
|
fill: "none",
|
|
290
395
|
stroke: "currentColor",
|
|
291
|
-
|
|
292
|
-
}, [createElementVNode("
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
"font-size": "64px",
|
|
300
|
-
"margin-bottom": "1rem"
|
|
301
|
-
} }, "✅", -1),
|
|
302
|
-
createElementVNode("h3", _hoisted_7, toDisplayString(y.plain === "subscription" ? "授权成功!" : "支付成功!"), 1),
|
|
303
|
-
createElementVNode("p", _hoisted_8, toDisplayString(y.plain === "subscription" ? "订阅已激活" : "交易已完成"), 1)
|
|
304
|
-
])) : createCommentVNode("", !0), S.value === "select" ? (openBlock(), createElementBlock("div", _hoisted_9, [
|
|
305
|
-
createElementVNode("div", _hoisted_10, [_[8] ||= createElementVNode("label", { class: "_cppay-label" }, "支付网络", -1), createElementVNode("div", _hoisted_11, [(openBlock(!0), createElementBlock(Fragment, null, renderList(D.value, (e) => (openBlock(), createElementBlock("button", {
|
|
306
|
-
key: e.chain,
|
|
307
|
-
onClick: (g) => O.value = e.chain,
|
|
308
|
-
class: normalizeClass(["_cppay-select-btn", O.value === e.chain ? "_cppay-selected" : ""])
|
|
309
|
-
}, [e.icon ? (openBlock(), createElementBlock("img", {
|
|
310
|
-
key: 0,
|
|
311
|
-
src: e.icon,
|
|
312
|
-
alt: e.chain
|
|
313
|
-
}, null, 8, _hoisted_13)) : createCommentVNode("", !0), createElementVNode("span", null, toDisplayString(e.chain), 1)], 10, _hoisted_12))), 128))])]),
|
|
314
|
-
createElementVNode("div", _hoisted_14, [_[9] ||= createElementVNode("label", { class: "_cppay-label" }, "支付代币", -1), createElementVNode("div", _hoisted_15, [(openBlock(!0), createElementBlock(Fragment, null, renderList(R.value, (e) => (openBlock(), createElementBlock("button", {
|
|
315
|
-
key: e.symbol,
|
|
316
|
-
onClick: (g) => k.value = e.symbol,
|
|
317
|
-
class: normalizeClass(["_cppay-select-btn", k.value === e.symbol ? "_cppay-selected" : ""])
|
|
318
|
-
}, [e.icon ? (openBlock(), createElementBlock("img", {
|
|
319
|
-
key: 0,
|
|
320
|
-
src: e.icon,
|
|
321
|
-
alt: e.symbol
|
|
322
|
-
}, null, 8, _hoisted_17)) : createCommentVNode("", !0), createElementVNode("span", null, toDisplayString(e.symbol), 1)], 10, _hoisted_16))), 128))])]),
|
|
323
|
-
createElementVNode("div", _hoisted_18, [createElementVNode("div", _hoisted_19, [createElementVNode("div", _hoisted_20, [_[10] ||= createElementVNode("span", { class: "_cppay-price-label" }, "支付金额", -1), createElementVNode("div", _hoisted_21, [createElementVNode("div", _hoisted_22, toDisplayString(H.value ?? "-") + " " + toDisplayString(k.value ?? ""), 1), createElementVNode("div", _hoisted_23, "≈ $" + toDisplayString(g.amount), 1)])])])]),
|
|
324
|
-
createElementVNode("div", _hoisted_24, [T.value ? (openBlock(), createElementBlock("div", {
|
|
325
|
-
key: 0,
|
|
326
|
-
class: "_cppay-error-tooltip-wrapper",
|
|
327
|
-
onMouseenter: _[0] ||= (e) => E.value = !0,
|
|
328
|
-
onMouseleave: _[1] ||= (e) => E.value = !1
|
|
329
|
-
}, [createElementVNode("div", _hoisted_25, [_[11] ||= createElementVNode("svg", {
|
|
330
|
-
viewBox: "0 0 20 20",
|
|
331
|
-
fill: "currentColor"
|
|
332
|
-
}, [createElementVNode("path", {
|
|
333
|
-
"fill-rule": "evenodd",
|
|
334
|
-
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",
|
|
335
|
-
"clip-rule": "evenodd"
|
|
336
|
-
})], -1), createElementVNode("span", null, toDisplayString(T.value), 1)]), E.value ? (openBlock(), createElementBlock("div", _hoisted_26, toDisplayString(T.value), 1)) : createCommentVNode("", !0)], 32)) : createCommentVNode("", !0), createElementVNode("button", {
|
|
337
|
-
onClick: Z,
|
|
338
|
-
disabled: !O.value || !k.value || C.value,
|
|
339
|
-
class: "_cppay-btn _cppay-btn-primary"
|
|
340
|
-
}, toDisplayString(C.value ? "处理中..." : "继续支付"), 9, _hoisted_27)])
|
|
341
|
-
])) : S.value === "payment" && A.value ? (openBlock(), createElementBlock("div", _hoisted_28, [
|
|
342
|
-
createElementVNode("div", _hoisted_29, [createElementVNode("div", _hoisted_30, [j.value ? (openBlock(), createElementBlock("img", {
|
|
343
|
-
key: 0,
|
|
344
|
-
src: j.value,
|
|
345
|
-
alt: "QR Code",
|
|
346
|
-
style: {
|
|
347
|
-
width: "160px",
|
|
348
|
-
height: "160px",
|
|
349
|
-
display: "block"
|
|
350
|
-
}
|
|
351
|
-
}, null, 8, _hoisted_31)) : createCommentVNode("", !0)])]),
|
|
352
|
-
createElementVNode("div", _hoisted_32, [
|
|
353
|
-
k.value ? (openBlock(), createElementBlock("div", _hoisted_33, [createElementVNode("div", _hoisted_34, toDisplayString(y.plain === "subscription" ? "授权金额" : "支付金额"), 1), createElementVNode("div", _hoisted_35, toDisplayString(A.value.paymentAmount) + " " + toDisplayString(k.value), 1)])) : createCommentVNode("", !0),
|
|
354
|
-
createElementVNode("div", _hoisted_36, [createElementVNode("div", _hoisted_37, toDisplayString(y.plain === "subscription" ? "授权合约地址" : "支付地址"), 1), createElementVNode("div", _hoisted_38, [createElementVNode("code", null, toDisplayString(A.value.receiveAddress), 1), createElementVNode("button", {
|
|
355
|
-
onClick: $,
|
|
356
|
-
class: "_cppay-copy-btn",
|
|
357
|
-
title: "复制地址"
|
|
358
|
-
}, [..._[12] ||= [createElementVNode("svg", {
|
|
359
|
-
fill: "none",
|
|
360
|
-
stroke: "currentColor",
|
|
361
|
-
viewBox: "0 0 24 24"
|
|
362
|
-
}, [createElementVNode("path", {
|
|
363
|
-
"stroke-linecap": "round",
|
|
364
|
-
"stroke-linejoin": "round",
|
|
365
|
-
"stroke-width": "2",
|
|
366
|
-
d: "M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z"
|
|
367
|
-
})], -1)]])])]),
|
|
368
|
-
y.plain === "subscription" ? (openBlock(), createElementBlock("div", _hoisted_39, [..._[13] ||= [createElementVNode("div", {
|
|
369
|
-
class: "_cppay-info-label",
|
|
370
|
-
style: { color: "#856404" }
|
|
371
|
-
}, "📌 订阅说明", -1), createElementVNode("div", {
|
|
372
|
-
class: "_cppay-info-value",
|
|
373
|
-
style: {
|
|
374
|
-
"font-size": "12px",
|
|
375
|
-
color: "#856404"
|
|
376
|
-
}
|
|
377
|
-
}, " 订阅支付需要授权代币给合约地址,系统将按周期自动扣款。授权后无需每次手动支付。 ", -1)]])) : createCommentVNode("", !0)
|
|
378
|
-
]),
|
|
379
|
-
T.value ? (openBlock(), createElementBlock("div", {
|
|
380
|
-
key: 0,
|
|
381
|
-
class: "_cppay-error-tooltip-wrapper",
|
|
382
|
-
onMouseenter: _[2] ||= (e) => E.value = !0,
|
|
383
|
-
onMouseleave: _[3] ||= (e) => E.value = !1
|
|
384
|
-
}, [createElementVNode("div", _hoisted_40, [_[14] ||= createElementVNode("svg", {
|
|
385
|
-
viewBox: "0 0 20 20",
|
|
386
|
-
fill: "currentColor"
|
|
387
|
-
}, [createElementVNode("path", {
|
|
388
|
-
"fill-rule": "evenodd",
|
|
389
|
-
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",
|
|
390
|
-
"clip-rule": "evenodd"
|
|
391
|
-
})], -1), createElementVNode("span", null, toDisplayString(T.value), 1)]), E.value ? (openBlock(), createElementBlock("div", _hoisted_41, toDisplayString(T.value), 1)) : createCommentVNode("", !0)], 32)) : createCommentVNode("", !0),
|
|
392
|
-
w.value ? createCommentVNode("", !0) : (openBlock(), createElementBlock("div", _hoisted_42, [M.value ? (openBlock(), createElementBlock("div", _hoisted_44, [createElementVNode("div", _hoisted_45, [createElementVNode("button", {
|
|
393
|
-
onClick: X,
|
|
394
|
-
disabled: C.value,
|
|
395
|
-
class: "_cppay-btn _cppay-btn-primary"
|
|
396
|
-
}, toDisplayString(C.value ? g.plain === "subscription" ? "授权中..." : "支付中..." : g.plain === "subscription" ? "💳 钱包授权" : "💳 钱包支付"), 9, _hoisted_46), createElementVNode("button", {
|
|
397
|
-
onClick: K,
|
|
398
|
-
disabled: C.value,
|
|
399
|
-
class: "_cppay-btn _cppay-btn-primary"
|
|
400
|
-
}, " 💰钱包状态 ", 8, _hoisted_47)]), createElementVNode("div", _hoisted_48, " 已连接: " + toDisplayString(M.value.slice(0, 6)) + "..." + toDisplayString(M.value.slice(-4)), 1)])) : (openBlock(), createElementBlock("button", {
|
|
401
|
-
key: 0,
|
|
402
|
-
onClick: K,
|
|
403
|
-
disabled: N.value,
|
|
404
|
-
class: "_cppay-btn _cppay-btn-secondary",
|
|
405
|
-
style: {
|
|
406
|
-
display: "flex",
|
|
407
|
-
"align-items": "center",
|
|
408
|
-
"justify-content": "center",
|
|
409
|
-
gap: "0.5rem",
|
|
410
|
-
padding: "0.75rem 1rem",
|
|
411
|
-
width: "100%"
|
|
412
|
-
}
|
|
413
|
-
}, [createElementVNode("span", null, toDisplayString(N.value ? "连接中..." : "💳 连接钱包"), 1)], 8, _hoisted_43))])),
|
|
414
|
-
createElementVNode("div", _hoisted_49, [createElementVNode("button", {
|
|
415
|
-
onClick: U,
|
|
416
|
-
disabled: w.value,
|
|
417
|
-
class: "_cppay-btn _cppay-btn-primary"
|
|
418
|
-
}, toDisplayString(w.value ? "检查中..." : "我已完成支付"), 9, _hoisted_50)]),
|
|
419
|
-
createElementVNode("div", _hoisted_51, [createElementVNode("button", {
|
|
420
|
-
onClick: _[4] ||= (e) => S.value = "select",
|
|
421
|
-
disabled: C.value || w.value,
|
|
422
|
-
class: "_cppay-btn _cppay-btn-text"
|
|
423
|
-
}, " 更改支付方式 ", 8, _hoisted_52)])
|
|
424
|
-
])) : createCommentVNode("", !0)])])])) : createCommentVNode("", !0)]),
|
|
425
|
-
_: 1
|
|
426
|
-
})]));
|
|
396
|
+
"stroke-width": "2"
|
|
397
|
+
}, [createElementVNode("polyline", { points: "6 9 12 15 18 9" })], -1)], 8, _hoisted_54)], 64)) : (openBlock(), createElementBlock("button", {
|
|
398
|
+
key: 0,
|
|
399
|
+
onClick: I,
|
|
400
|
+
disabled: E.value,
|
|
401
|
+
class: "_cppay-btn _cppay-btn-secondary _cppay-connect-wallet-btn"
|
|
402
|
+
}, [createElementVNode("span", null, toDisplayString(E.value ? "连接中..." : "💳 连接钱包"), 1)], 8, _hoisted_52))]))
|
|
403
|
+
]))]));
|
|
427
404
|
}
|
|
428
|
-
}),
|
|
405
|
+
}), _hoisted_1 = { class: "_cppay-dialog" }, _hoisted_2 = { class: "_cppay-header" }, _hoisted_3 = { class: "_cppay-title" }, _hoisted_4 = ["disabled"], PaymentDialog_default = /* @__PURE__ */ defineComponent({
|
|
406
|
+
__name: "PaymentDialog",
|
|
407
|
+
props: {
|
|
408
|
+
modelValue: { type: Boolean },
|
|
409
|
+
apikey: {},
|
|
410
|
+
orderId: {},
|
|
411
|
+
amount: {},
|
|
412
|
+
plain: { default: "one-time" },
|
|
413
|
+
intervalDays: { default: 30 }
|
|
414
|
+
},
|
|
415
|
+
emits: [
|
|
416
|
+
"update:modelValue",
|
|
417
|
+
"success",
|
|
418
|
+
"expired",
|
|
419
|
+
"failed",
|
|
420
|
+
"error"
|
|
421
|
+
],
|
|
422
|
+
setup(t, { emit: d }) {
|
|
423
|
+
let f = t, p = d, m = ref("select"), g = ref(!1), v = ref(!1), y = ref();
|
|
424
|
+
watch(() => m.value, (t) => {
|
|
425
|
+
t === "success" && setTimeout(() => {
|
|
426
|
+
b();
|
|
427
|
+
}, 1e3);
|
|
428
|
+
}), watch(() => f.modelValue, (t) => {
|
|
429
|
+
t || (m.value = "select", y.value = void 0, g.value = !1, v.value = !1);
|
|
430
|
+
}), onMounted(() => {
|
|
431
|
+
let t = (t) => {
|
|
432
|
+
t.key === "Escape" && f.modelValue && !g.value && !v.value && b();
|
|
433
|
+
};
|
|
434
|
+
return window.addEventListener("keydown", t), () => {
|
|
435
|
+
window.removeEventListener("keydown", t);
|
|
436
|
+
};
|
|
437
|
+
});
|
|
438
|
+
let b = () => {
|
|
439
|
+
g.value || v.value || p("update:modelValue", !1);
|
|
440
|
+
}, x = () => {
|
|
441
|
+
switch (m.value) {
|
|
442
|
+
case "success": return "支付结果";
|
|
443
|
+
case "expired": return "支付已过期";
|
|
444
|
+
case "failed": return "支付失败";
|
|
445
|
+
case "error": return "出错";
|
|
446
|
+
case "payment": return "完成支付";
|
|
447
|
+
default: return "选择支付方式";
|
|
448
|
+
}
|
|
449
|
+
};
|
|
450
|
+
return (d, f) => t.modelValue ? (openBlock(), createElementBlock("div", {
|
|
451
|
+
key: 0,
|
|
452
|
+
class: "_cppay-overlay",
|
|
453
|
+
onClick: f[6] ||= (t) => t.target === t.currentTarget && !g.value && !v.value && b()
|
|
454
|
+
}, [createElementVNode("div", _hoisted_1, [createElementVNode("div", _hoisted_2, [createElementVNode("h2", _hoisted_3, toDisplayString(x()), 1), createElementVNode("button", {
|
|
455
|
+
onClick: b,
|
|
456
|
+
disabled: g.value || v.value,
|
|
457
|
+
class: "_cppay-close-btn"
|
|
458
|
+
}, [...f[7] ||= [createElementVNode("svg", {
|
|
459
|
+
fill: "none",
|
|
460
|
+
stroke: "currentColor",
|
|
461
|
+
viewBox: "0 0 24 24"
|
|
462
|
+
}, [createElementVNode("path", {
|
|
463
|
+
"stroke-linecap": "round",
|
|
464
|
+
"stroke-linejoin": "round",
|
|
465
|
+
"stroke-width": "2",
|
|
466
|
+
d: "M6 18L18 6M6 6l12 12"
|
|
467
|
+
})], -1)]], 8, _hoisted_4)]), createVNode(PaymentContent_default, {
|
|
468
|
+
apikey: t.apikey,
|
|
469
|
+
orderId: t.orderId,
|
|
470
|
+
amount: t.amount,
|
|
471
|
+
plain: t.plain,
|
|
472
|
+
intervalDays: t.intervalDays,
|
|
473
|
+
paymentStep: m.value,
|
|
474
|
+
loading: g.value,
|
|
475
|
+
isCheckingPayment: v.value,
|
|
476
|
+
error: y.value,
|
|
477
|
+
"onUpdate:paymentStep": f[0] ||= (t) => m.value = t,
|
|
478
|
+
"onUpdate:error": f[1] ||= (t) => y.value = t,
|
|
479
|
+
onSuccess: f[2] ||= (t) => p("success", t),
|
|
480
|
+
onExpired: f[3] ||= (t) => p("expired", t),
|
|
481
|
+
onFailed: f[4] ||= (t) => p("failed", t),
|
|
482
|
+
onError: f[5] ||= (t) => p("error", t)
|
|
483
|
+
}, {
|
|
484
|
+
"choose-top": withCtx(() => [renderSlot(d.$slots, "choose-top")]),
|
|
485
|
+
"choose-bottom": withCtx(() => [renderSlot(d.$slots, "choose-bottom")]),
|
|
486
|
+
_: 3
|
|
487
|
+
}, 8, [
|
|
488
|
+
"apikey",
|
|
489
|
+
"orderId",
|
|
490
|
+
"amount",
|
|
491
|
+
"plain",
|
|
492
|
+
"intervalDays",
|
|
493
|
+
"paymentStep",
|
|
494
|
+
"loading",
|
|
495
|
+
"isCheckingPayment",
|
|
496
|
+
"error"
|
|
497
|
+
])])])) : createCommentVNode("", !0);
|
|
498
|
+
}
|
|
499
|
+
}), cppayState = ref({
|
|
429
500
|
apikey: "",
|
|
430
501
|
open: !1,
|
|
431
502
|
options: null
|
|
432
503
|
});
|
|
433
|
-
const showPayment = (
|
|
434
|
-
cppayState.value.options =
|
|
504
|
+
const showPayment = (t) => {
|
|
505
|
+
cppayState.value.options = t, cppayState.value.open = !0;
|
|
506
|
+
}, closePayment = () => {
|
|
507
|
+
cppayState.value.open = !1;
|
|
435
508
|
};
|
|
436
509
|
var handleClose = () => {
|
|
437
510
|
cppayState.value.open = !1;
|
|
438
|
-
}, handleSuccess = (
|
|
439
|
-
cppayState.value.options?.onSuccess?.(
|
|
440
|
-
|
|
441
|
-
|
|
511
|
+
}, handleSuccess = (t) => {
|
|
512
|
+
cppayState.value.options?.onSuccess?.(t), setTimeout(() => {
|
|
513
|
+
cppayState.value.open = !1;
|
|
514
|
+
}, 1e3);
|
|
515
|
+
}, handleExpired = (t) => {
|
|
516
|
+
cppayState.value.options?.onExpired?.(t);
|
|
517
|
+
}, handleFailed = (t) => {
|
|
518
|
+
cppayState.value.options?.onFailed?.(t);
|
|
519
|
+
}, handleError = (t) => {
|
|
520
|
+
cppayState.value.options?.onError?.(t);
|
|
442
521
|
};
|
|
443
|
-
const CppayPlugin = { install(
|
|
444
|
-
if (!
|
|
445
|
-
cppayState.value.apikey =
|
|
446
|
-
let
|
|
447
|
-
|
|
522
|
+
const CppayPlugin = { install(t, d) {
|
|
523
|
+
if (!d?.apikey) throw Error("Cppay plugin requires an apikey");
|
|
524
|
+
cppayState.value.apikey = d.apikey, t.config.globalProperties.$showPayment = showPayment, t.config.globalProperties.$closePayment = closePayment;
|
|
525
|
+
let f = (t) => {
|
|
526
|
+
t.key === "Escape" && cppayState.value.open && handleClose();
|
|
527
|
+
}, p = document.createElement("div");
|
|
528
|
+
document.body.appendChild(p), createApp({ setup() {
|
|
448
529
|
return () => cppayState.value.options ? h(PaymentDialog_default, {
|
|
449
530
|
modelValue: cppayState.value.open,
|
|
450
|
-
"onUpdate:modelValue": (
|
|
451
|
-
cppayState.value.open =
|
|
531
|
+
"onUpdate:modelValue": (t) => {
|
|
532
|
+
cppayState.value.open = t, t || handleClose();
|
|
452
533
|
},
|
|
453
534
|
apikey: cppayState.value.apikey,
|
|
454
535
|
plain: cppayState.value.options.plain,
|
|
@@ -456,12 +537,19 @@ const CppayPlugin = { install(e, g) {
|
|
|
456
537
|
amount: cppayState.value.options.amount,
|
|
457
538
|
intervalDays: cppayState.value.options.intervalDays,
|
|
458
539
|
onSuccess: handleSuccess,
|
|
540
|
+
onExpired: handleExpired,
|
|
541
|
+
onFailed: handleFailed,
|
|
459
542
|
onError: handleError
|
|
460
543
|
}) : null;
|
|
461
|
-
} }).mount(
|
|
544
|
+
} }).mount(p), cppayState.value.open && document.addEventListener("keydown", f), t.config.globalProperties.$watchEffect?.(() => {
|
|
545
|
+
cppayState.value.open ? document.addEventListener("keydown", f) : document.removeEventListener("keydown", f);
|
|
546
|
+
});
|
|
462
547
|
} }, useCppayPayment = () => {
|
|
463
548
|
if (!cppayState.value.apikey) throw Error("useCppayPayment must be used after installing CppayPlugin");
|
|
464
|
-
return {
|
|
549
|
+
return {
|
|
550
|
+
showPayment,
|
|
551
|
+
closePayment
|
|
552
|
+
};
|
|
465
553
|
};
|
|
466
554
|
injectStyle(payment_dialog_default);
|
|
467
|
-
export { CppayPlugin, PaymentDialog_default as PaymentDialog, showPayment, useCppayPayment };
|
|
555
|
+
export { CppayPlugin, PaymentContent_default as PaymentContent, PaymentDialog_default as PaymentDialog, showPayment, useCppayPayment };
|