IAP.ts 997 B

12345678910111213141516171819
  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(productId: string): Promise<IAPResult> {
  8. return { status: 'error', productId, errorCode: 'UNSUPPORTED_PLATFORM', reason: '当前平台尚未实现内购。' };
  9. }
  10. async restore(): Promise<IAPResult[]> { return this.unsupported(); }
  11. async getPendingTransactions(): Promise<IAPResult[]> { return this.unsupported(); }
  12. async finishTransaction(_id: string): Promise<void> { this.unsupported(); }
  13. onTransaction(_listener: (transaction: IAPResult) => void): () => void { return () => {}; }
  14. }
  15. const iap: IAPImpl = IOS ? new IOSIAP() : new UnsupportedIAP();
  16. export default iap;
  17. export * from './IAPImpl';