cppay-sdk 0.0.2-beta.20 → 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.js CHANGED
@@ -1,27 +1,49 @@
1
- import { i as __toESM, n as injectStyle, r as payment_dialog_default, t as require_browser } from "./browser-Dm8HHcNy.js";
2
- import { t as cppay_default } from "./cppay-LnYTnh4d.js";
3
- import { Fragment, Teleport, Transition, computed, createBlock, createCommentVNode, createElementBlock, createElementVNode, createVNode, defineComponent, normalizeClass, onUnmounted, openBlock, ref, renderList, toDisplayString, watch, withCtx, withModifiers } from "vue";
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
4
  import { EMPTY, defer, timer } from "rxjs";
5
5
  import { expand, retry, switchMap, tap, timeout } from "rxjs/operators";
6
- 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 = { key: 0 }, _hoisted_7 = { class: "_cppay-section" }, _hoisted_8 = { class: "_cppay-grid" }, _hoisted_9 = ["onClick"], _hoisted_10 = ["src", "alt"], _hoisted_11 = { class: "_cppay-section" }, _hoisted_12 = { class: "_cppay-grid" }, _hoisted_13 = ["onClick"], _hoisted_14 = ["src", "alt"], _hoisted_15 = { class: "_cppay-section" }, _hoisted_16 = { class: "_cppay-price-box" }, _hoisted_17 = { class: "_cppay-price-row" }, _hoisted_18 = { class: "_cppay-price-amount" }, _hoisted_19 = { class: "_cppay-price-main" }, _hoisted_20 = { class: "_cppay-price-sub" }, _hoisted_21 = { class: "_cppay-section" }, _hoisted_22 = ["disabled"], _hoisted_23 = { key: 1 }, _hoisted_24 = { class: "_cppay-qr-container" }, _hoisted_25 = {
7
- class: "_cppay-qr-code",
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,
8
11
  style: {
9
- background: "white",
10
- padding: "16px",
11
- "border-radius": "16px",
12
- display: "inline-block"
12
+ "text-align": "center",
13
+ padding: "2rem 0"
13
14
  }
14
- }, _hoisted_26 = ["src"], _hoisted_27 = { class: "_cppay-section" }, _hoisted_28 = { class: "_cppay-info-box" }, _hoisted_29 = { class: "_cppay-info-label" }, _hoisted_30 = { class: "_cppay-info-value" }, _hoisted_31 = { class: "_cppay-info-box" }, _hoisted_32 = { class: "_cppay-info-label" }, _hoisted_33 = { class: "_cppay-address-row" }, _hoisted_34 = {
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 = {
15
24
  key: 0,
16
25
  class: "_cppay-info-box",
17
26
  style: {
18
27
  background: "#fff3cd",
19
28
  "border-color": "#ffc107"
20
29
  }
21
- }, _hoisted_35 = { class: "_cppay-section" }, _hoisted_36 = ["disabled"], _hoisted_37 = { class: "_cppay-section" }, _hoisted_38 = ["disabled"], PaymentDialog_default = /* @__PURE__ */ ((r, M) => {
22
- let N = r.__vccOpts || r;
23
- for (let [r, P] of M) N[r] = P;
24
- return N;
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;
25
47
  })(/* @__PURE__ */ defineComponent({
26
48
  __name: "PaymentDialog",
27
49
  props: {
@@ -37,91 +59,260 @@ var import_browser = /* @__PURE__ */ __toESM(require_browser(), 1), _hoisted_1 =
37
59
  "success",
38
60
  "error"
39
61
  ],
40
- setup(r, { emit: M }) {
41
- let N = r, P = M, F = new cppay_default(N.apikey), I = ref("select"), L = ref(!1), R = ref([]), z = ref(""), B = ref(""), V = ref(null), H = ref(""), U = ref(null), W = computed(() => R.value.find((r) => r.chain === z.value)), G = computed(() => W.value?.tokens || []);
42
- computed(() => G.value.find((r) => r.symbol === B.value));
43
- let K = ref(1), q = computed(() => B.value ? (parseFloat(N.amount) / K.value).toFixed(6) : "0"), J = () => {
44
- P("update:modelValue", !1), setTimeout(() => {
45
- I.value = "select", V.value = null;
46
- }, 300);
47
- }, Y = async () => {
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) => {
48
102
  try {
49
- L.value = !0, R.value = await F.getSupportedChains(), R.value.length > 0 && (z.value = R.value[0].chain);
50
- } catch (r) {
51
- P("error", r);
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);
52
209
  } finally {
53
- L.value = !1;
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;
54
247
  }
55
248
  }, X = async () => {
56
- if (!(!z.value || !B.value)) try {
57
- L.value = !0;
58
- let r;
59
- N.plain === "one-time" ? r = await F.createPayment("one-time", {
60
- paymentChain: z.value,
61
- paymentToken: B.value,
62
- orderId: N.orderId,
63
- amount: q.value
64
- }) : N.plain === "subscription" && (r = await F.createPayment("subscription", {
65
- paymentChain: z.value,
66
- paymentToken: B.value,
67
- orderId: N.orderId,
68
- amountOfUsd: q.value,
69
- intervalDays: N.intervalDays || 30
70
- })), V.value = {
71
- paymentId: r.paymentId || r.subscriptionId,
72
- paymentAmount: r.paymentAmount || r.approveAmount,
73
- receiveAddress: r.receiveAddress || r.spenderAddress || ""
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 || ""
74
273
  };
75
- let M = `${z.value.toLowerCase()}:${V.value.receiveAddress}?amount=${V.value.paymentAmount}`;
76
- H.value = await import_browser.toDataURL(M, {
274
+ let v = `${E.value.toLowerCase()}:${O.value.receiveAddress}?amount=${O.value.paymentAmount}`;
275
+ k.value = await import_browser.toDataURL(v, {
77
276
  width: 200,
78
277
  margin: 2,
79
278
  errorCorrectionLevel: "H"
80
- }), I.value = "payment";
81
- } catch (r) {
82
- P("error", r);
279
+ }), C.value = "payment";
280
+ } catch (e) {
281
+ x("error", e);
83
282
  } finally {
84
- L.value = !1;
283
+ w.value = !1;
85
284
  }
86
- }, Z = (r) => {
87
- let M = () => defer(() => N.plain === "subscription" ? F.checkSubscriptionPaymentStatus({ subscriptionId: r }) : F.checkOnetimePaymentStatus({ paymentId: r })).pipe(timeout(15e3), retry({
285
+ }, Q = (e) => {
286
+ let v = () => defer(() => b.plain === "subscription" ? S.checkSubscriptionPaymentStatus({ subscriptionId: e }) : S.checkOnetimePaymentStatus({ paymentId: e })).pipe(timeout(15e3), retry({
88
287
  count: 3,
89
288
  delay: 2e3
90
289
  }));
91
- U.value?.unsubscribe(), U.value = M().pipe(expand((r) => r.status === "pending" ? timer(2e3).pipe(switchMap(() => M())) : EMPTY), tap((M) => {
92
- M.status === "expired" && alert("支付已过期"), M.status === "paid" && (alert("支付成功!"), P("success", r), J()), M.status === "failed" && alert("支付失败"), M.status === "approved" && (alert("订阅成功!"), P("success", r), J());
93
- })).subscribe({ error: (r) => {
94
- console.error("支付状态检查错误:", r), P("error", r);
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);
95
294
  } });
96
- }, Q = async () => {
97
- if (V.value) try {
98
- L.value = !0, Z(V.value.paymentId);
99
- } catch (r) {
100
- P("error", r);
101
- } finally {
102
- L.value = !1;
103
- }
104
295
  }, $ = async () => {
105
- V.value?.receiveAddress && (await navigator.clipboard.writeText(V.value.receiveAddress), alert("地址已复制"));
296
+ O.value?.receiveAddress && await navigator.clipboard.writeText(O.value.receiveAddress);
106
297
  };
107
- return watch(() => N.modelValue, (r) => {
108
- r && R.value.length === 0 && Y();
109
- }), watch(z, () => {
110
- G.value.length > 0 && (B.value = G.value[0].symbol);
111
- }), watch(I, (r) => {
112
- r === "payment" && V.value && Z(V.value.paymentId);
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);
113
304
  }), onUnmounted(() => {
114
- U.value?.unsubscribe();
115
- }), (M, P) => (openBlock(), createBlock(Teleport, { to: "body" }, [createVNode(Transition, { name: "_cppay-fade" }, {
116
- default: withCtx(() => [r.modelValue ? (openBlock(), createElementBlock("div", {
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", {
117
308
  key: 0,
118
309
  class: "_cppay-overlay",
119
- onClick: withModifiers(J, ["self"])
120
- }, [createElementVNode("div", _hoisted_1, [createElementVNode("div", _hoisted_2, [createElementVNode("h2", _hoisted_3, toDisplayString(I.value === "select" ? "选择支付方式" : "完成支付"), 1), createElementVNode("button", {
121
- onClick: J,
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,
122
313
  class: "_cppay-close-btn",
123
- disabled: L.value
124
- }, [...P[1] ||= [createElementVNode("svg", {
314
+ disabled: w.value
315
+ }, [...x[4] ||= [createElementVNode("svg", {
125
316
  fill: "none",
126
317
  stroke: "currentColor",
127
318
  viewBox: "0 0 24 24"
@@ -130,48 +321,56 @@ var import_browser = /* @__PURE__ */ __toESM(require_browser(), 1), _hoisted_1 =
130
321
  "stroke-linejoin": "round",
131
322
  "stroke-width": "2",
132
323
  d: "M6 18L18 6M6 6l12 12"
133
- })], -1)]], 8, _hoisted_4)]), createElementVNode("div", _hoisted_5, [I.value === "select" ? (openBlock(), createElementBlock("div", _hoisted_6, [
134
- createElementVNode("div", _hoisted_7, [P[2] ||= createElementVNode("label", { class: "_cppay-label" }, "支付网络", -1), createElementVNode("div", _hoisted_8, [(openBlock(!0), createElementBlock(Fragment, null, renderList(R.value, (r) => (openBlock(), createElementBlock("button", {
135
- key: r.chain,
136
- onClick: (M) => z.value = r.chain,
137
- class: normalizeClass(["_cppay-select-btn", z.value === r.chain ? "_cppay-selected" : ""])
138
- }, [r.icon ? (openBlock(), createElementBlock("img", {
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", {
139
337
  key: 0,
140
- src: r.icon,
141
- alt: r.chain
142
- }, null, 8, _hoisted_10)) : createCommentVNode("", !0), createElementVNode("span", null, toDisplayString(r.chain), 1)], 10, _hoisted_9))), 128))])]),
143
- createElementVNode("div", _hoisted_11, [P[3] ||= createElementVNode("label", { class: "_cppay-label" }, "支付代币", -1), createElementVNode("div", _hoisted_12, [(openBlock(!0), createElementBlock(Fragment, null, renderList(G.value, (r) => (openBlock(), createElementBlock("button", {
144
- key: r.symbol,
145
- onClick: (M) => B.value = r.symbol,
146
- class: normalizeClass(["_cppay-select-btn", B.value === r.symbol ? "_cppay-selected" : ""])
147
- }, [r.icon ? (openBlock(), createElementBlock("img", {
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", {
148
346
  key: 0,
149
- src: r.icon,
150
- alt: r.symbol
151
- }, null, 8, _hoisted_14)) : createCommentVNode("", !0), createElementVNode("span", null, toDisplayString(r.symbol), 1)], 10, _hoisted_13))), 128))])]),
152
- createElementVNode("div", _hoisted_15, [createElementVNode("div", _hoisted_16, [createElementVNode("div", _hoisted_17, [P[4] ||= createElementVNode("span", { class: "_cppay-price-label" }, "支付金额", -1), createElementVNode("div", _hoisted_18, [createElementVNode("div", _hoisted_19, toDisplayString(q.value) + " " + toDisplayString(B.value), 1), createElementVNode("div", _hoisted_20, "≈ $" + toDisplayString(r.amount), 1)])])])]),
153
- createElementVNode("div", _hoisted_21, [createElementVNode("button", {
154
- onClick: X,
155
- disabled: !z.value || !B.value || L.value,
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,
156
354
  class: "_cppay-btn _cppay-btn-primary"
157
- }, toDisplayString(L.value ? "处理中..." : "继续支付"), 9, _hoisted_22)])
158
- ])) : I.value === "payment" && V.value ? (openBlock(), createElementBlock("div", _hoisted_23, [
159
- createElementVNode("div", _hoisted_24, [createElementVNode("div", _hoisted_25, [H.value ? (openBlock(), createElementBlock("img", {
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", {
160
358
  key: 0,
161
- src: H.value,
359
+ src: k.value,
162
360
  alt: "QR Code",
163
361
  style: {
164
- width: "200px",
165
- height: "200px"
362
+ width: "160px",
363
+ height: "160px",
364
+ display: "block"
166
365
  }
167
- }, null, 8, _hoisted_26)) : createCommentVNode("", !0)])]),
168
- createElementVNode("div", _hoisted_27, [
169
- createElementVNode("div", _hoisted_28, [createElementVNode("div", _hoisted_29, toDisplayString(N.plain === "subscription" ? "授权金额" : "支付金额"), 1), createElementVNode("div", _hoisted_30, toDisplayString(V.value.paymentAmount) + " " + toDisplayString(B.value), 1)]),
170
- createElementVNode("div", _hoisted_31, [createElementVNode("div", _hoisted_32, toDisplayString(N.plain === "subscription" ? "授权合约地址" : "支付地址"), 1), createElementVNode("div", _hoisted_33, [createElementVNode("code", null, toDisplayString(V.value.receiveAddress), 1), createElementVNode("button", {
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", {
171
370
  onClick: $,
172
371
  class: "_cppay-copy-btn",
173
372
  title: "复制地址"
174
- }, [...P[5] ||= [createElementVNode("svg", {
373
+ }, [...x[9] ||= [createElementVNode("svg", {
175
374
  fill: "none",
176
375
  stroke: "currentColor",
177
376
  viewBox: "0 0 24 24"
@@ -181,7 +380,7 @@ var import_browser = /* @__PURE__ */ __toESM(require_browser(), 1), _hoisted_1 =
181
380
  "stroke-width": "2",
182
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"
183
382
  })], -1)]])])]),
184
- N.plain === "subscription" ? (openBlock(), createElementBlock("div", _hoisted_34, [...P[6] ||= [createElementVNode("div", {
383
+ b.plain === "subscription" ? (openBlock(), createElementBlock("div", _hoisted_37, [...x[10] ||= [createElementVNode("div", {
185
384
  class: "_cppay-info-label",
186
385
  style: { color: "#856404" }
187
386
  }, "📌 订阅说明", -1), createElementVNode("div", {
@@ -192,20 +391,102 @@ var import_browser = /* @__PURE__ */ __toESM(require_browser(), 1), _hoisted_1 =
192
391
  }
193
392
  }, " 订阅支付需要授权代币给合约地址,系统将按周期自动扣款。授权后无需每次手动支付。 ", -1)]])) : createCommentVNode("", !0)
194
393
  ]),
195
- createElementVNode("div", _hoisted_35, [createElementVNode("button", {
196
- onClick: Q,
197
- disabled: L.value,
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,
198
442
  class: "_cppay-btn _cppay-btn-primary"
199
- }, toDisplayString(L.value ? "检查支付状态..." : "我已完成支付"), 9, _hoisted_36)]),
200
- createElementVNode("div", _hoisted_37, [createElementVNode("button", {
201
- onClick: P[0] ||= (r) => I.value = "select",
202
- disabled: L.value,
203
- class: "_cppay-btn _cppay-btn-secondary"
204
- }, " 更改支付方式 ", 8, _hoisted_38)])
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)])
205
449
  ])) : createCommentVNode("", !0)])])])) : createCommentVNode("", !0)]),
206
450
  _: 1
207
451
  })]));
208
452
  }
209
- }), [["__scopeId", "data-v-681ced40"]]);
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
+ };
210
491
  injectStyle(payment_dialog_default);
211
- export { PaymentDialog_default as PaymentDialog };
492
+ export { CppayPlugin, PaymentDialog_default as PaymentDialog, showPayment, useCppayPayment };