@seaverse/payment-sdk 0.8.2 → 0.9.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 +158 -0
- package/dist/index.browser.js +4556 -767
- package/dist/index.browser.js.map +1 -1
- package/dist/index.cjs +4560 -768
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +650 -128
- package/dist/index.js +4556 -767
- package/dist/index.js.map +1 -1
- package/package.json +10 -9
package/README.md
CHANGED
|
@@ -219,6 +219,164 @@ SDK 内置以下积分套餐:
|
|
|
219
219
|
| Pro | 520 | $1.99 | 专业套餐 |
|
|
220
220
|
| Ultra | 1200 | $4.99 | 旗舰套餐 |
|
|
221
221
|
|
|
222
|
+
---
|
|
223
|
+
|
|
224
|
+
### PaymentCheckoutModal - 完整收银台流程
|
|
225
|
+
|
|
226
|
+
**适用场景**:
|
|
227
|
+
- ✅ 需要完整的支付收银台体验(支付方式选择 + 订单信息展示)
|
|
228
|
+
- ✅ 自动创建订单并完成支付
|
|
229
|
+
- ✅ 支持三种支付方式:Link Payment、Dropin Payment、BindCard Payment
|
|
230
|
+
- ✅ 适合需要更多控制和自定义的场景
|
|
231
|
+
|
|
232
|
+
#### 基础用法
|
|
233
|
+
|
|
234
|
+
```typescript
|
|
235
|
+
import { PaymentCheckoutModal, type Product, type AutoCreateOrderConfig } from '@seaverse/payment-sdk';
|
|
236
|
+
|
|
237
|
+
// 定义产品信息
|
|
238
|
+
const product: Product = {
|
|
239
|
+
id: 'pkg_credit_100',
|
|
240
|
+
name: '100 Credits Package',
|
|
241
|
+
price: 9.99,
|
|
242
|
+
currency: 'USD',
|
|
243
|
+
type: 'credit_package', // 'credit_package' | 'subscription' | 'change_subscription'
|
|
244
|
+
};
|
|
245
|
+
|
|
246
|
+
// 创建收银台 modal
|
|
247
|
+
const modal = new PaymentCheckoutModal({
|
|
248
|
+
// 产品信息
|
|
249
|
+
product: product,
|
|
250
|
+
|
|
251
|
+
// 自动创建订单配置
|
|
252
|
+
autoCreateOrder: {
|
|
253
|
+
productId: product.id,
|
|
254
|
+
purchaseType: 1, // 1=一次性购买, 2=订阅
|
|
255
|
+
apiHost: 'https://api.example.com',
|
|
256
|
+
accountToken: 'user-token',
|
|
257
|
+
clientId: 'your-client-id',
|
|
258
|
+
countryCode: 'SG',
|
|
259
|
+
},
|
|
260
|
+
|
|
261
|
+
// 可选配置
|
|
262
|
+
accountName: 'John Doe', // 显示在订单信息中
|
|
263
|
+
language: 'en', // 'en' | 'zh-CN'
|
|
264
|
+
|
|
265
|
+
// 回调函数
|
|
266
|
+
onPaymentSuccess: (payload) => {
|
|
267
|
+
console.log('支付成功!', payload);
|
|
268
|
+
// payload 包含: orderId, transactionId, 等信息
|
|
269
|
+
},
|
|
270
|
+
|
|
271
|
+
onPaymentFailed: (error) => {
|
|
272
|
+
console.error('支付失败:', error.message);
|
|
273
|
+
},
|
|
274
|
+
|
|
275
|
+
onPaymentMethodSelect: (method) => {
|
|
276
|
+
console.log('选择支付方式:', method.name);
|
|
277
|
+
},
|
|
278
|
+
|
|
279
|
+
onLinkPaymentStart: (methodName) => {
|
|
280
|
+
console.log('Link 支付开始:', methodName);
|
|
281
|
+
// 可以在这里显示 "请在新窗口完成支付" 提示
|
|
282
|
+
},
|
|
283
|
+
|
|
284
|
+
onLoading: (loading) => {
|
|
285
|
+
console.log('加载状态:', loading);
|
|
286
|
+
},
|
|
287
|
+
});
|
|
288
|
+
|
|
289
|
+
// 打开收银台
|
|
290
|
+
modal.open();
|
|
291
|
+
```
|
|
292
|
+
|
|
293
|
+
#### 三种初始化模式
|
|
294
|
+
|
|
295
|
+
PaymentCheckoutModal 支持三种初始化模式(三选一):
|
|
296
|
+
|
|
297
|
+
**模式 1: autoCreateOrder(推荐)**
|
|
298
|
+
```typescript
|
|
299
|
+
const modal = new PaymentCheckoutModal({
|
|
300
|
+
product: { id: 'pkg_1', name: 'Product', price: 9.99, currency: 'USD', type: 'credit_package' },
|
|
301
|
+
autoCreateOrder: {
|
|
302
|
+
productId: 'pkg_1',
|
|
303
|
+
purchaseType: 1,
|
|
304
|
+
apiHost: 'https://api.example.com',
|
|
305
|
+
accountToken: 'token',
|
|
306
|
+
clientId: 'client-id',
|
|
307
|
+
countryCode: 'SG',
|
|
308
|
+
},
|
|
309
|
+
onPaymentSuccess: (payload) => { /* ... */ },
|
|
310
|
+
});
|
|
311
|
+
```
|
|
312
|
+
|
|
313
|
+
**模式 2: payment(提前创建 OrderPayment 实例)**
|
|
314
|
+
```typescript
|
|
315
|
+
import { OrderPayment } from '@seaverse/payment-sdk';
|
|
316
|
+
|
|
317
|
+
const payment = new OrderPayment({
|
|
318
|
+
transactionId: 'txn_123',
|
|
319
|
+
apiHost: 'https://api.example.com',
|
|
320
|
+
accountToken: 'token',
|
|
321
|
+
});
|
|
322
|
+
|
|
323
|
+
const modal = new PaymentCheckoutModal({
|
|
324
|
+
product: { /* ... */ },
|
|
325
|
+
payment: payment,
|
|
326
|
+
paymentMethods: [...], // 需要手动提供支付方式列表
|
|
327
|
+
onPaymentSuccess: (payload) => { /* ... */ },
|
|
328
|
+
});
|
|
329
|
+
```
|
|
330
|
+
|
|
331
|
+
**模式 3: transactionId(延迟初始化)**
|
|
332
|
+
```typescript
|
|
333
|
+
const modal = new PaymentCheckoutModal({
|
|
334
|
+
product: { /* ... */ },
|
|
335
|
+
transactionId: 'txn_123',
|
|
336
|
+
paymentMethods: [...], // 需要手动提供支付方式列表
|
|
337
|
+
onPaymentSuccess: (payload) => { /* ... */ },
|
|
338
|
+
});
|
|
339
|
+
```
|
|
340
|
+
|
|
341
|
+
#### 配置选项说明
|
|
342
|
+
|
|
343
|
+
| 选项 | 类型 | 必填 | 说明 |
|
|
344
|
+
|------|------|------|------|
|
|
345
|
+
| `product` | `Product` | 否 | 产品信息(id, name, price, currency, type) |
|
|
346
|
+
| `autoCreateOrder` | `AutoCreateOrderConfig` | 三选一 | 自动创建订单配置(推荐) |
|
|
347
|
+
| `payment` | `OrderPayment` | 三选一 | 提前创建的 OrderPayment 实例 |
|
|
348
|
+
| `transactionId` | `string` | 三选一 | 订单 transaction_id(延迟初始化) |
|
|
349
|
+
| `paymentMethods` | `PaymentMethod[]` | 否 | 支付方式列表(autoCreateOrder 模式会自动获取) |
|
|
350
|
+
| `accountName` | `string` | 否 | 用户账号名称(显示在订单信息中) |
|
|
351
|
+
| `language` | `'en' \| 'zh-CN'` | 否 | 语言设置(默认 'en') |
|
|
352
|
+
| `onPaymentSuccess` | `(payload) => void` | 否 | 支付成功回调 |
|
|
353
|
+
| `onPaymentFailed` | `(error) => void` | 否 | 支付失败回调 |
|
|
354
|
+
| `onPaymentMethodSelect` | `(method) => void` | 否 | 选择支付方式回调 |
|
|
355
|
+
| `onLinkPaymentStart` | `(methodName) => void` | 否 | Link 支付开始回调 |
|
|
356
|
+
| `onLoading` | `(loading) => void` | 否 | 加载状态回调 |
|
|
357
|
+
|
|
358
|
+
#### 产品类型说明
|
|
359
|
+
|
|
360
|
+
| 类型 | 值 | 说明 |
|
|
361
|
+
|------|------|------|
|
|
362
|
+
| 信用包 | `'credit_package'` | 一次性购买积分包 |
|
|
363
|
+
| 订阅 | `'subscription'` | 新订阅购买 |
|
|
364
|
+
| 变更订阅 | `'change_subscription'` | 订阅升级/降级 |
|
|
365
|
+
|
|
366
|
+
#### 支付方式说明
|
|
367
|
+
|
|
368
|
+
PaymentCheckoutModal 支持三种支付方式:
|
|
369
|
+
|
|
370
|
+
1. **Link Payment**: 跳转到外部支付页面,自动轮询订单状态
|
|
371
|
+
2. **Dropin Payment**: 嵌入式支付表单,支持信用卡、PayPal 等
|
|
372
|
+
3. **BindCard Payment**: 使用已保存的卡片支付(显示卡片列表)
|
|
373
|
+
|
|
374
|
+
#### 完整示例
|
|
375
|
+
|
|
376
|
+
查看完整示例代码:`examples/payment-sdk-demo/src/components/new-sdk/PaymentCheckoutSection.tsx`
|
|
377
|
+
|
|
378
|
+
---
|
|
379
|
+
|
|
222
380
|
#### 环境配置
|
|
223
381
|
|
|
224
382
|
SDK 根据 `environment` 自动配置以下参数:
|