I'm making a mobile app in Unity. I have successfully set up a subscription in Google Play and PlayFab so that Android users can sign up for it through Unity IAP, and their receipt is validated so they get the membership in PlayFab. Great!
For testing purposes, Google's subscriptions renew every 5 minutes. At the end of the renewal period, Google "bills" me again. However, the subscription lapses in PlayFab! How do I get the billing info from Google, and give it to PlayFab so the subscription stays active?
Thanks,
Ryan
Answer by Brendan · May 22, 2020 at 07:28 PM
If you check the instructions sent when you were added to the beta, this is the relevant section:
"Today, PlayFab does not manage the auto renewable of these subscriptions. The client must validate new receipts for renewals with PlayFab. Both Apple and Google support re-validating the same original receipt multiple times for updates to the subscriptions. Additionally, the client can check for new transactions on login, and if there any new ones, validate them with PlayFab. Subscriptions also cannot be transferred between players (except in the case of iOS refresh receipts). That is, the first player to validate a subscription will be the sole player who is allowed to update that subscription. However, PlayFab provides customer support an explicit override to the expiration time on memberships, so that players in bad states can be manually adjusted. This override can be set via game manager, or using the API."
So, to process renewal, you need to re-submit the receipt from the client.
Answer by ryan-3 · May 25, 2020 at 06:03 AM
@Brendan Right. My confusion stems from this part: "The client must validate new receipts for renewals with PlayFab. Both Apple and Google support re-validating the same original receipt multiple times for updates to the subscriptions. Additionally, the client can check for new transactions on login, and if there any new ones, validate them with PlayFab."
Just to confirm, for guidance on getting updates for the original receipt, and checking for new transactions at login, I should be looking in the Google Play documentation?
Answer by ryan-3 · May 28, 2020 at 03:08 AM
Got it working now! Here's what I needed specifically, in case anyone else finds the process opaque:
1) I followed PlayFab's Getting Started w/ Unity Android Guide here:
https://docs.microsoft.com/en-us/gaming/playfab/features/commerce/economy/getting-started-with-unity-iap-android
You can use the same BuyProductID function for normal IAP one-time purchases as well as subscriptions. However, when using it for a subscription, you'll want to:
2) Edit the ProcessPurchase function so that it saves e.purchasedProduct. Since this is a Unity class, I made my own JSON wrapper with fields that match up to it. You can store this locally on the device, but I recommend using Player Data so auto renewal can occur from any device the account signs into.
3) In order to check whether a user has a membership, use GetPlayerProfile with ShowMemberships=true. Make sure you also give clients permission to view that; they don't have it by default. Make this call whenever is most reasonable for you (I chose on login and on purchase), and you can search the returned profile for a membership ID to see when it expires (and thus decide whether or not they get membership benefits at runtime).
4) Finally, if the membership has expired, you can "auto renew" by calling ValidateGooglePlayPurchase again, passing in the purchasedProduct you saved in step 2. This is what "re-validating the same original receipt multiple times" means in (in my opinion) clearer terms.
Facebook Canvas Async Payment error states 2 Answers
Facebook Purchase Items scrape as og:type="website" 2 Answers
iOS Reciept Validation Failed - Request Timeout 16 Answers
Store with random items 1 Answer