Skip to content

Commit

Permalink
13.10.1
Browse files Browse the repository at this point in the history
  • Loading branch information
j3k0 committed Jan 19, 2024
1 parent b783a53 commit 09253c5
Show file tree
Hide file tree
Showing 12 changed files with 115 additions and 26 deletions.
20 changes: 19 additions & 1 deletion RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,24 @@
# 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

Expand Down
6 changes: 4 additions & 2 deletions api/classes/CdvPurchase.GooglePlay.Transaction.md
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ ___

### refresh

**refresh**(`purchase`): `void`
**refresh**(`purchase`, `fromConstructor?`): `void`

Refresh the value in the transaction based on the native purchase update

Expand All @@ -315,6 +315,7 @@ Refresh the value in the transaction based on the native purchase update
| Name | Type |
| :------ | :------ |
| `purchase` | [`Purchase`](../interfaces/CdvPurchase.GooglePlay.Bridge.Purchase.md) |
| `fromConstructor?` | `boolean` |

#### Returns

Expand Down Expand Up @@ -351,12 +352,13 @@ ___

### toState

`Static` **toState**(`state`, `isAcknowledged`, `isConsumed`): [`TransactionState`](../enums/CdvPurchase.TransactionState.md)
`Static` **toState**(`fromConstructor`, `state`, `isAcknowledged`, `isConsumed`): [`TransactionState`](../enums/CdvPurchase.TransactionState.md)

#### Parameters

| Name | Type |
| :------ | :------ |
| `fromConstructor` | `boolean` |
| `state` | [`PurchaseState`](../enums/CdvPurchase.GooglePlay.Bridge.PurchaseState.md) |
| `isAcknowledged` | `boolean` |
| `isConsumed` | `boolean` |
Expand Down
6 changes: 5 additions & 1 deletion api/enums/CdvPurchase.TransactionState.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@

[CdvPurchase](../modules/CdvPurchase.md).TransactionState

Possible states of a product
Possible states of a transaction.

```
INITIATED → PENDING (optional) → APPROVED → FINISHED
```

## Table of contents

Expand Down
24 changes: 22 additions & 2 deletions api/interfaces/CdvPurchase.When.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Store events listener

