Django + Stripe made easy
Project description
Stripe Integrations
stripe-integrations
is an open source Python package that simplifies the integration of Stripe payments into your Django web application. Its key features include:
- Full support for Stripe's B2C Subscription.
- Management commands that help synchronize customer data, cards, subscriptions, coupons, prices, and products from Stripe.
- Built-in webhook handling for secure communication with Stripe.
- A wide range of functions for creating and managing customers, subscriptions, and other Stripe-related operations within your Django web application.
Table of Contents
💾 Installation
You can easily install or upgrade to the latest version of the package using pip:
pip install stripe-integrations
🚀 Quickstart
To get started quickly, follow these steps:
- Install the package using pip:
pip install stripe-integrations
- Add
stripe_integrations
to your INSTALLED_APPS setting:
INSTALLED_APPS = [
...,
'stripe_integrations',
]
- Create models to manage Stripe data using the abstract base classes provided in
stripe_integrations.models
. For example:
from stripe_integrations.models import StripeBaseCustomer, StripeBaseCard, StripeBaseSubscription, StripeBaseProduct, StripeBasePrice, StripeBaseCoupon, StripeBaseEvent
from users.models import User
class Customer(StripeBaseCustomer):
user = models.ForeignKey(
User,
on_delete=models.CASCADE,
related_name="stripe_customers",
)
# Add custom fields as per project requirement
class Card(StripeBaseCard):
customer = models.ForeignKey(
Customer,
on_delete=models.CASCADE,
related_name="cards",
)
# Add custom fields as per project requirement
class Subscription(StripeBaseSubscription):
customer = models.ForeignKey(
Customer,
on_delete=models.CASCADE,
related_name="subscriptions",
help_text="The customer associated with this subscription",
)
# Add custom fields as per project requirement
class Product(StripeBaseProduct):
# Add custom fields as per project requirement
pass
class Price(StripeBaseProduct):
product = models.ForeignKey(
Product,
on_delete=models.CASCADE,
related_name="prices",
)
# Add custom fields as per project requirement
class Coupon(StripeBaseCoupon):
# Add custom fields as per project requirement
pass
class Event(StripeBaseEvent):
# Add custom fields as per project requirement
pass
- Database migration
After implementing the models, create a migration file using the following command:
python manage.py makemigrations
Once the migration file has been created, apply the migrations to the database using the following command:
python manage.py migrate
- In your settings, update the model paths in
STRIPE_CONFIG
:
STRIPE_CONFIG = {
"API_VERSION": "2022-11-15", # Stripe API Version
"API_KEY": "api_key", # Stripe Secret Key
"CUSTOMER_MODEL": "project_name.app.models.Customer",
"CARD_MODEL": "project_name.app.models.Card",
"PRODUCT_MODEL": "project_name.app.models.Product",
"PRICE_MODEL": "project_name.app.models.Price",
"COUPON_MODEL": "project_name.app.models.Coupon",
"EVENT_MODEL": "project_name.app.models.Event",
"SUBSCRIPTION_MODEL": "project_name.app.models.Subscription",
"CUSTOMER_FIELD_NAME": "customer", # Field name used to have foreign key relation with `Customer` model
"USER_FIELD_NAME": "user", # Field name that is used by `Customer` model to have foreign relation to `User` model
}
- Implement APIs
You can use the appropriate actions to build payment APIs. Here are some examples:
- Creating a customer
from stripe_integrations.actions.customers import StripeCustomer
# Pass user model instance and email as argument
customer = StripeCustomer.create(user, billing_email)
- Creating a subscription
from stripe_integrations.actions.subscriptions import StripeSubscription
# Pass customer model instance and prices(List of stripe price ids) to subscribe as argument
subscription = StripeSubscription.create(customer, prices)
Code of Conduct
In order to foster a kind, inclusive, and harassment-free community, we have a code of conduct, which can be found here. We ask you to treat everyone as a smart human programmer that shares an interest in Python and stripe-integrations
with you.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for stripe_integrations-0.0.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 12a09dc83d25763e0e9a2b40f69e99b8b55a89a8d35a7f74484d66cf1aeaf315 |
|
MD5 | 118293d5ef1e0ca9b68b8d844c0c878f |
|
BLAKE2b-256 | adba9493487cb7b9f480b329dab4d875b0cab7f2d3f6f35c8b9e20d52944df3e |
Hashes for stripe_integrations-0.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1f533c02e46199414112af09acd30365ccba5f04c068a60a5c094ba16c5a040f |
|
MD5 | df0e6d3023b52c524cd759f802807433 |
|
BLAKE2b-256 | 17fe184e3ac55b3b2e7cb21ed6fbf8ac388a1336ab346f5bdaa164c27d82bf25 |