@t402/vue 2.3.0 → 2.3.1
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 +137 -0
- package/package.json +2 -2
package/README.md
ADDED
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
# @t402/vue
|
|
2
|
+
|
|
3
|
+
Vue components and composables for the t402 Payment Protocol. Build payment-aware UIs with pre-built components and reactive composables.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @t402/vue
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Quick Start
|
|
12
|
+
|
|
13
|
+
```vue
|
|
14
|
+
<script setup lang="ts">
|
|
15
|
+
import { PaymentButton, usePaymentRequired } from "@t402/vue";
|
|
16
|
+
|
|
17
|
+
const { paymentRequired, requirements, pay, status } = usePaymentRequired("/api/data");
|
|
18
|
+
</script>
|
|
19
|
+
|
|
20
|
+
<template>
|
|
21
|
+
<div v-if="paymentRequired">
|
|
22
|
+
<PaymentButton :requirements="requirements" :status="status" @pay="pay" />
|
|
23
|
+
</div>
|
|
24
|
+
<div v-else>
|
|
25
|
+
Premium content loaded!
|
|
26
|
+
</div>
|
|
27
|
+
</template>
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## Components
|
|
31
|
+
|
|
32
|
+
### PaymentButton
|
|
33
|
+
|
|
34
|
+
Renders a payment action button with loading and status states.
|
|
35
|
+
|
|
36
|
+
```vue
|
|
37
|
+
<PaymentButton
|
|
38
|
+
:requirements="requirements"
|
|
39
|
+
:status="status"
|
|
40
|
+
@pay="handlePay"
|
|
41
|
+
/>
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
### PaymentDetails
|
|
45
|
+
|
|
46
|
+
Displays payment requirements (amount, network, recipient).
|
|
47
|
+
|
|
48
|
+
```vue
|
|
49
|
+
<PaymentDetails :requirements="requirements" />
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
### PaymentStatusDisplay
|
|
53
|
+
|
|
54
|
+
Shows the current payment status with appropriate UI feedback.
|
|
55
|
+
|
|
56
|
+
```vue
|
|
57
|
+
<PaymentStatusDisplay :status="status" />
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
### AddressDisplay
|
|
61
|
+
|
|
62
|
+
Renders a blockchain address with truncation and copy functionality.
|
|
63
|
+
|
|
64
|
+
```vue
|
|
65
|
+
<AddressDisplay address="0x1234...5678" />
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
## Composables
|
|
69
|
+
|
|
70
|
+
### usePaymentRequired
|
|
71
|
+
|
|
72
|
+
Detects 402 responses and extracts payment requirements.
|
|
73
|
+
|
|
74
|
+
```typescript
|
|
75
|
+
const {
|
|
76
|
+
paymentRequired, // Ref<boolean>
|
|
77
|
+
requirements, // Ref<PaymentRequirements[]>
|
|
78
|
+
pay, // () => Promise<void>
|
|
79
|
+
status, // Ref<PaymentStatus>
|
|
80
|
+
} = usePaymentRequired(url, options);
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
### usePaymentStatus
|
|
84
|
+
|
|
85
|
+
Tracks the lifecycle of a payment (idle, pending, confirming, complete, error).
|
|
86
|
+
|
|
87
|
+
```typescript
|
|
88
|
+
const { status, error, reset } = usePaymentStatus();
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
### useAsyncPayment
|
|
92
|
+
|
|
93
|
+
Manages async payment flows with automatic retry and status tracking.
|
|
94
|
+
|
|
95
|
+
```typescript
|
|
96
|
+
const { execute, status, error } = useAsyncPayment(paymentFn);
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
## Utilities
|
|
100
|
+
|
|
101
|
+
```typescript
|
|
102
|
+
import {
|
|
103
|
+
isEvmNetwork,
|
|
104
|
+
isSvmNetwork,
|
|
105
|
+
isTonNetwork,
|
|
106
|
+
getNetworkDisplayName,
|
|
107
|
+
truncateAddress,
|
|
108
|
+
formatTokenAmount,
|
|
109
|
+
choosePaymentRequirement,
|
|
110
|
+
} from "@t402/vue";
|
|
111
|
+
|
|
112
|
+
// Network detection
|
|
113
|
+
isEvmNetwork("eip155:8453"); // true
|
|
114
|
+
|
|
115
|
+
// Display helpers
|
|
116
|
+
getNetworkDisplayName("eip155:8453"); // "Base"
|
|
117
|
+
truncateAddress("0x1234567890abcdef"); // "0x1234...cdef"
|
|
118
|
+
formatTokenAmount(1500000n, 6); // "1.50"
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
## Peer Dependencies
|
|
122
|
+
|
|
123
|
+
- `vue` ^3.3.0
|
|
124
|
+
|
|
125
|
+
## Development
|
|
126
|
+
|
|
127
|
+
```bash
|
|
128
|
+
pnpm build # Build the package
|
|
129
|
+
pnpm test # Run unit tests
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
## Related Packages
|
|
133
|
+
|
|
134
|
+
- `@t402/core` - Core protocol types
|
|
135
|
+
- `@t402/react` - React components & hooks
|
|
136
|
+
- `@t402/paywall` - Universal paywall UI
|
|
137
|
+
- `@t402/fetch` - Fetch wrapper with automatic payment
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@t402/vue",
|
|
3
|
-
"version": "2.3.
|
|
3
|
+
"version": "2.3.1",
|
|
4
4
|
"main": "./dist/cjs/index.js",
|
|
5
5
|
"module": "./dist/esm/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
"vue": "^3.5.0"
|
|
42
42
|
},
|
|
43
43
|
"dependencies": {
|
|
44
|
-
"@t402/core": "2.3.
|
|
44
|
+
"@t402/core": "2.3.1"
|
|
45
45
|
},
|
|
46
46
|
"peerDependencies": {
|
|
47
47
|
"vue": "^3.3.0"
|