@seaverse/payment-sdk 0.8.1 → 0.8.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/README.md +65 -3
- package/dist/index.browser.js +595 -965
- package/dist/index.browser.js.map +1 -1
- package/dist/index.cjs +595 -965
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +175 -155
- package/dist/index.js +595 -965
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1315,9 +1315,9 @@ interface BindCard {
|
|
|
1315
1315
|
user_type?: number;
|
|
1316
1316
|
}
|
|
1317
1317
|
/**
|
|
1318
|
-
*
|
|
1318
|
+
* Base package interface - common fields for all package types
|
|
1319
1319
|
*/
|
|
1320
|
-
interface
|
|
1320
|
+
interface BasePackage {
|
|
1321
1321
|
/** Unique package ID */
|
|
1322
1322
|
id: string;
|
|
1323
1323
|
/** Display name */
|
|
@@ -1332,6 +1332,11 @@ interface GenericPackage {
|
|
|
1332
1332
|
base_credits?: string;
|
|
1333
1333
|
/** Bonus credits (optional) */
|
|
1334
1334
|
bonus_credits?: string;
|
|
1335
|
+
}
|
|
1336
|
+
/**
|
|
1337
|
+
* Generic package interface that supports all package types
|
|
1338
|
+
*/
|
|
1339
|
+
interface GenericPackage extends BasePackage {
|
|
1335
1340
|
/** Bonus percentage (e.g., 20 for +20%) */
|
|
1336
1341
|
bonus_percentage?: number;
|
|
1337
1342
|
/** Daily purchase limit (0 = unlimited) */
|
|
@@ -1765,10 +1770,33 @@ declare class SeaartPaymentSDK {
|
|
|
1765
1770
|
destroy(): void;
|
|
1766
1771
|
}
|
|
1767
1772
|
|
|
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
|
+
|
|
1768
1795
|
/**
|
|
1769
1796
|
* 共享类型定义
|
|
1770
1797
|
* Shared types for CreditPackageModal and GenericPackageModal
|
|
1771
1798
|
*/
|
|
1799
|
+
|
|
1772
1800
|
/** 环境类型 */
|
|
1773
1801
|
type Environment = 'development' | 'production';
|
|
1774
1802
|
/** 环境配置接口 */
|
|
@@ -1811,237 +1839,229 @@ interface PaymentSDKConfig {
|
|
|
1811
1839
|
/** 自定义 CSS URL(覆盖环境配置) */
|
|
1812
1840
|
cssUrl?: string;
|
|
1813
1841
|
}
|
|
1814
|
-
|
|
1815
1842
|
/**
|
|
1816
|
-
*
|
|
1817
|
-
* 展示不同的积分套餐供用户选择
|
|
1843
|
+
* Base package modal options - common configuration for all package modals
|
|
1818
1844
|
*/
|
|
1819
|
-
|
|
1820
|
-
|
|
1821
|
-
/** SDK 配置(必填 - 用于自动初始化支付 SDK) */
|
|
1845
|
+
interface BasePackageModalOptions<TPackage extends BasePackage> {
|
|
1846
|
+
/** SDK configuration (required for automatic SDK initialization) */
|
|
1822
1847
|
sdkConfig: PaymentSDKConfig;
|
|
1823
|
-
/**
|
|
1848
|
+
/** Language (default 'en') */
|
|
1824
1849
|
language?: 'en' | 'zh-CN';
|
|
1825
|
-
/** 弹框标题 */
|
|
1826
|
-
title?: string;
|
|
1827
|
-
/** 弹框标题(中文) */
|
|
1828
|
-
title_cn?: string;
|
|
1829
|
-
/** 副标题 */
|
|
1830
|
-
subtitle?: string;
|
|
1831
|
-
/** 副标题(中文) */
|
|
1832
|
-
subtitle_cn?: string;
|
|
1833
1850
|
/**
|
|
1834
|
-
*
|
|
1835
|
-
* @param orderId
|
|
1836
|
-
* @param transactionId
|
|
1851
|
+
* Payment success callback - notifies when payment is completed
|
|
1852
|
+
* @param orderId Order ID
|
|
1853
|
+
* @param transactionId Transaction ID
|
|
1854
|
+
* @param pkg Purchased package
|
|
1837
1855
|
*/
|
|
1838
|
-
onPaymentSuccess?: (orderId: string, transactionId: string) => void;
|
|
1856
|
+
onPaymentSuccess?: (orderId: string, transactionId: string, pkg: TPackage) => void;
|
|
1839
1857
|
/**
|
|
1840
|
-
*
|
|
1841
|
-
* @param error
|
|
1858
|
+
* Payment failed callback
|
|
1859
|
+
* @param error Error information
|
|
1860
|
+
* @param pkg Package that failed to purchase
|
|
1842
1861
|
*/
|
|
1843
|
-
onPaymentFailed?: (error: Error) => void;
|
|
1844
|
-
/**
|
|
1862
|
+
onPaymentFailed?: (error: Error, pkg: TPackage) => void;
|
|
1863
|
+
/** Modal close callback */
|
|
1845
1864
|
onClose?: () => void;
|
|
1846
1865
|
paymentMethod?: PaymentMethod;
|
|
1847
1866
|
accountToken?: string;
|
|
1848
1867
|
}
|
|
1849
|
-
|
|
1850
|
-
|
|
1851
|
-
|
|
1852
|
-
|
|
1853
|
-
|
|
1854
|
-
|
|
1855
|
-
|
|
1856
|
-
|
|
1857
|
-
|
|
1858
|
-
|
|
1868
|
+
|
|
1869
|
+
/**
|
|
1870
|
+
* BasePackageModal - Abstract base class for package modals
|
|
1871
|
+
* Provides shared logic for SDK initialization, payment flow, and event handling
|
|
1872
|
+
*/
|
|
1873
|
+
|
|
1874
|
+
/**
|
|
1875
|
+
* Abstract base class for package modals
|
|
1876
|
+
* Provides common functionality for SDK initialization, payment flow, and event handling
|
|
1877
|
+
*/
|
|
1878
|
+
declare abstract class BasePackageModal<TPackage extends BasePackage, TOptions extends BasePackageModalOptions<TPackage>> {
|
|
1879
|
+
protected modal: PaymentModal;
|
|
1880
|
+
protected options: TOptions;
|
|
1881
|
+
protected language: 'en' | 'zh-CN';
|
|
1882
|
+
protected resizeHandler: (() => void) | null;
|
|
1883
|
+
protected isInitializingSDK: boolean;
|
|
1884
|
+
protected sdkInitialized: boolean;
|
|
1885
|
+
protected paymentMethod?: PaymentMethod;
|
|
1886
|
+
protected accountToken?: string;
|
|
1887
|
+
constructor(options: TOptions);
|
|
1859
1888
|
/**
|
|
1860
|
-
*
|
|
1889
|
+
* Create and configure the PaymentModal instance
|
|
1890
|
+
* Subclasses define modal title, width, close behavior
|
|
1861
1891
|
*/
|
|
1862
|
-
|
|
1892
|
+
protected abstract createModal(): PaymentModal;
|
|
1863
1893
|
/**
|
|
1864
|
-
*
|
|
1865
|
-
*
|
|
1866
|
-
* @param maxRetries 最大重试次数,默认 1 次
|
|
1867
|
-
* @returns 是否初始化成功
|
|
1894
|
+
* Render the modal content (UI-specific logic)
|
|
1895
|
+
* Subclasses implement their own UI rendering
|
|
1868
1896
|
*/
|
|
1869
|
-
|
|
1897
|
+
protected abstract renderContent(): void;
|
|
1870
1898
|
/**
|
|
1871
|
-
*
|
|
1899
|
+
* Get packages to display
|
|
1900
|
+
* CreditPackageModal returns CREDIT_PACKAGES
|
|
1901
|
+
* GenericPackageModal returns this.options.packages
|
|
1872
1902
|
*/
|
|
1873
|
-
|
|
1903
|
+
protected abstract getPackages(): TPackage[];
|
|
1874
1904
|
/**
|
|
1875
|
-
*
|
|
1905
|
+
* Get package display name for payment modal title
|
|
1906
|
+
*/
|
|
1907
|
+
protected abstract getPackageDisplayName(pkg: TPackage): string;
|
|
1908
|
+
/**
|
|
1909
|
+
* Get loading button HTML with spinner
|
|
1910
|
+
* @param text Loading text
|
|
1911
|
+
* @param args Additional arguments (e.g., isPopular for CreditPackageModal)
|
|
1912
|
+
*/
|
|
1913
|
+
protected abstract getLoadingButtonHTML(text: string, ...args: any[]): string;
|
|
1914
|
+
/**
|
|
1915
|
+
* Open the modal
|
|
1916
|
+
*/
|
|
1917
|
+
open(): Promise<void>;
|
|
1918
|
+
/**
|
|
1919
|
+
* Close the modal
|
|
1876
1920
|
*/
|
|
1877
1921
|
close(): void;
|
|
1878
1922
|
/**
|
|
1879
|
-
*
|
|
1923
|
+
* Check if modal is open
|
|
1880
1924
|
*/
|
|
1881
|
-
|
|
1925
|
+
isOpen(): boolean;
|
|
1882
1926
|
/**
|
|
1883
|
-
*
|
|
1927
|
+
* Apply modal styling (hook method)
|
|
1928
|
+
* Subclasses can override to customize modal appearance
|
|
1884
1929
|
*/
|
|
1885
|
-
|
|
1930
|
+
protected applyModalStyling(): void;
|
|
1886
1931
|
/**
|
|
1887
|
-
*
|
|
1932
|
+
* Initialize payment SDK (identical in both classes)
|
|
1888
1933
|
*/
|
|
1889
|
-
|
|
1934
|
+
protected initializeSDK(): Promise<void>;
|
|
1890
1935
|
/**
|
|
1891
|
-
*
|
|
1936
|
+
* Wait for SDK initialization with timeout and retry
|
|
1937
|
+
* @param timeout Timeout in milliseconds (default 30 seconds)
|
|
1938
|
+
* @param maxRetries Maximum retry count (default 1)
|
|
1939
|
+
* @returns Whether initialization succeeded
|
|
1892
1940
|
*/
|
|
1893
|
-
|
|
1941
|
+
protected waitForSDKInitialization(timeout?: number, maxRetries?: number): Promise<boolean>;
|
|
1894
1942
|
/**
|
|
1895
|
-
*
|
|
1896
|
-
* @param text 加载文本
|
|
1897
|
-
* @param isPopular 是否为 Popular 套餐(用于调整颜色)
|
|
1943
|
+
* Handle payment flow (order creation + payment modal)
|
|
1898
1944
|
*/
|
|
1899
|
-
|
|
1945
|
+
protected handlePaymentFlow(pkg: TPackage, button: HTMLButtonElement, originalHTML: string): Promise<void>;
|
|
1900
1946
|
/**
|
|
1901
|
-
*
|
|
1947
|
+
* Open payment modal (DropinPaymentModal + PurchaseSuccessModal)
|
|
1902
1948
|
*/
|
|
1903
|
-
|
|
1949
|
+
protected openPaymentModal(orderId: string, pkg: TPackage): Promise<void>;
|
|
1904
1950
|
/**
|
|
1905
|
-
*
|
|
1951
|
+
* Attach event listeners to package buttons
|
|
1906
1952
|
*/
|
|
1907
|
-
|
|
1953
|
+
protected attachEventListeners(container: HTMLElement): void;
|
|
1908
1954
|
/**
|
|
1909
|
-
*
|
|
1955
|
+
* Cleanup resources
|
|
1910
1956
|
*/
|
|
1911
|
-
|
|
1957
|
+
protected cleanup(): void;
|
|
1912
1958
|
/**
|
|
1913
|
-
*
|
|
1959
|
+
* Format number with commas
|
|
1914
1960
|
*/
|
|
1915
|
-
|
|
1961
|
+
protected formatNumber(num: string): string;
|
|
1916
1962
|
/**
|
|
1917
|
-
*
|
|
1963
|
+
* Get content container from modal
|
|
1918
1964
|
*/
|
|
1919
|
-
|
|
1965
|
+
protected getContentContainer(): HTMLElement | null;
|
|
1920
1966
|
}
|
|
1921
1967
|
|
|
1922
1968
|
/**
|
|
1923
|
-
*
|
|
1924
|
-
*
|
|
1925
|
-
* 套餐数据从外部配置传入,无硬编码
|
|
1969
|
+
* CreditPackageModal - 积分套餐选择弹框
|
|
1970
|
+
* 展示不同的积分套餐供用户选择
|
|
1926
1971
|
*/
|
|
1927
1972
|
|
|
1928
|
-
interface
|
|
1929
|
-
/**
|
|
1930
|
-
|
|
1931
|
-
/**
|
|
1932
|
-
|
|
1933
|
-
/**
|
|
1934
|
-
|
|
1973
|
+
interface CreditPackageModalOptions extends BasePackageModalOptions<CreditPackage> {
|
|
1974
|
+
/** Modal title */
|
|
1975
|
+
title?: string;
|
|
1976
|
+
/** Modal title (Chinese) */
|
|
1977
|
+
title_cn?: string;
|
|
1978
|
+
/** Subtitle */
|
|
1979
|
+
subtitle?: string;
|
|
1980
|
+
/** Subtitle (Chinese) */
|
|
1981
|
+
subtitle_cn?: string;
|
|
1982
|
+
}
|
|
1983
|
+
declare class CreditPackageModal extends BasePackageModal<CreditPackage, CreditPackageModalOptions> {
|
|
1984
|
+
private readonly SPACING;
|
|
1985
|
+
private readonly COLORS;
|
|
1935
1986
|
/**
|
|
1936
|
-
*
|
|
1937
|
-
* @param orderId 订单ID
|
|
1938
|
-
* @param transactionId 交易ID
|
|
1939
|
-
* @param pkg 购买的套餐
|
|
1987
|
+
* Create and configure the PaymentModal instance
|
|
1940
1988
|
*/
|
|
1941
|
-
|
|
1989
|
+
protected createModal(): PaymentModal;
|
|
1942
1990
|
/**
|
|
1943
|
-
*
|
|
1944
|
-
* @param error 错误信息
|
|
1945
|
-
* @param pkg 购买失败的套餐
|
|
1991
|
+
* Get packages to display
|
|
1946
1992
|
*/
|
|
1947
|
-
|
|
1948
|
-
/** 弹框关闭回调 */
|
|
1949
|
-
onClose?: () => void;
|
|
1950
|
-
}
|
|
1951
|
-
declare class GenericPackageModal {
|
|
1952
|
-
private modal;
|
|
1953
|
-
private options;
|
|
1954
|
-
private language;
|
|
1955
|
-
private resizeHandler;
|
|
1956
|
-
private isInitializingSDK;
|
|
1957
|
-
private sdkInitialized;
|
|
1958
|
-
private paymentMethod?;
|
|
1959
|
-
private accountToken?;
|
|
1960
|
-
constructor(options: GenericPackageModalOptions);
|
|
1993
|
+
protected getPackages(): CreditPackage[];
|
|
1961
1994
|
/**
|
|
1962
|
-
*
|
|
1995
|
+
* Get package display name for payment modal title
|
|
1963
1996
|
*/
|
|
1964
|
-
|
|
1997
|
+
protected getPackageDisplayName(pkg: CreditPackage): string;
|
|
1965
1998
|
/**
|
|
1966
|
-
*
|
|
1967
|
-
* @param timeout 超时时间(毫秒),默认 30 秒
|
|
1968
|
-
* @param maxRetries 最大重试次数,默认 1 次
|
|
1969
|
-
* @returns 是否初始化成功
|
|
1999
|
+
* Get loading button HTML with spinner
|
|
1970
2000
|
*/
|
|
1971
|
-
|
|
2001
|
+
protected getLoadingButtonHTML(text: string, isPopular?: boolean): string;
|
|
1972
2002
|
/**
|
|
1973
|
-
*
|
|
2003
|
+
* Apply modal styling (hook method override)
|
|
1974
2004
|
*/
|
|
1975
|
-
|
|
2005
|
+
protected applyModalStyling(): void;
|
|
1976
2006
|
/**
|
|
1977
|
-
*
|
|
2007
|
+
* Render modal content
|
|
1978
2008
|
*/
|
|
1979
|
-
|
|
2009
|
+
protected renderContent(): void;
|
|
1980
2010
|
/**
|
|
1981
|
-
*
|
|
2011
|
+
* Get responsive style configuration
|
|
1982
2012
|
*/
|
|
1983
|
-
private
|
|
2013
|
+
private getResponsiveStyles;
|
|
2014
|
+
/**
|
|
2015
|
+
* Render compute credits cards
|
|
2016
|
+
*/
|
|
2017
|
+
private renderComputeCreditsCards;
|
|
1984
2018
|
/**
|
|
1985
|
-
*
|
|
2019
|
+
* Render package card
|
|
1986
2020
|
*/
|
|
1987
2021
|
private renderPackageCard;
|
|
2022
|
+
}
|
|
2023
|
+
|
|
2024
|
+
/**
|
|
2025
|
+
* GenericPackageModal - 通用套餐选择弹框
|
|
2026
|
+
* 支持多种套餐类型(破冰包、告急包、首充包等)
|
|
2027
|
+
* 套餐数据从外部配置传入,无硬编码
|
|
2028
|
+
*/
|
|
2029
|
+
|
|
2030
|
+
interface GenericPackageModalOptions extends BasePackageModalOptions<GenericPackage> {
|
|
2031
|
+
/** Package data (required - passed from external configuration) */
|
|
2032
|
+
packages: GenericPackage[];
|
|
2033
|
+
}
|
|
2034
|
+
declare class GenericPackageModal extends BasePackageModal<GenericPackage, GenericPackageModalOptions> {
|
|
2035
|
+
constructor(options: GenericPackageModalOptions);
|
|
1988
2036
|
/**
|
|
1989
|
-
*
|
|
2037
|
+
* Create and configure the PaymentModal instance
|
|
1990
2038
|
*/
|
|
1991
|
-
|
|
2039
|
+
protected createModal(): PaymentModal;
|
|
1992
2040
|
/**
|
|
1993
|
-
*
|
|
2041
|
+
* Get packages to display
|
|
1994
2042
|
*/
|
|
1995
|
-
|
|
2043
|
+
protected getPackages(): GenericPackage[];
|
|
1996
2044
|
/**
|
|
1997
|
-
*
|
|
2045
|
+
* Get package display name for payment modal title
|
|
1998
2046
|
*/
|
|
1999
|
-
|
|
2047
|
+
protected getPackageDisplayName(pkg: GenericPackage): string;
|
|
2000
2048
|
/**
|
|
2001
|
-
*
|
|
2049
|
+
* Get loading button HTML with spinner
|
|
2002
2050
|
*/
|
|
2003
|
-
|
|
2051
|
+
protected getLoadingButtonHTML(text: string): string;
|
|
2004
2052
|
/**
|
|
2005
|
-
*
|
|
2053
|
+
* Apply modal styling (hook method override)
|
|
2006
2054
|
*/
|
|
2007
|
-
|
|
2055
|
+
protected applyModalStyling(): void;
|
|
2008
2056
|
/**
|
|
2009
|
-
*
|
|
2057
|
+
* Render modal content
|
|
2010
2058
|
*/
|
|
2011
|
-
|
|
2059
|
+
protected renderContent(): void;
|
|
2012
2060
|
/**
|
|
2013
|
-
*
|
|
2061
|
+
* Render package card
|
|
2014
2062
|
*/
|
|
2015
|
-
|
|
2016
|
-
}
|
|
2017
|
-
|
|
2018
|
-
/**
|
|
2019
|
-
* 积分套餐数据
|
|
2020
|
-
*/
|
|
2021
|
-
interface CreditPackage {
|
|
2022
|
-
id: string;
|
|
2023
|
-
name: string;
|
|
2024
|
-
price: string;
|
|
2025
|
-
currency: string;
|
|
2026
|
-
base_credits: string;
|
|
2027
|
-
bonus_credits: string;
|
|
2028
|
-
credits: string;
|
|
2029
|
-
day_limit: number;
|
|
2030
|
-
is_popular?: boolean;
|
|
2031
|
-
}
|
|
2032
|
-
declare const CREDIT_PACKAGES: CreditPackage[];
|
|
2033
|
-
/**
|
|
2034
|
-
* 创作力量类型和对应的积分消耗
|
|
2035
|
-
*/
|
|
2036
|
-
interface CreativePowerType {
|
|
2037
|
-
icon: string;
|
|
2038
|
-
name: string;
|
|
2039
|
-
name_cn: string;
|
|
2040
|
-
credits_range: string;
|
|
2041
|
-
description: string;
|
|
2042
|
-
description_cn: string;
|
|
2063
|
+
private renderPackageCard;
|
|
2043
2064
|
}
|
|
2044
|
-
declare const CREATIVE_POWER_TYPES: CreativePowerType[];
|
|
2045
2065
|
|
|
2046
2066
|
/**
|
|
2047
2067
|
* 共享配置文件
|