Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check if Users Subscription is still active with the RevenueCat API

Tags:

revenuecat

Whats the best way to check if a users subscription is still active with the RevenueCat API?

I can get the entitlements of a user but it seems like, after the expiration of the subscription, the entitlement is still in the entitlements object.

"entitlements": {
      "premium_monthly": {
        "expires_date": "2019-10-27T17:27:59Z",
        "product_identifier": "app_premium_monthly",
        "purchase_date": "2019-10-27T17:21:24Z"
      }
    },

The only way I see to do this is something like this:

                const exp = new Date(res.data.subscriber.entitlements.premium_monthly.expires_date)
                const now = new Date();
                if (exp.getTime() < now.getTime()) {
                    // Subscription is no longer valid
                }

Is that the intended way to do this or is there a better one?

like image 884
Jonas Avatar asked Sep 14 '25 09:09

Jonas


1 Answers

Yes, that's the way to check it. Compare current time with the expiration time provided by RevenueCat's API.

like image 61
MiguelCarranza Avatar answered Sep 17 '25 21:09

MiguelCarranza



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!