| 12345678910111213141516171819 |
- import { IOS } from 'cc/env';
- import { IAPImpl, IAPProductsResult, IAPResult } from './IAPImpl';
- import { IOSIAP } from './IOSIAP';
- class UnsupportedIAP extends IAPImpl {
- private unsupported(): never { throw new Error('当前平台尚未实现内购。'); }
- async init(_ids: string[]): Promise<IAPProductsResult> { return this.unsupported(); }
- async purchase(productId: string): Promise<IAPResult> {
- return { status: 'error', productId, errorCode: 'UNSUPPORTED_PLATFORM', reason: '当前平台尚未实现内购。' };
- }
- async restore(): Promise<IAPResult[]> { return this.unsupported(); }
- async getPendingTransactions(): Promise<IAPResult[]> { return this.unsupported(); }
- async finishTransaction(_id: string): Promise<void> { this.unsupported(); }
- onTransaction(_listener: (transaction: IAPResult) => void): () => void { return () => {}; }
- }
- const iap: IAPImpl = IOS ? new IOSIAP() : new UnsupportedIAP();
- export default iap;
- export * from './IAPImpl';
|