react-native-iap icon indicating copy to clipboard operation
react-native-iap copied to clipboard

Which base plan selected and renewal problems.

Open darimuhittinhey opened this issue 8 months ago • 0 comments

Description

I have 2 base plans in my google play console. I can fetch them and they are like this :

image

and i have a purchase updated listener like this :

image

and this is what is passed to my purchaseIUpdatedListener when i subscribe something :

image

QUESTION ONE : There is no information about which base plan that i subscribed. If i need to inform backend about the subscription i need these data right ? I can take which base plan is subscribed myself from the selected plan in the beginning of subscribe operation but this is not safe cuz documentation says purchaseIUpdatedListener can be called any time , for example app crushes and after user reopens the app or something else.

QUESTION TWO : And assuming that question one is solved, the second problem is purchaseUpdatedListener doesnt called when a renewal happens. Because of that i can't be informed about the renewal and backend doesnt know if a renewal happened. In #1202 @henrik-d says :

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!

and adds:

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());
      }
    }
  }

but the object returned from getAvailablePurchases looks like this :

image

again, there is no information about which base plan it is and more, the transactionDate is the date of the first subscription operation not the date that renewal happened. And plus, there is no expiration date. If you think that i have to check all of this on the backend please tell me how ? Is there libraries or apis of Google Play and StoreKit to check and validate the transaction or something else ?

and i assume this problem is solved too again and another question arises in my mind:

QUESTION THREE: I have one Google Play account. I subscribed one plan with my in app account. I informed my backend about subscription. I logged out from my application account and logged in another in app account. Then if i check every start mentioned in above using getAvailablePurchases(), the getAvailablePurchases() returns the subscription and i send it to my backend again to validate and it validates because it is a valid transaction ? So this user can have unlimited subscribed in-app accounts only with one subscription ? How to avoid this ?

Environment:

  • react-native-iap: "^11.0.0-rc.7"
  • react-native: "0.70.6"
  • Platforms : Android - Real device

darimuhittinhey avatar Oct 23 '23 07:10 darimuhittinhey