Sample app to demonstrate the entire flow of keeping mobile entitlements up-to-date with RevenueCat.
The primary goal for this sample code is to be easy to understand and get setup with minimal dependencies.
The only third-party dependencies required are:
Bottle- lightweight WSGI framework for receiving HTTP webhooks from RevenueCatrequests- make HTTP request to RevenueCat APIcertifi- keeps the TLS certificate bundles up to date
The example uses sqlite so that the database can be created automatically, and should work wherever you can run Python code. Versions of the dependencies shouldn't matter since we're only using some of the most basic functionality.
main.py- Entry point for program and where all business logic takes placeapi_client.py- HTTP client interface to fetch from the RevenueCat APIdb_interface.py- Simple functions for interacting with the database using raw SQLexample-config.json- Template for config. More details in quickstart steps.
- Python 3
- pipenv (optional)
- Network tunnel to consume webhooks on your dev machine
- Mobile app that allows IAP
- RevenueCat account w/ Admin dashboard access
- Clone this repository &
cdinto it - Install without
pipenv:pip install -r requirements.txt
- OR Install with
pipenv- Install pipenv:
pip install --user pipenv pipenv installto install this project's dependencies
- Install pipenv:
- If running locally on your own computer, launch your network tunnel and point it to
localhost:8080 - Copy
example-config.jsontoconfig.jsonand add the values from your RevenueCat dashboard- Create a webhook and set the Authorization header value, which must be prefixed with
Bearer - Generate a V1 API secret key
- Get your project ID from the URL by
- Clicking the
Projectsdropdown, then select your preferred project - Copy the ID from the URL:
/projects/{PROJECT ID}/apps
- Clicking the
- Create a webhook and set the Authorization header value, which must be prefixed with
python3 main.py- You should see
Listening on http://localhost:8080in the console, which means your webhook server is up and listening for webhooks from RevenueCat
- You should see
- Try out a test webhook in the dashboard!
https://app.revenuecat.com/projects/{PROJECT ID}/integrations/webhooks
This diagram illustrates how the flow originates with RevenueCat webhooks, then moves through this sample app.
The TLS tunnel is optional, but typically the easiest way (vs port forwarding, etc.) to get HTTP requests to
your localhost. If you're running this behind a server that can already accept HTTP requests over the web, then you
can (and should) skip this entirely.
This is the simplest data model you need in order to track entitlement status in your system from RevenueCat.
On your end, tracking entitlement status for a given user is simplified by relying on the expiration timestamp.
Do not rely on a boolean field in the database because it will become stale if you don't see changes to entitlement.
Always just check if expiration > current_time because RevenueCat will calculate the litany of rules required and
provide you with an expiration if a subscription changes.
| Column | Type | Description |
|---|---|---|
| user_id | String | User ID your app uses to identify the user, or RC-generated Anonymous ID |
| entitlement | String | Entitlement ID granted for this user |
| expiration | Unix timestamp | When the entitlement access expires. Used to determine if the entitlement is active. |
| last_sync | Unix timestamp | Last time entitlements were synced from RevenueCat. |
| source | String | Reason for the entitlement sync. Defaults to 'revenuecat'. |