@seaverse/payment-sdk 0.9.0 → 0.9.2

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/dist/index.d.ts CHANGED
@@ -1032,10 +1032,96 @@ declare const BIZ_CODE: {
1032
1032
  readonly INVALID_ORDER_STATUS: 4006;
1033
1033
  };
1034
1034
 
1035
+ /**
1036
+ * 共享类型定义
1037
+ * Shared types for CreditPackageModal and GenericPackageModal
1038
+ */
1039
+
1040
+ /** 环境类型 */
1041
+ type Environment = 'development' | 'production';
1042
+ /** 环境配置接口 */
1043
+ interface EnvironmentConfig {
1044
+ /** SDK 脚本 URL */
1045
+ scriptUrl: string;
1046
+ /** 客户端 ID */
1047
+ clientId: string;
1048
+ /** 订单 API 地址 */
1049
+ orderApiUrl: string;
1050
+ /** 钱包 API 地址 */
1051
+ walletApiUrl: string;
1052
+ /** CSS 文件 URL */
1053
+ cssUrl: string;
1054
+ }
1055
+ /**
1056
+ * 语言代码(ISO 639-1 + BCP 47 区域子标签)
1057
+ *
1058
+ * 格式说明:
1059
+ * - 基础码:ISO 639-1 两字母语言码(en, zh, ja, ko...)
1060
+ * - 区域变体:BCP 47 格式 language-REGION(zh-CN, zh-TW, pt-BR...)
1061
+ * - zh-CN / zh-TW 需要区分简繁体,不能只用 zh
1062
+ */
1063
+ type LocaleCode = 'en' | 'zh' | 'zh-TW' | 'ja' | 'ko' | 'es' | 'fr' | 'de' | 'pt' | 'ru' | 'ar' | 'hi' | 'id';
1064
+ /** 国家/地区代码(ISO 3166-1 alpha-2) */
1065
+ type CountryCode = 'US' | 'CN' | 'TW' | 'JP' | 'KR' | 'ES' | 'FR' | 'DE' | 'PT' | 'BR' | 'RU' | 'SA' | 'IN' | 'ID';
1066
+ /**
1067
+ * SDK 配置选项 - 简化版(支持环境变量)
1068
+ * 用户只需提供 environment、countryCode、accountToken 三个核心参数
1069
+ * SDK 会自动根据 environment 选择对应的配置
1070
+ */
1071
+ interface PaymentSDKConfig {
1072
+ /** 环境变量(development/production) - SDK 自动选择对应配置 */
1073
+ environment: Environment;
1074
+ /** 国家/地区代码 */
1075
+ countryCode?: CountryCode;
1076
+ /** 账户 Token(用于用户认证) */
1077
+ accountToken: string;
1078
+ /** 业务类型:1-一次性,2-订阅(可选,默认为 1) */
1079
+ businessType?: 1 | 2;
1080
+ /** 脚本加载超时(毫秒,默认 10000ms) */
1081
+ scriptTimeout?: number;
1082
+ /** 支付方式类型过滤(可选,默认 'dropin') */
1083
+ paymentMethodType?: string;
1084
+ /** 自定义脚本 URL(覆盖环境配置) */
1085
+ scriptUrl?: string;
1086
+ /** 自定义客户端 ID(覆盖环境配置) */
1087
+ clientId?: string;
1088
+ /** 自定义订单 API 地址(覆盖环境配置) */
1089
+ orderApiUrl?: string;
1090
+ /** 自定义 CSS URL(覆盖环境配置) */
1091
+ cssUrl?: string;
1092
+ }
1093
+ /**
1094
+ * Base package modal options - common configuration for all package modals
1095
+ */
1096
+ interface BasePackageModalOptions<TPackage extends BasePackage> {
1097
+ /** SDK configuration (required for automatic SDK initialization) */
1098
+ sdkConfig: PaymentSDKConfig;
1099
+ /** Language (default 'en') */
1100
+ language: LocaleCode;
1101
+ /**
1102
+ * Payment success callback - notifies when payment is completed
1103
+ * @param orderId Order ID
1104
+ * @param transactionId Transaction ID
1105
+ * @param pkg Purchased package
1106
+ */
1107
+ onPaymentSuccess?: (orderId: string, transactionId: string, pkg: TPackage) => void;
1108
+ /**
1109
+ * Payment failed callback
1110
+ * @param error Error information
1111
+ * @param pkg Package that failed to purchase
1112
+ */
1113
+ onPaymentFailed?: (error: Error, pkg: TPackage) => void;
1114
+ /** Modal close callback */
1115
+ onClose?: () => void;
1116
+ paymentMethod?: PaymentMethod;
1117
+ accountToken?: string;
1118
+ }
1119
+
1035
1120
  /**
1036
1121
  * SeaartPayment Types
1037
1122
  * SeaartPaymentComponent SDK 相关类型定义
1038
1123
  */
