跳至正文
rdlabo.dev文档

API

此功能为实验性功能,仅支持 iOS 16+ 和 Swift Package Manager。Android 和 Web 平台不受支持。

method initialize(...)

initialize(options: InitializeOptions) => Promise<void>

在初始化前注册 customerSessionRequested。切换用户前调用 reset。

参数 类型
options InitializeOptions

method setCustomerSession(...)

setCustomerSession(options: CustomerSessionResponse) => Promise<void>

在 30 秒内完成一次会话请求;过期或重复的响应会被拒绝。

参数 类型
options CustomerSessionResponse

method getBuyButton(...)

getBuyButton(options: { id: string; }) => Promise<BuyButton>
参数 类型
options { id: string; }

返回值: Promise<BuyButton>


method presentBuyButton(...)

presentBuyButton(options: { id: string; }) => Promise<void>

展示 SDK 的原生购买按钮。按钮一经展示,Promise 即完成,无需等待付款完成。

参数 类型
options { id: string; }

method getActiveEntitlements(...)

getActiveEntitlements(options?: { forceRefresh?: boolean | undefined; } | undefined) => Promise<{ entitlements: Entitlement[]; }>
参数 类型
options { forceRefresh?: boolean; }

返回值: Promise<{ entitlements: Entitlement[]; }>


method hasEntitlement(...)

hasEntitlement(options: { lookupKey: string; forceRefresh?: boolean; }) => Promise<{ active: boolean; }>
参数 类型
options { lookupKey: string; forceRefresh?: boolean; }

返回: Promise<{ active: boolean; }>


method presentCustomerPortal(...)

presentCustomerPortal(options?: { external?: boolean | undefined; } | undefined) => Promise<void>

默认在应用内打开门户。展示或启动时 Promise 即完成,无需等待订阅变更。

参数 类型
options { external?: boolean; }

method reset()

reset() => Promise<void>

取消待处理的工作,关闭插件界面,并清除会话和缓存。再次使用前需重新调用 initialize。


method addListener('customerSessionRequested', ...)

addListener(eventName: 'customerSessionRequested', listenerFunc: (event: { requestId: string; }) => void) => Promise<PluginListenerHandle>

每个请求都应从后端获取新的 Customer Session,切勿缓存其密钥。

参数 类型
eventName 'customerSessionRequested'
listenerFunc (event: { requestId: string; }) => void

返回值: Promise<PluginListenerHandle>


method addListener('entitlementsChanged', ...)

addListener(eventName: 'entitlementsChanged', listenerFunc: (event: { entitlements: Entitlement[]; }) => void) => Promise<PluginListenerHandle>

SDK 刷新通知,并非服务器推送订阅。

参数 类型
eventName 'entitlementsChanged'
listenerFunc (event: { entitlements: Entitlement[]; }) => void

返回值: Promise<PluginListenerHandle>


method addListener('billingError', ...)

addListener(eventName: 'billingError', listenerFunc: (event: { message: string; }) => void) => Promise<PluginListenerHandle>

点击已显示的原生购买按钮时产生的错误。

参数 类型
eventName 'billingError'
listenerFunc (event: { message: string; }) => void

返回值: Promise<PluginListenerHandle>


method removeAllListeners()

removeAllListeners() => Promise<void>

接口

interface InitializeOptions

属性 类型 说明
publishableKey string
maximumStaleEntitlementsDuration number 刷新权益前允许的最长缓存时间,单位为秒。默认为 300。

interface CustomerSessionResponse

属性 类型 说明
requestId string
session CustomerSession \| null 新会话;仅当用户未登录时返回 null。
failed boolean 后端或网络故障时设为 true。不要在未告知用户的情况下回退到匿名结账。

interface CustomerSession

属性 类型 说明
customer string
clientSecret string
expiresAt number 经身份验证的后端返回的 Unix 时间戳,单位为秒。

interface BuyButton

属性 类型 说明
id string
active boolean
callToAction string
amount string 以该币种最小单位表示的金额,由 Stripe 以字符串形式提供。
currency string

interface Entitlement

属性 类型
id string
feature string
lookupKey string

interface PluginListenerHandle

属性 类型
remove () => Promise<void>