This repository contains a Flask application that seamlessly integrates Stripe to facilitate one-time payments using the checkout strategy. It offers a clear and concise implementation, providing a robust starting point for integrating Stripe's payment processing capabilities into your Flask projects. Whether you're building a simple e-commerce site or a more complex application, this example will help you quickly set up and customize Stripe payments to suit your needs.
- Project Description
- Features
- Getting Started
- Usage
- Database Migrations
- Testing
- Extending the Project
- Contributing
- License
This project demonstrates how to integrate Stripe into a Flask application for handling one-time payments. The implementation includes secure payment processing using Stripe Checkout, making it easier to add payment capabilities to your Flask applications.
- Stripe Integration: Easily integrate Stripe for handling one-time payments.
- Secure Payments: Utilize Stripe’s secure payment processing.
- Extensible Codebase: Designed to be easily extended for additional payment-related features.
- Configuration Management: Handle configuration through a dedicated endpoint.
- Webhooks: Receive and handle real-time notifications from Stripe for various events (e.g., payment success).
- Dockerized Setup: Run the application and database using Docker containers.
- Database Migrations: Use Flask-Migrate to handle database migrations.
- Docker and Docker Compose
- Stripe account (with API keys)
- Create Stripe Account then navigate to the dashboard, then click 'Developers'.
-
Clone the repository:
Using HTTPS:
git clone https://github.com/yourusername/flask-stripe-payments.git cd flask-stripe-payments
Using SSH:
git clone [email protected]:yourusername/flask-stripe-payments.git cd flask-stripe-payments
-
Set up your Stripe API keys and other environment variables:
Create a
docker.env
file in the root directory and add your Stripe keys and other environment variables e.g:STRIPE_PUBLISHABLE_KEY=your_publishable_key STRIPE_SECRET_KEY=your_secret_key STRIPE_ENDPOINT_SECRET=your_webhook_endpoint_secret POSTGRES_DB=your_postgres_database
-
Build and run the Docker containers:
docker-compose up --build
This will start the Flask application and a PostgreSQL database in Docker containers.
-
Access the application: Open your browser and go to
http://127.0.0.1:5000/
. -
Make a payment: Click the "Purchase Supa Tee" button and complete the payment using the Stripe Checkout page.
To handle database migrations using Flask-Migrate, follow these steps:
-
Create a migration script:
docker-compose exec flask_app flask db migrate -m "Initial migration."
-
Apply the migration:
docker-compose exec flask_app flask db upgrade
These commands should be run inside the Docker container since the database is hosted there.
To run tests, execute the following command in your terminal:
docker-compose exec flask_app pytest
- Add Subscriptions: Implement subscription-based payments using Stripe.
- Multiple Payment Methods: Extend the payment options to include more methods supported by Stripe.
- Sending Emails: Send payment confirmation emails to customers.
- Update Order Status: Update the status of orders in the database.
Contributions are welcome! Please open an issue or submit a pull request for any enhancements or bug fixes.
This project is licensed under the MIT License. See the LICENSE file for details.