UNPKG

@revenuecat/purchases-capacitor-ui

Version:
50 lines 2.02 kB
import { WebPlugin } from '@capacitor/core'; import { PAYWALL_RESULT } from '@revenuecat/purchases-typescript-internal-esm'; export class RevenueCatUIWeb extends WebPlugin { constructor() { super(); this.shouldMockWebResults = false; this.webNotSupportedErrorMessage = 'RevenueCatUI is not supported on web platforms.'; } async setMockWebResults(options) { this.shouldMockWebResults = options.shouldMockWebResults; return Promise.resolve(); } async presentPaywall(options) { return this.mockReturningFunctionIfEnabled('presentPaywall', { result: PAYWALL_RESULT.NOT_PRESENTED, }, options); } async presentPaywallIfNeeded(options) { return this.mockReturningFunctionIfEnabled('presentPaywallIfNeeded', { result: PAYWALL_RESULT.NOT_PRESENTED, }, options); } async presentCustomerCenter() { return this.mockNonReturningFunctionIfEnabled('presentCustomerCenter'); } addListener(eventName, listener) { if (eventName !== 'paywallDisplayed' && eventName !== 'paywallDismissed') { console.warn(`Unsupported event: ${eventName}`); } return super.addListener(eventName, listener); } removeAllListeners() { return super.removeAllListeners(); } mockNonReturningFunctionIfEnabled(functionName) { if (!this.shouldMockWebResults) { return Promise.reject(this.webNotSupportedErrorMessage); } console.log(`${functionName} called on web with mocking enabled. No-op`); return Promise.resolve(); } mockReturningFunctionIfEnabled(functionName, returnValue, options) { if (!this.shouldMockWebResults) { return Promise.reject(this.webNotSupportedErrorMessage); } console.log(`${functionName} called on web with mocking enabled. Returning mocked value`, options); return Promise.resolve(returnValue); } } //# sourceMappingURL=web.js.map