@seaverse/payment-sdk 0.4.0 → 0.4.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 +72 -13
- package/dist/index.browser.js +64 -3948
- package/dist/index.browser.js.map +1 -1
- package/dist/index.cjs +38 -12
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +8 -0
- package/dist/index.js +38 -12
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -52,7 +52,7 @@ Show payment modal for purchases:
|
|
|
52
52
|
|
|
53
53
|
```typescript
|
|
54
54
|
import { PaymentCheckoutClient } from '@seaverse/payment-sdk';
|
|
55
|
-
// Import the Web Component styles
|
|
55
|
+
// Import the Web Component styles
|
|
56
56
|
import '@seaverse/payment-sdk/style.css';
|
|
57
57
|
|
|
58
58
|
const checkoutClient = new PaymentCheckoutClient({
|
|
@@ -160,7 +160,7 @@ interface CheckoutClientConfig {
|
|
|
160
160
|
<script setup lang="ts">
|
|
161
161
|
import { ref, onMounted } from 'vue';
|
|
162
162
|
import { PaymentCheckoutClient } from '@seaverse/payment-sdk';
|
|
163
|
-
import '@
|
|
163
|
+
import '@seaverse/payment-sdk/style.css';
|
|
164
164
|
|
|
165
165
|
const checkoutClient = ref<PaymentCheckoutClient | null>(null);
|
|
166
166
|
|
|
@@ -187,7 +187,7 @@ async function handlePurchase() {
|
|
|
187
187
|
```tsx
|
|
188
188
|
import { useEffect, useRef } from 'react';
|
|
189
189
|
import { PaymentCheckoutClient } from '@seaverse/payment-sdk';
|
|
190
|
-
import '@
|
|
190
|
+
import '@seaverse/payment-sdk/style.css';
|
|
191
191
|
|
|
192
192
|
function PaymentPage() {
|
|
193
193
|
const clientRef = useRef<PaymentCheckoutClient | null>(null);
|
|
@@ -223,17 +223,12 @@ function PaymentPage() {
|
|
|
223
223
|
- `'develop'` → `'development'`
|
|
224
224
|
- `'release'` → `'production'`
|
|
225
225
|
|
|
226
|
-
2. **
|
|
227
|
-
```bash
|
|
228
|
-
npm install @seaart/payment-component
|
|
229
|
-
```
|
|
230
|
-
|
|
231
|
-
3. **Import CSS file:**
|
|
226
|
+
2. **Import CSS file:**
|
|
232
227
|
```typescript
|
|
233
|
-
import '@
|
|
228
|
+
import '@seaverse/payment-sdk/style.css';
|
|
234
229
|
```
|
|
235
230
|
|
|
236
|
-
|
|
231
|
+
3. **Configuration options renamed:**
|
|
237
232
|
- `sdkCdnUrl` removed (no longer uses CDN)
|
|
238
233
|
- `sdkTimeout` → `componentTimeout`
|
|
239
234
|
|
|
@@ -247,10 +242,10 @@ const client = new PaymentCheckoutClient({
|
|
|
247
242
|
});
|
|
248
243
|
```
|
|
249
244
|
|
|
250
|
-
### After (v0.2.x)
|
|
245
|
+
### After (v0.2.x+)
|
|
251
246
|
|
|
252
247
|
```typescript
|
|
253
|
-
import '@
|
|
248
|
+
import '@seaverse/payment-sdk/style.css'; // Required!
|
|
254
249
|
|
|
255
250
|
const client = new PaymentCheckoutClient({
|
|
256
251
|
apiHost: 'https://payment.sg.seaverse.dev',
|
|
@@ -259,6 +254,70 @@ const client = new PaymentCheckoutClient({
|
|
|
259
254
|
});
|
|
260
255
|
```
|
|
261
256
|
|
|
257
|
+
## Error Handling
|
|
258
|
+
|
|
259
|
+
### Business Error Codes (BIZ_CODE)
|
|
260
|
+
|
|
261
|
+
The SDK uses standardized business error codes returned from the API:
|
|
262
|
+
|
|
263
|
+
| Code | Constant | Description |
|
|
264
|
+
|------|----------|-------------|
|
|
265
|
+
| `0` | `SUCCESS` | 操作成功 |
|
|
266
|
+
| `400` | `BAD_REQUEST` | 请求参数错误 |
|
|
267
|
+
| `401` | `UNAUTHORIZED` | 未授权 |
|
|
268
|
+
| `500` | `SERVER_ERROR` | 服务器错误 |
|
|
269
|
+
| `4001` | `DAILY_LIMIT_EXCEEDED` | 超过每日限额 |
|
|
270
|
+
| `4002` | `PRODUCT_NOT_FOUND` | 商品不存在 |
|
|
271
|
+
| `4003` | `PRODUCT_DISABLED` | 商品已禁用 |
|
|
272
|
+
| `4004` | `INSUFFICIENT_BALANCE` | 余额不足 |
|
|
273
|
+
| `4005` | `ORDER_NOT_FOUND` | 订单不存在 |
|
|
274
|
+
| `4006` | `INVALID_ORDER_STATUS` | 订单状态无效 |
|
|
275
|
+
|
|
276
|
+
### Checkout Error Codes
|
|
277
|
+
|
|
278
|
+
Payment checkout operations may throw errors with these codes:
|
|
279
|
+
|
|
280
|
+
| Code | Description |
|
|
281
|
+
|------|-------------|
|
|
282
|
+
| `COMPONENT_LOAD_FAILED` | Web Component 加载失败 |
|
|
283
|
+
| `COMPONENT_NOT_READY` | Web Component 未就绪 |
|
|
284
|
+
| `API_ERROR` | API 请求错误 |
|
|
285
|
+
| `CHECKOUT_FAILED` | 结账失败 |
|
|
286
|
+
| `PAYMENT_CANCELLED` | 用户取消支付 |
|
|
287
|
+
| `PAYMENT_FAILED` | 支付失败 |
|
|
288
|
+
| `INVALID_PARAMS` | 参数无效 |
|
|
289
|
+
| `UNAUTHORIZED` | 未授权 |
|
|
290
|
+
| `NETWORK_ERROR` | 网络错误 |
|
|
291
|
+
| `UNKNOWN_ERROR` | 未知错误 |
|
|
292
|
+
|
|
293
|
+
### Error Handling Example
|
|
294
|
+
|
|
295
|
+
```typescript
|
|
296
|
+
import { PaymentCheckoutClient, isCheckoutPaymentError } from '@seaverse/payment-sdk';
|
|
297
|
+
|
|
298
|
+
try {
|
|
299
|
+
await checkoutClient.checkout({
|
|
300
|
+
productId: 'pkg_starter',
|
|
301
|
+
onError: (error) => {
|
|
302
|
+
console.error('Payment error:', error.code, error.message);
|
|
303
|
+
|
|
304
|
+
// 检查业务错误码
|
|
305
|
+
if (error.bizCode === 4004) {
|
|
306
|
+
alert('余额不足,请充值后重试');
|
|
307
|
+
}
|
|
308
|
+
},
|
|
309
|
+
});
|
|
310
|
+
} catch (error) {
|
|
311
|
+
if (isCheckoutPaymentError(error)) {
|
|
312
|
+
// 处理支付相关错误
|
|
313
|
+
console.error('Checkout error:', error.code);
|
|
314
|
+
} else {
|
|
315
|
+
// 处理其他错误
|
|
316
|
+
console.error('Unknown error:', error);
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
```
|
|
320
|
+
|
|
262
321
|
## Test Cards (Development)
|
|
263
322
|
|
|
264
323
|
| Field | Value |
|