@seaverse/payment-sdk 0.1.0
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 +156 -0
- package/dist/index.browser.js +5058 -0
- package/dist/index.browser.js.map +1 -0
- package/dist/index.cjs +1177 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +1058 -0
- package/dist/index.js +1148 -0
- package/dist/index.js.map +1 -0
- package/package.json +61 -0
package/README.md
ADDED
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
# @seaverse/payment-sdk
|
|
2
|
+
|
|
3
|
+
SeaVerse Payment SDK - Credit management and payment checkout for SeaVerse applications.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- **Credit Query** - Query user credit balance, pool details, and transaction history
|
|
8
|
+
- **Payment Checkout** - Show payment modal for one-time purchases and subscriptions
|
|
9
|
+
- **Multi-tenant Support** - Isolated credit accounts per application
|
|
10
|
+
- **TypeScript** - Full type definitions included
|
|
11
|
+
|
|
12
|
+
## Installation
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
npm install @seaverse/payment-sdk
|
|
16
|
+
# or
|
|
17
|
+
pnpm add @seaverse/payment-sdk
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Quick Start
|
|
21
|
+
|
|
22
|
+
### Credit Query
|
|
23
|
+
|
|
24
|
+
Query user credit accounts and transaction history:
|
|
25
|
+
|
|
26
|
+
```typescript
|
|
27
|
+
import { PaymentClient } from '@seaverse/payment-sdk';
|
|
28
|
+
|
|
29
|
+
const client = new PaymentClient({
|
|
30
|
+
appId: 'seaverse',
|
|
31
|
+
token: 'your-bearer-token',
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
// Get credit detail with 4-pool breakdown
|
|
35
|
+
const detail = await client.getCreditDetail();
|
|
36
|
+
console.log(`Total Balance: ${detail.total_balance}`);
|
|
37
|
+
|
|
38
|
+
detail.pools.forEach(pool => {
|
|
39
|
+
console.log(`${pool.type}: ${pool.balance}`);
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
// List transactions
|
|
43
|
+
const transactions = await client.listTransactions({ page_size: 10 });
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
### Payment Checkout
|
|
47
|
+
|
|
48
|
+
Show payment modal for purchases:
|
|
49
|
+
|
|
50
|
+
```typescript
|
|
51
|
+
import { PaymentCheckoutClient } from '@seaverse/payment-sdk';
|
|
52
|
+
|
|
53
|
+
const checkoutClient = new PaymentCheckoutClient({
|
|
54
|
+
apiHost: 'https://payment.sg.seaverse.dev',
|
|
55
|
+
authToken: 'your-jwt-token',
|
|
56
|
+
environment: 'develop',
|
|
57
|
+
debug: true,
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
// Initialize (loads SeaArtPay SDK)
|
|
61
|
+
await checkoutClient.init();
|
|
62
|
+
|
|
63
|
+
// One-time purchase
|
|
64
|
+
await checkoutClient.checkout({
|
|
65
|
+
productId: 'pkg_starter',
|
|
66
|
+
onSuccess: (res) => console.log('Payment success:', res),
|
|
67
|
+
onError: (err) => console.error('Payment failed:', err),
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
// Subscription
|
|
71
|
+
await checkoutClient.subscribe({
|
|
72
|
+
productId: 'pro',
|
|
73
|
+
period: 'month',
|
|
74
|
+
periodAmount: 24.99,
|
|
75
|
+
onSuccess: (res) => console.log('Subscription success:', res),
|
|
76
|
+
});
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
## API Reference
|
|
80
|
+
|
|
81
|
+
### PaymentClient (Credit Query)
|
|
82
|
+
|
|
83
|
+
| Method | Description |
|
|
84
|
+
|--------|-------------|
|
|
85
|
+
| `getCreditDetail()` | Get credit balance with 4-pool breakdown |
|
|
86
|
+
| `getCreditAccount()` | Get credit account information (deprecated) |
|
|
87
|
+
| `listTransactions(request)` | List credit transactions with filters |
|
|
88
|
+
| `setToken(token)` | Update bearer token |
|
|
89
|
+
| `setBaseURL(baseURL)` | Update API base URL |
|
|
90
|
+
| `setAppId(appId)` | Update application ID |
|
|
91
|
+
|
|
92
|
+
### PaymentCheckoutClient (Payment Modal)
|
|
93
|
+
|
|
94
|
+
| Method | Description |
|
|
95
|
+
|--------|-------------|
|
|
96
|
+
| `init()` | Initialize and load SeaArtPay SDK |
|
|
97
|
+
| `checkout(options)` | One-time purchase with payment modal |
|
|
98
|
+
| `subscribe(options)` | Subscription purchase with payment modal |
|
|
99
|
+
| `showPayment(options)` | Show payment modal with existing transactionId |
|
|
100
|
+
| `close()` | Close payment modal |
|
|
101
|
+
| `getStatus()` | Get client status |
|
|
102
|
+
| `isReady()` | Check if client is initialized |
|
|
103
|
+
|
|
104
|
+
## Credit Pool Types
|
|
105
|
+
|
|
106
|
+
The 4-pool credit system:
|
|
107
|
+
|
|
108
|
+
| Pool | Description | Expiration |
|
|
109
|
+
|------|-------------|------------|
|
|
110
|
+
| `daily` | Daily credits | Next day 00:00 UTC |
|
|
111
|
+
| `event` | Event credits | Event deadline |
|
|
112
|
+
| `monthly` | Monthly credits | 30 days after grant |
|
|
113
|
+
| `permanent` | Permanent credits | Never |
|
|
114
|
+
|
|
115
|
+
**Consumption Priority:** Daily → Event → Monthly → Permanent
|
|
116
|
+
|
|
117
|
+
## Configuration
|
|
118
|
+
|
|
119
|
+
### PaymentClient Options
|
|
120
|
+
|
|
121
|
+
```typescript
|
|
122
|
+
interface PaymentClientOptions {
|
|
123
|
+
appId: string; // Application ID for multi-tenant isolation
|
|
124
|
+
token: string; // Bearer token for authentication
|
|
125
|
+
baseURL?: string; // API base URL (default: 'https://payment.sg.seaverse.dev')
|
|
126
|
+
timeout?: number; // Request timeout in ms (default: 30000)
|
|
127
|
+
}
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
### PaymentCheckoutClient Options
|
|
131
|
+
|
|
132
|
+
```typescript
|
|
133
|
+
interface CheckoutClientConfig {
|
|
134
|
+
apiHost: string; // Payment gateway API URL
|
|
135
|
+
authToken?: string; // Static JWT token
|
|
136
|
+
getAuthToken?: () => string; // Dynamic token getter
|
|
137
|
+
environment?: 'develop' | 'release';
|
|
138
|
+
debug?: boolean;
|
|
139
|
+
sdkCdnUrl?: string; // Custom SDK CDN URL
|
|
140
|
+
sdkTimeout?: number; // SDK load timeout in ms
|
|
141
|
+
}
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
## Test Cards (Development)
|
|
145
|
+
|
|
146
|
+
| Field | Value |
|
|
147
|
+
|-------|-------|
|
|
148
|
+
| Card Number | `4212345678910006` |
|
|
149
|
+
| Expiry | `03/30` |
|
|
150
|
+
| CVC | `737` |
|
|
151
|
+
| 3DS Password | `password` |
|
|
152
|
+
|
|
153
|
+
## License
|
|
154
|
+
|
|
155
|
+
MIT
|
|
156
|
+
|