Is purchaseUpdatedListener called again, when a subscription is renewed? If not, what is the best way to detect this event, when not using server notifications?
@henrik-d did you figure this out already? I am asking myself the same question
My observation was that purchaseUpdatedListener as called on the next app-start after a renewal, but only on iOS! So that was not a solution for us. Instead we check the status of the subscription on every app start manually, by validating the receipt again with our server. That way we get the latest information about expiryDate etc.
Hope this helps!
@henrik-d That definitely helps! Thank you!
I have done some more research and it seems that the official way to achieve this is to use server-notifications: https://developer.apple.com/documentation/appstoreservernotifications
have you had experiences with this? @henrik-d
Using server notifications is definitely the more robust way to implement this. We decided against it, because it seems very complicated, especially when you need support for iOS and Android. It might be worth to check out https://www.iaphub.com/ or https://www.revenuecat.com/ which take the heavy lifting for you.
Thanks for confirming!
If anyone is using Laravel, this seems to be the best package that handles all of the server notifications and receipt validation stuff: https://github.com/imdhemy/laravel-in-app-purchases
@henrik-d how exactly did you handle the renewal for android an ios on startup? Just fetch the receipt for iOS and token for android and then send it to the backend?
@kayamy Yes, here is the basic function:
private async checkForSubscriptionUpdates() {
// check if user was subscribed (information is stored in redux store)
if (!this.isUserSubscribed()) return;
if (Platform.OS === 'ios') {
const receipt = await IAP.getReceiptIOS();
await this.processReceipt(receipt);
}
if (Platform.OS === 'android') {
const subscriptionPurchase = await this.getMostRecentSubscriptionPurchase(); // uses IAP.getAvailablePurchases()
if (subscriptionPurchase) {
await this.processReceipt(subscriptionPurchase.transactionReceipt);
} else {
await this.store.dispatch(user.actions.revokeProSubscription());
}
}
}
processReceipt() sends the receipt to the server to check if the subscription is still active.
@henrik-d thanks! I'm guessing you keep track of the subscription status serverside?
@kayamy As stated early, keeping track on the server using server notifications is the more robust solutions, but also way more complicated to implement. We only check the subscription status on the client side.
You need to validate receipt in order to do this progress which is recommended to handle in the server-side.