Skip to content

Commit

Permalink
v13.8.4
Browse files Browse the repository at this point in the history
  • Loading branch information
j3k0 committed Sep 27, 2023
1 parent 416de8f commit fadfae6
Show file tree
Hide file tree
Showing 8 changed files with 167 additions and 19 deletions.
38 changes: 38 additions & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,44 @@

## 13.8

### 13.8.4

#### Trim product titles on Google Play

Google Play returns the app name in parenthesis in product titles. The plugin
now automatically trims it from the app name.

This behavior can be disabled by setting:

```ts
CdvPurchase.GooglePlay.Adapter.trimProductTitles = false
```

#### Automatically re-validate just-expired subscriptions

The plugin will now monitor active subscripion purchases (as returned by a
receipt validation service) and re-validate the receipt automatically when the
subscription expires or renews.

You can customize the expiry monitor (which should rarely be needed):

```ts
// interval between checks in milliseconds
CdvPurchase.Internal.ExpiryMonitor.INTERVAL_MS = 10000; // default: 10s

// extra time before a subscription is considered expired (when re-validating
// too early, sometime the new transaction isn't available yet).
CdvPurchase.Internal.ExpiryMonitor.GRACE_PERIOD_MS = 10000; // default: 10s
```

#### Add expiry date to Test Adapter's subscription

The expiry date was missing from the test product:

```ts
CdvPurchase.Test.testProducts.PAID_SUBSCRIPTION
```

### 13.8.3

Fix npm package.
Expand Down
16 changes: 3 additions & 13 deletions api/modules/CdvPurchase.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,8 @@
# Namespace: CdvPurchase

Namespace for the cordova-plugin-purchase plugin.
The platform doesn't send notifications when a subscription expires.

All classes, enumerations and variables defined by the plugin are in this namespace.

Throughout the documentation, in order to keep examples readable, we omit the `CdvPurchase` prefix.

When you see, for example `ProductType.PAID_SUBSCRIPTION`, it refers to `CdvPurchase.ProductType.PAID_SUBSCRIPTION`.

In the files that interact with the plugin, I recommend creating those shortcuts (and more if needed):

```ts
const {store, ProductType, Platform, LogLevel} = CdvPurchase;
```
However this is useful, so let's do just that.

## Table of contents

Expand Down Expand Up @@ -153,7 +143,7 @@ ___

### PLUGIN\_VERSION

`Const` **PLUGIN\_VERSION**: ``"13.8.3"``
`Const` **PLUGIN\_VERSION**: ``"13.8.4"``

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.8.3",
"version": "13.8.4",
"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.8.3">
version="13.8.4">

