cppay-sdk 0.0.2-beta.39 → 0.0.2-beta.40

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