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/{cppay-DXZVBIDi.cjs → cppay-BYRjTzRF.cjs} +1 -1
- package/dist/{cppay-BPtRBPjB.js → cppay-C_gp2ZZ3.js} +4 -7
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +18 -8
- package/dist/index.js +1 -1
- package/dist/locales-DAKREZkH.cjs +1 -0
- package/dist/locales-DGvDecya.js +112 -0
- package/dist/react.cjs +1 -1
- package/dist/react.d.ts +141 -2
- package/dist/react.js +540 -434
- package/dist/vue.cjs +1 -1
- package/dist/vue.d.ts +131 -12
- package/dist/vue.js +454 -351
- package/package.json +1 -1
- package/dist/cppay-sdk.css +0 -2
- package/dist/inject-style-Boo8CMsU.cjs +0 -1
- package/dist/inject-style-CWza6SKp.js +0 -7
package/dist/vue.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { t as cppay_default } from "./cppay-
|
|
2
|
-
import { n as payment_dialog_default, t as
|
|
3
|
-
import { Fragment,
|
|
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-
|
|
11
|
+
var _hoisted_1$1 = { class: "_cppay-content" }, _hoisted_2$1 = {
|
|
12
12
|
key: 0,
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
},
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
margin: "0"
|
|
25
|
-
} }, _hoisted_9 = { key: 1 }, _hoisted_10 = { class: "_cppay-section" }, _hoisted_11 = { class: "_cppay-grid" }, _hoisted_12 = ["onClick"], _hoisted_13 = ["src", "alt"], _hoisted_14 = { class: "_cppay-section" }, _hoisted_15 = { class: "_cppay-grid" }, _hoisted_16 = ["onClick"], _hoisted_17 = ["src", "alt"], _hoisted_18 = { class: "_cppay-section" }, _hoisted_19 = { class: "_cppay-price-box" }, _hoisted_20 = { class: "_cppay-price-row" }, _hoisted_21 = { class: "_cppay-price-amount" }, _hoisted_22 = { class: "_cppay-price-main" }, _hoisted_23 = { class: "_cppay-price-sub" }, _hoisted_24 = { class: "_cppay-section" }, _hoisted_25 = { class: "_cppay-error-tooltip" }, _hoisted_26 = {
|
|
13
|
+
class: "_cppay-state-container"
|
|
14
|
+
}, _hoisted_3$1 = { class: "_cppay-state-title" }, _hoisted_4$1 = { class: "_cppay-state-message" }, _hoisted_5 = {
|
|
15
|
+
key: 1,
|
|
16
|
+
class: "_cppay-state-container"
|
|
17
|
+
}, _hoisted_6 = { 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
|
-
},
|
|
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
|
-
},
|
|
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-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
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
|
-
},
|
|
50
|
+
}, _hoisted_59 = {
|
|
42
51
|
key: 1,
|
|
43
52
|
class: "_cppay-section"
|
|
44
|
-
},
|
|
45
|
-
|
|
46
|
-
"margin-top": "8px",
|
|
47
|
-
"font-size": "12px",
|
|
48
|
-
color: "#666"
|
|
49
|
-
} }, _hoisted_49 = { class: "_cppay-section" }, _hoisted_50 = ["disabled"], _hoisted_51 = { class: "_cppay-section" }, _hoisted_52 = ["disabled"], PaymentDialog_default = /* @__PURE__ */ ((e, g) => {
|
|
50
|
-
let _ = e.__vccOpts || e;
|
|
51
|
-
for (let [e, v] of g) _[e] = v;
|
|
52
|
-
return _;
|
|
53
|
-
})(/* @__PURE__ */ defineComponent({
|
|
54
|
-
__name: "PaymentDialog",
|
|
53
|
+
}, _hoisted_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: {
|
|
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:
|
|
75
|
+
"update:paymentStep",
|
|
65
76
|
"success",
|
|
66
|
-
"
|
|
77
|
+
"expired",
|
|
78
|
+
"failed",
|
|
79
|
+
"error",
|
|
80
|
+
"update:error"
|
|
67
81
|
],
|
|
68
|
-
setup(
|
|
69
|
-
let
|
|
70
|
-
"
|
|
71
|
-
"USDC",
|
|
72
|
-
"BUSD",
|
|
73
|
-
"DAI",
|
|
74
|
-
"TUSD",
|
|
75
|
-
"USDD",
|
|
76
|
-
"FDUSD"
|
|
77
|
-
].includes(e.toUpperCase()) ? 2 : 6, V = (e, g) => {
|
|
78
|
-
let _ = parseFloat(e);
|
|
79
|
-
return isNaN(_) ? "0" : _.toFixed(g).replace(/\.?0+$/, "");
|
|
80
|
-
}, H = computed(() => {
|
|
81
|
-
if (!k.value || !z.value) return "0";
|
|
82
|
-
let e = parseFloat(z.value.price);
|
|
83
|
-
if (isNaN(e) || e === 0) return "0";
|
|
84
|
-
let g = B(k.value);
|
|
85
|
-
return V((parseFloat(y.amount) / e).toFixed(g), g);
|
|
86
|
-
}), U = () => {
|
|
87
|
-
A.value && (T.value = void 0, w.value = !0, y.plain === "one-time" ? Q(A.value.paymentId) : y.plain === "subscription" && Q(A.value.subscriptionId));
|
|
88
|
-
}, W = () => {
|
|
89
|
-
C.value || w.value || (b("update:modelValue", !1), setTimeout(() => {
|
|
90
|
-
S.value = "select", T.value = void 0, A.value = null;
|
|
91
|
-
}, 300));
|
|
92
|
-
}, G = async () => {
|
|
93
|
-
try {
|
|
94
|
-
C.value = !0, T.value = void 0, D.value = await x.getSupportedChains(), D.value.length > 0 && (O.value = D.value[0].chain);
|
|
95
|
-
} catch (e) {
|
|
96
|
-
T.value = e instanceof Error ? e.message : "加载支付网络失败", b("error", e);
|
|
97
|
-
} finally {
|
|
98
|
-
C.value = !1;
|
|
99
|
-
}
|
|
100
|
-
};
|
|
101
|
-
onMounted(() => {
|
|
102
|
-
typeof window < "u" && !I && (I = createAppKit({
|
|
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
|
-
}),
|
|
124
|
-
|
|
125
|
-
}),
|
|
126
|
-
|
|
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
|
-
|
|
132
|
-
} catch (
|
|
133
|
-
|
|
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
|
-
|
|
116
|
+
E.value = !1;
|
|
136
117
|
}
|
|
137
|
-
},
|
|
138
|
-
|
|
139
|
-
|
|
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${
|
|
160
|
+
params: [{ chainId: `0x${r.toString(16)}` }]
|
|
142
161
|
});
|
|
143
|
-
} catch (
|
|
144
|
-
throw
|
|
162
|
+
} catch (r) {
|
|
163
|
+
throw r.code === 4902 ? Error(m.value.pleaseAddNetwork) : r;
|
|
145
164
|
}
|
|
146
165
|
}, J = async () => {
|
|
147
|
-
if (!(!
|
|
148
|
-
|
|
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
|
|
152
|
-
account:
|
|
153
|
-
transport: custom(
|
|
169
|
+
let c = createWalletClient({
|
|
170
|
+
account: T.value,
|
|
171
|
+
transport: custom(D.value)
|
|
154
172
|
});
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
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
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
}
|
|
184
|
-
C.value = !1, w.value = !0, Q(e.paymentId);
|
|
185
|
-
} catch (e) {
|
|
186
|
-
console.error("钱包支付失败:", e), T.value = e instanceof Error ? e.message : "钱包支付失败", b("error", e), C.value = !1;
|
|
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 (!(!
|
|
190
|
-
|
|
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
|
|
194
|
-
account:
|
|
195
|
-
transport: custom(
|
|
203
|
+
let c = createWalletClient({
|
|
204
|
+
account: T.value,
|
|
205
|
+
transport: custom(D.value)
|
|
196
206
|
});
|
|
197
|
-
if (!z.value.address) throw Error(
|
|
198
|
-
|
|
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: [
|
|
224
|
+
args: [r.spenderAddress, parseUnits(r.approveAmount, z.value.decimals)],
|
|
215
225
|
chain: null
|
|
216
|
-
});
|
|
217
|
-
|
|
218
|
-
|
|
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 (!
|
|
223
|
-
|
|
231
|
+
if (!T.value) {
|
|
232
|
+
p("update:error", m.value.pleaseConnectWallet), p("error", Error(m.value.pleaseConnectWallet));
|
|
224
233
|
return;
|
|
225
234
|
}
|
|
226
|
-
|
|
235
|
+
f.plain === "one-time" ? await J() : f.plain === "subscription" && await Y();
|
|
227
236
|
}, Z = async () => {
|
|
228
|
-
if (!(!
|
|
229
|
-
|
|
230
|
-
let
|
|
231
|
-
|
|
232
|
-
paymentChain:
|
|
233
|
-
paymentToken:
|
|
234
|
-
orderId:
|
|
235
|
-
amount:
|
|
236
|
-
}) :
|
|
237
|
-
paymentChain:
|
|
238
|
-
paymentToken:
|
|
239
|
-
orderId:
|
|
240
|
-
amountOfUsd:
|
|
241
|
-
intervalDays:
|
|
242
|
-
})),
|
|
243
|
-
paymentId: e.paymentId || e.subscriptionId,
|
|
244
|
-
paymentAmount: e.paymentAmount || e.approveAmount,
|
|
245
|
-
receiveAddress: e.receiveAddress || e.spenderAddress || ""
|
|
246
|
-
};
|
|
247
|
-
let g = `${O.value.toLowerCase()}:${A.value.receiveAddress}?amount=${A.value.paymentAmount}`;
|
|
248
|
-
j.value = await QRCode.toDataURL(g, {
|
|
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
|
-
})
|
|
253
|
-
} catch (
|
|
254
|
-
|
|
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 = (
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
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
|
-
|
|
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(() =>
|
|
272
|
-
|
|
273
|
-
}), watch(
|
|
274
|
-
|
|
275
|
-
}), watch(
|
|
276
|
-
|
|
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
|
-
|
|
279
|
-
}), (
|
|
280
|
-
|
|
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-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
}, [
|
|
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
|
-
|
|
292
|
-
}, [createElementVNode("
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
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
|
-
}),
|
|
514
|
+
}), cppayState = ref({
|
|
429
515
|
apikey: "",
|
|
430
516
|
open: !1,
|
|
431
517
|
options: null
|
|
432
518
|
});
|
|
433
|
-
const showPayment = (
|
|
434
|
-
cppayState.value.options =
|
|
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 = (
|
|
439
|
-
cppayState.value.options?.onSuccess?.(
|
|
440
|
-
|
|
441
|
-
|
|
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(
|
|
444
|
-
if (!
|
|
445
|
-
cppayState.value.apikey =
|
|
446
|
-
let
|
|
447
|
-
|
|
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": (
|
|
451
|
-
cppayState.value.open =
|
|
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 {
|
|
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 };
|