Mars Fitness is a gym that uses a subscription based membership.
The Flask Stripe Subscriptions tutorial by Nik Tomazic was used as a guide to integrate Stripe Payment in this application.
- Python 3.9 - Follow instruction to install the lates version of python for your platform in the python docs.
- Virtual Environment - Creating a virtual environment for the python project is recommended. Refer to the python docs.
- PIP Dependencies - After you set up the virtual enviornment setup and have it running, install dependencies by running the below command within the
/Mars-Fitness
folder.
$ pip install -r requirements.txt
- Key Dependencies
- Flask is a lightweight backend microservices framework. Flask is required to handle requests and responses.
- SQLAlchemy is the Python SQL toolkit and ORM we'll use to handle the postgres database.
- Psycopg2-binary is a PostgreSQL database adapter for the Python.
- Stripe is a suite of payment APIs that powers commerce for online businesses of all sizes.
Add following environemental variables must be set:
- Stripe test secret key
- test publishable key
- endpoint secret
- price API ID
$ export STRIPE_PUBLISHABLE_KEY=<YOUR_STRIPE_PUBLISHABLE_KEY>
$ export STRIPE_SECRET_KEY=<YOUR_STRIPE_SECRET_KEY>
$ export STRIPE_PRICE_ID=<YOUR_PRICE_API_ID>
$ export STRIPE_ENDPOINT_SECRET=<YOUR_ENDPOINT_SECRET_KEY>
For this project, Postgres is used as our database. Make sure to download the Postgres here.
$ createdb gym -U postgres
You may need to provide different postgres database url in config.py
if you used different users, password, or database name.
SQLALCHEMY_DATABASE_URI = 'postgres://<USER_NAME>:<PASSWORD>@localhost:<PORT>/<DATABASE_NAME>'
From within the ./Mars-Fitness
directory, first ensure that you are working using your created virtual environmentl.
To run the server, first set Flask Environment variables:
$ export FLASK_APP=app.py
$ export FLASK_ENV=development
and excute:
$ flask run --reload
The --reload
flag will detect file changes and restart the server automatically.
The application will be running on port 5000.
- Implement endpoint to fetch subscription data
- modify template to display the current plan to subscribed users
- Implement user authentication and restrict some routes
- Use Flask-User
- Create a database that holds user subscriptions
- Allow users to manage/cancel their current plan
- Handle future payment failures
- Deploy to Heroku and register webhook endpoints on Stripe