| 12345678910111213141516171819202122232425262728293031323334353637383940 |
- export interface IAPProduct {
- productId: string;
- title: string;
- description: string;
- price: string;
- localizedPrice: string;
- currencyCode: string;
- }
- export type IAPErrorCode = 'INVALID_PRODUCT_ID' | 'PRODUCT_NOT_LOADED' | 'PAYMENTS_NOT_ALLOWED'
- | 'OPERATION_IN_PROGRESS' | 'PENDING_TRANSACTIONS' | 'PAYMENT_FAILED'
- | 'TIMEOUT' | 'BRIDGE_ERROR' | 'UNSUPPORTED_PLATFORM' | 'UNKNOWN';
- export interface IAPResult {
- status: 'purchased' | 'restored' | 'cancelled' | 'deferred' | 'error';
- /** 请求失败原因;超时不代表 Apple 已取消或支付失败。 */
- reason?: string;
- errorCode?: IAPErrorCode;
- /** Apple 原始错误,仅用于诊断,不依赖本地化 message 判断逻辑。 */
- nativeError?: { domain: string; code: number };
- productId: string;
- transactionId?: string;
- originalTransactionId?: string;
- /** Base64 App Store receipt; send to your backend for validation. */
- receipt?: string;
- }
- export interface IAPProductsResult {
- products: IAPProduct[];
- invalidProductIds: string[];
- }
- export abstract class IAPImpl {
- abstract init(products: string[]): Promise<IAPProductsResult>;
- abstract purchase(product: string): Promise<IAPResult>;
- abstract restore(): Promise<IAPResult[]>;
- abstract getPendingTransactions(): Promise<IAPResult[]>;
- /** Only call after verification and idempotent delivery of the purchase. */
- abstract finishTransaction(transactionId: string): Promise<void>;
- abstract onTransaction(listener: (transaction: IAPResult) => void): () => void;
- }
|