cppay-sdk 0.0.2-beta.42 → 0.0.2-beta.44
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/react.cjs +1 -1
- package/dist/react.js +3 -1
- package/dist/vue.cjs +1 -1
- package/dist/vue.js +3 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,3 +1,631 @@
|
|
|
1
|
-
#
|
|
1
|
+
# CPPay SDK
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
CPPay SDK 是一个支持多链加密货币支付的前端 SDK,支持一次性支付和订阅支付。
|
|
4
|
+
|
|
5
|
+
## 📦 安装
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install cppay-sdk
|
|
9
|
+
# 或
|
|
10
|
+
yarn add cppay-sdk
|
|
11
|
+
# 或
|
|
12
|
+
pnpm add cppay-sdk
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## 🚀 快速开始
|
|
16
|
+
|
|
17
|
+
### React 使用
|
|
18
|
+
|
|
19
|
+
#### 方式一:使用 Provider + Hook(推荐)
|
|
20
|
+
|
|
21
|
+
这是最灵活的方式,适合需要在多个组件中调用支付功能的场景。
|
|
22
|
+
|
|
23
|
+
**1. 配置 Provider**
|
|
24
|
+
|
|
25
|
+
```tsx
|
|
26
|
+
// App.tsx
|
|
27
|
+
import { CppayProvider } from "cppay-sdk/react";
|
|
28
|
+
|
|
29
|
+
function App() {
|
|
30
|
+
return (
|
|
31
|
+
<CppayProvider>
|
|
32
|
+
<YourApp />
|
|
33
|
+
</CppayProvider>
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
**2. 使用 Hook 调用支付**
|
|
39
|
+
|
|
40
|
+
```tsx
|
|
41
|
+
// PaymentButton.tsx
|
|
42
|
+
import { useCppayPayment } from "cppay-sdk/react";
|
|
43
|
+
|
|
44
|
+
function PaymentButton() {
|
|
45
|
+
const { showPayment, closePayment } = useCppayPayment();
|
|
46
|
+
|
|
47
|
+
const handlePay = () => {
|
|
48
|
+
showPayment({
|
|
49
|
+
apikey: "your-api-key",
|
|
50
|
+
plain: "instant", // instant | 'subscription'
|
|
51
|
+
orderId: "ORD-0000001",
|
|
52
|
+
amount: "100", // USD
|
|
53
|
+
onSuccess: (order) => {
|
|
54
|
+
console.log("支付成功", order);
|
|
55
|
+
},
|
|
56
|
+
onError: (error) => {
|
|
57
|
+
console.error("支付失败", error);
|
|
58
|
+
},
|
|
59
|
+
onExpired: (order) => {
|
|
60
|
+
console.log("支付已过期", order);
|
|
61
|
+
},
|
|
62
|
+
onFailed: (order) => {
|
|
63
|
+
console.log("支付失败", order);
|
|
64
|
+
},
|
|
65
|
+
});
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
return <button onClick={handlePay}>支付</button>;
|
|
69
|
+
}
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
#### 方式二:使用 PaymentDialog 组件
|
|
73
|
+
|
|
74
|
+
适合需要手动控制弹框显示隐藏的场景。
|
|
75
|
+
|
|
76
|
+
```tsx
|
|
77
|
+
import { useState } from "react";
|
|
78
|
+
import { PaymentDialog } from "cppay-sdk/react";
|
|
79
|
+
|
|
80
|
+
function App() {
|
|
81
|
+
const [open, setOpen] = useState(false);
|
|
82
|
+
|
|
83
|
+
return (
|
|
84
|
+
<>
|
|
85
|
+
<button onClick={() => setOpen(true)}>支付</button>
|
|
86
|
+
|
|
87
|
+
<PaymentDialog
|
|
88
|
+
open={open}
|
|
89
|
+
onClose={() => setOpen(false)}
|
|
90
|
+
apikey="your-api-key"
|
|
91
|
+
plain="instant"
|
|
92
|
+
orderId="order-123"
|
|
93
|
+
amount="100"
|
|
94
|
+
onSuccess={(order) => {
|
|
95
|
+
console.log("支付成功", order);
|
|
96
|
+
setOpen(false);
|
|
97
|
+
}}
|
|
98
|
+
onError={(error) => {
|
|
99
|
+
console.error("支付失败", error);
|
|
100
|
+
}}
|
|
101
|
+
/>
|
|
102
|
+
</>
|
|
103
|
+
);
|
|
104
|
+
}
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
#### 方式三:使用 PaymentContent 组件
|
|
108
|
+
|
|
109
|
+
适合需要自定义页面布局,不使用弹框的场景。
|
|
110
|
+
|
|
111
|
+
```tsx
|
|
112
|
+
import { PaymentContent } from "cppay-sdk/react";
|
|
113
|
+
|
|
114
|
+
function PaymentPage() {
|
|
115
|
+
return (
|
|
116
|
+
<div className="payment-page">
|
|
117
|
+
<h1>支付页面</h1>
|
|
118
|
+
<PaymentContent
|
|
119
|
+
apikey="your-api-key"
|
|
120
|
+
plain="instant"
|
|
121
|
+
orderId="order-123"
|
|
122
|
+
amount="100"
|
|
123
|
+
onSuccess={(order) => {
|
|
124
|
+
console.log("支付成功", order);
|
|
125
|
+
}}
|
|
126
|
+
onError={(error) => {
|
|
127
|
+
console.error("支付失败", error);
|
|
128
|
+
}}
|
|
129
|
+
/>
|
|
130
|
+
</div>
|
|
131
|
+
);
|
|
132
|
+
}
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
---
|
|
136
|
+
|
|
137
|
+
### Vue 使用
|
|
138
|
+
|
|
139
|
+
#### 方式一:使用 Plugin + Composable(推荐)
|
|
140
|
+
|
|
141
|
+
**1. 安装插件**
|
|
142
|
+
|
|
143
|
+
```typescript
|
|
144
|
+
// main.ts
|
|
145
|
+
import { createApp } from "vue";
|
|
146
|
+
import App from "./App.vue";
|
|
147
|
+
import { CppayPlugin } from "cppay-sdk/vue";
|
|
148
|
+
|
|
149
|
+
const app = createApp(App);
|
|
150
|
+
|
|
151
|
+
app.use(CppayPlugin);
|
|
152
|
+
|
|
153
|
+
app.mount("#app");
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
**2. 使用 Composable 调用支付**
|
|
157
|
+
|
|
158
|
+
```vue
|
|
159
|
+
<script setup lang="ts">
|
|
160
|
+
import { useCppayPayment } from "cppay-sdk/vue";
|
|
161
|
+
|
|
162
|
+
const { showPayment, closePayment } = useCppayPayment();
|
|
163
|
+
|
|
164
|
+
const handlePay = () => {
|
|
165
|
+
showPayment({
|
|
166
|
+
apikey: "your-api-key",
|
|
167
|
+
plain: "instant",
|
|
168
|
+
orderId: "order-123",
|
|
169
|
+
amount: "100",
|
|
170
|
+
onSuccess: (order) => {
|
|
171
|
+
console.log("支付成功", order);
|
|
172
|
+
},
|
|
173
|
+
onError: (error) => {
|
|
174
|
+
console.error("支付失败", error);
|
|
175
|
+
},
|
|
176
|
+
});
|
|
177
|
+
};
|
|
178
|
+
</script>
|
|
179
|
+
|
|
180
|
+
<template>
|
|
181
|
+
<button @click="handlePay">支付</button>
|
|
182
|
+
</template>
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
**3. 或使用全局方法**
|
|
186
|
+
|
|
187
|
+
```vue
|
|
188
|
+
<script setup lang="ts">
|
|
189
|
+
import { getCurrentInstance } from "vue";
|
|
190
|
+
|
|
191
|
+
const instance = getCurrentInstance();
|
|
192
|
+
|
|
193
|
+
const handlePay = () => {
|
|
194
|
+
instance?.proxy?.$showPayment({
|
|
195
|
+
apikey: "your-api-key",
|
|
196
|
+
plain: "instant",
|
|
197
|
+
orderId: "order-123",
|
|
198
|
+
amount: "100",
|
|
199
|
+
onSuccess: (order) => {
|
|
200
|
+
console.log("支付成功", order);
|
|
201
|
+
},
|
|
202
|
+
});
|
|
203
|
+
};
|
|
204
|
+
</script>
|
|
205
|
+
|
|
206
|
+
<template>
|
|
207
|
+
<button @click="handlePay">支付</button>
|
|
208
|
+
</template>
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
#### 方式二:使用 PaymentDialog 组件
|
|
212
|
+
|
|
213
|
+
```vue
|
|
214
|
+
<script setup lang="ts">
|
|
215
|
+
import { ref } from "vue";
|
|
216
|
+
import { PaymentDialog } from "cppay-sdk/vue";
|
|
217
|
+
|
|
218
|
+
const dialogOpen = ref(false);
|
|
219
|
+
|
|
220
|
+
const handleSuccess = (order: any) => {
|
|
221
|
+
console.log("支付成功", order);
|
|
222
|
+
dialogOpen.value = false;
|
|
223
|
+
};
|
|
224
|
+
</script>
|
|
225
|
+
|
|
226
|
+
<template>
|
|
227
|
+
<button @click="dialogOpen = true">支付</button>
|
|
228
|
+
|
|
229
|
+
<PaymentDialog
|
|
230
|
+
v-model="dialogOpen"
|
|
231
|
+
apikey="your-api-key"
|
|
232
|
+
plain="instant"
|
|
233
|
+
order-id="order-123"
|
|
234
|
+
amount="100"
|
|
235
|
+
@success="handleSuccess"
|
|
236
|
+
@error="(error) => console.error(error)"
|
|
237
|
+
/>
|
|
238
|
+
</template>
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
#### 方式三:使用 PaymentContent 组件
|
|
242
|
+
|
|
243
|
+
```vue
|
|
244
|
+
<script setup lang="ts">
|
|
245
|
+
import { PaymentContent } from "cppay-sdk/vue";
|
|
246
|
+
|
|
247
|
+
const handleSuccess = (order: any) => {
|
|
248
|
+
console.log("支付成功", order);
|
|
249
|
+
};
|
|
250
|
+
</script>
|
|
251
|
+
|
|
252
|
+
<template>
|
|
253
|
+
<div class="payment-page">
|
|
254
|
+
<h1>支付页面</h1>
|
|
255
|
+
<PaymentContent
|
|
256
|
+
apikey="your-api-key"
|
|
257
|
+
plain="instant"
|
|
258
|
+
order-id="order-123"
|
|
259
|
+
amount="100"
|
|
260
|
+
@success="handleSuccess"
|
|
261
|
+
@error="(error) => console.error(error)"
|
|
262
|
+
/>
|
|
263
|
+
</div>
|
|
264
|
+
</template>
|
|
265
|
+
```
|
|
266
|
+
|
|
267
|
+
---
|
|
268
|
+
|
|
269
|
+
## 🔧 直接使用 API(不使用组件)
|
|
270
|
+
|
|
271
|
+
如果你不想使用我们提供的 UI 组件,可以直接调用底层 API 来实现自定义的支付流程。
|
|
272
|
+
|
|
273
|
+
### 安装和初始化
|
|
274
|
+
|
|
275
|
+
```typescript
|
|
276
|
+
import Cppay from "cppay-sdk";
|
|
277
|
+
|
|
278
|
+
// 使用 API Key 初始化
|
|
279
|
+
const cppay = new Cppay("your-api-key");
|
|
280
|
+
```
|
|
281
|
+
|
|
282
|
+
### 1. 获取支持的链和代币
|
|
283
|
+
|
|
284
|
+
```typescript
|
|
285
|
+
const chains = await cppay.getSupportedChains();
|
|
286
|
+
|
|
287
|
+
console.log(chains);
|
|
288
|
+
// [
|
|
289
|
+
// {
|
|
290
|
+
// chain: 'Ethereum',
|
|
291
|
+
// chainId: 1,
|
|
292
|
+
// icon: 'https://...',
|
|
293
|
+
// tokens: [
|
|
294
|
+
// {
|
|
295
|
+
// symbol: 'USDT',
|
|
296
|
+
// decimals: 6,
|
|
297
|
+
// address: '0x...',
|
|
298
|
+
// icon: 'https://...',
|
|
299
|
+
// price: '1.00'
|
|
300
|
+
// },
|
|
301
|
+
// // ...
|
|
302
|
+
// ]
|
|
303
|
+
// },
|
|
304
|
+
// // ...
|
|
305
|
+
// ]
|
|
306
|
+
```
|
|
307
|
+
|
|
308
|
+
### 2. 创建一次性支付
|
|
309
|
+
|
|
310
|
+
```typescript
|
|
311
|
+
const paymentInfo = await cppay.createOnetimePayment({
|
|
312
|
+
paymentChain: "Ethereum",
|
|
313
|
+
paymentToken: "USDT",
|
|
314
|
+
orderId: "order-123",
|
|
315
|
+
amount: "0.0001", // Token Amount
|
|
316
|
+
remark: "商品购买",
|
|
317
|
+
});
|
|
318
|
+
|
|
319
|
+
console.log(paymentInfo);
|
|
320
|
+
// {
|
|
321
|
+
// orderId: 'order-123',
|
|
322
|
+
// paymentId: 'pay-xxx',
|
|
323
|
+
// paymentAmount: '0.0001',
|
|
324
|
+
// paymentChain: 'Ethereum',
|
|
325
|
+
// paymentToken: 'USDT',
|
|
326
|
+
// receiveAddress: '0x...',
|
|
327
|
+
// expireAt: 1234567890
|
|
328
|
+
// }
|
|
329
|
+
```
|
|
330
|
+
|
|
331
|
+
### 3. 创建订阅支付
|
|
332
|
+
|
|
333
|
+
```typescript
|
|
334
|
+
const subscriptionInfo = await cppay.createSubscriptionPayment({
|
|
335
|
+
paymentChain: "BSC",
|
|
336
|
+
paymentToken: "USDT",
|
|
337
|
+
orderId: "subscription-123",
|
|
338
|
+
amountOfUsd: "9.99",
|
|
339
|
+
intervalDays: 30,
|
|
340
|
+
});
|
|
341
|
+
|
|
342
|
+
console.log(subscriptionInfo);
|
|
343
|
+
// {
|
|
344
|
+
// orderId: 'subscription-123',
|
|
345
|
+
// subscriptionId: 'sub-xxx',
|
|
346
|
+
// approveAmount: '299.70',
|
|
347
|
+
// spenderAddress: '0x...',
|
|
348
|
+
// expireAt: 1234567890,
|
|
349
|
+
// paymentChain: 'BSC',
|
|
350
|
+
// paymentToken: 'USDT',
|
|
351
|
+
// amountOfUsd: '9.99',
|
|
352
|
+
// intervalDays: 30
|
|
353
|
+
// }
|
|
354
|
+
```
|
|
355
|
+
|
|
356
|
+
### 4. 查询支付状态
|
|
357
|
+
|
|
358
|
+
```typescript
|
|
359
|
+
// 查询一次性支付状态
|
|
360
|
+
const status = await cppay.checkOnetimePaymentStatus({
|
|
361
|
+
paymentId: "pay-xxx",
|
|
362
|
+
});
|
|
363
|
+
|
|
364
|
+
console.log(status);
|
|
365
|
+
// {
|
|
366
|
+
// orderId: 'order-123',
|
|
367
|
+
// paymentId: 'pay-xxx',
|
|
368
|
+
// status: 'paid', // 'pending' | 'paid' | 'expired' | 'failed'
|
|
369
|
+
// chain: 'Ethereum',
|
|
370
|
+
// token: 'USDT',
|
|
371
|
+
// baseAmount: '100',
|
|
372
|
+
// payAmount: '100.00',
|
|
373
|
+
// receiveAddress: '0x...',
|
|
374
|
+
// expireAt: 1234567890
|
|
375
|
+
// }
|
|
376
|
+
|
|
377
|
+
// 查询订阅支付状态
|
|
378
|
+
const subscriptionStatus = await cppay.checkSubscriptionPaymentStatus({
|
|
379
|
+
subscriptionId: "sub-xxx",
|
|
380
|
+
});
|
|
381
|
+
|
|
382
|
+
console.log(subscriptionStatus);
|
|
383
|
+
// {
|
|
384
|
+
// orderId: 'subscription-123',
|
|
385
|
+
// subscriptionId: 'sub-xxx',
|
|
386
|
+
// status: 'approved', // 'pending' | 'approved' | 'expired' | 'failed'
|
|
387
|
+
// chain: 'BSC',
|
|
388
|
+
// token: 'USDT',
|
|
389
|
+
// approvedAddress: '0x...',
|
|
390
|
+
// txHash: '0x...',
|
|
391
|
+
// approveAmount: '299.70',
|
|
392
|
+
// amountOfUsd: '9.99',
|
|
393
|
+
// expireAt: 1234567890
|
|
394
|
+
// }
|
|
395
|
+
```
|
|
396
|
+
|
|
397
|
+
### 完整的自定义支付流程示例
|
|
398
|
+
|
|
399
|
+
```typescript
|
|
400
|
+
import Cppay from "cppay-sdk";
|
|
401
|
+
|
|
402
|
+
const cppay = new Cppay("your-api-key", undefined);
|
|
403
|
+
|
|
404
|
+
async function customPaymentFlow() {
|
|
405
|
+
try {
|
|
406
|
+
// 1. 获取支持的链和代币
|
|
407
|
+
const chains = await cppay.getSupportedChains();
|
|
408
|
+
console.log("支持的链:", chains);
|
|
409
|
+
|
|
410
|
+
// 2. 用户选择链和代币
|
|
411
|
+
const selectedChain = "Ethereum";
|
|
412
|
+
const selectedToken = "USDT";
|
|
413
|
+
|
|
414
|
+
// 3. 创建支付
|
|
415
|
+
const paymentInfo = await cppay.createOnetimePayment({
|
|
416
|
+
paymentChain: selectedChain,
|
|
417
|
+
paymentToken: selectedToken,
|
|
418
|
+
orderId: `order-${Date.now()}`,
|
|
419
|
+
amount: "0.1",
|
|
420
|
+
// remark: "商品购买",
|
|
421
|
+
});
|
|
422
|
+
|
|
423
|
+
console.log("支付信息:", paymentInfo);
|
|
424
|
+
console.log("请向地址转账:", paymentInfo.receiveAddress);
|
|
425
|
+
console.log("金额:", paymentInfo.paymentAmount);
|
|
426
|
+
|
|
427
|
+
// 4. 轮询检查支付状态
|
|
428
|
+
const checkPayment = setInterval(async () => {
|
|
429
|
+
const status = await cppay.checkOnetimePaymentStatus({
|
|
430
|
+
paymentId: paymentInfo.paymentId,
|
|
431
|
+
});
|
|
432
|
+
|
|
433
|
+
console.log("支付状态:", status.status);
|
|
434
|
+
|
|
435
|
+
if (status.status === "paid") {
|
|
436
|
+
console.log("支付成功!");
|
|
437
|
+
clearInterval(checkPayment);
|
|
438
|
+
} else if (status.status === "expired" || status.status === "failed") {
|
|
439
|
+
console.log("支付失败或过期");
|
|
440
|
+
clearInterval(checkPayment);
|
|
441
|
+
}
|
|
442
|
+
}, 3000); // 每3秒检查一次
|
|
443
|
+
} catch (error) {
|
|
444
|
+
console.error("支付流程错误:", error);
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
customPaymentFlow();
|
|
449
|
+
```
|
|
450
|
+
|
|
451
|
+
---
|
|
452
|
+
|
|
453
|
+
## 📖 API 参数说明
|
|
454
|
+
|
|
455
|
+
### 通用参数
|
|
456
|
+
|
|
457
|
+
| 参数 | 类型 | 必填 | 说明 |
|
|
458
|
+
| -------------- | ----------------------------- | ---- | ------------------------------------------------------- |
|
|
459
|
+
| `apikey` | `string` | 是 | API 密钥. |
|
|
460
|
+
| `plain` | `'instant' \| 'subscription'` | 是 | 支付类型:`instant` 一次性支付,`subscription` 订阅支付 |
|
|
461
|
+
| `orderId` | `string` | 是 | 订单 ID(唯一标识) |
|
|
462
|
+
| `amount` | `string` | 是 | 支付金额(USD) |
|
|
463
|
+
| `intervalDays` | `number` | 否 | 订阅间隔天数(订阅支付时必填) |
|
|
464
|
+
| `remark` | `string` | 否 | 备注信息 |
|
|
465
|
+
| `locale` | `'en' \| 'zh-CN'` | 否 | 语言设置,默认 `'en'` |
|
|
466
|
+
|
|
467
|
+
### 回调函数
|
|
468
|
+
|
|
469
|
+
| 回调 | 参数类型 | 说明 |
|
|
470
|
+
| ----------- | ----------------- | ------------ |
|
|
471
|
+
| `onSuccess` | `(order) => void` | 支付成功回调 |
|
|
472
|
+
| `onError` | `(error) => void` | 支付错误回调 |
|
|
473
|
+
| `onExpired` | `(order) => void` | 支付过期回调 |
|
|
474
|
+
| `onFailed` | `(order) => void` | 支付失败回调 |
|
|
475
|
+
|
|
476
|
+
### PaymentDialog 特有参数(React)
|
|
477
|
+
|
|
478
|
+
| 参数 | 类型 | 必填 | 说明 |
|
|
479
|
+
| --------- | ------------ | ---- | ----------------- |
|
|
480
|
+
| `open` | `boolean` | 是 | 控制弹框显示/隐藏 |
|
|
481
|
+
| `onClose` | `() => void` | 是 | 关闭弹框回调 |
|
|
482
|
+
|
|
483
|
+
### PaymentDialog 特有参数(Vue)
|
|
484
|
+
|
|
485
|
+
| 参数 | 类型 | 必填 | 说明 |
|
|
486
|
+
| ------------------------ | --------- | ---- | ----------------- |
|
|
487
|
+
| `v-model` / `modelValue` | `boolean` | 是 | 控制弹框显示/隐藏 |
|
|
488
|
+
|
|
489
|
+
---
|
|
490
|
+
|
|
491
|
+
## 🎨 自定义插槽(Slots)
|
|
492
|
+
|
|
493
|
+
组件支持自定义插槽,可以替换默认的 UI 展示。
|
|
494
|
+
|
|
495
|
+
### React 示例
|
|
496
|
+
|
|
497
|
+
```tsx
|
|
498
|
+
<PaymentDialog
|
|
499
|
+
open={open}
|
|
500
|
+
onClose={() => setOpen(false)}
|
|
501
|
+
apikey="your-api-key"
|
|
502
|
+
plain="instant"
|
|
503
|
+
orderId="order-123"
|
|
504
|
+
amount="100"
|
|
505
|
+
Slots={{
|
|
506
|
+
Success: ({ paymentInfo }) => (
|
|
507
|
+
<div>
|
|
508
|
+
<h2>支付成功!</h2>
|
|
509
|
+
<p>订单号: {paymentInfo.orderId}</p>
|
|
510
|
+
</div>
|
|
511
|
+
),
|
|
512
|
+
Error: ({ paymentInfo }) => (
|
|
513
|
+
<div>
|
|
514
|
+
<h2>支付出错</h2>
|
|
515
|
+
<p>请稍后重试</p>
|
|
516
|
+
</div>
|
|
517
|
+
),
|
|
518
|
+
}}
|
|
519
|
+
/>
|
|
520
|
+
```
|
|
521
|
+
|
|
522
|
+
### 可用插槽
|
|
523
|
+
|
|
524
|
+
- `ChooseTop`: 选择支付方式页面顶部内容
|
|
525
|
+
- `ChooseBottom`: 选择支付方式页面底部内容
|
|
526
|
+
- `Success`: 支付成功页面
|
|
527
|
+
- `Expired`: 支付过期页面
|
|
528
|
+
- `Failed`: 支付失败页面
|
|
529
|
+
- `Error`: 支付错误页面
|
|
530
|
+
|
|
531
|
+
---
|
|
532
|
+
|
|
533
|
+
## 🌍 支持的链和代币
|
|
534
|
+
|
|
535
|
+
SDK 支持多个主流区块链网络:
|
|
536
|
+
|
|
537
|
+
- **Ethereum**(以太坊)
|
|
538
|
+
- **BSC**(币安智能链)
|
|
539
|
+
- **Polygon**(马蹄链)
|
|
540
|
+
- **Tron**(波场)
|
|
541
|
+
- **Solana**(索拉纳)
|
|
542
|
+
|
|
543
|
+
支持的代币:
|
|
544
|
+
|
|
545
|
+
- USDT
|
|
546
|
+
- USDC
|
|
547
|
+
- ETH
|
|
548
|
+
- BNB
|
|
549
|
+
- TRX
|
|
550
|
+
- SOL
|
|
551
|
+
|
|
552
|
+
具体支持的链和代币可通过 `getSupportedChains()` API 动态获取。
|
|
553
|
+
|
|
554
|
+
---
|
|
555
|
+
|
|
556
|
+
## 📝 类型定义
|
|
557
|
+
|
|
558
|
+
```typescript
|
|
559
|
+
// 支付类型
|
|
560
|
+
type PaymentPlain = "instant" | "subscription";
|
|
561
|
+
|
|
562
|
+
// 支付状态
|
|
563
|
+
type PaymentStatus = "pending" | "paid" | "expired" | "failed";
|
|
564
|
+
|
|
565
|
+
// 订阅支付状态
|
|
566
|
+
type SubscriptionPaymentStatus = "pending" | "approved" | "expired" | "failed";
|
|
567
|
+
|
|
568
|
+
// 一次性支付信息
|
|
569
|
+
interface OnetimePaymentInfo {
|
|
570
|
+
orderId: string;
|
|
571
|
+
paymentId: string;
|
|
572
|
+
paymentAmount: string;
|
|
573
|
+
paymentChain: string;
|
|
574
|
+
paymentToken: string;
|
|
575
|
+
receiveAddress: string;
|
|
576
|
+
expireAt: number;
|
|
577
|
+
}
|
|
578
|
+
|
|
579
|
+
// 订阅支付信息
|
|
580
|
+
interface SubscriptionPaymentInfo {
|
|
581
|
+
orderId: string;
|
|
582
|
+
subscriptionId: string;
|
|
583
|
+
approveAmount: string;
|
|
584
|
+
spenderAddress: string;
|
|
585
|
+
expireAt: number;
|
|
586
|
+
paymentChain: string;
|
|
587
|
+
paymentToken: string;
|
|
588
|
+
amountOfUsd: string;
|
|
589
|
+
intervalDays: number;
|
|
590
|
+
}
|
|
591
|
+
|
|
592
|
+
// 链信息
|
|
593
|
+
interface ChainInfo {
|
|
594
|
+
chain: string;
|
|
595
|
+
chainId: number;
|
|
596
|
+
icon?: string;
|
|
597
|
+
tokens: TokenInfo[];
|
|
598
|
+
}
|
|
599
|
+
|
|
600
|
+
// 代币信息
|
|
601
|
+
interface TokenInfo {
|
|
602
|
+
symbol: string;
|
|
603
|
+
decimals: number;
|
|
604
|
+
address: string;
|
|
605
|
+
icon?: string;
|
|
606
|
+
price: string;
|
|
607
|
+
}
|
|
608
|
+
```
|
|
609
|
+
|
|
610
|
+
---
|
|
611
|
+
|
|
612
|
+
## ⚠️ 注意事项
|
|
613
|
+
|
|
614
|
+
1. **API Key 安全性**:请勿在前端代码中直接暴露 API Key,建议使用环境变量或后端代理。
|
|
615
|
+
2. **支付轮询**:使用组件时会自动轮询支付状态,直接使用 API 时需要自行实现轮询逻辑。
|
|
616
|
+
3. **订阅支付**:订阅支付需要用户授权代币使用权限,首次支付会有两笔交易(授权 + 支付)。
|
|
617
|
+
4. **过期时间**:支付订单有过期时间限制,请在 `expireAt` 之前完成支付。
|
|
618
|
+
|
|
619
|
+
---
|
|
620
|
+
|
|
621
|
+
## 🔗 相关链接
|
|
622
|
+
|
|
623
|
+
- [官方文档](https://docs.cppay.io)
|
|
624
|
+
- [API 参考](https://api.cppay.io/docs)
|
|
625
|
+
- [示例项目](https://github.com/cppay/examples)
|
|
626
|
+
|
|
627
|
+
---
|
|
628
|
+
|
|
629
|
+
## 📄 License
|
|
630
|
+
|
|
631
|
+
MIT License
|
package/dist/react.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
const e=require(`./locales-Cm9yIiVb.cjs`),t=require(`./cppay-DuOJqlpA.cjs`);let n=require(`qrcode`);n=e.i(n);let r=require(`rxjs`),i=require(`rxjs/operators`),a=require(`viem`),o=require(`viem/chains`),ee=require(`@reown/appkit`),te=require(`@reown/appkit-adapter-ethers`),s=require(`react`);s=e.i(s);let c=require(`react/jsx-runtime`);var l=({apikey:l,ott:u,plain:d,orderId:f,amount:p,intervalDays:m,remark:ne,locale:h,onSuccess:g,onExpired:re,onFailed:_,onError:v,Slots:y,onPaymentStepChange:ie})=>{let b=(0,s.useMemo)(()=>new t.t(l,u),[l,u]),x=(0,s.useMemo)(()=>e.t(h),[h]),[S,C]=(0,s.useState)(`select`),w=(0,s.useMemo)(()=>S===`checking`,[S]),[T,E]=(0,s.useState)(!1),[D,O]=(0,s.useState)(),[k,ae]=(0,s.useState)([]),[A,j]=(0,s.useState)(),[M,N]=(0,s.useState)(),[oe,se]=(0,s.useState)(),[P,F]=(0,s.useState)(),[ce,le]=(0,s.useState)(!1),[I,ue]=(0,s.useState)(),[de,fe]=(0,s.useState)(``),[L,R]=(0,s.useState)(!1),[pe,z]=(0,s.useState)(!1),[B,me]=(0,s.useState)(``),V=(0,s.useRef)(null),H=(0,s.useRef)(null),U=(0,s.useRef)(null),W=(0,s.useRef)(null),G=(0,s.useRef)(``);(0,s.useEffect)(()=>{typeof window<`u`&&!V.current&&(V.current=(0,ee.createAppKit)({debug:!1,enableNetworkSwitch:!1,adapters:[new te.EthersAdapter],projectId:`8d2e1854d3f1782e45aa15fbd8938894`,allowUnsupportedChain:!0,networks:[o.mainnet,o.bsc,o.polygon,o.arbitrum,o.optimism,o.base],metadata:{name:`Cppay`,description:`Cppay Payment Gateway`,url:window.location.origin,icons:[`https://cppay.com/icon.png`]},features:{analytics:!1}}),F(V.current.getAddress()),ue(V.current.getProvider(`eip155`)),V.current.subscribeAccount(e=>{e.isConnected?F(e.address):(F(void 0),ue(void 0))}),V.current.subscribeProviders(e=>{let t=e?.eip155;ue(t)}))},[]),(0,s.useEffect)(()=>{ie?.(S)},[S]);let he=async()=>{try{le(!0),O(void 0),V.current&&await V.current.open()}catch(e){console.error(`钱包连接失败:`,e),O(e instanceof Error?e.message:x.walletConnectionFailed),v?.(e)}finally{le(!1)}},K=(0,s.useMemo)(()=>k.find(e=>e.chain===A),[k,A]),q=(0,s.useMemo)(()=>K?.tokens||[],[K]),J=(0,s.useMemo)(()=>q.find(e=>e.symbol===M),[q,M]),Y=e=>[`USDT`,`USDC`,`BUSD`,`DAI`,`TUSD`,`USDD`,`FDUSD`].includes(e.toUpperCase())?2:6,X=(e,t)=>{let n=parseFloat(e);return isNaN(n)?`0`:n.toFixed(t).replace(/\.?0+$/,``)},ge=e=>{if(e<=0)return x.expired;let t=Math.floor(e/3600),n=Math.floor(e%3600/60),r=e%60,i=e=>e.toString().padStart(2,`0`);return t>0?`${t}:${i(n)}:${i(r)}`:`${n}:${i(r)}`},Z=e=>{U.current&&clearInterval(U.current);let t=()=>{if(S===`checking`){_e();return}let t=e-Math.floor(Date.now()/1e3);fe(ge(t)),t<=0&&_e()};t(),U.current=setInterval(t,1e3)},_e=()=>{U.current&&=(clearInterval(U.current),null)},ve=(0,s.useMemo)(()=>{if(!M||!J)return`0`;let e=parseFloat(J.price);if(isNaN(e)||e===0)return`0`;let t=Y(M);return X((parseFloat(p)/e).toFixed(t),t)},[p,M,J]),ye=async()=>{try{E(!0),O(void 0);let e=await b.getSupportedChains();ae(e),e.length>0&&j(e[0].chain)}catch(e){O(e instanceof Error?e.message:x.loadPaymentNetworkFailed),v?.(e)}finally{E(!1)}},be=async e=>{if(I)try{await I.request({method:`wallet_switchEthereumChain`,params:[{chainId:`0x${e.toString(16)}`}]})}catch(e){throw e.code===4902?Error(x.pleaseAddNetwork):e}},xe=async()=>{if(!(!P||!I||!W.current||!J||!K))try{E(!0);let e=W.current;await be(K.chainId);let t=(0,a.createWalletClient)({account:P,transport:(0,a.custom)(I)});if(J.address){let n=await t.writeContract({address:J.address,abi:[{name:`transfer`,type:`function`,stateMutability:`nonpayable`,inputs:[{name:`to`,type:`address`},{name:`amount`,type:`uint256`}],outputs:[{type:`bool`}]}],functionName:`transfer`,args:[e.receiveAddress,(0,a.parseUnits)(e.paymentAmount,J.decimals)],chain:null});console.log(`转账交易哈希:`,n),me(n),G.current=n}else{let n=await t.sendTransaction({to:e.receiveAddress,value:(0,a.parseUnits)(e.paymentAmount,J.decimals),chain:null});console.log(`转账交易哈希:`,n),me(n),G.current=n}E(!1),C(`checking`),Q({paymentId:e.paymentId})}catch(e){console.error(`钱包支付失败:`,e),O(e instanceof Error?e.message:x.walletPaymentFailed),v?.(e),E(!1)}},Se=async()=>{if(!(!P||!I||!W.current||!J||!K))try{E(!0);let e=W.current;await be(K.chainId);let t=(0,a.createWalletClient)({account:P,transport:(0,a.custom)(I)});if(!J.address)throw Error(x.subscriptionDoesNotSupportNative);let n=await t.writeContract({address:J.address,abi:[{name:`approve`,type:`function`,stateMutability:`nonpayable`,inputs:[{name:`spender`,type:`address`},{name:`amount`,type:`uint256`}],outputs:[{type:`bool`}]}],functionName:`approve`,args:[e.spenderAddress,(0,a.parseUnits)(e.approveAmount,J.decimals)],chain:null});console.log(`授权交易哈希:`,n),me(n),G.current=n,E(!1),C(`checking`),Q({subscriptionId:e.subscriptionId})}catch(e){console.error(`钱包授权失败:`,e),O(e instanceof Error?e.message:x.walletPaymentFailed),v?.(e),E(!1)}},Ce=async()=>{if(!P){let e=x.pleaseConnectWallet;O(e),v?.(Error(e));return}d===`instant`?await xe():d===`subscription`&&await Se()},we=async()=>{if(!(!A||!M))try{E(!0),O(void 0);let e=``;if(d===`instant`)W.current=await b.createOnetimePayment({paymentChain:A,paymentToken:M,orderId:f,amount:ve,remark:ne}),e=`${A.toLowerCase()}:${W.current.receiveAddress}?amount=${W.current.paymentAmount}`,Z(W.current.expireAt),Oe(W.current.paymentId,`instant`);else if(d===`subscription`){if(!m)throw Error(`Invalid Renewal Days: ${m??``}`);W.current=await b.createSubscriptionPayment({paymentChain:A,paymentToken:M,orderId:f,amountOfUsd:ve,intervalDays:m}),e=`${A.toLowerCase()}:${W.current.spenderAddress}?amount=${W.current.approveAmount}`,Z(W.current.expireAt),Oe(W.current.subscriptionId,`subscription`)}C(`payment`),se(await n.toDataURL(e,{width:200,margin:2,errorCorrectionLevel:`H`}))}catch(e){O(e instanceof Error?e.message:x.createPaymentFailed),v?.(e)}finally{E(!1)}},Te=()=>{W.current&&(C(`checking`),O(void 0),d===`instant`?Q({paymentId:W.current.paymentId}):d===`subscription`&&Q({subscriptionId:W.current.subscriptionId}))},Q=e=>{H.current?.unsubscribe();let t=()=>(0,r.defer)(()=>d===`subscription`?b.checkSubscriptionPaymentStatus(e):b.checkOnetimePaymentStatus(e)).pipe((0,i.timeout)(15e3),(0,i.retry)({delay:2e3}));H.current=t().pipe((0,i.expand)(e=>e.status===`pending`?(0,r.timer)(2e3).pipe((0,i.switchMap)(()=>t())):r.EMPTY),(0,i.tap)(e=>{if(!W.current&&d===`instant`){let t=e;W.current={paymentId:t.paymentId,orderId:t.orderId,paymentChain:t.chain,paymentToken:t.token,paymentAmount:t.payAmount,receiveAddress:t.receiveAddress,expireAt:t.expireAt},j(t.chain),N(t.token),Z(t.expireAt);let r=`${t.chain.toLowerCase()}:${t.receiveAddress}?amount=${t.payAmount}`;n.toDataURL(r,{width:200,margin:2,errorCorrectionLevel:`H`}).then(e=>{se(e),C(`payment`)}).catch(e=>{console.error(`生成二维码失败:`,e),C(`payment`)})}if(!W.current&&d===`subscription`){let t=e;W.current={subscriptionId:t.subscriptionId,orderId:t.orderId,paymentChain:t.chain,paymentToken:t.token,approveAmount:t.approveAmount,spenderAddress:t.approvedAddress,expireAt:t.expireAt,intervalDays:0,amountOfUsd:t.amountOfUsd},j(t.chain),N(t.token),Z(t.expireAt);let r=`${t.chain.toLowerCase()}:${t.approvedAddress}?amount=${t.approveAmount}`;n.toDataURL(r,{width:200,margin:2,errorCorrectionLevel:`H`}).then(e=>{se(e),C(`payment`)}).catch(e=>{console.error(`生成二维码失败:`,e),C(`payment`)})}(e.status===`paid`||e.status===`approved`)&&(C(`success`),$(),g?.(e)),e.status===`expired`&&(C(`expired`),$(),re?.(e)),e.status===`failed`&&(C(`failed`),$(),_?.(e))})).subscribe({error:e=>{if(W.current){let t=e instanceof Error?e.message:x.checkPaymentStatusFailed;C(`error`),O(t),v?.(e)}},complete:()=>{H.current?.unsubscribe()}})},Ee=async()=>{if(!W.current)return;let e=d===`subscription`?W.current.spenderAddress:W.current.receiveAddress;if(e)try{await navigator.clipboard.writeText(e),R(!0),setTimeout(()=>{R(!1)},2e3)}catch(e){console.error(`复制失败:`,e)}},De=async()=>{if(B)try{await navigator.clipboard.writeText(B),R(!0),setTimeout(()=>{R(!1)},2e3)}catch(e){console.error(`复制失败:`,e)}},Oe=(e,t)=>{if(typeof window>`u`)return;let n=new URL(window.location.href),r=t===`subscription`?`subscriptionId`:`paymentId`;n.searchParams.set(r,e),window.history.replaceState({},``,n.toString())},$=()=>{if(typeof window>`u`)return;let e=new URL(window.location.href);e.searchParams.delete(`paymentId`),e.searchParams.delete(`subscriptionId`),window.history.replaceState({},``,e.toString())};return(0,s.useEffect)(()=>{k.length===0&&ye()},[]),(0,s.useEffect)(()=>{q.length>0&&N(q[0].symbol)},[q]),(0,s.useEffect)(()=>{if(typeof window>`u`)return;let e=new URL(window.location.href);if(d===`instant`){let t=e.searchParams.get(`paymentId`);t&&(C(`payment`),Q({paymentId:t}))}if(d===`subscription`){let t=e.searchParams.get(`subscriptionId`);t&&(C(`payment`),Q({subscriptionId:t}))}},[]),(0,s.useEffect)(()=>()=>{H.current?.unsubscribe(),_e()},[]),(0,c.jsx)(`div`,{className:`_cppay-content`,children:S===`success`?y?.Success?(0,c.jsx)(y.Success,{paymentInfo:W.current}):(0,c.jsxs)(`div`,{className:`_cppay-state-container`,children:[(0,c.jsx)(`div`,{className:`_cppay-state-success-bg`,children:(0,c.jsx)(`div`,{className:`_cppay-state-success-icon`,children:`✓`})}),(0,c.jsx)(`h3`,{className:`_cppay-state-title _cppay-state-title-success`,children:d===`subscription`?x.authorizationSuccess:x.paymentSuccess}),B&&(0,c.jsxs)(`div`,{className:`_cppay-state-hash-container`,children:[(0,c.jsx)(`div`,{className:`_cppay-state-label`,children:x.transactionHash}),(0,c.jsxs)(`div`,{className:`_cppay-hash-row`,children:[(0,c.jsxs)(`code`,{className:`_cppay-state-hash`,children:[B.slice(0,18),`...`,B.slice(-18)]}),(0,c.jsx)(`button`,{onClick:De,className:`_cppay-state-copy-btn`,title:x.copyAddress,children:(0,c.jsxs)(`svg`,{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,children:[(0,c.jsx)(`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`}),(0,c.jsx)(`rect`,{x:`8`,y:`2`,width:`8`,height:`4`,rx:`1`,ry:`1`})]})})]})]}),W.current&&(0,c.jsxs)(`div`,{className:`_cppay-success-details`,children:[(0,c.jsxs)(`div`,{className:`_cppay-detail-item`,children:[(0,c.jsx)(`span`,{className:`_cppay-detail-label`,children:x.orderId}),(0,c.jsx)(`span`,{className:`_cppay-detail-value`,children:W.current.orderId})]}),(0,c.jsxs)(`div`,{className:`_cppay-detail-item`,children:[(0,c.jsx)(`span`,{className:`_cppay-detail-label`,children:d===`subscription`?x.authorizationAmount:x.paymentAmount}),(0,c.jsx)(`span`,{className:`_cppay-detail-value`,children:d===`subscription`?`${X(W.current.approveAmount,Y(M))} ${M}`:`${X(W.current.paymentAmount,Y(M))} ${M}`})]}),(0,c.jsxs)(`div`,{className:`_cppay-detail-item`,children:[(0,c.jsx)(`span`,{className:`_cppay-detail-label`,children:x.paymentNetwork}),(0,c.jsx)(`span`,{className:`_cppay-detail-value`,children:W.current.paymentChain})]}),(0,c.jsxs)(`div`,{className:`_cppay-detail-item`,children:[(0,c.jsx)(`span`,{className:`_cppay-detail-label`,children:x.paymentToken}),(0,c.jsx)(`span`,{className:`_cppay-detail-value`,children:W.current.paymentToken})]}),d===`subscription`&&(0,c.jsxs)(`div`,{className:`_cppay-detail-item`,children:[(0,c.jsx)(`span`,{className:`_cppay-detail-label`,children:x.renewalInterval}),(0,c.jsxs)(`span`,{className:`_cppay-detail-value`,children:[W.current.intervalDays,` `,x.days]})]}),(0,c.jsxs)(`div`,{className:`_cppay-detail-item`,children:[(0,c.jsx)(`span`,{className:`_cppay-detail-label`,children:d===`subscription`?x.subscriptionId:x.paymentId}),(0,c.jsx)(`span`,{className:`_cppay-detail-value _cppay-detail-id`,children:d===`subscription`?W.current.subscriptionId:W.current.paymentId})]})]})]}):S===`expired`?y?.Expired?(0,c.jsx)(y.Expired,{paymentInfo:W.current}):(0,c.jsxs)(`div`,{className:`_cppay-state-container`,children:[(0,c.jsx)(`div`,{className:`_cppay-state-expired-bg`,children:(0,c.jsx)(`div`,{className:`_cppay-state-expired-icon`,children:`⏰`})}),(0,c.jsx)(`h3`,{className:`_cppay-state-title _cppay-state-title-expired`,children:x.paymentExpired}),(0,c.jsx)(`p`,{className:`_cppay-state-message`,children:x.pleaseInitiatePaymentAgain}),(0,c.jsx)(`button`,{onClick:()=>{C(`select`),$()},disabled:T||w,className:`_cppay-btn _cppay-btn-primary _cppay-state-btn`,children:x.returnButton})]}):S===`error`?y?.Error?(0,c.jsx)(y.Error,{paymentInfo:W.current}):(0,c.jsxs)(`div`,{className:`_cppay-state-container`,children:[(0,c.jsx)(`div`,{className:`_cppay-state-error-bg`,children:(0,c.jsx)(`div`,{className:`_cppay-state-error-icon`,children:`!`})}),(0,c.jsx)(`h3`,{className:`_cppay-state-title _cppay-state-title-error`,children:D||x.error}),(0,c.jsx)(`p`,{className:`_cppay-state-message`,children:x.checkStatusFailed}),(0,c.jsx)(`button`,{onClick:()=>{C(`select`),$()},disabled:T||w,className:`_cppay-btn _cppay-btn-primary _cppay-state-btn`,children:x.returnButton})]}):S===`failed`?y?.Failed?(0,c.jsx)(y.Failed,{paymentInfo:W.current}):(0,c.jsxs)(`div`,{className:`_cppay-state-container`,children:[(0,c.jsx)(`div`,{className:`_cppay-state-failed-bg`,children:(0,c.jsx)(`div`,{className:`_cppay-state-failed-icon`,children:`✕`})}),(0,c.jsx)(`h3`,{className:`_cppay-state-title _cppay-state-title-failed`,children:x.paymentFailed}),(0,c.jsx)(`p`,{className:`_cppay-state-message`,children:x.pleaseInitiatePaymentAgain}),(0,c.jsx)(`button`,{onClick:()=>{C(`select`),$()},disabled:T||w,className:`_cppay-btn _cppay-btn-primary _cppay-state-btn`,children:x.returnButton})]}):S===`select`?(0,c.jsxs)(`div`,{children:[y?.ChooseTop,(0,c.jsxs)(`div`,{className:`_cppay-section`,children:[(0,c.jsx)(`label`,{className:`_cppay-label`,children:x.paymentNetwork}),(0,c.jsx)(`div`,{className:`_cppay-grid`,children:k.map(e=>(0,c.jsxs)(`button`,{onClick:()=>j(e.chain),className:`_cppay-select-btn ${A===e.chain?`_cppay-selected`:``}`,children:[e.icon&&(0,c.jsx)(`img`,{src:e.icon,alt:e.chain}),(0,c.jsx)(`span`,{children:e.chain})]},e.chain))})]}),(0,c.jsxs)(`div`,{className:`_cppay-section`,children:[(0,c.jsx)(`label`,{className:`_cppay-label`,children:x.paymentToken}),(0,c.jsx)(`div`,{className:`_cppay-grid`,children:q.map(e=>(0,c.jsxs)(`button`,{onClick:()=>N(e.symbol),className:`_cppay-select-btn ${M===e.symbol?`_cppay-selected`:``}`,children:[e.icon&&(0,c.jsx)(`img`,{src:e.icon,alt:e.symbol}),(0,c.jsx)(`span`,{children:e.symbol})]},e.symbol))})]}),y?.ChooseBottom,(0,c.jsx)(`div`,{className:`_cppay-section`,children:(0,c.jsx)(`div`,{className:`_cppay-price-box`,children:(0,c.jsxs)(`div`,{className:`_cppay-price-row`,children:[(0,c.jsx)(`span`,{className:`_cppay-price-label`,children:x.paymentAmount}),(0,c.jsxs)(`div`,{className:`_cppay-price-amount`,children:[(0,c.jsxs)(`div`,{className:`_cppay-price-main`,children:[ve??`-`,` `,M??``]}),(0,c.jsxs)(`div`,{className:`_cppay-price-sub`,children:[`≈ $`,p]})]})]})})}),(0,c.jsxs)(`div`,{className:`_cppay-section`,children:[D&&(0,c.jsxs)(`div`,{className:`_cppay-error-tooltip-wrapper`,onMouseEnter:()=>z(!0),onMouseLeave:()=>z(!1),children:[(0,c.jsxs)(`div`,{className:`_cppay-error-tooltip`,children:[(0,c.jsx)(`svg`,{viewBox:`0 0 20 20`,fill:`currentColor`,children:(0,c.jsx)(`path`,{fillRule:`evenodd`,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`,clipRule:`evenodd`})}),(0,c.jsx)(`span`,{children:D})]}),pe&&(0,c.jsx)(`div`,{className:`_cppay-error-tooltip-full`,children:D})]}),(0,c.jsx)(`button`,{onClick:we,disabled:!A||!M||T,className:`_cppay-btn _cppay-btn-primary`,children:T?x.processing:x.continuePayment})]})]}):(0,c.jsxs)(`div`,{children:[(0,c.jsx)(`div`,{className:`_cppay-qr-container`,children:(0,c.jsx)(`div`,{className:`_cppay-qr-code`,children:oe&&(0,c.jsx)(`img`,{src:oe,alt:`Payment QR Code`,className:`_cppay-qr-image`})})}),(0,c.jsxs)(`div`,{className:`_cppay-section`,children:[J&&(0,c.jsx)(`div`,{className:`_cppay-info-box`,children:(0,c.jsx)(`div`,{className:`_cppay-info-flex-container`,children:(0,c.jsxs)(`div`,{className:`_cppay-info-flex-child`,children:[(0,c.jsx)(`div`,{className:`_cppay-info-label`,children:d===`subscription`?x.authorizationAmount:x.paymentAmount}),(0,c.jsxs)(`div`,{className:`_cppay-info-value _cppay-info-value-flex`,children:[W.current&&(0,c.jsx)(`span`,{children:d===`subscription`?`${X(W.current.approveAmount,Y(J.symbol))} ${J.symbol}`:`${X(W.current.paymentAmount,Y(J.symbol))} ${J.symbol}`}),(0,c.jsxs)(`span`,{children:[`≈ $`,p]})]})]})})}),(0,c.jsx)(`div`,{className:`_cppay-info-box`,children:(0,c.jsxs)(`div`,{className:`_cppay-info-flex-child`,children:[(0,c.jsxs)(`div`,{className:`_cppay-info-label _cppay-info-label-flex`,children:[(0,c.jsx)(`span`,{children:d===`subscription`?x.authorizationContractAddress:x.paymentAddress}),de&&(0,c.jsxs)(`span`,{className:`_cppay-countdown`,children:[`⏰ `,de]})]}),(0,c.jsxs)(`div`,{className:`_cppay-address-row`,children:[W.current&&(0,c.jsx)(`code`,{children:d===`subscription`?W.current.spenderAddress:W.current.receiveAddress}),(0,c.jsx)(`button`,{onClick:Ee,className:`_cppay-copy-btn ${L?`_cppay-copy-success`:``}`,title:L?x.copied:x.copyAddress,children:L?(0,c.jsx)(`svg`,{className:`_cppay-copy-icon`,viewBox:`0 0 24 24`,fill:`currentColor`,children:(0,c.jsx)(`path`,{d:`M9 16.17L4.83 12l-1.42 1.41L9 19 21 7l-1.41-1.41z`})}):(0,c.jsxs)(`svg`,{className:`_cppay-copy-icon`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,children:[(0,c.jsx)(`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`}),(0,c.jsx)(`rect`,{x:`8`,y:`2`,width:`8`,height:`4`,rx:`1`,ry:`1`})]})})]})]})}),d===`subscription`&&(0,c.jsxs)(`div`,{className:`_cppay-info-box _cppay-subscription-box`,children:[(0,c.jsx)(`div`,{className:`_cppay-info-label _cppay-subscription-label`,children:x.subscriptionNotice}),(0,c.jsx)(`div`,{className:`_cppay-info-value _cppay-subscription-message`,children:x.subscriptionNoticeMessage})]})]}),D&&(0,c.jsxs)(`div`,{className:`_cppay-error-tooltip-wrapper`,onMouseEnter:()=>z(!0),onMouseLeave:()=>z(!1),children:[(0,c.jsxs)(`div`,{className:`_cppay-error-tooltip`,children:[(0,c.jsx)(`svg`,{viewBox:`0 0 20 20`,fill:`currentColor`,children:(0,c.jsx)(`path`,{fillRule:`evenodd`,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`,clipRule:`evenodd`})}),(0,c.jsx)(`span`,{children:D})]}),pe&&(0,c.jsx)(`div`,{className:`_cppay-error-tooltip-full`,children:D})]}),!w&&(0,c.jsx)(`div`,{className:`_cppay-section`,children:P?(0,c.jsxs)(c.Fragment,{children:[(0,c.jsx)(`button`,{onClick:Ce,disabled:T,className:`_cppay-btn _cppay-btn-primary`,children:T?d===`subscription`?x.authorizing:x.processing:d===`subscription`?`💳 ${x.connectWallet}`:`💳 ${x.walletPay}`}),(0,c.jsxs)(`button`,{onClick:he,disabled:T,className:`_cppay-btn _cppay-wallet-address-btn`,title:x.clickToModifyWallet,children:[(0,c.jsxs)(`span`,{className:`_cppay-wallet-address-text`,children:[P.slice(0,10),`...`,P.slice(-4)]}),(0,c.jsx)(`svg`,{className:`_cppay-wallet-arrow`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,children:(0,c.jsx)(`polyline`,{points:`6 9 12 15 18 9`})})]})]}):(0,c.jsx)(`button`,{onClick:he,disabled:ce,className:`_cppay-btn _cppay-btn-secondary _cppay-connect-wallet-btn`,children:(0,c.jsx)(`span`,{children:ce?x.processing:`💳 ${x.connectWallet}`})})}),(0,c.jsx)(`div`,{className:`_cppay-section`,children:(0,c.jsx)(`button`,{onClick:Te,disabled:w,className:`_cppay-btn _cppay-btn-primary`,children:w?(0,c.jsxs)(c.Fragment,{children:[(0,c.jsxs)(`svg`,{className:`_cppay-spinner`,viewBox:`0 0 24 24`,fill:`none`,xmlns:`http://www.w3.org/2000/svg`,children:[(0,c.jsx)(`circle`,{cx:`12`,cy:`12`,r:`10`,stroke:`currentColor`,strokeWidth:`3`,strokeOpacity:`0.25`}),(0,c.jsx)(`path`,{d:`M12 2a10 10 0 0 1 10 10`,stroke:`currentColor`,strokeWidth:`3`,strokeLinecap:`round`})]}),x.checking]}):x.completedPayment})}),(0,c.jsx)(`hr`,{className:`_cppay-divider`}),(0,c.jsx)(`div`,{className:`_cppay-section`,children:(0,c.jsx)(`button`,{onClick:()=>{C(`select`),$()},disabled:T||w,className:`_cppay-btn _cppay-btn-text`,children:x.changePaymentMethod})})]})})},u=l,d=({open:t,onClose:n,ott:r,apikey:i,plain:a,orderId:o,amount:ee,intervalDays:te,remark:l,locale:d,onExpired:f,onSuccess:p,onFailed:m,onError:ne,Slots:h})=>{let[g,re]=(0,s.useState)(`select`),_=(0,s.useMemo)(()=>g!==`checking`,[g]);(0,s.useEffect)(()=>{t||re(`select`)},[t]),(0,s.useEffect)(()=>{if(!t)return;let e=e=>{e.key===`Escape`&&_&&v()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[t,_]);let v=()=>{_&&n()},y=(0,s.useMemo)(()=>e.t(d),[d]);return t?(0,c.jsx)(`div`,{className:`_cppay-overlay`,onClick:e=>e.target===e.currentTarget&&v(),children:(0,c.jsxs)(`div`,{className:`_cppay-dialog`,children:[(0,c.jsxs)(`div`,{className:`_cppay-header`,children:[(0,c.jsx)(`h2`,{className:`_cppay-title`,children:(()=>{switch(g){case`success`:return y.paymentResult;case`expired`:return y.paymentExpired;case`failed`:return y.paymentFailed;case`error`:return y.error;case`payment`:case`checking`:return y.completePayment;default:return y.selectPaymentMethod}})()}),(0,c.jsx)(`button`,{onClick:v,disabled:!_,className:`_cppay-close-btn`,children:(0,c.jsx)(`svg`,{fill:`none`,stroke:`currentColor`,viewBox:`0 0 24 24`,children:(0,c.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:2,d:`M6 18L18 6M6 6l12 12`})})})]}),(0,c.jsx)(u,{apikey:i,ott:r,plain:a,orderId:o,amount:ee,intervalDays:te,remark:l,locale:d,onSuccess:p,onExpired:f,onFailed:m,onError:ne,Slots:h,onPaymentStepChange:re})]})}):null},f=d,p=(0,s.createContext)(null);const m=({children:e})=>{let[t,n]=(0,s.useState)(!1),[r,i]=(0,s.useState)(null),a=(0,s.useCallback)(e=>{i(e),n(!0)},[]),o=(0,s.useCallback)(()=>{n(!1)},[]),ee=(0,s.useCallback)(()=>{n(!1)},[]),te=(0,s.useCallback)(e=>{r?.onSuccess?.(e)},[r]),l=(0,s.useCallback)(e=>{r?.onExpired?.(e)},[r]),u=(0,s.useCallback)(e=>{r?.onFailed?.(e)},[r]),d=(0,s.useCallback)(e=>{r?.onError?.(e)},[r]);return(0,c.jsxs)(p.Provider,{value:{showPayment:a,closePayment:o},children:[e,r&&(0,c.jsx)(f,{open:t,onClose:ee,...r,onSuccess:te,onExpired:l,onFailed:u,onError:d})]})},ne=()=>{let e=(0,s.useContext)(p);if(!e)throw Error(`useCppayPayment must be used within CppayProvider`);return e};e.n(e.r),exports.CppayProvider=m,exports.PaymentContent=u,exports.PaymentDialog=f,exports.useCppayPayment=ne;
|
|
1
|
+
const e=require(`./locales-Cm9yIiVb.cjs`),t=require(`./cppay-DuOJqlpA.cjs`);let n=require(`qrcode`);n=e.i(n);let r=require(`rxjs`),i=require(`rxjs/operators`),a=require(`viem`),o=require(`viem/chains`),ee=require(`@reown/appkit`),te=require(`@reown/appkit-adapter-ethers`),s=require(`react`);s=e.i(s);let c=require(`react/jsx-runtime`);var l=({apikey:l,ott:u,plain:d,orderId:f,amount:p,intervalDays:m,remark:ne,locale:h,onSuccess:g,onExpired:re,onFailed:_,onError:v,Slots:y,onPaymentStepChange:ie})=>{let b=(0,s.useMemo)(()=>new t.t(l,u),[l,u]),x=(0,s.useMemo)(()=>e.t(h),[h]),[S,C]=(0,s.useState)(`select`),w=(0,s.useMemo)(()=>S===`checking`,[S]),[T,E]=(0,s.useState)(!1),[D,O]=(0,s.useState)(),[k,ae]=(0,s.useState)([]),[A,j]=(0,s.useState)(),[M,N]=(0,s.useState)(),[oe,se]=(0,s.useState)(),[P,F]=(0,s.useState)(),[ce,le]=(0,s.useState)(!1),[I,ue]=(0,s.useState)(),[de,fe]=(0,s.useState)(``),[L,R]=(0,s.useState)(!1),[pe,z]=(0,s.useState)(!1),[B,me]=(0,s.useState)(``),V=(0,s.useRef)(null),H=(0,s.useRef)(null),U=(0,s.useRef)(null),W=(0,s.useRef)(null),G=(0,s.useRef)(``);(0,s.useEffect)(()=>{typeof window<`u`&&!V.current&&(V.current=(0,ee.createAppKit)({debug:!1,enableNetworkSwitch:!1,adapters:[new te.EthersAdapter],projectId:`8d2e1854d3f1782e45aa15fbd8938894`,allowUnsupportedChain:!0,networks:[o.mainnet,o.bsc,o.polygon,o.arbitrum,o.optimism,o.base],metadata:{name:`Cppay`,description:`Cppay Payment Gateway`,url:window.location.origin,icons:[`https://cppay.com/icon.png`]},features:{analytics:!1}}),F(V.current.getAddress()),ue(V.current.getProvider(`eip155`)),V.current.subscribeAccount(e=>{e.isConnected?F(e.address):(F(void 0),ue(void 0))}),V.current.subscribeProviders(e=>{let t=e?.eip155;ue(t)}))},[]),(0,s.useEffect)(()=>{ie?.(S)},[S]);let he=async()=>{try{le(!0),O(void 0),V.current&&await V.current.open()}catch(e){console.error(`钱包连接失败:`,e),O(e instanceof Error?e.message:x.walletConnectionFailed),v?.(e)}finally{le(!1)}},K=(0,s.useMemo)(()=>k.find(e=>e.chain===A),[k,A]),q=(0,s.useMemo)(()=>K?.tokens||[],[K]),J=(0,s.useMemo)(()=>q.find(e=>e.symbol===M),[q,M]),Y=e=>[`USDT`,`USDC`,`BUSD`,`DAI`,`TUSD`,`USDD`,`FDUSD`].includes(e.toUpperCase())?2:6,X=(e,t)=>{let n=parseFloat(e);return isNaN(n)?`0`:n.toFixed(t).replace(/\.?0+$/,``)},ge=e=>{if(e<=0)return x.expired;let t=Math.floor(e/3600),n=Math.floor(e%3600/60),r=e%60,i=e=>e.toString().padStart(2,`0`);return t>0?`${t}:${i(n)}:${i(r)}`:`${n}:${i(r)}`},Z=e=>{U.current&&clearInterval(U.current);let t=()=>{if(S===`checking`){_e();return}let t=e-Math.floor(Date.now()/1e3);fe(ge(t)),t<=0&&_e()};t(),U.current=setInterval(t,1e3)},_e=()=>{U.current&&=(clearInterval(U.current),null)},ve=(0,s.useMemo)(()=>{if(!M||!J)return`0`;let e=parseFloat(J.price);if(isNaN(e)||e===0)return`0`;let t=Y(M);return X((parseFloat(p)/e).toFixed(t),t)},[p,M,J]),ye=async()=>{try{E(!0),O(void 0);let e=await b.getSupportedChains();ae(e),e.length>0&&j(e[0].chain)}catch(e){O(e instanceof Error?e.message:x.loadPaymentNetworkFailed),v?.(e)}finally{E(!1)}},be=async e=>{if(I)try{await I.request({method:`wallet_switchEthereumChain`,params:[{chainId:`0x${e.toString(16)}`}]})}catch(e){throw e.code===4902?Error(x.pleaseAddNetwork):e}},xe=async()=>{if(!(!P||!I||!W.current||!J||!K))try{E(!0);let e=W.current;await be(K.chainId);let t=(0,a.createWalletClient)({account:P,transport:(0,a.custom)(I)});if(J.address){let n=await t.writeContract({address:J.address,abi:[{name:`transfer`,type:`function`,stateMutability:`nonpayable`,inputs:[{name:`to`,type:`address`},{name:`amount`,type:`uint256`}],outputs:[{type:`bool`}]}],functionName:`transfer`,args:[e.receiveAddress,(0,a.parseUnits)(e.paymentAmount,J.decimals)],chain:null});console.log(`转账交易哈希:`,n),me(n),G.current=n}else{let n=await t.sendTransaction({to:e.receiveAddress,value:(0,a.parseUnits)(e.paymentAmount,J.decimals),chain:null});console.log(`转账交易哈希:`,n),me(n),G.current=n}E(!1),C(`checking`),Q({paymentId:e.paymentId})}catch(e){console.error(`钱包支付失败:`,e),O(e instanceof Error?e.message:x.walletPaymentFailed),v?.(e),E(!1)}},Se=async()=>{if(!(!P||!I||!W.current||!J||!K))try{E(!0);let e=W.current;await be(K.chainId);let t=(0,a.createWalletClient)({account:P,transport:(0,a.custom)(I)});if(!J.address)throw Error(x.subscriptionDoesNotSupportNative);let n=await t.writeContract({address:J.address,abi:[{name:`approve`,type:`function`,stateMutability:`nonpayable`,inputs:[{name:`spender`,type:`address`},{name:`amount`,type:`uint256`}],outputs:[{type:`bool`}]}],functionName:`approve`,args:[e.spenderAddress,(0,a.parseUnits)(e.approveAmount,J.decimals)],chain:null});console.log(`授权交易哈希:`,n),me(n),G.current=n,E(!1),C(`checking`),Q({subscriptionId:e.subscriptionId})}catch(e){console.error(`钱包授权失败:`,e),O(e instanceof Error?e.message:x.walletPaymentFailed),v?.(e),E(!1)}},Ce=async()=>{if(!P){let e=x.pleaseConnectWallet;O(e),v?.(Error(e));return}d===`instant`?await xe():d===`subscription`&&await Se()},we=async()=>{if(!(!A||!M))try{E(!0),O(void 0);let e=``;if(d===`instant`)W.current=await b.createOnetimePayment({paymentChain:A,paymentToken:M,orderId:f,amount:ve,remark:ne}),e=`${A.toLowerCase()}:${W.current.receiveAddress}?amount=${W.current.paymentAmount}`,Z(W.current.expireAt),Oe(W.current.paymentId,`instant`);else if(d===`subscription`){if(!m)throw Error(`Invalid Renewal Days: ${m??``}`);W.current=await b.createSubscriptionPayment({paymentChain:A,paymentToken:M,orderId:f,amountOfUsd:ve,intervalDays:m}),e=`${A.toLowerCase()}:${W.current.spenderAddress}?amount=${W.current.approveAmount}`,Z(W.current.expireAt),Oe(W.current.subscriptionId,`subscription`)}C(`payment`),se(await n.toDataURL(e,{width:200,margin:2,errorCorrectionLevel:`H`}))}catch(e){O(e instanceof Error?e.message:x.createPaymentFailed),v?.(e)}finally{E(!1)}},Te=()=>{W.current&&(C(`checking`),O(void 0),d===`instant`?Q({paymentId:W.current.paymentId}):d===`subscription`&&Q({subscriptionId:W.current.subscriptionId}))},Q=e=>{H.current?.unsubscribe();let t=()=>(0,r.defer)(()=>d===`subscription`?b.checkSubscriptionPaymentStatus(e):b.checkOnetimePaymentStatus(e)).pipe((0,i.timeout)(15e3),(0,i.retry)({delay:2e3}));H.current=t().pipe((0,i.expand)(e=>e.status===`pending`?(0,r.timer)(2e3).pipe((0,i.switchMap)(()=>t())):r.EMPTY),(0,i.tap)(e=>{if(!W.current&&d===`instant`){let t=e;W.current={paymentId:t.paymentId,orderId:t.orderId,paymentChain:t.chain,paymentToken:t.token,paymentAmount:t.payAmount,receiveAddress:t.receiveAddress,expireAt:t.expireAt},j(t.chain),N(t.token),Z(t.expireAt);let r=`${t.chain.toLowerCase()}:${t.receiveAddress}?amount=${t.payAmount}`;n.toDataURL(r,{width:200,margin:2,errorCorrectionLevel:`H`}).then(e=>{se(e),C(`payment`)}).catch(e=>{console.error(`生成二维码失败:`,e),C(`payment`)})}if(!W.current&&d===`subscription`){let t=e;W.current={subscriptionId:t.subscriptionId,orderId:t.orderId,paymentChain:t.chain,paymentToken:t.token,approveAmount:t.approveAmount,spenderAddress:t.approvedAddress,expireAt:t.expireAt,intervalDays:0,amountOfUsd:t.amountOfUsd},j(t.chain),N(t.token),Z(t.expireAt);let r=`${t.chain.toLowerCase()}:${t.approvedAddress}?amount=${t.approveAmount}`;n.toDataURL(r,{width:200,margin:2,errorCorrectionLevel:`H`}).then(e=>{se(e),C(`payment`)}).catch(e=>{console.error(`生成二维码失败:`,e),C(`payment`)})}(e.status===`paid`||e.status===`approved`)&&(C(`success`),$(),g?.(e)),e.status===`expired`&&(C(`expired`),$(),re?.(e)),e.status===`failed`&&(C(`failed`),$(),_?.(e))})).subscribe({error:e=>{if(W.current){let t=e instanceof Error?e.message:x.checkPaymentStatusFailed;C(`error`),O(t),v?.(e)}},complete:()=>{H.current?.unsubscribe()}})},Ee=async()=>{if(!W.current)return;let e=d===`subscription`?W.current.spenderAddress:W.current.receiveAddress;if(e)try{await navigator.clipboard.writeText(e),R(!0),setTimeout(()=>{R(!1)},2e3)}catch(e){console.error(`复制失败:`,e)}},De=async()=>{if(B)try{await navigator.clipboard.writeText(B),R(!0),setTimeout(()=>{R(!1)},2e3)}catch(e){console.error(`复制失败:`,e)}},Oe=(e,t)=>{if(typeof window>`u`)return;let n=new URL(window.location.href),r=t===`subscription`?`subscriptionId`:`paymentId`;n.searchParams.set(r,e),window.history.replaceState({},``,n.toString())},$=()=>{if(typeof window>`u`)return;let e=new URL(window.location.href);e.searchParams.delete(`paymentId`),e.searchParams.delete(`subscriptionId`),window.history.replaceState({},``,e.toString())};return(0,s.useEffect)(()=>{k.length===0&&ye()},[]),(0,s.useEffect)(()=>{q.length>0&&N(q[0].symbol)},[q]),(0,s.useEffect)(()=>{if(typeof window>`u`)return;let e=new URL(window.location.href);if(d===`instant`){let t=e.searchParams.get(`paymentId`);t&&(C(`payment`),Q({paymentId:t}))}if(d===`subscription`){let t=e.searchParams.get(`subscriptionId`);t&&(C(`payment`),Q({subscriptionId:t}))}},[]),(0,s.useEffect)(()=>()=>{H.current?.unsubscribe(),_e()},[]),(0,c.jsx)(`div`,{className:`_cppay-content`,children:S===`success`?y?.Success?(0,c.jsx)(y.Success,{paymentInfo:W.current}):(0,c.jsxs)(`div`,{className:`_cppay-state-container`,children:[(0,c.jsx)(`div`,{className:`_cppay-state-success-bg`,children:(0,c.jsx)(`div`,{className:`_cppay-state-success-icon`,children:`✓`})}),(0,c.jsx)(`h3`,{className:`_cppay-state-title _cppay-state-title-success`,children:d===`subscription`?x.authorizationSuccess:x.paymentSuccess}),B&&(0,c.jsxs)(`div`,{className:`_cppay-state-hash-container`,children:[(0,c.jsx)(`div`,{className:`_cppay-state-label`,children:x.transactionHash}),(0,c.jsxs)(`div`,{className:`_cppay-hash-row`,children:[(0,c.jsxs)(`code`,{className:`_cppay-state-hash`,children:[B.slice(0,18),`...`,B.slice(-18)]}),(0,c.jsx)(`button`,{onClick:De,className:`_cppay-state-copy-btn`,title:x.copyAddress,children:(0,c.jsxs)(`svg`,{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,children:[(0,c.jsx)(`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`}),(0,c.jsx)(`rect`,{x:`8`,y:`2`,width:`8`,height:`4`,rx:`1`,ry:`1`})]})})]})]}),W.current&&(0,c.jsxs)(`div`,{className:`_cppay-success-details`,children:[(0,c.jsxs)(`div`,{className:`_cppay-detail-item`,children:[(0,c.jsx)(`span`,{className:`_cppay-detail-label`,children:x.orderId}),(0,c.jsx)(`span`,{className:`_cppay-detail-value`,children:W.current.orderId})]}),(0,c.jsxs)(`div`,{className:`_cppay-detail-item`,children:[(0,c.jsx)(`span`,{className:`_cppay-detail-label`,children:d===`subscription`?x.authorizationAmount:x.paymentAmount}),(0,c.jsx)(`span`,{className:`_cppay-detail-value`,children:d===`subscription`?`${X(W.current.approveAmount,Y(M))} ${M}`:`${X(W.current.paymentAmount,Y(M))} ${M}`})]}),(0,c.jsxs)(`div`,{className:`_cppay-detail-item`,children:[(0,c.jsx)(`span`,{className:`_cppay-detail-label`,children:x.paymentNetwork}),(0,c.jsx)(`span`,{className:`_cppay-detail-value`,children:W.current.paymentChain})]}),(0,c.jsxs)(`div`,{className:`_cppay-detail-item`,children:[(0,c.jsx)(`span`,{className:`_cppay-detail-label`,children:x.paymentToken}),(0,c.jsx)(`span`,{className:`_cppay-detail-value`,children:W.current.paymentToken})]}),d===`subscription`&&(0,c.jsxs)(`div`,{className:`_cppay-detail-item`,children:[(0,c.jsx)(`span`,{className:`_cppay-detail-label`,children:x.renewalInterval}),(0,c.jsxs)(`span`,{className:`_cppay-detail-value`,children:[W.current.intervalDays,` `,x.days]})]}),(0,c.jsxs)(`div`,{className:`_cppay-detail-item`,children:[(0,c.jsx)(`span`,{className:`_cppay-detail-label`,children:d===`subscription`?x.subscriptionId:x.paymentId}),(0,c.jsx)(`span`,{className:`_cppay-detail-value _cppay-detail-id`,children:d===`subscription`?W.current.subscriptionId:W.current.paymentId})]})]})]}):S===`expired`?y?.Expired?(0,c.jsx)(y.Expired,{paymentInfo:W.current}):(0,c.jsxs)(`div`,{className:`_cppay-state-container`,children:[(0,c.jsx)(`div`,{className:`_cppay-state-expired-bg`,children:(0,c.jsx)(`div`,{className:`_cppay-state-expired-icon`,children:`⏰`})}),(0,c.jsx)(`h3`,{className:`_cppay-state-title _cppay-state-title-expired`,children:x.paymentExpired}),(0,c.jsx)(`p`,{className:`_cppay-state-message`,children:x.pleaseInitiatePaymentAgain}),(0,c.jsx)(`button`,{onClick:()=>{C(`select`),$()},disabled:T||w,className:`_cppay-btn _cppay-btn-primary _cppay-state-btn`,children:x.returnButton})]}):S===`error`?y?.Error?(0,c.jsx)(y.Error,{paymentInfo:W.current}):(0,c.jsxs)(`div`,{className:`_cppay-state-container`,children:[(0,c.jsx)(`div`,{className:`_cppay-state-error-bg`,children:(0,c.jsx)(`div`,{className:`_cppay-state-error-icon`,children:`!`})}),(0,c.jsx)(`h3`,{className:`_cppay-state-title _cppay-state-title-error`,children:D||x.error}),(0,c.jsx)(`p`,{className:`_cppay-state-message`,children:x.checkStatusFailed}),(0,c.jsx)(`button`,{onClick:()=>{C(`select`),$()},disabled:T||w,className:`_cppay-btn _cppay-btn-primary _cppay-state-btn`,children:x.returnButton})]}):S===`failed`?y?.Failed?(0,c.jsx)(y.Failed,{paymentInfo:W.current}):(0,c.jsxs)(`div`,{className:`_cppay-state-container`,children:[(0,c.jsx)(`div`,{className:`_cppay-state-failed-bg`,children:(0,c.jsx)(`div`,{className:`_cppay-state-failed-icon`,children:`✕`})}),(0,c.jsx)(`h3`,{className:`_cppay-state-title _cppay-state-title-failed`,children:x.paymentFailed}),(0,c.jsx)(`p`,{className:`_cppay-state-message`,children:x.pleaseInitiatePaymentAgain}),(0,c.jsx)(`button`,{onClick:()=>{C(`select`),$()},disabled:T||w,className:`_cppay-btn _cppay-btn-primary _cppay-state-btn`,children:x.returnButton})]}):S===`select`?(0,c.jsxs)(`div`,{children:[y?.ChooseTop,(0,c.jsxs)(`div`,{className:`_cppay-section`,children:[(0,c.jsx)(`label`,{className:`_cppay-label`,children:x.paymentNetwork}),(0,c.jsx)(`div`,{className:`_cppay-grid`,children:k.map(e=>(0,c.jsxs)(`button`,{onClick:()=>j(e.chain),className:`_cppay-select-btn ${A===e.chain?`_cppay-selected`:``}`,children:[e.icon&&(0,c.jsx)(`img`,{src:e.icon,alt:e.chain}),(0,c.jsx)(`span`,{children:e.chain})]},e.chain))})]}),(0,c.jsxs)(`div`,{className:`_cppay-section`,children:[(0,c.jsx)(`label`,{className:`_cppay-label`,children:x.paymentToken}),(0,c.jsx)(`div`,{className:`_cppay-grid`,children:q.map(e=>(0,c.jsxs)(`button`,{onClick:()=>N(e.symbol),className:`_cppay-select-btn ${M===e.symbol?`_cppay-selected`:``}`,children:[e.icon&&(0,c.jsx)(`img`,{src:e.icon,alt:e.symbol}),(0,c.jsx)(`span`,{children:e.symbol})]},e.symbol))})]}),y?.ChooseBottom,(0,c.jsx)(`div`,{className:`_cppay-section`,children:(0,c.jsx)(`div`,{className:`_cppay-price-box`,children:(0,c.jsxs)(`div`,{className:`_cppay-price-row`,children:[(0,c.jsx)(`span`,{className:`_cppay-price-label`,children:x.paymentAmount}),(0,c.jsxs)(`div`,{className:`_cppay-price-amount`,children:[(0,c.jsxs)(`div`,{className:`_cppay-price-main`,children:[ve??`-`,` `,M??``]}),(0,c.jsxs)(`div`,{className:`_cppay-price-sub`,children:[`≈ $`,p]})]})]})})}),(0,c.jsxs)(`div`,{className:`_cppay-section`,children:[D&&(0,c.jsxs)(`div`,{className:`_cppay-error-tooltip-wrapper`,onMouseEnter:()=>z(!0),onMouseLeave:()=>z(!1),children:[(0,c.jsxs)(`div`,{className:`_cppay-error-tooltip`,children:[(0,c.jsx)(`svg`,{viewBox:`0 0 20 20`,fill:`currentColor`,children:(0,c.jsx)(`path`,{fillRule:`evenodd`,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`,clipRule:`evenodd`})}),(0,c.jsx)(`span`,{children:D})]}),pe&&(0,c.jsx)(`div`,{className:`_cppay-error-tooltip-full`,children:D})]}),(0,c.jsx)(`button`,{onClick:we,disabled:!A||!M||T,className:`_cppay-btn _cppay-btn-primary`,children:T?x.processing:x.continuePayment})]})]}):(0,c.jsxs)(`div`,{children:[(0,c.jsx)(`div`,{className:`_cppay-qr-container`,children:(0,c.jsx)(`div`,{className:`_cppay-qr-code`,children:oe&&(0,c.jsx)(`img`,{src:oe,alt:`Payment QR Code`,className:`_cppay-qr-image`})})}),(0,c.jsxs)(`div`,{className:`_cppay-section`,children:[J&&(0,c.jsx)(`div`,{className:`_cppay-info-box`,children:(0,c.jsx)(`div`,{className:`_cppay-info-flex-container`,children:(0,c.jsxs)(`div`,{className:`_cppay-info-flex-child`,children:[(0,c.jsx)(`div`,{className:`_cppay-info-label`,children:d===`subscription`?x.authorizationAmount:x.paymentAmount}),(0,c.jsxs)(`div`,{className:`_cppay-info-value _cppay-info-value-flex`,children:[W.current&&(0,c.jsx)(`span`,{children:d===`subscription`?`${X(W.current.approveAmount,Y(J.symbol))} ${J.symbol}`:`${X(W.current.paymentAmount,Y(J.symbol))} ${J.symbol}`}),(0,c.jsxs)(`span`,{children:[`≈ $`,p]})]})]})})}),(0,c.jsx)(`div`,{className:`_cppay-info-box`,children:(0,c.jsxs)(`div`,{className:`_cppay-info-flex-child`,children:[(0,c.jsxs)(`div`,{className:`_cppay-info-label _cppay-info-label-flex`,children:[(0,c.jsx)(`span`,{children:d===`subscription`?x.authorizationContractAddress:x.paymentAddress}),de&&(0,c.jsxs)(`span`,{className:`_cppay-countdown`,children:[`⏰ `,de]})]}),(0,c.jsxs)(`div`,{className:`_cppay-address-row`,children:[W.current&&(0,c.jsx)(`code`,{children:d===`subscription`?W.current.spenderAddress:W.current.receiveAddress}),(0,c.jsx)(`button`,{onClick:Ee,className:`_cppay-copy-btn ${L?`_cppay-copy-success`:``}`,title:L?x.copied:x.copyAddress,children:L?(0,c.jsx)(`svg`,{className:`_cppay-copy-icon`,viewBox:`0 0 24 24`,fill:`currentColor`,children:(0,c.jsx)(`path`,{d:`M9 16.17L4.83 12l-1.42 1.41L9 19 21 7l-1.41-1.41z`})}):(0,c.jsxs)(`svg`,{className:`_cppay-copy-icon`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,children:[(0,c.jsx)(`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`}),(0,c.jsx)(`rect`,{x:`8`,y:`2`,width:`8`,height:`4`,rx:`1`,ry:`1`})]})})]})]})}),d===`subscription`&&(0,c.jsxs)(`div`,{className:`_cppay-info-box _cppay-subscription-box`,children:[(0,c.jsx)(`div`,{className:`_cppay-info-label _cppay-subscription-label`,children:x.subscriptionNotice}),(0,c.jsx)(`div`,{className:`_cppay-info-value _cppay-subscription-message`,children:x.subscriptionNoticeMessage})]})]}),D&&(0,c.jsxs)(`div`,{className:`_cppay-error-tooltip-wrapper`,onMouseEnter:()=>z(!0),onMouseLeave:()=>z(!1),children:[(0,c.jsxs)(`div`,{className:`_cppay-error-tooltip`,children:[(0,c.jsx)(`svg`,{viewBox:`0 0 20 20`,fill:`currentColor`,children:(0,c.jsx)(`path`,{fillRule:`evenodd`,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`,clipRule:`evenodd`})}),(0,c.jsx)(`span`,{children:D})]}),pe&&(0,c.jsx)(`div`,{className:`_cppay-error-tooltip-full`,children:D})]}),!w&&(0,c.jsx)(`div`,{className:`_cppay-section`,children:P?(0,c.jsxs)(c.Fragment,{children:[(0,c.jsx)(`button`,{onClick:Ce,disabled:T,className:`_cppay-btn _cppay-btn-primary`,children:T?d===`subscription`?x.authorizing:x.processing:d===`subscription`?`💳 ${x.connectWallet}`:`💳 ${x.walletPay}`}),(0,c.jsxs)(`button`,{onClick:he,disabled:T,className:`_cppay-btn _cppay-wallet-address-btn`,title:x.clickToModifyWallet,children:[(0,c.jsxs)(`span`,{className:`_cppay-wallet-address-text`,children:[P.slice(0,10),`...`,P.slice(-4)]}),(0,c.jsx)(`svg`,{className:`_cppay-wallet-arrow`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,children:(0,c.jsx)(`polyline`,{points:`6 9 12 15 18 9`})})]})]}):(0,c.jsx)(`button`,{onClick:he,disabled:ce,className:`_cppay-btn _cppay-btn-secondary _cppay-connect-wallet-btn`,children:(0,c.jsx)(`span`,{children:ce?x.processing:`💳 ${x.connectWallet}`})})}),(0,c.jsx)(`div`,{className:`_cppay-section`,children:(0,c.jsx)(`button`,{onClick:Te,disabled:w,className:`_cppay-btn _cppay-btn-primary`,children:w?(0,c.jsxs)(c.Fragment,{children:[(0,c.jsxs)(`svg`,{className:`_cppay-spinner`,viewBox:`0 0 24 24`,fill:`none`,xmlns:`http://www.w3.org/2000/svg`,children:[(0,c.jsx)(`circle`,{cx:`12`,cy:`12`,r:`10`,stroke:`currentColor`,strokeWidth:`3`,strokeOpacity:`0.25`}),(0,c.jsx)(`path`,{d:`M12 2a10 10 0 0 1 10 10`,stroke:`currentColor`,strokeWidth:`3`,strokeLinecap:`round`})]}),x.checking]}):x.completedPayment})}),(0,c.jsx)(`hr`,{className:`_cppay-divider`}),(0,c.jsx)(`div`,{className:`_cppay-section`,children:(0,c.jsx)(`button`,{onClick:()=>{C(`select`),$()},disabled:T||w,className:`_cppay-btn _cppay-btn-text`,children:x.changePaymentMethod})})]})})},u=l,d=({open:t,onClose:n,ott:r,apikey:i,plain:a,orderId:o,amount:ee,intervalDays:te,remark:l,locale:d,onExpired:f,onSuccess:p,onFailed:m,onError:ne,Slots:h})=>{let[g,re]=(0,s.useState)(`select`),_=(0,s.useMemo)(()=>g!==`checking`,[g]);(0,s.useEffect)(()=>{t||re(`select`)},[t]),(0,s.useEffect)(()=>{if(!t)return;let e=e=>{e.key===`Escape`&&_&&v()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[t,_]);let v=()=>{if(!_||typeof window>`u`)return;let e=new URL(window.location.href);e.searchParams.delete(`paymentId`),e.searchParams.delete(`subscriptionId`),window.history.replaceState({},``,e.toString()),n()},y=(0,s.useMemo)(()=>e.t(d),[d]);return t?(0,c.jsx)(`div`,{className:`_cppay-overlay`,onClick:e=>e.target===e.currentTarget&&v(),children:(0,c.jsxs)(`div`,{className:`_cppay-dialog`,children:[(0,c.jsxs)(`div`,{className:`_cppay-header`,children:[(0,c.jsx)(`h2`,{className:`_cppay-title`,children:(()=>{switch(g){case`success`:return y.paymentResult;case`expired`:return y.paymentExpired;case`failed`:return y.paymentFailed;case`error`:return y.error;case`payment`:case`checking`:return y.completePayment;default:return y.selectPaymentMethod}})()}),(0,c.jsx)(`button`,{onClick:v,disabled:!_,className:`_cppay-close-btn`,children:(0,c.jsx)(`svg`,{fill:`none`,stroke:`currentColor`,viewBox:`0 0 24 24`,children:(0,c.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:2,d:`M6 18L18 6M6 6l12 12`})})})]}),(0,c.jsx)(u,{apikey:i,ott:r,plain:a,orderId:o,amount:ee,intervalDays:te,remark:l,locale:d,onSuccess:p,onExpired:f,onFailed:m,onError:ne,Slots:h,onPaymentStepChange:re})]})}):null},f=d,p=(0,s.createContext)(null);const m=({children:e})=>{let[t,n]=(0,s.useState)(!1),[r,i]=(0,s.useState)(null),a=(0,s.useCallback)(e=>{i(e),n(!0)},[]),o=(0,s.useCallback)(()=>{n(!1)},[]),ee=(0,s.useCallback)(()=>{n(!1)},[]),te=(0,s.useCallback)(e=>{r?.onSuccess?.(e)},[r]),l=(0,s.useCallback)(e=>{r?.onExpired?.(e)},[r]),u=(0,s.useCallback)(e=>{r?.onFailed?.(e)},[r]),d=(0,s.useCallback)(e=>{r?.onError?.(e)},[r]);return(0,c.jsxs)(p.Provider,{value:{showPayment:a,closePayment:o},children:[e,r&&(0,c.jsx)(f,{open:t,onClose:ee,...r,onSuccess:te,onExpired:l,onFailed:u,onError:d})]})},ne=()=>{let e=(0,s.useContext)(p);if(!e)throw Error(`useCppayPayment must be used within CppayProvider`);return e};e.n(e.r),exports.CppayProvider=m,exports.PaymentContent=u,exports.PaymentDialog=f,exports.useCppayPayment=ne;
|
package/dist/react.js
CHANGED
|
@@ -811,7 +811,9 @@ var PaymentContent_default = ({ apikey: t, ott: n, plain: u, orderId: xe, amount
|
|
|
811
811
|
return window.addEventListener("keydown", t), () => window.removeEventListener("keydown", t);
|
|
812
812
|
}, [e, s]);
|
|
813
813
|
let c = () => {
|
|
814
|
-
s
|
|
814
|
+
if (!s || typeof window > "u") return;
|
|
815
|
+
let e = new URL(window.location.href);
|
|
816
|
+
e.searchParams.delete("paymentId"), e.searchParams.delete("subscriptionId"), window.history.replaceState({}, "", e.toString()), t();
|
|
815
817
|
}, l = useMemo(() => getLocaleMessages(a), [a]);
|
|
816
818
|
return e ? /* @__PURE__ */ jsx("div", {
|
|
817
819
|
className: "_cppay-overlay",
|
package/dist/vue.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
const e=require(`./locales-Cm9yIiVb.cjs`),t=require(`./cppay-DuOJqlpA.cjs`);let n=require(`vue`),r=require(`qrcode`);r=e.i(r);let i=require(`rxjs`),a=require(`rxjs/operators`),o=require(`viem`),s=require(`viem/chains`),c=require(`@reown/appkit`),l=require(`@reown/appkit-adapter-ethers`);var u={class:`_cppay-content`},d={class:`_cppay-state-container`},ee={class:`_cppay-state-title _cppay-state-title-success`},te={key:0,class:`_cppay-state-hash-container`},ne={class:`_cppay-state-label`},re={class:`_cppay-hash-row`},ie={class:`_cppay-state-hash`},ae=[`title`],oe={key:1,class:`_cppay-success-details`},se={class:`_cppay-detail-item`},ce={class:`_cppay-detail-label`},le={class:`_cppay-detail-value`},ue={class:`_cppay-detail-item`},de={class:`_cppay-detail-label`},fe={class:`_cppay-detail-value`},pe={class:`_cppay-detail-item`},me={class:`_cppay-detail-label`},he={class:`_cppay-detail-value`},ge={class:`_cppay-detail-item`},_e={class:`_cppay-detail-label`},ve={class:`_cppay-detail-value`},ye={key:0,class:`_cppay-detail-item`},be={class:`_cppay-detail-label`},xe={class:`_cppay-detail-value`},Se={class:`_cppay-detail-item`},Ce={class:`_cppay-detail-label`},we={class:`_cppay-detail-value _cppay-detail-id`},Te={class:`_cppay-state-container`},Ee={class:`_cppay-state-title _cppay-state-title-expired`},De={class:`_cppay-state-message`},Oe=[`disabled`],ke={class:`_cppay-state-container`},Ae={class:`_cppay-state-title _cppay-state-title-error`},je={class:`_cppay-state-message`},Me=[`disabled`],Ne={class:`_cppay-state-container`},Pe={class:`_cppay-state-title _cppay-state-title-failed`},Fe={class:`_cppay-state-message`},Ie=[`disabled`],Le={key:4},Re={class:`_cppay-section`},ze={class:`_cppay-label`},f={class:`_cppay-grid`},p=[`onClick`],m=[`src`,`alt`],Be={class:`_cppay-section`},Ve={class:`_cppay-label`},He={class:`_cppay-grid`},Ue=[`onClick`],We=[`src`,`alt`],Ge={class:`_cppay-section`},Ke={class:`_cppay-price-box`},qe={class:`_cppay-price-row`},Je={class:`_cppay-price-label`},Ye={class:`_cppay-price-amount`},Xe={class:`_cppay-price-main`},Ze={class:`_cppay-price-sub`},Qe={class:`_cppay-section`},$e={class:`_cppay-error-tooltip`},et={key:0,class:`_cppay-error-tooltip-full`},tt=[`disabled`],nt={key:5},rt={class:`_cppay-qr-container`},it={class:`_cppay-qr-code`},at=[`src`],ot={class:`_cppay-section`},st={key:0,class:`_cppay-info-box`},ct={class:`_cppay-info-flex-container`},lt={class:`_cppay-info-flex-child`},ut={class:`_cppay-info-label`},dt={class:`_cppay-info-value _cppay-info-value-flex`},ft={key:0},pt={class:`_cppay-info-box`},mt={class:`_cppay-info-flex-child`},ht={class:`_cppay-info-label _cppay-info-label-flex`},gt={key:0,class:`_cppay-countdown`},_t={class:`_cppay-address-row`},vt={key:0},yt=[`title`],bt={key:0,class:`_cppay-copy-icon`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,"stroke-width":`2`},xt={key:1,class:`_cppay-copy-icon`,viewBox:`0 0 24 24`,fill:`currentColor`},St={key:1,class:`_cppay-info-box _cppay-subscription-box`},Ct={class:`_cppay-info-label _cppay-subscription-label`},wt={class:`_cppay-info-value _cppay-subscription-message`},Tt={class:`_cppay-error-tooltip`},Et={key:0,class:`_cppay-error-tooltip-full`},Dt={key:1,class:`_cppay-section`},Ot=[`disabled`],kt=[`disabled`],At=[`disabled`,`title`],jt={class:`_cppay-wallet-address-text`},Mt={class:`_cppay-section`},Nt=[`disabled`],Pt={class:`_cppay-section`},Ft=[`disabled`],h=(0,n.defineComponent)({__name:`PaymentContent`,props:{apikey:{},ott:{},orderId:{},amount:{},plain:{},intervalDays:{},remark:{},slots:{},locale:{}},emits:[`update:paymentStep`,`success`,`expired`,`failed`,`error`],setup(h,{emit:g}){let _=h,v=g,y=(0,n.computed)(()=>e.t(_.locale)),b=(0,n.computed)(()=>new t.t(_.apikey,_.ott)),x=(0,n.ref)(`select`),S=(0,n.ref)(!1),C=(0,n.computed)(()=>x.value===`checking`),w=(0,n.ref)(),T=(0,n.ref)([]),E=(0,n.ref)(),D=(0,n.ref)(),O=(0,n.ref)(),k=(0,n.ref)(),A=(0,n.ref)(!1),j=(0,n.ref)(),M=(0,n.ref)(``),N=(0,n.ref)(!1),P=(0,n.ref)(!1),F=(0,n.shallowRef)(null),I=(0,n.ref)(null),L=(0,n.ref)(null),R=(0,n.ref)(null),z=(0,n.ref)(``),It=()=>{typeof window<`u`&&!F.value&&(F.value=(0,c.createAppKit)({debug:!1,enableNetworkSwitch:!1,adapters:[new l.EthersAdapter],projectId:`8d2e1854d3f1782e45aa15fbd8938894`,allowUnsupportedChain:!0,networks:[s.mainnet,s.bsc,s.polygon,s.arbitrum,s.optimism,s.base],metadata:{name:`Cppay`,description:`Cppay Payment Gateway`,url:window.location.origin,icons:[`https://cppay.com/icon.png`]},features:{analytics:!1}}),k.value=F.value.getAddress(),j.value=F.value.getProvider(`eip155`),F.value.subscribeAccount(e=>{e.isConnected?k.value=e.address:(k.value=void 0,j.value=void 0)}),F.value.subscribeProviders(e=>{j.value=e?.eip155}))};(0,n.watch)(x,e=>{v(`update:paymentStep`,e)});let B=async()=>{try{A.value=!0,w.value=void 0,F.value&&await F.value.open()}catch(e){w.value=e instanceof Error?e.message:y.value.walletConnectionFailed,v(`error`,e)}finally{A.value=!1}},V=(0,n.computed)(()=>T.value.find(e=>e.chain===E.value)),H=(0,n.computed)(()=>V.value?.tokens||[]),U=(0,n.computed)(()=>H.value.find(e=>e.symbol===D.value)),W=e=>[`USDT`,`USDC`,`BUSD`,`DAI`,`TUSD`,`USDD`,`FDUSD`].includes(e.toUpperCase())?2:6,G=(e,t)=>{let n=parseFloat(e);return isNaN(n)?`0`:n.toFixed(t).replace(/\.?0+$/,``)},Lt=e=>{if(e<=0)return y.value.expired;let t=Math.floor(e/3600),n=Math.floor(e%3600/60),r=e%60,i=e=>e.toString().padStart(2,`0`);return t>0?`${t}:${i(n)}:${i(r)}`:`${n}:${i(r)}`},K=e=>{L.value&&clearInterval(L.value);let t=()=>{if(x.value===`checking`){q();return}let t=e-Math.floor(Date.now()/1e3);M.value=Lt(t),t<=0&&q()};t(),L.value=setInterval(t,1e3)},q=()=>{L.value&&=(clearInterval(L.value),null)},J=(0,n.computed)(()=>{if(!D.value||!U.value)return`0`;let e=parseFloat(U.value.price);if(isNaN(e)||e===0)return`0`;let t=W(D.value);return G((parseFloat(_.amount)/e).toFixed(t),t)}),Rt=async()=>{try{S.value=!0,w.value=void 0,T.value=await b.value.getSupportedChains(),T.value.length>0&&(E.value=T.value[0].chain)}catch(e){w.value=e instanceof Error?e.message:y.value.loadPaymentNetworkFailed,v(`error`,e)}finally{S.value=!1}},Y=async e=>{if(j.value)try{await j.value.request({method:`wallet_switchEthereumChain`,params:[{chainId:`0x${e.toString(16)}`}]})}catch(e){throw e.code===4902?Error(y.value.pleaseAddNetwork):e}},zt=async()=>{if(!(!k.value||!j.value||!R.value||!U.value||!V.value))try{S.value=!0;let e=R.value;await Y(V.value.chainId);let t=(0,o.createWalletClient)({account:k.value,transport:(0,o.custom)(j.value)});if(U.value.address){let n=await t.writeContract({address:U.value.address,abi:[{name:`transfer`,type:`function`,stateMutability:`nonpayable`,inputs:[{name:`to`,type:`address`},{name:`amount`,type:`uint256`}],outputs:[{type:`bool`}]}],functionName:`transfer`,args:[e.receiveAddress,(0,o.parseUnits)(e.paymentAmount,U.value.decimals)],chain:null});console.log(`转账交易哈希:`,n),z.value=n}else{let n=await t.sendTransaction({to:e.receiveAddress,value:(0,o.parseUnits)(e.paymentAmount,U.value.decimals),chain:null});console.log(`转账交易哈希:`,n),z.value=n}S.value=!1,x.value=`checking`,Z({paymentId:e.paymentId})}catch(e){console.error(`钱包支付失败:`,e),w.value=e instanceof Error?e.message:y.value.walletPaymentFailed,v(`error`,e),S.value=!1}},Bt=async()=>{if(!(!k.value||!j.value||!R.value||!U.value||!V.value))try{let e=R.value;await Y(V.value.chainId);let t=(0,o.createWalletClient)({account:k.value,transport:(0,o.custom)(j.value)});if(!U.value.address)throw Error(y.value.subscriptionDoesNotSupportNative);let n=await t.writeContract({address:U.value.address,abi:[{name:`approve`,type:`function`,stateMutability:`nonpayable`,inputs:[{name:`spender`,type:`address`},{name:`amount`,type:`uint256`}],outputs:[{type:`bool`}]}],functionName:`approve`,args:[e.spenderAddress,(0,o.parseUnits)(e.approveAmount,U.value.decimals)],chain:null});console.log(`授权交易哈希:`,n),z.value=n,S.value=!1,x.value=`checking`,Z({subscriptionId:e.subscriptionId})}catch(e){console.error(`钱包授权失败:`,e),w.value=e instanceof Error?e.message:y.value.walletPaymentFailed,v(`error`,e),S.value=!1}},Vt=async()=>{if(!k.value){w.value=y.value.pleaseConnectWallet,v(`error`,Error(y.value.pleaseConnectWallet));return}_.plain===`instant`?await zt():_.plain===`subscription`&&await Bt()},Ht=async()=>{if(!(!E.value||!D.value))try{w.value=void 0;let e=``;if(_.plain===`instant`)R.value=await b.value.createOnetimePayment({paymentChain:E.value,paymentToken:D.value,orderId:_.orderId,amount:J.value,remark:_.remark}),e=`${E.value.toLowerCase()}:${R.value.receiveAddress}?amount=${R.value.paymentAmount}`,K(R.value.expireAt),Q(R.value.paymentId,`instant`);else if(_.plain===`subscription`){if(!_.intervalDays)throw Error(`Invalid Renewal Days: ${_.intervalDays??``}`);R.value=await b.value.createSubscriptionPayment({paymentChain:E.value,paymentToken:D.value,orderId:_.orderId,amountOfUsd:J.value,intervalDays:_.intervalDays}),e=`${E.value.toLowerCase()}:${R.value.spenderAddress}?amount=${R.value.approveAmount}`,K(R.value.expireAt),Q(R.value.subscriptionId,`subscription`)}x.value=`payment`,O.value=await r.toDataURL(e,{width:200,margin:2,errorCorrectionLevel:`H`})}catch(e){w.value=e instanceof Error?e.message:y.value.createPaymentFailed,v(`error`,e)}},X=()=>{R.value&&(w.value=void 0,x.value=`checking`,_.plain===`instant`?Z({paymentId:R.value.paymentId}):_.plain===`subscription`&&Z({subscriptionId:R.value.subscriptionId}))},Z=e=>{I.value?.unsubscribe();let t=()=>(0,i.defer)(()=>_.plain===`subscription`?b.value.checkSubscriptionPaymentStatus(e):b.value.checkOnetimePaymentStatus(e)).pipe((0,a.timeout)(15e3),(0,a.retry)({delay:2e3}));I.value=t().pipe((0,a.expand)(e=>e.status===`pending`?(0,i.timer)(2e3).pipe((0,a.switchMap)(()=>t())):i.EMPTY),(0,a.tap)(e=>{if(!R.value&&_.plain===`instant`){let t=e;R.value={paymentId:t.paymentId,orderId:t.orderId,paymentChain:t.chain,paymentToken:t.token,paymentAmount:t.payAmount,receiveAddress:t.receiveAddress,expireAt:t.expireAt},E.value=t.chain,D.value=t.token,K(t.expireAt);let n=`${t.chain.toLowerCase()}:${t.receiveAddress}?amount=${t.payAmount}`;r.toDataURL(n,{width:200,margin:2,errorCorrectionLevel:`H`}).then(e=>{O.value=e,x.value=`payment`}).catch(e=>{console.error(`生成二维码失败:`,e),x.value=`select`})}if(!R.value&&_.plain===`subscription`){let t=e;R.value={subscriptionId:t.subscriptionId,orderId:t.orderId,paymentChain:t.chain,paymentToken:t.token,approveAmount:t.approveAmount,spenderAddress:t.approvedAddress,expireAt:t.expireAt,intervalDays:0,amountOfUsd:t.amountOfUsd},E.value=t.chain,D.value=t.token,K(t.expireAt);let n=`${t.chain.toLowerCase()}:${t.approvedAddress}?amount=${t.approveAmount}`;r.toDataURL(n,{width:200,margin:2,errorCorrectionLevel:`H`}).then(e=>{O.value=e,x.value=`payment`}).catch(e=>{console.error(`生成二维码失败:`,e),x.value=`select`})}(e.status===`paid`||e.status===`approved`)&&(x.value=`success`,$(),v(`success`,e)),e.status===`expired`&&(x.value=`expired`,$(),v(`expired`,e)),e.status===`failed`&&(x.value=`failed`,$(),v(`failed`,e))})).subscribe({error:e=>{if(R.value){let t=e instanceof Error?e.message:y.value.checkPaymentStatusFailed;x.value=`error`,w.value=t,$(),v(`error`,e)}},complete:()=>{I.value?.unsubscribe()}})},Ut=async()=>{if(!R.value)return;let e=_.plain===`subscription`?R.value.spenderAddress:R.value.receiveAddress;if(e)try{await navigator.clipboard.writeText(e),N.value=!0,setTimeout(()=>{N.value=!1},2e3)}catch(e){console.error(`复制失败:`,e)}};(0,n.watch)(H,e=>{e.length>0&&(D.value=e[0].symbol)}),(0,n.onMounted)(()=>{It(),T.value.length||Rt(),Gt()}),(0,n.onUnmounted)(()=>{I.value?.unsubscribe(),q()});let Wt=async()=>{if(z.value)try{await navigator.clipboard.writeText(z.value);let e=N.value;N.value=!0,setTimeout(()=>{N.value=e},2e3)}catch(e){console.error(`复制失败:`,e)}},Q=(e,t)=>{if(typeof window>`u`)return;let n=new URL(window.location.href),r=t===`subscription`?`subscriptionId`:`paymentId`;n.searchParams.set(r,e),window.history.replaceState({},``,n.toString())},$=()=>{if(typeof window>`u`)return;let e=new URL(window.location.href);e.searchParams.delete(`paymentId`),e.searchParams.delete(`subscriptionId`),window.history.replaceState({},``,e.toString())},Gt=async()=>{if(typeof window>`u`)return;let e=new URL(window.location.href);if(_.plain===`instant`){let t=e.searchParams.get(`paymentId`);t&&(x.value=`payment`,Z({paymentId:t}))}if(_.plain===`subscription`){let t=e.searchParams.get(`subscriptionId`);t&&(x.value=`payment`,Z({subscriptionId:t}))}};return(e,t)=>((0,n.openBlock)(),(0,n.createElementBlock)(`div`,u,[x.value===`success`?(0,n.renderSlot)(e.$slots,`success`,{key:0},()=>[(0,n.createElementVNode)(`div`,d,[t[9]||=(0,n.createElementVNode)(`div`,{class:`_cppay-state-success-bg`},[(0,n.createElementVNode)(`div`,{class:`_cppay-state-success-icon`},`✓`)],-1),(0,n.createElementVNode)(`h3`,ee,(0,n.toDisplayString)(h.plain===`subscription`?y.value.authorizationSuccess:y.value.paymentSuccess),1),z.value?((0,n.openBlock)(),(0,n.createElementBlock)(`div`,te,[(0,n.createElementVNode)(`div`,ne,(0,n.toDisplayString)(y.value.transactionHash),1),(0,n.createElementVNode)(`div`,re,[(0,n.createElementVNode)(`code`,ie,(0,n.toDisplayString)(z.value.slice(0,18))+`...`+(0,n.toDisplayString)(z.value.slice(-18)),1),(0,n.createElementVNode)(`button`,{onClick:Wt,class:`_cppay-state-copy-btn`,title:y.value.copyAddress},[...t[8]||=[(0,n.createElementVNode)(`svg`,{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,"stroke-width":`2`},[(0,n.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`}),(0,n.createElementVNode)(`rect`,{x:`8`,y:`2`,width:`8`,height:`4`,rx:`1`,ry:`1`})],-1)]],8,ae)])])):(0,n.createCommentVNode)(``,!0),R.value?((0,n.openBlock)(),(0,n.createElementBlock)(`div`,oe,[(0,n.createElementVNode)(`div`,se,[(0,n.createElementVNode)(`span`,ce,(0,n.toDisplayString)(y.value.orderId),1),(0,n.createElementVNode)(`span`,le,(0,n.toDisplayString)(R.value.orderId),1)]),(0,n.createElementVNode)(`div`,ue,[(0,n.createElementVNode)(`span`,de,(0,n.toDisplayString)(h.plain===`subscription`?y.value.authorizationAmount:y.value.paymentAmount),1),(0,n.createElementVNode)(`span`,fe,(0,n.toDisplayString)(h.plain===`subscription`?`${G(R.value.approveAmount,W(D.value))} ${D.value}`:`${G(R.value.paymentAmount,W(D.value))} ${D.value}`),1)]),(0,n.createElementVNode)(`div`,pe,[(0,n.createElementVNode)(`span`,me,(0,n.toDisplayString)(y.value.paymentNetwork),1),(0,n.createElementVNode)(`span`,he,(0,n.toDisplayString)(R.value.paymentChain),1)]),(0,n.createElementVNode)(`div`,ge,[(0,n.createElementVNode)(`span`,_e,(0,n.toDisplayString)(y.value.paymentToken),1),(0,n.createElementVNode)(`span`,ve,(0,n.toDisplayString)(R.value.paymentToken),1)]),h.plain===`subscription`?((0,n.openBlock)(),(0,n.createElementBlock)(`div`,ye,[(0,n.createElementVNode)(`span`,be,(0,n.toDisplayString)(y.value.renewalInterval),1),(0,n.createElementVNode)(`span`,xe,(0,n.toDisplayString)(R.value.intervalDays)+` `+(0,n.toDisplayString)(y.value.days),1)])):(0,n.createCommentVNode)(``,!0),(0,n.createElementVNode)(`div`,Se,[(0,n.createElementVNode)(`span`,Ce,(0,n.toDisplayString)(h.plain===`subscription`?y.value.subscriptionId:y.value.paymentId),1),(0,n.createElementVNode)(`span`,we,(0,n.toDisplayString)(h.plain===`subscription`?R.value.subscriptionId:R.value.paymentId),1)])])):(0,n.createCommentVNode)(``,!0)])]):x.value===`expired`?(0,n.renderSlot)(e.$slots,`expired`,{key:1},()=>[(0,n.createElementVNode)(`div`,Te,[t[10]||=(0,n.createElementVNode)(`div`,{class:`_cppay-state-expired-bg`},[(0,n.createElementVNode)(`div`,{class:`_cppay-state-expired-icon`},`⏰`)],-1),(0,n.createElementVNode)(`h3`,Ee,(0,n.toDisplayString)(y.value.paymentExpired),1),(0,n.createElementVNode)(`p`,De,(0,n.toDisplayString)(y.value.pleaseInitiatePaymentAgain),1),(0,n.createElementVNode)(`button`,{onClick:t[0]||=()=>{x.value=`select`,$()},disabled:S.value||C.value,class:`_cppay-btn _cppay-btn-primary _cppay-state-btn`},(0,n.toDisplayString)(y.value.returnButton),9,Oe)])]):x.value===`error`?(0,n.renderSlot)(e.$slots,`error`,{key:2},()=>[(0,n.createElementVNode)(`div`,ke,[t[11]||=(0,n.createElementVNode)(`div`,{class:`_cppay-state-error-bg`},[(0,n.createElementVNode)(`div`,{class:`_cppay-state-error-icon`},`!`)],-1),(0,n.createElementVNode)(`h3`,Ae,(0,n.toDisplayString)(w.value||y.value.error),1),(0,n.createElementVNode)(`p`,je,(0,n.toDisplayString)(y.value.checkStatusFailed),1),(0,n.createElementVNode)(`button`,{onClick:t[1]||=()=>{x.value=`select`,$()},disabled:S.value||C.value,class:`_cppay-btn _cppay-btn-primary _cppay-state-btn`},(0,n.toDisplayString)(y.value.returnButton),9,Me)])]):x.value===`failed`?(0,n.renderSlot)(e.$slots,`failed`,{key:3},()=>[(0,n.createElementVNode)(`div`,Ne,[t[12]||=(0,n.createElementVNode)(`div`,{class:`_cppay-state-failed-bg`},[(0,n.createElementVNode)(`div`,{class:`_cppay-state-failed-icon`},`✕`)],-1),(0,n.createElementVNode)(`h3`,Pe,(0,n.toDisplayString)(y.value.paymentFailed),1),(0,n.createElementVNode)(`p`,Fe,(0,n.toDisplayString)(y.value.pleaseInitiatePaymentAgain),1),(0,n.createElementVNode)(`button`,{onClick:t[2]||=()=>{x.value=`select`,$()},disabled:S.value||C.value,class:`_cppay-btn _cppay-btn-primary _cppay-state-btn`},(0,n.toDisplayString)(y.value.returnButton),9,Ie)])]):x.value===`select`?((0,n.openBlock)(),(0,n.createElementBlock)(`div`,Le,[(0,n.renderSlot)(e.$slots,`choose-top`),(0,n.createElementVNode)(`div`,Re,[(0,n.createElementVNode)(`label`,ze,(0,n.toDisplayString)(y.value.paymentNetwork),1),(0,n.createElementVNode)(`div`,f,[((0,n.openBlock)(!0),(0,n.createElementBlock)(n.Fragment,null,(0,n.renderList)(T.value,e=>((0,n.openBlock)(),(0,n.createElementBlock)(`button`,{key:e.chain,onClick:t=>E.value=e.chain,class:(0,n.normalizeClass)([`_cppay-select-btn`,{"_cppay-selected":E.value===e.chain}])},[e.icon?((0,n.openBlock)(),(0,n.createElementBlock)(`img`,{key:0,src:e.icon,alt:e.chain},null,8,m)):(0,n.createCommentVNode)(``,!0),(0,n.createElementVNode)(`span`,null,(0,n.toDisplayString)(e.chain),1)],10,p))),128))])]),(0,n.createElementVNode)(`div`,Be,[(0,n.createElementVNode)(`label`,Ve,(0,n.toDisplayString)(y.value.paymentToken),1),(0,n.createElementVNode)(`div`,He,[((0,n.openBlock)(!0),(0,n.createElementBlock)(n.Fragment,null,(0,n.renderList)(H.value,e=>((0,n.openBlock)(),(0,n.createElementBlock)(`button`,{key:e.symbol,onClick:t=>D.value=e.symbol,class:(0,n.normalizeClass)([`_cppay-select-btn`,{"_cppay-selected":D.value===e.symbol}])},[e.icon?((0,n.openBlock)(),(0,n.createElementBlock)(`img`,{key:0,src:e.icon,alt:e.symbol},null,8,We)):(0,n.createCommentVNode)(``,!0),(0,n.createElementVNode)(`span`,null,(0,n.toDisplayString)(e.symbol),1)],10,Ue))),128))])]),(0,n.renderSlot)(e.$slots,`choose-bottom`),(0,n.createElementVNode)(`div`,Ge,[(0,n.createElementVNode)(`div`,Ke,[(0,n.createElementVNode)(`div`,qe,[(0,n.createElementVNode)(`span`,Je,(0,n.toDisplayString)(y.value.paymentAmount),1),(0,n.createElementVNode)(`div`,Ye,[(0,n.createElementVNode)(`div`,Xe,(0,n.toDisplayString)(J.value??`-`)+` `+(0,n.toDisplayString)(D.value??``),1),(0,n.createElementVNode)(`div`,Ze,`≈ $`+(0,n.toDisplayString)(h.amount),1)])])])]),(0,n.createElementVNode)(`div`,Qe,[w.value?((0,n.openBlock)(),(0,n.createElementBlock)(`div`,{key:0,class:`_cppay-error-tooltip-wrapper`,onMouseenter:t[3]||=e=>P.value=!0,onMouseleave:t[4]||=e=>P.value=!1},[(0,n.createElementVNode)(`div`,$e,[t[13]||=(0,n.createElementVNode)(`svg`,{viewBox:`0 0 20 20`,fill:`currentColor`},[(0,n.createElementVNode)(`path`,{"fill-rule":`evenodd`,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`,"clip-rule":`evenodd`})],-1),(0,n.createElementVNode)(`span`,null,(0,n.toDisplayString)(w.value),1)]),P.value?((0,n.openBlock)(),(0,n.createElementBlock)(`div`,et,(0,n.toDisplayString)(w.value),1)):(0,n.createCommentVNode)(``,!0)],32)):(0,n.createCommentVNode)(``,!0),(0,n.createElementVNode)(`button`,{onClick:Ht,disabled:!E.value||!D.value||S.value,class:`_cppay-btn _cppay-btn-primary`},(0,n.toDisplayString)(S.value?y.value.processing:y.value.continuePayment),9,tt)])])):((0,n.openBlock)(),(0,n.createElementBlock)(`div`,nt,[(0,n.createElementVNode)(`div`,rt,[(0,n.createElementVNode)(`div`,it,[O.value?((0,n.openBlock)(),(0,n.createElementBlock)(`img`,{key:0,src:O.value,alt:`Payment QR Code`,class:`_cppay-qr-image`},null,8,at)):(0,n.createCommentVNode)(``,!0)])]),(0,n.createElementVNode)(`div`,ot,[U.value?((0,n.openBlock)(),(0,n.createElementBlock)(`div`,st,[(0,n.createElementVNode)(`div`,ct,[(0,n.createElementVNode)(`div`,lt,[(0,n.createElementVNode)(`div`,ut,(0,n.toDisplayString)(h.plain===`subscription`?y.value.authorizationAmount:y.value.paymentAmount),1),(0,n.createElementVNode)(`div`,dt,[R.value?((0,n.openBlock)(),(0,n.createElementBlock)(`span`,ft,(0,n.toDisplayString)(h.plain===`subscription`?`${G(R.value.approveAmount,W(U.value.symbol))} ${U.value.symbol}`:`${G(R.value.paymentAmount,W(U.value.symbol))} ${U.value.symbol}`),1)):(0,n.createCommentVNode)(``,!0),(0,n.createElementVNode)(`span`,null,`≈ $`+(0,n.toDisplayString)(h.amount),1)])])])])):(0,n.createCommentVNode)(``,!0),(0,n.createElementVNode)(`div`,pt,[(0,n.createElementVNode)(`div`,mt,[(0,n.createElementVNode)(`div`,ht,[(0,n.createElementVNode)(`span`,null,(0,n.toDisplayString)(h.plain===`subscription`?y.value.authorizationContractAddress:y.value.paymentAddress),1),M.value?((0,n.openBlock)(),(0,n.createElementBlock)(`span`,gt,`⏰ `+(0,n.toDisplayString)(M.value),1)):(0,n.createCommentVNode)(``,!0)]),(0,n.createElementVNode)(`div`,_t,[R.value?((0,n.openBlock)(),(0,n.createElementBlock)(`code`,vt,(0,n.toDisplayString)(h.plain===`subscription`?R.value.spenderAddress:R.value.receiveAddress),1)):(0,n.createCommentVNode)(``,!0),(0,n.createElementVNode)(`button`,{onClick:Ut,class:(0,n.normalizeClass)([`_cppay-copy-btn`,{"_cppay-copy-success":N.value}]),title:N.value?y.value.copied:y.value.copyAddress},[N.value?((0,n.openBlock)(),(0,n.createElementBlock)(`svg`,xt,[...t[15]||=[(0,n.createElementVNode)(`path`,{d:`M9 16.17L4.83 12l-1.42 1.41L9 19 21 7l-1.41-1.41z`},null,-1)]])):((0,n.openBlock)(),(0,n.createElementBlock)(`svg`,bt,[...t[14]||=[(0,n.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),(0,n.createElementVNode)(`rect`,{x:`8`,y:`2`,width:`8`,height:`4`,rx:`1`,ry:`1`},null,-1)]]))],10,yt)])])]),h.plain===`subscription`?((0,n.openBlock)(),(0,n.createElementBlock)(`div`,St,[(0,n.createElementVNode)(`div`,Ct,(0,n.toDisplayString)(y.value.subscriptionNotice),1),(0,n.createElementVNode)(`div`,wt,(0,n.toDisplayString)(y.value.subscriptionNoticeMessage),1)])):(0,n.createCommentVNode)(``,!0)]),w.value?((0,n.openBlock)(),(0,n.createElementBlock)(`div`,{key:0,class:`_cppay-error-tooltip-wrapper`,onMouseenter:t[5]||=e=>P.value=!0,onMouseleave:t[6]||=e=>P.value=!1},[(0,n.createElementVNode)(`div`,Tt,[t[16]||=(0,n.createElementVNode)(`svg`,{viewBox:`0 0 20 20`,fill:`currentColor`},[(0,n.createElementVNode)(`path`,{"fill-rule":`evenodd`,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`,"clip-rule":`evenodd`})],-1),(0,n.createElementVNode)(`span`,null,(0,n.toDisplayString)(w.value),1)]),P.value?((0,n.openBlock)(),(0,n.createElementBlock)(`div`,Et,(0,n.toDisplayString)(w.value),1)):(0,n.createCommentVNode)(``,!0)],32)):(0,n.createCommentVNode)(``,!0),C.value?(0,n.createCommentVNode)(``,!0):((0,n.openBlock)(),(0,n.createElementBlock)(`div`,Dt,[k.value?((0,n.openBlock)(),(0,n.createElementBlock)(n.Fragment,{key:1},[(0,n.createElementVNode)(`button`,{onClick:Vt,disabled:S.value,class:`_cppay-btn _cppay-btn-primary`},(0,n.toDisplayString)(S.value?h.plain===`subscription`?y.value.authorizing:y.value.processing:(h.plain,y.value.walletPay)),9,kt),(0,n.createElementVNode)(`button`,{onClick:B,disabled:S.value,class:`_cppay-btn _cppay-wallet-address-btn`,title:y.value.clickToModifyWallet},[(0,n.createElementVNode)(`span`,jt,(0,n.toDisplayString)(k.value.slice(0,10))+`...`+(0,n.toDisplayString)(k.value.slice(-4)),1),t[17]||=(0,n.createElementVNode)(`svg`,{class:`_cppay-wallet-arrow`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,"stroke-width":`2`},[(0,n.createElementVNode)(`polyline`,{points:`6 9 12 15 18 9`})],-1)],8,At)],64)):((0,n.openBlock)(),(0,n.createElementBlock)(`button`,{key:0,onClick:B,disabled:A.value,class:`_cppay-btn _cppay-btn-secondary _cppay-connect-wallet-btn`},[(0,n.createElementVNode)(`span`,null,(0,n.toDisplayString)(A.value?y.value.processing:y.value.connectWallet),1)],8,Ot))])),(0,n.createElementVNode)(`div`,Mt,[(0,n.createElementVNode)(`button`,{onClick:X,disabled:C.value,class:`_cppay-btn _cppay-btn-primary`},[C.value?((0,n.openBlock)(),(0,n.createElementBlock)(n.Fragment,{key:0},[t[18]||=(0,n.createElementVNode)(`svg`,{class:`_cppay-spinner`,viewBox:`0 0 24 24`,fill:`none`,xmlns:`http://www.w3.org/2000/svg`},[(0,n.createElementVNode)(`circle`,{cx:`12`,cy:`12`,r:`10`,stroke:`currentColor`,"stroke-width":`3`,"stroke-opacity":`0.25`}),(0,n.createElementVNode)(`path`,{d:`M12 2a10 10 0 0 1 10 10`,stroke:`currentColor`,"stroke-width":`3`,"stroke-linecap":`round`})],-1),(0,n.createTextVNode)(` `+(0,n.toDisplayString)(y.value.checking),1)],64)):((0,n.openBlock)(),(0,n.createElementBlock)(n.Fragment,{key:1},[(0,n.createTextVNode)((0,n.toDisplayString)(y.value.completedPayment),1)],64))],8,Nt)]),t[19]||=(0,n.createElementVNode)(`hr`,{class:`_cppay-divider`},null,-1),(0,n.createElementVNode)(`div`,Pt,[(0,n.createElementVNode)(`button`,{onClick:t[7]||=()=>{x.value=`select`,$()},disabled:S.value||C.value,class:`_cppay-btn _cppay-btn-text`},(0,n.toDisplayString)(y.value.changePaymentMethod),9,Ft)])]))]))}}),g=h,_={class:`_cppay-dialog`},v={class:`_cppay-header`},y={class:`_cppay-title`},b=[`disabled`],x=(0,n.defineComponent)({__name:`PaymentDialog`,props:{modelValue:{type:Boolean},ott:{},apikey:{},orderId:{},amount:{},plain:{},intervalDays:{},locale:{}},emits:[`update:modelValue`,`success`,`expired`,`failed`,`error`],setup(t,{emit:r}){let i=t,a=r,o=(0,n.computed)(()=>e.t(i.locale)),s=(0,n.ref)(`select`),c=(0,n.computed)(()=>s.value!==`checking`);(0,n.watch)(()=>i.modelValue,e=>{e||(s.value=`select`)});let l=e=>{s.value=e};(0,n.onMounted)(()=>{let e=e=>{e.key===`Escape`&&i.modelValue&&!c.value&&u()};return window.addEventListener(`keydown`,e),()=>{window.removeEventListener(`keydown`,e)}});let u=()=>{c.value&&a(`update:modelValue`,!1)},d=()=>{switch(s.value){case`success`:return o.value.paymentResult;case`expired`:return o.value.paymentExpired;case`failed`:return o.value.paymentFailed;case`error`:return o.value.error;case`payment`:return o.value.completePayment;default:return o.value.selectPaymentMethod}};return(e,r)=>t.modelValue?((0,n.openBlock)(),(0,n.createElementBlock)(`div`,{key:0,class:`_cppay-overlay`,onClick:r[4]||=e=>e.target===e.currentTarget&&u()},[(0,n.createElementVNode)(`div`,_,[(0,n.createElementVNode)(`div`,v,[(0,n.createElementVNode)(`h2`,y,(0,n.toDisplayString)(d()),1),(0,n.createElementVNode)(`button`,{onClick:u,disabled:!c.value,class:`_cppay-close-btn`},[...r[5]||=[(0,n.createElementVNode)(`svg`,{fill:`none`,stroke:`currentColor`,viewBox:`0 0 24 24`},[(0,n.createElementVNode)(`path`,{"stroke-linecap":`round`,"stroke-linejoin":`round`,"stroke-width":`2`,d:`M6 18L18 6M6 6l12 12`})],-1)]],8,b)]),t.modelValue?((0,n.openBlock)(),(0,n.createBlock)(g,{key:0,apikey:t.apikey,ott:t.ott,orderId:t.orderId,amount:t.amount,plain:t.plain,intervalDays:t.intervalDays,locale:t.locale,"onUpdate:paymentStep":l,onSuccess:r[0]||=e=>a(`success`,e),onExpired:r[1]||=e=>a(`expired`,e),onFailed:r[2]||=e=>a(`failed`,e),onError:r[3]||=e=>a(`error`,e)},{"choose-top":(0,n.withCtx)(()=>[(0,n.renderSlot)(e.$slots,`choose-top`)]),"choose-bottom":(0,n.withCtx)(()=>[(0,n.renderSlot)(e.$slots,`choose-bottom`)]),success:(0,n.withCtx)(()=>[(0,n.renderSlot)(e.$slots,`success`)]),failed:(0,n.withCtx)(()=>[(0,n.renderSlot)(e.$slots,`failed`)]),error:(0,n.withCtx)(()=>[(0,n.renderSlot)(e.$slots,`error`)]),expired:(0,n.withCtx)(()=>[(0,n.renderSlot)(e.$slots,`expired`)]),_:3},8,[`apikey`,`ott`,`orderId`,`amount`,`plain`,`intervalDays`,`locale`])):(0,n.createCommentVNode)(``,!0)])])):(0,n.createCommentVNode)(``,!0)}}),S=x,C=(0,n.ref)({open:!1,options:null});const w=e=>{C.value.options=e,C.value.open=!0},T=()=>{C.value.open=!1};var E=()=>{C.value.open=!1},D=e=>{C.value.options?.onSuccess?.(e)},O=e=>{C.value.options?.onExpired?.(e)},k=e=>{C.value.options?.onFailed?.(e)},A=e=>{C.value.options?.onError?.(e)};const j={install(e){e.config.globalProperties.$showPayment=w,e.config.globalProperties.$closePayment=T;let t=document.createElement(`div`);document.body.appendChild(t),(0,n.createApp)({setup(){return()=>C.value.options?(0,n.h)(S,{modelValue:C.value.open,"onUpdate:modelValue":e=>{C.value.open=e,e||E()},...C.value.options,onSuccess:D,onExpired:O,onFailed:k,onError:A}):null}}).mount(t)}},M=()=>({showPayment:w,closePayment:T});e.n(e.r),exports.CppayPlugin=j,exports.PaymentContent=g,exports.PaymentDialog=S,exports.showPayment=w,exports.useCppayPayment=M;
|
|
1
|
+
const e=require(`./locales-Cm9yIiVb.cjs`),t=require(`./cppay-DuOJqlpA.cjs`);let n=require(`vue`),r=require(`qrcode`);r=e.i(r);let i=require(`rxjs`),a=require(`rxjs/operators`),o=require(`viem`),s=require(`viem/chains`),c=require(`@reown/appkit`),l=require(`@reown/appkit-adapter-ethers`);var u={class:`_cppay-content`},d={class:`_cppay-state-container`},ee={class:`_cppay-state-title _cppay-state-title-success`},te={key:0,class:`_cppay-state-hash-container`},ne={class:`_cppay-state-label`},re={class:`_cppay-hash-row`},ie={class:`_cppay-state-hash`},ae=[`title`],oe={key:1,class:`_cppay-success-details`},se={class:`_cppay-detail-item`},ce={class:`_cppay-detail-label`},le={class:`_cppay-detail-value`},ue={class:`_cppay-detail-item`},de={class:`_cppay-detail-label`},fe={class:`_cppay-detail-value`},pe={class:`_cppay-detail-item`},me={class:`_cppay-detail-label`},he={class:`_cppay-detail-value`},ge={class:`_cppay-detail-item`},_e={class:`_cppay-detail-label`},ve={class:`_cppay-detail-value`},ye={key:0,class:`_cppay-detail-item`},be={class:`_cppay-detail-label`},xe={class:`_cppay-detail-value`},Se={class:`_cppay-detail-item`},Ce={class:`_cppay-detail-label`},we={class:`_cppay-detail-value _cppay-detail-id`},Te={class:`_cppay-state-container`},Ee={class:`_cppay-state-title _cppay-state-title-expired`},De={class:`_cppay-state-message`},Oe=[`disabled`],ke={class:`_cppay-state-container`},Ae={class:`_cppay-state-title _cppay-state-title-error`},je={class:`_cppay-state-message`},Me=[`disabled`],Ne={class:`_cppay-state-container`},Pe={class:`_cppay-state-title _cppay-state-title-failed`},Fe={class:`_cppay-state-message`},Ie=[`disabled`],Le={key:4},Re={class:`_cppay-section`},ze={class:`_cppay-label`},f={class:`_cppay-grid`},p=[`onClick`],m=[`src`,`alt`],Be={class:`_cppay-section`},Ve={class:`_cppay-label`},He={class:`_cppay-grid`},Ue=[`onClick`],We=[`src`,`alt`],Ge={class:`_cppay-section`},Ke={class:`_cppay-price-box`},qe={class:`_cppay-price-row`},Je={class:`_cppay-price-label`},Ye={class:`_cppay-price-amount`},Xe={class:`_cppay-price-main`},Ze={class:`_cppay-price-sub`},Qe={class:`_cppay-section`},$e={class:`_cppay-error-tooltip`},et={key:0,class:`_cppay-error-tooltip-full`},tt=[`disabled`],nt={key:5},rt={class:`_cppay-qr-container`},it={class:`_cppay-qr-code`},at=[`src`],ot={class:`_cppay-section`},st={key:0,class:`_cppay-info-box`},ct={class:`_cppay-info-flex-container`},lt={class:`_cppay-info-flex-child`},ut={class:`_cppay-info-label`},dt={class:`_cppay-info-value _cppay-info-value-flex`},ft={key:0},pt={class:`_cppay-info-box`},mt={class:`_cppay-info-flex-child`},ht={class:`_cppay-info-label _cppay-info-label-flex`},gt={key:0,class:`_cppay-countdown`},_t={class:`_cppay-address-row`},vt={key:0},yt=[`title`],bt={key:0,class:`_cppay-copy-icon`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,"stroke-width":`2`},xt={key:1,class:`_cppay-copy-icon`,viewBox:`0 0 24 24`,fill:`currentColor`},St={key:1,class:`_cppay-info-box _cppay-subscription-box`},Ct={class:`_cppay-info-label _cppay-subscription-label`},wt={class:`_cppay-info-value _cppay-subscription-message`},Tt={class:`_cppay-error-tooltip`},Et={key:0,class:`_cppay-error-tooltip-full`},Dt={key:1,class:`_cppay-section`},Ot=[`disabled`],kt=[`disabled`],At=[`disabled`,`title`],jt={class:`_cppay-wallet-address-text`},Mt={class:`_cppay-section`},Nt=[`disabled`],Pt={class:`_cppay-section`},Ft=[`disabled`],h=(0,n.defineComponent)({__name:`PaymentContent`,props:{apikey:{},ott:{},orderId:{},amount:{},plain:{},intervalDays:{},remark:{},slots:{},locale:{}},emits:[`update:paymentStep`,`success`,`expired`,`failed`,`error`],setup(h,{emit:g}){let _=h,v=g,y=(0,n.computed)(()=>e.t(_.locale)),b=(0,n.computed)(()=>new t.t(_.apikey,_.ott)),x=(0,n.ref)(`select`),S=(0,n.ref)(!1),C=(0,n.computed)(()=>x.value===`checking`),w=(0,n.ref)(),T=(0,n.ref)([]),E=(0,n.ref)(),D=(0,n.ref)(),O=(0,n.ref)(),k=(0,n.ref)(),A=(0,n.ref)(!1),j=(0,n.ref)(),M=(0,n.ref)(``),N=(0,n.ref)(!1),P=(0,n.ref)(!1),F=(0,n.shallowRef)(null),I=(0,n.ref)(null),L=(0,n.ref)(null),R=(0,n.ref)(null),z=(0,n.ref)(``),It=()=>{typeof window<`u`&&!F.value&&(F.value=(0,c.createAppKit)({debug:!1,enableNetworkSwitch:!1,adapters:[new l.EthersAdapter],projectId:`8d2e1854d3f1782e45aa15fbd8938894`,allowUnsupportedChain:!0,networks:[s.mainnet,s.bsc,s.polygon,s.arbitrum,s.optimism,s.base],metadata:{name:`Cppay`,description:`Cppay Payment Gateway`,url:window.location.origin,icons:[`https://cppay.com/icon.png`]},features:{analytics:!1}}),k.value=F.value.getAddress(),j.value=F.value.getProvider(`eip155`),F.value.subscribeAccount(e=>{e.isConnected?k.value=e.address:(k.value=void 0,j.value=void 0)}),F.value.subscribeProviders(e=>{j.value=e?.eip155}))};(0,n.watch)(x,e=>{v(`update:paymentStep`,e)});let B=async()=>{try{A.value=!0,w.value=void 0,F.value&&await F.value.open()}catch(e){w.value=e instanceof Error?e.message:y.value.walletConnectionFailed,v(`error`,e)}finally{A.value=!1}},V=(0,n.computed)(()=>T.value.find(e=>e.chain===E.value)),H=(0,n.computed)(()=>V.value?.tokens||[]),U=(0,n.computed)(()=>H.value.find(e=>e.symbol===D.value)),W=e=>[`USDT`,`USDC`,`BUSD`,`DAI`,`TUSD`,`USDD`,`FDUSD`].includes(e.toUpperCase())?2:6,G=(e,t)=>{let n=parseFloat(e);return isNaN(n)?`0`:n.toFixed(t).replace(/\.?0+$/,``)},Lt=e=>{if(e<=0)return y.value.expired;let t=Math.floor(e/3600),n=Math.floor(e%3600/60),r=e%60,i=e=>e.toString().padStart(2,`0`);return t>0?`${t}:${i(n)}:${i(r)}`:`${n}:${i(r)}`},K=e=>{L.value&&clearInterval(L.value);let t=()=>{if(x.value===`checking`){q();return}let t=e-Math.floor(Date.now()/1e3);M.value=Lt(t),t<=0&&q()};t(),L.value=setInterval(t,1e3)},q=()=>{L.value&&=(clearInterval(L.value),null)},J=(0,n.computed)(()=>{if(!D.value||!U.value)return`0`;let e=parseFloat(U.value.price);if(isNaN(e)||e===0)return`0`;let t=W(D.value);return G((parseFloat(_.amount)/e).toFixed(t),t)}),Rt=async()=>{try{S.value=!0,w.value=void 0,T.value=await b.value.getSupportedChains(),T.value.length>0&&(E.value=T.value[0].chain)}catch(e){w.value=e instanceof Error?e.message:y.value.loadPaymentNetworkFailed,v(`error`,e)}finally{S.value=!1}},Y=async e=>{if(j.value)try{await j.value.request({method:`wallet_switchEthereumChain`,params:[{chainId:`0x${e.toString(16)}`}]})}catch(e){throw e.code===4902?Error(y.value.pleaseAddNetwork):e}},zt=async()=>{if(!(!k.value||!j.value||!R.value||!U.value||!V.value))try{S.value=!0;let e=R.value;await Y(V.value.chainId);let t=(0,o.createWalletClient)({account:k.value,transport:(0,o.custom)(j.value)});if(U.value.address){let n=await t.writeContract({address:U.value.address,abi:[{name:`transfer`,type:`function`,stateMutability:`nonpayable`,inputs:[{name:`to`,type:`address`},{name:`amount`,type:`uint256`}],outputs:[{type:`bool`}]}],functionName:`transfer`,args:[e.receiveAddress,(0,o.parseUnits)(e.paymentAmount,U.value.decimals)],chain:null});console.log(`转账交易哈希:`,n),z.value=n}else{let n=await t.sendTransaction({to:e.receiveAddress,value:(0,o.parseUnits)(e.paymentAmount,U.value.decimals),chain:null});console.log(`转账交易哈希:`,n),z.value=n}S.value=!1,x.value=`checking`,Z({paymentId:e.paymentId})}catch(e){console.error(`钱包支付失败:`,e),w.value=e instanceof Error?e.message:y.value.walletPaymentFailed,v(`error`,e),S.value=!1}},Bt=async()=>{if(!(!k.value||!j.value||!R.value||!U.value||!V.value))try{let e=R.value;await Y(V.value.chainId);let t=(0,o.createWalletClient)({account:k.value,transport:(0,o.custom)(j.value)});if(!U.value.address)throw Error(y.value.subscriptionDoesNotSupportNative);let n=await t.writeContract({address:U.value.address,abi:[{name:`approve`,type:`function`,stateMutability:`nonpayable`,inputs:[{name:`spender`,type:`address`},{name:`amount`,type:`uint256`}],outputs:[{type:`bool`}]}],functionName:`approve`,args:[e.spenderAddress,(0,o.parseUnits)(e.approveAmount,U.value.decimals)],chain:null});console.log(`授权交易哈希:`,n),z.value=n,S.value=!1,x.value=`checking`,Z({subscriptionId:e.subscriptionId})}catch(e){console.error(`钱包授权失败:`,e),w.value=e instanceof Error?e.message:y.value.walletPaymentFailed,v(`error`,e),S.value=!1}},Vt=async()=>{if(!k.value){w.value=y.value.pleaseConnectWallet,v(`error`,Error(y.value.pleaseConnectWallet));return}_.plain===`instant`?await zt():_.plain===`subscription`&&await Bt()},Ht=async()=>{if(!(!E.value||!D.value))try{w.value=void 0;let e=``;if(_.plain===`instant`)R.value=await b.value.createOnetimePayment({paymentChain:E.value,paymentToken:D.value,orderId:_.orderId,amount:J.value,remark:_.remark}),e=`${E.value.toLowerCase()}:${R.value.receiveAddress}?amount=${R.value.paymentAmount}`,K(R.value.expireAt),Q(R.value.paymentId,`instant`);else if(_.plain===`subscription`){if(!_.intervalDays)throw Error(`Invalid Renewal Days: ${_.intervalDays??``}`);R.value=await b.value.createSubscriptionPayment({paymentChain:E.value,paymentToken:D.value,orderId:_.orderId,amountOfUsd:J.value,intervalDays:_.intervalDays}),e=`${E.value.toLowerCase()}:${R.value.spenderAddress}?amount=${R.value.approveAmount}`,K(R.value.expireAt),Q(R.value.subscriptionId,`subscription`)}x.value=`payment`,O.value=await r.toDataURL(e,{width:200,margin:2,errorCorrectionLevel:`H`})}catch(e){w.value=e instanceof Error?e.message:y.value.createPaymentFailed,v(`error`,e)}},X=()=>{R.value&&(w.value=void 0,x.value=`checking`,_.plain===`instant`?Z({paymentId:R.value.paymentId}):_.plain===`subscription`&&Z({subscriptionId:R.value.subscriptionId}))},Z=e=>{I.value?.unsubscribe();let t=()=>(0,i.defer)(()=>_.plain===`subscription`?b.value.checkSubscriptionPaymentStatus(e):b.value.checkOnetimePaymentStatus(e)).pipe((0,a.timeout)(15e3),(0,a.retry)({delay:2e3}));I.value=t().pipe((0,a.expand)(e=>e.status===`pending`?(0,i.timer)(2e3).pipe((0,a.switchMap)(()=>t())):i.EMPTY),(0,a.tap)(e=>{if(!R.value&&_.plain===`instant`){let t=e;R.value={paymentId:t.paymentId,orderId:t.orderId,paymentChain:t.chain,paymentToken:t.token,paymentAmount:t.payAmount,receiveAddress:t.receiveAddress,expireAt:t.expireAt},E.value=t.chain,D.value=t.token,K(t.expireAt);let n=`${t.chain.toLowerCase()}:${t.receiveAddress}?amount=${t.payAmount}`;r.toDataURL(n,{width:200,margin:2,errorCorrectionLevel:`H`}).then(e=>{O.value=e,x.value=`payment`}).catch(e=>{console.error(`生成二维码失败:`,e),x.value=`select`})}if(!R.value&&_.plain===`subscription`){let t=e;R.value={subscriptionId:t.subscriptionId,orderId:t.orderId,paymentChain:t.chain,paymentToken:t.token,approveAmount:t.approveAmount,spenderAddress:t.approvedAddress,expireAt:t.expireAt,intervalDays:0,amountOfUsd:t.amountOfUsd},E.value=t.chain,D.value=t.token,K(t.expireAt);let n=`${t.chain.toLowerCase()}:${t.approvedAddress}?amount=${t.approveAmount}`;r.toDataURL(n,{width:200,margin:2,errorCorrectionLevel:`H`}).then(e=>{O.value=e,x.value=`payment`}).catch(e=>{console.error(`生成二维码失败:`,e),x.value=`select`})}(e.status===`paid`||e.status===`approved`)&&(x.value=`success`,$(),v(`success`,e)),e.status===`expired`&&(x.value=`expired`,$(),v(`expired`,e)),e.status===`failed`&&(x.value=`failed`,$(),v(`failed`,e))})).subscribe({error:e=>{if(R.value){let t=e instanceof Error?e.message:y.value.checkPaymentStatusFailed;x.value=`error`,w.value=t,$(),v(`error`,e)}},complete:()=>{I.value?.unsubscribe()}})},Ut=async()=>{if(!R.value)return;let e=_.plain===`subscription`?R.value.spenderAddress:R.value.receiveAddress;if(e)try{await navigator.clipboard.writeText(e),N.value=!0,setTimeout(()=>{N.value=!1},2e3)}catch(e){console.error(`复制失败:`,e)}};(0,n.watch)(H,e=>{e.length>0&&(D.value=e[0].symbol)}),(0,n.onMounted)(()=>{It(),T.value.length||Rt(),Gt()}),(0,n.onUnmounted)(()=>{I.value?.unsubscribe(),q()});let Wt=async()=>{if(z.value)try{await navigator.clipboard.writeText(z.value);let e=N.value;N.value=!0,setTimeout(()=>{N.value=e},2e3)}catch(e){console.error(`复制失败:`,e)}},Q=(e,t)=>{if(typeof window>`u`)return;let n=new URL(window.location.href),r=t===`subscription`?`subscriptionId`:`paymentId`;n.searchParams.set(r,e),window.history.replaceState({},``,n.toString())},$=()=>{if(typeof window>`u`)return;let e=new URL(window.location.href);e.searchParams.delete(`paymentId`),e.searchParams.delete(`subscriptionId`),window.history.replaceState({},``,e.toString())},Gt=async()=>{if(typeof window>`u`)return;let e=new URL(window.location.href);if(_.plain===`instant`){let t=e.searchParams.get(`paymentId`);t&&(x.value=`payment`,Z({paymentId:t}))}if(_.plain===`subscription`){let t=e.searchParams.get(`subscriptionId`);t&&(x.value=`payment`,Z({subscriptionId:t}))}};return(e,t)=>((0,n.openBlock)(),(0,n.createElementBlock)(`div`,u,[x.value===`success`?(0,n.renderSlot)(e.$slots,`success`,{key:0},()=>[(0,n.createElementVNode)(`div`,d,[t[9]||=(0,n.createElementVNode)(`div`,{class:`_cppay-state-success-bg`},[(0,n.createElementVNode)(`div`,{class:`_cppay-state-success-icon`},`✓`)],-1),(0,n.createElementVNode)(`h3`,ee,(0,n.toDisplayString)(h.plain===`subscription`?y.value.authorizationSuccess:y.value.paymentSuccess),1),z.value?((0,n.openBlock)(),(0,n.createElementBlock)(`div`,te,[(0,n.createElementVNode)(`div`,ne,(0,n.toDisplayString)(y.value.transactionHash),1),(0,n.createElementVNode)(`div`,re,[(0,n.createElementVNode)(`code`,ie,(0,n.toDisplayString)(z.value.slice(0,18))+`...`+(0,n.toDisplayString)(z.value.slice(-18)),1),(0,n.createElementVNode)(`button`,{onClick:Wt,class:`_cppay-state-copy-btn`,title:y.value.copyAddress},[...t[8]||=[(0,n.createElementVNode)(`svg`,{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,"stroke-width":`2`},[(0,n.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`}),(0,n.createElementVNode)(`rect`,{x:`8`,y:`2`,width:`8`,height:`4`,rx:`1`,ry:`1`})],-1)]],8,ae)])])):(0,n.createCommentVNode)(``,!0),R.value?((0,n.openBlock)(),(0,n.createElementBlock)(`div`,oe,[(0,n.createElementVNode)(`div`,se,[(0,n.createElementVNode)(`span`,ce,(0,n.toDisplayString)(y.value.orderId),1),(0,n.createElementVNode)(`span`,le,(0,n.toDisplayString)(R.value.orderId),1)]),(0,n.createElementVNode)(`div`,ue,[(0,n.createElementVNode)(`span`,de,(0,n.toDisplayString)(h.plain===`subscription`?y.value.authorizationAmount:y.value.paymentAmount),1),(0,n.createElementVNode)(`span`,fe,(0,n.toDisplayString)(h.plain===`subscription`?`${G(R.value.approveAmount,W(D.value))} ${D.value}`:`${G(R.value.paymentAmount,W(D.value))} ${D.value}`),1)]),(0,n.createElementVNode)(`div`,pe,[(0,n.createElementVNode)(`span`,me,(0,n.toDisplayString)(y.value.paymentNetwork),1),(0,n.createElementVNode)(`span`,he,(0,n.toDisplayString)(R.value.paymentChain),1)]),(0,n.createElementVNode)(`div`,ge,[(0,n.createElementVNode)(`span`,_e,(0,n.toDisplayString)(y.value.paymentToken),1),(0,n.createElementVNode)(`span`,ve,(0,n.toDisplayString)(R.value.paymentToken),1)]),h.plain===`subscription`?((0,n.openBlock)(),(0,n.createElementBlock)(`div`,ye,[(0,n.createElementVNode)(`span`,be,(0,n.toDisplayString)(y.value.renewalInterval),1),(0,n.createElementVNode)(`span`,xe,(0,n.toDisplayString)(R.value.intervalDays)+` `+(0,n.toDisplayString)(y.value.days),1)])):(0,n.createCommentVNode)(``,!0),(0,n.createElementVNode)(`div`,Se,[(0,n.createElementVNode)(`span`,Ce,(0,n.toDisplayString)(h.plain===`subscription`?y.value.subscriptionId:y.value.paymentId),1),(0,n.createElementVNode)(`span`,we,(0,n.toDisplayString)(h.plain===`subscription`?R.value.subscriptionId:R.value.paymentId),1)])])):(0,n.createCommentVNode)(``,!0)])]):x.value===`expired`?(0,n.renderSlot)(e.$slots,`expired`,{key:1},()=>[(0,n.createElementVNode)(`div`,Te,[t[10]||=(0,n.createElementVNode)(`div`,{class:`_cppay-state-expired-bg`},[(0,n.createElementVNode)(`div`,{class:`_cppay-state-expired-icon`},`⏰`)],-1),(0,n.createElementVNode)(`h3`,Ee,(0,n.toDisplayString)(y.value.paymentExpired),1),(0,n.createElementVNode)(`p`,De,(0,n.toDisplayString)(y.value.pleaseInitiatePaymentAgain),1),(0,n.createElementVNode)(`button`,{onClick:t[0]||=()=>{x.value=`select`,$()},disabled:S.value||C.value,class:`_cppay-btn _cppay-btn-primary _cppay-state-btn`},(0,n.toDisplayString)(y.value.returnButton),9,Oe)])]):x.value===`error`?(0,n.renderSlot)(e.$slots,`error`,{key:2},()=>[(0,n.createElementVNode)(`div`,ke,[t[11]||=(0,n.createElementVNode)(`div`,{class:`_cppay-state-error-bg`},[(0,n.createElementVNode)(`div`,{class:`_cppay-state-error-icon`},`!`)],-1),(0,n.createElementVNode)(`h3`,Ae,(0,n.toDisplayString)(w.value||y.value.error),1),(0,n.createElementVNode)(`p`,je,(0,n.toDisplayString)(y.value.checkStatusFailed),1),(0,n.createElementVNode)(`button`,{onClick:t[1]||=()=>{x.value=`select`,$()},disabled:S.value||C.value,class:`_cppay-btn _cppay-btn-primary _cppay-state-btn`},(0,n.toDisplayString)(y.value.returnButton),9,Me)])]):x.value===`failed`?(0,n.renderSlot)(e.$slots,`failed`,{key:3},()=>[(0,n.createElementVNode)(`div`,Ne,[t[12]||=(0,n.createElementVNode)(`div`,{class:`_cppay-state-failed-bg`},[(0,n.createElementVNode)(`div`,{class:`_cppay-state-failed-icon`},`✕`)],-1),(0,n.createElementVNode)(`h3`,Pe,(0,n.toDisplayString)(y.value.paymentFailed),1),(0,n.createElementVNode)(`p`,Fe,(0,n.toDisplayString)(y.value.pleaseInitiatePaymentAgain),1),(0,n.createElementVNode)(`button`,{onClick:t[2]||=()=>{x.value=`select`,$()},disabled:S.value||C.value,class:`_cppay-btn _cppay-btn-primary _cppay-state-btn`},(0,n.toDisplayString)(y.value.returnButton),9,Ie)])]):x.value===`select`?((0,n.openBlock)(),(0,n.createElementBlock)(`div`,Le,[(0,n.renderSlot)(e.$slots,`choose-top`),(0,n.createElementVNode)(`div`,Re,[(0,n.createElementVNode)(`label`,ze,(0,n.toDisplayString)(y.value.paymentNetwork),1),(0,n.createElementVNode)(`div`,f,[((0,n.openBlock)(!0),(0,n.createElementBlock)(n.Fragment,null,(0,n.renderList)(T.value,e=>((0,n.openBlock)(),(0,n.createElementBlock)(`button`,{key:e.chain,onClick:t=>E.value=e.chain,class:(0,n.normalizeClass)([`_cppay-select-btn`,{"_cppay-selected":E.value===e.chain}])},[e.icon?((0,n.openBlock)(),(0,n.createElementBlock)(`img`,{key:0,src:e.icon,alt:e.chain},null,8,m)):(0,n.createCommentVNode)(``,!0),(0,n.createElementVNode)(`span`,null,(0,n.toDisplayString)(e.chain),1)],10,p))),128))])]),(0,n.createElementVNode)(`div`,Be,[(0,n.createElementVNode)(`label`,Ve,(0,n.toDisplayString)(y.value.paymentToken),1),(0,n.createElementVNode)(`div`,He,[((0,n.openBlock)(!0),(0,n.createElementBlock)(n.Fragment,null,(0,n.renderList)(H.value,e=>((0,n.openBlock)(),(0,n.createElementBlock)(`button`,{key:e.symbol,onClick:t=>D.value=e.symbol,class:(0,n.normalizeClass)([`_cppay-select-btn`,{"_cppay-selected":D.value===e.symbol}])},[e.icon?((0,n.openBlock)(),(0,n.createElementBlock)(`img`,{key:0,src:e.icon,alt:e.symbol},null,8,We)):(0,n.createCommentVNode)(``,!0),(0,n.createElementVNode)(`span`,null,(0,n.toDisplayString)(e.symbol),1)],10,Ue))),128))])]),(0,n.renderSlot)(e.$slots,`choose-bottom`),(0,n.createElementVNode)(`div`,Ge,[(0,n.createElementVNode)(`div`,Ke,[(0,n.createElementVNode)(`div`,qe,[(0,n.createElementVNode)(`span`,Je,(0,n.toDisplayString)(y.value.paymentAmount),1),(0,n.createElementVNode)(`div`,Ye,[(0,n.createElementVNode)(`div`,Xe,(0,n.toDisplayString)(J.value??`-`)+` `+(0,n.toDisplayString)(D.value??``),1),(0,n.createElementVNode)(`div`,Ze,`≈ $`+(0,n.toDisplayString)(h.amount),1)])])])]),(0,n.createElementVNode)(`div`,Qe,[w.value?((0,n.openBlock)(),(0,n.createElementBlock)(`div`,{key:0,class:`_cppay-error-tooltip-wrapper`,onMouseenter:t[3]||=e=>P.value=!0,onMouseleave:t[4]||=e=>P.value=!1},[(0,n.createElementVNode)(`div`,$e,[t[13]||=(0,n.createElementVNode)(`svg`,{viewBox:`0 0 20 20`,fill:`currentColor`},[(0,n.createElementVNode)(`path`,{"fill-rule":`evenodd`,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`,"clip-rule":`evenodd`})],-1),(0,n.createElementVNode)(`span`,null,(0,n.toDisplayString)(w.value),1)]),P.value?((0,n.openBlock)(),(0,n.createElementBlock)(`div`,et,(0,n.toDisplayString)(w.value),1)):(0,n.createCommentVNode)(``,!0)],32)):(0,n.createCommentVNode)(``,!0),(0,n.createElementVNode)(`button`,{onClick:Ht,disabled:!E.value||!D.value||S.value,class:`_cppay-btn _cppay-btn-primary`},(0,n.toDisplayString)(S.value?y.value.processing:y.value.continuePayment),9,tt)])])):((0,n.openBlock)(),(0,n.createElementBlock)(`div`,nt,[(0,n.createElementVNode)(`div`,rt,[(0,n.createElementVNode)(`div`,it,[O.value?((0,n.openBlock)(),(0,n.createElementBlock)(`img`,{key:0,src:O.value,alt:`Payment QR Code`,class:`_cppay-qr-image`},null,8,at)):(0,n.createCommentVNode)(``,!0)])]),(0,n.createElementVNode)(`div`,ot,[U.value?((0,n.openBlock)(),(0,n.createElementBlock)(`div`,st,[(0,n.createElementVNode)(`div`,ct,[(0,n.createElementVNode)(`div`,lt,[(0,n.createElementVNode)(`div`,ut,(0,n.toDisplayString)(h.plain===`subscription`?y.value.authorizationAmount:y.value.paymentAmount),1),(0,n.createElementVNode)(`div`,dt,[R.value?((0,n.openBlock)(),(0,n.createElementBlock)(`span`,ft,(0,n.toDisplayString)(h.plain===`subscription`?`${G(R.value.approveAmount,W(U.value.symbol))} ${U.value.symbol}`:`${G(R.value.paymentAmount,W(U.value.symbol))} ${U.value.symbol}`),1)):(0,n.createCommentVNode)(``,!0),(0,n.createElementVNode)(`span`,null,`≈ $`+(0,n.toDisplayString)(h.amount),1)])])])])):(0,n.createCommentVNode)(``,!0),(0,n.createElementVNode)(`div`,pt,[(0,n.createElementVNode)(`div`,mt,[(0,n.createElementVNode)(`div`,ht,[(0,n.createElementVNode)(`span`,null,(0,n.toDisplayString)(h.plain===`subscription`?y.value.authorizationContractAddress:y.value.paymentAddress),1),M.value?((0,n.openBlock)(),(0,n.createElementBlock)(`span`,gt,`⏰ `+(0,n.toDisplayString)(M.value),1)):(0,n.createCommentVNode)(``,!0)]),(0,n.createElementVNode)(`div`,_t,[R.value?((0,n.openBlock)(),(0,n.createElementBlock)(`code`,vt,(0,n.toDisplayString)(h.plain===`subscription`?R.value.spenderAddress:R.value.receiveAddress),1)):(0,n.createCommentVNode)(``,!0),(0,n.createElementVNode)(`button`,{onClick:Ut,class:(0,n.normalizeClass)([`_cppay-copy-btn`,{"_cppay-copy-success":N.value}]),title:N.value?y.value.copied:y.value.copyAddress},[N.value?((0,n.openBlock)(),(0,n.createElementBlock)(`svg`,xt,[...t[15]||=[(0,n.createElementVNode)(`path`,{d:`M9 16.17L4.83 12l-1.42 1.41L9 19 21 7l-1.41-1.41z`},null,-1)]])):((0,n.openBlock)(),(0,n.createElementBlock)(`svg`,bt,[...t[14]||=[(0,n.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),(0,n.createElementVNode)(`rect`,{x:`8`,y:`2`,width:`8`,height:`4`,rx:`1`,ry:`1`},null,-1)]]))],10,yt)])])]),h.plain===`subscription`?((0,n.openBlock)(),(0,n.createElementBlock)(`div`,St,[(0,n.createElementVNode)(`div`,Ct,(0,n.toDisplayString)(y.value.subscriptionNotice),1),(0,n.createElementVNode)(`div`,wt,(0,n.toDisplayString)(y.value.subscriptionNoticeMessage),1)])):(0,n.createCommentVNode)(``,!0)]),w.value?((0,n.openBlock)(),(0,n.createElementBlock)(`div`,{key:0,class:`_cppay-error-tooltip-wrapper`,onMouseenter:t[5]||=e=>P.value=!0,onMouseleave:t[6]||=e=>P.value=!1},[(0,n.createElementVNode)(`div`,Tt,[t[16]||=(0,n.createElementVNode)(`svg`,{viewBox:`0 0 20 20`,fill:`currentColor`},[(0,n.createElementVNode)(`path`,{"fill-rule":`evenodd`,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`,"clip-rule":`evenodd`})],-1),(0,n.createElementVNode)(`span`,null,(0,n.toDisplayString)(w.value),1)]),P.value?((0,n.openBlock)(),(0,n.createElementBlock)(`div`,Et,(0,n.toDisplayString)(w.value),1)):(0,n.createCommentVNode)(``,!0)],32)):(0,n.createCommentVNode)(``,!0),C.value?(0,n.createCommentVNode)(``,!0):((0,n.openBlock)(),(0,n.createElementBlock)(`div`,Dt,[k.value?((0,n.openBlock)(),(0,n.createElementBlock)(n.Fragment,{key:1},[(0,n.createElementVNode)(`button`,{onClick:Vt,disabled:S.value,class:`_cppay-btn _cppay-btn-primary`},(0,n.toDisplayString)(S.value?h.plain===`subscription`?y.value.authorizing:y.value.processing:(h.plain,y.value.walletPay)),9,kt),(0,n.createElementVNode)(`button`,{onClick:B,disabled:S.value,class:`_cppay-btn _cppay-wallet-address-btn`,title:y.value.clickToModifyWallet},[(0,n.createElementVNode)(`span`,jt,(0,n.toDisplayString)(k.value.slice(0,10))+`...`+(0,n.toDisplayString)(k.value.slice(-4)),1),t[17]||=(0,n.createElementVNode)(`svg`,{class:`_cppay-wallet-arrow`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,"stroke-width":`2`},[(0,n.createElementVNode)(`polyline`,{points:`6 9 12 15 18 9`})],-1)],8,At)],64)):((0,n.openBlock)(),(0,n.createElementBlock)(`button`,{key:0,onClick:B,disabled:A.value,class:`_cppay-btn _cppay-btn-secondary _cppay-connect-wallet-btn`},[(0,n.createElementVNode)(`span`,null,(0,n.toDisplayString)(A.value?y.value.processing:y.value.connectWallet),1)],8,Ot))])),(0,n.createElementVNode)(`div`,Mt,[(0,n.createElementVNode)(`button`,{onClick:X,disabled:C.value,class:`_cppay-btn _cppay-btn-primary`},[C.value?((0,n.openBlock)(),(0,n.createElementBlock)(n.Fragment,{key:0},[t[18]||=(0,n.createElementVNode)(`svg`,{class:`_cppay-spinner`,viewBox:`0 0 24 24`,fill:`none`,xmlns:`http://www.w3.org/2000/svg`},[(0,n.createElementVNode)(`circle`,{cx:`12`,cy:`12`,r:`10`,stroke:`currentColor`,"stroke-width":`3`,"stroke-opacity":`0.25`}),(0,n.createElementVNode)(`path`,{d:`M12 2a10 10 0 0 1 10 10`,stroke:`currentColor`,"stroke-width":`3`,"stroke-linecap":`round`})],-1),(0,n.createTextVNode)(` `+(0,n.toDisplayString)(y.value.checking),1)],64)):((0,n.openBlock)(),(0,n.createElementBlock)(n.Fragment,{key:1},[(0,n.createTextVNode)((0,n.toDisplayString)(y.value.completedPayment),1)],64))],8,Nt)]),t[19]||=(0,n.createElementVNode)(`hr`,{class:`_cppay-divider`},null,-1),(0,n.createElementVNode)(`div`,Pt,[(0,n.createElementVNode)(`button`,{onClick:t[7]||=()=>{x.value=`select`,$()},disabled:S.value||C.value,class:`_cppay-btn _cppay-btn-text`},(0,n.toDisplayString)(y.value.changePaymentMethod),9,Ft)])]))]))}}),g=h,_={class:`_cppay-dialog`},v={class:`_cppay-header`},y={class:`_cppay-title`},b=[`disabled`],x=(0,n.defineComponent)({__name:`PaymentDialog`,props:{modelValue:{type:Boolean},ott:{},apikey:{},orderId:{},amount:{},plain:{},intervalDays:{},locale:{}},emits:[`update:modelValue`,`success`,`expired`,`failed`,`error`],setup(t,{emit:r}){let i=t,a=r,o=(0,n.computed)(()=>e.t(i.locale)),s=(0,n.ref)(`select`),c=(0,n.computed)(()=>s.value!==`checking`);(0,n.watch)(()=>i.modelValue,e=>{e||(s.value=`select`)});let l=e=>{s.value=e};(0,n.onMounted)(()=>{let e=e=>{e.key===`Escape`&&i.modelValue&&!c.value&&u()};return window.addEventListener(`keydown`,e),()=>{window.removeEventListener(`keydown`,e)}});let u=()=>{if(!c.value||typeof window>`u`)return;let e=new URL(window.location.href);e.searchParams.delete(`paymentId`),e.searchParams.delete(`subscriptionId`),window.history.replaceState({},``,e.toString()),a(`update:modelValue`,!1)},d=()=>{switch(s.value){case`success`:return o.value.paymentResult;case`expired`:return o.value.paymentExpired;case`failed`:return o.value.paymentFailed;case`error`:return o.value.error;case`payment`:return o.value.completePayment;default:return o.value.selectPaymentMethod}};return(e,r)=>t.modelValue?((0,n.openBlock)(),(0,n.createElementBlock)(`div`,{key:0,class:`_cppay-overlay`,onClick:r[4]||=e=>e.target===e.currentTarget&&u()},[(0,n.createElementVNode)(`div`,_,[(0,n.createElementVNode)(`div`,v,[(0,n.createElementVNode)(`h2`,y,(0,n.toDisplayString)(d()),1),(0,n.createElementVNode)(`button`,{onClick:u,disabled:!c.value,class:`_cppay-close-btn`},[...r[5]||=[(0,n.createElementVNode)(`svg`,{fill:`none`,stroke:`currentColor`,viewBox:`0 0 24 24`},[(0,n.createElementVNode)(`path`,{"stroke-linecap":`round`,"stroke-linejoin":`round`,"stroke-width":`2`,d:`M6 18L18 6M6 6l12 12`})],-1)]],8,b)]),t.modelValue?((0,n.openBlock)(),(0,n.createBlock)(g,{key:0,apikey:t.apikey,ott:t.ott,orderId:t.orderId,amount:t.amount,plain:t.plain,intervalDays:t.intervalDays,locale:t.locale,"onUpdate:paymentStep":l,onSuccess:r[0]||=e=>a(`success`,e),onExpired:r[1]||=e=>a(`expired`,e),onFailed:r[2]||=e=>a(`failed`,e),onError:r[3]||=e=>a(`error`,e)},{"choose-top":(0,n.withCtx)(()=>[(0,n.renderSlot)(e.$slots,`choose-top`)]),"choose-bottom":(0,n.withCtx)(()=>[(0,n.renderSlot)(e.$slots,`choose-bottom`)]),success:(0,n.withCtx)(()=>[(0,n.renderSlot)(e.$slots,`success`)]),failed:(0,n.withCtx)(()=>[(0,n.renderSlot)(e.$slots,`failed`)]),error:(0,n.withCtx)(()=>[(0,n.renderSlot)(e.$slots,`error`)]),expired:(0,n.withCtx)(()=>[(0,n.renderSlot)(e.$slots,`expired`)]),_:3},8,[`apikey`,`ott`,`orderId`,`amount`,`plain`,`intervalDays`,`locale`])):(0,n.createCommentVNode)(``,!0)])])):(0,n.createCommentVNode)(``,!0)}}),S=x,C=(0,n.ref)({open:!1,options:null});const w=e=>{C.value.options=e,C.value.open=!0},T=()=>{C.value.open=!1};var E=()=>{C.value.open=!1},D=e=>{C.value.options?.onSuccess?.(e)},O=e=>{C.value.options?.onExpired?.(e)},k=e=>{C.value.options?.onFailed?.(e)},A=e=>{C.value.options?.onError?.(e)};const j={install(e){e.config.globalProperties.$showPayment=w,e.config.globalProperties.$closePayment=T;let t=document.createElement(`div`);document.body.appendChild(t),(0,n.createApp)({setup(){return()=>C.value.options?(0,n.h)(S,{modelValue:C.value.open,"onUpdate:modelValue":e=>{C.value.open=e,e||E()},...C.value.options,onSuccess:D,onExpired:O,onFailed:k,onError:A}):null}}).mount(t)}},M=()=>({showPayment:w,closePayment:T});e.n(e.r),exports.CppayPlugin=j,exports.PaymentContent=g,exports.PaymentDialog=S,exports.showPayment=w,exports.useCppayPayment=M;
|
package/dist/vue.js
CHANGED
|
@@ -604,7 +604,9 @@ var _hoisted_1$1 = { class: "_cppay-content" }, _hoisted_2$1 = { class: "_cppay-
|
|
|
604
604
|
};
|
|
605
605
|
});
|
|
606
606
|
let u = () => {
|
|
607
|
-
c.value
|
|
607
|
+
if (!c.value || typeof window > "u") return;
|
|
608
|
+
let e = new URL(window.location.href);
|
|
609
|
+
e.searchParams.delete("paymentId"), e.searchParams.delete("subscriptionId"), window.history.replaceState({}, "", e.toString()), i("update:modelValue", !1);
|
|
608
610
|
}, d = () => {
|
|
609
611
|
switch (s.value) {
|
|
610
612
|
case "success": return a.value.paymentResult;
|