-
-
Notifications
You must be signed in to change notification settings - Fork 13
Open
Description
I have a situation where I offer two subscriptions and an additional "lifetime" subscription (which is really an in-app purchase, consumable). I may easily be mistaken, but the way the plugin implementation is designed, you can't really offer both subs and purchases because of an overwrite of _fetchedItems
when calling both fetchSubscriptions
and fetchItems
consecutively?
My very hacky workaround is to:
fetchSubscriptions
where I normally would- Call a separate method, like
loadAll()
after that:
async loadAll() {
await this.waitForSubscriptions();
fetchItems(["com.nativescript.whatever.item]);
}
- This will
await
subscriptions being loaded andwaitForSubscriptions
returns a promise when there is something in the array (yeah this isn't perfect):
waitForSubscriptions(): Promise<void> {
return new Promise<void>((resolve) => {
const check = setInterval(() => {
if (this._fetchedSubscriptions.length > 0) {
clearInterval(check);
resolve(); // now valid, since T is void
}
}, 500);
});
}
- After subscriptions are confirmed, then call
fetchItems
(see step 2). - Finally merge the two arrays:
if (this._fetchedSubscriptions.length > 0 && this._fetchedProducts.length > 0) {
this._fetchedItems = [
...this._fetchedSubscriptions,
...this._fetchedProducts,
];
console.log('Fetched subscription items:', this._fetchedItems);
}
It's a little more complicated than this and I'd be happy to share my full code if anyone is curious.
Metadata
Metadata
Assignees
Labels
No labels