cordova-plugin-purchase
Advanced tools
Comparing version 13.8.6 to 13.9.0
{ | ||
"name": "cordova-plugin-purchase", | ||
"version": "13.8.6", | ||
"version": "13.9.0", | ||
"description": "Cordova Purchase plugin for iOS, Android, Windows (AppStore, Play, UWP)", | ||
@@ -5,0 +5,0 @@ "cordova": { |
@@ -78,2 +78,12 @@ # Cordova Purchase Plugin | ||
### Note for ionic 3 | ||
Since version 13 of the plugin, it should be used **without** `@ionic-native/in-app-purchase-2`. | ||
ionic 3 doesn't support recent typescript notations, but the plugin can be used without typings by just declaring it: | ||
```ts | ||
declare var CdvPurchase: any | ||
``` | ||
### Note for Capacitor users | ||
@@ -85,4 +95,20 @@ | ||
See [here](https://github.com/danielsogl/awesome-cordova-plugins/issues/4457) for some info. | ||
```ts | ||
import 'cordova-plugin-purchase'; | ||
@Injectable() | ||
export class AppStoreService { | ||
// DO NOT initialize to CdvPurchase.store here | ||
store?: CdvPurchase.Store; | ||
constructor() { | ||
this.platform.ready().then(() => { | ||
// MUST WAIT for Cordova to initialize before referencing CdvPurchase namespace | ||
this.store = CdvPurchase.store | ||
}); | ||
} | ||
} | ||
``` | ||
### Setup your Application | ||
@@ -89,0 +115,0 @@ |
# Release Notes - Cordova Plugin Purchase | ||
## 13.9 | ||
### 13.9.0 | ||
#### (appstore) store.restorePurchases() return potential errors | ||
The return value for `store.restorePurchases()` has been changed from `Promise<void>` to `Promise<IError|undefined>`. | ||
You can now inspect the value returned to figure out if processing complete with or without errors. | ||
#### (appstore) Fix forceReceiptReload | ||
In certain conditions (calls to `order` and `restorePurchases`), the AppStore adapter wants to force a refresh of the application receipt. This fix prevents it from returning the version cached in memory. | ||
## 13.8 | ||
@@ -4,0 +18,0 @@ |
@@ -44,7 +44,12 @@ namespace CdvPurchase | ||
/** | ||
* Set the list of supported platforms. | ||
* | ||
* Called by the store when it is initialized. | ||
*/ | ||
setSupportedPlatforms(platforms: Platform[]) { | ||
this.log.debug('setSupportedPlatforms: ' + platforms.join(',')); | ||
this.log.debug(`setSupportedPlatforms: ${platforms.join(',')} (${this.platformWithReceiptsReady.length} have their receipts ready)`); | ||
this.supportedPlatforms = platforms; | ||
if (this.supportedPlatforms.length === this.platformWithReceiptsReady.length) { | ||
this.log.debug('triggering receiptsReady()'); | ||
this.delegate.receiptsReadyCallbacks.trigger(); | ||
@@ -54,11 +59,20 @@ } | ||
/** | ||
* Trigger the "receiptsReady" event when all platforms have reported that their receipts are ready. | ||
* | ||
* This function is used by adapters to report that their receipts are ready. | ||
* Once all adapters have reported their receipts, the "receiptsReady" event is triggered. | ||
* | ||
* @param platform The platform that has its receipts ready. | ||
*/ | ||
receiptsReady(platform: Platform): void { | ||
if (this.supportedPlatforms.length > 0 && this.platformWithReceiptsReady.length === this.supportedPlatforms.length) { | ||
this.log.debug('receiptsReady: ' + platform + '(skipping)'); | ||
return; | ||
} | ||
if (this.platformWithReceiptsReady.indexOf(platform) < 0) { | ||
this.log.debug('receiptsReady: ' + platform); | ||
this.platformWithReceiptsReady.push(platform); | ||
this.log.debug(`receiptsReady: ${platform} (${this.platformWithReceiptsReady.length}/${this.supportedPlatforms.length})`); | ||
if (this.platformWithReceiptsReady.length === this.supportedPlatforms.length) { | ||
this.log.debug('calling receiptsReady()'); | ||
this.log.debug('triggering receiptsReady()'); | ||
this.delegate.receiptsReadyCallbacks.trigger(); | ||
@@ -69,2 +83,5 @@ } | ||
/** | ||
* Trigger the "updated" event for each product. | ||
*/ | ||
productsUpdated(platform: Platform, products: Product[]): void { | ||
@@ -74,2 +91,11 @@ products.forEach(product => this.delegate.updatedCallbacks.trigger(product)); | ||
/** | ||
* Triggers the "approved", "pending" and "finished" events for transactions. | ||
* | ||
* - "approved" is triggered only if it hasn't been called for the same transaction in the last 5 seconds. | ||
* - "finished" and "pending" are triggered only if the transaction state has changed. | ||
* | ||
* @param platform The platform that has its receipts updated. | ||
* @param receipts The receipts that have been updated. | ||
*/ | ||
receiptsUpdated(platform: Platform, receipts: Receipt[]): void { | ||
@@ -76,0 +102,0 @@ const now = +new Date(); |
@@ -96,4 +96,5 @@ namespace CdvPurchase | ||
case Platform.TEST: | ||
return this.list.push(new Test.Adapter(context)); | ||
default: | ||
return this.list.push(new Test.Adapter(context)); | ||
return; | ||
} | ||
@@ -100,0 +101,0 @@ }); |
@@ -141,2 +141,5 @@ /// <reference path="../../types.ts" /> | ||
/** Callback called when the restore process is completed */ | ||
onRestoreCompleted?: (code: IError | undefined) => void; | ||
constructor(context: CdvPurchase.Internal.AdapterContext, options: AdapterOptions) { | ||
@@ -180,2 +183,3 @@ this.context = context; | ||
/** Remove a transaction from the pseudo receipt */ | ||
private removeTransactionInProgress(productId: string) { | ||
@@ -186,2 +190,3 @@ const transactionId = virtualTransactionId(productId); | ||
/** Insert or update a transaction in the pseudo receipt */ | ||
private async upsertTransaction(productId: string, transactionId: string, state: TransactionState): Promise<SKTransaction> { | ||
@@ -332,2 +337,6 @@ return new Promise(resolve => { | ||
this.log.info('restoreFailed: ' + errorCode); | ||
if (this.onRestoreCompleted) { | ||
this.onRestoreCompleted(appStoreError(errorCode, 'Restore purchases failed', null)); | ||
this.onRestoreCompleted = undefined; | ||
} | ||
}, | ||
@@ -337,2 +346,6 @@ | ||
this.log.info('restoreCompleted'); | ||
if (this.onRestoreCompleted) { | ||
this.onRestoreCompleted(undefined); | ||
this.onRestoreCompleted = undefined; | ||
} | ||
}, | ||
@@ -434,3 +447,3 @@ }, async () => { | ||
return new Promise<undefined | ApplicationReceipt>(resolve => { | ||
if (this.bridge.appStoreReceipt?.appStoreReceipt) { | ||
if (this.bridge.appStoreReceipt?.appStoreReceipt && !this.forceReceiptReload) { | ||
this.log.debug('using cached appstore receipt'); | ||
@@ -440,2 +453,3 @@ return resolve(this.bridge.appStoreReceipt); | ||
this.log.debug('loading appstore receipt...'); | ||
this.forceReceiptReload = false; | ||
this.bridge.loadReceipts(receipt => { | ||
@@ -660,4 +674,4 @@ this.log.debug('appstore receipt loaded'); | ||
if (this.forceReceiptReload) { | ||
const nativeData = await this.loadAppStoreReceipt(); | ||
this.forceReceiptReload = false; | ||
const nativeData = await this.loadAppStoreReceipt(); | ||
if (nativeData) { | ||
@@ -734,11 +748,14 @@ applicationReceipt = nativeData; | ||
restorePurchases(): Promise<void> { | ||
return new Promise(resolve => { | ||
restorePurchases(): Promise<IError | undefined> { | ||
return new Promise<IError | undefined>(resolve => { | ||
this.onRestoreCompleted = (error) => { | ||
this.onRestoreCompleted = undefined; | ||
this.bridge.refreshReceipts(obj => { | ||
resolve(error) | ||
}, (code, message) => { | ||
resolve(error || appStoreError(code, message, null)); | ||
}); | ||
} | ||
this.forceReceiptReload = true; | ||
this.bridge.restore(); | ||
this.bridge.refreshReceipts(obj => { | ||
resolve(); | ||
}, (code, message) => { | ||
resolve(); | ||
}); | ||
}); | ||
@@ -745,0 +762,0 @@ } |
@@ -304,2 +304,11 @@ namespace CdvPurchase { | ||
/** | ||
* Initialize the AppStore bridge. | ||
* | ||
* This calls the native "setup" method from the "InAppPurchase" Objective-C class. | ||
* | ||
* @param options Options for the bridge | ||
* @param success Called when the bridge is ready | ||
* @param error Called when the bridge failed to initialize | ||
*/ | ||
init(options: Partial<BridgeOptions>, success: () => void, error: (code: ErrorCode, message: string) => void) { | ||
@@ -340,6 +349,6 @@ this.options = { | ||
const setupFailed = () => { | ||
const setupFailed = (err: string) => { | ||
log('setup failed'); | ||
// protectCall(this.options.error, 'options.error', ErrorCode.SETUP, 'Setup failed'); | ||
protectCall(error, 'init.error', ErrorCode.SETUP, 'Setup failed'); | ||
protectCall(error, 'init.error', ErrorCode.SETUP, 'Setup failed: ' + err); | ||
}; | ||
@@ -346,0 +355,0 @@ |
@@ -428,3 +428,4 @@ namespace CdvPurchase { | ||
async restorePurchases(): Promise<void> { | ||
async restorePurchases(): Promise<IError | undefined> { | ||
return undefined; | ||
} | ||
@@ -431,0 +432,0 @@ } |
@@ -435,7 +435,7 @@ /// <reference path="../../receipt.ts" /> | ||
restorePurchases(): Promise<void> { | ||
restorePurchases(): Promise<IError | undefined> { | ||
return new Promise(resolve => { | ||
this.bridge.getPurchases(resolve, (message, code) => { | ||
this.bridge.getPurchases(() => resolve(undefined), (message, code) => { | ||
this.log.warn('getPurchases() failed: ' + (code ?? 'ERROR') + ': ' + message); | ||
resolve(); | ||
resolve(playStoreError(code ?? ErrorCode.UNKNOWN, message, null)); | ||
}); | ||
@@ -442,0 +442,0 @@ }); |
@@ -279,3 +279,4 @@ namespace CdvPurchase { | ||
async restorePurchases(): Promise<void> { | ||
async restorePurchases(): Promise<IError | undefined> { | ||
return undefined; | ||
} | ||
@@ -282,0 +283,0 @@ } |
@@ -44,3 +44,4 @@ namespace CdvPurchase { | ||
} | ||
async restorePurchases(): Promise<void> { | ||
async restorePurchases(): Promise<IError | undefined> { | ||
return undefined; | ||
} | ||
@@ -47,0 +48,0 @@ } |
@@ -35,3 +35,3 @@ /// <reference path="types.ts" /> | ||
*/ | ||
export const PLUGIN_VERSION = '13.8.6'; | ||
export const PLUGIN_VERSION = '13.9.0'; | ||
@@ -625,6 +625,9 @@ /** | ||
async restorePurchases() { | ||
let error: IError | undefined; | ||
for (const adapter of this.adapters.list) { | ||
if (adapter.ready) await adapter.restorePurchases(); | ||
if (adapter.ready) { | ||
error = error ?? await adapter.restorePurchases(); | ||
} | ||
} | ||
// store.triggerError(storeError(ErrorCode.UNKNOWN, 'restorePurchases() is not implemented yet')); | ||
return error; | ||
} | ||
@@ -631,0 +634,0 @@ |
@@ -206,3 +206,3 @@ /// <reference path="store.ts" /> | ||
*/ | ||
restorePurchases(): Promise<void>; | ||
restorePurchases(): Promise<IError | undefined>; | ||
} | ||
@@ -209,0 +209,0 @@ |
@@ -26,9 +26,11 @@ namespace CdvPurchase { | ||
export function safeCall<T>(logger: Logger, className: string, callback: Callback<T>, value: T): void { | ||
const callbackName = callback.name || ('#' + md5(callback.toString())); | ||
setTimeout(() => { | ||
try { | ||
logger.debug(`Calling callback: type=${className} name=${callback.name}`); | ||
logger.debug(`Calling callback: type=${className} name=${callbackName}`); | ||
callback(value); | ||
} | ||
catch (error) { | ||
logger.error(`Error in callback: type=${className} name=${callback.name}`); | ||
logger.error(`Error in callback: type=${className} name=${callbackName}`); | ||
logger.debug(callback.toString()); | ||
const errorAsError = error as Error; | ||
@@ -35,0 +37,0 @@ if ('message' in errorAsError) |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1339675
24973
219