cordova-plugin-purchase
Advanced tools
Comparing version 13.10.0 to 13.10.1
{ | ||
"name": "cordova-plugin-purchase", | ||
"version": "13.10.0", | ||
"version": "13.10.1", | ||
"description": "Cordova Purchase plugin for iOS, Android, Windows (AppStore, Play, UWP)", | ||
@@ -5,0 +5,0 @@ "cordova": { |
# Release Notes - Cordova Plugin Purchase | ||
## 13.10.0 | ||
## 13.10 | ||
### 13.10.1 | ||
#### Fix store.initialize() when passed a single value | ||
`store.initialize()` was supposed to work when passed a single value instead of an array. It turns out there was a regression, fixed with this release. | ||
#### Add store.when().initiated(transaction) | ||
Allows monitoring `INITIATED` (new) transactions. | ||
```ts | ||
store.when().initiated(transaction => { | ||
// a new transaction has been initiated. | ||
}); | ||
``` | ||
### 13.10.0 | ||
#### (googleplay) Add "isConsumed" to consumed transactions | ||
@@ -6,0 +24,0 @@ |
@@ -6,2 +6,3 @@ namespace CdvPurchase | ||
export interface StoreAdapterDelegate { | ||
initiatedCallbacks: Callbacks<Transaction>; | ||
approvedCallbacks: Callbacks<Transaction>; | ||
@@ -116,3 +117,7 @@ pendingCallbacks: Callbacks<Transaction>; | ||
else if (lastState !== transaction.state) { | ||
if (transaction.state === TransactionState.FINISHED) { | ||
if (transaction.state === TransactionState.INITIATED) { | ||
this.delegate.initiatedCallbacks.trigger(transaction, 'adapterListener_receiptsUpdated_initiated'); | ||
this.lastCallTimeForState[tokenWithState] = now; | ||
} | ||
else if (transaction.state === TransactionState.FINISHED) { | ||
this.delegate.finishedCallbacks.trigger(transaction, 'adapterListener_receiptsUpdated_finished'); | ||
@@ -119,0 +124,0 @@ this.lastCallTimeForState[tokenWithState] = now; |
@@ -107,2 +107,5 @@ namespace CdvPurchase | ||
async initialize(platforms: (Platform | PlatformWithOptions)[], context: AdapterContext): Promise<IError[]> { | ||
if (typeof platforms === 'string') { | ||
platforms = [platforms]; | ||
} | ||
const newPlatforms = platforms.map(p => typeof p === 'string' ? { platform: p } : p).filter(p => !this.find(p.platform)) as PlatformWithOptions[]; | ||
@@ -109,0 +112,0 @@ const log = context.log.child('Adapters'); |
@@ -15,6 +15,6 @@ /// <reference path="../../receipt.ts" /> | ||
this.nativePurchase = purchase; | ||
this.refresh(purchase); | ||
this.refresh(purchase, true); | ||
} | ||
static toState(state: Bridge.PurchaseState, isAcknowledged: boolean, isConsumed: boolean): TransactionState { | ||
static toState(fromConstructor: boolean, state: Bridge.PurchaseState, isAcknowledged: boolean, isConsumed: boolean): TransactionState { | ||
switch(state) { | ||
@@ -28,2 +28,6 @@ case Bridge.PurchaseState.PENDING: | ||
return TransactionState.FINISHED; | ||
else if (isAcknowledged) | ||
return TransactionState.APPROVED; | ||
else if (fromConstructor) | ||
return TransactionState.INITIATED; | ||
else | ||
@@ -39,3 +43,3 @@ return TransactionState.APPROVED; | ||
*/ | ||
refresh(purchase: Bridge.Purchase) { | ||
refresh(purchase: Bridge.Purchase, fromConstructor?: boolean) { | ||
this.nativePurchase = purchase; | ||
@@ -50,3 +54,3 @@ this.transactionId = `${purchase.orderId || purchase.purchaseToken}`; | ||
if (typeof purchase.autoRenewing !== 'undefined') this.renewalIntent = purchase.autoRenewing ? RenewalIntent.RENEW : RenewalIntent.LAPSE; | ||
this.state = Transaction.toState(purchase.getPurchaseState, this.isAcknowledged ?? false, this.isConsumed ?? false); | ||
this.state = Transaction.toState(fromConstructor ?? false, purchase.getPurchaseState, this.isAcknowledged ?? false, this.isConsumed ?? false); | ||
} | ||
@@ -295,2 +299,9 @@ } | ||
this.context.listener.receiptsUpdated(Platform.GOOGLE_PLAY, [newReceipt]); | ||
if (newReceipt.transactions[0].state === TransactionState.INITIATED && !newReceipt.transactions[0].isPending) { | ||
// For compatibility, we set the state of "new" purchases to initiated from the constructor, | ||
// they'll got to "approved" when refreshed. | ||
// this way, users receive the "initiated" event, then "approved" | ||
newReceipt.refreshPurchase(purchase); | ||
this.context.listener.receiptsUpdated(Platform.GOOGLE_PLAY, [newReceipt]); | ||
} | ||
} | ||
@@ -297,0 +308,0 @@ }); |
@@ -35,3 +35,3 @@ /// <reference path="types.ts" /> | ||
*/ | ||
export const PLUGIN_VERSION = '13.10.0'; | ||
export const PLUGIN_VERSION = '13.10.1'; | ||
@@ -153,2 +153,5 @@ /** | ||
/** Callbacks when a transaction is initiated */ | ||
private initiatedCallbacks = new Internal.Callbacks<Transaction>(this.log, 'initiated()'); | ||
/** Callbacks when a transaction has been approved */ | ||
@@ -192,2 +195,3 @@ private approvedCallbacks = new Internal.Callbacks<Transaction>(this.log, 'approved()'); | ||
updatedReceiptCallbacks: this.updatedReceiptsCallbacks, | ||
initiatedCallbacks: this.initiatedCallbacks, | ||
approvedCallbacks: this.approvedCallbacks, | ||
@@ -270,3 +274,3 @@ finishedCallbacks: this.finishedCallbacks, | ||
} | ||
this.log.info('initialize()'); | ||
this.log.info('initialize(' + JSON.stringify(platforms) + ') v' + PLUGIN_VERSION); | ||
this.initializedHasBeenCalled = true; | ||
@@ -362,2 +366,3 @@ this.lastUpdate = +new Date(); | ||
approved: (cb: Callback<Transaction>, callbackName?: string) => (this.approvedCallbacks.push(cb, callbackName), ret), | ||
initiated: (cb: Callback<Transaction>, callbackName?: string) => (this.initiatedCallbacks.push(cb, callbackName), ret), | ||
pending: (cb: Callback<Transaction>, callbackName?: string) => (this.pendingCallbacks.push(cb, callbackName), ret), | ||
@@ -364,0 +369,0 @@ finished: (cb: Callback<Transaction>, callbackName?: string) => (this.finishedCallbacks.push(cb, callbackName), ret), |
@@ -262,3 +262,9 @@ /// <reference path="store.ts" /> | ||
/** Possible states of a product */ | ||
/** | ||
* Possible states of a transaction. | ||
* | ||
* ``` | ||
* INITIATED → PENDING (optional) → APPROVED → FINISHED | ||
* ``` | ||
*/ | ||
export enum TransactionState { | ||
@@ -297,6 +303,9 @@ // REQUESTED = 'requested', | ||
/** Register a function called when transaction is approved. */ | ||
/** Register a function called when a transaction is initiated. */ | ||
initiated(cb: Callback<Transaction>, callbackName?: string): When; | ||
/** Register a function called when a transaction is approved. */ | ||
approved(cb: Callback<Transaction>, callbackName?: string): When; | ||
/** Register a function called when transaction is pending. */ | ||
/** Register a function called when a transaction is pending. */ | ||
pending(cb: Callback<Transaction>, callbackName?: string): When; | ||
@@ -303,0 +312,0 @@ |
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
1349732
23856