IAP.ts 887 B

1234567891011121314151617
  1. import { IOS } from 'cc/env';
  2. import { IAPImpl, IAPProductsResult, IAPResult } from './IAPImpl';
  3. import { IOSIAP } from './IOSIAP';
  4. class UnsupportedIAP extends IAPImpl {
  5. private unsupported(): never { throw new Error('当前平台尚未实现内购。'); }
  6. async init(_ids: string[]): Promise<IAPProductsResult> { return this.unsupported(); }
  7. async purchase(_id: string): Promise<IAPResult> { return this.unsupported(); }
  8. async restore(): Promise<IAPResult[]> { return this.unsupported(); }
  9. async getPendingTransactions(): Promise<IAPResult[]> { return this.unsupported(); }
  10. async finishTransaction(_id: string): Promise<void> { this.unsupported(); }
  11. onTransaction(_listener: (transaction: IAPResult) => void): () => void { return () => {}; }
  12. }
  13. const iap: IAPImpl = IOS ? new IOSIAP() : new UnsupportedIAP();
  14. export default iap;
  15. export * from './IAPImpl';