1124
+
1039
1125
  declare global {
1040
1126
  interface Window {
1041
1127
  SeaartPaymentComponent: SeaartPaymentComponentSDK;
@@ -1187,7 +1273,7 @@ interface SeaartPaymentSDKConfig {
1187
1273
  /** 客户端 ID */
1188
1274
  clientId: string;
1189
1275
  /** 语言 */
1190
- language?: string;
1276
+ language?: LocaleCode;
1191
1277
  /** 脚本加载超时(毫秒) */
1192
1278
  scriptTimeout?: number;
1193
1279
  /** CSS 样式表 URL(可选) */
@@ -1569,9 +1655,10 @@ declare class PaymentModal {
1569
1655
  *
1570
1656
  * 设计风格:深色卡片 + 清晰信息层次 + 渐变 CTA 按钮
1571
1657
  */
1658
+
1572
1659
  interface RetentionModalOptions {
1573
1660
  /** 语言,默认 'en' */
1574
- language?: 'en' | 'zh-CN';
1661
+ language?: LocaleCode;
1575
1662
  /** 商品名称 */
1576
1663
  productName: string;
1577
1664
  /** 购买数量(积分数等) */
@@ -1767,80 +1854,6 @@ declare class SeaartPaymentSDK {
1767
1854
  destroy(): void;
1768
1855
  }
1769
1856
 
1770
- /**
1771
- * 共享类型定义
1772
- * Shared types for CreditPackageModal and GenericPackageModal
1773
- */
1774
-
1775
- /** 环境类型 */
1776
- type Environment = 'development' | 'production';
1777
- /** 环境配置接口 */
1778
- interface EnvironmentConfig {
1779
- /** SDK 脚本 URL */
1780
- scriptUrl: string;
1781
- /** 客户端 ID */
1782
- clientId: string;
1783
- /** 订单 API 地址 */
1784
- orderApiUrl: string;
1785
- /** 钱包 API 地址 */
1786
- walletApiUrl: string;
1787
- /** CSS 文件 URL */
1788
- cssUrl: string;
1789
- }
1790
- /**
1791
- * SDK 配置选项 - 简化版(支持环境变量)
1792
- * 用户只需提供 environment、countryCode、accountToken 三个核心参数
1793
- * SDK 会自动根据 environment 选择对应的配置
1794
- */
1795
- interface PaymentSDKConfig {
1796
- /** 环境变量(development/production) - SDK 自动选择对应配置 */
1797
- environment: Environment;
1798
- /** 国家/地区代码 */
1799
- countryCode: string;
1800
- /** 账户 Token(用于用户认证) */
1801
- accountToken?: string;
1802
- /** 业务类型:1-一次性,2-订阅(可选,默认为 1) */
1803
- businessType?: 1 | 2;
1804
- /** 脚本加载超时(毫秒,默认 10000ms) */
1805
- scriptTimeout?: number;
1806
- /** 支付方式类型过滤(可选,默认 'dropin') */
1807
- paymentMethodType?: string;
1808
- /** 自定义脚本 URL(覆盖环境配置) */
1809
- scriptUrl?: string;
1810
- /** 自定义客户端 ID(覆盖环境配置) */
1811
- clientId?: string;
1812
- /** 自定义订单 API 地址(覆盖环境配置) */
1813
- orderApiUrl?: string;
1814
- /** 自定义 CSS URL(覆盖环境配置) */
1815
- cssUrl?: string;
1816
- }
1817
- /**
1818
- * Base package modal options - common configuration for all package modals
1819
- */
1820
- interface BasePackageModalOptions<TPackage extends BasePackage> {
1821
- /** SDK configuration (required for automatic SDK initialization) */
1822
- sdkConfig: PaymentSDKConfig;
1823
- /** Language (default 'en') */
1824
- language?: 'en' | 'zh-CN';
1825
- /**
1826
- * Payment success callback - notifies when payment is completed
1827
- * @param orderId Order ID
1828
- * @param transactionId Transaction ID
1829
- * @param pkg Purchased package
1830
- */
1831
- onPaymentSuccess?: (orderId: string, transactionId: string, pkg: TPackage) => void;
1832
- /**
1833
- * Payment failed callback
1834
- * @param error Error information
1835
- * @param pkg Package that failed to purchase
1836
- */
1837
- onPaymentFailed?: (error: Error, pkg: TPackage) => void;
1838
- /** Modal close callback */
1839
- onClose?: () => void;
1840
- paymentMethod?: PaymentMethod;
1841
- accountToken?: string;
1842
- }
1843
-
1844
1857
  /**
1845
1858
  * BasePackageModal - Abstract base class for package modals
1846
1859
  * Provides shared logic for SDK initialization, payment flow, and event handling
@@ -1853,7 +1866,7 @@ interface BasePackageModalOptions<TPackage extends BasePackage> {
1853
1866
  declare abstract class BasePackageModal<TPackage extends BasePackage, TOptions extends BasePackageModalOptions<TPackage>> {
1854
1867
  protected modal: PaymentModal;
1855
1868
  protected options: TOptions;
1856
- protected language: 'en' | 'zh-CN';
1869
+ protected language: LocaleCode;
1857
1870
  protected resizeHandler: (() => void) | null;
1858
1871
  protected isInitializingSDK: boolean;
1859
1872
  protected sdkInitialized: boolean;
@@ -1960,6 +1973,17 @@ declare class CreditPackageModal extends BasePackageModal<CreditPackageItem, Cre
1960
1973
  * Override open to fetch packages before rendering
1961
1974
  */
1962
1975
  open(): Promise<void>;
1976
+ /**
1977
+ * 覆盖 BasePackageModal 的 initializeSDK 方法
1978
+ * CreditPackageModal 使用 PaymentCheckoutModal,不需要 BasePackageModal 的 SDK 初始化
1979
+ * PaymentCheckoutModal 会自行处理 SDK 初始化
1980
+ */
1981
+ protected initializeSDK(): Promise<void>;
1982
+ /**
1983
+ * 覆盖 BasePackageModal 的 waitForSDKInitialization 方法
1984
+ * CreditPackageModal 使用 PaymentCheckoutModal,不需要等待 BasePackageModal 的 SDK 初始化
1985
+ */
1986
+ protected waitForSDKInitialization(_timeout?: number, _maxRetries?: number): Promise<boolean>;
1963
1987
  /**
1964
1988
  * Create and configure the PaymentModal instance
1965
1989
  */
@@ -2029,6 +2053,17 @@ interface GenericPackageModalOptions extends BasePackageModalOptions<GenericPack
2029
2053
  }
2030
2054
  declare class GenericPackageModal extends BasePackageModal<GenericPackage, GenericPackageModalOptions> {
2031
2055
  constructor(options: GenericPackageModalOptions);
2056
+ /**
2057
+ * 覆盖 BasePackageModal 的 initializeSDK 方法
2058
+ * GenericPackageModal 使用 PaymentCheckoutModal,不需要 BasePackageModal 的 SDK 初始化
2059
+ * PaymentCheckoutModal 会自行处理 SDK 初始化
2060
+ */
2061
+ protected initializeSDK(): Promise<void>;
2062
+ /**
2063
+ * 覆盖 BasePackageModal 的 waitForSDKInitialization 方法
2064
+ * GenericPackageModal 使用 PaymentCheckoutModal,不需要等待 BasePackageModal 的 SDK 初始化
2065
+ */
2066
+ protected waitForSDKInitialization(_timeout?: number, _maxRetries?: number): Promise<boolean>;
2032
2067
  /**
2033
2068
  * Create and configure the PaymentModal instance
2034
2069
  */
@@ -2202,7 +2237,7 @@ interface AutoCreateOrderConfig {
2202
2237
  /** 客户端 ID */
2203
2238
  clientId: string;
2204
2239
  /** 国家代码 */
2205
- countryCode: string;
2240
+ language_code: LocaleCode;
2206
2241
  }
2207
2242
  /**
2208
2243
  * PaymentCheckoutModal 配置选项
@@ -2245,7 +2280,7 @@ interface PaymentCheckoutModalOptions {
2245
2280
  /** 用户账号名称 */
2246
2281
  accountName?: string;
2247
2282
  /** 语言设置 */
2248
- language?: 'en' | 'zh-CN';
2283
+ language?: LocaleCode;
2249
2284
  }
2250
2285
 
2251
2286
  /**
@@ -2327,7 +2362,10 @@ declare class PaymentCheckoutModal {
2327
2362
  */
2328
2363
  private renderPaymentMethods;
2329
2364
  /**
2330
- * 自动选中默认支付方式(优先选中第一个 Dropin 支付方式)
2365
+ * 自动选中默认支付方式
2366
+ * 策略:
2367
+ * - 如果有 Dropin(payment_type === 2),自动选中并渲染表单
2368
+ * - 如果只有 Link(payment_type === 1),不自动选中,让用户手动选择
2331
2369
  */
2332
2370
  private autoSelectDefaultPaymentMethod;
2333
2371
  /**
@@ -2452,6 +2490,16 @@ declare function hideLoadingIndicator(loader?: HTMLElement | null): void;
2452
2490
  */
2453
2491
  declare function showInfoMessage(message: string, duration?: number): void;
2454
2492
 
2493
+ /**
2494
+ * PurchaseSuccessModal - 购买成功弹窗
2495
+ * 纯 JavaScript 实现,不依赖 React
2496
+ *
2497
+ * 参考设计: credit-pack-success-modal
2498
+ * - 邮件确认卡片风格
2499
+ * - 精美的动画效果(淡入淡出、缩放)
2500
+ * - 包含成功图标、套餐详情、积分数、支付金额
2501
+ */
2502
+
2455
2503
  interface PurchaseSuccessData {
2456
2504
  /** 套餐名称 */
2457
2505
  packName: string;
@@ -2470,7 +2518,7 @@ interface PurchaseSuccessModalOptions {
2470
2518
  /** 购买成功数据 */
2471
2519
  data: PurchaseSuccessData;
2472
2520
  /** 语言,默认 'en' */
2473
- language?: 'en' | 'zh-CN';
2521
+ language?: LocaleCode;
2474
2522
  /** 关闭回调 */
2475
2523
  onClose?: () => void;
2476
2524
  }
@@ -2540,9 +2588,10 @@ declare class PurchaseSuccessModal {
2540
2588
  * 样式完全参考 next-meta 项目的设计
2541
2589
  * 按钮逻辑参考 @seaart/payment-component
2542
2590
  */
2591
+
2543
2592
  interface PaymentVerificationOptions {
2544
2593
  /** 语言,默认 'en' */
2545
- language?: 'en' | 'zh-CN';
2594
+ language?: LocaleCode;
2546
2595
  /** 交易ID */
2547
2596
  transactionId: string;
2548
2597
  /** 产品名称(可选) */
@@ -2645,9 +2694,10 @@ declare class PaymentVerificationModal {
2645
2694
  * 样式与 PaymentVerificationModal 保持一致
2646
2695
  * 深蓝渐变主题背景,按钮样式统一
2647
2696
  */
2697
+
2648
2698
  interface PaymentFailedModalOptions {
2649
2699
  /** 语言,默认 'en' */
2650
- language?: 'en' | 'zh-CN';
2700
+ language?: LocaleCode;
2651
2701
  /** 错误标题 */
2652
2702
  title?: string;
2653
2703
  /** 错误消息 */
@@ -2989,6 +3039,7 @@ declare function fetchAvailablePackages(apiHost: string, token: string): Promise
2989
3039
  * - SVG 徽章装饰(首充双倍)
2990
3040
  * - 悬停微交互和平滑过渡
2991
3041
  */
3042
+
2992
3043
  interface CreditPackCardOptions {
2993
3044
  /** 积分包 ID */
2994
3045
  id: string;
@@ -3009,7 +3060,7 @@ interface CreditPackCardOptions {
3009
3060
  /** 是否首充双倍 */
3010
3061
  isFirstPurchase?: boolean;
3011
3062
  /** 语言 */
3012
- language?: 'en' | 'zh-CN';
3063
+ language?: LocaleCode;
3013
3064
  /** 点击购买回调 */
3014
3065
  onBuy: (packId: string) => Promise<void>;
3015
3066
  }
@@ -3090,7 +3141,7 @@ declare class CreditPackCard {
3090
3141
  /**
3091
3142
  * SDK version
3092
3143
  */
3093
- declare const VERSION = "0.9.0";
3144
+ declare const VERSION = "0.9.2";
3094
3145
 
3095
3146
  export { API_ENDPOINTS, BIZ_CODE, BindCardPaymentComponent, COMPONENT_LOAD_TIMEOUT, CheckoutAPI, CreditPackCard, CreditPackageModal, DEFAULT_CHECKOUT_CONFIG, DropinPaymentComponent, DropinPaymentModal, ENVIRONMENT_CONFIGS, ENV_CONFIG, ErrorHandler, GRID_COLUMNS, GenericPackageModal, HTTP_STATUS, LinkPaymentComponent, OrderPayment, PAYMENT_ELEMENT_NAME, PaymentAPIError, PaymentCheckoutClient, PaymentCheckoutModal, PaymentClient, PaymentError, PaymentFailedModal, PaymentModal, PaymentStorage, PaymentVerificationModal, PurchaseSuccessModal, RESPONSIVE_BREAKPOINTS, RetentionModal, SDK_CONFIG, ScriptLoader, SeaArtPayLoader, SeaartPaymentSDK, StylesheetLoader, VERSION, centsToDollars, changeSubscription, checkOrderStatus, createCheckoutPaymentError, createOrder, delay, dollarsToCents, fetchAvailablePackages, formatPrice, generateOrderReference, getActiveSubscription, getCreditDetail, getCurrentSubscription, getCurrentUrl, getGlobalLoader, getSDKLocale, hideLoadingIndicator, isBrowser, isCheckoutPaymentError, pollOrderStatus, resetGlobalLoader, restartSubscription, safeJsonParse, showErrorMessage, showInfoMessage, showLoadingIndicator, showSuccessMessage, withTimeout };
3096
- export type { ActiveSubscription, ApiErrorResponse, ApiResponse, ApiSuccessResponse, AutoCreateOrderConfig, AvailablePackagesResponse, BaseCheckoutOptions, BillingPeriod$1 as BillingPeriod, BindCard, BindCardCallbacks, BindCardPaymentOptions, CheckoutAPIConfig, CheckoutAPIResponse, CheckoutClientConfig, CheckoutClientStatus, CheckoutOptions, CheckoutPaymentError, CheckoutPaymentErrorCode, CheckoutResult, ComponentLoadStatus, CreateOrderResponse, CreditAccount, CreditAccountStatus, CreditDetailResponse$1 as CreditDetailResponse, CreditDetailSuccessResponse, CreditPackCardOptions, CreditPackageModalOptions, CreditPoolDetail, CreditPoolType$1 as CreditPoolType, CreditTransaction, CurrentSubscription, DropinCallbacks, DropinPaymentModalOptions, DropinPaymentOptions, Environment, EnvironmentConfig, GenericPackage, GenericPackageModalOptions, LinkPaymentOptions, ListTransactionsRequest, LoaderConfig, OrderInfo, OrderStatus, OrderStatusResponse, PaymentCheckoutModalOptions, PaymentClientOptions, PaymentEnvironment, PaymentFailedModalOptions, PaymentMethod, PaymentMethodsParams, PaymentModalOptions, PaymentReadyEventDetail, PaymentResult, PaymentSDKConfig, PaymentSuccessEventDetail, PaymentUnsuccessEventDetail, PaymentUnsuccessResult, PaymentVerificationOptions, Product, PurchaseSuccessData, PurchaseSuccessModalOptions, PurchaseType, RetentionModalOptions, SDKCheckoutRequest, SDKCheckoutResponse, SDKConfig, SDKLoadStatus, ScriptLoaderOptions, SeaArtPaymentElement, SeaartBindCardPayment, SeaartDropinPayment, SeaartLinkPayment, SeaartPaymentComponentSDK, SeaartPaymentInstance, SeaartPaymentSDKConfig, ShowPaymentOptions, SubscribeOptions, SubscriptionParams, SubscriptionPeriod, TransactionListResponse, TransactionStatus, TransactionStorageData, TransactionType };
3147
+ export type { ActiveSubscription, ApiErrorResponse, ApiResponse, ApiSuccessResponse, AutoCreateOrderConfig, AvailablePackagesResponse, BaseCheckoutOptions, BillingPeriod$1 as BillingPeriod, BindCard, BindCardCallbacks, BindCardPaymentOptions, CheckoutAPIConfig, CheckoutAPIResponse, CheckoutClientConfig, CheckoutClientStatus, CheckoutOptions, CheckoutPaymentError, CheckoutPaymentErrorCode, CheckoutResult, ComponentLoadStatus, CreateOrderResponse, CreditAccount, CreditAccountStatus, CreditDetailResponse$1 as CreditDetailResponse, CreditDetailSuccessResponse, CreditPackCardOptions, CreditPackageModalOptions, CreditPoolDetail, CreditPoolType$1 as CreditPoolType, CreditTransaction, CurrentSubscription, DropinCallbacks, DropinPaymentModalOptions, DropinPaymentOptions, Environment, EnvironmentConfig, GenericPackage, GenericPackageModalOptions, LinkPaymentOptions, ListTransactionsRequest, LoaderConfig, LocaleCode, OrderInfo, OrderStatus, OrderStatusResponse, PaymentCheckoutModalOptions, PaymentClientOptions, PaymentEnvironment, PaymentFailedModalOptions, PaymentMethod, PaymentMethodsParams, PaymentModalOptions, PaymentReadyEventDetail, PaymentResult, PaymentSDKConfig, PaymentSuccessEventDetail, PaymentUnsuccessEventDetail, PaymentUnsuccessResult, PaymentVerificationOptions, Product, PurchaseSuccessData, PurchaseSuccessModalOptions, PurchaseType, RetentionModalOptions, SDKCheckoutRequest, SDKCheckoutResponse, SDKConfig, SDKLoadStatus, ScriptLoaderOptions, SeaArtPaymentElement, SeaartBindCardPayment, SeaartDropinPayment, SeaartLinkPayment, SeaartPaymentComponentSDK, SeaartPaymentInstance, SeaartPaymentSDKConfig, ShowPaymentOptions, SubscribeOptions, SubscriptionParams, SubscriptionPeriod, TransactionListResponse, TransactionStatus, TransactionStorageData, TransactionType };