question

Ozan Yilmaz avatar image
Ozan Yilmaz asked

How to handle cancel/renew subscriptions?

Hello everyone,

I'm trying to implement subscription logic in the game, but I couldn't find any way to handle cancel/renew subscriptions. Here's the things I've tried so far: (I'm using Unity and Unity IAP plugin)

I created an empty item in the catalog so that when a player purchases a subscription, I can give them an item and do some logic on PlayFab.

First purchase is made without a problem. I can see the item in the player's inventory and I can see the receipt in the Purchases menu. The problem is when the subscription renews itself, the receipt isn't renewed, which means I have the same receipt on the client side. When I send the receipt to PlayFab, I got this log:

        "Valid": true,
        "Error": "Receipt already used",

Receipt validation says that the receipt is already used, which is true. I can see the receipt in the Purchases menu.

At this point, I thought that maybe I can ignore the error and use "valid" value to check if the player's subscription is still active. Just to test this value, I canceled my subscription on Play Store and sent the same receipt to PlayFab. In the log, I got the same output. Valid value was true even though I canceled my subscription and it's expired, and the error message was same.

I have no idea how I can check if the player still has a valid receipt. There is a something called "Service account key" in Google Add-on, but I don't really know what it is and if it's related to this problem. How can I handle subscriptions?

EDIT: I'm trying to make a system like this:

A player buys a subscription. The receipt gets validated on PlayFab. At this point, I need to save expiration date to the player's read only or internal data. I can't trust the client about this information. The context can be modified. The first problem is how can I get the expiration date on the server-side?

Let's say I got the expiration date and saved the date in the player's read only data. Every time the player logs in to the game, I check if the player's subscription expired or not by using the date I saved in the player's read only data. If the date indicates the future, that means the subscription is valid. I don't have to do anything. If the date indicates the past, that means the subscription needs to be renewed. At this point, I get the receipt information again from the client and check if the receipt is still active/valid (check if the player canceled the subscription on Google Play or not). Since the receipt is the same as the old one, PlayFab returns error saying receipt already used. I need to check if that receipt is still active on Play Store or not. How can I check this situation?

After checking the receipt, I need to get a new expiration date and overwrite it in the player's read only data. This process repeats itself.

While checking the receipt if the receipt is not valid/canceled, I simply need to delete the expiration date that is in the player's read only data so that I can understand that the player doesn't have a valid subscription. (When I try to read the expiration date on Cloudscript, it will return null since the key doesn't exist).

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
Seth Du avatar image
Seth Du answered

Currently, Subscription is not publicly supported by PlayFab and if you are in Premium or Enterprise Tier plan, you may submit a support ticket for application, though we can not guarantee the grant.

The auto-renewal cannot be handled well with the current system, I suggest do not use Play Store subscription feature. For the workarounds, as you are using an item in the catalog to represent the subscription, you may configure this item as non-stackable and consumed-by-time so that it requires players to purchase manually when the item is expired. In this case, it should be defined in Play Store as a normal item.

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.