cppay-sdk 0.0.2-beta.2 → 0.0.2-beta.21

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/vue.d.ts ADDED
@@ -0,0 +1,88 @@
1
+ import { ComponentOptionsMixin } from '../../vue/dist/vue.esm-bundler.js';
2
+ import { ComponentProvideOptions } from '../../vue/dist/vue.esm-bundler.js';
3
+ import { DefineComponent } from '../../vue/dist/vue.esm-bundler.js';
4
+ import { Plugin as Plugin_2 } from '../../vue/dist/vue.esm-bundler.js';
5
+ import { PublicProps } from '../../vue/dist/vue.esm-bundler.js';
6
+
7
+ declare type Address = `0x${string}`;
8
+
9
+ export declare const CppayPlugin: Plugin_2;
10
+
11
+ declare type Numberic = `${number}.${number}` | `${number}`;
12
+
13
+ declare interface OnetimePaymentOrderStatus {
14
+ orderId: string;
15
+ paymentId: string;
16
+ chain: string;
17
+ token: string;
18
+ baseAmount: Numberic;
19
+ payAmount: Numberic;
20
+ receiveAddress: Address;
21
+ expireAt: number;
22
+ status: PaymentStatus;
23
+ }
24
+
25
+ export declare const PaymentDialog: DefineComponent<Props, {}, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, {} & {
26
+ error: (error: Error) => any;
27
+ "update:modelValue": (value: boolean) => any;
28
+ success: (order: OnetimePaymentOrderStatus | SubscriptionPaymentOrderStatus) => any;
29
+ }, string, PublicProps, Readonly<Props> & Readonly<{
30
+ onError?: ((error: Error) => any) | undefined;
31
+ "onUpdate:modelValue"?: ((value: boolean) => any) | undefined;
32
+ onSuccess?: ((order: OnetimePaymentOrderStatus | SubscriptionPaymentOrderStatus) => any) | undefined;
33
+ }>, {
34
+ intervalDays: number;
35
+ plain: PaymentPlain;
36
+ }, {}, {}, {}, string, ComponentProvideOptions, false, {}, any>;
37
+
38
+ declare interface PaymentOptions_2 {
39
+ plain: PaymentPlain;
40
+ orderId: string;
41
+ amount: string;
42
+ intervalDays?: number;
43
+ onSuccess?: (order: SubscriptionPaymentOrderStatus | OnetimePaymentOrderStatus) => void;
44
+ onError?: (error: Error) => void;
45
+ }
46
+
47
+ declare type PaymentPlain = "one-time" | "subscription" | "x402";
48
+
49
+ declare type PaymentStatus = "pending" | "paid" | "expired" | "failed";
50
+
51
+ declare interface Props {
52
+ modelValue: boolean;
53
+ apikey: string;
54
+ orderId: string;
55
+ amount: string;
56
+ plain?: PaymentPlain;
57
+ intervalDays?: number;
58
+ }
59
+
60
+ export declare const showPayment: (options: PaymentOptions_2) => void;
61
+
62
+ declare interface SubscriptionPaymentOrderStatus {
63
+ orderId: string;
64
+ subscriptionId: string;
65
+ chain: string;
66
+ token: string;
67
+ approvedAddress: string;
68
+ txHash: string;
69
+ approveAmount: string;
70
+ amountOfUsd: string;
71
+ expireAt: number;
72
+ status: SubscriptionPaymentStatus;
73
+ }
74
+
75
+ declare type SubscriptionPaymentStatus = "pending" | "approved" | "expired" | "failed";
76
+
77
+ export declare const useCppayPayment: () => {
78
+ showPayment: (options: PaymentOptions_2) => void;
79
+ };
80
+
81
+ export { }
82
+
83
+
84
+ declare module "@vue/runtime-core" {
85
+ interface ComponentCustomProperties {
86
+ $showPayment: typeof showPayment;
87
+ }
88
+ }
package/dist/vue.js ADDED
@@ -0,0 +1,492 @@
1
+ import { a as payment_dialog_default, i as injectStyle, n as metamask_default, o as __toESM, r as require_browser, t as walletconnect_default } from "./walletconnect-B0L70Mgc.js";
2
+ import { t as cppay_default } from "./cppay-BcCDwXlg.js";
3
+ import { Fragment, Teleport, Transition, computed, createApp, createBlock, createCommentVNode, createElementBlock, createElementVNode, createVNode, defineComponent, h, normalizeClass, onUnmounted, openBlock, ref, renderList, toDisplayString, unref, watch, withCtx, withModifiers } from "vue";
4
+ import { EMPTY, defer, timer } from "rxjs";
5
+ import { expand, retry, switchMap, tap, timeout } from "rxjs/operators";
6
+ import { createWalletClient, custom, parseUnits } from "viem";
7
+ import { arbitrum, base, bsc, mainnet, optimism, polygon } from "viem/chains";
8
+ import EthereumProvider from "@walletconnect/ethereum-provider";
9
+ var import_browser = /* @__PURE__ */ __toESM(require_browser(), 1), _hoisted_1 = { class: "_cppay-dialog" }, _hoisted_2 = { class: "_cppay-header" }, _hoisted_3 = { class: "_cppay-title" }, _hoisted_4 = ["disabled"], _hoisted_5 = { class: "_cppay-content" }, _hoisted_6 = {
10
+ key: 0,
11
+ style: {
12
+ "text-align": "center",
13
+ padding: "2rem 0"
14
+ }
15
+ }, _hoisted_7 = { style: {
16
+ "font-size": "1.5rem",
17
+ "font-weight": "600",
18
+ color: "#10b981",
19
+ margin: "0 0 0.5rem 0"
20
+ } }, _hoisted_8 = { style: {
21
+ color: "#6b7280",
22
+ margin: "0"
23
+ } }, _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 = ["disabled"], _hoisted_26 = { key: 2 }, _hoisted_27 = { class: "_cppay-qr-container" }, _hoisted_28 = { class: "_cppay-qr-code" }, _hoisted_29 = ["src"], _hoisted_30 = { class: "_cppay-section" }, _hoisted_31 = { class: "_cppay-info-box" }, _hoisted_32 = { class: "_cppay-info-label" }, _hoisted_33 = { class: "_cppay-info-value" }, _hoisted_34 = { class: "_cppay-info-box" }, _hoisted_35 = { class: "_cppay-info-label" }, _hoisted_36 = { class: "_cppay-address-row" }, _hoisted_37 = {
24
+ key: 0,
25
+ class: "_cppay-info-box",
26
+ style: {
27
+ background: "#fff3cd",
28
+ "border-color": "#ffc107"
29
+ }
30
+ }, _hoisted_38 = { class: "_cppay-section" }, _hoisted_39 = {
31
+ key: 0,
32
+ style: {
33
+ display: "flex",
34
+ "flex-direction": "row",
35
+ gap: "0.5rem",
36
+ "justify-content": "center"
37
+ }
38
+ }, _hoisted_40 = ["disabled"], _hoisted_41 = ["src"], _hoisted_42 = ["disabled"], _hoisted_43 = ["src"], _hoisted_44 = { key: 1 }, _hoisted_45 = ["disabled"], _hoisted_46 = { style: {
39
+ "text-align": "center",
40
+ "margin-top": "8px",
41
+ "font-size": "12px",
42
+ color: "#666"
43
+ } }, _hoisted_47 = { class: "_cppay-section" }, _hoisted_48 = ["disabled"], _hoisted_49 = { class: "_cppay-section" }, _hoisted_50 = ["disabled"], PaymentDialog_default = /* @__PURE__ */ ((e, v) => {
44
+ let y = e.__vccOpts || e;
45
+ for (let [e, b] of v) y[e] = b;
46
+ return y;
47
+ })(/* @__PURE__ */ defineComponent({
48
+ __name: "PaymentDialog",
49
+ props: {
50
+ modelValue: { type: Boolean },
51
+ apikey: {},
52
+ orderId: {},
53
+ amount: {},
54
+ plain: { default: "one-time" },
55
+ intervalDays: { default: 30 }
56
+ },
57
+ emits: [
58
+ "update:modelValue",
59
+ "success",
60
+ "error"
61
+ ],
62
+ setup(e, { emit: v }) {
63
+ let b = e, x = v, S = new cppay_default(b.apikey), C = ref("select"), w = ref(!1), T = ref([]), E = ref(""), D = ref(""), O = ref(null), k = ref(""), A = ref(""), j = ref(!1), M = ref(!0), N = ref(null), P = ref(null), F = ref(null), I = computed(() => T.value.find((e) => e.chain === E.value)), L = computed(() => I.value?.tokens || []), R = computed(() => L.value.find((e) => e.symbol === D.value)), z = (e) => [
64
+ "USDT",
65
+ "USDC",
66
+ "BUSD",
67
+ "DAI",
68
+ "TUSD",
69
+ "USDD",
70
+ "FDUSD"
71
+ ].includes(e.toUpperCase()) ? 2 : 6, B = (e, v) => {
72
+ let y = parseFloat(e);
73
+ return isNaN(y) ? "0" : y.toFixed(v).replace(/\.?0+$/, "");
74
+ }, V = computed(() => {
75
+ if (!D.value || !R.value) return "0";
76
+ let e = parseFloat(R.value.price);
77
+ if (isNaN(e) || e === 0) return "0";
78
+ let v = z(D.value);
79
+ return B((parseFloat(b.amount) / e).toFixed(v), v);
80
+ }), H = () => {
81
+ O.value && (w.value = !0, b.plain === "one-time" ? Q(O.value.paymentId) : b.plain === "subscription" && Q(O.value.subscriptionId));
82
+ }, U = () => {
83
+ w.value || (x("update:modelValue", !1), setTimeout(() => {
84
+ C.value = "select", O.value = null;
85
+ }, 300));
86
+ }, W = async () => {
87
+ try {
88
+ w.value = !0, T.value = await S.getSupportedChains(), T.value.length > 0 && (E.value = T.value[0].chain);
89
+ } catch (e) {
90
+ x("error", e);
91
+ } finally {
92
+ w.value = !1;
93
+ }
94
+ }, G = (e) => ({
95
+ ETH: mainnet,
96
+ BSC: bsc,
97
+ Polygon: polygon,
98
+ Arbitrum: arbitrum,
99
+ Optimism: optimism,
100
+ Base: base
101
+ })[e] || mainnet, K = async (e) => {
102
+ try {
103
+ if (j.value = !0, e === "metamask") {
104
+ if (typeof window < "u" && window.ethereum?.isMetaMask) {
105
+ let e = await window.ethereum.request({ method: "eth_requestAccounts" });
106
+ if (e && e.length > 0) {
107
+ A.value = e[0], N.value = "metamask", M.value = !1;
108
+ return;
109
+ }
110
+ }
111
+ throw Error("请安装 MetaMask 扩展");
112
+ }
113
+ if (e === "walletconnect") {
114
+ let e = await EthereumProvider.init({
115
+ projectId: "8d2e1854d3f1782e45aa15fbd8938894",
116
+ chains: [1],
117
+ showQrModal: !0,
118
+ optionalChains: [
119
+ 56,
120
+ 137,
121
+ 42161,
122
+ 10,
123
+ 8453
124
+ ],
125
+ methods: [
126
+ "eth_sendTransaction",
127
+ "eth_signTransaction",
128
+ "eth_sign",
129
+ "personal_sign",
130
+ "eth_signTypedData"
131
+ ],
132
+ events: ["chainChanged", "accountsChanged"],
133
+ metadata: {
134
+ name: "Cppay",
135
+ description: "Cppay Payment Gateway",
136
+ url: typeof window < "u" ? window.location.origin : "https://cppay.com",
137
+ icons: ["https://cppay.com/icon.png"]
138
+ },
139
+ rpcMap: {
140
+ 1: "https://ethereum.publicnode.com",
141
+ 56: "https://bsc-dataseed.binance.org",
142
+ 137: "https://polygon-rpc.com",
143
+ 42161: "https://arb1.arbitrum.io/rpc",
144
+ 10: "https://mainnet.optimism.io",
145
+ 8453: "https://mainnet.base.org"
146
+ }
147
+ });
148
+ await e.enable();
149
+ let v = await e.request({ method: "eth_accounts" });
150
+ v && v.length > 0 && (A.value = v[0], N.value = "walletconnect", P.value = e, M.value = !1);
151
+ }
152
+ } catch (e) {
153
+ console.error("钱包连接失败:", e), x("error", e);
154
+ } finally {
155
+ j.value = !1;
156
+ }
157
+ }, q = async (e) => {
158
+ let v;
159
+ if (v = N.value === "walletconnect" ? P.value : window.ethereum, v) try {
160
+ await v.request({
161
+ method: "wallet_switchEthereumChain",
162
+ params: [{ chainId: `0x${e.toString(16)}` }]
163
+ });
164
+ } catch (e) {
165
+ throw e.code === 4902 ? Error("请在钱包中添加该网络") : e;
166
+ }
167
+ }, J = async () => {
168
+ if (!(!A.value || !O.value || !R.value)) try {
169
+ w.value = !0;
170
+ let e = O.value, v = G(E.value);
171
+ await q(I.value.chainId);
172
+ let y = createWalletClient({
173
+ account: A.value,
174
+ chain: v,
175
+ transport: custom(N.value === "walletconnect" ? P.value : window.ethereum)
176
+ });
177
+ if (R.value.address) {
178
+ let v = await y.writeContract({
179
+ address: R.value.address,
180
+ abi: [{
181
+ name: "transfer",
182
+ type: "function",
183
+ stateMutability: "nonpayable",
184
+ inputs: [{
185
+ name: "to",
186
+ type: "address"
187
+ }, {
188
+ name: "amount",
189
+ type: "uint256"
190
+ }],
191
+ outputs: [{ type: "bool" }]
192
+ }],
193
+ functionName: "transfer",
194
+ args: [e.receiveAddress, parseUnits(e.paymentAmount, R.value.decimals)],
195
+ chain: null
196
+ });
197
+ console.log("转账交易哈希:", v);
198
+ } else {
199
+ let v = await y.sendTransaction({
200
+ to: e.receiveAddress,
201
+ value: parseUnits(e.paymentAmount, R.value.decimals),
202
+ chain: null
203
+ });
204
+ console.log("转账交易哈希:", v);
205
+ }
206
+ Q(e.paymentId);
207
+ } catch (e) {
208
+ console.error("钱包支付失败:", e), x("error", e);
209
+ } finally {
210
+ w.value = !1;
211
+ }
212
+ }, Y = async () => {
213
+ if (!(!A.value || !O.value || !R.value)) try {
214
+ w.value = !0;
215
+ let e = O.value, v = G(E.value);
216
+ await q(I.value.chainId);
217
+ let y = createWalletClient({
218
+ account: A.value,
219
+ chain: v,
220
+ transport: custom(N.value === "walletconnect" ? P.value : window.ethereum)
221
+ });
222
+ if (!R.value.address) throw Error("订阅支付不支持原生代币");
223
+ let b = await y.writeContract({
224
+ address: R.value.address,
225
+ abi: [{
226
+ name: "approve",
227
+ type: "function",
228
+ stateMutability: "nonpayable",
229
+ inputs: [{
230
+ name: "spender",
231
+ type: "address"
232
+ }, {
233
+ name: "amount",
234
+ type: "uint256"
235
+ }],
236
+ outputs: [{ type: "bool" }]
237
+ }],
238
+ functionName: "approve",
239
+ args: [e.receiveAddress, parseUnits(e.paymentAmount, R.value.decimals)],
240
+ chain: null
241
+ });
242
+ console.log("授权交易哈希:", b), Q(e.paymentId);
243
+ } catch (e) {
244
+ console.error("钱包授权失败:", e), x("error", e);
245
+ } finally {
246
+ w.value = !1;
247
+ }
248
+ }, X = async () => {
249
+ if (!A.value) {
250
+ M.value = !0;
251
+ return;
252
+ }
253
+ b.plain === "one-time" ? await J() : b.plain === "subscription" && await Y();
254
+ }, Z = async () => {
255
+ if (!(!E.value || !D.value)) try {
256
+ w.value = !0;
257
+ let e;
258
+ b.plain === "one-time" ? e = await S.createPayment("one-time", {
259
+ paymentChain: E.value,
260
+ paymentToken: D.value,
261
+ orderId: b.orderId,
262
+ amount: V.value
263
+ }) : b.plain === "subscription" && (e = await S.createPayment("subscription", {
264
+ paymentChain: E.value,
265
+ paymentToken: D.value,
266
+ orderId: b.orderId,
267
+ amountOfUsd: V.value,
268
+ intervalDays: b.intervalDays || 30
269
+ })), O.value = {
270
+ paymentId: e.paymentId || e.subscriptionId,
271
+ paymentAmount: e.paymentAmount || e.approveAmount,
272
+ receiveAddress: e.receiveAddress || e.spenderAddress || ""
273
+ };
274
+ let v = `${E.value.toLowerCase()}:${O.value.receiveAddress}?amount=${O.value.paymentAmount}`;
275
+ k.value = await import_browser.toDataURL(v, {
276
+ width: 200,
277
+ margin: 2,
278
+ errorCorrectionLevel: "H"
279
+ }), C.value = "payment";
280
+ } catch (e) {
281
+ x("error", e);
282
+ } finally {
283
+ w.value = !1;
284
+ }
285
+ }, Q = (e) => {
286
+ let v = () => defer(() => b.plain === "subscription" ? S.checkSubscriptionPaymentStatus({ subscriptionId: e }) : S.checkOnetimePaymentStatus({ paymentId: e })).pipe(timeout(15e3), retry({
287
+ count: 3,
288
+ delay: 2e3
289
+ }));
290
+ F.value?.unsubscribe(), F.value = v().pipe(expand((e) => e.status === "pending" ? timer(2e3).pipe(switchMap(() => v())) : EMPTY), tap((e) => {
291
+ e.status === "expired" && (w.value = !1), e.status === "paid" && (w.value = !1, C.value = "success", x("success", e)), e.status === "failed" && (w.value = !1), e.status === "approved" && (w.value = !1, C.value = "success", x("success", e));
292
+ })).subscribe({ error: (e) => {
293
+ console.error("支付状态检查错误:", e), w.value = !1, x("error", e);
294
+ } });
295
+ }, $ = async () => {
296
+ O.value?.receiveAddress && await navigator.clipboard.writeText(O.value.receiveAddress);
297
+ };
298
+ return watch(() => b.modelValue, (e) => {
299
+ e && T.value.length === 0 && W();
300
+ }), watch(E, () => {
301
+ L.value.length > 0 && (D.value = L.value[0].symbol);
302
+ }), watch(C, (e) => {
303
+ e === "payment" && O.value && Q(O.value.paymentId);
304
+ }), onUnmounted(() => {
305
+ F.value?.unsubscribe();
306
+ }), (v, x) => (openBlock(), createBlock(Teleport, { to: "body" }, [createVNode(Transition, { name: "_cppay-fade" }, {
307
+ default: withCtx(() => [e.modelValue ? (openBlock(), createElementBlock("div", {
308
+ key: 0,
309
+ class: "_cppay-overlay",
310
+ onClick: x[3] ||= withModifiers((e) => !w.value && U(), ["self"])
311
+ }, [createElementVNode("div", _hoisted_1, [createElementVNode("div", _hoisted_2, [createElementVNode("h2", _hoisted_3, toDisplayString(C.value === "select" ? "选择支付方式" : C.value === "success" ? "支付结果" : "完成支付"), 1), createElementVNode("button", {
312
+ onClick: U,
313
+ class: "_cppay-close-btn",
314
+ disabled: w.value
315
+ }, [...x[4] ||= [createElementVNode("svg", {
316
+ fill: "none",
317
+ stroke: "currentColor",
318
+ viewBox: "0 0 24 24"
319
+ }, [createElementVNode("path", {
320
+ "stroke-linecap": "round",
321
+ "stroke-linejoin": "round",
322
+ "stroke-width": "2",
323
+ d: "M6 18L18 6M6 6l12 12"
324
+ })], -1)]], 8, _hoisted_4)]), createElementVNode("div", _hoisted_5, [C.value === "success" ? (openBlock(), createElementBlock("div", _hoisted_6, [
325
+ x[5] ||= createElementVNode("div", { style: {
326
+ "font-size": "64px",
327
+ "margin-bottom": "1rem"
328
+ } }, "✅", -1),
329
+ createElementVNode("h3", _hoisted_7, toDisplayString(b.plain === "subscription" ? "授权成功!" : "支付成功!"), 1),
330
+ createElementVNode("p", _hoisted_8, toDisplayString(b.plain === "subscription" ? "订阅已激活" : "交易已完成"), 1)
331
+ ])) : createCommentVNode("", !0), C.value === "select" ? (openBlock(), createElementBlock("div", _hoisted_9, [
332
+ createElementVNode("div", _hoisted_10, [x[6] ||= createElementVNode("label", { class: "_cppay-label" }, "支付网络", -1), createElementVNode("div", _hoisted_11, [(openBlock(!0), createElementBlock(Fragment, null, renderList(T.value, (e) => (openBlock(), createElementBlock("button", {
333
+ key: e.chain,
334
+ onClick: (v) => E.value = e.chain,
335
+ class: normalizeClass(["_cppay-select-btn", E.value === e.chain ? "_cppay-selected" : ""])
336
+ }, [e.icon ? (openBlock(), createElementBlock("img", {
337
+ key: 0,
338
+ src: e.icon,
339
+ alt: e.chain
340
+ }, null, 8, _hoisted_13)) : createCommentVNode("", !0), createElementVNode("span", null, toDisplayString(e.chain), 1)], 10, _hoisted_12))), 128))])]),
341
+ createElementVNode("div", _hoisted_14, [x[7] ||= createElementVNode("label", { class: "_cppay-label" }, "支付代币", -1), createElementVNode("div", _hoisted_15, [(openBlock(!0), createElementBlock(Fragment, null, renderList(L.value, (e) => (openBlock(), createElementBlock("button", {
342
+ key: e.symbol,
343
+ onClick: (v) => D.value = e.symbol,
344
+ class: normalizeClass(["_cppay-select-btn", D.value === e.symbol ? "_cppay-selected" : ""])
345
+ }, [e.icon ? (openBlock(), createElementBlock("img", {
346
+ key: 0,
347
+ src: e.icon,
348
+ alt: e.symbol
349
+ }, null, 8, _hoisted_17)) : createCommentVNode("", !0), createElementVNode("span", null, toDisplayString(e.symbol), 1)], 10, _hoisted_16))), 128))])]),
350
+ createElementVNode("div", _hoisted_18, [createElementVNode("div", _hoisted_19, [createElementVNode("div", _hoisted_20, [x[8] ||= createElementVNode("span", { class: "_cppay-price-label" }, "支付金额", -1), createElementVNode("div", _hoisted_21, [createElementVNode("div", _hoisted_22, toDisplayString(V.value) + " " + toDisplayString(D.value), 1), createElementVNode("div", _hoisted_23, "≈ $" + toDisplayString(e.amount), 1)])])])]),
351
+ createElementVNode("div", _hoisted_24, [createElementVNode("button", {
352
+ onClick: Z,
353
+ disabled: !E.value || !D.value || w.value,
354
+ class: "_cppay-btn _cppay-btn-primary"
355
+ }, toDisplayString(w.value ? "处理中..." : "继续支付"), 9, _hoisted_25)])
356
+ ])) : C.value === "payment" && O.value ? (openBlock(), createElementBlock("div", _hoisted_26, [
357
+ createElementVNode("div", _hoisted_27, [createElementVNode("div", _hoisted_28, [k.value ? (openBlock(), createElementBlock("img", {
358
+ key: 0,
359
+ src: k.value,
360
+ alt: "QR Code",
361
+ style: {
362
+ width: "160px",
363
+ height: "160px",
364
+ display: "block"
365
+ }
366
+ }, null, 8, _hoisted_29)) : createCommentVNode("", !0)])]),
367
+ createElementVNode("div", _hoisted_30, [
368
+ createElementVNode("div", _hoisted_31, [createElementVNode("div", _hoisted_32, toDisplayString(b.plain === "subscription" ? "授权金额" : "支付金额"), 1), createElementVNode("div", _hoisted_33, toDisplayString(O.value.paymentAmount) + " " + toDisplayString(D.value), 1)]),
369
+ createElementVNode("div", _hoisted_34, [createElementVNode("div", _hoisted_35, toDisplayString(b.plain === "subscription" ? "授权合约地址" : "支付地址"), 1), createElementVNode("div", _hoisted_36, [createElementVNode("code", null, toDisplayString(O.value.receiveAddress), 1), createElementVNode("button", {
370
+ onClick: $,
371
+ class: "_cppay-copy-btn",
372
+ title: "复制地址"
373
+ }, [...x[9] ||= [createElementVNode("svg", {
374
+ fill: "none",
375
+ stroke: "currentColor",
376
+ viewBox: "0 0 24 24"
377
+ }, [createElementVNode("path", {
378
+ "stroke-linecap": "round",
379
+ "stroke-linejoin": "round",
380
+ "stroke-width": "2",
381
+ 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"
382
+ })], -1)]])])]),
383
+ b.plain === "subscription" ? (openBlock(), createElementBlock("div", _hoisted_37, [...x[10] ||= [createElementVNode("div", {
384
+ class: "_cppay-info-label",
385
+ style: { color: "#856404" }
386
+ }, "📌 订阅说明", -1), createElementVNode("div", {
387
+ class: "_cppay-info-value",
388
+ style: {
389
+ "font-size": "12px",
390
+ color: "#856404"
391
+ }
392
+ }, " 订阅支付需要授权代币给合约地址,系统将按周期自动扣款。授权后无需每次手动支付。 ", -1)]])) : createCommentVNode("", !0)
393
+ ]),
394
+ createElementVNode("div", _hoisted_38, [A.value ? (openBlock(), createElementBlock("div", _hoisted_44, [createElementVNode("button", {
395
+ onClick: X,
396
+ disabled: w.value,
397
+ class: "_cppay-btn _cppay-btn-primary"
398
+ }, toDisplayString(w.value ? e.plain === "subscription" ? "授权中..." : "支付中..." : e.plain === "subscription" ? "💳 钱包授权" : "💳 钱包支付"), 9, _hoisted_45), createElementVNode("div", _hoisted_46, " 已连接: " + toDisplayString(A.value.slice(0, 6)) + "..." + toDisplayString(A.value.slice(-4)), 1)])) : (openBlock(), createElementBlock("div", _hoisted_39, [createElementVNode("button", {
399
+ onClick: x[0] ||= () => K("metamask"),
400
+ disabled: j.value,
401
+ class: "_cppay-btn _cppay-btn-secondary",
402
+ style: {
403
+ display: "flex",
404
+ "align-items": "center",
405
+ "justify-content": "center",
406
+ gap: "0.5rem",
407
+ padding: "0.5rem 1rem",
408
+ "font-size": "14px",
409
+ flex: "1"
410
+ }
411
+ }, [createElementVNode("img", {
412
+ src: unref(metamask_default),
413
+ alt: "MetaMask",
414
+ style: {
415
+ width: "20px",
416
+ height: "20px"
417
+ }
418
+ }, null, 8, _hoisted_41), x[11] ||= createElementVNode("span", null, "MetaMask", -1)], 8, _hoisted_40), createElementVNode("button", {
419
+ onClick: x[1] ||= () => K("walletconnect"),
420
+ disabled: j.value,
421
+ class: "_cppay-btn _cppay-btn-secondary",
422
+ style: {
423
+ display: "flex",
424
+ "align-items": "center",
425
+ "justify-content": "center",
426
+ gap: "0.5rem",
427
+ padding: "0.5rem 1rem",
428
+ "font-size": "14px",
429
+ flex: "1"
430
+ }
431
+ }, [createElementVNode("img", {
432
+ src: unref(walletconnect_default),
433
+ alt: "WalletConnect",
434
+ style: {
435
+ width: "20px",
436
+ height: "20px"
437
+ }
438
+ }, null, 8, _hoisted_43), x[12] ||= createElementVNode("span", null, "WalletConnect", -1)], 8, _hoisted_42)]))]),
439
+ createElementVNode("div", _hoisted_47, [createElementVNode("button", {
440
+ onClick: H,
441
+ disabled: w.value,
442
+ class: "_cppay-btn _cppay-btn-primary"
443
+ }, toDisplayString(w.value ? "检查中..." : "我已完成支付"), 9, _hoisted_48)]),
444
+ createElementVNode("div", _hoisted_49, [createElementVNode("button", {
445
+ onClick: x[2] ||= (e) => C.value = "select",
446
+ disabled: w.value,
447
+ class: "_cppay-btn _cppay-btn-text"
448
+ }, " 更改支付方式 ", 8, _hoisted_50)])
449
+ ])) : createCommentVNode("", !0)])])])) : createCommentVNode("", !0)]),
450
+ _: 1
451
+ })]));
452
+ }
453
+ }), [["__scopeId", "data-v-1a5fedf2"]]), cppayState = ref({
454
+ apikey: "",
455
+ open: !1,
456
+ options: null
457
+ });
458
+ const showPayment = (e) => {
459
+ cppayState.value.options = e, cppayState.value.open = !0;
460
+ };
461
+ var handleClose = () => {
462
+ cppayState.value.open = !1;
463
+ }, handleSuccess = (e) => {
464
+ cppayState.value.options?.onSuccess?.(e), cppayState.value.open = !1;
465
+ }, handleError = (e) => {
466
+ cppayState.value.options?.onError?.(e);
467
+ };
468
+ const CppayPlugin = { install(e, v) {
469
+ if (!v?.apikey) throw Error("Cppay plugin requires an apikey");
470
+ cppayState.value.apikey = v.apikey, e.config.globalProperties.$showPayment = showPayment;
471
+ let y = document.createElement("div");
472
+ document.body.appendChild(y), createApp({ setup() {
473
+ return () => cppayState.value.options ? h(PaymentDialog_default, {
474
+ modelValue: cppayState.value.open,
475
+ "onUpdate:modelValue": (e) => {
476
+ cppayState.value.open = e, e || handleClose();
477
+ },
478
+ apikey: cppayState.value.apikey,
479
+ plain: cppayState.value.options.plain,
480
+ orderId: cppayState.value.options.orderId,
481
+ amount: cppayState.value.options.amount,
482
+ intervalDays: cppayState.value.options.intervalDays,
483
+ onSuccess: handleSuccess,
484
+ onError: handleError
485
+ }) : null;
486
+ } }).mount(y);
487
+ } }, useCppayPayment = () => {
488
+ if (!cppayState.value.apikey) throw Error("useCppayPayment must be used after installing CppayPlugin");
489
+ return { showPayment };
490
+ };
491
+ injectStyle(payment_dialog_default);
492
+ export { CppayPlugin, PaymentDialog_default as PaymentDialog, showPayment, useCppayPayment };