<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 @@ -31,7 +31,7 @@ namespace CdvPurchase {
/**
* Current release number of the plugin.
*/
export const PLUGIN_VERSION = '13.8.3';
export const PLUGIN_VERSION = '13.8.4';

/**
* Entry class of the plugin.
Expand Down
40 changes: 39 additions & 1 deletion www/store.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -643,6 +643,42 @@ declare namespace CdvPurchase {
}
}
}
/**
* The platform doesn't send notifications when a subscription expires.
*
* However this is useful, so let's do just that.
*/
declare namespace CdvPurchase {
namespace Internal {
/** Data and callbacks to interface with the ExpiryMonitor */
interface ExpiryMonitorController {
verifiedReceipts: VerifiedReceipt[];
/** Called when a verified purchase expires */
onVerifiedPurchaseExpired(verifiedPurchase: VerifiedPurchase, receipt: VerifiedReceipt): void;
}
class ExpiryMonitor {
/** Time between */
static INTERVAL_MS: number;
static GRACE_PERIOD_MS: number;
/** controller */
controller: ExpiryMonitorController;
/** reference to the function that runs at a given interval */
interval?: number;
/** Track active verified purchases */
activePurchases: {
[transactionId: string]: true;
};
/** Track notified verified purchases */
notifiedPurchases: {
[transactionId: string]: true;
};
/** Track active local transactions */
/** Track notified local transactions */
constructor(controller: ExpiryMonitorController);
launch(): void;
}
}
}
/**
* Namespace for the cordova-plugin-purchase plugin.
*
Expand All @@ -662,7 +698,7 @@ declare namespace CdvPurchase {
/**
* Current release number of the plugin.
*/
const PLUGIN_VERSION = "13.8.3";
const PLUGIN_VERSION = "13.8.4";
/**
* Entry class of the plugin.
*/
Expand Down Expand Up @@ -777,6 +813,8 @@ declare namespace CdvPurchase {
private _validator;
/** Monitor state changes for transactions */
private transactionStateMonitors;
/** Monitor subscription expiry */
private expiryMonitor;
constructor();
/**
* Register a product.
Expand Down
84 changes: 83 additions & 1 deletion www/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -1161,6 +1161,76 @@ var CdvPurchase;
Internal.ReceiptsMonitor = ReceiptsMonitor;
})(Internal = CdvPurchase.Internal || (CdvPurchase.Internal = {}));
})(CdvPurchase || (CdvPurchase = {}));
/**
* The platform doesn't send notifications when a subscription expires.
*
* However this is useful, so let's do just that.
*/
var CdvPurchase;
(function (CdvPurchase) {
let Internal;
(function (Internal) {
class ExpiryMonitor {
/** Track active local transactions */
// activeTransactions: {
// [transactionId: string]: true;
// } = {};
/** Track notified local transactions */
// notifiedTransactions: {
// [transactionId: string]: true;
// } = {};
constructor(controller) {
/** Track active verified purchases */
this.activePurchases = {};
/** Track notified verified purchases */
this.notifiedPurchases = {};
this.controller = controller;
}
launch() {
this.interval = setInterval(() => {
var _a;
const now = +new Date();
// Check for verified purchases expiry
for (const receipt of this.controller.verifiedReceipts) {
for (const purchase of receipt.collection) {
if (purchase.expiryDate) {
const expiryDate = purchase.expiryDate + ExpiryMonitor.GRACE_PERIOD_MS;
const transactionId = (_a = purchase.transactionId) !== null && _a !== void 0 ? _a : `${expiryDate}`;
if (expiryDate > now) {
this.activePurchases[transactionId] = true;
}
if (expiryDate < now && this.activePurchases[transactionId] && !this.notifiedPurchases[transactionId]) {
this.notifiedPurchases[transactionId] = true;
this.controller.onVerifiedPurchaseExpired(purchase, receipt);
}
}
}
}
// Check for local purchases expiry
// for (const receipt of this.controller.localReceipts) {
// for (const transaction of receipt.transactions) {
// if (transaction.expirationDate) {
// const expirationDate = +transaction.expirationDate + ExpiryMonitor.GRACE_PERIOD_MS;
// const transactionId = transaction.transactionId ?? `${expirationDate}`;
// if (expirationDate > now) {
// this.activeTransactions[transactionId] = true;
// }
// if (expirationDate < now && this.activeTransactions[transactionId] && !this.notifiedTransactions[transactionId]) {
// this.notifiedTransactions[transactionId] = true;
// this.controller.onTransactionExpired(transaction);
// }
// }
// }
// }
}, ExpiryMonitor.INTERVAL_MS);
}
}
/** Time between */
ExpiryMonitor.INTERVAL_MS = 10000;
ExpiryMonitor.GRACE_PERIOD_MS = 10000;
Internal.ExpiryMonitor = ExpiryMonitor;
})(Internal = CdvPurchase.Internal || (CdvPurchase.Internal = {}));
})(CdvPurchase || (CdvPurchase = {}));
/// <reference path="types.ts" />
/// <reference path="utils/compatibility.ts" />
/// <reference path="validator/validator.ts" />
Expand All @@ -1172,6 +1242,7 @@ var CdvPurchase;
/// <reference path="internal/register.ts" />
/// <reference path="internal/transaction-monitor.ts" />
/// <reference path="internal/receipts-monitor.ts" />
/// <reference path="internal/expiry-monitor.ts" />
/**
* Namespace for the cordova-plugin-purchase plugin.
*
Expand All @@ -1192,7 +1263,7 @@ var CdvPurchase;
/**
* Current release number of the plugin.
*/
CdvPurchase.PLUGIN_VERSION = '13.8.3';
CdvPurchase.PLUGIN_VERSION = '13.8.4';
/**
* Entry class of the plugin.
*/
Expand Down Expand Up @@ -1289,6 +1360,17 @@ var CdvPurchase;
receiptsVerified: () => { store.receiptsVerifiedCallbacks.trigger(); },
log: this.log,
}).launch();
this.expiryMonitor = new CdvPurchase.Internal.ExpiryMonitor({
// get localReceipts() { return store.localReceipts; },
get verifiedReceipts() { return store.verifiedReceipts; },
// onTransactionExpired(transaction) {
// store.approvedCallbacks.trigger(transaction);
// },
onVerifiedPurchaseExpired(verifiedPurchase, receipt) {
store.verify(receipt.sourceReceipt);
},
});
this.expiryMonitor.launch();
}
/**
* Retrieve a platform adapter.
Expand Down

0 comments on commit fadfae6

Please sign in to comment.