cppay-sdk 0.0.2-beta.31 → 0.0.2-beta.33

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