Skip to content

Commit

Permalink
v13.3.1
Browse files Browse the repository at this point in the history
  • Loading branch information
j3k0 committed Feb 9, 2023
1 parent 84a2e86 commit 26a39b5
Show file tree
Hide file tree
Showing 8 changed files with 82 additions and 9 deletions.
28 changes: 28 additions & 0 deletions api/modules/CdvPurchase.AppleAppStore.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ Apple AppStore adapter using StoreKit version 1

- [DiscountEligibilityDeterminer](CdvPurchase.AppleAppStore.md#discounteligibilitydeterminer)
- [DiscountType](CdvPurchase.AppleAppStore.md#discounttype)
- [PaymentMonitor](CdvPurchase.AppleAppStore.md#paymentmonitor)
- [PaymentMonitorStatus](CdvPurchase.AppleAppStore.md#paymentmonitorstatus)
- [SKOfferType](CdvPurchase.AppleAppStore.md#skoffertype)

### Variables
Expand Down Expand Up @@ -68,6 +70,32 @@ ___

___

### PaymentMonitor

Ƭ **PaymentMonitor**: (`status`: [`PaymentMonitorStatus`](CdvPurchase.AppleAppStore.md#paymentmonitorstatus)) => `void`

#### Type declaration

▸ (`status`): `void`

##### Parameters

| Name | Type |
| :------ | :------ |
| `status` | [`PaymentMonitorStatus`](CdvPurchase.AppleAppStore.md#paymentmonitorstatus) |

##### Returns

`void`

___

### PaymentMonitorStatus

Ƭ **PaymentMonitorStatus**: ``"cancelled"`` \| ``"failed"`` \| ``"purchased"`` \| ``"deferred"``

___

### SKOfferType

Ƭ **SKOfferType**: [`DiscountType`](CdvPurchase.AppleAppStore.md#discounttype) \| ``"Default"``
Expand Down
2 changes: 1 addition & 1 deletion api/modules/CdvPurchase.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ ___

### PLUGIN\_VERSION

`Const` **PLUGIN\_VERSION**: ``"13.3.0"``
`Const` **PLUGIN\_VERSION**: ``"13.3.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.3.0",
"version": "13.3.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.3.0">
version="13.3.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 @@ -24,7 +24,7 @@ namespace CdvPurchase {
/**
* Current release number of the plugin.
*/
export const PLUGIN_VERSION = '13.3.0';
export const PLUGIN_VERSION = '13.3.1';

/**
* Entry class of the plugin.
Expand Down
7 changes: 6 additions & 1 deletion www/store.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@ declare namespace CdvPurchase {
/**
* Current release number of the plugin.
*/
const PLUGIN_VERSION = "13.3.0";
const PLUGIN_VERSION = "13.3.1";
/**
* Entry class of the plugin.
*/
Expand Down Expand Up @@ -2148,6 +2148,8 @@ declare namespace CdvPurchase {
* Apple AppStore adapter using StoreKit version 1
*/
namespace AppleAppStore {
type PaymentMonitorStatus = 'cancelled' | 'failed' | 'purchased' | 'deferred';
type PaymentMonitor = (status: PaymentMonitorStatus) => void;
/**
* Determine which discount the user is eligible to.
*
Expand Down Expand Up @@ -2234,6 +2236,9 @@ declare namespace CdvPurchase {
private receiptsUpdated;
/** Notify the store that the receipts have been updated */
private _receiptsUpdated;
private _paymentMonitor;
private setPaymentMonitor;
private callPaymentMonitor;
initialize(): Promise<IError | undefined>;
/** True iff the appStoreReceipt is already being initialized */
private _appStoreReceiptLoading;
Expand Down
46 changes: 43 additions & 3 deletions www/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -826,7 +826,7 @@ var CdvPurchase;
/**
* Current release number of the plugin.
*/
CdvPurchase.PLUGIN_VERSION = '13.3.0';
CdvPurchase.PLUGIN_VERSION = '13.3.1';
/**
* Entry class of the plugin.
*/
Expand Down Expand Up @@ -2136,6 +2136,7 @@ var CdvPurchase;
/** List of products loaded from AppStore */
this._products = [];
this.validProducts = {};
this._paymentMonitor = () => { };
/** True iff the appStoreReceipt is already being initialized */
this._appStoreReceiptLoading = false;
/** List of functions waiting for the appStoreReceipt to be initialized */
Expand Down Expand Up @@ -2233,6 +2234,12 @@ var CdvPurchase;
this.context.listener.receiptsUpdated(CdvPurchase.Platform.APPLE_APPSTORE, [this.pseudoReceipt]);
}
}
setPaymentMonitor(fn) {
this._paymentMonitor = fn;
}
callPaymentMonitor(status, code, message) {
this._paymentMonitor(status);
}
initialize() {
return new Promise(resolve => {
this.log.info('bridge.init');
Expand All @@ -2247,6 +2254,7 @@ var CdvPurchase;
// When the user closes the payment sheet, this generates a
// PAYMENT_CANCELLED error that isn't an error anymore since version 13
// of the plugin.
this.callPaymentMonitor('cancelled', CdvPurchase.ErrorCode.PAYMENT_CANCELLED, message);
return;
}
else {
Expand All @@ -2263,6 +2271,7 @@ var CdvPurchase;
transaction.refresh(productId, originalTransactionIdentifier, transactionDate, discountId);
this.removeTransactionInProgress(productId);
this.receiptsUpdated();
this.callPaymentMonitor('purchased');
},
purchaseEnqueued: async (productId, quantity) => {
this.log.info('purchaseEnqueued: ' + productId + ' - ' + quantity);
Expand All @@ -2274,6 +2283,7 @@ var CdvPurchase;
this.log.info('purchaseFailed: ' + productId + ' - ' + code + ' - ' + message);
this.removeTransactionInProgress(productId);
this.context.listener.receiptsUpdated(CdvPurchase.Platform.APPLE_APPSTORE, [this.pseudoReceipt]);
this.callPaymentMonitor('failed', code, message);
},
purchasing: async (productId) => {
// purchase has been requested, but there's no transactionIdentifier yet.
Expand All @@ -2289,6 +2299,7 @@ var CdvPurchase;
this.log.info('deferred: ' + productId);
await this.upsertTransactionInProgress(productId, CdvPurchase.TransactionState.PENDING);
this.context.listener.receiptsUpdated(CdvPurchase.Platform.APPLE_APPSTORE, [this.pseudoReceipt]);
this.callPaymentMonitor('deferred');
},
finished: async (transactionIdentifier, productId) => {
this.log.info('finish: ' + transactionIdentifier + ' - ' + productId);
Expand Down Expand Up @@ -2472,16 +2483,45 @@ var CdvPurchase;
});
}
async order(offer) {
let resolved = false;
return new Promise(resolve => {
const callResolve = (result) => {
if (resolved)
return;
this.setPaymentMonitor(() => { });
resolved = true;
resolve(result);
};
this.log.info('order');
const discountId = offer.id !== AppleAppStore.DEFAULT_OFFER_ID ? offer.id : undefined;
this.setPaymentMonitor((status, code, message) => {
this.log.info('order.paymentMonitor => ' + status + ' ' + (code !== null && code !== void 0 ? code : '') + ' ' + (message !== null && message !== void 0 ? message : ''));
if (resolved)
return;
switch (status) {
case 'cancelled':
callResolve(CdvPurchase.storeError(code !== null && code !== void 0 ? code : CdvPurchase.ErrorCode.PAYMENT_CANCELLED, message !== null && message !== void 0 ? message : 'The user cancelled the order.'));
break;
case 'failed':
// note, "failed" might be triggered before "cancelled",
// so we'll give some time to catch the "cancelled" event.
setTimeout(() => {
callResolve(CdvPurchase.storeError(code !== null && code !== void 0 ? code : CdvPurchase.ErrorCode.PURCHASE, message !== null && message !== void 0 ? message : 'Purchase failed'));
}, 500);
break;
case 'purchased':
case 'deferred':
callResolve(undefined);
break;
}
});
const success = () => {
this.log.info('order.success');
resolve(undefined);
// We'll monitor the payment before resolving.
};
const error = () => {
this.log.info('order.error');
resolve(CdvPurchase.storeError(CdvPurchase.ErrorCode.PURCHASE, 'Failed to place order'));
callResolve(CdvPurchase.storeError(CdvPurchase.ErrorCode.PURCHASE, 'Failed to place order'));
};
// When we switch AppStore user, the cached receipt isn't from the new user.
// so after a purchase, we want to make sure we're using the receipt from the logged in user.
Expand Down

0 comments on commit 26a39b5

Please sign in to comment.