@seaverse/payment-sdk 0.6.1 → 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/dist/style.css +1482 -0
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -412,21 +412,13 @@ interface SubscriptionParams {
|
|
|
412
412
|
firstDays?: number;
|
|
413
413
|
/** 每周期金额(USD) */
|
|
414
414
|
periodAmount: number;
|
|
415
|
-
/** 计费周期(可选,"month" 或 "year") */
|
|
416
|
-
billing_period?: BillingPeriod;
|
|
417
415
|
}
|
|
418
416
|
/**
|
|
419
417
|
* 基础结账选项
|
|
420
418
|
*/
|
|
421
419
|
interface BaseCheckoutOptions {
|
|
422
|
-
/** 商品 ID
|
|
423
|
-
productId
|
|
424
|
-
/** 商品名称(仅当未提供 productId 时使用) */
|
|
425
|
-
productName?: string;
|
|
426
|
-
/** 价格 USD(仅当未提供 productId 时使用) */
|
|
427
|
-
price?: number;
|
|
428
|
-
/** 额外自定义数据 */
|
|
429
|
-
extra?: Record<string, unknown>;
|
|
420
|
+
/** 商品 ID(必填,自动查询价格) */
|
|
421
|
+
productId: string;
|
|
430
422
|
/** 语言设置 */
|
|
431
423
|
language?: string;
|
|
432
424
|
/** 用户名(显示用) */
|
|
@@ -438,6 +430,8 @@ interface BaseCheckoutOptions {
|
|
|
438
430
|
* 一次性购买选项
|
|
439
431
|
*/
|
|
440
432
|
interface CheckoutOptions extends BaseCheckoutOptions {
|
|
433
|
+
/** 商品名称(可选,用于支付弹窗显示) */
|
|
434
|
+
productName?: string;
|
|
441
435
|
/** 支付成功回调 */
|
|
442
436
|
onSuccess?: (result: PaymentResult) => void;
|
|
443
437
|
/** 支付失败/取消回调 */
|
|
@@ -449,13 +443,7 @@ interface CheckoutOptions extends BaseCheckoutOptions {
|
|
|
449
443
|
* 订阅购买选项
|
|
450
444
|
*/
|
|
451
445
|
interface SubscribeOptions extends CheckoutOptions {
|
|
452
|
-
/**
|
|
453
|
-
period: SubscriptionPeriod;
|
|
454
|
-
/** 每期金额 */
|
|
455
|
-
periodAmount: number;
|
|
456
|
-
/** 首次扣款延迟天数(0 = 立即扣款) */
|
|
457
|
-
firstDays?: number;
|
|
458
|
-
/** 计费周期(可选,"month" 或 "year") */
|
|
446
|
+
/** 计费周期(可选,"month" 或 "year",默认 "month") */
|
|
459
447
|
billing_period?: BillingPeriod;
|
|
460
448
|
}
|
|
461
449
|
/**
|
|
@@ -468,7 +456,7 @@ interface ShowPaymentOptions {
|
|
|
468
456
|
language?: string;
|
|
469
457
|
/** 用户名 */
|
|
470
458
|
userName?: string;
|
|
471
|
-
/**
|
|
459
|
+
/** 商品名称(可选,用于显示) */
|
|
472
460
|
productName?: string;
|
|
473
461
|
/** 来源标识 */
|
|
474
462
|
from?: string;
|
|
@@ -481,18 +469,12 @@ interface ShowPaymentOptions {
|
|
|
481
469
|
* SDK 结账请求
|
|
482
470
|
*/
|
|
483
471
|
interface SDKCheckoutRequest {
|
|
484
|
-
/** 商品 ID
|
|
485
|
-
product_id
|
|
486
|
-
/**
|
|
487
|
-
product_name?: string;
|
|
488
|
-
/** 价格(USD) */
|
|
489
|
-
price?: number;
|
|
490
|
-
/** 购买类型:1-一次性,2-订阅 */
|
|
472
|
+
/** 商品 ID(必填)*/
|
|
473
|
+
product_id: string;
|
|
474
|
+
/** 购买类型:1-一次性,2-订阅(必填) */
|
|
491
475
|
purchase_type: PurchaseType;
|
|
492
|
-
/**
|
|
493
|
-
|
|
494
|
-
/** 额外数据 */
|
|
495
|
-
extra?: Record<string, unknown>;
|
|
476
|
+
/** 计费周期(可选,仅订阅时使用,默认 'month')- 用于区分月付和年付 */
|
|
477
|
+
billing_period?: BillingPeriod;
|
|
496
478
|
/** 支付完成后的重定向 URL(可选) */
|
|
497
479
|
redirect_url?: string;
|
|
498
480
|
}
|
|
@@ -775,10 +757,7 @@ declare class CheckoutAPI {
|
|
|
775
757
|
* 创建一次性购买订单
|
|
776
758
|
*/
|
|
777
759
|
createOneTimeCheckout(params: {
|
|
778
|
-
productId
|
|
779
|
-
productName?: string;
|
|
780
|
-
price?: number;
|
|
781
|
-
extra?: Record<string, unknown>;
|
|
760
|
+
productId: string;
|
|
782
761
|
/** 支付完成后的重定向 URL */
|
|
783
762
|
redirectUrl?: string;
|
|
784
763
|
}): Promise<CheckoutResult>;
|
|
@@ -786,11 +765,8 @@ declare class CheckoutAPI {
|
|
|
786
765
|
* 创建订阅订单
|
|
787
766
|
*/
|
|
788
767
|
createSubscriptionCheckout(params: {
|
|
789
|
-
productId
|
|
790
|
-
|
|
791
|
-
price?: number;
|
|
792
|
-
subscription: SubscriptionParams;
|
|
793
|
-
extra?: Record<string, unknown>;
|
|
768
|
+
productId: string;
|
|
769
|
+
billingPeriod?: BillingPeriod;
|
|
794
770
|
/** 支付完成后的重定向 URL */
|
|
795
771
|
redirectUrl?: string;
|
|
796
772
|
}): Promise<CheckoutResult>;
|
|
@@ -1101,7 +1077,7 @@ declare const BIZ_CODE: {
|
|
|
1101
1077
|
/**
|
|
1102
1078
|
* SDK version
|
|
1103
1079
|
*/
|
|
1104
|
-
declare const VERSION = "0.
|
|
1080
|
+
declare const VERSION = "0.7.0";
|
|
1105
1081
|
|
|
1106
1082
|
export { API_ENDPOINTS, BIZ_CODE, COMPONENT_LOAD_TIMEOUT, CheckoutAPI, DEFAULT_CHECKOUT_CONFIG, ENV_CONFIG, HTTP_STATUS, PAYMENT_ELEMENT_NAME, PaymentAPIError, PaymentCheckoutClient, PaymentClient, SeaArtPayLoader, VERSION, centsToDollars, createCheckoutPaymentError, delay, dollarsToCents, formatPrice, generateOrderReference, getCurrentUrl, getGlobalLoader, getSDKLocale, isBrowser, isCheckoutPaymentError, resetGlobalLoader, safeJsonParse, withTimeout };
|
|
1107
1083
|
export type { ApiErrorResponse, ApiResponse, ApiSuccessResponse, BaseCheckoutOptions, BillingPeriod, CheckoutAPIConfig, CheckoutAPIResponse, CheckoutClientConfig, CheckoutClientStatus, CheckoutOptions, CheckoutPaymentError, CheckoutPaymentErrorCode, CheckoutResult, ComponentLoadStatus, CreditAccount, CreditAccountStatus, CreditDetailResponse, CreditDetailSuccessResponse, CreditPoolDetail, CreditPoolType, CreditTransaction, ListTransactionsRequest, LoaderConfig, PaymentClientOptions, PaymentEnvironment, PaymentReadyEventDetail, PaymentResult, PaymentSuccessEventDetail, PaymentUnsuccessEventDetail, PaymentUnsuccessResult, PurchaseType, SDKCheckoutRequest, SDKCheckoutResponse, SDKConfig, SDKLoadStatus, SeaArtPaymentElement, ShowPaymentOptions, SubscribeOptions, SubscriptionParams, SubscriptionPeriod, TransactionListResponse, TransactionStatus, TransactionType };
|
package/dist/index.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;
|