@seaverse/payment-sdk 0.6.2 → 0.7.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 +14 -15
- package/dist/index.browser.js +14 -38
- package/dist/index.browser.js.map +1 -1
- package/dist/index.cjs +14 -38
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +15 -39
- package/dist/index.js +14 -38
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -67,17 +67,15 @@ await checkoutClient.init();
|
|
|
67
67
|
|
|
68
68
|
// One-time purchase
|
|
69
69
|
await checkoutClient.checkout({
|
|
70
|
-
productId: 'pkg_starter',
|
|
70
|
+
productId: 'pkg_starter', // Required
|
|
71
71
|
onSuccess: (res) => console.log('Payment success:', res),
|
|
72
72
|
onError: (err) => console.error('Payment failed:', err),
|
|
73
73
|
});
|
|
74
74
|
|
|
75
75
|
// Subscription
|
|
76
76
|
await checkoutClient.subscribe({
|
|
77
|
-
productId: 'pro',
|
|
78
|
-
|
|
79
|
-
periodAmount: 24.99,
|
|
80
|
-
billing_period: 'month', // Optional: billing period - 'month' | 'year'
|
|
77
|
+
productId: 'pro', // Required
|
|
78
|
+
billing_period: 'month', // Optional: 'month' | 'year' (default: 'month')
|
|
81
79
|
onSuccess: (res) => console.log('Subscription success:', res),
|
|
82
80
|
});
|
|
83
81
|
```
|
|
@@ -146,18 +144,11 @@ interface CheckoutClientConfig {
|
|
|
146
144
|
}
|
|
147
145
|
```
|
|
148
146
|
|
|
149
|
-
###
|
|
147
|
+
### Checkout Options
|
|
150
148
|
|
|
151
149
|
```typescript
|
|
152
|
-
interface
|
|
153
|
-
productId
|
|
154
|
-
productName?: string; // Product name (if no productId)
|
|
155
|
-
price?: number; // Price in USD (if no productId)
|
|
156
|
-
period: SubscriptionPeriod; // Subscription period: 'week' | 'month' | 'year'
|
|
157
|
-
periodAmount: number; // Amount per period (USD)
|
|
158
|
-
firstDays?: number; // First billing delay in days (default: 0)
|
|
159
|
-
billing_period?: 'month' | 'year'; // Optional: billing period
|
|
160
|
-
extra?: Record<string, unknown>; // Extra custom data
|
|
150
|
+
interface CheckoutOptions {
|
|
151
|
+
productId: string; // Product ID (required)
|
|
161
152
|
language?: string; // Language setting
|
|
162
153
|
userName?: string; // User name for display
|
|
163
154
|
redirectUrl?: string; // Redirect URL after payment
|
|
@@ -167,6 +158,14 @@ interface SubscribeOptions {
|
|
|
167
158
|
}
|
|
168
159
|
```
|
|
169
160
|
|
|
161
|
+
### Subscription Options
|
|
162
|
+
|
|
163
|
+
```typescript
|
|
164
|
+
interface SubscribeOptions extends CheckoutOptions {
|
|
165
|
+
billing_period?: 'month' | 'year'; // Optional: billing period (default: 'month')
|
|
166
|
+
}
|
|
167
|
+
```
|
|
168
|
+
|
|
170
169
|
### Environment Configuration
|
|
171
170
|
|
|
172
171
|
| Environment | API Host |
|
package/dist/index.browser.js
CHANGED
|
@@ -495,10 +495,7 @@ class CheckoutAPI {
|
|
|
495
495
|
async createOneTimeCheckout(params) {
|
|
496
496
|
return this.createCheckout({
|
|
497
497
|
product_id: params.productId,
|
|
498
|
-
product_name: params.productName,
|
|
499
|
-
price: params.price,
|
|
500
498
|
purchase_type: 1,
|
|
501
|
-
extra: params.extra,
|
|
502
499
|
redirect_url: params.redirectUrl,
|
|
503
500
|
});
|
|
504
501
|
}
|
|
@@ -508,11 +505,8 @@ class CheckoutAPI {
|
|
|
508
505
|
async createSubscriptionCheckout(params) {
|
|
509
506
|
return this.createCheckout({
|
|
510
507
|
product_id: params.productId,
|
|
511
|
-
product_name: params.productName,
|
|
512
|
-
price: params.price,
|
|
513
508
|
purchase_type: 2,
|
|
514
|
-
|
|
515
|
-
extra: params.extra,
|
|
509
|
+
billing_period: params.billingPeriod,
|
|
516
510
|
redirect_url: params.redirectUrl,
|
|
517
511
|
});
|
|
518
512
|
}
|
|
@@ -561,24 +555,9 @@ class CheckoutAPI {
|
|
|
561
555
|
* 验证请求参数
|
|
562
556
|
*/
|
|
563
557
|
validateRequest(request) {
|
|
564
|
-
// 必须提供
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
if (!hasProductId && !hasManualProduct) {
|
|
568
|
-
throw this.createError('INVALID_PARAMS', '必须提供 productId 或 (productName + price)');
|
|
569
|
-
}
|
|
570
|
-
// 订阅类型必须提供订阅参数
|
|
571
|
-
if (request.purchase_type === 2 && !request.subscription) {
|
|
572
|
-
throw this.createError('INVALID_PARAMS', '订阅类型必须提供 subscription 参数');
|
|
573
|
-
}
|
|
574
|
-
// 验证订阅参数
|
|
575
|
-
if (request.subscription) {
|
|
576
|
-
if (!request.subscription.period) {
|
|
577
|
-
throw this.createError('INVALID_PARAMS', '订阅参数缺少 period');
|
|
578
|
-
}
|
|
579
|
-
if (request.subscription.periodAmount == null) {
|
|
580
|
-
throw this.createError('INVALID_PARAMS', '订阅参数缺少 periodAmount');
|
|
581
|
-
}
|
|
558
|
+
// 必须提供 product_id
|
|
559
|
+
if (!request.product_id) {
|
|
560
|
+
throw this.createError('INVALID_PARAMS', '必须提供 product_id');
|
|
582
561
|
}
|
|
583
562
|
}
|
|
584
563
|
/**
|
|
@@ -767,12 +746,13 @@ class PaymentCheckoutClient {
|
|
|
767
746
|
async checkout(options) {
|
|
768
747
|
await this.ensureReady();
|
|
769
748
|
this.log('发起一次性购买:', options);
|
|
749
|
+
// 验证必需参数
|
|
750
|
+
if (!options.productId) {
|
|
751
|
+
throw this.createError('INVALID_PARAMS', '缺少必需参数: productId');
|
|
752
|
+
}
|
|
770
753
|
// 调用结账 API
|
|
771
754
|
const result = await this.checkoutAPI.createOneTimeCheckout({
|
|
772
755
|
productId: options.productId,
|
|
773
|
-
productName: options.productName,
|
|
774
|
-
price: options.price,
|
|
775
|
-
extra: options.extra,
|
|
776
756
|
redirectUrl: options.redirectUrl,
|
|
777
757
|
});
|
|
778
758
|
// 自动打开支付弹窗
|
|
@@ -804,18 +784,14 @@ class PaymentCheckoutClient {
|
|
|
804
784
|
async subscribe(options) {
|
|
805
785
|
await this.ensureReady();
|
|
806
786
|
this.log('发起订阅购买:', options);
|
|
787
|
+
// 验证必需参数
|
|
788
|
+
if (!options.productId) {
|
|
789
|
+
throw this.createError('INVALID_PARAMS', '缺少必需参数: productId');
|
|
790
|
+
}
|
|
807
791
|
// 调用结账 API
|
|
808
792
|
const result = await this.checkoutAPI.createSubscriptionCheckout({
|
|
809
793
|
productId: options.productId,
|
|
810
|
-
|
|
811
|
-
price: options.price,
|
|
812
|
-
subscription: {
|
|
813
|
-
period: options.period,
|
|
814
|
-
periodAmount: options.periodAmount,
|
|
815
|
-
firstDays: options.firstDays ?? 0,
|
|
816
|
-
billing_period: options.billing_period,
|
|
817
|
-
},
|
|
818
|
-
extra: options.extra,
|
|
794
|
+
billingPeriod: options.billing_period,
|
|
819
795
|
redirectUrl: options.redirectUrl,
|
|
820
796
|
});
|
|
821
797
|
// 自动打开支付弹窗
|
|
@@ -1167,7 +1143,7 @@ function getSDKLocale(locale) {
|
|
|
1167
1143
|
/**
|
|
1168
1144
|
* SDK version
|
|
1169
1145
|
*/
|
|
1170
|
-
const VERSION$2 = '0.
|
|
1146
|
+
const VERSION$2 = '0.7.0';
|
|
1171
1147
|
|
|
1172
1148
|
var __defProp = Object.defineProperty;
|
|
1173
1149
|
var __defProps = Object.defineProperties;
|