@seaverse/payment-sdk 0.8.2 → 0.9.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 +597 -695
- package/dist/index.browser.js +4628 -767
- package/dist/index.browser.js.map +1 -1
- package/dist/index.cjs +4632 -768
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +796 -223
- package/dist/index.js +4628 -767
- package/dist/index.js.map +1 -1
- package/package.json +10 -9
package/dist/index.d.ts
CHANGED
|
@@ -401,7 +401,7 @@ type SubscriptionPeriod = 'week' | 'month' | 'year' | 'WEEK' | 'MONTH' | 'YEAR';
|
|
|
401
401
|
/**
|
|
402
402
|
* 计费周期
|
|
403
403
|
*/
|
|
404
|
-
type BillingPeriod = 'month' | 'year';
|
|
404
|
+
type BillingPeriod$1 = 'month' | 'year';
|
|
405
405
|
/**
|
|
406
406
|
* 订阅参数
|
|
407
407
|
*/
|
|
@@ -444,7 +444,7 @@ interface CheckoutOptions extends BaseCheckoutOptions {
|
|
|
444
444
|
*/
|
|
445
445
|
interface SubscribeOptions extends CheckoutOptions {
|
|
446
446
|
/** 计费周期(可选,"month" 或 "year",默认 "month") */
|
|
447
|
-
billing_period?: BillingPeriod;
|
|
447
|
+
billing_period?: BillingPeriod$1;
|
|
448
448
|
/** 购买类型:1-一次性,2-订阅(必填) */
|
|
449
449
|
purchaseType: PurchaseType;
|
|
450
450
|
}
|
|
@@ -476,7 +476,7 @@ interface SDKCheckoutRequest {
|
|
|
476
476
|
/** 购买类型:1-一次性,2-订阅(必填) */
|
|
477
477
|
purchase_type: PurchaseType;
|
|
478
478
|
/** 计费周期(可选,仅订阅时使用,默认 'month')- 用于区分月付和年付 */
|
|
479
|
-
billing_period?: BillingPeriod;
|
|
479
|
+
billing_period?: BillingPeriod$1;
|
|
480
480
|
/** 支付完成后的重定向 URL(可选) */
|
|
481
481
|
redirect_url?: string;
|
|
482
482
|
}
|
|
@@ -768,7 +768,7 @@ declare class CheckoutAPI {
|
|
|
768
768
|
*/
|
|
769
769
|
createSubscriptionCheckout(params: {
|
|
770
770
|
productId: string;
|
|
771
|
-
billingPeriod?: BillingPeriod;
|
|
771
|
+
billingPeriod?: BillingPeriod$1;
|
|
772
772
|
/** 支付完成后的重定向 URL */
|
|
773
773
|
redirectUrl?: string;
|
|
774
774
|
}): Promise<CheckoutResult>;
|
|
@@ -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?:
|
|
1276
|
+
language?: LocaleCode;
|
|
1191
1277
|
/** 脚本加载超时(毫秒) */
|
|
1192
1278
|
scriptTimeout?: number;
|
|
1193
1279
|
/** CSS 样式表 URL(可选) */
|
|
@@ -1346,6 +1432,18 @@ interface GenericPackage extends BasePackage {
|
|
|
1346
1432
|
/** Package type for categorization */
|
|
1347
1433
|
package_type?: 'iceBreaker' | 'emergency' | 'firstCharge' | 'custom';
|
|
1348
1434
|
}
|
|
1435
|
+
interface CreditPackageItem extends BasePackage {
|
|
1436
|
+
/** 总积分(与 credits 相同,API 返回字段) */
|
|
1437
|
+
total_credits: string;
|
|
1438
|
+
/** 基础积分 */
|
|
1439
|
+
base_credits: string;
|
|
1440
|
+
/** 奖励积分 */
|
|
1441
|
+
bonus_credits: string;
|
|
1442
|
+
/** 每日购买限制 */
|
|
1443
|
+
remain_daily_limit: number;
|
|
1444
|
+
/** 是否为首次购买积分包 */
|
|
1445
|
+
is_first_purchase_pkg: boolean;
|
|
1446
|
+
}
|
|
1349
1447
|
|
|
1350
1448
|
/**
|
|
1351
1449
|
* LinkPaymentComponent
|
|
@@ -1553,19 +1651,21 @@ declare class PaymentModal {
|
|
|
1553
1651
|
|
|
1554
1652
|
/**
|
|
1555
1653
|
* RetentionModal - 支付挽留弹框
|
|
1556
|
-
*
|
|
1557
|
-
*
|
|
1654
|
+
* 当用户尝试取消支付时弹出,提供订单信息以挽留用户
|
|
1655
|
+
*
|
|
1656
|
+
* 设计风格:深色卡片 + 清晰信息层次 + 渐变 CTA 按钮
|
|
1558
1657
|
*/
|
|
1658
|
+
|
|
1559
1659
|
interface RetentionModalOptions {
|
|
1560
1660
|
/** 语言,默认 'en' */
|
|
1561
|
-
language?:
|
|
1661
|
+
language?: LocaleCode;
|
|
1562
1662
|
/** 商品名称 */
|
|
1563
1663
|
productName: string;
|
|
1564
1664
|
/** 购买数量(积分数等) */
|
|
1565
1665
|
purchaseAmount: number;
|
|
1566
1666
|
/** 活动赠送(例如:990) */
|
|
1567
1667
|
bonusAmount?: number;
|
|
1568
|
-
/** 优惠价格(例如:"
|
|
1668
|
+
/** 优惠价格(例如:"$4.99") */
|
|
1569
1669
|
discountPrice: string;
|
|
1570
1670
|
/** 确认继续支付回调 */
|
|
1571
1671
|
onContinue: () => void;
|
|
@@ -1600,41 +1700,25 @@ declare class RetentionModal {
|
|
|
1600
1700
|
*/
|
|
1601
1701
|
private createModal;
|
|
1602
1702
|
/**
|
|
1603
|
-
*
|
|
1703
|
+
* 注入 CSS 动画和 hover 效果
|
|
1604
1704
|
*/
|
|
1605
1705
|
private addStyles;
|
|
1606
1706
|
/**
|
|
1607
|
-
*
|
|
1707
|
+
* 事件监听
|
|
1608
1708
|
*/
|
|
1609
1709
|
private attachEventListeners;
|
|
1610
|
-
/**
|
|
1611
|
-
* 处理 ESC 键
|
|
1612
|
-
*/
|
|
1613
1710
|
private handleEscKey;
|
|
1614
1711
|
/**
|
|
1615
|
-
*
|
|
1712
|
+
* 倒计时
|
|
1616
1713
|
*/
|
|
1617
1714
|
private startCountdown;
|
|
1618
|
-
/**
|
|
1619
|
-
* 停止倒计时
|
|
1620
|
-
*/
|
|
1621
1715
|
private stopCountdown;
|
|
1622
|
-
/**
|
|
1623
|
-
* 更新倒计时显示
|
|
1624
|
-
*/
|
|
1625
1716
|
private updateCountdownDisplay;
|
|
1626
1717
|
/**
|
|
1627
1718
|
* 清理资源
|
|
1628
1719
|
*/
|
|
1629
1720
|
private cleanup;
|
|
1630
|
-
/**
|
|
1631
|
-
* HTML 转义工具函数
|
|
1632
|
-
* 防止 XSS 攻击
|
|
1633
|
-
*/
|
|
1634
1721
|
private escapeHtml;
|
|
1635
|
-
/**
|
|
1636
|
-
* 检查弹框是否打开
|
|
1637
|
-
*/
|
|
1638
1722
|
isOpen(): boolean;
|
|
1639
1723
|
}
|
|
1640
1724
|
|
|
@@ -1770,102 +1854,6 @@ declare class SeaartPaymentSDK {
|
|
|
1770
1854
|
destroy(): void;
|
|
1771
1855
|
}
|
|
1772
1856
|
|
|
1773
|
-
/**
|
|
1774
|
-
* 积分套餐数据
|
|
1775
|
-
*/
|
|
1776
|
-
|
|
1777
|
-
interface CreditPackage extends BasePackage {
|
|
1778
|
-
day_limit: number;
|
|
1779
|
-
is_popular?: boolean;
|
|
1780
|
-
}
|
|
1781
|
-
declare const CREDIT_PACKAGES: CreditPackage[];
|
|
1782
|
-
/**
|
|
1783
|
-
* 创作力量类型和对应的积分消耗
|
|
1784
|
-
*/
|
|
1785
|
-
interface CreativePowerType {
|
|
1786
|
-
icon: string;
|
|
1787
|
-
name: string;
|
|
1788
|
-
name_cn: string;
|
|
1789
|
-
credits_range: string;
|
|
1790
|
-
description: string;
|
|
1791
|
-
description_cn: string;
|
|
1792
|
-
}
|
|
1793
|
-
declare const CREATIVE_POWER_TYPES: CreativePowerType[];
|
|
1794
|
-
|
|
1795
|
-
/**
|
|
1796
|
-
* 共享类型定义
|
|
1797
|
-
* Shared types for CreditPackageModal and GenericPackageModal
|
|
1798
|
-
*/
|
|
1799
|
-
|
|
1800
|
-
/** 环境类型 */
|
|
1801
|
-
type Environment = 'development' | 'production';
|
|
1802
|
-
/** 环境配置接口 */
|
|
1803
|
-
interface EnvironmentConfig {
|
|
1804
|
-
/** SDK 脚本 URL */
|
|
1805
|
-
scriptUrl: string;
|
|
1806
|
-
/** 客户端 ID */
|
|
1807
|
-
clientId: string;
|
|
1808
|
-
/** 订单 API 地址 */
|
|
1809
|
-
orderApiUrl: string;
|
|
1810
|
-
/** 钱包 API 地址 */
|
|
1811
|
-
walletApiUrl: string;
|
|
1812
|
-
/** CSS 文件 URL */
|
|
1813
|
-
cssUrl: string;
|
|
1814
|
-
}
|
|
1815
|
-
/**
|
|
1816
|
-
* SDK 配置选项 - 简化版(支持环境变量)
|
|
1817
|
-
* 用户只需提供 environment、countryCode、accountToken 三个核心参数
|
|
1818
|
-
* SDK 会自动根据 environment 选择对应的配置
|
|
1819
|
-
*/
|
|
1820
|
-
interface PaymentSDKConfig {
|
|
1821
|
-
/** 环境变量(development/production) - SDK 自动选择对应配置 */
|
|
1822
|
-
environment: Environment;
|
|
1823
|
-
/** 国家/地区代码 */
|
|
1824
|
-
countryCode: string;
|
|
1825
|
-
/** 账户 Token(用于用户认证) */
|
|
1826
|
-
accountToken?: string;
|
|
1827
|
-
/** 业务类型:1-一次性,2-订阅(可选,默认为 1) */
|
|
1828
|
-
businessType?: 1 | 2;
|
|
1829
|
-
/** 脚本加载超时(毫秒,默认 10000ms) */
|
|
1830
|
-
scriptTimeout?: number;
|
|
1831
|
-
/** 支付方式类型过滤(可选,默认 'dropin') */
|
|
1832
|
-
paymentMethodType?: string;
|
|
1833
|
-
/** 自定义脚本 URL(覆盖环境配置) */
|
|
1834
|
-
scriptUrl?: string;
|
|
1835
|
-
/** 自定义客户端 ID(覆盖环境配置) */
|
|
1836
|
-
clientId?: string;
|
|
1837
|
-
/** 自定义订单 API 地址(覆盖环境配置) */
|
|
1838
|
-
orderApiUrl?: string;
|
|
1839
|
-
/** 自定义 CSS URL(覆盖环境配置) */
|
|
1840
|
-
cssUrl?: string;
|
|
1841
|
-
}
|
|
1842
|
-
/**
|
|
1843
|
-
* Base package modal options - common configuration for all package modals
|
|
1844
|
-
*/
|
|
1845
|
-
interface BasePackageModalOptions<TPackage extends BasePackage> {
|
|
1846
|
-
/** SDK configuration (required for automatic SDK initialization) */
|
|
1847
|
-
sdkConfig: PaymentSDKConfig;
|
|
1848
|
-
/** Language (default 'en') */
|
|
1849
|
-
language?: 'en' | 'zh-CN';
|
|
1850
|
-
/**
|
|
1851
|
-
* Payment success callback - notifies when payment is completed
|
|
1852
|
-
* @param orderId Order ID
|
|
1853
|
-
* @param transactionId Transaction ID
|
|
1854
|
-
* @param pkg Purchased package
|
|
1855
|
-
*/
|
|
1856
|
-
onPaymentSuccess?: (orderId: string, transactionId: string, pkg: TPackage) => void;
|
|
1857
|
-
/**
|
|
1858
|
-
* Payment failed callback
|
|
1859
|
-
* @param error Error information
|
|
1860
|
-
* @param pkg Package that failed to purchase
|
|
1861
|
-
*/
|
|
1862
|
-
onPaymentFailed?: (error: Error, pkg: TPackage) => void;
|
|
1863
|
-
/** Modal close callback */
|
|
1864
|
-
onClose?: () => void;
|
|
1865
|
-
paymentMethod?: PaymentMethod;
|
|
1866
|
-
accountToken?: string;
|
|
1867
|
-
}
|
|
1868
|
-
|
|
1869
1857
|
/**
|
|
1870
1858
|
* BasePackageModal - Abstract base class for package modals
|
|
1871
1859
|
* Provides shared logic for SDK initialization, payment flow, and event handling
|
|
@@ -1878,7 +1866,7 @@ interface BasePackageModalOptions<TPackage extends BasePackage> {
|
|
|
1878
1866
|
declare abstract class BasePackageModal<TPackage extends BasePackage, TOptions extends BasePackageModalOptions<TPackage>> {
|
|
1879
1867
|
protected modal: PaymentModal;
|
|
1880
1868
|
protected options: TOptions;
|
|
1881
|
-
protected language:
|
|
1869
|
+
protected language: LocaleCode;
|
|
1882
1870
|
protected resizeHandler: (() => void) | null;
|
|
1883
1871
|
protected isInitializingSDK: boolean;
|
|
1884
1872
|
protected sdkInitialized: boolean;
|
|
@@ -1970,31 +1958,67 @@ declare abstract class BasePackageModal<TPackage extends BasePackage, TOptions e
|
|
|
1970
1958
|
* 展示不同的积分套餐供用户选择
|
|
1971
1959
|
*/
|
|
1972
1960
|
|
|
1973
|
-
interface CreditPackageModalOptions extends BasePackageModalOptions<
|
|
1961
|
+
interface CreditPackageModalOptions extends BasePackageModalOptions<CreditPackageItem> {
|
|
1974
1962
|
/** Modal title */
|
|
1975
1963
|
title?: string;
|
|
1976
1964
|
/** Modal title (Chinese) */
|
|
1977
1965
|
title_cn?: string;
|
|
1978
|
-
/** Subtitle */
|
|
1979
|
-
subtitle?: string;
|
|
1980
|
-
/** Subtitle (Chinese) */
|
|
1981
|
-
subtitle_cn?: string;
|
|
1982
1966
|
}
|
|
1983
|
-
declare class CreditPackageModal extends BasePackageModal<
|
|
1967
|
+
declare class CreditPackageModal extends BasePackageModal<CreditPackageItem, CreditPackageModalOptions> {
|
|
1984
1968
|
private readonly SPACING;
|
|
1985
1969
|
private readonly COLORS;
|
|
1970
|
+
private dynamicPackages;
|
|
1971
|
+
private isFetchingPackages;
|
|
1972
|
+
/**
|
|
1973
|
+
* Override open to fetch packages before rendering
|
|
1974
|
+
*/
|
|
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>;
|
|
1986
1987
|
/**
|
|
1987
1988
|
* Create and configure the PaymentModal instance
|
|
1988
1989
|
*/
|
|
1989
1990
|
protected createModal(): PaymentModal;
|
|
1990
1991
|
/**
|
|
1991
|
-
* Get packages to display
|
|
1992
|
+
* Get packages to display (dynamic or fallback to static)
|
|
1993
|
+
*/
|
|
1994
|
+
protected getPackages(): CreditPackageItem[];
|
|
1995
|
+
/**
|
|
1996
|
+
* Fetch available packages from API
|
|
1997
|
+
*/
|
|
1998
|
+
private fetchDynamicPackages;
|
|
1999
|
+
/**
|
|
2000
|
+
* Parse purchase limit string to day_limit number
|
|
2001
|
+
* Example: "Daily limit: 1" => 1
|
|
2002
|
+
*/
|
|
2003
|
+
private parsePurchaseLimit;
|
|
2004
|
+
/**
|
|
2005
|
+
* 覆盖 BasePackageModal 的 handlePaymentFlow 方法
|
|
2006
|
+
* 使用 PaymentCheckoutModal 替代旧的 DropinPaymentModal
|
|
2007
|
+
* 支付成功后刷新积分包列表,而不是立即关闭弹框
|
|
2008
|
+
*/
|
|
2009
|
+
protected handlePaymentFlow(pkg: CreditPackageItem, button: HTMLButtonElement, originalHTML: string): Promise<void>;
|
|
2010
|
+
/**
|
|
2011
|
+
* 将 CreditPackageItem 转换为 Product
|
|
2012
|
+
*/
|
|
2013
|
+
private convertToProduct;
|
|
2014
|
+
/**
|
|
2015
|
+
* 构建 AutoCreateOrderConfig
|
|
1992
2016
|
*/
|
|
1993
|
-
|
|
2017
|
+
private buildAutoCreateOrderConfig;
|
|
1994
2018
|
/**
|
|
1995
2019
|
* Get package display name for payment modal title
|
|
1996
2020
|
*/
|
|
1997
|
-
protected getPackageDisplayName(pkg:
|
|
2021
|
+
protected getPackageDisplayName(pkg: CreditPackageItem): string;
|
|
1998
2022
|
/**
|
|
1999
2023
|
* Get loading button HTML with spinner
|
|
2000
2024
|
*/
|
|
@@ -2012,11 +2036,7 @@ declare class CreditPackageModal extends BasePackageModal<CreditPackage, CreditP
|
|
|
2012
2036
|
*/
|
|
2013
2037
|
private getResponsiveStyles;
|
|
2014
2038
|
/**
|
|
2015
|
-
* Render
|
|
2016
|
-
*/
|
|
2017
|
-
private renderComputeCreditsCards;
|
|
2018
|
-
/**
|
|
2019
|
-
* Render package card
|
|
2039
|
+
* Render package card using CreditPackCard component
|
|
2020
2040
|
*/
|
|
2021
2041
|
private renderPackageCard;
|
|
2022
2042
|
}
|
|
@@ -2033,6 +2053,17 @@ interface GenericPackageModalOptions extends BasePackageModalOptions<GenericPack
|
|
|
2033
2053
|
}
|
|
2034
2054
|
declare class GenericPackageModal extends BasePackageModal<GenericPackage, GenericPackageModalOptions> {
|
|
2035
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>;
|
|
2036
2067
|
/**
|
|
2037
2068
|
* Create and configure the PaymentModal instance
|
|
2038
2069
|
*/
|
|
@@ -2057,6 +2088,19 @@ declare class GenericPackageModal extends BasePackageModal<GenericPackage, Gener
|
|
|
2057
2088
|
* Render modal content
|
|
2058
2089
|
*/
|
|
2059
2090
|
protected renderContent(): void;
|
|
2091
|
+
/**
|
|
2092
|
+
* 覆盖 BasePackageModal 的 handlePaymentFlow 方法
|
|
2093
|
+
* 使用 PaymentCheckoutModal 替代 DropinPaymentModal
|
|
2094
|
+
*/
|
|
2095
|
+
protected handlePaymentFlow(pkg: GenericPackage, button: HTMLButtonElement, originalHTML: string): Promise<void>;
|
|
2096
|
+
/**
|
|
2097
|
+
* 将 GenericPackage 转换为 Product
|
|
2098
|
+
*/
|
|
2099
|
+
private convertToProduct;
|
|
2100
|
+
/**
|
|
2101
|
+
* 构建 AutoCreateOrderConfig
|
|
2102
|
+
*/
|
|
2103
|
+
private buildAutoCreateOrderConfig;
|
|
2060
2104
|
/**
|
|
2061
2105
|
* Render package card
|
|
2062
2106
|
*/
|
|
@@ -2064,42 +2108,341 @@ declare class GenericPackageModal extends BasePackageModal<GenericPackage, Gener
|
|
|
2064
2108
|
}
|
|
2065
2109
|
|
|
2066
2110
|
/**
|
|
2067
|
-
*
|
|
2068
|
-
* Shared configuration for CreditPackageModal and GenericPackageModal
|
|
2111
|
+
* 商品类型
|
|
2069
2112
|
*/
|
|
2070
|
-
|
|
2113
|
+
declare enum PRODUCT_TYPE$1 {
|
|
2114
|
+
SUBSCRIPTION = "subscription",
|
|
2115
|
+
CREDITPACK = "credit_package"
|
|
2116
|
+
}
|
|
2071
2117
|
/**
|
|
2072
|
-
*
|
|
2073
|
-
* SDK 根据 environment 参数自动选择对应的配置
|
|
2118
|
+
* 订单状态
|
|
2074
2119
|
*/
|
|
2075
|
-
|
|
2120
|
+
type OrderStatus = 'pending' | 'paid' | 'failed' | 'expired' | 'refunded';
|
|
2076
2121
|
/**
|
|
2077
|
-
*
|
|
2078
|
-
* Responsive breakpoints for grid layout
|
|
2122
|
+
* 商品数据
|
|
2079
2123
|
*/
|
|
2080
|
-
|
|
2081
|
-
|
|
2082
|
-
|
|
2083
|
-
|
|
2084
|
-
|
|
2085
|
-
|
|
2124
|
+
interface ProductData {
|
|
2125
|
+
/** 商品ID */
|
|
2126
|
+
product_id: string;
|
|
2127
|
+
/** 商品名称 */
|
|
2128
|
+
product_name: string;
|
|
2129
|
+
/** 商品类型 */
|
|
2130
|
+
product_type: PRODUCT_TYPE$1;
|
|
2131
|
+
/** 商品价格 */
|
|
2132
|
+
price: number;
|
|
2133
|
+
/** 商品货币 */
|
|
2134
|
+
currency: string;
|
|
2135
|
+
/** 订阅周期 */
|
|
2136
|
+
subscription_period?: 'month' | 'year';
|
|
2137
|
+
/** 积分 */
|
|
2138
|
+
total_credits?: number;
|
|
2139
|
+
}
|
|
2086
2140
|
/**
|
|
2087
|
-
*
|
|
2088
|
-
* Grid columns for different screen sizes
|
|
2141
|
+
* SDK 配置
|
|
2089
2142
|
*/
|
|
2090
|
-
|
|
2091
|
-
|
|
2092
|
-
|
|
2093
|
-
|
|
2094
|
-
|
|
2095
|
-
|
|
2143
|
+
interface SdkConfig {
|
|
2144
|
+
/** 应用 ID */
|
|
2145
|
+
app_id: string;
|
|
2146
|
+
/** API 域名 */
|
|
2147
|
+
api_host: string;
|
|
2148
|
+
/** 环境 */
|
|
2149
|
+
environment: string;
|
|
2150
|
+
}
|
|
2096
2151
|
/**
|
|
2097
|
-
*
|
|
2152
|
+
* 订阅计费周期
|
|
2098
2153
|
*/
|
|
2099
|
-
|
|
2100
|
-
|
|
2101
|
-
|
|
2102
|
-
|
|
2154
|
+
type BillingPeriod = 'month' | 'year';
|
|
2155
|
+
/**
|
|
2156
|
+
* 积分池类型
|
|
2157
|
+
*/
|
|
2158
|
+
type CreditPoolType = 'daily' | 'event' | 'monthly' | 'permanent';
|
|
2159
|
+
|
|
2160
|
+
/**
|
|
2161
|
+
* Order API
|
|
2162
|
+
* 订单管理 - 查询和轮询订单状态
|
|
2163
|
+
*/
|
|
2164
|
+
|
|
2165
|
+
/**
|
|
2166
|
+
* 订单状态响应
|
|
2167
|
+
*/
|
|
2168
|
+
interface OrderStatusResponse {
|
|
2169
|
+
status: OrderStatus;
|
|
2170
|
+
product: ProductData;
|
|
2171
|
+
}
|
|
2172
|
+
|
|
2173
|
+
/**
|
|
2174
|
+
* 查询订单状态
|
|
2175
|
+
* @param transactionId SDK checkout 返回的 transaction_id
|
|
2176
|
+
* @param apiHost Payment API 地址
|
|
2177
|
+
* @param authToken 认证 Token
|
|
2178
|
+
* @returns 订单状态
|
|
2179
|
+
*/
|
|
2180
|
+
declare function checkOrderStatus(transactionId: string, apiHost: string, authToken?: string): Promise<OrderStatusResponse>;
|
|
2181
|
+
/**
|
|
2182
|
+
* 轮询订单状态直到支付完成或超时
|
|
2183
|
+
* @param transactionId SDK checkout 返回的 transaction_id
|
|
2184
|
+
* @param apiHost Payment API 地址
|
|
2185
|
+
* @param authToken 认证 Token
|
|
2186
|
+
* @param options 轮询配置
|
|
2187
|
+
* @returns 最终订单状态
|
|
2188
|
+
*/
|
|
2189
|
+
declare function pollOrderStatus(transactionId: string, apiHost: string, authToken: string | undefined, options?: {
|
|
2190
|
+
/** 轮询间隔(毫秒),默认 2000ms */
|
|
2191
|
+
interval?: number;
|
|
2192
|
+
/** 最大轮询次数,默认 30 次(总计 60 秒) */
|
|
2193
|
+
maxAttempts?: number;
|
|
2194
|
+
/** 每次轮询后的回调 */
|
|
2195
|
+
onPoll?: (status: OrderStatus, attempt: number) => void;
|
|
2196
|
+
}): Promise<OrderStatusResponse>;
|
|
2197
|
+
|
|
2198
|
+
/**
|
|
2199
|
+
* @filename types.ts
|
|
2200
|
+
* @description PaymentCheckoutModal 的 TypeScript 类型定义
|
|
2201
|
+
*/
|
|
2202
|
+
|
|
2203
|
+
/**
|
|
2204
|
+
* 产品类型
|
|
2205
|
+
*/
|
|
2206
|
+
declare const PRODUCT_TYPE: {
|
|
2207
|
+
readonly SUBSCRIPTION: "subscription";
|
|
2208
|
+
readonly CREDITPACK: "credit_package";
|
|
2209
|
+
readonly CHANGE_SUBSCRIPTION: "change_subscription";
|
|
2210
|
+
};
|
|
2211
|
+
/**
|
|
2212
|
+
* 产品类型的类型定义
|
|
2213
|
+
*/
|
|
2214
|
+
type ProductType = (typeof PRODUCT_TYPE)[keyof typeof PRODUCT_TYPE];
|
|
2215
|
+
/**
|
|
2216
|
+
* 商品信息
|
|
2217
|
+
*/
|
|
2218
|
+
interface Product {
|
|
2219
|
+
id: string;
|
|
2220
|
+
name: string;
|
|
2221
|
+
price: number;
|
|
2222
|
+
currency: string;
|
|
2223
|
+
type: ProductType;
|
|
2224
|
+
}
|
|
2225
|
+
/**
|
|
2226
|
+
* 自动创建订单配置
|
|
2227
|
+
*/
|
|
2228
|
+
interface AutoCreateOrderConfig {
|
|
2229
|
+
/** 产品ID */
|
|
2230
|
+
productId: string;
|
|
2231
|
+
/** 购买类型:1-一次性购买,2-订阅 */
|
|
2232
|
+
purchaseType: 1 | 2;
|
|
2233
|
+
/** API 主机地址 */
|
|
2234
|
+
apiHost: string;
|
|
2235
|
+
/** 账户 Token */
|
|
2236
|
+
accountToken: string;
|
|
2237
|
+
/** 客户端 ID */
|
|
2238
|
+
clientId: string;
|
|
2239
|
+
/** 国家代码 */
|
|
2240
|
+
language_code: LocaleCode;
|
|
2241
|
+
}
|
|
2242
|
+
/**
|
|
2243
|
+
* PaymentCheckoutModal 配置选项
|
|
2244
|
+
*/
|
|
2245
|
+
interface PaymentCheckoutModalOptions {
|
|
2246
|
+
/** 当前选择的商品 */
|
|
2247
|
+
product?: Product | null;
|
|
2248
|
+
/** 自动创建订单配置(优先级最高) */
|
|
2249
|
+
autoCreateOrder?: AutoCreateOrderConfig;
|
|
2250
|
+
/** OrderPayment 实例(提前创建时使用) */
|
|
2251
|
+
payment?: OrderPayment;
|
|
2252
|
+
/** 订单 transaction_id(延迟创建支付实例时使用) */
|
|
2253
|
+
transactionId?: string;
|
|
2254
|
+
/** 支付方式列表(当不使用 autoCreateOrder 时需要提供) */
|
|
2255
|
+
paymentMethods?: PaymentMethod[];
|
|
2256
|
+
/** 是否正在加载支付方式 */
|
|
2257
|
+
loadingMethods?: boolean;
|
|
2258
|
+
/** 当前业务类型:1-一次性购买,2-订阅 */
|
|
2259
|
+
currentBusinessType?: 1 | 2 | null;
|
|
2260
|
+
/** 支付成功回调 */
|
|
2261
|
+
onPaymentSuccess?: (payload: OrderStatusResponse) => void;
|
|
2262
|
+
/** 支付失败回调 */
|
|
2263
|
+
onPaymentFailed?: (error: {
|
|
2264
|
+
message: string;
|
|
2265
|
+
}) => void;
|
|
2266
|
+
/** 选择支付方式回调 */
|
|
2267
|
+
onPaymentMethodSelect?: (method: PaymentMethod) => void;
|
|
2268
|
+
/** Link 支付开始回调(用于显示验证弹窗) */
|
|
2269
|
+
onLinkPaymentStart?: (paymentMethodName: string) => void;
|
|
2270
|
+
/** 加载回调 */
|
|
2271
|
+
onLoading?: (loading: boolean) => void;
|
|
2272
|
+
/** 弹框标题 */
|
|
2273
|
+
modalTitle?: string;
|
|
2274
|
+
/** 弹框选项 */
|
|
2275
|
+
modalOptions?: Omit<PaymentModalOptions, 'title'>;
|
|
2276
|
+
/** 是否显示返回按钮 */
|
|
2277
|
+
showBackButton?: boolean;
|
|
2278
|
+
/** 返回按钮文本 */
|
|
2279
|
+
backButtonText?: string;
|
|
2280
|
+
/** 用户账号名称 */
|
|
2281
|
+
accountName?: string;
|
|
2282
|
+
/** 语言设置 */
|
|
2283
|
+
language?: LocaleCode;
|
|
2284
|
+
}
|
|
2285
|
+
|
|
2286
|
+
/**
|
|
2287
|
+
* PaymentCheckoutModal - 通用支付收银台弹框
|
|
2288
|
+
* 支持 Link、Dropin 和 BindCard 三种支付方式
|
|
2289
|
+
* 纯 JavaScript 实现,不依赖任何框架
|
|
2290
|
+
*/
|
|
2291
|
+
|
|
2292
|
+
declare class PaymentCheckoutModal {
|
|
2293
|
+
private options;
|
|
2294
|
+
private modal;
|
|
2295
|
+
private orderPayment;
|
|
2296
|
+
private containerElement;
|
|
2297
|
+
private retentionModal;
|
|
2298
|
+
private bindCardPayment;
|
|
2299
|
+
private verificationModal;
|
|
2300
|
+
private isCleanedUp;
|
|
2301
|
+
private orderService;
|
|
2302
|
+
private loadingManager;
|
|
2303
|
+
private stateManager;
|
|
2304
|
+
private strategyFactory;
|
|
2305
|
+
private uiRenderer;
|
|
2306
|
+
constructor(options: PaymentCheckoutModalOptions);
|
|
2307
|
+
/**
|
|
2308
|
+
* 获取当前语言的文本
|
|
2309
|
+
*/
|
|
2310
|
+
private getText;
|
|
2311
|
+
/**
|
|
2312
|
+
* 打开弹框
|
|
2313
|
+
*/
|
|
2314
|
+
open(): Promise<void>;
|
|
2315
|
+
/**
|
|
2316
|
+
* 显示加载指示器(使用 LoadingManager)
|
|
2317
|
+
*/
|
|
2318
|
+
private showLoading;
|
|
2319
|
+
/**
|
|
2320
|
+
* 隐藏加载指示器(使用 LoadingManager)
|
|
2321
|
+
*/
|
|
2322
|
+
private hideLoading;
|
|
2323
|
+
/**
|
|
2324
|
+
* 自动创建订单(使用 OrderService)
|
|
2325
|
+
*/
|
|
2326
|
+
private handleAutoCreateOrder;
|
|
2327
|
+
/**
|
|
2328
|
+
* 检查 SDK 是否已初始化
|
|
2329
|
+
*/
|
|
2330
|
+
private checkSDKInitialized;
|
|
2331
|
+
/**
|
|
2332
|
+
* 开始轮询订单状态(使用 OrderService)
|
|
2333
|
+
*/
|
|
2334
|
+
private startOrderPolling;
|
|
2335
|
+
/**
|
|
2336
|
+
* 停止轮询订单状态(使用 OrderService)
|
|
2337
|
+
*/
|
|
2338
|
+
private stopOrderPolling;
|
|
2339
|
+
/**
|
|
2340
|
+
* 检查订单状态(使用 OrderService)
|
|
2341
|
+
* 点击"我已完成支付"按钮后,开始轮询订单状态(最多 10 次)
|
|
2342
|
+
*/
|
|
2343
|
+
private checkOrderStatus;
|
|
2344
|
+
/**
|
|
2345
|
+
* 显示支付失败弹窗
|
|
2346
|
+
*/
|
|
2347
|
+
private showPaymentFailedModal;
|
|
2348
|
+
/**
|
|
2349
|
+
* 显示支付验证弹窗(仅用于 Link 支付)
|
|
2350
|
+
*/
|
|
2351
|
+
private showVerificationModal;
|
|
2352
|
+
/**
|
|
2353
|
+
* 处理支付成功
|
|
2354
|
+
*/
|
|
2355
|
+
private handlePaymentSuccess;
|
|
2356
|
+
/**
|
|
2357
|
+
* 从 transactionId 创建 OrderPayment
|
|
2358
|
+
*/
|
|
2359
|
+
private createOrderPaymentFromTransactionId;
|
|
2360
|
+
/**
|
|
2361
|
+
* 渲染支付方式列表
|
|
2362
|
+
*/
|
|
2363
|
+
private renderPaymentMethods;
|
|
2364
|
+
/**
|
|
2365
|
+
* 自动选中默认支付方式
|
|
2366
|
+
* 策略:
|
|
2367
|
+
* - 如果有 Dropin(payment_type === 2),自动选中并渲染表单
|
|
2368
|
+
* - 如果只有 Link(payment_type === 1),不自动选中,让用户手动选择
|
|
2369
|
+
*/
|
|
2370
|
+
private autoSelectDefaultPaymentMethod;
|
|
2371
|
+
/**
|
|
2372
|
+
* 处理支付方式选择
|
|
2373
|
+
*/
|
|
2374
|
+
private handleSelectPaymentMethod;
|
|
2375
|
+
/**
|
|
2376
|
+
* 执行支付策略
|
|
2377
|
+
*/
|
|
2378
|
+
private executePaymentStrategy;
|
|
2379
|
+
/**
|
|
2380
|
+
* 渲染卡片列表
|
|
2381
|
+
*/
|
|
2382
|
+
private renderCardList;
|
|
2383
|
+
/**
|
|
2384
|
+
* 渲染错误状态
|
|
2385
|
+
*/
|
|
2386
|
+
private renderError;
|
|
2387
|
+
/**
|
|
2388
|
+
* 显示挽留弹框
|
|
2389
|
+
*/
|
|
2390
|
+
private showRetentionModal;
|
|
2391
|
+
/**
|
|
2392
|
+
* 显示购买成功弹框
|
|
2393
|
+
*/
|
|
2394
|
+
private showPurchaseSuccessModal;
|
|
2395
|
+
/**
|
|
2396
|
+
* 关闭弹框
|
|
2397
|
+
*/
|
|
2398
|
+
close(): void;
|
|
2399
|
+
/**
|
|
2400
|
+
* 清理资源
|
|
2401
|
+
*/
|
|
2402
|
+
private cleanup;
|
|
2403
|
+
/**
|
|
2404
|
+
* 检查弹框是否打开
|
|
2405
|
+
*/
|
|
2406
|
+
isOpen(): boolean;
|
|
2407
|
+
}
|
|
2408
|
+
|
|
2409
|
+
/**
|
|
2410
|
+
* 共享配置文件
|
|
2411
|
+
* Shared configuration for CreditPackageModal and GenericPackageModal
|
|
2412
|
+
*/
|
|
2413
|
+
|
|
2414
|
+
/**
|
|
2415
|
+
* 环境配置映射表
|
|
2416
|
+
* SDK 根据 environment 参数自动选择对应的配置
|
|
2417
|
+
*/
|
|
2418
|
+
declare const ENVIRONMENT_CONFIGS: Record<Environment, EnvironmentConfig>;
|
|
2419
|
+
/**
|
|
2420
|
+
* 响应式断点配置
|
|
2421
|
+
* Responsive breakpoints for grid layout
|
|
2422
|
+
*/
|
|
2423
|
+
declare const RESPONSIVE_BREAKPOINTS: {
|
|
2424
|
+
readonly mobile: 768;
|
|
2425
|
+
readonly tablet: 1200;
|
|
2426
|
+
readonly laptop: 1400;
|
|
2427
|
+
readonly desktop: number;
|
|
2428
|
+
};
|
|
2429
|
+
/**
|
|
2430
|
+
* 网格列数配置
|
|
2431
|
+
* Grid columns for different screen sizes
|
|
2432
|
+
*/
|
|
2433
|
+
declare const GRID_COLUMNS: {
|
|
2434
|
+
readonly mobile: 1;
|
|
2435
|
+
readonly tablet: 2;
|
|
2436
|
+
readonly laptop: 2;
|
|
2437
|
+
readonly desktop: 4;
|
|
2438
|
+
};
|
|
2439
|
+
/**
|
|
2440
|
+
* SDK 初始化配置
|
|
2441
|
+
*/
|
|
2442
|
+
declare const SDK_CONFIG: {
|
|
2443
|
+
/** 默认脚本加载超时 (毫秒) */
|
|
2444
|
+
readonly DEFAULT_SCRIPT_TIMEOUT: 10000;
|
|
2445
|
+
/** 默认 SDK 初始化超时 (毫秒) */
|
|
2103
2446
|
readonly DEFAULT_INIT_TIMEOUT: 30000;
|
|
2104
2447
|
/** 默认最大重试次数 */
|
|
2105
2448
|
readonly DEFAULT_MAX_RETRIES: 1;
|
|
@@ -2156,6 +2499,7 @@ declare function showInfoMessage(message: string, duration?: number): void;
|
|
|
2156
2499
|
* - 精美的动画效果(淡入淡出、缩放)
|
|
2157
2500
|
* - 包含成功图标、套餐详情、积分数、支付金额
|
|
2158
2501
|
*/
|
|
2502
|
+
|
|
2159
2503
|
interface PurchaseSuccessData {
|
|
2160
2504
|
/** 套餐名称 */
|
|
2161
2505
|
packName: string;
|
|
@@ -2174,7 +2518,7 @@ interface PurchaseSuccessModalOptions {
|
|
|
2174
2518
|
/** 购买成功数据 */
|
|
2175
2519
|
data: PurchaseSuccessData;
|
|
2176
2520
|
/** 语言,默认 'en' */
|
|
2177
|
-
language?:
|
|
2521
|
+
language?: LocaleCode;
|
|
2178
2522
|
/** 关闭回调 */
|
|
2179
2523
|
onClose?: () => void;
|
|
2180
2524
|
}
|
|
@@ -2188,6 +2532,7 @@ declare class PurchaseSuccessModal {
|
|
|
2188
2532
|
private isExiting;
|
|
2189
2533
|
private scrollY;
|
|
2190
2534
|
private boundHandleEscKey;
|
|
2535
|
+
private boundPreventTouchMove;
|
|
2191
2536
|
constructor(options: PurchaseSuccessModalOptions);
|
|
2192
2537
|
/**
|
|
2193
2538
|
* 打开弹窗
|
|
@@ -2217,6 +2562,202 @@ declare class PurchaseSuccessModal {
|
|
|
2217
2562
|
* 处理 ESC 键
|
|
2218
2563
|
*/
|
|
2219
2564
|
private handleEscKey;
|
|
2565
|
+
/**
|
|
2566
|
+
* 阻止 body 的触摸滑动
|
|
2567
|
+
*/
|
|
2568
|
+
private preventTouchMove;
|
|
2569
|
+
/**
|
|
2570
|
+
* 清理资源
|
|
2571
|
+
*/
|
|
2572
|
+
private cleanup;
|
|
2573
|
+
/**
|
|
2574
|
+
* HTML 转义工具函数
|
|
2575
|
+
* 防止 XSS 攻击
|
|
2576
|
+
*/
|
|
2577
|
+
private escapeHtml;
|
|
2578
|
+
/**
|
|
2579
|
+
* 检查弹窗是否打开
|
|
2580
|
+
*/
|
|
2581
|
+
isOpen(): boolean;
|
|
2582
|
+
}
|
|
2583
|
+
|
|
2584
|
+
/**
|
|
2585
|
+
* PaymentVerificationModal - 支付验证状态弹窗
|
|
2586
|
+
* 纯 JavaScript 实现,不依赖 React
|
|
2587
|
+
*
|
|
2588
|
+
* 样式完全参考 next-meta 项目的设计
|
|
2589
|
+
* 按钮逻辑参考 @seaart/payment-component
|
|
2590
|
+
*/
|
|
2591
|
+
|
|
2592
|
+
interface PaymentVerificationOptions {
|
|
2593
|
+
/** 语言,默认 'en' */
|
|
2594
|
+
language?: LocaleCode;
|
|
2595
|
+
/** 交易ID */
|
|
2596
|
+
transactionId: string;
|
|
2597
|
+
/** 产品名称(可选) */
|
|
2598
|
+
productName?: string;
|
|
2599
|
+
/** 支付方式名称 */
|
|
2600
|
+
paymentMethodName?: string;
|
|
2601
|
+
/** 成功回调 */
|
|
2602
|
+
onSuccess?: (orderInfo: any) => void;
|
|
2603
|
+
/** 失败回调 */
|
|
2604
|
+
onFailed?: (error: {
|
|
2605
|
+
message: string;
|
|
2606
|
+
}) => void;
|
|
2607
|
+
/** 超时回调 */
|
|
2608
|
+
onTimeout?: () => void;
|
|
2609
|
+
/** Cancel 按钮回调 */
|
|
2610
|
+
onCancel?: () => void;
|
|
2611
|
+
/** Complete Payment 按钮回调 */
|
|
2612
|
+
onCompletePayment?: () => void;
|
|
2613
|
+
}
|
|
2614
|
+
/**
|
|
2615
|
+
* 支付验证弹窗类
|
|
2616
|
+
*/
|
|
2617
|
+
declare class PaymentVerificationModal {
|
|
2618
|
+
private overlay;
|
|
2619
|
+
private modal;
|
|
2620
|
+
private options;
|
|
2621
|
+
private isExiting;
|
|
2622
|
+
private scrollY;
|
|
2623
|
+
private boundHandleEscKey;
|
|
2624
|
+
private boundPreventTouchMove;
|
|
2625
|
+
constructor(options: PaymentVerificationOptions);
|
|
2626
|
+
/**
|
|
2627
|
+
* 打开弹窗
|
|
2628
|
+
*/
|
|
2629
|
+
open(): void;
|
|
2630
|
+
/**
|
|
2631
|
+
* 关闭弹窗
|
|
2632
|
+
*/
|
|
2633
|
+
close(): void;
|
|
2634
|
+
/**
|
|
2635
|
+
* 创建弹窗元素
|
|
2636
|
+
*/
|
|
2637
|
+
private createModal;
|
|
2638
|
+
/**
|
|
2639
|
+
* 生成弹窗 HTML
|
|
2640
|
+
*/
|
|
2641
|
+
private getModalHTML;
|
|
2642
|
+
/**
|
|
2643
|
+
* 获取语言文本
|
|
2644
|
+
*/
|
|
2645
|
+
private getTexts;
|
|
2646
|
+
/**
|
|
2647
|
+
* 添加 CSS 动画
|
|
2648
|
+
*/
|
|
2649
|
+
private addStyles;
|
|
2650
|
+
/**
|
|
2651
|
+
* 添加事件监听
|
|
2652
|
+
*/
|
|
2653
|
+
private attachEventListeners;
|
|
2654
|
+
/**
|
|
2655
|
+
* 处理 Cancel 按钮
|
|
2656
|
+
*/
|
|
2657
|
+
private handleCancel;
|
|
2658
|
+
/**
|
|
2659
|
+
* 处理 Complete Payment 按钮
|
|
2660
|
+
*/
|
|
2661
|
+
private handleCompletePayment;
|
|
2662
|
+
/**
|
|
2663
|
+
* 切换到 Processing(加载中)状态
|
|
2664
|
+
* 显示加载动画和 "Checking payment status..." 文本
|
|
2665
|
+
* 按钮变为 "Processing..." 且不可点击
|
|
2666
|
+
*/
|
|
2667
|
+
showProcessing(): void;
|
|
2668
|
+
/**
|
|
2669
|
+
* 恢复到初始状态(隐藏加载动画,恢复按钮文本)
|
|
2670
|
+
*/
|
|
2671
|
+
hideProcessing(): void;
|
|
2672
|
+
/**
|
|
2673
|
+
* 处理 ESC 键
|
|
2674
|
+
*/
|
|
2675
|
+
private handleEscKey;
|
|
2676
|
+
/**
|
|
2677
|
+
* 阻止 body 的触摸滑动
|
|
2678
|
+
*/
|
|
2679
|
+
private preventTouchMove;
|
|
2680
|
+
/**
|
|
2681
|
+
* 清理资源
|
|
2682
|
+
*/
|
|
2683
|
+
private cleanup;
|
|
2684
|
+
/**
|
|
2685
|
+
* 检查弹窗是否打开
|
|
2686
|
+
*/
|
|
2687
|
+
isOpen(): boolean;
|
|
2688
|
+
}
|
|
2689
|
+
|
|
2690
|
+
/**
|
|
2691
|
+
* PaymentFailedModal - 支付失败弹窗
|
|
2692
|
+
* 纯 JavaScript 实现,不依赖 React
|
|
2693
|
+
*
|
|
2694
|
+
* 样式与 PaymentVerificationModal 保持一致
|
|
2695
|
+
* 深蓝渐变主题背景,按钮样式统一
|
|
2696
|
+
*/
|
|
2697
|
+
|
|
2698
|
+
interface PaymentFailedModalOptions {
|
|
2699
|
+
/** 语言,默认 'en' */
|
|
2700
|
+
language?: LocaleCode;
|
|
2701
|
+
/** 错误标题 */
|
|
2702
|
+
title?: string;
|
|
2703
|
+
/** 错误消息 */
|
|
2704
|
+
message: string;
|
|
2705
|
+
/** 错误详情(可选,支持展开/折叠) */
|
|
2706
|
+
details?: string;
|
|
2707
|
+
/** 关闭回调 */
|
|
2708
|
+
onClose?: () => void;
|
|
2709
|
+
/** 重试回调(可选) */
|
|
2710
|
+
onRetry?: () => void;
|
|
2711
|
+
}
|
|
2712
|
+
/**
|
|
2713
|
+
* 支付失败弹窗类
|
|
2714
|
+
*/
|
|
2715
|
+
declare class PaymentFailedModal {
|
|
2716
|
+
private overlay;
|
|
2717
|
+
private modal;
|
|
2718
|
+
private options;
|
|
2719
|
+
private isExiting;
|
|
2720
|
+
private scrollY;
|
|
2721
|
+
private boundHandleEscKey;
|
|
2722
|
+
private boundPreventTouchMove;
|
|
2723
|
+
private detailsExpanded;
|
|
2724
|
+
constructor(options: PaymentFailedModalOptions);
|
|
2725
|
+
/**
|
|
2726
|
+
* 打开弹窗
|
|
2727
|
+
*/
|
|
2728
|
+
open(): void;
|
|
2729
|
+
/**
|
|
2730
|
+
* 关闭弹窗
|
|
2731
|
+
*/
|
|
2732
|
+
close(): void;
|
|
2733
|
+
/**
|
|
2734
|
+
* 创建弹窗元素
|
|
2735
|
+
*/
|
|
2736
|
+
private createModal;
|
|
2737
|
+
/**
|
|
2738
|
+
* 生成弹窗 HTML
|
|
2739
|
+
*/
|
|
2740
|
+
private getModalHTML;
|
|
2741
|
+
/**
|
|
2742
|
+
* 添加 CSS 动画
|
|
2743
|
+
*/
|
|
2744
|
+
private addStyles;
|
|
2745
|
+
/**
|
|
2746
|
+
* 添加事件监听
|
|
2747
|
+
*/
|
|
2748
|
+
private attachEventListeners;
|
|
2749
|
+
/**
|
|
2750
|
+
* 切换详情展开/折叠
|
|
2751
|
+
*/
|
|
2752
|
+
private toggleDetails;
|
|
2753
|
+
/**
|
|
2754
|
+
* 处理 ESC 键
|
|
2755
|
+
*/
|
|
2756
|
+
private handleEscKey;
|
|
2757
|
+
/**
|
|
2758
|
+
* 阻止 body 的触摸滑动
|
|
2759
|
+
*/
|
|
2760
|
+
private preventTouchMove;
|
|
2220
2761
|
/**
|
|
2221
2762
|
* 清理资源
|
|
2222
2763
|
*/
|
|
@@ -2340,6 +2881,7 @@ declare class StylesheetLoader {
|
|
|
2340
2881
|
* Subscription API
|
|
2341
2882
|
* 订阅管理 - 查询、变更、重启订阅
|
|
2342
2883
|
*/
|
|
2884
|
+
|
|
2343
2885
|
/**
|
|
2344
2886
|
* 当前订阅状态
|
|
2345
2887
|
*/
|
|
@@ -2347,7 +2889,7 @@ interface CurrentSubscription {
|
|
|
2347
2889
|
subscription_id: string;
|
|
2348
2890
|
product_id: string;
|
|
2349
2891
|
tier: string;
|
|
2350
|
-
billing_period:
|
|
2892
|
+
billing_period: BillingPeriod;
|
|
2351
2893
|
status: string;
|
|
2352
2894
|
cancel_at_period_end: boolean;
|
|
2353
2895
|
current_period_end: number;
|
|
@@ -2358,7 +2900,7 @@ interface CurrentSubscription {
|
|
|
2358
2900
|
interface ActiveSubscription {
|
|
2359
2901
|
subscription_id: string;
|
|
2360
2902
|
tier: number;
|
|
2361
|
-
billing_period:
|
|
2903
|
+
billing_period: BillingPeriod;
|
|
2362
2904
|
price: string;
|
|
2363
2905
|
currency: string;
|
|
2364
2906
|
current_period_start: number;
|
|
@@ -2367,14 +2909,6 @@ interface ActiveSubscription {
|
|
|
2367
2909
|
cancel_at_period_end: boolean;
|
|
2368
2910
|
can_cancel: boolean;
|
|
2369
2911
|
}
|
|
2370
|
-
/**
|
|
2371
|
-
* 统一响应格式
|
|
2372
|
-
*/
|
|
2373
|
-
interface UnifiedResponse<T = any> {
|
|
2374
|
-
code: number;
|
|
2375
|
-
msg: string;
|
|
2376
|
-
data: T | null;
|
|
2377
|
-
}
|
|
2378
2912
|
/**
|
|
2379
2913
|
* 创建订单响应
|
|
2380
2914
|
*/
|
|
@@ -2392,17 +2926,6 @@ interface CreateOrderResponse {
|
|
|
2392
2926
|
/** SDK 配置 */
|
|
2393
2927
|
sdk_config: SdkConfig;
|
|
2394
2928
|
}
|
|
2395
|
-
/**
|
|
2396
|
-
* SDK 配置
|
|
2397
|
-
*/
|
|
2398
|
-
interface SdkConfig {
|
|
2399
|
-
/** 应用 ID */
|
|
2400
|
-
app_id: string;
|
|
2401
|
-
/** API 域名 */
|
|
2402
|
-
api_host: string;
|
|
2403
|
-
/** 环境 */
|
|
2404
|
-
environment: string;
|
|
2405
|
-
}
|
|
2406
2929
|
/**
|
|
2407
2930
|
* 获取当前订阅状态(用于升降级判断)
|
|
2408
2931
|
*/
|
|
@@ -2414,11 +2937,13 @@ declare function getCurrentSubscription(apiHost: string, authToken?: string, sig
|
|
|
2414
2937
|
* @param params 创建订单参数
|
|
2415
2938
|
* @param product_id 产品ID
|
|
2416
2939
|
* @param purchase_type 购买类型(1=一次性, 2=订阅)
|
|
2940
|
+
* @param currency 币种(可选,如 USD, CNY)
|
|
2417
2941
|
* @returns 创建订单响应
|
|
2418
2942
|
*/
|
|
2419
2943
|
declare function createOrder(apiHost: string, authToken: string, params: {
|
|
2420
2944
|
product_id: string;
|
|
2421
2945
|
purchase_type: number | string;
|
|
2946
|
+
currency?: string;
|
|
2422
2947
|
}): Promise<CreateOrderResponse | null | undefined>;
|
|
2423
2948
|
/**
|
|
2424
2949
|
* 获取活跃订阅详情
|
|
@@ -2448,10 +2973,6 @@ declare function restartSubscription(apiHost: string, authToken: string | undefi
|
|
|
2448
2973
|
message: string;
|
|
2449
2974
|
next_billing_date: number;
|
|
2450
2975
|
}>;
|
|
2451
|
-
/**
|
|
2452
|
-
* 积分池类型
|
|
2453
|
-
*/
|
|
2454
|
-
type CreditPoolType = 'daily' | 'event' | 'monthly' | 'permanent';
|
|
2455
2976
|
/**
|
|
2456
2977
|
* 积分池详情
|
|
2457
2978
|
*/
|
|
@@ -2483,43 +3004,95 @@ interface CreditDetailResponse {
|
|
|
2483
3004
|
declare function getCreditDetail(apiHost: string, authToken?: string): Promise<CreditDetailResponse | null>;
|
|
2484
3005
|
|
|
2485
3006
|
/**
|
|
2486
|
-
*
|
|
2487
|
-
*
|
|
3007
|
+
* @filename packages/index.ts
|
|
3008
|
+
* @description 积分包(Credit Package)API 接口
|
|
3009
|
+
* 新版接口:GET /api/v1/payment/sdk/packages/available
|
|
2488
3010
|
*/
|
|
3011
|
+
|
|
2489
3012
|
/**
|
|
2490
|
-
*
|
|
3013
|
+
* 可用积分包列表响应
|
|
2491
3014
|
*/
|
|
2492
|
-
|
|
3015
|
+
interface AvailablePackagesResponse {
|
|
3016
|
+
code: number;
|
|
3017
|
+
msg: string;
|
|
3018
|
+
data: {
|
|
3019
|
+
packages: CreditPackageItem[];
|
|
3020
|
+
} | null;
|
|
3021
|
+
}
|
|
2493
3022
|
/**
|
|
2494
|
-
*
|
|
3023
|
+
* 获取可用积分包列表
|
|
3024
|
+
* @param apiHost API 主机地址
|
|
3025
|
+
* @param token 认证 Token
|
|
3026
|
+
* @returns 可用的积分包列表
|
|
2495
3027
|
*/
|
|
2496
|
-
|
|
2497
|
-
|
|
2498
|
-
}
|
|
3028
|
+
declare function fetchAvailablePackages(apiHost: string, token: string): Promise<CreditPackageItem[]>;
|
|
3029
|
+
|
|
2499
3030
|
/**
|
|
2500
|
-
*
|
|
2501
|
-
* @
|
|
2502
|
-
*
|
|
2503
|
-
*
|
|
2504
|
-
*
|
|
3031
|
+
* @filename CreditPackCard.ts
|
|
3032
|
+
* @description 积分包卡片组件(纯 JavaScript 实现)
|
|
3033
|
+
* 完整迁移自 Restore UI Design 项目的 PricingCard 组件
|
|
3034
|
+
*
|
|
3035
|
+
* 设计特点:
|
|
3036
|
+
* - 深色主题,半透明玻璃态背景
|
|
3037
|
+
* - 支持高亮状态(推荐套餐)带绿色渐变
|
|
3038
|
+
* - 光晕效果和呼吸动画
|
|
3039
|
+
* - SVG 徽章装饰(首充双倍)
|
|
3040
|
+
* - 悬停微交互和平滑过渡
|
|
2505
3041
|
*/
|
|
2506
|
-
|
|
3042
|
+
|
|
3043
|
+
interface CreditPackCardOptions {
|
|
3044
|
+
/** 积分包 ID */
|
|
3045
|
+
id: string;
|
|
3046
|
+
/** 积分包名称 */
|
|
3047
|
+
name: string;
|
|
3048
|
+
/** 价格(美元) */
|
|
3049
|
+
price: number;
|
|
3050
|
+
/** 基础积分 */
|
|
3051
|
+
baseCredits: number;
|
|
3052
|
+
/** 奖励积分 */
|
|
3053
|
+
bonusCredits: number;
|
|
3054
|
+
/** 总积分 */
|
|
3055
|
+
totalCredits: number;
|
|
3056
|
+
/** 购买限制(可选) */
|
|
3057
|
+
purchaseLimit?: string;
|
|
3058
|
+
/** 是否推荐 */
|
|
3059
|
+
recommended?: boolean;
|
|
3060
|
+
/** 是否首充双倍 */
|
|
3061
|
+
isFirstPurchase?: boolean;
|
|
3062
|
+
/** 语言 */
|
|
3063
|
+
language?: LocaleCode;
|
|
3064
|
+
/** 点击购买回调 */
|
|
3065
|
+
onBuy: (packId: string) => Promise<void>;
|
|
3066
|
+
}
|
|
2507
3067
|
/**
|
|
2508
|
-
*
|
|
2509
|
-
* @param transactionId SDK checkout 返回的 transaction_id
|
|
2510
|
-
* @param apiHost Payment API 地址
|
|
2511
|
-
* @param authToken 认证 Token
|
|
2512
|
-
* @param options 轮询配置
|
|
2513
|
-
* @returns 最终订单状态
|
|
3068
|
+
* 积分包卡片组件
|
|
2514
3069
|
*/
|
|
2515
|
-
declare
|
|
2516
|
-
|
|
2517
|
-
|
|
2518
|
-
|
|
2519
|
-
|
|
2520
|
-
/**
|
|
2521
|
-
|
|
2522
|
-
|
|
3070
|
+
declare class CreditPackCard {
|
|
3071
|
+
private options;
|
|
3072
|
+
private card;
|
|
3073
|
+
private loading;
|
|
3074
|
+
constructor(options: CreditPackCardOptions);
|
|
3075
|
+
/**
|
|
3076
|
+
* 渲染卡片到容器
|
|
3077
|
+
*/
|
|
3078
|
+
render(container: HTMLElement): void;
|
|
3079
|
+
/**
|
|
3080
|
+
* 创建卡片元素 - 完全还原 Restore UI Design
|
|
3081
|
+
*/
|
|
3082
|
+
private createCard;
|
|
3083
|
+
/**
|
|
3084
|
+
* 创建双倍奖励徽章 SVG
|
|
3085
|
+
*/
|
|
3086
|
+
private createDoubleBonusBadge;
|
|
3087
|
+
/**
|
|
3088
|
+
* 处理购买 - 更新为使用 span 而不是 button
|
|
3089
|
+
*/
|
|
3090
|
+
private handleBuy;
|
|
3091
|
+
/**
|
|
3092
|
+
* 销毁卡片
|
|
3093
|
+
*/
|
|
3094
|
+
destroy(): void;
|
|
3095
|
+
}
|
|
2523
3096
|
|
|
2524
3097
|
/**
|
|
2525
3098
|
* @seaverse/payment-sdk
|
|
@@ -2568,7 +3141,7 @@ declare function pollOrderStatus(transactionId: string, apiHost: string, authTok
|
|
|
2568
3141
|
/**
|
|
2569
3142
|
* SDK version
|
|
2570
3143
|
*/
|
|
2571
|
-
declare const VERSION = "0.
|
|
3144
|
+
declare const VERSION = "0.9.1";
|
|
2572
3145
|
|
|
2573
|
-
export { API_ENDPOINTS, BIZ_CODE, BindCardPaymentComponent, COMPONENT_LOAD_TIMEOUT,
|
|
2574
|
-
export type { ActiveSubscription, ApiErrorResponse, ApiResponse, ApiSuccessResponse, BaseCheckoutOptions, BillingPeriod, BindCard, BindCardCallbacks, BindCardPaymentOptions, CheckoutAPIConfig, CheckoutAPIResponse, CheckoutClientConfig, CheckoutClientStatus, CheckoutOptions, CheckoutPaymentError, CheckoutPaymentErrorCode, CheckoutResult, ComponentLoadStatus, CreateOrderResponse,
|
|
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 };
|
|
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 };
|