cppay-sdk 0.0.2-beta.8 → 0.0.2
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/README.md +630 -2
- package/dist/cppay-Db8t1Cra.js +216 -0
- package/dist/cppay-DuOJqlpA.cjs +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +169 -14
- package/dist/index.js +1 -1
- package/dist/locales-BWWyDdfj.cjs +1 -0
- package/dist/locales-BZF2EQ2A.js +128 -0
- package/dist/react.cjs +1 -1
- package/dist/react.d.ts +232 -3
- package/dist/react.js +868 -193
- package/dist/vue.cjs +1 -1
- package/dist/vue.d.ts +183 -10
- package/dist/vue.js +687 -122
- package/package.json +46 -18
- package/dist/cppay-D7czsjj1.cjs +0 -1
- package/dist/cppay-Oxm_gXCa.js +0 -97
- package/dist/cppay-sdk.css +0 -2
- package/dist/inject-style-Dz7JsQxo.cjs +0 -1
- package/dist/inject-style-qX_0AjjE.js +0 -7
package/dist/vue.js
CHANGED
|
@@ -1,143 +1,708 @@
|
|
|
1
|
-
import { t as cppay_default } from "./cppay-
|
|
2
|
-
import { n as payment_dialog_default, t as
|
|
3
|
-
import { Fragment,
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
}
|
|
9
|
-
|
|
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-BZF2EQ2A.js";
|
|
3
|
+
import { Fragment, computed, createApp, createBlock, createCommentVNode, createElementBlock, createElementVNode, createTextVNode, defineComponent, h, normalizeClass, onMounted, onUnmounted, openBlock, ref, renderList, renderSlot, shallowRef, toDisplayString, watch, withCtx } from "vue";
|
|
4
|
+
import * as QRCode from "qrcode";
|
|
5
|
+
import { EMPTY, defer, timer } from "rxjs";
|
|
6
|
+
import { expand, retry, switchMap, tap, timeout } from "rxjs/operators";
|
|
7
|
+
import { createWalletClient, custom, parseUnits } from "viem";
|
|
8
|
+
import { arbitrum, base, bsc, mainnet, optimism, polygon } from "viem/chains";
|
|
9
|
+
import { createAppKit } from "@reown/appkit";
|
|
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 _cppay-state-title-success" }, _hoisted_4$1 = {
|
|
12
|
+
key: 0,
|
|
13
|
+
class: "_cppay-state-hash-container"
|
|
14
|
+
}, _hoisted_5 = { class: "_cppay-state-label" }, _hoisted_6 = { class: "_cppay-hash-row" }, _hoisted_7 = { class: "_cppay-state-hash" }, _hoisted_8 = ["title"], _hoisted_9 = {
|
|
15
|
+
key: 1,
|
|
16
|
+
class: "_cppay-success-details"
|
|
17
|
+
}, _hoisted_10 = { class: "_cppay-detail-item" }, _hoisted_11 = { class: "_cppay-detail-label" }, _hoisted_12 = { class: "_cppay-detail-value" }, _hoisted_13 = { class: "_cppay-detail-item" }, _hoisted_14 = { class: "_cppay-detail-label" }, _hoisted_15 = { class: "_cppay-detail-value" }, _hoisted_16 = { class: "_cppay-detail-item" }, _hoisted_17 = { class: "_cppay-detail-label" }, _hoisted_18 = { class: "_cppay-detail-value" }, _hoisted_19 = { class: "_cppay-detail-item" }, _hoisted_20 = { class: "_cppay-detail-label" }, _hoisted_21 = { class: "_cppay-detail-value" }, _hoisted_22 = {
|
|
18
|
+
key: 0,
|
|
19
|
+
class: "_cppay-detail-item"
|
|
20
|
+
}, _hoisted_23 = { class: "_cppay-detail-label" }, _hoisted_24 = { class: "_cppay-detail-value" }, _hoisted_25 = { class: "_cppay-detail-item" }, _hoisted_26 = { class: "_cppay-detail-label" }, _hoisted_27 = { class: "_cppay-detail-value _cppay-detail-id" }, _hoisted_28 = { class: "_cppay-state-container" }, _hoisted_29 = { class: "_cppay-state-title _cppay-state-title-expired" }, _hoisted_30 = { class: "_cppay-state-message" }, _hoisted_31 = ["disabled"], _hoisted_32 = { class: "_cppay-state-container" }, _hoisted_33 = { class: "_cppay-state-title _cppay-state-title-error" }, _hoisted_34 = { class: "_cppay-state-message" }, _hoisted_35 = ["disabled"], _hoisted_36 = { class: "_cppay-state-container" }, _hoisted_37 = { class: "_cppay-state-title _cppay-state-title-failed" }, _hoisted_38 = { class: "_cppay-state-message" }, _hoisted_39 = ["disabled"], _hoisted_40 = { key: 4 }, _hoisted_41 = { class: "_cppay-section" }, _hoisted_42 = { class: "_cppay-label" }, _hoisted_43 = { class: "_cppay-grid" }, _hoisted_44 = ["onClick"], _hoisted_45 = ["src", "alt"], _hoisted_46 = { class: "_cppay-section" }, _hoisted_47 = { class: "_cppay-label" }, _hoisted_48 = { class: "_cppay-grid" }, _hoisted_49 = ["onClick"], _hoisted_50 = ["src", "alt"], _hoisted_51 = { class: "_cppay-section" }, _hoisted_52 = { class: "_cppay-price-box" }, _hoisted_53 = { class: "_cppay-price-row" }, _hoisted_54 = { class: "_cppay-price-label" }, _hoisted_55 = { class: "_cppay-price-amount" }, _hoisted_56 = { class: "_cppay-price-main" }, _hoisted_57 = { class: "_cppay-price-sub" }, _hoisted_58 = { class: "_cppay-section" }, _hoisted_59 = { class: "_cppay-error-tooltip" }, _hoisted_60 = {
|
|
21
|
+
key: 0,
|
|
22
|
+
class: "_cppay-error-tooltip-full"
|
|
23
|
+
}, _hoisted_61 = ["disabled"], _hoisted_62 = { key: 5 }, _hoisted_63 = { class: "_cppay-qr-container" }, _hoisted_64 = { class: "_cppay-qr-code" }, _hoisted_65 = ["src"], _hoisted_66 = { class: "_cppay-section" }, _hoisted_67 = {
|
|
24
|
+
key: 0,
|
|
25
|
+
class: "_cppay-info-box"
|
|
26
|
+
}, _hoisted_68 = { class: "_cppay-info-flex-container" }, _hoisted_69 = { class: "_cppay-info-flex-child" }, _hoisted_70 = { class: "_cppay-info-label" }, _hoisted_71 = { class: "_cppay-info-value _cppay-info-value-flex" }, _hoisted_72 = { key: 0 }, _hoisted_73 = { class: "_cppay-info-box" }, _hoisted_74 = { class: "_cppay-info-flex-child" }, _hoisted_75 = { class: "_cppay-info-label _cppay-info-label-flex" }, _hoisted_76 = {
|
|
27
|
+
key: 0,
|
|
28
|
+
class: "_cppay-countdown"
|
|
29
|
+
}, _hoisted_77 = { class: "_cppay-address-row" }, _hoisted_78 = { key: 0 }, _hoisted_79 = ["title"], _hoisted_80 = {
|
|
30
|
+
key: 0,
|
|
31
|
+
class: "_cppay-copy-icon",
|
|
32
|
+
viewBox: "0 0 24 24",
|
|
33
|
+
fill: "none",
|
|
34
|
+
stroke: "currentColor",
|
|
35
|
+
"stroke-width": "2"
|
|
36
|
+
}, _hoisted_81 = {
|
|
37
|
+
key: 1,
|
|
38
|
+
class: "_cppay-copy-icon",
|
|
39
|
+
viewBox: "0 0 24 24",
|
|
40
|
+
fill: "currentColor"
|
|
41
|
+
}, _hoisted_82 = {
|
|
42
|
+
key: 1,
|
|
43
|
+
class: "_cppay-info-box _cppay-subscription-box"
|
|
44
|
+
}, _hoisted_83 = { class: "_cppay-info-label _cppay-subscription-label" }, _hoisted_84 = { class: "_cppay-info-value _cppay-subscription-message" }, _hoisted_85 = { class: "_cppay-error-tooltip" }, _hoisted_86 = {
|
|
45
|
+
key: 0,
|
|
46
|
+
class: "_cppay-error-tooltip-full"
|
|
47
|
+
}, _hoisted_87 = {
|
|
48
|
+
key: 1,
|
|
49
|
+
class: "_cppay-section"
|
|
50
|
+
}, _hoisted_88 = ["disabled"], _hoisted_89 = ["disabled"], _hoisted_90 = ["disabled", "title"], _hoisted_91 = { class: "_cppay-wallet-address-text" }, _hoisted_92 = { class: "_cppay-section" }, _hoisted_93 = ["disabled"], _hoisted_94 = { class: "_cppay-section" }, _hoisted_95 = ["disabled"], PaymentContent_default = /* @__PURE__ */ defineComponent({
|
|
51
|
+
__name: "PaymentContent",
|
|
10
52
|
props: {
|
|
11
|
-
|
|
12
|
-
|
|
53
|
+
apikey: {},
|
|
54
|
+
ott: {},
|
|
13
55
|
orderId: {},
|
|
14
|
-
amount: {}
|
|
56
|
+
amount: {},
|
|
57
|
+
plain: {},
|
|
58
|
+
intervalDays: {},
|
|
59
|
+
remark: {},
|
|
60
|
+
slots: {},
|
|
61
|
+
locale: {}
|
|
15
62
|
},
|
|
16
63
|
emits: [
|
|
17
|
-
"update:
|
|
64
|
+
"update:paymentStep",
|
|
18
65
|
"success",
|
|
66
|
+
"expired",
|
|
67
|
+
"failed",
|
|
19
68
|
"error"
|
|
20
69
|
],
|
|
21
|
-
setup(
|
|
22
|
-
let
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
70
|
+
setup(t, { emit: n }) {
|
|
71
|
+
let a = t, o = n, c = computed(() => getLocaleMessages(a.locale)), l = computed(() => new cppay_default(a.apikey, a.ott)), f = ref("select"), p = ref(!1), m = computed(() => f.value === "checking"), g = ref(), _ = ref([]), v = ref(), y = ref(), b = ref(), x = ref(), S = ref(!1), C = ref(), w = ref(""), T = ref(!1), E = ref(!1), D = shallowRef(null), O = ref(null), k = ref(null), A = ref(null), j = ref(""), M = () => {
|
|
72
|
+
typeof window < "u" && !D.value && (D.value = createAppKit({
|
|
73
|
+
debug: !1,
|
|
74
|
+
enableNetworkSwitch: !1,
|
|
75
|
+
adapters: [new EthersAdapter()],
|
|
76
|
+
projectId: "8d2e1854d3f1782e45aa15fbd8938894",
|
|
77
|
+
allowUnsupportedChain: !0,
|
|
78
|
+
networks: [
|
|
79
|
+
mainnet,
|
|
80
|
+
bsc,
|
|
81
|
+
polygon,
|
|
82
|
+
arbitrum,
|
|
83
|
+
optimism,
|
|
84
|
+
base
|
|
85
|
+
],
|
|
86
|
+
metadata: {
|
|
87
|
+
name: "Cppay",
|
|
88
|
+
description: "Cppay Payment Gateway",
|
|
89
|
+
url: window.location.origin,
|
|
90
|
+
icons: ["https://cppay.com/icon.png"]
|
|
91
|
+
},
|
|
92
|
+
features: { analytics: !1 }
|
|
93
|
+
}), x.value = D.value.getAddress(), C.value = D.value.getProvider("eip155"), D.value.subscribeAccount((e) => {
|
|
94
|
+
e.isConnected ? x.value = e.address : (x.value = void 0, C.value = void 0);
|
|
95
|
+
}), D.value.subscribeProviders((e) => {
|
|
96
|
+
C.value = e?.eip155;
|
|
97
|
+
}));
|
|
98
|
+
};
|
|
99
|
+
watch(f, (e) => {
|
|
100
|
+
o("update:paymentStep", e);
|
|
101
|
+
});
|
|
102
|
+
let N = async () => {
|
|
27
103
|
try {
|
|
28
|
-
|
|
29
|
-
} catch (
|
|
30
|
-
|
|
104
|
+
S.value = !0, g.value = void 0, D.value && await D.value.open();
|
|
105
|
+
} catch (e) {
|
|
106
|
+
g.value = e instanceof Error ? e.message : c.value.walletConnectionFailed, o("error", e);
|
|
31
107
|
} finally {
|
|
32
|
-
|
|
108
|
+
S.value = !1;
|
|
33
109
|
}
|
|
34
|
-
},
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
110
|
+
}, P = computed(() => _.value.find((e) => e.chain === v.value)), F = computed(() => P.value?.tokens || []), I = computed(() => F.value.find((e) => e.symbol === y.value)), L = (e) => [
|
|
111
|
+
"USDT",
|
|
112
|
+
"USDC",
|
|
113
|
+
"BUSD",
|
|
114
|
+
"DAI",
|
|
115
|
+
"TUSD",
|
|
116
|
+
"USDD",
|
|
117
|
+
"FDUSD"
|
|
118
|
+
].includes(e.toUpperCase()) ? 2 : 6, R = (e, t) => {
|
|
119
|
+
let n = parseFloat(e);
|
|
120
|
+
return isNaN(n) ? "0" : n.toFixed(t).replace(/\.?0+$/, "");
|
|
121
|
+
}, z = (e) => {
|
|
122
|
+
if (e <= 0) return c.value.expired;
|
|
123
|
+
let t = Math.floor(e / 3600), n = Math.floor(e % 3600 / 60), r = e % 60, i = (e) => e.toString().padStart(2, "0");
|
|
124
|
+
return t > 0 ? `${t}:${i(n)}:${i(r)}` : `${n}:${i(r)}`;
|
|
125
|
+
}, B = (e) => {
|
|
126
|
+
k.value && clearInterval(k.value);
|
|
127
|
+
let t = () => {
|
|
128
|
+
if (f.value === "checking") {
|
|
129
|
+
V();
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
let t = e - Math.floor(Date.now() / 1e3);
|
|
133
|
+
w.value = z(t), t <= 0 && V();
|
|
134
|
+
};
|
|
135
|
+
t(), k.value = setInterval(t, 1e3);
|
|
136
|
+
}, V = () => {
|
|
137
|
+
k.value &&= (clearInterval(k.value), null);
|
|
138
|
+
}, H = computed(() => {
|
|
139
|
+
if (!y.value || !I.value) return "0";
|
|
140
|
+
let e = parseFloat(I.value.price);
|
|
141
|
+
if (isNaN(e) || e === 0) return "0";
|
|
142
|
+
let t = L(y.value);
|
|
143
|
+
return R((parseFloat(a.amount) / e).toFixed(t), t);
|
|
144
|
+
}), U = async () => {
|
|
145
|
+
try {
|
|
146
|
+
p.value = !0, g.value = void 0, _.value = await l.value.getSupportedChains(), _.value.length > 0 && (v.value = _.value[0].chain);
|
|
147
|
+
} catch (e) {
|
|
148
|
+
g.value = e instanceof Error ? e.message : c.value.loadPaymentNetworkFailed, o("error", e);
|
|
50
149
|
} finally {
|
|
51
|
-
|
|
150
|
+
p.value = !1;
|
|
52
151
|
}
|
|
53
|
-
},
|
|
54
|
-
if (
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
152
|
+
}, W = async (e) => {
|
|
153
|
+
if (C.value) try {
|
|
154
|
+
await C.value.request({
|
|
155
|
+
method: "wallet_switchEthereumChain",
|
|
156
|
+
params: [{ chainId: `0x${e.toString(16)}` }]
|
|
157
|
+
});
|
|
158
|
+
} catch (e) {
|
|
159
|
+
throw e.code === 4902 ? Error(c.value.pleaseAddNetwork) : e;
|
|
160
|
+
}
|
|
161
|
+
}, G = async () => {
|
|
162
|
+
if (!(!x.value || !C.value || !A.value || !I.value || !P.value)) try {
|
|
163
|
+
p.value = !0;
|
|
164
|
+
let e = A.value;
|
|
165
|
+
await W(P.value.chainId);
|
|
166
|
+
let t = createWalletClient({
|
|
167
|
+
account: x.value,
|
|
168
|
+
transport: custom(C.value)
|
|
169
|
+
});
|
|
170
|
+
if (I.value.address) {
|
|
171
|
+
let n = await t.writeContract({
|
|
172
|
+
address: I.value.address,
|
|
173
|
+
abi: [{
|
|
174
|
+
name: "transfer",
|
|
175
|
+
type: "function",
|
|
176
|
+
stateMutability: "nonpayable",
|
|
177
|
+
inputs: [{
|
|
178
|
+
name: "to",
|
|
179
|
+
type: "address"
|
|
180
|
+
}, {
|
|
181
|
+
name: "amount",
|
|
182
|
+
type: "uint256"
|
|
183
|
+
}],
|
|
184
|
+
outputs: [{ type: "bool" }]
|
|
185
|
+
}],
|
|
186
|
+
functionName: "transfer",
|
|
187
|
+
args: [e.receiveAddress, parseUnits(e.paymentAmount, I.value.decimals)],
|
|
188
|
+
chain: null
|
|
189
|
+
});
|
|
190
|
+
console.log("转账交易哈希:", n), j.value = n;
|
|
191
|
+
} else {
|
|
192
|
+
let n = await t.sendTransaction({
|
|
193
|
+
to: e.receiveAddress,
|
|
194
|
+
value: parseUnits(e.paymentAmount, I.value.decimals),
|
|
195
|
+
chain: null
|
|
196
|
+
});
|
|
197
|
+
console.log("转账交易哈希:", n), j.value = n;
|
|
198
|
+
}
|
|
199
|
+
p.value = !1, f.value = "checking", X({ paymentId: e.paymentId });
|
|
200
|
+
} catch (e) {
|
|
201
|
+
console.error("钱包支付失败:", e), g.value = e instanceof Error ? e.message : c.value.walletPaymentFailed, o("error", e), p.value = !1;
|
|
202
|
+
}
|
|
203
|
+
}, K = async () => {
|
|
204
|
+
if (!(!x.value || !C.value || !A.value || !I.value || !P.value)) try {
|
|
205
|
+
let e = A.value;
|
|
206
|
+
await W(P.value.chainId);
|
|
207
|
+
let t = createWalletClient({
|
|
208
|
+
account: x.value,
|
|
209
|
+
transport: custom(C.value)
|
|
210
|
+
});
|
|
211
|
+
if (!I.value.address) throw Error(c.value.subscriptionDoesNotSupportNative);
|
|
212
|
+
let n = await t.writeContract({
|
|
213
|
+
address: I.value.address,
|
|
214
|
+
abi: [{
|
|
215
|
+
name: "approve",
|
|
216
|
+
type: "function",
|
|
217
|
+
stateMutability: "nonpayable",
|
|
218
|
+
inputs: [{
|
|
219
|
+
name: "spender",
|
|
220
|
+
type: "address"
|
|
221
|
+
}, {
|
|
222
|
+
name: "amount",
|
|
223
|
+
type: "uint256"
|
|
224
|
+
}],
|
|
225
|
+
outputs: [{ type: "bool" }]
|
|
226
|
+
}],
|
|
227
|
+
functionName: "approve",
|
|
228
|
+
args: [e.spenderAddress, parseUnits(e.approveAmount, I.value.decimals)],
|
|
229
|
+
chain: null
|
|
230
|
+
});
|
|
231
|
+
console.log("授权交易哈希:", n), j.value = n, p.value = !1, f.value = "checking", X({ subscriptionId: e.subscriptionId });
|
|
232
|
+
} catch (e) {
|
|
233
|
+
console.error("钱包授权失败:", e), g.value = e instanceof Error ? e.message : c.value.walletPaymentFailed, o("error", e), p.value = !1;
|
|
234
|
+
}
|
|
235
|
+
}, q = async () => {
|
|
236
|
+
if (!x.value) {
|
|
237
|
+
g.value = c.value.pleaseConnectWallet, o("error", Error(c.value.pleaseConnectWallet));
|
|
238
|
+
return;
|
|
239
|
+
}
|
|
240
|
+
a.plain === "instant" ? await G() : a.plain === "subscription" && await K();
|
|
241
|
+
}, J = async () => {
|
|
242
|
+
if (!(!v.value || !y.value)) try {
|
|
243
|
+
g.value = void 0;
|
|
244
|
+
let e = "";
|
|
245
|
+
if (a.plain === "instant") A.value = await l.value.createOnetimePayment({
|
|
246
|
+
paymentChain: v.value,
|
|
247
|
+
paymentToken: y.value,
|
|
248
|
+
orderId: a.orderId,
|
|
249
|
+
amount: H.value,
|
|
250
|
+
remark: a.remark
|
|
251
|
+
}), e = `${v.value.toLowerCase()}:${A.value.receiveAddress}?amount=${A.value.paymentAmount}`, B(A.value.expireAt), Z(A.value.paymentId, "instant");
|
|
252
|
+
else if (a.plain === "subscription") {
|
|
253
|
+
if (!a.intervalDays) throw Error(`Invalid Renewal Days: ${a.intervalDays ?? ""}`);
|
|
254
|
+
A.value = await l.value.createSubscriptionPayment({
|
|
255
|
+
paymentChain: v.value,
|
|
256
|
+
paymentToken: y.value,
|
|
257
|
+
orderId: a.orderId,
|
|
258
|
+
amountOfUsd: H.value,
|
|
259
|
+
intervalDays: a.intervalDays
|
|
260
|
+
}), e = `${v.value.toLowerCase()}:${A.value.spenderAddress}?amount=${A.value.approveAmount}`, B(A.value.expireAt), Z(A.value.subscriptionId, "subscription");
|
|
261
|
+
}
|
|
262
|
+
f.value = "payment", b.value = await QRCode.toDataURL(e, {
|
|
263
|
+
width: 200,
|
|
264
|
+
margin: 2,
|
|
265
|
+
errorCorrectionLevel: "H"
|
|
266
|
+
});
|
|
267
|
+
} catch (e) {
|
|
268
|
+
g.value = e instanceof Error ? e.message : c.value.createPaymentFailed, o("error", e);
|
|
269
|
+
}
|
|
270
|
+
}, Y = () => {
|
|
271
|
+
A.value && (g.value = void 0, f.value = "checking", a.plain === "instant" ? X({ paymentId: A.value.paymentId }) : a.plain === "subscription" && X({ subscriptionId: A.value.subscriptionId }));
|
|
272
|
+
}, X = (e) => {
|
|
273
|
+
O.value?.unsubscribe();
|
|
274
|
+
let t = () => defer(() => a.plain === "subscription" ? l.value.checkSubscriptionPaymentStatus(e) : l.value.checkOnetimePaymentStatus(e)).pipe(timeout(15e3), retry({ delay: 2e3 }));
|
|
275
|
+
O.value = t().pipe(expand((e) => e.status === "pending" ? timer(2e3).pipe(switchMap(() => t())) : EMPTY), tap((e) => {
|
|
276
|
+
if (!A.value && a.plain === "instant") {
|
|
277
|
+
let t = e;
|
|
278
|
+
A.value = {
|
|
279
|
+
paymentId: t.paymentId,
|
|
280
|
+
orderId: t.orderId,
|
|
281
|
+
paymentChain: t.chain,
|
|
282
|
+
paymentToken: t.token,
|
|
283
|
+
paymentAmount: t.payAmount,
|
|
284
|
+
receiveAddress: t.receiveAddress,
|
|
285
|
+
expireAt: t.expireAt
|
|
286
|
+
}, v.value = t.chain, y.value = t.token, B(t.expireAt);
|
|
287
|
+
let n = `${t.chain.toLowerCase()}:${t.receiveAddress}?amount=${t.payAmount}`;
|
|
288
|
+
QRCode.toDataURL(n, {
|
|
289
|
+
width: 200,
|
|
290
|
+
margin: 2,
|
|
291
|
+
errorCorrectionLevel: "H"
|
|
292
|
+
}).then((e) => {
|
|
293
|
+
b.value = e, f.value = "payment";
|
|
294
|
+
}).catch((e) => {
|
|
295
|
+
console.error("生成二维码失败:", e), f.value = "select";
|
|
296
|
+
});
|
|
297
|
+
}
|
|
298
|
+
if (!A.value && a.plain === "subscription") {
|
|
299
|
+
let t = e;
|
|
300
|
+
A.value = {
|
|
301
|
+
subscriptionId: t.subscriptionId,
|
|
302
|
+
orderId: t.orderId,
|
|
303
|
+
paymentChain: t.chain,
|
|
304
|
+
paymentToken: t.token,
|
|
305
|
+
approveAmount: t.approveAmount,
|
|
306
|
+
spenderAddress: t.approvedAddress,
|
|
307
|
+
expireAt: t.expireAt,
|
|
308
|
+
intervalDays: 0,
|
|
309
|
+
amountOfUsd: t.amountOfUsd
|
|
310
|
+
}, v.value = t.chain, y.value = t.token, B(t.expireAt);
|
|
311
|
+
let n = `${t.chain.toLowerCase()}:${t.approvedAddress}?amount=${t.approveAmount}`;
|
|
312
|
+
QRCode.toDataURL(n, {
|
|
313
|
+
width: 200,
|
|
314
|
+
margin: 2,
|
|
315
|
+
errorCorrectionLevel: "H"
|
|
316
|
+
}).then((e) => {
|
|
317
|
+
b.value = e, f.value = "payment";
|
|
318
|
+
}).catch((e) => {
|
|
319
|
+
console.error("生成二维码失败:", e), f.value = "select";
|
|
320
|
+
});
|
|
321
|
+
}
|
|
322
|
+
(e.status === "paid" || e.status === "approved") && (f.value = "success", Q(), o("success", e)), e.status === "expired" && (f.value = "expired", Q(), o("expired", e)), e.status === "failed" && (f.value = "failed", Q(), o("failed", e));
|
|
323
|
+
})).subscribe({
|
|
324
|
+
error: (e) => {
|
|
325
|
+
if (A.value) {
|
|
326
|
+
let t = e instanceof Error ? e.message : c.value.checkPaymentStatusFailed;
|
|
327
|
+
f.value = "error", g.value = t, Q(), o("error", e);
|
|
328
|
+
}
|
|
329
|
+
},
|
|
330
|
+
complete: () => {
|
|
331
|
+
O.value?.unsubscribe();
|
|
332
|
+
}
|
|
333
|
+
});
|
|
334
|
+
}, bn = async () => {
|
|
335
|
+
if (!A.value) return;
|
|
336
|
+
let e = a.plain === "subscription" ? A.value.spenderAddress : A.value.receiveAddress;
|
|
337
|
+
if (e) try {
|
|
338
|
+
await navigator.clipboard.writeText(e), T.value = !0, setTimeout(() => {
|
|
339
|
+
T.value = !1;
|
|
340
|
+
}, 2e3);
|
|
341
|
+
} catch (e) {
|
|
342
|
+
console.error("复制失败:", e);
|
|
343
|
+
}
|
|
344
|
+
};
|
|
345
|
+
watch(F, (e) => {
|
|
346
|
+
e.length > 0 && (y.value = e[0].symbol);
|
|
347
|
+
}), onMounted(() => {
|
|
348
|
+
M(), _.value.length || U(), $();
|
|
349
|
+
}), onUnmounted(() => {
|
|
350
|
+
O.value?.unsubscribe(), V();
|
|
351
|
+
});
|
|
352
|
+
let xn = async () => {
|
|
353
|
+
if (j.value) try {
|
|
354
|
+
await navigator.clipboard.writeText(j.value);
|
|
355
|
+
let e = T.value;
|
|
356
|
+
T.value = !0, setTimeout(() => {
|
|
357
|
+
T.value = e;
|
|
358
|
+
}, 2e3);
|
|
359
|
+
} catch (e) {
|
|
360
|
+
console.error("复制失败:", e);
|
|
60
361
|
}
|
|
362
|
+
}, Z = (e, t) => {
|
|
363
|
+
if (!a.ott || typeof window > "u") return;
|
|
364
|
+
let n = new URL(window.location.href), r = t === "subscription" ? "subscriptionId" : "paymentId";
|
|
365
|
+
n.searchParams.set(r, e), window.history.replaceState({}, "", n.toString());
|
|
366
|
+
}, Q = () => {
|
|
367
|
+
if (typeof window > "u") return;
|
|
368
|
+
let e = new URL(window.location.href);
|
|
369
|
+
e.searchParams.delete("paymentId"), e.searchParams.delete("subscriptionId"), window.history.replaceState({}, "", e.toString());
|
|
61
370
|
}, $ = async () => {
|
|
62
|
-
|
|
371
|
+
if (typeof window > "u") return;
|
|
372
|
+
let e = new URL(window.location.href);
|
|
373
|
+
if (a.plain === "instant") {
|
|
374
|
+
let t = e.searchParams.get("paymentId");
|
|
375
|
+
t && (f.value = "payment", X({ paymentId: t }));
|
|
376
|
+
}
|
|
377
|
+
if (a.plain === "subscription") {
|
|
378
|
+
let t = e.searchParams.get("subscriptionId");
|
|
379
|
+
t && (f.value = "payment", X({ subscriptionId: t }));
|
|
380
|
+
}
|
|
63
381
|
};
|
|
64
|
-
return
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
382
|
+
return (e, n) => (openBlock(), createElementBlock("div", _hoisted_1$1, [f.value === "success" ? renderSlot(e.$slots, "success", { key: 0 }, () => [createElementVNode("div", _hoisted_2$1, [
|
|
383
|
+
n[9] ||= createElementVNode("div", { class: "_cppay-state-success-bg" }, [createElementVNode("div", { class: "_cppay-state-success-icon" }, "✓")], -1),
|
|
384
|
+
createElementVNode("h3", _hoisted_3$1, toDisplayString(t.plain === "subscription" ? c.value.authorizationSuccess : c.value.paymentSuccess), 1),
|
|
385
|
+
j.value ? (openBlock(), createElementBlock("div", _hoisted_4$1, [createElementVNode("div", _hoisted_5, toDisplayString(c.value.transactionHash), 1), createElementVNode("div", _hoisted_6, [createElementVNode("code", _hoisted_7, toDisplayString(j.value), 1), createElementVNode("button", {
|
|
386
|
+
onClick: xn,
|
|
387
|
+
class: "_cppay-state-copy-btn",
|
|
388
|
+
title: c.value.copyAddress
|
|
389
|
+
}, [...n[8] ||= [createElementVNode("svg", {
|
|
390
|
+
viewBox: "0 0 24 24",
|
|
391
|
+
fill: "none",
|
|
392
|
+
stroke: "currentColor",
|
|
393
|
+
"stroke-width": "2"
|
|
394
|
+
}, [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", {
|
|
395
|
+
x: "8",
|
|
396
|
+
y: "2",
|
|
397
|
+
width: "8",
|
|
398
|
+
height: "4",
|
|
399
|
+
rx: "1",
|
|
400
|
+
ry: "1"
|
|
401
|
+
})], -1)]], 8, _hoisted_8)])])) : createCommentVNode("", !0),
|
|
402
|
+
A.value ? (openBlock(), createElementBlock("div", _hoisted_9, [
|
|
403
|
+
createElementVNode("div", _hoisted_10, [createElementVNode("span", _hoisted_11, toDisplayString(c.value.orderId), 1), createElementVNode("span", _hoisted_12, toDisplayString(A.value.orderId), 1)]),
|
|
404
|
+
createElementVNode("div", _hoisted_13, [createElementVNode("span", _hoisted_14, toDisplayString(t.plain === "subscription" ? c.value.authorizationAmount : c.value.paymentAmount), 1), createElementVNode("span", _hoisted_15, toDisplayString(t.plain === "subscription" ? `${R(A.value.approveAmount, L(y.value))} ${y.value}` : `${R(A.value.paymentAmount, L(y.value))} ${y.value}`), 1)]),
|
|
405
|
+
createElementVNode("div", _hoisted_16, [createElementVNode("span", _hoisted_17, toDisplayString(c.value.paymentNetwork), 1), createElementVNode("span", _hoisted_18, toDisplayString(A.value.paymentChain), 1)]),
|
|
406
|
+
createElementVNode("div", _hoisted_19, [createElementVNode("span", _hoisted_20, toDisplayString(c.value.paymentToken), 1), createElementVNode("span", _hoisted_21, toDisplayString(A.value.paymentToken), 1)]),
|
|
407
|
+
t.plain === "subscription" ? (openBlock(), createElementBlock("div", _hoisted_22, [createElementVNode("span", _hoisted_23, toDisplayString(c.value.renewalInterval), 1), createElementVNode("span", _hoisted_24, toDisplayString(A.value.intervalDays) + " " + toDisplayString(c.value.days), 1)])) : createCommentVNode("", !0),
|
|
408
|
+
createElementVNode("div", _hoisted_25, [createElementVNode("span", _hoisted_26, toDisplayString(t.plain === "subscription" ? c.value.subscriptionId : c.value.paymentId), 1), createElementVNode("span", _hoisted_27, toDisplayString(t.plain === "subscription" ? A.value.subscriptionId : A.value.paymentId), 1)])
|
|
409
|
+
])) : createCommentVNode("", !0)
|
|
410
|
+
])]) : f.value === "expired" ? renderSlot(e.$slots, "expired", { key: 1 }, () => [createElementVNode("div", _hoisted_28, [
|
|
411
|
+
n[10] ||= createElementVNode("div", { class: "_cppay-state-expired-bg" }, [createElementVNode("div", { class: "_cppay-state-expired-icon" }, "⏰")], -1),
|
|
412
|
+
createElementVNode("h3", _hoisted_29, toDisplayString(c.value.paymentExpired), 1),
|
|
413
|
+
createElementVNode("p", _hoisted_30, toDisplayString(c.value.pleaseInitiatePaymentAgain), 1),
|
|
414
|
+
createElementVNode("button", {
|
|
415
|
+
onClick: n[0] ||= () => {
|
|
416
|
+
f.value = "select", Q();
|
|
417
|
+
},
|
|
418
|
+
disabled: p.value || m.value,
|
|
419
|
+
class: "_cppay-btn _cppay-btn-primary _cppay-state-btn"
|
|
420
|
+
}, toDisplayString(c.value.returnButton), 9, _hoisted_31)
|
|
421
|
+
])]) : f.value === "error" ? renderSlot(e.$slots, "error", { key: 2 }, () => [createElementVNode("div", _hoisted_32, [
|
|
422
|
+
n[11] ||= createElementVNode("div", { class: "_cppay-state-error-bg" }, [createElementVNode("div", { class: "_cppay-state-error-icon" }, "!")], -1),
|
|
423
|
+
createElementVNode("h3", _hoisted_33, toDisplayString(g.value || c.value.error), 1),
|
|
424
|
+
createElementVNode("p", _hoisted_34, toDisplayString(c.value.checkStatusFailed), 1),
|
|
425
|
+
createElementVNode("button", {
|
|
426
|
+
onClick: n[1] ||= () => {
|
|
427
|
+
f.value = "select", Q();
|
|
428
|
+
},
|
|
429
|
+
disabled: p.value || m.value,
|
|
430
|
+
class: "_cppay-btn _cppay-btn-primary _cppay-state-btn"
|
|
431
|
+
}, toDisplayString(c.value.returnButton), 9, _hoisted_35)
|
|
432
|
+
])]) : f.value === "failed" ? renderSlot(e.$slots, "failed", { key: 3 }, () => [createElementVNode("div", _hoisted_36, [
|
|
433
|
+
n[12] ||= createElementVNode("div", { class: "_cppay-state-failed-bg" }, [createElementVNode("div", { class: "_cppay-state-failed-icon" }, "✕")], -1),
|
|
434
|
+
createElementVNode("h3", _hoisted_37, toDisplayString(c.value.paymentFailed), 1),
|
|
435
|
+
createElementVNode("p", _hoisted_38, toDisplayString(c.value.pleaseInitiatePaymentAgain), 1),
|
|
436
|
+
createElementVNode("button", {
|
|
437
|
+
onClick: n[2] ||= () => {
|
|
438
|
+
f.value = "select", Q();
|
|
439
|
+
},
|
|
440
|
+
disabled: p.value || m.value,
|
|
441
|
+
class: "_cppay-btn _cppay-btn-primary _cppay-state-btn"
|
|
442
|
+
}, toDisplayString(c.value.returnButton), 9, _hoisted_39)
|
|
443
|
+
])]) : f.value === "select" ? (openBlock(), createElementBlock("div", _hoisted_40, [
|
|
444
|
+
renderSlot(e.$slots, "choose-top"),
|
|
445
|
+
createElementVNode("div", _hoisted_41, [createElementVNode("label", _hoisted_42, toDisplayString(c.value.paymentNetwork), 1), createElementVNode("div", _hoisted_43, [(openBlock(!0), createElementBlock(Fragment, null, renderList(_.value, (e) => (openBlock(), createElementBlock("button", {
|
|
446
|
+
key: e.chain,
|
|
447
|
+
onClick: (t) => v.value = e.chain,
|
|
448
|
+
class: normalizeClass(["_cppay-select-btn", { "_cppay-selected": v.value === e.chain }])
|
|
449
|
+
}, [e.icon ? (openBlock(), createElementBlock("img", {
|
|
450
|
+
key: 0,
|
|
451
|
+
src: e.icon,
|
|
452
|
+
alt: e.chain
|
|
453
|
+
}, null, 8, _hoisted_45)) : createCommentVNode("", !0), createElementVNode("span", null, toDisplayString(e.chain), 1)], 10, _hoisted_44))), 128))])]),
|
|
454
|
+
createElementVNode("div", _hoisted_46, [createElementVNode("label", _hoisted_47, toDisplayString(c.value.paymentToken), 1), createElementVNode("div", _hoisted_48, [(openBlock(!0), createElementBlock(Fragment, null, renderList(F.value, (e) => (openBlock(), createElementBlock("button", {
|
|
455
|
+
key: e.symbol,
|
|
456
|
+
onClick: (t) => y.value = e.symbol,
|
|
457
|
+
class: normalizeClass(["_cppay-select-btn", { "_cppay-selected": y.value === e.symbol }])
|
|
458
|
+
}, [e.icon ? (openBlock(), createElementBlock("img", {
|
|
70
459
|
key: 0,
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
},
|
|
460
|
+
src: e.icon,
|
|
461
|
+
alt: e.symbol
|
|
462
|
+
}, null, 8, _hoisted_50)) : createCommentVNode("", !0), createElementVNode("span", null, toDisplayString(e.symbol), 1)], 10, _hoisted_49))), 128))])]),
|
|
463
|
+
renderSlot(e.$slots, "choose-bottom"),
|
|
464
|
+
createElementVNode("div", _hoisted_51, [createElementVNode("div", _hoisted_52, [createElementVNode("div", _hoisted_53, [createElementVNode("span", _hoisted_54, toDisplayString(c.value.paymentAmount), 1), createElementVNode("div", _hoisted_55, [createElementVNode("div", _hoisted_56, toDisplayString(H.value ?? "-") + " " + toDisplayString(y.value ?? ""), 1), createElementVNode("div", _hoisted_57, "≈ $" + toDisplayString(t.amount), 1)])])])]),
|
|
465
|
+
createElementVNode("div", _hoisted_58, [g.value ? (openBlock(), createElementBlock("div", {
|
|
466
|
+
key: 0,
|
|
467
|
+
class: "_cppay-error-tooltip-wrapper",
|
|
468
|
+
onMouseenter: n[3] ||= (e) => E.value = !0,
|
|
469
|
+
onMouseleave: n[4] ||= (e) => E.value = !1
|
|
470
|
+
}, [createElementVNode("div", _hoisted_59, [n[13] ||= createElementVNode("svg", {
|
|
471
|
+
viewBox: "0 0 20 20",
|
|
472
|
+
fill: "currentColor"
|
|
473
|
+
}, [createElementVNode("path", {
|
|
474
|
+
"fill-rule": "evenodd",
|
|
475
|
+
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",
|
|
476
|
+
"clip-rule": "evenodd"
|
|
477
|
+
})], -1), createElementVNode("span", null, toDisplayString(g.value), 1)]), E.value ? (openBlock(), createElementBlock("div", _hoisted_60, toDisplayString(g.value), 1)) : createCommentVNode("", !0)], 32)) : createCommentVNode("", !0), createElementVNode("button", {
|
|
478
|
+
onClick: J,
|
|
479
|
+
disabled: !v.value || !y.value || p.value,
|
|
480
|
+
class: "_cppay-btn _cppay-btn-primary"
|
|
481
|
+
}, toDisplayString(p.value ? c.value.processing : c.value.continuePayment), 9, _hoisted_61)])
|
|
482
|
+
])) : (openBlock(), createElementBlock("div", _hoisted_62, [
|
|
483
|
+
createElementVNode("div", _hoisted_63, [createElementVNode("div", _hoisted_64, [b.value ? (openBlock(), createElementBlock("img", {
|
|
484
|
+
key: 0,
|
|
485
|
+
src: b.value,
|
|
486
|
+
alt: "Payment QR Code",
|
|
487
|
+
class: "_cppay-qr-image"
|
|
488
|
+
}, null, 8, _hoisted_65)) : createCommentVNode("", !0)])]),
|
|
489
|
+
createElementVNode("div", _hoisted_66, [
|
|
490
|
+
I.value ? (openBlock(), createElementBlock("div", _hoisted_67, [createElementVNode("div", _hoisted_68, [createElementVNode("div", _hoisted_69, [createElementVNode("div", _hoisted_70, toDisplayString(t.plain === "subscription" ? c.value.authorizationAmount : c.value.paymentAmount), 1), createElementVNode("div", _hoisted_71, [A.value ? (openBlock(), createElementBlock("span", _hoisted_72, toDisplayString(t.plain === "subscription" ? `${R(A.value.approveAmount, L(I.value.symbol))} ${I.value.symbol}` : `${R(A.value.paymentAmount, L(I.value.symbol))} ${I.value.symbol}`), 1)) : createCommentVNode("", !0), createElementVNode("span", null, "≈ $" + toDisplayString(t.amount), 1)])])])])) : createCommentVNode("", !0),
|
|
491
|
+
createElementVNode("div", _hoisted_73, [createElementVNode("div", _hoisted_74, [createElementVNode("div", _hoisted_75, [createElementVNode("span", null, toDisplayString(t.plain === "subscription" ? c.value.authorizationContractAddress : c.value.paymentAddress), 1), w.value ? (openBlock(), createElementBlock("span", _hoisted_76, "⏰ " + toDisplayString(w.value), 1)) : createCommentVNode("", !0)]), createElementVNode("div", _hoisted_77, [A.value ? (openBlock(), createElementBlock("code", _hoisted_78, toDisplayString(t.plain === "subscription" ? A.value.spenderAddress : A.value.receiveAddress), 1)) : createCommentVNode("", !0), createElementVNode("button", {
|
|
492
|
+
onClick: bn,
|
|
493
|
+
class: normalizeClass(["_cppay-copy-btn", { "_cppay-copy-success": T.value }]),
|
|
494
|
+
title: T.value ? c.value.copied : c.value.copyAddress
|
|
495
|
+
}, [T.value ? (openBlock(), createElementBlock("svg", _hoisted_81, [...n[15] ||= [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_80, [...n[14] ||= [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", {
|
|
496
|
+
x: "8",
|
|
497
|
+
y: "2",
|
|
498
|
+
width: "8",
|
|
499
|
+
height: "4",
|
|
500
|
+
rx: "1",
|
|
501
|
+
ry: "1"
|
|
502
|
+
}, null, -1)]]))], 10, _hoisted_79)])])]),
|
|
503
|
+
t.plain === "subscription" ? (openBlock(), createElementBlock("div", _hoisted_82, [createElementVNode("div", _hoisted_83, toDisplayString(c.value.subscriptionNotice), 1), createElementVNode("div", _hoisted_84, toDisplayString(c.value.subscriptionNoticeMessage), 1)])) : createCommentVNode("", !0)
|
|
504
|
+
]),
|
|
505
|
+
g.value ? (openBlock(), createElementBlock("div", {
|
|
506
|
+
key: 0,
|
|
507
|
+
class: "_cppay-error-tooltip-wrapper",
|
|
508
|
+
onMouseenter: n[5] ||= (e) => E.value = !0,
|
|
509
|
+
onMouseleave: n[6] ||= (e) => E.value = !1
|
|
510
|
+
}, [createElementVNode("div", _hoisted_85, [n[16] ||= createElementVNode("svg", {
|
|
511
|
+
viewBox: "0 0 20 20",
|
|
512
|
+
fill: "currentColor"
|
|
513
|
+
}, [createElementVNode("path", {
|
|
514
|
+
"fill-rule": "evenodd",
|
|
515
|
+
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",
|
|
516
|
+
"clip-rule": "evenodd"
|
|
517
|
+
})], -1), createElementVNode("span", null, toDisplayString(g.value), 1)]), E.value ? (openBlock(), createElementBlock("div", _hoisted_86, toDisplayString(g.value), 1)) : createCommentVNode("", !0)], 32)) : createCommentVNode("", !0),
|
|
518
|
+
m.value ? createCommentVNode("", !0) : (openBlock(), createElementBlock("div", _hoisted_87, [x.value ? (openBlock(), createElementBlock(Fragment, { key: 1 }, [createElementVNode("button", {
|
|
519
|
+
onClick: q,
|
|
520
|
+
disabled: p.value,
|
|
521
|
+
class: "_cppay-btn _cppay-btn-primary"
|
|
522
|
+
}, toDisplayString(p.value ? t.plain === "subscription" ? c.value.authorizing : c.value.processing : (t.plain, c.value.walletPay)), 9, _hoisted_89), createElementVNode("button", {
|
|
523
|
+
onClick: N,
|
|
524
|
+
disabled: p.value,
|
|
525
|
+
class: "_cppay-btn _cppay-wallet-address-btn",
|
|
526
|
+
title: c.value.clickToModifyWallet
|
|
527
|
+
}, [createElementVNode("span", _hoisted_91, toDisplayString(x.value.slice(0, 10)) + "..." + toDisplayString(x.value.slice(-4)), 1), n[17] ||= createElementVNode("svg", {
|
|
528
|
+
class: "_cppay-wallet-arrow",
|
|
529
|
+
viewBox: "0 0 24 24",
|
|
530
|
+
fill: "none",
|
|
531
|
+
stroke: "currentColor",
|
|
532
|
+
"stroke-width": "2"
|
|
533
|
+
}, [createElementVNode("polyline", { points: "6 9 12 15 18 9" })], -1)], 8, _hoisted_90)], 64)) : (openBlock(), createElementBlock("button", {
|
|
534
|
+
key: 0,
|
|
535
|
+
onClick: N,
|
|
536
|
+
disabled: S.value,
|
|
537
|
+
class: "_cppay-btn _cppay-btn-secondary _cppay-connect-wallet-btn"
|
|
538
|
+
}, [createElementVNode("span", null, toDisplayString(S.value ? c.value.processing : c.value.connectWallet), 1)], 8, _hoisted_88))])),
|
|
539
|
+
createElementVNode("div", _hoisted_92, [createElementVNode("button", {
|
|
74
540
|
onClick: Y,
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
}, [
|
|
541
|
+
disabled: m.value,
|
|
542
|
+
class: "_cppay-btn _cppay-btn-primary"
|
|
543
|
+
}, [m.value ? (openBlock(), createElementBlock(Fragment, { key: 0 }, [n[18] ||= createElementVNode("svg", {
|
|
544
|
+
class: "_cppay-spinner",
|
|
545
|
+
viewBox: "0 0 24 24",
|
|
78
546
|
fill: "none",
|
|
547
|
+
xmlns: "http://www.w3.org/2000/svg"
|
|
548
|
+
}, [createElementVNode("circle", {
|
|
549
|
+
cx: "12",
|
|
550
|
+
cy: "12",
|
|
551
|
+
r: "10",
|
|
79
552
|
stroke: "currentColor",
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
553
|
+
"stroke-width": "3",
|
|
554
|
+
"stroke-opacity": "0.25"
|
|
555
|
+
}), createElementVNode("path", {
|
|
556
|
+
d: "M12 2a10 10 0 0 1 10 10",
|
|
557
|
+
stroke: "currentColor",
|
|
558
|
+
"stroke-width": "3",
|
|
559
|
+
"stroke-linecap": "round"
|
|
560
|
+
})], -1), createTextVNode(" " + toDisplayString(c.value.checking), 1)], 64)) : (openBlock(), createElementBlock(Fragment, { key: 1 }, [createTextVNode(toDisplayString(c.value.completedPayment), 1)], 64))], 8, _hoisted_93)]),
|
|
561
|
+
n[19] ||= createElementVNode("hr", { class: "_cppay-divider" }, null, -1),
|
|
562
|
+
createElementVNode("div", _hoisted_94, [createElementVNode("button", {
|
|
563
|
+
onClick: n[7] ||= () => {
|
|
564
|
+
f.value = "select", Q();
|
|
565
|
+
},
|
|
566
|
+
disabled: p.value || m.value,
|
|
567
|
+
class: "_cppay-btn _cppay-btn-text"
|
|
568
|
+
}, toDisplayString(c.value.changePaymentMethod), 9, _hoisted_95)])
|
|
569
|
+
]))]));
|
|
570
|
+
}
|
|
571
|
+
}), _hoisted_1 = { class: "_cppay-dialog" }, _hoisted_2 = { class: "_cppay-header" }, _hoisted_3 = { class: "_cppay-title" }, _hoisted_4 = ["disabled"], PaymentDialog_default = /* @__PURE__ */ defineComponent({
|
|
572
|
+
__name: "PaymentDialog",
|
|
573
|
+
props: {
|
|
574
|
+
modelValue: { type: Boolean },
|
|
575
|
+
ott: {},
|
|
576
|
+
apikey: {},
|
|
577
|
+
orderId: {},
|
|
578
|
+
amount: {},
|
|
579
|
+
plain: {},
|
|
580
|
+
intervalDays: {},
|
|
581
|
+
locale: {}
|
|
582
|
+
},
|
|
583
|
+
emits: [
|
|
584
|
+
"update:modelValue",
|
|
585
|
+
"success",
|
|
586
|
+
"expired",
|
|
587
|
+
"failed",
|
|
588
|
+
"error"
|
|
589
|
+
],
|
|
590
|
+
setup(e, { emit: t }) {
|
|
591
|
+
let n = e, i = t, a = computed(() => getLocaleMessages(n.locale)), s = ref("select"), c = computed(() => s.value !== "checking");
|
|
592
|
+
watch(() => n.modelValue, (e) => {
|
|
593
|
+
e || (s.value = "select");
|
|
594
|
+
});
|
|
595
|
+
let l = (e) => {
|
|
596
|
+
s.value = e;
|
|
597
|
+
};
|
|
598
|
+
onMounted(() => {
|
|
599
|
+
let e = (e) => {
|
|
600
|
+
e.key === "Escape" && n.modelValue && !c.value && u();
|
|
601
|
+
};
|
|
602
|
+
return window.addEventListener("keydown", e), () => {
|
|
603
|
+
window.removeEventListener("keydown", e);
|
|
604
|
+
};
|
|
605
|
+
});
|
|
606
|
+
let u = () => {
|
|
607
|
+
c.value && i("update:modelValue", !1);
|
|
608
|
+
}, d = () => {
|
|
609
|
+
switch (s.value) {
|
|
610
|
+
case "success": return a.value.paymentResult;
|
|
611
|
+
case "expired": return a.value.paymentExpired;
|
|
612
|
+
case "failed": return a.value.paymentFailed;
|
|
613
|
+
case "error": return a.value.error;
|
|
614
|
+
case "payment": return a.value.completePayment;
|
|
615
|
+
default: return a.value.selectPaymentMethod;
|
|
616
|
+
}
|
|
617
|
+
};
|
|
618
|
+
return (t, n) => e.modelValue ? (openBlock(), createElementBlock("div", {
|
|
619
|
+
key: 0,
|
|
620
|
+
class: "_cppay-overlay",
|
|
621
|
+
onClick: n[4] ||= (e) => e.target === e.currentTarget && u()
|
|
622
|
+
}, [createElementVNode("div", _hoisted_1, [createElementVNode("div", _hoisted_2, [createElementVNode("h2", _hoisted_3, toDisplayString(d()), 1), createElementVNode("button", {
|
|
623
|
+
onClick: u,
|
|
624
|
+
disabled: !c.value,
|
|
625
|
+
class: "_cppay-close-btn"
|
|
626
|
+
}, [...n[5] ||= [createElementVNode("svg", {
|
|
627
|
+
fill: "none",
|
|
628
|
+
stroke: "currentColor",
|
|
629
|
+
viewBox: "0 0 24 24"
|
|
630
|
+
}, [createElementVNode("path", {
|
|
631
|
+
"stroke-linecap": "round",
|
|
632
|
+
"stroke-linejoin": "round",
|
|
633
|
+
"stroke-width": "2",
|
|
634
|
+
d: "M6 18L18 6M6 6l12 12"
|
|
635
|
+
})], -1)]], 8, _hoisted_4)]), e.modelValue ? (openBlock(), createBlock(PaymentContent_default, {
|
|
636
|
+
key: 0,
|
|
637
|
+
apikey: e.apikey,
|
|
638
|
+
ott: e.ott,
|
|
639
|
+
orderId: e.orderId,
|
|
640
|
+
amount: e.amount,
|
|
641
|
+
plain: e.plain,
|
|
642
|
+
intervalDays: e.intervalDays,
|
|
643
|
+
locale: e.locale,
|
|
644
|
+
"onUpdate:paymentStep": l,
|
|
645
|
+
onSuccess: n[0] ||= (e) => i("success", e),
|
|
646
|
+
onExpired: n[1] ||= (e) => i("expired", e),
|
|
647
|
+
onFailed: n[2] ||= (e) => i("failed", e),
|
|
648
|
+
onError: n[3] ||= (e) => i("error", e)
|
|
649
|
+
}, {
|
|
650
|
+
"choose-top": withCtx(() => [renderSlot(t.$slots, "choose-top")]),
|
|
651
|
+
"choose-bottom": withCtx(() => [renderSlot(t.$slots, "choose-bottom")]),
|
|
652
|
+
success: withCtx(() => [renderSlot(t.$slots, "success")]),
|
|
653
|
+
failed: withCtx(() => [renderSlot(t.$slots, "failed")]),
|
|
654
|
+
error: withCtx(() => [renderSlot(t.$slots, "error")]),
|
|
655
|
+
expired: withCtx(() => [renderSlot(t.$slots, "expired")]),
|
|
656
|
+
_: 3
|
|
657
|
+
}, 8, [
|
|
658
|
+
"apikey",
|
|
659
|
+
"ott",
|
|
660
|
+
"orderId",
|
|
661
|
+
"amount",
|
|
662
|
+
"plain",
|
|
663
|
+
"intervalDays",
|
|
664
|
+
"locale"
|
|
665
|
+
])) : createCommentVNode("", !0)])])) : createCommentVNode("", !0);
|
|
140
666
|
}
|
|
141
|
-
}),
|
|
667
|
+
}), cppayState = ref({
|
|
668
|
+
open: !1,
|
|
669
|
+
options: null
|
|
670
|
+
});
|
|
671
|
+
const showPayment = (e) => {
|
|
672
|
+
cppayState.value.options = e, cppayState.value.open = !0;
|
|
673
|
+
}, closePayment = () => {
|
|
674
|
+
cppayState.value.open = !1;
|
|
675
|
+
};
|
|
676
|
+
var handleClose = () => {
|
|
677
|
+
cppayState.value.open = !1;
|
|
678
|
+
}, handleSuccess = (e) => {
|
|
679
|
+
cppayState.value.options?.onSuccess?.(e);
|
|
680
|
+
}, handleExpired = (e) => {
|
|
681
|
+
cppayState.value.options?.onExpired?.(e);
|
|
682
|
+
}, handleFailed = (e) => {
|
|
683
|
+
cppayState.value.options?.onFailed?.(e);
|
|
684
|
+
}, handleError = (e) => {
|
|
685
|
+
cppayState.value.options?.onError?.(e);
|
|
686
|
+
};
|
|
687
|
+
const CppayPlugin = { install(e) {
|
|
688
|
+
e.config.globalProperties.$showPayment = showPayment, e.config.globalProperties.$closePayment = closePayment;
|
|
689
|
+
let t = document.createElement("div");
|
|
690
|
+
document.body.appendChild(t), createApp({ setup() {
|
|
691
|
+
return () => cppayState.value.options ? h(PaymentDialog_default, {
|
|
692
|
+
modelValue: cppayState.value.open,
|
|
693
|
+
"onUpdate:modelValue": (e) => {
|
|
694
|
+
cppayState.value.open = e, e || handleClose();
|
|
695
|
+
},
|
|
696
|
+
...cppayState.value.options,
|
|
697
|
+
onSuccess: handleSuccess,
|
|
698
|
+
onExpired: handleExpired,
|
|
699
|
+
onFailed: handleFailed,
|
|
700
|
+
onError: handleError
|
|
701
|
+
}) : null;
|
|
702
|
+
} }).mount(t);
|
|
703
|
+
} }, useCppayPayment = () => ({
|
|
704
|
+
showPayment,
|
|
705
|
+
closePayment
|
|
706
|
+
});
|
|
142
707
|
injectStyle(payment_dialog_default);
|
|
143
|
-
export { PaymentDialog_default as PaymentDialog };
|
|
708
|
+
export { CppayPlugin, PaymentContent_default as PaymentContent, PaymentDialog_default as PaymentDialog, showPayment, useCppayPayment };
|