IAPImpl.ts 1.0 KB

12345678910111213141516171819202122232425262728293031
  1. export interface IAPProduct {
  2. productId: string;
  3. title: string;
  4. description: string;
  5. price: string;
  6. localizedPrice: string;
  7. currencyCode: string;
  8. }
  9. export interface IAPResult {
  10. status: 'purchased' | 'restored' | 'cancelled' | 'deferred';
  11. productId: string;
  12. transactionId?: string;
  13. originalTransactionId?: string;
  14. /** Base64 App Store receipt; send to your backend for validation. */
  15. receipt?: string;
  16. }
  17. export interface IAPProductsResult {
  18. products: IAPProduct[];
  19. invalidProductIds: string[];
  20. }
  21. export abstract class IAPImpl {
  22. abstract init(products: string[]): Promise<IAPProductsResult>;
  23. abstract purchase(product: string): Promise<IAPResult>;
  24. abstract restore(): Promise<IAPResult[]>;
  25. abstract getPendingTransactions(): Promise<IAPResult[]>;
  26. /** Only call after verification and idempotent delivery of the purchase. */
  27. abstract finishTransaction(transactionId: string): Promise<void>;
  28. abstract onTransaction(listener: (transaction: IAPResult) => void): () => void;
  29. }