- [approved](CdvPurchase.When.md#approved)
- [finished](CdvPurchase.When.md#finished)
- [initiated](CdvPurchase.When.md#initiated)
- [pending](CdvPurchase.When.md#pending)
- [productUpdated](CdvPurchase.When.md#productupdated)
- [receiptUpdated](CdvPurchase.When.md#receiptupdated)
Expand All @@ -25,7 +26,7 @@ Store events listener

**approved**(`cb`, `callbackName?`): [`When`](CdvPurchase.When.md)

Register a function called when transaction is approved.
Register a function called when a transaction is approved.

#### Parameters

Expand Down Expand Up @@ -59,11 +60,30 @@ Register a function called when a transaction is finished.

___

### initiated

**initiated**(`cb`, `callbackName?`): [`When`](CdvPurchase.When.md)

Register a function called when a transaction is initiated.

#### Parameters

| Name | Type |
| :------ | :------ |
| `cb` | [`Callback`](../modules/CdvPurchase.md#callback)<[`Transaction`](../classes/CdvPurchase.Transaction.md)\> |
| `callbackName?` | `string` |

#### Returns

[`When`](CdvPurchase.When.md)

___

### pending

**pending**(`cb`, `callbackName?`): [`When`](CdvPurchase.When.md)

Register a function called when transaction is pending.
Register a function called when a transaction is pending.

#### Parameters

Expand Down
2 changes: 1 addition & 1 deletion api/modules/CdvPurchase.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ ___

### PLUGIN\_VERSION

`Const` **PLUGIN\_VERSION**: ``"13.10.0"``
`Const` **PLUGIN\_VERSION**: ``"13.10.1"``

Current release number of the plugin.

Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cordova-plugin-purchase",
"version": "13.10.0",
"version": "13.10.1",
"description": "Cordova Purchase plugin for iOS, Android, Windows (AppStore, Play, UWP)",
"cordova": {
"id": "cordova-plugin-purchase",
Expand Down
2 changes: 1 addition & 1 deletion plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ SOFTWARE.
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
id="cordova-plugin-purchase"
xmlns:android="http://schemas.android.com/apk/res/android"
version="13.10.0">
version="13.10.1">

<name>Purchase</name>
<description>Cordova Purchase plugin for iOS (AppStore), Android (PlayStore) and Windows</description>
Expand Down
2 changes: 1 addition & 1 deletion src/ts/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ namespace CdvPurchase {
/**
* Current release number of the plugin.
*/
export const PLUGIN_VERSION = '13.10.0';
export const PLUGIN_VERSION = '13.10.1';

/**
* Entry class of the plugin.
Expand Down
8 changes: 7 additions & 1 deletion src/ts/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,13 @@ namespace CdvPurchase {
*/
export type PlatformFunctionality = 'requestPayment' | 'order' | 'manageSubscriptions' | 'manageBilling';

/** Possible states of a product */
/**
* Possible states of a transaction.
*
* ```
* INITIATED → PENDING (optional) → APPROVED → FINISHED
* ```
*/
export enum TransactionState {
// REQUESTED = 'requested',
INITIATED = 'initiated',
Expand Down
23 changes: 17 additions & 6 deletions www/store.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,7 @@ declare namespace CdvPurchase {
declare namespace CdvPurchase {
namespace Internal {
interface StoreAdapterDelegate {
initiatedCallbacks: Callbacks<Transaction>;
approvedCallbacks: Callbacks<Transaction>;
pendingCallbacks: Callbacks<Transaction>;
finishedCallbacks: Callbacks<Transaction>;
Expand Down Expand Up @@ -740,7 +741,7 @@ declare namespace CdvPurchase {
/**
* Current release number of the plugin.
*/
const PLUGIN_VERSION = "13.10.0";
const PLUGIN_VERSION = "13.10.1";
/**
* Entry class of the plugin.
*/
Expand Down Expand Up @@ -835,6 +836,8 @@ declare namespace CdvPurchase {
/** Callback when a receipt was updated */
private updatedReceiptsCallbacks;
/** Callbacks when a product is owned */
/** Callbacks when a transaction is initiated */
private initiatedCallbacks;
/** Callbacks when a transaction has been approved */
private approvedCallbacks;
/** Callbacks when a transaction has been finished */
Expand Down Expand Up @@ -1292,7 +1295,13 @@ declare namespace CdvPurchase {
* @see {@link Store.checkSupport}
*/
type PlatformFunctionality = 'requestPayment' | 'order' | 'manageSubscriptions' | 'manageBilling';
/** Possible states of a product */
/**
* Possible states of a transaction.
*
* ```
* INITIATED → PENDING (optional) → APPROVED → FINISHED
* ```
*/
enum TransactionState {
INITIATED = "initiated",
PENDING = "pending",
Expand All @@ -1314,9 +1323,11 @@ declare namespace CdvPurchase {
receiptUpdated(cb: Callback<Receipt>, callbackName?: string): When;
/** Register a function called when a product is updated. */
productUpdated(cb: Callback<Product>, callbackName?: string): When;
/** 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;
/** Register a function called when a transaction is finished. */
finished(cb: Callback<Transaction>, callbackName?: string): When;
Expand Down Expand Up @@ -4135,11 +4146,11 @@ declare namespace CdvPurchase {
class Transaction extends CdvPurchase.Transaction {
nativePurchase: Bridge.Purchase;
constructor(purchase: Bridge.Purchase, parentReceipt: Receipt, decorator: Internal.TransactionDecorator);
static toState(state: Bridge.PurchaseState, isAcknowledged: boolean, isConsumed: boolean): TransactionState;
static toState(fromConstructor: boolean, state: Bridge.PurchaseState, isAcknowledged: boolean, isConsumed: boolean): TransactionState;
/**
* Refresh the value in the transaction based on the native purchase update
*/
refresh(purchase: Bridge.Purchase): void;
refresh(purchase: Bridge.Purchase, fromConstructor?: boolean): void;
}
class Receipt extends CdvPurchase.Receipt {
/** Token that uniquely identifies a purchase for a given item and user pair. */
Expand Down
44 changes: 36 additions & 8 deletions www/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -804,6 +804,9 @@ var CdvPurchase;
*/
initialize(platforms, context) {
return __awaiter(this, void 0, void 0, function* () {
if (typeof platforms === 'string') {
platforms = [platforms];
}
const newPlatforms = platforms.map(p => typeof p === 'string' ? { platform: p } : p).filter(p => !this.find(p.platform));
const log = context.log.child('Adapters');
log.info("Adding platforms: " + JSON.stringify(newPlatforms));
Expand Down Expand Up @@ -964,7 +967,11 @@ var CdvPurchase;
}
}
else if (lastState !== transaction.state) {
if (transaction.state === CdvPurchase.TransactionState.FINISHED) {
if (transaction.state === CdvPurchase.TransactionState.INITIATED) {
this.delegate.initiatedCallbacks.trigger(transaction, 'adapterListener_receiptsUpdated_initiated');
this.lastCallTimeForState[tokenWithState] = now;
}
else if (transaction.state === CdvPurchase.TransactionState.FINISHED) {
this.delegate.finishedCallbacks.trigger(transaction, 'adapterListener_receiptsUpdated_finished');
this.lastCallTimeForState[tokenWithState] = now;
}
Expand Down Expand Up @@ -1339,7 +1346,7 @@ var CdvPurchase;
/**
* Current release number of the plugin.
*/
CdvPurchase.PLUGIN_VERSION = '13.10.0';
CdvPurchase.PLUGIN_VERSION = '13.10.1';
/**
* Entry class of the plugin.
*/
Expand Down Expand Up @@ -1379,6 +1386,8 @@ var CdvPurchase;
this.updatedReceiptsCallbacks = new CdvPurchase.Internal.Callbacks(this.log, 'receiptUpdated()');
/** Callbacks when a product is owned */
// private ownedCallbacks = new Callbacks<Product>();
/** Callbacks when a transaction is initiated */
this.initiatedCallbacks = new CdvPurchase.Internal.Callbacks(this.log, 'initiated()');
/** Callbacks when a transaction has been approved */
this.approvedCallbacks = new CdvPurchase.Internal.Callbacks(this.log, 'approved()');
/** Callbacks when a transaction has been finished */
Expand Down Expand Up @@ -1410,6 +1419,7 @@ var CdvPurchase;
this.listener = new CdvPurchase.Internal.StoreAdapterListener({
updatedCallbacks: this.updatedCallbacks,
updatedReceiptCallbacks: this.updatedReceiptsCallbacks,
initiatedCallbacks: this.initiatedCallbacks,
approvedCallbacks: this.approvedCallbacks,
finishedCallbacks: this.finishedCallbacks,
pendingCallbacks: this.pendingCallbacks,
Expand Down Expand Up @@ -1502,7 +1512,7 @@ var CdvPurchase;
this.log.warn('store.initialized() has been called already.');
return [];
}
this.log.info('initialize()');
this.log.info('initialize(' + JSON.stringify(platforms) + ') v' + CdvPurchase.PLUGIN_VERSION);
this.initializedHasBeenCalled = true;
this.lastUpdate = +new Date();
const store = this;
Expand Down Expand Up @@ -1585,6 +1595,7 @@ var CdvPurchase;
updated: (cb, callbackName) => (this.updatedCallbacks.push(cb, callbackName), this.updatedReceiptsCallbacks.push(cb, callbackName), ret),
// owned: (cb: Callback<Product>) => (this.ownedCallbacks.push(cb), ret),
approved: (cb, callbackName) => (this.approvedCallbacks.push(cb, callbackName), ret),
initiated: (cb, callbackName) => (this.initiatedCallbacks.push(cb, callbackName), ret),
pending: (cb, callbackName) => (this.pendingCallbacks.push(cb, callbackName), ret),
finished: (cb, callbackName) => (this.finishedCallbacks.push(cb, callbackName), ret),
verified: (cb, callbackName) => (this.verifiedCallbacks.push(cb, callbackName), ret),
Expand Down Expand Up @@ -2006,7 +2017,13 @@ var CdvPurchase;
/** Test platform */
Platform["TEST"] = "test";
})(Platform = CdvPurchase.Platform || (CdvPurchase.Platform = {}));
/** Possible states of a product */
/**
* Possible states of a transaction.
*
* ```
* INITIATED → PENDING (optional) → APPROVED → FINISHED
* ```
*/
let TransactionState;
(function (TransactionState) {
// REQUESTED = 'requested',
Expand Down Expand Up @@ -4723,9 +4740,9 @@ var CdvPurchase;
constructor(purchase, parentReceipt, decorator) {
super(CdvPurchase.Platform.GOOGLE_PLAY, parentReceipt, decorator);
this.nativePurchase = purchase;
this.refresh(purchase);
this.refresh(purchase, true);
}
static toState(state, isAcknowledged, isConsumed) {
static toState(fromConstructor, state, isAcknowledged, isConsumed) {
switch (state) {
case GooglePlay.Bridge.PurchaseState.PENDING:
return CdvPurchase.TransactionState.INITIATED;
Expand All @@ -4734,6 +4751,10 @@ var CdvPurchase;
// so we don't return APPROVED
if (isConsumed)
return CdvPurchase.TransactionState.FINISHED;
else if (isAcknowledged)
return CdvPurchase.TransactionState.APPROVED;
else if (fromConstructor)
return CdvPurchase.TransactionState.INITIATED;
else
return CdvPurchase.TransactionState.APPROVED;
case GooglePlay.Bridge.PurchaseState.UNSPECIFIED_STATE:
Expand All @@ -4743,7 +4764,7 @@ var CdvPurchase;
/**
* Refresh the value in the transaction based on the native purchase update
*/
refresh(purchase) {
refresh(purchase, fromConstructor) {
var _a, _b;
this.nativePurchase = purchase;
this.transactionId = `${purchase.orderId || purchase.purchaseToken}`;
Expand All @@ -4758,7 +4779,7 @@ var CdvPurchase;
this.isConsumed = purchase.consumed;
if (typeof purchase.autoRenewing !== 'undefined')
this.renewalIntent = purchase.autoRenewing ? CdvPurchase.RenewalIntent.RENEW : CdvPurchase.RenewalIntent.LAPSE;
this.state = Transaction.toState(purchase.getPurchaseState, (_a = this.isAcknowledged) !== null && _a !== void 0 ? _a : false, (_b = this.isConsumed) !== null && _b !== void 0 ? _b : false);
this.state = Transaction.toState(fromConstructor !== null && fromConstructor !== void 0 ? fromConstructor : false, purchase.getPurchaseState, (_a = this.isAcknowledged) !== null && _a !== void 0 ? _a : false, (_b = this.isConsumed) !== null && _b !== void 0 ? _b : false);
}
}
GooglePlay.Transaction = Transaction;
Expand Down Expand Up @@ -4949,6 +4970,13 @@ var CdvPurchase;
const newReceipt = new Receipt(purchase, this.context.apiDecorators);
this.receipts.push(newReceipt);
this.context.listener.receiptsUpdated(CdvPurchase.Platform.GOOGLE_PLAY, [newReceipt]);
if (newReceipt.transactions[0].state === CdvPurchase.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(CdvPurchase.Platform.GOOGLE_PLAY, [newReceipt]);
}
}
});
}
Expand Down

0 comments on commit 09253c5

Please sign in to comment.