[Solved] how can I handle expiration dates for subscriptions?

Hi Community,
I am making an app which enables users to buy package which has an expiry date.
If the expiry date has passed the user should not be able to use the app.
I had searched the topics but most of them have project which cannot open.

I tried with Google Sheets, but not working. If i add formula, the formula will not apply for new subscribers.
Web API could be an option, but after some time that too is removed.

Can you help me with this one ??

Thanks,
Rohan

You are using IAP, right? You can meter it as such. After the purchase, depending on the length of purchase allowed, block access to the app.

I would save the date to a. user Object in my DB
when the user pays for a purchase, i set a date at some point in the future in my DB, in seconds since 1970.

Current seconds since 1970 + (duration in days * 1440 * 86400) = the future expiration date
when app opens and user signs in , first check that saved value and compare to current seconds since 1970 and if the current seconds since 1970 is smaller than the saved value, access should be permitted

2 Likes

Thanks Jared, Yes i am using IAP.
I am storing payment date and expiration date .
For each user expiration date can be different based on package selected.

I basically need if that date is crossed…

{
"packageName":"edu.fit.my.jgibb2018.pob",
"productId":"another1",
"acknowledged":false,
"purchaseToken":"gebigihgjkjgcfblmgnifmlh.AO-J1OxG8eGbkBVgA-tNuiejHB1hn4aWbOIjQjQgK3jw4K_-6RIKhDpgG6bI1-ZmqXF_VWaYQ-HJt_ouXSd6KsZ-cM4RtEqv7kfEKzexox_tNAWHJvFJndo",
"purchaseState":1,
"orderId":"GPA.3391-7141-0219-39243",
"purchaseTime":1654540369553
}

this is the response object returned by the get purchase history block. The most reliable way of making sure a sub is still valid is by calling htis method and comparing the purchaseTime + duration of subscription in seconds against the current time since 1970. Also making sure the purchase state is 1

Notes about purchaseState:

0 = PURCHASING - The transaction is being processed.

1 = PURCHASED - The App Store successfully processed payment.

2 = FAILED - The transaction failed.

3 = RESTORED - iOS OnlyThis transaction restores content previously purchased by the user. Read the originalTransaction properties to obtain information about the original purchase. InAppPurchaseState.RESTORED = 3

4 = DEFERRED - iOS OnlyThe transaction has been received, but its final status is pending external action such as the Ask to Buy feature where a child initiates a new purchase and has to wait for the family organizer's approval. Update your UI to show the deferred state, and wait for another callback that indicates the final status.

This is what i did … I used google Sheets but instead of putting predefined formula, i am putting formula via script. This way , this would be applied for new subscribers as well.

FORMULA : =IF(EXPIRATION_DATE< Today(), “Yes”,“No”) .

For No, i have already added logic id PAID Value is NO, then don’t allow to i.e will re-direct to non-paid subscription profile.

I know this is not the best way to deal with this, but somehow it works.

This is a good start. It would be best to move this into a firebase account and store the info under the users UUID as an object OR to use a DB that allows you to query against it’s values e.g. Airtable, Xano

  1. this would reduce the data transmission times (speed things up)
  2. this would reduce the data packet size (save on monthly bandwidth)
  3. this would protect the privacy of users on your app (your method sends everyones emails to each end user)
1 Like

Hi Jared, i forgot to ask why 1440 needs to be multiplied ?? When Days to second is *86400.

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.