diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index e9252470..511cbdb1 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -2,6 +2,14 @@ ## 13.11 +### 13.11.1 + +#### Fix running from browser with Capacitor + +Add `Utils.platformId()` helper function to get rid of an error when running a Capacitor app in a browser. + +Ref issue #1566 + ### 13.11.0 #### Upgrade to Google Play Billing library 7.0.0 diff --git a/api/modules/CdvPurchase.Utils.md b/api/modules/CdvPurchase.Utils.md index e33f3ecf..1a3de224 100644 --- a/api/modules/CdvPurchase.Utils.md +++ b/api/modules/CdvPurchase.Utils.md @@ -8,6 +8,10 @@ - [Ajax](CdvPurchase.Utils.Ajax.md) +### Type Aliases + +- [PlatformID](CdvPurchase.Utils.md#platformid) + ### Functions - [ajax](CdvPurchase.Utils.md#ajax) @@ -17,11 +21,18 @@ - [md5](CdvPurchase.Utils.md#md5) - [nonEnumerable](CdvPurchase.Utils.md#nonenumerable) - [objectValues](CdvPurchase.Utils.md#objectvalues) +- [platformId](CdvPurchase.Utils.md#platformid-1) - [platformName](CdvPurchase.Utils.md#platformname) - [safeCall](CdvPurchase.Utils.md#safecall) - [safeCallback](CdvPurchase.Utils.md#safecallback) - [uuidv4](CdvPurchase.Utils.md#uuidv4) +## Type Aliases + +### PlatformID + +Ƭ **PlatformID**: ``"ios"`` \| ``"android"`` \| ``"web"`` + ## Functions ### ajax @@ -210,6 +221,18 @@ Object.values() for ES6 ___ +### platformId + +▸ **platformId**(): [`PlatformID`](CdvPurchase.Utils.md#platformid) + +Returns an UUID v4. Uses `window.crypto` internally to generate random values. + +#### Returns + +[`PlatformID`](CdvPurchase.Utils.md#platformid) + +___ + ### platformName ▸ **platformName**(`platform`): `string` diff --git a/api/modules/CdvPurchase.md b/api/modules/CdvPurchase.md index 8baaa04e..b495f10d 100644 --- a/api/modules/CdvPurchase.md +++ b/api/modules/CdvPurchase.md @@ -153,7 +153,7 @@ ___ ### PLUGIN\_VERSION -• `Const` **PLUGIN\_VERSION**: ``"13.11.0"`` +• `Const` **PLUGIN\_VERSION**: ``"13.11.1"`` Current release number of the plugin. diff --git a/package-lock.json b/package-lock.json index 40f9365f..cb57dc5b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "cordova-plugin-purchase", - "version": "13.11.0", + "version": "13.11.1", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "cordova-plugin-purchase", - "version": "13.11.0", + "version": "13.11.1", "license": "MIT", "devDependencies": { "@types/jest": "^29.5.4", diff --git a/package.json b/package.json index 575e40f4..879e71eb 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "cordova-plugin-purchase", - "version": "13.11.0", + "version": "13.11.1", "description": "Cordova Purchase plugin for iOS, Android, Windows (AppStore, Play, UWP)", "cordova": { "id": "cordova-plugin-purchase", diff --git a/plugin.xml b/plugin.xml index 40fb4084..1461f9df 100644 --- a/plugin.xml +++ b/plugin.xml @@ -26,7 +26,7 @@ SOFTWARE. + version="13.11.1"> Purchase Cordova Purchase plugin for iOS (AppStore), Android (PlayStore) and Windows diff --git a/src/ts/store.ts b/src/ts/store.ts index 4eb2fecf..18c49b97 100644 --- a/src/ts/store.ts +++ b/src/ts/store.ts @@ -32,7 +32,7 @@ namespace CdvPurchase { /** * Current release number of the plugin. */ - export const PLUGIN_VERSION = '13.11.0'; + export const PLUGIN_VERSION = '13.11.1'; /** * Entry class of the plugin. diff --git a/www/store.d.ts b/www/store.d.ts index f7d9e0d9..832aca6b 100644 --- a/www/store.d.ts +++ b/www/store.d.ts @@ -743,7 +743,7 @@ declare namespace CdvPurchase { /** * Current release number of the plugin. */ - const PLUGIN_VERSION = "13.11.0"; + const PLUGIN_VERSION = "13.11.1"; /** * Entry class of the plugin. */ @@ -5383,6 +5383,13 @@ declare namespace CdvPurchase { function md5(str: string): string; } } +declare namespace CdvPurchase { + namespace Utils { + type PlatformID = 'ios' | 'android' | 'web'; + /** Returns an UUID v4. Uses `window.crypto` internally to generate random values. */ + function platformId(): PlatformID; + } +} declare namespace CdvPurchase { namespace Utils { /** diff --git a/www/store.js b/www/store.js index 34ff187c..f13aa93b 100644 --- a/www/store.js +++ b/www/store.js @@ -1348,7 +1348,7 @@ var CdvPurchase; /** * Current release number of the plugin. */ - CdvPurchase.PLUGIN_VERSION = '13.11.0'; + CdvPurchase.PLUGIN_VERSION = '13.11.1'; /** * Entry class of the plugin. */ @@ -1906,7 +1906,7 @@ var CdvPurchase; * - on Android: `GOOGLE_PLAY` */ defaultPlatform() { - switch (window.cordova.platformId) { + switch (CdvPurchase.Utils.platformId()) { case 'android': return CdvPurchase.Platform.GOOGLE_PLAY; case 'ios': return CdvPurchase.Platform.APPLE_APPSTORE; default: return CdvPurchase.Platform.TEST; @@ -2699,7 +2699,7 @@ var CdvPurchase; } /** Returns true on iOS, the only platform supported by this adapter */ get isSupported() { - return window.cordova.platformId === 'ios'; + return CdvPurchase.Utils.platformId() === 'ios'; } upsertTransactionInProgress(productId, state) { const transactionId = virtualTransactionId(productId); @@ -4300,7 +4300,7 @@ var CdvPurchase; } /** Returns true on Android, the only platform supported by this Braintree bridge */ static isSupported() { - return window.cordova.platformId === 'android'; + return CdvPurchase.Utils.platformId() === 'android'; } isApplePaySupported() { return __awaiter(this, void 0, void 0, function* () { @@ -4466,7 +4466,7 @@ var CdvPurchase; static isSupported(log) { return new Promise(resolve => { var _a; - if (window.cordova.platformId !== 'ios') { + if (CdvPurchase.Utils.platformId() !== 'ios') { log.info('BraintreeApplePayPlugin is only available for ios.'); return resolve(false); } @@ -4589,7 +4589,7 @@ var CdvPurchase; return window.CdvPurchaseBraintree; } static isSupported() { - return window.cordova.platformId === 'ios'; + return CdvPurchase.Utils.platformId() === 'ios'; } } IosBridge.Bridge = Bridge; @@ -4834,7 +4834,7 @@ var CdvPurchase; get receipts() { return this._receipts; } /** Returns true on Android, the only platform supported by this adapter */ get isSupported() { - return window.cordova.platformId === 'android'; + return CdvPurchase.Utils.platformId() === 'android'; } initialize() { return __awaiter(this, void 0, void 0, function* () { @@ -6746,6 +6746,22 @@ var CdvPurchase; })(Utils = CdvPurchase.Utils || (CdvPurchase.Utils = {})); })(CdvPurchase || (CdvPurchase = {})); var CdvPurchase; +(function (CdvPurchase) { + let Utils; + (function (Utils) { + /** Returns an UUID v4. Uses `window.crypto` internally to generate random values. */ + function platformId() { + var _a, _b, _c; + if ((_a = window.cordova) === null || _a === void 0 ? void 0 : _a.platformId) + return (_b = window.cordova) === null || _b === void 0 ? void 0 : _b.platformId; + if ((_c = window.Capacitor) === null || _c === void 0 ? void 0 : _c.getPlatform) + return window.Capacitor.getPlatform(); + return 'web'; + } + Utils.platformId = platformId; + })(Utils = CdvPurchase.Utils || (CdvPurchase.Utils = {})); +})(CdvPurchase || (CdvPurchase = {})); +var CdvPurchase; (function (CdvPurchase) { let Utils; (function (Utils) {