tikhop / TPInAppReceipt

Reading and Validating In App Purchase Receipt Locally.
MIT License
630 stars 93 forks source link

Library says NOT eligible after resetting introductory offer eligibility for sandbox user #111

Closed KevinQuisquater closed 6 months ago

KevinQuisquater commented 1 year ago

(Amazing library, thank you)

Expected Behavior

After resetting the eligibility for introductory offers of a sandbox user, the library should say that the user is eligible for that introductory offer. We have tried refreshing the receipt, deleting the purchase history of the sandbox user, and deleting and re-installing the app.

Current Behavior

TPInAppReceipt still says a sandbox user is not eligible for introductory offer after resetting the introductory offer eligibility of a sandbox user via the Settings app or via App Store Connect.

This is probably not a problem in production since a user can't reset their eligibility for introductory offers. But it makes testing the library difficult.

Possible Solution

Should work in production, since eligibility can only be reset for a sandbox user.

Steps to Reproduce (for bugs)

With a sandbox user:

  1. With the library, test the introductory offer eligibility for a product that has a free trial (for instance). The library correctly returns that the user is eligible for the introductory offer of the product.
  2. Start a free trial for that product with the sandbox user.
  3. Check eligibility again. The library correctly returns false.
  4. Cancel the subscription and let it expire (just in case).
  5. In the phone Settings > App Store > Sandbox User > Manage > Subscriptions > Reset eligibility
  6. Check eligibility again. The library correctly still returns false, despite the free trial being available if you try and purchase the product again
  7. Try deleting the purchase history of the sandbox user from App Store Connect.
  8. Try deleting and re-installing the app from Xcode.

Your Environment

Big thanks in advance!

KevinQuisquater commented 1 year ago

Found several people with the same issue, so it might not be linked to the library but be a StoreKit bug! https://developer.apple.com/forums/thread/707319 https://developer.apple.com/forums/thread/716661 https://community.revenuecat.com/sdks-51/question-about-storekit2-iseligibleforintrooffer-testing-with-sandbox-users-1623

They use StoreKit 2, and 9 months ago an engineer commented (second link) that the problem should now be fixed.

tikhop commented 1 year ago

Hello @KevinQuisquater, thanks for bringing this up, and my apologies for the delayed response.

You are absolutely right, it's a "bug/feature" within the StoreKit framework. When a user calls InAppReceipt.isEligibleForIntroductoryOffer, the library simply goes thru the local receipt to determine whether the introductory offer has been used. The inherent nature of the in-app receipt is that it's an immutable collection of purchases. It appears that when you perform 'Reset eligibility,' it doesn't actually clear the receipt itself. As a result, the library indicates 'true,' regardless of whether the eligibility has been reset.

Once again, I appreciate your input and your kind words. I'm glad to know that you find this library helpful.

KevinQuisquater commented 1 year ago

Thank you very much for taking the time to look into it and answer! We will test using StoreKit2 to see if this is a StoreKit1 problem or a StoreKit problem.

(As the comment of the Apple Commerce Engineer on this post suggests that it might be fixed in StoreKit2: https://developer.apple.com/forums/thread/716661)

If you happen to know the answer, I'd love to know! Thank you.

tikhop commented 6 months ago

Hi @KevinQuisquater, I hope you're doing well.

Recently, I've been playing around with introductory offers and I was able to reproduce the issue you mentioned. However, as soon as I refreshed the receipt for the sandbox user, the issue disappeared, and the library once again returned true.

I'm closing the issue, but if you have any other issues or questions, please feel free to open another ticket. Thank you!.

KevinQuisquater commented 6 months ago

Amazing discovery, thank you!